#215 - Add reactive examples for MongoDB, Apache Cassandra and Redis.
This commit is contained in:
committed by
Oliver Gierke
parent
cf5d9f3562
commit
20879e7fa3
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package example.springdata.cassandra.people;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.data.cassandra.config.SchemaAction;
|
||||
import org.springframework.data.cassandra.config.java.AbstractReactiveCassandraConfiguration;
|
||||
import org.springframework.data.cassandra.repository.config.EnableReactiveCassandraRepositories;
|
||||
|
||||
/**
|
||||
* Simple configuration for reactive Cassandra support.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableReactiveCassandraRepositories
|
||||
class ApplicationConfiguration extends AbstractReactiveCassandraConfiguration {
|
||||
|
||||
@Override
|
||||
protected String getKeyspaceName() {
|
||||
return "example";
|
||||
}
|
||||
|
||||
@Override
|
||||
public SchemaAction getSchemaAction() {
|
||||
return SchemaAction.RECREATE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package example.springdata.cassandra.people;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.springframework.cassandra.core.PrimaryKeyType;
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
/**
|
||||
* An entity to represent a Person.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@Table
|
||||
public class Person {
|
||||
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.CLUSTERED, ordinal = 2) private String firstname;
|
||||
@PrimaryKeyColumn(type = PrimaryKeyType.PARTITIONED, ordinal = 1) private String lastname;
|
||||
private int age;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package example.springdata.cassandra.people;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.data.cassandra.repository.Query;
|
||||
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
|
||||
|
||||
/**
|
||||
* Repository interface to manage {@link Person} instances.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public interface ReactivePersonRepository extends ReactiveCrudRepository<Person, String> {
|
||||
|
||||
/**
|
||||
* Derived query selecting by {@code lastname}.
|
||||
*
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
Flux<Person> findByLastname(String lastname);
|
||||
|
||||
/**
|
||||
* String query selecting one entity.
|
||||
*
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
@Query("SELECT * FROM person WHERE firstname = ?0 and lastname = ?1")
|
||||
Mono<Person> findByFirstnameInAndLastname(String firstname, String lastname);
|
||||
|
||||
/**
|
||||
* Derived query selecting by {@code lastname}. {@code lastname} uses deferred resolution that does not require
|
||||
* blocking to obtain the parameter value.
|
||||
*
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
Flux<Person> findByLastname(Mono<String> lastname);
|
||||
|
||||
/**
|
||||
* Derived query selecting by {@code firstname} and {@code lastname}. {@code firstname} uses deferred resolution that
|
||||
* does not require blocking to obtain the parameter value.
|
||||
*
|
||||
* @param firstname
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
Mono<Person> findByFirstnameAndLastname(Mono<String> firstname, String lastname);
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package example.springdata.cassandra.people;
|
||||
|
||||
import rx.Observable;
|
||||
import rx.Single;
|
||||
|
||||
import org.springframework.data.cassandra.repository.Query;
|
||||
import org.springframework.data.repository.reactive.RxJava1CrudRepository;
|
||||
|
||||
/**
|
||||
* Repository interface to manage {@link Person} instances.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public interface RxJava1PersonRepository extends RxJava1CrudRepository<Person, String> {
|
||||
|
||||
/**
|
||||
* Derived query selecting by {@code lastname}.
|
||||
*
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
Observable<Person> findByLastname(String lastname);
|
||||
|
||||
/**
|
||||
* String query selecting one entity.
|
||||
*
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
@Query("SELECT * FROM person WHERE firstname = ?0 and lastname = ?1")
|
||||
Single<Person> findByFirstnameAndLastname(String firstname, String lastname);
|
||||
|
||||
/**
|
||||
* Derived query selecting by {@code lastname}. {@code lastname} uses deferred resolution that does not require
|
||||
* blocking to obtain the parameter value.
|
||||
*
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
Observable<Person> findByLastname(Single<String> lastname);
|
||||
|
||||
/**
|
||||
* Derived query selecting by {@code firstname} and {@code lastname}. {@code firstname} uses deferred resolution that
|
||||
* does not require blocking to obtain the parameter value.
|
||||
*
|
||||
* @param firstname
|
||||
* @param lastname
|
||||
* @return
|
||||
*/
|
||||
Single<Person> findByFirstnameAndLastname(Single<String> firstname, String lastname);
|
||||
}
|
||||
Reference in New Issue
Block a user