Search in sources :

Example 1 with DalCustomRowMapper

use of com.ctrip.platform.dal.dao.helper.DalCustomRowMapper in project dal by ctripcorp.

the class DalCustomRowMapperTest method testArray.

@Test
public void testArray() throws SQLException {
    DalCustomRowMapper mapper = new DalCustomRowMapper("id", "quantity", "type");
    String sql = "select id, quantity, type from " + database.getTableName();
    DalRowMapperExtractor<Map<String, Object>> rse = new DalRowMapperExtractor<Map<String, Object>>(mapper);
    List<Map<String, Object>> rest = database.getClient().query(sql, new StatementParameters(), new DalHints(), rse);
    Assert.assertEquals(3, rest.size());
    Assert.assertEquals("1", rest.get(0).get("id").toString());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalCustomRowMapper(com.ctrip.platform.dal.dao.helper.DalCustomRowMapper) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Map(java.util.Map) DalRowMapperExtractor(com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor) Test(org.junit.Test)

Example 2 with DalCustomRowMapper

use of com.ctrip.platform.dal.dao.helper.DalCustomRowMapper in project dal by ctripcorp.

the class DalCustomRowMapperTest method testList.

@Test
public void testList() throws SQLException {
    List<String> columns = new ArrayList<String>();
    columns.add("id");
    DalCustomRowMapper mapper = new DalCustomRowMapper(columns);
    String sql = "select id from " + database.getTableName();
    DalRowMapperExtractor<Map<String, Object>> rse = new DalRowMapperExtractor<Map<String, Object>>(mapper);
    List<Map<String, Object>> rest = database.getClient().query(sql, new StatementParameters(), new DalHints(), rse);
    Assert.assertEquals(3, rest.size());
    Assert.assertEquals("1", rest.get(0).get("id").toString());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalCustomRowMapper(com.ctrip.platform.dal.dao.helper.DalCustomRowMapper) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) Map(java.util.Map) DalRowMapperExtractor(com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)2 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)2 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)2 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)2 Map (java.util.Map)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1