Search in sources :

Example 1 with ActivitiWrongDbException

use of org.activiti.engine.ActivitiWrongDbException in project Activiti by Activiti.

the class DbSqlSession method dbSchemaCheckVersion.

// schema operations ////////////////////////////////////////////////////////
public void dbSchemaCheckVersion() {
    try {
        String dbVersion = getDbVersion();
        if (!ProcessEngine.VERSION.equals(dbVersion)) {
            throw new ActivitiWrongDbException(ProcessEngine.VERSION, dbVersion);
        }
        String errorMessage = null;
        if (!isEngineTablePresent()) {
            errorMessage = addMissingComponent(errorMessage, "engine");
        }
        if (dbSqlSessionFactory.isDbHistoryUsed() && !isHistoryTablePresent()) {
            errorMessage = addMissingComponent(errorMessage, "history");
        }
        if (dbSqlSessionFactory.isDbIdentityUsed() && !isIdentityTablePresent()) {
            errorMessage = addMissingComponent(errorMessage, "identity");
        }
        if (errorMessage != null) {
            throw new ActivitiException("Activiti database problem: " + errorMessage);
        }
    } catch (Exception e) {
        if (isMissingTablesException(e)) {
            throw new ActivitiException("no activiti tables in db. set <property name=\"databaseSchemaUpdate\" to value=\"true\" or value=\"create-drop\" (use create-drop for testing only!) in bean processEngineConfiguration in activiti.cfg.xml for automatic schema creation", e);
        } else {
            if (e instanceof RuntimeException) {
                throw (RuntimeException) e;
            } else {
                throw new ActivitiException("couldn't get db schema version", e);
            }
        }
    }
    log.debug("activiti db schema check successful");
}
Also used : ActivitiWrongDbException(org.activiti.engine.ActivitiWrongDbException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiOptimisticLockingException(org.activiti.engine.ActivitiOptimisticLockingException) ActivitiWrongDbException(org.activiti.engine.ActivitiWrongDbException) IOException(java.io.IOException)

Example 2 with ActivitiWrongDbException

use of org.activiti.engine.ActivitiWrongDbException 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

ActivitiException (org.activiti.engine.ActivitiException)2 ActivitiWrongDbException (org.activiti.engine.ActivitiWrongDbException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ActivitiOptimisticLockingException (org.activiti.engine.ActivitiOptimisticLockingException)1 ProcessEngineImpl (org.activiti.engine.impl.ProcessEngineImpl)1 DbSqlSession (org.activiti.engine.impl.db.DbSqlSession)1 DbSqlSessionFactory (org.activiti.engine.impl.db.DbSqlSessionFactory)1 SqlSession (org.apache.ibatis.session.SqlSession)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1