Search in sources :

Example 41 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryFromWithWhereClauseFailed.

/**
 * Test Query range of result with where clause failed when return not enough recodes
 * @throws SQLException
 */
@Test
public void testQueryFromWithWhereClauseFailed() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    List<ClientTestModel> models = dao.queryFrom(whereClause, parameters, new DalHints(), 0, 10);
    Assert.assertTrue(null != models);
    Assert.assertEquals(3, models.size());
}
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 42 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryByPkWithEntity.

/**
 * Query by Entity with Primary key
 * @throws SQLException
 */
@Test
public void testQueryByPkWithEntity() throws SQLException {
    ClientTestModel pk = new ClientTestModel();
    pk.setId(1);
    ClientTestModel model = dao.queryByPk(pk, new DalHints());
    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 43 with ClientTestModel

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

the class DalTableDaoTestStub method testInsertMultipleAsListWithKeyHolder.

/**
 * Test Insert multiple entities with key-holder
 * @throws SQLException
 */
@Test
public void testInsertMultipleAsListWithKeyHolder() throws SQLException {
    List<ClientTestModel> entities = new ArrayList<ClientTestModel>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setQuantity(10 + 1 % 3);
        model.setType(((Number) (1 % 3)).shortValue());
        model.setAddress("CTRIP");
        entities.add(model);
    }
    KeyHolder holder = diff.supportGetGeneratedKeys ? new KeyHolder() : null;
    int[] res = dao.insert(new DalHints(), holder, entities);
    assertEquals(new int[] { 1, 1, 1 }, res, 4 + 3);
    if (diff.supportGetGeneratedKeys) {
        Assert.assertEquals(3, holder.size());
        Assert.assertTrue(holder.getKeyList().get(0).containsKey("GENERATED_KEY"));
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) ArrayList(java.util.ArrayList) KeyHolder(com.ctrip.platform.dal.dao.KeyHolder) Test(org.junit.Test)

Example 44 with ClientTestModel

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

the class DalTableDaoTestStub method testDeleteWithWhereClause.

/**
 * Test delete entities with where clause and parameters
 * @throws SQLException
 */
@Test
public void testDeleteWithWhereClause() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    DalHints hints = new DalHints();
    int res = dao.delete(whereClause, parameters, hints);
    assertEquals(3, res, 1);
    List<ClientTestModel> models = dao.query(whereClause, parameters, hints);
    Assert.assertEquals(0, models.size());
}
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 45 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryWithWhereClause.

/**
 * Query by Entity with where clause
 * @throws SQLException
 */
@Test
public void testQueryWithWhereClause() throws SQLException {
    String whereClause = "type=? and id=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 1);
    parameters.set(2, Types.INTEGER, 1);
    List<ClientTestModel> models = dao.query(whereClause, parameters, new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(1, models.size());
    Assert.assertEquals("SH INFO", models.get(0).getAddress());
}
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