Search in sources :

Example 1 with SessionFactoryBuilder

use of com.manydesigns.portofino.persistence.hibernate.SessionFactoryBuilder 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)

Aggregations

HibernateDatabaseSetup (com.manydesigns.portofino.persistence.hibernate.HibernateDatabaseSetup)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