List of usage examples for org.apache.ibatis.session SqlSession commit
void commit(boolean force);
From source file:com.ehensin.paypal.account.repository.AccountRepository.java
License:Apache License
public void addCustomerAccount(CustomerAccountEntity entity) throws Exception { String dbRepName = entityDBRepNameMap.get(CustomerAccountEntity.class); SplitFactor factor = new SplitFactor(SplitAlg.Hash, entity.getUuid()); SqlSessionFactory factory = dbRepository.getSessionFactory(dbRepName, factor, true); SqlSession session = factory.openSession(); try {/*w ww . j a va 2s. co m*/ AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); CustomerAccountORMapping orm = new CustomerAccountORMapping(entity.getUuid(), entity.getPhone(), entity.getLoginName(), entity.getMail(), entity.getPassword(), entity.getStatus(), entity.getBalance1(), entity.getBalance2(), entity.getBalance3(), entity.getBalance4(), entity.getBalance5(), entity.getLastUpdateTime()); mapper.insert(orm); session.commit(true); } catch (PersistenceException e) { logger.error(e.getMessage(), e); throw e; } finally { session.close(); } }
From source file:com.ehensin.paypal.account.test.CustomerAccountTest.java
License:Apache License
@Test public void testInsert() throws Exception { DBRepositoryBuilder builder = new DBRepositoryBuilder(); DBRepository repository = builder.build(new String[] { "com.ehensin.paypal.account.service" }); SplitFactor factor = new SplitFactor(SplitAlg.Hash, 1); SqlSessionFactory factory = repository.getSessionFactory("account", factor, true); SqlSession session = factory.openSession(); AccountMapper mapper = (AccountMapper) session.getMapper(AccountMapper.class); int count = mapper.getCount(); System.out.println("hash customer count : " + count); CustomerAccountORMapping orm = new CustomerAccountORMapping(); orm.setBalance1(0);//w w w. jav a2 s.c o m orm.setBalance2(0); orm.setLastUpdateTime(new Timestamp(System.currentTimeMillis())); orm.setLoginName("hhb"); orm.setMail("huanghaibo@newcosoft.com"); orm.setPhone("13917310925"); orm.setStatus(0); orm.setUuid("123"); orm.setPassword("123456"); mapper.insert(orm); count = mapper.getCount(); System.out.println("hash customer count : " + count); session.commit(true); session.close(); }
From source file:com.oneops.cms.transmitter.BaseEventReader.java
License:Apache License
public List<CMSEvent> getEvents() { SqlSession session = null; List<CMSEvent> cmsEvents = new ArrayList<>(); try {//from w ww . ja v a2 s .com session = sqlsf.openSession(); EventMapper eventMapper = session.getMapper(EventMapper.class); if (!eventMapper.good2run(getLockName(), processId, PROCESS_TIMEOUT_SECONDS)) { if (iamActiveProcess == null || iamActiveProcess) { logger.info(">>>>>>>>>Other process has a lock " + getLockName() + ", will wait"); iamActiveProcess = false; } session.commit(true); return cmsEvents; } else { if (iamActiveProcess == null || !iamActiveProcess) { logger.info(">>>>>>>>>Acquired lock " + getLockName() + ", I'm the active process now"); iamActiveProcess = true; } session.commit(true); } if (isCmsPubActive()) { for (CMSEventRecord record : getEvents(eventMapper)) { CMSEvent event = populateEvent(record); if (event != null) { cmsEvents.add(event); } } } } catch (Exception e) { if (e instanceof PersistenceException) { logger.error("Problem connecting to the postgres db, I will try reconnect..."); logger.error(e.getMessage()); } else { e.printStackTrace(); throw new RuntimeException(e); } } finally { if (session != null) { session.close(); } } return cmsEvents; }
From source file:com.tianjunwei.lazy.LazyMain.java
License:Apache License
public static void main(String[] args) { //mybatis?/*from www . j a v a2 s .co m*/ String resource = "learn/mybatis-config.xml"; InputStream is = LazyMain.class.getClassLoader().getResourceAsStream(resource); //sqlSession SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is); SqlSession session = sessionFactory.openSession(); String statement = "com.tianjunwei.lazy.entity.User.getById";//sql //usersql User user = session.selectOne(statement, 1); session.commit(true); System.out.println(user.getNames()); //Teacher teacher = user.getTeacher(); //System.err.println(teacher.getName()); }
From source file:com.tianjunwei.lazy.LazyMainTeacher.java
License:Apache License
public static void main(String[] args) throws IOException { //mybatis?//from ww w . ja v a 2 s . c o m String resource = "learn/mybatis-config.xml"; InputStream is = LazyMainTeacher.class.getClassLoader().getResourceAsStream(resource); //sqlSession SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is); SqlSession session = sessionFactory.openSession(); String statement = "com.tianjunwei.lazy.entity.Teacher.getTeacher";//sql //usersql Teacher teacher = (Teacher) session.selectList(statement, 1).get(0); session.commit(true); System.out.println(teacher.getName()); List<User> users = teacher.getUsers(); System.err.println(users.get(3).getAge()); System.err.println(teacher.getClass()); System.in.read(); }
From source file:com.tianjunwei.lazy.LazyUser.java
License:Apache License
public static void main(String[] args) { //mybatis?//from ww w. j av a 2s. com String resource = "learn/mybatis-config.xml"; InputStream is = LazyUser.class.getClassLoader().getResourceAsStream(resource); //sqlSession SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(is); SqlSession session = sessionFactory.openSession(); String statement = "com.tianjunwei.lazy.entity.Users.getUser";//sql //usersql User user = session.selectOne(statement, 1); session.commit(true); System.out.println(user.getNames()); Teacher teacher = user.getTeacher(); System.err.println(teacher.getName()); }
From source file:net.cbtltd.rest.mybookingpal.A_Handler.java
License:Open Source License
@Override public void readSchedule() { LOG.debug("readSchedule"); long lStartTime = System.currentTimeMillis(); String filename = "reserveddates"; String ROOT_ELEMENT = "products"; BufferedWriter bw = createXMLFile(filename); writeOpeningXML(ROOT_ELEMENT, bw);/*www . j ava 2 s .co m*/ ReservationFeedGenerator reservationfeedgenerator = null; reservationfeedgenerator = reservationfeedgenerator.getInstance(); final SqlSession sqlSession = RazorServer.openSession(); ArrayList<String> productidlist = sqlSession.getMapper(ProductMapper.class).activeproductid(); Reservation reservation = new Reservation(); Calendar date = Calendar.getInstance(); date.setTime(new Date()); reservation.setFromdate(date.getTime()); date.add(Calendar.YEAR, 1); reservation.setTodate(date.getTime()); XStream xstream = new XStream(); xstream.processAnnotations(net.cbtltd.rest.mybookingpal.ProductSchedule.class); try { for (int i = 0; i < productidlist.size(); i++) { reservation.setProductid(productidlist.get(i)); bw.write( xstream.toXML(reservationfeedgenerator.generatScheduleForProduct(reservation, sqlSession))); } } catch (IOException e) { LOG.error(e.getMessage()); ; } finally { writeClosingXML(ROOT_ELEMENT, bw); sqlSession.commit(false); sqlSession.close(); } System.out.println("Elapsed seconds: " + (System.currentTimeMillis() - lStartTime) / 1000.0); }
From source file:net.cbtltd.rest.mybookingpal.A_Handler.java
License:Open Source License
public void writeSummaryInformation() { long lStartTime = System.currentTimeMillis(); String toplevelelement = "products"; BufferedWriter bw = createXMLFile("summaryinformation"); writeOpeningXML(toplevelelement, bw); LOG.debug("Started_writeSummaryInformation :" + new Date()); productFeedGenerator = productFeedGenerator.getInstance(); final SqlSession sqlSession = RazorServer.openSession(); ArrayList<String> productidlist = getActivePropertyList(); XStream xstream = new XStream(); xstream.autodetectAnnotations(true); xstream.processAnnotations(net.cbtltd.rest.Ratings.class); xstream.processAnnotations(net.cbtltd.rest.Property.class); xstream.alias("property", net.cbtltd.rest.Property.class); xstream.processAnnotations(net.cbtltd.rest.Values.class); xstream.processAnnotations(net.cbtltd.rest.Attributes.class); xstream.omitField(net.cbtltd.shared.ModelTable.class, "numrows"); xstream.omitField(net.cbtltd.shared.ModelTable.class, "startrow"); xstream.omitField(net.cbtltd.shared.Model.class, "status"); xstream.processAnnotations(net.cbtltd.shared.NameIdAction.class); try {/*from w w w . j a va 2 s .co m*/ for (int i = 0; i < productidlist.size(); i++) { LOG.debug("Count = " + i + " ProductID =" + productidlist.get(i)); //bw.write(xstream.toXML(productFeedGenerator.generatPropertySummary(productidlist.get(i), POS,sqlSession))); String xml = xstream.toXML( productFeedGenerator.generatPropertySummary(productidlist.get(i), "POS", sqlSession)); System.out.println(xml); if (i > 0 && i % IsPartner.PRICE_BATCH_SIZE == 0) { sqlSession.commit(false); } } } catch (Throwable e) { LOG.equals(e.getMessage()); } writeClosingXML(toplevelelement, bw); System.out.println("Elapsed seconds: " + (System.currentTimeMillis() - lStartTime) / 1000.0); }
From source file:net.cbtltd.rest.mybookingpal.A_Handler.java
License:Open Source License
public void writePriceList() { int countnonblankelement = 0; long lStartTime = System.currentTimeMillis(); int pagenumber = 0; String filename = "pricelist_"; PriceList productpricelist;/*from w ww.j ava 2s. c om*/ String ROOT_ELEMENT = "pricelists"; LOG.debug("writePriceList"); BufferedWriter bw = createXMLFile(filename + pagenumber); // add page // number. writeOpeningXML(ROOT_ELEMENT, bw); XStream xstream = new XStream(); xstream.processAnnotations(net.cbtltd.rest.PriceList.class); final SqlSession sqlSession = RazorServer.openSession(); ArrayList<String> productidlist = getActivePropertyList(); productFeedGenerator = productFeedGenerator.getInstance(); try { for (int i = 0; i < productidlist.size(); i++) { // for (int i = 0; i < 10; i++) { LOG.debug("PropertyID:" + productidlist.get(i)); productpricelist = productFeedGenerator.generatePriceList(productidlist.get(i), "POS", sqlSession); if (productpricelist.prices != null) { bw.write(xstream.toXML(productpricelist)); countnonblankelement++; } if (i % IsPartner.PRICE_BATCH_SIZE == 0) { sqlSession.commit(false); } if (countnonblankelement % NUMBER_PRODUCT_PER_PAGE == 0 & countnonblankelement != 0) {//(i % NUMBER_PRODUCT_PER_PAGE == 0 & i != 0) { pagenumber++; bw = openNewXMLFile(ROOT_ELEMENT, filename + pagenumber, bw); } } } catch (IOException e) { LOG.error(e.getMessage()); ; } finally { writeClosingXML(ROOT_ELEMENT, bw); sqlSession.commit(false); sqlSession.close(); } System.out.println("Elapsed seconds: " + (System.currentTimeMillis() - lStartTime) / 1000.0); }
From source file:org.activiti.engine.impl.persistence.db.DbSqlSessionFactory.java
License:Apache License
public void dbSchemaCheckVersion() { /*/*from www . j a v a2 s . com*/ * Not quite sure if this is the right setting? We do want multiple updates * to be batched for performance ... */ SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); boolean success = false; try { String selectSchemaVersionStatement = mapStatement("selectDbSchemaVersion"); String dbVersion = (String) sqlSession.selectOne(selectSchemaVersionStatement); if (!ProcessEngine.VERSION.equals(dbVersion)) { throw new ActivitiWrongDbException(ProcessEngine.VERSION, dbVersion); } success = true; } catch (Exception e) { String exceptionMessage = e.getMessage(); if ((exceptionMessage.indexOf("Table") != -1) && (exceptionMessage.indexOf("not found") != -1)) { throw new ActivitiException( "no activiti tables in db. set property db.schema.strategy=create-drop in activiti.properties for automatic schema creation", e); } else { if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new ActivitiException("couldn't get db schema version", e); } } } finally { if (success) { sqlSession.commit(true); } else { sqlSession.rollback(true); } sqlSession.close(); } log.fine("activiti db schema check successful"); }