From 8a749c98ab71c4e3bae6d8baec3b6eaa97d8f06e Mon Sep 17 00:00:00 2001 From: niravassar Date: Wed, 1 Jul 2020 13:26:55 -0500 Subject: [PATCH] add to documentation on how to use gorm service with multiple dbs --- .../multipleDataSources/dataServices.adoc | 19 +++++++++++++++ .../asciidoc/multipleDataSources/index.adoc | 8 +++++++ .../asciidoc/multipleDataSources/queries.adoc | 23 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 docs/src/docs/asciidoc/multipleDataSources/dataServices.adoc create mode 100644 docs/src/docs/asciidoc/multipleDataSources/queries.adoc diff --git a/docs/src/docs/asciidoc/multipleDataSources/dataServices.adoc b/docs/src/docs/asciidoc/multipleDataSources/dataServices.adoc new file mode 100644 index 000000000..87efacab9 --- /dev/null +++ b/docs/src/docs/asciidoc/multipleDataSources/dataServices.adoc @@ -0,0 +1,19 @@ + +GORM Data Services can operate on multiple data sources. + +The `@Transactional` annotation can specify the `DataSource` where `ZipCode` domains exists. + +When no annotation is used, then the service goes to the default `DataSource`, as in `deleteByCode(String code)`. + +[source,groovy] +---- +@CompileStatic +@Service(ZipCode) +interface ZipCodeService { + + @Transactional('lookup') + ZipCode findByCode(String code) + + void deleteByCode(String code) +} +---- diff --git a/docs/src/docs/asciidoc/multipleDataSources/index.adoc b/docs/src/docs/asciidoc/multipleDataSources/index.adoc index 5648f086e..b689e7c23 100644 --- a/docs/src/docs/asciidoc/multipleDataSources/index.adoc +++ b/docs/src/docs/asciidoc/multipleDataSources/index.adoc @@ -30,3 +30,11 @@ for(ConnectionSource connecti SessionFactory sessionFactory = connectionSource.source } ---- + +=== Data Services with Multiple Data Sources + +include::dataServices.adoc[] + +=== Queries with Multiple Data Sources + +include::queries.adoc[] diff --git a/docs/src/docs/asciidoc/multipleDataSources/queries.adoc b/docs/src/docs/asciidoc/multipleDataSources/queries.adoc new file mode 100644 index 000000000..1c885cd20 --- /dev/null +++ b/docs/src/docs/asciidoc/multipleDataSources/queries.adoc @@ -0,0 +1,23 @@ + +Queries can be written for mulitiple data sources with a dynamic finder, where query, or criteria query as well. + +Where Query: + +[source,groovy] +---- +ZipCode.where {}.withConnection('lookup').list() +---- + +Dynamic Finder: + +[source,groovy] +---- +ZipCode.lookup.findAll() +---- + +Criteria: + +[source,groovy] +---- +ZipCode.lookup.createCriteria.list {} +----