List of usage examples for org.apache.ibatis.session SqlSession commit
void commit();
From source file:net.nexxus.db.DBManagerImpl.java
License:Open Source License
/** * add an NntpGroup to our groups list//w w w. j av a2s . co m */ public void addServer(NntpServer server) throws Exception { HashMap map = new HashMap(); map.put("table", serverTable); map.put("server", server.getServer()); map.put("port", server.getPort()); map.put("username", server.getUsername()); map.put("password", server.getPassword()); SqlSession session = sqlFactory.openSession(); session.insert("addServer", map); session.commit(); session.close(); }
From source file:net.nexxus.db.DBManagerImpl.java
License:Open Source License
/** * remove an NntpServer from our groups list *//* ww w .jav a 2 s.co m*/ public void removeServer(NntpServer server) throws Exception { HashMap<String, String> map = new HashMap<String, String>(); map.put("table", serverTable); map.put("server", server.getServer()); SqlSession session = sqlFactory.openSession(); session.insert("removeServer", map); session.commit(); session.close(); }
From source file:org.activiti.standalone.initialization.ProcessEngineInitializationTest.java
License:Apache License
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();//from www . j av a2 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 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(); }
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();/*from w w w.j av a2 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 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 {//from w w w .ja v a 2 s . com 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.DefaultMyBatisProcessingStrategy.java
License:Apache License
public List<?> poll(MyBatisConsumer consumer, MyBatisEndpoint endpoint) throws Exception { SqlSession session = endpoint.getSqlSessionFactory().openSession(); try {/* w w w. j av a 2 s. c om*/ List<Object> objects = session.selectList(endpoint.getStatement(), null); session.commit(); return objects; } catch (Exception e) { session.rollback(); throw e; } finally { session.close(); } }
From source file:org.apache.camel.component.mybatis.MyBatisProducer.java
License:Apache License
public void process(Exchange exchange) throws Exception { SqlSession session; ExecutorType executorType = endpoint.getExecutorType(); if (executorType == null) { session = endpoint.getSqlSessionFactory().openSession(); } else {//from w ww. j av a 2 s . c o m session = endpoint.getSqlSessionFactory().openSession(executorType); } try { switch (endpoint.getStatementType()) { case SelectOne: doSelectOne(exchange, session); break; case SelectList: doSelectList(exchange, session); break; case Insert: doInsert(exchange, session); break; case InsertList: doInsertList(exchange, session); break; case Update: doUpdate(exchange, session); break; case UpdateList: doUpdateList(exchange, session); break; case Delete: doDelete(exchange, session); break; case DeleteList: doDeleteList(exchange, session); break; default: throw new IllegalArgumentException("Unsupported statementType: " + endpoint.getStatementType()); } // flush the batch statements and commit the database connection session.commit(); } catch (Exception e) { // discard the pending batch statements and roll the database connection back session.rollback(); throw e; } finally { // and finally close the session as we're done session.close(); } }
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();//from w w w. ja 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", 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.codehaus.griffon.runtime.mybatis.DefaultMybatisHandler.java
License:Apache License
@Nullable @Override/*from w ww . ja v a 2 s .com*/ public <R> R withSqlSession(@Nonnull String sessionFactoryName, @Nonnull MybatisCallback<R> callback) throws RuntimeMybatisException { requireNonBlank(sessionFactoryName, ERROR_SQLSESSION_BLANK); requireNonNull(callback, ERROR_CALLBACK_NULL); SqlSession session = getSqlSession(sessionFactoryName); try { LOG.debug("Executing statements on mybatis '{}'", sessionFactoryName); return callback.handle(sessionFactoryName, session); } catch (Exception e) { throw new RuntimeMybatisException(sessionFactoryName, e); } finally { session.commit(); session.close(); } }
From source file:org.fbi.fskfq.processor.T4013Processor.java
private void processTxn(CbsTia4013 cbsTia, Stdp10ProcessorRequest request, TpsToaXmlBean tpsToa, Stdp10ProcessorResponse response) { FsKfqPaymentInfo paymentInfo;/* w w w. j a v a 2 s .co m*/ SqlSessionFactory sqlSessionFactory = MybatisFactory.ORACLE.getInstance(); SqlSession session = sqlSessionFactory.openSession(); String orignResult = tpsToa.getMaininfoMap().get("RESULT"); boolean updateFlag = false; try { // if ("1457101".equals(orignResult)) { paymentInfo = selectNotCanceledPaymentInfoFromDB(cbsTia.getBillNo()); if (paymentInfo != null) { updateFlag = true; } else { paymentInfo = new FsKfqPaymentInfo(); FbiBeanUtils.copyProperties(cbsTia, paymentInfo); Map<String, String> toaMap = tpsToa.getMaininfoMap(); paymentInfo.setChrId(toaMap.get("CHR_ID")); paymentInfo.setBilltypeCode(toaMap.get("BILLTYPE_CODE")); paymentInfo.setBilltypeName(toaMap.get("BILLTYPE_NAME")); // 2457 cbstia, // paymentInfo.setVerifyNo(toaMap.get("VERIFY_NO")); paymentInfo.setVerifyNo(cbsTia.getVerifyNo()); paymentInfo.setMakedate(toaMap.get("MAKEDATE")); paymentInfo.setIenCode(toaMap.get("IEN_CODE")); paymentInfo.setIenName(toaMap.get("IEN_NAME")); paymentInfo.setSetYear(toaMap.get("SET_YEAR")); //TODO BankIndateincomingstatuspm_code Date date = null; try { date = new SimpleDateFormat("yyyyMMddHHmmss").parse(request.getHeader("txnTime")); } catch (ParseException e) { e.printStackTrace(); } paymentInfo.setBankIndate(new SimpleDateFormat("yyyy-MM-dd").format(date)); paymentInfo.setBusinessId(request.getHeader("serialNo")); paymentInfo.setOperPayBankid(request.getHeader("branchId")); paymentInfo.setOperPayTlrid(request.getHeader("tellerId")); paymentInfo.setOperPayDate(new SimpleDateFormat("yyyyMMdd").format(new Date())); paymentInfo.setOperPayTime(new SimpleDateFormat("HHmmss").format(new Date())); paymentInfo.setOperPayHostsn(request.getHeader("serialNo")); paymentInfo.setManualFlag("1"); // paymentInfo.setArchiveFlag("0"); paymentInfo.setPkid(UUID.randomUUID().toString()); } // TODO 2402 - 20141231 TpsTia2402 tpstia = new TpsTia2402(); TpsTia2402.BodyRecord record = ((TpsTia2402.Body) tpstia.getBody()).getObject().getRecord(); // TODO BEAN 2402Bean FbiBeanUtils.copyProperties(cbsTia, record, true); record.setChr_id(paymentInfo.getChrId()); record.setBank_indate(paymentInfo.getBankIndate()); record.setIncomestatus(paymentInfo.getIncomestatus()); record.setRoute_user_code(paymentInfo.getRouteUserCode()); record.setBusiness_id(paymentInfo.getBusinessId()); record.setLicense(paymentInfo.getLicense()); record.setIncomestatus("5"); generateTpsBizMsgHeader(tpstia, "2402", request); tpstia.getHeader().setMsgRef(request.getHeader("serialNo") + "9"); tpstia.getHeader().setMsgId(request.getHeader("txnTime") + request.getHeader("serialNo") + "9"); // TpsToaXmlBean tps2402Toa = new TpsToaXmlBean(); byte[] sendTpsBuf = new byte[0]; try { sendTpsBuf = generateTpsTxMsgHeader(tpstia, request); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String dataType = tpstia.getHeader().getDataType(); byte[] recvTpsBuf = new byte[0]; try { recvTpsBuf = processThirdPartyServer(sendTpsBuf, dataType); } catch (Exception e) { e.printStackTrace(); } String recvTpsMsg = null; try { recvTpsMsg = new String(recvTpsBuf, "GBK"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String rtnDataType = substr(recvTpsMsg, "<dataType>", "</dataType>").trim(); if ("9910".equals(rtnDataType)) { // 9910 TpsToa9910 tpsToa9910 = transXmlToBeanForTps9910(recvTpsBuf); String errType = tpsToa9910.Body.Object.Record.result; String errMsg = tpsToa9910.Body.Object.Record.add_word; if (StringUtils.isEmpty(errMsg)) errMsg = ":"; else errMsg = ":" + errMsg; marshalAbnormalCbsResponse(TxnRtnCode.TXN_EXECUTE_FAILED, errMsg, response); logger.info("===()\n" + tpsToa9910.toString()); throw new RuntimeException(errMsg); } else { // 1402 tpsToa = transXmlToBeanForTps(recvTpsBuf); if (tpsToa == null) { // throw new RuntimeException(""); } String result = tpsToa.getMaininfoMap().get("RESULT"); if (result != null) { // TpsToa9000 tpsToa9000 = new TpsToa9000(); FbiBeanUtils.copyProperties(tpsToa.getMaininfoMap(), tpsToa9000, true); marshalAbnormalCbsResponse(TxnRtnCode.TXN_EXECUTE_FAILED, tpsToa9000.getAddWord(), response); } else { String rtnStatus = tpsToa.getMaininfoMap().get("SUCC_CODE"); String chr_id = tpsToa.getMaininfoMap().get("CHR_ID"); String bill_no = tpsToa.getMaininfoMap().get("BILL_NO"); // 2014-12-23 40132457 paymentInfo.setHostBookFlag("0"); paymentInfo.setHostChkFlag("0"); paymentInfo.setFbBookFlag("0"); paymentInfo.setFbChkFlag("0"); // paymentInfo.setAreaCode("KaiFaQu-FeiShui"); //20150105 paymentInfo.setAreaCode(cbsTia.getAreaCode()); paymentInfo.setHostAckFlag("0"); paymentInfo.setLnkBillStatus(BillStatus.INIT.getCode()); // FsKfqPaymentInfoMapper infoMapper = session.getMapper(FsKfqPaymentInfoMapper.class); if (!paymentInfo.getChrId().equals(chr_id) || !paymentInfo.getBillNo().equals(bill_no)) { marshalAbnormalCbsResponse(TxnRtnCode.TXN_EXECUTE_FAILED, "", response); } else { if (!"OK".equals(rtnStatus)) { marshalAbnormalCbsResponse(TxnRtnCode.TXN_EXECUTE_FAILED, rtnStatus, response); } else { // // 20141231 ccblinking paymentInfo.setHostBookFlag("1"); paymentInfo.setHostChkFlag("0"); paymentInfo.setFbBookFlag("1"); paymentInfo.setFbChkFlag("0"); // paymentInfo.setAreaCode("KaiFaQu-FeiShui"); //20150105 paymentInfo.setAreaCode(cbsTia.getAreaCode()); paymentInfo.setHostAckFlag("0"); paymentInfo.setLnkBillStatus(BillStatus.PAYOFF.getCode()); // marshalSuccessTxnCbsResponse(response); if ("1457101".equals(orignResult) || updateFlag) { // infoMapper.updateByPrimaryKey(paymentInfo); } } if (!updateFlag) { infoMapper.insert(paymentInfo); //Items FsKfqPaymentItemMapper itemMapper = session.getMapper(FsKfqPaymentItemMapper.class); for (CbsTia4013Item cbsTia4013Item : cbsTia.getItems()) { FsKfqPaymentItem item = new FsKfqPaymentItem(); FbiBeanUtils.copyProperties(cbsTia4013Item, item); item.setMainPkid(paymentInfo.getPkid()); itemMapper.insert(item); } } } } // TODO----------- session.commit(); } } finally { session.close(); } }