Search in sources :

Example 36 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryForObjectNullableSuccess.

/**
 * Test query for object success
 * @throws SQLException
 */
@Test
public void testQueryForObjectNullableSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    ClientTestModel model = client.queryForObjectNullable(sql, param, hints, mapper);
    Assert.assertNotNull(model);
    Assert.assertEquals(1, model.getId().intValue());
    sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = -1";
    Assert.assertNull(client.queryForObjectNullable(sql, param, hints, mapper));
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 37 with ClientTestModel

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

the class DalQueryDaoTestStub method testQueryForObjectSuccess.

/**
 * Test query for object success
 * @throws SQLException
 */
@Test
public void testQueryForObjectSuccess() throws SQLException {
    String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
    StatementParameters param = new StatementParameters();
    DalHints hints = new DalHints();
    ClientTestModel model = client.queryForObject(sql, param, hints, mapper);
    Assert.assertEquals(1, model.getId().intValue());
    FreeSelectSqlBuilder<List<Map<String, Object>>> builder = new FreeSelectSqlBuilder<>();
    builder.append("select count(*) as c1, 111 as c2");
    builder.mapWith(new DalCustomRowMapper("c1", "c2"));
    builder.with(new StatementParameters());
    List<Map<String, Object>> l = client.query(builder, hints);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) DalCustomRowMapper(com.ctrip.platform.dal.dao.helper.DalCustomRowMapper) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 38 with ClientTestModel

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

the class DalTableDaoTestStub method testDeleteMultiple.

/**
 * Test delete multiple entities
 * @throws SQLException
 */
@Test
public void testDeleteMultiple() throws SQLException {
    List<ClientTestModel> modelList = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setId(i + 1);
        modelList.add(model);
    }
    int[] res = dao.delete(new DalHints(), modelList);
    assertEquals(new int[] { 1, 1, 1 }, res, 4 - 3);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 39 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryByPkWithEntityByColumnNames.

/**
 * Query by Entity with Primary key
 * @throws SQLException
 */
@Test
public void testQueryByPkWithEntityByColumnNames() throws SQLException {
    ClientTestModel pk = new ClientTestModel();
    pk.setId(1);
    ClientTestModel model = dao.queryByPk(pk, new DalHints().selectByNames());
    Assert.assertTrue(null != model);
    Assert.assertEquals(10, model.getQuantity().intValue());
    model = dao.queryByPk(pk, new DalHints(DalHintEnum.selectByNames));
    Assert.assertTrue(null != model);
    Assert.assertEquals(10, model.getQuantity().intValue());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) Test(org.junit.Test)

Example 40 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryFirstWithWhereClause.

/**
 * Test Query the first row with where clause
 * @throws SQLException
 */
@Test
public void testQueryFirstWithWhereClause() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    ClientTestModel model = dao.queryFirst(whereClause, parameters, new DalHints());
    Assert.assertTrue(null != model);
    Assert.assertEquals(1, model.getId().intValue());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)61 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)61 Test (org.junit.Test)59 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)40 ArrayList (java.util.ArrayList)13 SQLException (java.sql.SQLException)9 DalClient (com.ctrip.platform.dal.dao.DalClient)3 DalCommand (com.ctrip.platform.dal.dao.DalCommand)3 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)3 ClientTestDalRowMapper (test.com.ctrip.platform.dal.dao.unitbase.ClientTestDalRowMapper)3 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)2 DalRowMapperExtractor (com.ctrip.platform.dal.dao.helper.DalRowMapperExtractor)2 DalRowCallback (com.ctrip.platform.dal.dao.DalRowCallback)1 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)1 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)1 ResultSet (java.sql.ResultSet)1 Timestamp (java.sql.Timestamp)1 List (java.util.List)1 Map (java.util.Map)1