use of com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementation in project Portofino by ManyDesigns.
the class Persistence method initConnectionProvider.
protected void initConnectionProvider(Database database) {
logger.info("Initializing connection provider for database " + database.getDatabaseName());
try {
ConnectionProvider connectionProvider = database.getConnectionProvider();
connectionProvider.init(databasePlatformsRegistry);
if (connectionProvider.getStatus().equals(ConnectionProvider.STATUS_CONNECTED)) {
MultiTenancyImplementation implementation = getMultiTenancyImplementation(database);
SessionFactoryBuilder builder = new SessionFactoryBuilder(database, configuration.getProperties(), implementation);
SessionFactoryAndCodeBase sessionFactoryAndCodeBase = builder.buildSessionFactory();
HibernateDatabaseSetup setup = new HibernateDatabaseSetup(database, sessionFactoryAndCodeBase.sessionFactory, sessionFactoryAndCodeBase.codeBase, builder.getEntityMode(), configuration.getProperties(), implementation);
String databaseName = database.getDatabaseName();
HibernateDatabaseSetup oldSetup = setups.get(databaseName);
setups.put(databaseName, setup);
if (oldSetup != null) {
oldSetup.dispose();
databaseSetupEvents.onNext(new DatabaseSetupEvent(oldSetup, setup));
} else {
databaseSetupEvents.onNext(new DatabaseSetupEvent(DatabaseSetupEvent.ADDED, setup));
}
}
} catch (Exception e) {
logger.error("Could not create connection provider for " + database, e);
}
}
use of com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementation in project Portofino by ManyDesigns.
the class Persistence method getMultiTenancyImplementation.
protected MultiTenancyImplementation getMultiTenancyImplementation(Database database) {
Optional<MultiTenant> multiTenant = database.getJavaAnnotation(MultiTenant.class);
if (multiTenant.isPresent()) {
Class<? extends MultiTenancyImplementation> implClass = multiTenant.get().strategy();
// TODO injection?
if (!MultiTenancyImplementation.class.isAssignableFrom(implClass)) {
throw new ClassCastException(implClass + " does not extend " + MultiTenancyImplementation.class);
}
try {
MultiTenancyImplementation implementation = multiTenancyImplementationFactory.make(implClass);
MultiTenancyStrategy strategy = implementation.getStrategy();
if (strategy.requiresMultiTenantConnectionProvider()) {
return implementation;
}
} catch (Exception e) {
throw new RuntimeException("Could not instantiate multi tenancy implementation " + implClass + " for " + database, e);
}
}
return null;
}
Aggregations