org.springframework.orm.ibatis.SqlMapClientTemplate Java Examples

The following examples show how to use org.springframework.orm.ibatis.SqlMapClientTemplate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SqlMapClientTemplateIT.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void deleteShouldBeTraced() throws Exception {
    // Given
    final String deleteId = "deleteId";
    SqlMapClientTemplate clientTemplate = new SqlMapClientTemplate(this.mockDataSource, this.sqlMapClient);
    // When
    clientTemplate.delete(deleteId);
    clientTemplate.delete(deleteId, new Object());
    clientTemplate.delete(deleteId, new Object(), 0);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method delete1 = SqlMapClientTemplate.class.getDeclaredMethod("delete", String.class);
    Method delete2 = SqlMapClientTemplate.class.getDeclaredMethod("delete", String.class, Object.class);
    Method delete3 = SqlMapClientTemplate.class.getDeclaredMethod("delete", String.class, Object.class, int.class);
    verifier.verifyTrace(event("IBATIS_SPRING", delete1, Expectations.cachedArgs(deleteId)));
    verifier.verifyTrace(event("IBATIS_SPRING", delete2, Expectations.cachedArgs(deleteId)));
    verifier.verifyTrace(event("IBATIS_SPRING", delete3, Expectations.cachedArgs(deleteId)));
}
 
Example #2
Source File: SqlMapClientTemplateIT.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void updateShouldBeTraced() throws Exception {
    // Given
    final String updateId = "updateId";
    SqlMapClientTemplate clientTemplate = new SqlMapClientTemplate(this.mockDataSource, this.sqlMapClient);
    // When
    clientTemplate.update(updateId);
    clientTemplate.update(updateId, new Object());
    clientTemplate.update(updateId, new Object(), 0);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method update1 = SqlMapClientTemplate.class.getDeclaredMethod("update", String.class);
    Method update2 = SqlMapClientTemplate.class.getDeclaredMethod("update", String.class, Object.class);
    Method update3 = SqlMapClientTemplate.class.getDeclaredMethod("update", String.class, Object.class, int.class);
    verifier.verifyTrace(event("IBATIS_SPRING", update1, Expectations.cachedArgs(updateId)));
    verifier.verifyTrace(event("IBATIS_SPRING", update2, Expectations.cachedArgs(updateId)));
    verifier.verifyTrace(event("IBATIS_SPRING", update3, Expectations.cachedArgs(updateId)));
}
 
Example #3
Source File: SqlMapClientTemplateIT.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void queryForListShouldBeTraced() throws Exception {
    // Given
    final String queryForListId = "queryForListId";
    SqlMapClientTemplate clientTemplate = new SqlMapClientTemplate(this.mockDataSource, this.sqlMapClient);
    // When
    clientTemplate.queryForList(queryForListId);
    clientTemplate.queryForList(queryForListId, new Object());
    clientTemplate.queryForList(queryForListId, 0, 1);
    clientTemplate.queryForList(queryForListId, new Object(), 0, 1);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method queryForList1 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class);
    Method queryForList2 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class, Object.class);
    Method queryForList3 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class, int.class,
            int.class);
    Method queryForList4 = SqlMapClientTemplate.class.getDeclaredMethod("queryForList", String.class, Object.class,
            int.class, int.class);
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList1, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList2, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList3, Expectations.cachedArgs(queryForListId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForList4, Expectations.cachedArgs(queryForListId)));
}
 
Example #4
Source File: SqlMapClientTemplateIT.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void queryForMapShouldBeTraced() throws Exception {
    // Given
    final String queryForMapId = "queryForMapId";
    SqlMapClientTemplate clientTemplate = new SqlMapClientTemplate(this.mockDataSource, this.sqlMapClient);
    // When
    clientTemplate.queryForMap(queryForMapId, new Object(), "key");
    clientTemplate.queryForMap(queryForMapId, new Object(), "key", "value");
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method queryForMap1 = SqlMapClientTemplate.class.getDeclaredMethod("queryForMap", String.class, Object.class,
            String.class);
    Method queryForMap2 = SqlMapClientTemplate.class.getDeclaredMethod("queryForMap", String.class, Object.class,
            String.class, String.class);
    verifier.verifyTrace(event("IBATIS_SPRING", queryForMap1, Expectations.cachedArgs(queryForMapId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForMap2, Expectations.cachedArgs(queryForMapId)));
}
 
Example #5
Source File: SqlMapClientTemplateIT.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
public void queryForObjectShouldBeTraced() throws Exception {
    // Given
    final String queryForObjectId = "queryForObjectId";
    SqlMapClientTemplate clientTemplate = new SqlMapClientTemplate(this.mockDataSource, this.sqlMapClient);
    // When
    clientTemplate.queryForObject(queryForObjectId);
    clientTemplate.queryForObject(queryForObjectId, new Object());
    clientTemplate.queryForObject(queryForObjectId, new Object(), new Object());
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method queryForObject1 = SqlMapClientTemplate.class.getDeclaredMethod("queryForObject", String.class);
    Method queryForObject2 = SqlMapClientTemplate.class.getDeclaredMethod("queryForObject", String.class,
            Object.class);
    Method queryForObject3 = SqlMapClientTemplate.class.getDeclaredMethod("queryForObject", String.class,
            Object.class, Object.class);
    verifier.verifyTrace(event("IBATIS_SPRING", queryForObject1, Expectations.cachedArgs(queryForObjectId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForObject2, Expectations.cachedArgs(queryForObjectId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForObject3, Expectations.cachedArgs(queryForObjectId)));
}
 
Example #6
Source File: SqlMapClientTemplateIT.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void queryForPaginagedListShouldBeTraced() throws Exception {
    // Given
    final String queryForPaginatedListId = "queryForPaginatedListId";
    // to emulate lazy-loading, otherwise exception is thrown
    TransactionManager mockTxManager = mock(TransactionManager.class);
    when(this.mockSqlMapExecutorDelegate.getTxManager()).thenReturn(mockTxManager);
    SqlMapClientTemplate clientTemplate = new SqlMapClientTemplate(this.mockDataSource, this.sqlMapClient);
    // When
    clientTemplate.queryForPaginatedList(queryForPaginatedListId, 1);
    clientTemplate.queryForPaginatedList(queryForPaginatedListId, new Object(), 1);
    // Then
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    Method queryForPaginatedList1 = SqlMapClientTemplate.class.getDeclaredMethod("queryForPaginatedList",
            String.class, int.class);
    Method queryForPaginatedList2 = SqlMapClientTemplate.class.getDeclaredMethod("queryForPaginatedList",
            String.class, Object.class, int.class);
    verifier.verifyTrace(event("IBATIS_SPRING", queryForPaginatedList1,
            Expectations.cachedArgs(queryForPaginatedListId)));
    verifier.verifyTrace(event("IBATIS_SPRING", queryForPaginatedList2,
            Expectations.cachedArgs(queryForPaginatedListId)));
}
 
Example #7
Source File: IbatisDaoImpl.java    From EserKnife with Apache License 2.0 5 votes vote down vote up
public final void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
    if (sqlMapClientTemplate == null) {
        throw new IllegalArgumentException("Cannot set sqlMapClientTemplate to null");
    } else {
        this.sqlMapClientTemplate = sqlMapClientTemplate;
    }
}
 
Example #8
Source File: AbstractTestNGCobarClientTest.java    From cobarclient with Apache License 2.0 5 votes vote down vote up
public AbstractTestNGCobarClientTest(String[] locations) {
    applicationContext = new ClassPathXmlApplicationContext(locations);
    ((AbstractApplicationContext) applicationContext).registerShutdownHook();

    setSqlMapClientTemplate((SqlMapClientTemplate) applicationContext
            .getBean("sqlMapClientTemplate"));

    jt1m = new JdbcTemplate((DataSource) applicationContext.getBean("partition1_main"));
    jt1s = new JdbcTemplate((DataSource) applicationContext.getBean("partition1_standby"));
    jt2m = new JdbcTemplate((DataSource) applicationContext.getBean("partition2_main"));
    jt2s = new JdbcTemplate((DataSource) applicationContext.getBean("partition2_standby"));

    jt1m.execute(CREATE_TABLE_COBAR_HA);
    jt1m.execute(CREATE_TABLE_TWEETS);
    jt1m.execute(CREATE_TABLE_FOLLOWERS);
    jt1m.execute(CREATE_TABLE_OFFERS);

    jt1s.execute(CREATE_TABLE_COBAR_HA);
    jt1s.execute(CREATE_TABLE_TWEETS);
    jt1s.execute(CREATE_TABLE_FOLLOWERS);
    jt1s.execute(CREATE_TABLE_OFFERS);

    jt2m.execute(CREATE_TABLE_COBAR_HA);
    jt2m.execute(CREATE_TABLE_FOLLOWERS);
    jt2m.execute(CREATE_TABLE_TWEETS);
    jt2m.execute(CREATE_TABLE_OFFERS);

    jt2s.execute(CREATE_TABLE_COBAR_HA);
    jt2s.execute(CREATE_TABLE_FOLLOWERS);
    jt2s.execute(CREATE_TABLE_TWEETS);
    jt2s.execute(CREATE_TABLE_OFFERS);
}
 
Example #9
Source File: CobarSqlMapClientTemplateWithCustomMergerTest.java    From cobarclient with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryForListWithCustomMerger() {
    batchInsertOffersAsFixture();

    SqlMapClientTemplate st = (SqlMapClientTemplate) getApplicationContext().getBean(
            "sqlMapClientTemplateWithMerger");
    @SuppressWarnings("unchecked")
    List lst = st
            .queryForList("com.alibaba.cobar.client.entities.Offer.findAllWithOrderByOnSubject");
    assertTrue(CollectionUtils.isNotEmpty(lst));
    assertEquals(5, lst.size());

    verifyOffersOrderBySubject(lst);

}
 
Example #10
Source File: IbatisDaoImpl.java    From EserKnife with Apache License 2.0 4 votes vote down vote up
public IbatisDaoImpl(boolean isProxy) {
    this.sqlMapClientTemplate = new SqlMapClientTemplate();
}
 
Example #11
Source File: IbatisDaoImpl.java    From EserKnife with Apache License 2.0 4 votes vote down vote up
protected SqlMapClientTemplate getSqlMapClientTemplate() {
    return this.sqlMapClientTemplate;
}
 
Example #12
Source File: AbstractTestNGCobarClientTest.java    From cobarclient with Apache License 2.0 4 votes vote down vote up
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
    this.sqlMapClientTemplate = sqlMapClientTemplate;
}
 
Example #13
Source File: AbstractTestNGCobarClientTest.java    From cobarclient with Apache License 2.0 4 votes vote down vote up
public SqlMapClientTemplate getSqlMapClientTemplate() {
    return sqlMapClientTemplate;
}
 
Example #14
Source File: AbstractOfferService.java    From cobarclient with Apache License 2.0 4 votes vote down vote up
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
    this.sqlMapClientTemplate = sqlMapClientTemplate;
}
 
Example #15
Source File: AbstractOfferService.java    From cobarclient with Apache License 2.0 4 votes vote down vote up
public SqlMapClientTemplate getSqlMapClientTemplate() {
    return sqlMapClientTemplate;
}