Skip to content

Commit

Permalink
Merge pull request #52 from sdelamo/multi-tenancy-to-main-gorm-hibern…
Browse files Browse the repository at this point in the history
…ate-docs

Add Multi-tenancy Transforms info
  • Loading branch information
graemerocher committed Sep 11, 2017
2 parents d1584ba + 2428254 commit 531d396
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/src/docs/asciidoc/multiTenancy/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ This type of architecture is highly common in Software as a Service (SaaS) and C

include::modes.adoc[]

=== Multi-Tenancy Transformations

include::tenantTransforms.adoc[]

=== Database Per Tenant

include::databasePerTenant.adoc[]
Expand Down
38 changes: 38 additions & 0 deletions docs/src/docs/asciidoc/multiTenancy/tenantTransforms.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
The following transformations can be applied to any class to simplify greatly the development of Multi-Tenant applications. These include:

- `@CurrentTenant` - Resolve the current tenant for the context of a class or method
- `@Tenant` - Use a specific tenant for the context of a class or method
- `@WithoutTenant` - Execute logic without a specific tenant (using the default connection)
For example:

[source,groovy]
----
import grails.gorm.multitenancy.*
// resolve the current tenant for every method
@CurrentTenant
class TeamService {
// execute the countPlayers method without a tenant id
@WithoutTenant
int countPlayers() {
Player.count()
}
// use the tenant id "another" for all GORM logic within the method
@Tenant({"another"})
List<Team> allTwoTeams() {
Team.list()
}
List<Team> listTeams() {
Team.list(max:10)
}
@Transactional
void addTeam(String name) {
new Team(name:name).save(flush:true)
}
}
----

0 comments on commit 531d396

Please sign in to comment.