Search in sources :

Example 1 with HibernateDatabaseSetup

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();
}
Also used : HibernateDatabaseSetup(com.manydesigns.portofino.persistence.hibernate.HibernateDatabaseSetup)

Example 2 with HibernateDatabaseSetup

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);
    }
}
Also used : SessionFactoryAndCodeBase(com.manydesigns.portofino.persistence.hibernate.SessionFactoryAndCodeBase) MultiTenancyImplementation(com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementation) SessionFactoryBuilder(com.manydesigns.portofino.persistence.hibernate.SessionFactoryBuilder) HibernateDatabaseSetup(com.manydesigns.portofino.persistence.hibernate.HibernateDatabaseSetup) FileSystemException(org.apache.commons.vfs2.FileSystemException) IOException(java.io.IOException) JAXBException(javax.xml.bind.JAXBException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException)

Example 3 with HibernateDatabaseSetup

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));
    }
}
Also used : CacheResetEvent(com.manydesigns.portofino.cache.CacheResetEvent) HibernateDatabaseSetup(com.manydesigns.portofino.persistence.hibernate.HibernateDatabaseSetup)

Aggregations

HibernateDatabaseSetup (com.manydesigns.portofino.persistence.hibernate.HibernateDatabaseSetup)3 CacheResetEvent (com.manydesigns.portofino.cache.CacheResetEvent)1 SessionFactoryAndCodeBase (com.manydesigns.portofino.persistence.hibernate.SessionFactoryAndCodeBase)1 SessionFactoryBuilder (com.manydesigns.portofino.persistence.hibernate.SessionFactoryBuilder)1 MultiTenancyImplementation (com.manydesigns.portofino.persistence.hibernate.multitenancy.MultiTenancyImplementation)1 IOException (java.io.IOException)1 JAXBException (javax.xml.bind.JAXBException)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1 FileSystemException (org.apache.commons.vfs2.FileSystemException)1