Search in sources :

Example 1 with ClientTestDalRowMapper

use of com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper in project dal by ctripcorp.

the class DalDirectClientTestStub method queryTestWithFetchSizeLimit.

/**
 * Test the basic query function with maxRows limit
 *
 * @throws SQLException
 */
@Test
public void queryTestWithFetchSizeLimit() throws SQLException {
    String querySql = "SELECT * FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
    DalHints hints = new DalHints();
    // Set fetch size limit
    hints.set(DalHintEnum.maxRows, 1);
    List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
    Assert.assertTrue(null != res);
    Assert.assertEquals(1, res.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ClientTestDalRowMapper(com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper) Test(org.junit.Test)

Example 2 with ClientTestDalRowMapper

use of com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper in project dal by ctripcorp.

the class DalDirectClientTestStub method queryTestWithoutParameters.

/**
 * Test the basic query function without parameters
 *
 * @throws SQLException
 */
@Test
public void queryTestWithoutParameters() throws SQLException {
    String querySql = "SELECT * FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
    DalHints hints = new DalHints();
    List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
    Assert.assertTrue(null != res && res.size() == 3);
    ClientTestModel model = res.get(0);
    Assert.assertTrue(model.getQuantity() == 10 && model.getType() == 1 && model.getAddress().equals("SH INFO"));
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ClientTestDalRowMapper(com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper) Test(org.junit.Test)

Example 3 with ClientTestDalRowMapper

use of com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper in project dal by ctripcorp.

the class DalDirectClientTestStub method queryTestWithParameters.

/**
 * Test the basic query function without parameters
 *
 * @throws SQLException
 */
@Test
public void queryTestWithParameters() throws SQLException {
    String querySql = "SELECT * FROM " + TABLE_NAME + " WHERE type = ?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    ClientTestDalRowMapper mapper = new ClientTestDalRowMapper();
    DalHints hints = new DalHints();
    List<ClientTestModel> res = client.query(querySql, parameters, hints, new DalRowMapperExtractor<ClientTestModel>(mapper));
    Assert.assertTrue(null != res);
    Assert.assertEquals(2, res.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ClientTestDalRowMapper(com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)3 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)3 ClientTestDalRowMapper (com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper)3 ClientTestModel (com.ctrip.platform.dal.dao.unitbase.ClientTestModel)3 Test (org.junit.Test)3