grails.gorm.rx.MultiTenant.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of grails-datastore-gorm-rx Show documentation
Show all versions of grails-datastore-gorm-rx Show documentation
GORM - Grails Data Access Framework
The newest version!
package grails.gorm.rx
import grails.gorm.api.GormAllOperations
import grails.gorm.rx.api.RxGormAllOperations
import groovy.transform.CompileStatic
import org.grails.datastore.gorm.GormEnhancer
import org.grails.datastore.mapping.core.connections.ConnectionSource
import org.grails.gorm.rx.api.RxGormEnhancer
/**
* A trait for domain classes that should be treated as multi tenant
*
* @author Graeme Rocher
* @since 6.0
*/
@CompileStatic
trait MultiTenant extends RxEntity {
/**
* Execute the closure with the given tenantId
*
* @param tenantId The tenant id
* @param callable The closure
* @return The result of the closure
*/
static T withTenant(Serializable tenantId, @DelegatesTo(RxGormAllOperations) Closure callable) {
RxGormEnhancer.findStaticApi(this).withTenant tenantId, callable
}
/**
* Execute the closure for each tenant
*
* @param callable The closure
* @return The result of the closure
*/
static RxGormAllOperations eachTenant( @DelegatesTo(RxGormAllOperations) Closure callable) {
RxGormEnhancer.findStaticApi(this, ConnectionSource.DEFAULT).eachTenant callable
}
/**
* Return the {@link GormAllOperations} for the given tenant id
*
* @param tenantId The tenant id
* @return The operations
*/
static RxGormAllOperations withTenant(Serializable tenantId) {
(RxGormAllOperations)RxGormEnhancer.findStaticApi(this).withTenant(tenantId)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy