Search in sources :

Example 56 with SqlSession

use of org.apache.ibatis.session.SqlSession in project camunda-bpm-platform by camunda.

the class TransactionIsolationLevelTest method testTransactionIsolationLevelOnConnection.

@Test
public void testTransactionIsolationLevelOnConnection() {
    ProcessEngineConfigurationImpl processEngineConfiguration = (ProcessEngineConfigurationImpl) processEngine.getProcessEngineConfiguration();
    SqlSession sqlSession = processEngineConfiguration.getDbSqlSessionFactory().getSqlSessionFactory().openSession();
    try {
        int transactionIsolation = sqlSession.getConnection().getTransactionIsolation();
        assertEquals("TransactionIsolationLevel for connection is " + transactionIsolation + " instead of " + Connection.TRANSACTION_READ_COMMITTED, Connection.TRANSACTION_READ_COMMITTED, transactionIsolation);
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SQLException(java.sql.SQLException) ProcessEngineConfigurationImpl(org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl) Test(org.junit.Test) AbstractFoxPlatformIntegrationTest(org.camunda.bpm.integrationtest.util.AbstractFoxPlatformIntegrationTest)

Example 57 with SqlSession

use of org.apache.ibatis.session.SqlSession in project pinpoint by naver.

the class SqlSessionTestBase method testAndVerifySelectList.

protected final void testAndVerifySelectList() throws Exception {
    // Given
    final String selectListId = "selectListId";
    SqlSession sqlSession = getSqlSession();
    // When
    sqlSession.selectList(selectListId);
    sqlSession.selectList(selectListId, new Object());
    sqlSession.selectList(selectListId, new Object(), RowBounds.DEFAULT);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method selectList1 = sqlSession.getClass().getDeclaredMethod("selectList", String.class);
    Method selectList2 = sqlSession.getClass().getDeclaredMethod("selectList", String.class, Object.class);
    Method selectList3 = sqlSession.getClass().getDeclaredMethod("selectList", String.class, Object.class, RowBounds.class);
    verifier.verifyTrace(event("MYBATIS", selectList1, Expectations.cachedArgs(selectListId)));
    verifier.verifyTrace(event("MYBATIS", selectList2, Expectations.cachedArgs(selectListId)));
    verifier.verifyTrace(event("MYBATIS", selectList3, Expectations.cachedArgs(selectListId)));
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)

Example 58 with SqlSession

use of org.apache.ibatis.session.SqlSession in project pinpoint by naver.

the class SqlSessionTestBase method testAndVerifySelectMap.

protected final void testAndVerifySelectMap() throws Exception {
    // Given
    final String selectMapId = "selectListId";
    SqlSession sqlSession = getSqlSession();
    // When
    sqlSession.selectMap(selectMapId, "key");
    sqlSession.selectMap(selectMapId, new Object(), "key");
    sqlSession.selectMap(selectMapId, new Object(), "key", RowBounds.DEFAULT);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method selectMap1 = sqlSession.getClass().getDeclaredMethod("selectMap", String.class, String.class);
    Method selectMap2 = sqlSession.getClass().getDeclaredMethod("selectMap", String.class, Object.class, String.class);
    Method selectMap3 = sqlSession.getClass().getDeclaredMethod("selectMap", String.class, Object.class, String.class, RowBounds.class);
    verifier.verifyTrace(event("MYBATIS", selectMap1, Expectations.cachedArgs(selectMapId)));
    verifier.verifyTrace(event("MYBATIS", selectMap2, Expectations.cachedArgs(selectMapId)));
    verifier.verifyTrace(event("MYBATIS", selectMap3, Expectations.cachedArgs(selectMapId)));
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)

Example 59 with SqlSession

use of org.apache.ibatis.session.SqlSession in project pinpoint by naver.

the class SqlSessionTestBase method testAndVerifySelectOne.

protected final void testAndVerifySelectOne() throws Exception {
    // Given
    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)));
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)

Example 60 with SqlSession

use of org.apache.ibatis.session.SqlSession in project generator by mybatis.

the class ConditionalJava5Test method testPKFieldsSelectByExampleEscapedFields.

@Test
public void testPKFieldsSelectByExampleEscapedFields() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PkfieldsMapper mapper = sqlSession.getMapper(PkfieldsMapper.class);
        Pkfields record = new Pkfields();
        record.setFirstname("Fred");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(1);
        record.setWierdField(11);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Wilma");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(2);
        record.setWierdField(22);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Pebbles");
        record.setLastname("Flintstone");
        record.setId1(1);
        record.setId2(3);
        record.setWierdField(33);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Barney");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(1);
        record.setWierdField(44);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Betty");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(2);
        record.setWierdField(55);
        mapper.insert(record);
        record = new Pkfields();
        record.setFirstname("Bamm Bamm");
        record.setLastname("Rubble");
        record.setId1(2);
        record.setId2(3);
        record.setWierdField(66);
        mapper.insert(record);
        List<Integer> values = new ArrayList<>();
        values.add(11);
        values.add(22);
        PkfieldsExample example = new PkfieldsExample();
        example.createCriteria().andWierdFieldLessThan(40).andWierdFieldIn(values);
        example.setOrderByClause("ID1, ID2");
        List<Pkfields> answer = mapper.selectByExample(example);
        assertEquals(2, answer.size());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) PkfieldsMapper(mbg.test.mb3.generated.annotated.conditional.mapper.PkfieldsMapper) ArrayList(java.util.ArrayList) Pkfields(mbg.test.mb3.generated.annotated.conditional.model.Pkfields) PkfieldsExample(mbg.test.mb3.generated.annotated.conditional.model.PkfieldsExample) Test(org.junit.jupiter.api.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)2117 Test (org.junit.jupiter.api.Test)1845 BaseDataTest (org.apache.ibatis.BaseDataTest)593 Test (org.junit.Test)127 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)104 Reader (java.io.Reader)97 User (com.github.pagehelper.model.User)87 ArrayList (java.util.ArrayList)84 UserMapper (com.github.pagehelper.mapper.UserMapper)75 Connection (java.sql.Connection)68 FirstName (mbg.test.common.FirstName)60 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)60 HashMap (java.util.HashMap)59 BeforeClass (org.junit.BeforeClass)56 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)54 RowBounds (org.apache.ibatis.session.RowBounds)36 Map (java.util.Map)34 Date (java.util.Date)33 List (java.util.List)24 AwfulTableMapper (mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper)23