List of usage examples for org.apache.ibatis.session SqlSession selectOne
<T> T selectOne(String statement);
From source file:com.baidu.oped.apm.plugin.mybatis.SqlSessionTestBase.java
License:Apache License
protected final void testAndVerifySelectOne() throws Exception { // Given//from w ww. ja va 2 s .c o m final String selectOneId = "selectOneId"; SqlSession sqlSession = getSqlSession(); // When sqlSession.selectOne(selectOneId); sqlSession.selectOne(selectOneId, new Object()); // Then PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance(); Method selectOne1 = sqlSession.getClass().getDeclaredMethod("selectOne", String.class); Method selectOne2 = sqlSession.getClass().getDeclaredMethod("selectOne", String.class, Object.class); verifier.verifyTrace(event("MYBATIS", selectOne1, Expectations.cachedArgs(selectOneId))); verifier.verifyTrace(event("MYBATIS", selectOne2, Expectations.cachedArgs(selectOneId))); }
From source file:net.hasor.db.orm.mybatis3.SqlExecutorTemplate.java
License:Apache License
public <T> T selectOne(final String statement) throws SQLException { return this.execute(new SqlSessionCallback<T>() { public T doSqlSession(SqlSession sqlSession) { return sqlSession.selectOne(statement); }//from w ww . j a va 2s .co m }); }
From source file:org.activiti.engine.impl.persistence.db.DbSqlSessionFactory.java
License:Apache License
public void dbSchemaCheckVersion() { /*//from w ww . j ava 2s . co m * 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"); }
From source file:org.activiti.impl.db.Db.java
License:Apache License
public static void dbSchemaCheckVersion(SqlSessionFactory sqlSessionFactory) { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); // Not quite sure if this is the right setting? We do want multiple updates to be batched for performance ... boolean success = false; try {/*from w w w . jav a2 s. c om*/ String dbVersion = (String) sqlSession.selectOne("selectDbSchemaVersion"); 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' to value '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"); }
From source file:org.activiti.impl.persistence.IbatisPersistenceSessionFactory.java
License:Apache License
public void dbSchemaCheckVersion() { /*/*from w ww.java2 s.c o m*/ * 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 dbVersion = (String) sqlSession.selectOne(statement("selectDbSchemaVersion")); 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"); }
From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisInstanceIdDao.java
License:Open Source License
@Override public InstanceId getInstanceId() { final SqlSession session = sessions.openSession(); try {/*from w ww .j a va2 s . com*/ final Map<String, Object> result = session.selectOne(namespace + "getInstanceId"); if (result != null) { return toInstanceId(result); } else { return null; } } finally { session.close(); } }
From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisStatisticsDao.java
License:Open Source License
@Override public StatisticsTotalCallsLast24Hours getTotalCallsLast24Hours() { final SqlSession session = sessions.openSession(); try {// ww w. j ava2 s . co m final String result = session.selectOne(namespace + "Totalcallslast24hours"); StatisticsTotalCallsLast24Hours statistics = new StatisticsTotalCallsLast24Hours(result); if (result != null) { statistics = new StatisticsTotalCallsLast24Hours(result); } return statistics; } finally { session.close(); } }
From source file:org.mobicents.servlet.restcomm.dao.mybatis.MybatisStatisticsDao.java
License:Open Source License
@Override public StatisticsTotalSMSLast24Hours getTotalSMSLast24Hours() { final SqlSession session = sessions.openSession(); try {//from w w w. jav a 2 s .com final String result = session.selectOne(namespace + "Totalsmslast24hours"); StatisticsTotalSMSLast24Hours statistics = new StatisticsTotalSMSLast24Hours(result); if (result != null) { statistics = new StatisticsTotalSMSLast24Hours(result); } return statistics; } finally { session.close(); } }
From source file:pecosa.daoImpl.TemporalDaoImpl.java
@Override public Integer getLote() { Integer idlote = null;//from w w w .j a v a 2 s.c om SqlSession session = sqlSessionFactory.openSession(); try { idlote = session.selectOne("VistaData.getLote"); } catch (Exception e) { System.out.println(e.getMessage()); System.out.println("ERROR EN Confirmados.getLote"); } finally { session.close(); } return idlote; }
From source file:zll.MybatisTest.java
public static void main(String args[]) throws IOException { SqlSessionFactory sqlSessionFactory = MybatisUtil.getSessionFactory(); SqlSession session = sqlSessionFactory.openSession(); try {//from w ww . jav a2s. c o m // do work Customer c = session.selectOne("Customer.list"); if (c == null) { System.out.print("empty"); } else { System.out.print("not empty"); System.out.println(c.getName()); } session.commit(); } finally { session.close(); } }