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);
}
}
}
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();
}
Aggregations