use of com.manydesigns.portofino.persistence.hibernate.HibernateDatabaseSetup in project Portofino by ManyDesigns.
the class Persistence method stop.
public void stop() {
// TODO complete subscriptions?
status.onNext(Status.STOPPING);
closeSessions();
for (HibernateDatabaseSetup setup : setups.values()) {
setup.dispose();
}
for (Database database : model.getDatabases()) {
ConnectionProvider connectionProvider = database.getConnectionProvider();
connectionProvider.shutdown();
}
status.onNext(Status.STOPPED);
databaseSetupEvents.onComplete();
status.onComplete();
}
use of com.manydesigns.portofino.persistence.hibernate.HibernateDatabaseSetup 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.HibernateDatabaseSetup in project Portofino by ManyDesigns.
the class Persistence method initModel.
public synchronized void initModel() {
logger.info("Cleaning up old setups");
closeSessions();
for (Map.Entry<String, HibernateDatabaseSetup> current : setups.entrySet()) {
String databaseName = current.getKey();
logger.debug("Cleaning up old setup for: {}", databaseName);
HibernateDatabaseSetup setup = current.getValue();
try {
setup.dispose();
} catch (Throwable t) {
logger.warn("Cannot close session factory for: " + databaseName, t);
}
databaseSetupEvents.onNext(new DatabaseSetupEvent(DatabaseSetupEvent.REMOVED, setup));
}
// TODO it would perhaps be preferable that we generated REPLACED events here rather than REMOVED followed by ADDED
setups.clear();
model.init(configuration.getProperties());
for (Database database : model.getDatabases()) {
Boolean enabled = database.getJavaAnnotation(Enabled.class).map(Enabled::value).orElse(true);
if (enabled) {
initConnectionProvider(database);
} else {
logger.info("Skipping disabled database " + database.getQualifiedName());
}
}
if (cacheResetListenerRegistry != null) {
cacheResetListenerRegistry.fireReset(new CacheResetEvent(this));
}
}
Aggregations