Search in sources :

Example 6 with SqlMapClientImpl

use of com.ibatis.sqlmap.engine.impl.SqlMapClientImpl in project pinpoint by naver.

the class SqlMapClientTemplateIT method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(this.mockSqlMapExecutorDelegate.beginSessionScope()).thenReturn(this.mockSessionScope);
    this.sqlMapClient = new SqlMapClientImpl(this.mockSqlMapExecutorDelegate);
}
Also used : SqlMapClientImpl(com.ibatis.sqlmap.engine.impl.SqlMapClientImpl) Before(org.junit.Before)

Example 7 with SqlMapClientImpl

use of com.ibatis.sqlmap.engine.impl.SqlMapClientImpl in project druid by alibaba.

the class IbatisUtils method set.

public static void set(SqlMapSessionImpl session, SqlMapClientImpl client) {
    if (sessionField == null) {
        for (Field field : SqlMapSessionImpl.class.getDeclaredFields()) {
            if (field.getName().equals("session") || field.getName().equals("sessionScope")) {
                sessionField = field;
                sessionField.setAccessible(true);
                break;
            }
        }
    }
    if (sessionField != null) {
        SessionScope sessionScope;
        try {
            sessionScope = (SessionScope) sessionField.get(session);
            if (sessionScope != null) {
                if (sessionScope.getSqlMapClient() != null && sessionScope.getSqlMapClient().getClass() == SqlMapClientImpl.class) {
                    sessionScope.setSqlMapClient(client);
                }
                if (sessionScope.getSqlMapExecutor() != null && sessionScope.getSqlMapExecutor().getClass() == SqlMapClientImpl.class) {
                    sessionScope.setSqlMapExecutor(client);
                }
                if (sessionScope.getSqlMapTxMgr() != null && sessionScope.getSqlMapTxMgr().getClass() == SqlMapClientImpl.class) {
                    sessionScope.setSqlMapTxMgr(client);
                }
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
}
Also used : Field(java.lang.reflect.Field) SqlMapClientImpl(com.ibatis.sqlmap.engine.impl.SqlMapClientImpl) SessionScope(com.ibatis.sqlmap.engine.scope.SessionScope)

Example 8 with SqlMapClientImpl

use of com.ibatis.sqlmap.engine.impl.SqlMapClientImpl in project druid by alibaba.

the class SqlMapClientWrapperTest method test_wrap.

public void test_wrap() throws Exception {
    SqlMapClientImpl client = (SqlMapClientImpl) context.getBean("master-sqlMapClient");
    Assert.assertNotNull(client);
    SqlMapClientWrapper wrapper = new SqlMapClientWrapper(client);
    wrapper.insert("User.insert", new User(12345678, "aaa"));
    {
        Exception error = null;
        try {
            wrapper.insert("User.insert");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    wrapper.update("User.update", new User(12345678, "bbb"));
    {
        Exception error = null;
        try {
            wrapper.update("User.update");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    Assert.assertNotNull((User) wrapper.queryForObject("User.select"));
    Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap()));
    Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap(), new User()));
    Assert.assertEquals(1, wrapper.queryForList("User.select").size());
    Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap()).size());
    Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap(), 0, 2).size());
    wrapper.queryWithRowHandler("User.select", new RowHandler() {

        @Override
        public void handleRow(Object valueObject) {
        }
    });
    wrapper.queryWithRowHandler("User.select", Collections.emptyMap(), new RowHandler() {

        @Override
        public void handleRow(Object valueObject) {
        }
    });
    Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", 10).size());
    Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", Collections.emptyMap(), 10).size());
    Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id"));
    Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id", "name"));
    wrapper.delete("User.delete", 12345678L);
    {
        Exception error = null;
        try {
            wrapper.delete("User.delete");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    wrapper.startBatch();
    wrapper.executeBatch();
    wrapper.executeBatchDetailed();
}
Also used : RowHandler(com.ibatis.sqlmap.client.event.RowHandler) User(com.alibaba.druid.spring.User) SqlMapClientImpl(com.ibatis.sqlmap.engine.impl.SqlMapClientImpl) SqlMapClientWrapper(com.alibaba.druid.support.ibatis.SqlMapClientWrapper)

Example 9 with SqlMapClientImpl

use of com.ibatis.sqlmap.engine.impl.SqlMapClientImpl in project druid by alibaba.

the class SqlMapExecutorWrapperTest method test_wrap.

public void test_wrap() throws Exception {
    SqlMapClientImpl client = (SqlMapClientImpl) context.getBean("master-sqlMapClient");
    Assert.assertNotNull(client);
    SqlMapClientWrapper wrapper = new SqlMapClientWrapper(client);
    wrapper.getClient();
    wrapper.startTransaction();
    wrapper.endTransaction();
    wrapper.startTransaction(Connection.TRANSACTION_NONE);
    wrapper.endTransaction();
    wrapper.setUserConnection(wrapper.getUserConnection());
    wrapper.getCurrentConnection();
    wrapper.getDataSource();
    wrapper.openSession().close();
    wrapper.openSession(wrapper.getCurrentConnection()).close();
    wrapper.getSession();
    wrapper.flushDataCache();
    Exception error = null;
    try {
        wrapper.flushDataCache(null);
    } catch (Exception ex) {
        error = ex;
    }
    Assert.assertNotNull(error);
    wrapper.startTransaction();
    wrapper.commitTransaction();
    wrapper.getMappedStatement("Sequence.getValue");
    wrapper.isEnhancementEnabled();
    wrapper.isLazyLoadingEnabled();
    wrapper.getSqlExecutor();
    wrapper.getDelegate();
    wrapper.getResultObjectFactory();
}
Also used : SqlMapClientImpl(com.ibatis.sqlmap.engine.impl.SqlMapClientImpl) SqlMapClientWrapper(com.alibaba.druid.support.ibatis.SqlMapClientWrapper)

Example 10 with SqlMapClientImpl

use of com.ibatis.sqlmap.engine.impl.SqlMapClientImpl in project druid by alibaba.

the class SqlMapExecutorWrapperTest_2 method test_wrap.

public void test_wrap() throws Exception {
    SqlMapClientImpl client = (SqlMapClientImpl) context.getBean("master-sqlMapClient");
    Assert.assertNotNull(client);
    SqlMapExecutorWrapper wrapper = new SqlMapExecutorWrapper(client, client);
    wrapper.insert("User.insert", new User(12345678, "aaa"));
    {
        Exception error = null;
        try {
            wrapper.insert("User.insert");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    wrapper.update("User.update", new User(12345678, "bbb"));
    {
        Exception error = null;
        try {
            wrapper.update("User.update");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    Assert.assertNotNull((User) wrapper.queryForObject("User.select"));
    Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap()));
    Assert.assertNotNull((User) wrapper.queryForObject("User.select", Collections.emptyMap(), new User()));
    Assert.assertEquals(1, wrapper.queryForList("User.select").size());
    Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap()).size());
    Assert.assertEquals(1, wrapper.queryForList("User.select", Collections.emptyMap(), 0, 2).size());
    wrapper.queryWithRowHandler("User.select", new RowHandler() {

        @Override
        public void handleRow(Object valueObject) {
        }
    });
    wrapper.queryWithRowHandler("User.select", Collections.emptyMap(), new RowHandler() {

        @Override
        public void handleRow(Object valueObject) {
        }
    });
    Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", 10).size());
    Assert.assertEquals(1, wrapper.queryForPaginatedList("User.select", Collections.emptyMap(), 10).size());
    Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id"));
    Assert.assertNotNull(wrapper.queryForMap("User.select", Collections.emptyMap(), "id", "name"));
    wrapper.delete("User.delete", 12345678L);
    {
        Exception error = null;
        try {
            wrapper.delete("User.delete");
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }
    wrapper.startBatch();
    wrapper.executeBatch();
    wrapper.executeBatchDetailed();
}
Also used : RowHandler(com.ibatis.sqlmap.client.event.RowHandler) User(com.alibaba.druid.spring.User) SqlMapExecutorWrapper(com.alibaba.druid.support.ibatis.SqlMapExecutorWrapper) SqlMapClientImpl(com.ibatis.sqlmap.engine.impl.SqlMapClientImpl)

Aggregations

SqlMapClientImpl (com.ibatis.sqlmap.engine.impl.SqlMapClientImpl)15 SqlMapClient (com.ibatis.sqlmap.client.SqlMapClient)8 Test (org.junit.Test)8 User (com.alibaba.druid.spring.User)2 SqlMapClientWrapper (com.alibaba.druid.support.ibatis.SqlMapClientWrapper)2 RowHandler (com.ibatis.sqlmap.client.event.RowHandler)2 Before (org.junit.Before)2 SqlMapExecutorWrapper (com.alibaba.druid.support.ibatis.SqlMapExecutorWrapper)1 SqlMapSessionWrapper (com.alibaba.druid.support.ibatis.SqlMapSessionWrapper)1 SqlMapSessionImpl (com.ibatis.sqlmap.engine.impl.SqlMapSessionImpl)1 SessionScope (com.ibatis.sqlmap.engine.scope.SessionScope)1 Field (java.lang.reflect.Field)1