diff --git a/spring-geode-docs/src/docs/asciidoc/index.adoc b/spring-geode-docs/src/docs/asciidoc/index.adoc index daca7c83..f6fbfc56 100644 --- a/spring-geode-docs/src/docs/asciidoc/index.adoc +++ b/spring-geode-docs/src/docs/asciidoc/index.adoc @@ -107,3 +107,4 @@ Finally, we arrive at Spring Boot for Apache Geode & Pivotal GemFire. include::clientcache-applications.adoc[] include::caching.adoc[] +include::repositories.adoc[] diff --git a/spring-geode-docs/src/docs/asciidoc/repositories.adoc b/spring-geode-docs/src/docs/asciidoc/repositories.adoc new file mode 100644 index 00000000..9559b525 --- /dev/null +++ b/spring-geode-docs/src/docs/asciidoc/repositories.adoc @@ -0,0 +1,88 @@ +[[geode-repositories]] +== Spring Data for Apache Geode & Pivotal GemFire Repositories + +Using Spring Data Repositories with Apache Geode or Pivotal GemFire makes short work of data access operations +when using either Apache Geode or Pivotal GemFire as your System of Record (SOR), persisting your application's +state. + +{spring-data-commons-docs-html}/#repositories[Spring Data Repositories] provides a convenient and highly powerful way +to define basic CRUD and simply query data access operations simply by specifying the contract of those data access +operations with a Java interface. + +Spring Boot for Apache Geode & Pivotal GemFire _auto-configures_ the Spring Data for Apache Geode/Pivotal GemFire +{spring-data-geode-docs-html}/#gemfire-repositories[Repository infrastructure and extension] when either is +declared on your application's classpath. You do not need to do anything special to enable it. Simply start coding +your application-specific Repository interface extensions and the way you go. + +For example: + +Define the `Customer` application domain object modeling customers and map it to the GemFire/Geode "Customers" Region +using SDG's {spring-data-geode-javadoc}/org/springframework/data/gemfire/mapping/annotation/Region.html[`@Region`] +mapping annotation: + +.Customer application domain object +[source,java] +---- +package example.app.model; + +import ...; +@Region("Customers") +class Customer { + + @Id + private Long id; + + private String name; + + .... +} +---- + +Declare your _Repository_ (Data Access Object (DAO)) for `Customers`... + +.CustomerRepository for peristing and accessing `Customers` +[source,java] +---- +package example.app.repo; + +import ...; + +interface CustomerRepository extends CrudRepository { + + List findByLastNameLikeOrderByLastNameDescFirstNameAsc(String customerLastNameWildcard); + +} +---- + +Then use the `CustomerRepository` in an application service class: + +.Inject and use the `CustomerRepository` +[source,java] +---- +package example.app; + +import ...; + +@SpringBootApplication +@EnableEntityDefinedRegions(basePackageClasses = Customer.class) +class SpringBootApacheGeodeClientCacheApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootApacheGeodeClientCacheApplication.class, args); + } + + @Bean + ApplicationRunner runner(CustomerRepository customerRepository) { + + // Matches Williams, Wilson, etc. + List customers = + customerRepository.findByLastNameLikeOrderByLastNameDescFirstNameAsc("Wil%"); + + // process the list of matching customers... + } +} +---- + +Again, see Spring Data Commons' {spring-data-commons-docs-html}/#repositories[Repositories abstraction] in general, +and Spring Data for Apache Geode/Pivotal GemFire {spring-data-geode-docs-html}/#gemfire-repositories[Repositories extension] +in particular, for more details.