Search in sources :

Example 1 with DalColumnMapRowMapper

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

the class DalSingleResultExtractorTest method testExtract.

@Test
public void testExtract() {
    DalColumnMapRowMapper mapper = new DalColumnMapRowMapper();
    DalSingleResultExtractor test = new DalSingleResultExtractor(mapper, true);
}
Also used : DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalSingleResultExtractor(com.ctrip.platform.dal.dao.helper.DalSingleResultExtractor) Test(org.junit.Test)

Example 2 with DalColumnMapRowMapper

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperEmpty.

@Test
public void testDalColumnMapRowMapperEmpty() {
    try {
        StatementParameters parameters = new StatementParameters();
        DalClient client = DalClientFactory.getClient(DATABASE_NAME);
        List<Map<String, Object>> result1 = client.query(sqlNoResult, parameters, new DalHints(), new DalRowMapperExtractor<Map<String, Object>>(new DalColumnMapRowMapper()));
        assertEquals(0, result1.size());
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlNoResult, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(0, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Map(java.util.Map) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 3 with DalColumnMapRowMapper

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperOne.

@Test
public void testDalColumnMapRowMapperOne() {
    try {
        StatementParameters parameters = new StatementParameters();
        parameters.set(1, Types.INTEGER, 3);
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlObject, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(1, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Map(java.util.Map) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 4 with DalColumnMapRowMapper

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

the class DalDirectClient method update.

@Override
public int update(String sql, StatementParameters parameters, final DalHints hints) throws SQLException {
    final KeyHolder generatedKeyHolder = hints.getKeyHolder();
    ConnectionAction<Integer> action = new ConnectionAction<Integer>() {

        @Override
        public Integer execute() throws Exception {
            conn = getConnection(hints, this);
            // For old generated free update, the parameters is not compiled before invoke direct client
            parameters.compile();
            if (generatedKeyHolder == null)
                preparedStatement = createPreparedStatement(conn, sql, parameters, hints);
            else
                preparedStatement = createPreparedStatement(conn, sql, parameters, hints, generatedKeyHolder);
            beginExecute();
            int rows = executeUpdate(preparedStatement, entry);
            endExectue();
            if (generatedKeyHolder == null)
                return rows;
            rs = preparedStatement.getGeneratedKeys();
            if (rs == null)
                return rows;
            DalRowMapperExtractor<Map<String, Object>> rse = new DalRowMapperExtractor<Map<String, Object>>(new DalColumnMapRowMapper());
            generatedKeyHolder.addKeys(rse.extract(rs));
            return rows;
        }
    };
    action.populate(generatedKeyHolder == null ? DalEventEnum.UPDATE_SIMPLE : DalEventEnum.UPDATE_KH, sql, parameters);
    return doInConnection(action, hints);
}
Also used : DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) KeyHolder(com.ctrip.platform.dal.dao.KeyHolder) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DalRowMapperExtractor(com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)

Example 5 with DalColumnMapRowMapper

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperList.

@Test
public void testDalColumnMapRowMapperList() {
    try {
        StatementParameters parameters = new StatementParameters();
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlList, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(3, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Map(java.util.Map) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

DalColumnMapRowMapper (com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper)5 Map (java.util.Map)4 Test (org.junit.Test)4 DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)3 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)3 SQLException (java.sql.SQLException)3 DalClient (com.ctrip.platform.dal.dao.DalClient)1 DalHints (com.ctrip.platform.dal.dao.DalHints)1 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)1 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)1 DalSingleResultExtractor (com.ctrip.platform.dal.dao.helper.DalSingleResultExtractor)1 LinkedHashMap (java.util.LinkedHashMap)1