-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from sdelamo/multi-tenancy-to-main-gorm-hibern…
…ate-docs Add Multi-tenancy Transforms info
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
---- |