Example usage for org.apache.ibatis.session SqlSession commit

List of usage examples for org.apache.ibatis.session SqlSession commit

Introduction

In this page you can find the example usage for org.apache.ibatis.session SqlSession commit.

Prototype

void commit();

Source Link

Document

Flushes batch statements and commits database connection.

Usage

From source file:org.flowable.standalone.initialization.ProcessEngineInitializationTest.java

License:Apache License

public void testVersionMismatch() {
    // first create the schema
    ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngineConfiguration
            .createProcessEngineConfigurationFromResource(
                    "org/flowable/standalone/initialization/notables.flowable.cfg.xml")
            .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP)
            .buildProcessEngine();//from  w  w  w .  j  a  va2  s  .  c om

    // 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 FlowableException("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/flowable/standalone/initialization/notables.flowable.cfg.xml")
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                .buildProcessEngine();

        fail("expected exception");
    } catch (FlowableWrongDbException 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();
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisAccountsDao.java

License:Open Source License

@Override
public void addAccount(final Account account) {
    final SqlSession session = sessions.openSession();
    try {/* www  .  j  a  v a2  s. c o m*/
        session.insert(namespace + "addAccount", toMap(account));
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisAccountsDao.java

License:Open Source License

private void removeAccount(final String selector, final Sid sid) {
    final SqlSession session = sessions.openSession();
    try {// www.j av a 2s . c  om
        session.delete(selector, sid.toString());
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisAccountsDao.java

License:Open Source License

private void updateAccount(final String selector, final Account account) {
    final SqlSession session = sessions.openSession();
    try {/*w ww  . j  av  a2  s.  com*/
        session.update(selector, toMap(account));
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisApplicationsDao.java

License:Open Source License

@Override
public void addApplication(final Application application) {
    final SqlSession session = sessions.openSession();
    try {/* w  ww . j a v a2  s.  c  om*/
        session.insert(namespace + "addApplication", toMap(application));
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisApplicationsDao.java

License:Open Source License

private void removeApplications(final String selector, final Sid sid) {
    final SqlSession session = sessions.openSession();
    try {//from w  w  w .  java2 s .c o m
        session.delete(namespace + selector, sid.toString());
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisApplicationsDao.java

License:Open Source License

@Override
public void updateApplication(final Application application) {
    final SqlSession session = sessions.openSession();
    try {/*  w  w  w. j av a  2  s  .  c  o m*/
        session.update(namespace + "updateApplication", toMap(application));
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisAvailablePhoneNumbersDao.java

License:Open Source License

@Override
public void addAvailablePhoneNumber(final AvailablePhoneNumber availablePhoneNumber) {
    final SqlSession session = sessions.openSession();
    try {/*from  w w w .  ja  v  a 2  s. c om*/
        session.insert(namespace + "addAvailablePhoneNumber", toMap(availablePhoneNumber));
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisAvailablePhoneNumbersDao.java

License:Open Source License

@Override
public void removeAvailablePhoneNumber(final String phoneNumber) {
    final SqlSession session = sessions.openSession();
    try {/*w  ww . j a v  a  2  s. c  om*/
        session.delete(namespace + "removeAvailablePhoneNumber", phoneNumber);
        session.commit();
    } finally {
        session.close();
    }
}

From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisCallDetailRecordsDao.java

License:Open Source License

@Override
public void addCallDetailRecord(final CallDetailRecord cdr) {
    final SqlSession session = sessions.openSession();
    try {/*w w  w .j ava 2  s  .  c  o  m*/
        session.insert(namespace + "addCallDetailRecord", toMap(cdr));
        session.commit();
    } finally {
        session.close();
    }
}