Search in sources :

Example 1 with DbSqlSessionFactory

use of org.activiti.engine.impl.db.DbSqlSessionFactory in project Activiti by Activiti.

the class ProcessEngineConfigurationImpl method initSessionFactories.

// session factories ////////////////////////////////////////////////////////
protected void initSessionFactories() {
    if (sessionFactories == null) {
        sessionFactories = new HashMap<Class<?>, SessionFactory>();
        if (dbSqlSessionFactory == null) {
            dbSqlSessionFactory = new DbSqlSessionFactory();
        }
        dbSqlSessionFactory.setDatabaseType(databaseType);
        dbSqlSessionFactory.setIdGenerator(idGenerator);
        dbSqlSessionFactory.setSqlSessionFactory(sqlSessionFactory);
        dbSqlSessionFactory.setDbIdentityUsed(isDbIdentityUsed);
        dbSqlSessionFactory.setDbHistoryUsed(isDbHistoryUsed);
        dbSqlSessionFactory.setDatabaseTablePrefix(databaseTablePrefix);
        dbSqlSessionFactory.setTablePrefixIsSchema(tablePrefixIsSchema);
        dbSqlSessionFactory.setDatabaseCatalog(databaseCatalog);
        dbSqlSessionFactory.setDatabaseSchema(databaseSchema);
        dbSqlSessionFactory.setBulkInsertEnabled(isBulkInsertEnabled, databaseType);
        dbSqlSessionFactory.setMaxNrOfStatementsInBulkInsert(maxNrOfStatementsInBulkInsert);
        addSessionFactory(dbSqlSessionFactory);
        addSessionFactory(new GenericManagerFactory(AttachmentEntityManager.class));
        addSessionFactory(new GenericManagerFactory(CommentEntityManager.class));
        addSessionFactory(new GenericManagerFactory(DeploymentEntityManager.class));
        addSessionFactory(new GenericManagerFactory(ModelEntityManager.class));
        addSessionFactory(new GenericManagerFactory(ExecutionEntityManager.class));
        addSessionFactory(new GenericManagerFactory(HistoricActivityInstanceEntityManager.class));
        addSessionFactory(new GenericManagerFactory(HistoricDetailEntityManager.class));
        addSessionFactory(new GenericManagerFactory(HistoricProcessInstanceEntityManager.class));
        addSessionFactory(new GenericManagerFactory(HistoricVariableInstanceEntityManager.class));
        addSessionFactory(new GenericManagerFactory(HistoricTaskInstanceEntityManager.class));
        addSessionFactory(new GenericManagerFactory(HistoricIdentityLinkEntityManager.class));
        addSessionFactory(new GenericManagerFactory(IdentityInfoEntityManager.class));
        addSessionFactory(new GenericManagerFactory(IdentityLinkEntityManager.class));
        addSessionFactory(new GenericManagerFactory(JobEntityManager.class));
        addSessionFactory(new GenericManagerFactory(ProcessDefinitionEntityManager.class));
        addSessionFactory(new GenericManagerFactory(ProcessDefinitionInfoEntityManager.class));
        addSessionFactory(new GenericManagerFactory(PropertyEntityManager.class));
        addSessionFactory(new GenericManagerFactory(ResourceEntityManager.class));
        addSessionFactory(new GenericManagerFactory(ByteArrayEntityManager.class));
        addSessionFactory(new GenericManagerFactory(TableDataManager.class));
        addSessionFactory(new GenericManagerFactory(TaskEntityManager.class));
        addSessionFactory(new GenericManagerFactory(VariableInstanceEntityManager.class));
        addSessionFactory(new GenericManagerFactory(EventSubscriptionEntityManager.class));
        addSessionFactory(new GenericManagerFactory(EventLogEntryEntityManager.class));
        addSessionFactory(new DefaultHistoryManagerSessionFactory());
        addSessionFactory(new UserEntityManagerFactory());
        addSessionFactory(new GroupEntityManagerFactory());
        addSessionFactory(new MembershipEntityManagerFactory());
    }
    if (customSessionFactories != null) {
        for (SessionFactory sessionFactory : customSessionFactories) {
            addSessionFactory(sessionFactory);
        }
    }
}
Also used : HistoricTaskInstanceEntityManager(org.activiti.engine.impl.persistence.entity.HistoricTaskInstanceEntityManager) EventSubscriptionEntityManager(org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager) GroupEntityManagerFactory(org.activiti.engine.impl.persistence.GroupEntityManagerFactory) HistoricVariableInstanceEntityManager(org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntityManager) UserEntityManagerFactory(org.activiti.engine.impl.persistence.UserEntityManagerFactory) EventLogEntryEntityManager(org.activiti.engine.impl.persistence.entity.EventLogEntryEntityManager) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager) DeploymentEntityManager(org.activiti.engine.impl.persistence.entity.DeploymentEntityManager) ResourceEntityManager(org.activiti.engine.impl.persistence.entity.ResourceEntityManager) CommentEntityManager(org.activiti.engine.impl.persistence.entity.CommentEntityManager) HistoricDetailEntityManager(org.activiti.engine.impl.persistence.entity.HistoricDetailEntityManager) GenericManagerFactory(org.activiti.engine.impl.persistence.GenericManagerFactory) HistoricVariableInstanceEntityManager(org.activiti.engine.impl.persistence.entity.HistoricVariableInstanceEntityManager) VariableInstanceEntityManager(org.activiti.engine.impl.persistence.entity.VariableInstanceEntityManager) SessionFactory(org.activiti.engine.impl.interceptor.SessionFactory) DefaultSqlSessionFactory(org.apache.ibatis.session.defaults.DefaultSqlSessionFactory) DefaultHistoryManagerSessionFactory(org.activiti.engine.impl.persistence.DefaultHistoryManagerSessionFactory) DbSqlSessionFactory(org.activiti.engine.impl.db.DbSqlSessionFactory) EntityManagerSessionFactory(org.activiti.engine.impl.variable.EntityManagerSessionFactory) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) JobEntityManager(org.activiti.engine.impl.persistence.entity.JobEntityManager) ProcessDefinitionInfoEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionInfoEntityManager) DefaultHistoryManagerSessionFactory(org.activiti.engine.impl.persistence.DefaultHistoryManagerSessionFactory) ProcessDefinitionEntityManager(org.activiti.engine.impl.persistence.entity.ProcessDefinitionEntityManager) HistoricIdentityLinkEntityManager(org.activiti.engine.impl.persistence.entity.HistoricIdentityLinkEntityManager) IdentityLinkEntityManager(org.activiti.engine.impl.persistence.entity.IdentityLinkEntityManager) MembershipEntityManagerFactory(org.activiti.engine.impl.persistence.MembershipEntityManagerFactory) HistoricActivityInstanceEntityManager(org.activiti.engine.impl.persistence.entity.HistoricActivityInstanceEntityManager) IdentityInfoEntityManager(org.activiti.engine.impl.persistence.entity.IdentityInfoEntityManager) DbSqlSessionFactory(org.activiti.engine.impl.db.DbSqlSessionFactory) HistoricIdentityLinkEntityManager(org.activiti.engine.impl.persistence.entity.HistoricIdentityLinkEntityManager) PropertyEntityManager(org.activiti.engine.impl.persistence.entity.PropertyEntityManager) TableDataManager(org.activiti.engine.impl.persistence.entity.TableDataManager) TaskEntityManager(org.activiti.engine.impl.persistence.entity.TaskEntityManager) ModelEntityManager(org.activiti.engine.impl.persistence.entity.ModelEntityManager) HistoricProcessInstanceEntityManager(org.activiti.engine.impl.persistence.entity.HistoricProcessInstanceEntityManager) AttachmentEntityManager(org.activiti.engine.impl.persistence.entity.AttachmentEntityManager) ByteArrayEntityManager(org.activiti.engine.impl.persistence.entity.ByteArrayEntityManager)

Example 2 with DbSqlSessionFactory

use of org.activiti.engine.impl.db.DbSqlSessionFactory in project Activiti by Activiti.

the class ProcessEngineInitializationTest method testVersionMismatch.

public void testVersionMismatch() {
    // first create the schema
    ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/standalone/initialization/notables.activiti.cfg.xml").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP).buildProcessEngine();
    // then update the version to something that is different to the library
    // version
    DbSqlSessionFactory dbSqlSessionFactory = (DbSqlSessionFactory) processEngine.getProcessEngineConfiguration().getSessionFactories().get(DbSqlSession.class);
    SqlSessionFactory sqlSessionFactory = dbSqlSessionFactory.getSqlSessionFactory();
    SqlSession sqlSession = sqlSessionFactory.openSession();
    boolean success = false;
    try {
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("name", "schema.version");
        parameters.put("value", "25.7");
        parameters.put("revision", 1);
        parameters.put("newRevision", 2);
        sqlSession.update("updateProperty", parameters);
        success = true;
    } catch (Exception e) {
        throw new ActivitiException("couldn't update db schema version", e);
    } finally {
        if (success) {
            sqlSession.commit();
        } else {
            sqlSession.rollback();
        }
        sqlSession.close();
    }
    try {
        // now we can see what happens if when a process engine is being
        // build with a version mismatch between library and db tables
        ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("org/activiti/standalone/initialization/notables.activiti.cfg.xml").setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE).buildProcessEngine();
        fail("expected exception");
    } catch (ActivitiWrongDbException e) {
        assertTextPresent("version mismatch", e.getMessage());
        assertEquals("25.7", e.getDbVersion());
        assertEquals(ProcessEngine.VERSION, e.getLibraryVersion());
    }
    // closing the original process engine to drop the db tables
    processEngine.close();
}
Also used : ActivitiException(org.activiti.engine.ActivitiException) ActivitiWrongDbException(org.activiti.engine.ActivitiWrongDbException) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession) SqlSession(org.apache.ibatis.session.SqlSession) HashMap(java.util.HashMap) ActivitiException(org.activiti.engine.ActivitiException) ActivitiWrongDbException(org.activiti.engine.ActivitiWrongDbException) DbSqlSession(org.activiti.engine.impl.db.DbSqlSession) DbSqlSessionFactory(org.activiti.engine.impl.db.DbSqlSessionFactory) DbSqlSessionFactory(org.activiti.engine.impl.db.DbSqlSessionFactory) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) ProcessEngineImpl(org.activiti.engine.impl.ProcessEngineImpl)

Aggregations

DbSqlSessionFactory (org.activiti.engine.impl.db.DbSqlSessionFactory)2 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)2 HashMap (java.util.HashMap)1 ActivitiException (org.activiti.engine.ActivitiException)1 ActivitiWrongDbException (org.activiti.engine.ActivitiWrongDbException)1 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)1 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)1 SessionFactory (org.activiti.engine.impl.interceptor.SessionFactory)1 DefaultHistoryManagerSessionFactory (org.activiti.engine.impl.persistence.DefaultHistoryManagerSessionFactory)1 GenericManagerFactory (org.activiti.engine.impl.persistence.GenericManagerFactory)1 GroupEntityManagerFactory (org.activiti.engine.impl.persistence.GroupEntityManagerFactory)1 MembershipEntityManagerFactory (org.activiti.engine.impl.persistence.MembershipEntityManagerFactory)1 UserEntityManagerFactory (org.activiti.engine.impl.persistence.UserEntityManagerFactory)1 AttachmentEntityManager (org.activiti.engine.impl.persistence.entity.AttachmentEntityManager)1 ByteArrayEntityManager (org.activiti.engine.impl.persistence.entity.ByteArrayEntityManager)1 CommentEntityManager (org.activiti.engine.impl.persistence.entity.CommentEntityManager)1 DeploymentEntityManager (org.activiti.engine.impl.persistence.entity.DeploymentEntityManager)1 EventLogEntryEntityManager (org.activiti.engine.impl.persistence.entity.EventLogEntryEntityManager)1 EventSubscriptionEntityManager (org.activiti.engine.impl.persistence.entity.EventSubscriptionEntityManager)1 ExecutionEntityManager (org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)1