List of usage examples for org.apache.ibatis.session SqlSession update
int update(String statement, Object parameter);
From source file:org.activiti.test.db.ProcessEngineInitializationTest.java
License:Apache License
@Test public void testVersionMismatch() { // first create the schema ProcessEngineImpl processEngine = (ProcessEngineImpl) new DbProcessEngineBuilder() .configureFromPropertiesResource("org/activiti/test/db/activiti.properties") .setDbSchemaStrategy(DbSchemaStrategy.CREATE_DROP).buildProcessEngine(); // then update the version to something that is different to the library // version// w ww .j a v a 2s. c o m PersistenceSessionFactory persistenceSessionFactory = processEngine.getPersistenceSessionFactory(); SqlSessionFactory sqlSessionFactory = ((IbatisPersistenceSessionFactory) persistenceSessionFactory) .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", new Integer(1)); parameters.put("newRevision", new Integer(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(true); } else { sqlSession.rollback(true); } sqlSession.close(); } exception.expect(ActivitiWrongDbException.class); exception.expect(new TypeSafeMatcher<ActivitiWrongDbException>() { @Override public boolean matchesSafely(ActivitiWrongDbException e) { return e.getMessage().contains("version mismatch") && "25.7".equals(e.getDbVersion()) && ProcessEngine.VERSION == e.getLibraryVersion(); } public void describeTo(Description description) { description.appendText("'version mismatch' with dbVersion=25.7 and libraryVersion=") .appendValue(ProcessEngine.VERSION); } }); // now we can see what happens if when a process engine is being // build with a version mismatch between library and db tables new DbProcessEngineBuilder().configureFromPropertiesResource("org/activiti/test/db/activiti.properties") .setDbSchemaStrategy(DbSchemaStrategy.CHECK_VERSION).buildProcessEngine(); // closing the original process engine to drop the db tables processEngine.close(); }
From source file:org.activiti5.standalone.initialization.ProcessEngineInitializationTest.java
License:Apache License
public void testVersionMismatch() { // first create the schema ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngineConfiguration .createProcessEngineConfigurationFromResource( "org/activiti5/standalone/initialization/notables.activiti.cfg.xml") .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP) .buildProcessEngine();/* w w w. j a v a 2 s.c o m*/ // 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/activiti5/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(); }
From source file:org.apache.camel.component.mybatis.DefaultMyBatisProcessingStrategy.java
License:Apache License
public void commit(MyBatisEndpoint endpoint, Exchange exchange, Object data, String consumeStatements) throws Exception { SqlSession session = endpoint.getSqlSessionFactory().openSession(); String[] statements = consumeStatements.split(","); try {/*ww w . j ava2s . c o m*/ for (String statement : statements) { session.update(statement.trim(), data); } session.commit(); } catch (Exception e) { session.rollback(); throw e; } finally { session.close(); } }
From source file:org.apache.camel.component.mybatis.MyBatisProducer.java
License:Apache License
private void doUpdate(Exchange exchange, SqlSession session) throws Exception { Object result;//from w ww . j a v a 2 s .c om Object in = exchange.getIn().getBody(); if (in != null) { // lets handle arrays or collections of objects Iterator<?> iter = ObjectHelper.createIterator(in); while (iter.hasNext()) { Object value = iter.next(); LOG.trace("Updating: {} using statement: {}", value, statement); result = session.update(statement, value); doProcessResult(exchange, result); } } else { LOG.trace("Updating using statement: {}", statement); result = session.update(statement); doProcessResult(exchange, result); } }
From source file:org.apache.camel.component.mybatis.MyBatisProducer.java
License:Apache License
private void doUpdateList(Exchange exchange, SqlSession session) throws Exception { Object result;/*from w w w . j av a 2 s . com*/ Object in = exchange.getIn().getBody(); if (in != null) { // just pass in the body as Object and allow MyBatis to iterate using its own foreach statement LOG.trace("Updating: {} using statement: {}", in, statement); result = session.update(statement, in); doProcessResult(exchange, result); } else { LOG.trace("Updating using statement: {}", statement); result = session.update(statement); doProcessResult(exchange, result); } }
From source file:org.camunda.bpm.engine.test.standalone.initialization.ProcessEngineInitializationTest.java
License:Apache License
public void testVersionMismatch() { // first create the schema ProcessEngineImpl processEngine = (ProcessEngineImpl) ProcessEngineConfiguration .createProcessEngineConfigurationFromResource( "org/camunda/bpm/engine/test/standalone/initialization/notables.camunda.cfg.xml") .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_CREATE_DROP) .buildProcessEngine();/*w w w . j a va 2s. c o m*/ // 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", new Integer(1)); parameters.put("newRevision", new Integer(2)); sqlSession.update("updateProperty", parameters); success = true; } catch (Exception e) { throw new ProcessEngineException("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/camunda/bpm/engine/test/standalone/initialization/notables.camunda.cfg.xml") .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE) .buildProcessEngine(); fail("expected exception"); } catch (WrongDbException 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.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 o m*/ // 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
private void updateAccount(final String selector, final Account account) { final SqlSession session = sessions.openSession(); try {/*from w ww. j a v a2s .c o m*/ 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 updateApplication(final Application application) { final SqlSession session = sessions.openSession(); try {//ww w .j a v a 2s. c o m session.update(namespace + "updateApplication", toMap(application)); session.commit(); } finally { session.close(); } }
From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisCallDetailRecordsDao.java
License:Open Source License
@Override public void updateCallDetailRecord(final CallDetailRecord cdr) { final SqlSession session = sessions.openSession(); try {/*from w ww .ja v a 2s.c o m*/ session.update(namespace + "updateCallDetailRecord", toMap(cdr)); session.commit(); } finally { session.close(); } }