Search in sources :

Example 6 with ClientTestModel

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

the class DalTableDaoTestStub method testInsertMultipleAsListWithContinueOnErrorHints.

/**
 * Test Test Insert multiple entities one by one with continueOnError hints
 * @throws SQLException
 */
@Test
public void testInsertMultipleAsListWithContinueOnErrorHints() 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());
        if (i == 1) {
            model.setAddress("CTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIP" + "CTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIPCTRIP" + "CTRIPCTRIPCTRIPCTRIP");
        } else {
            model.setAddress("CTRIP");
        }
        entities.add(model);
    }
    DalHints hints = new DalHints(DalHintEnum.continueOnError);
    int[] res = dao.insert(hints, entities);
    assertEquals(new int[] { 1, 0, 1 }, res, 4 + 2);
}
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 7 with ClientTestModel

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

the class DalTableDaoTestStub method testUpdateMultiple.

/**
 * Test update multiple entities with primary key
 * @throws SQLException
 */
@Test
public void testUpdateMultiple() throws SQLException {
    DalHints hints = new DalHints();
    List<ClientTestModel> models = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setId(i + 1);
        model.setAddress("CTRIP");
        models.add(model);
    }
    int[] res = dao.update(hints, models);
    assertEquals(new int[] { 1, 1, 1 }, res, 3, "address='CTRIP'");
    ClientTestModel model = dao.queryByPk(1, hints);
    Assert.assertTrue(null != model);
    Assert.assertEquals("CTRIP", model.getAddress());
}
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 8 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryFromWithWhereClause.

/**
 * Test Query range of result with where clause
 * @throws SQLException
 */
@Test
public void testQueryFromWithWhereClause() 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, 1);
    Assert.assertTrue(null != models);
    Assert.assertEquals(1, 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 9 with ClientTestModel

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

the class DalTableDaoTestStub method testUpdatePlain.

/**
 * Test plain update with SQL
 * @throws SQLException
 */
@Test
public void testUpdatePlain() throws SQLException {
    String sql = "UPDATE " + TABLE_NAME + " SET address = 'CTRIP' WHERE id = 1";
    StatementParameters parameters = new StatementParameters();
    DalHints hints = new DalHints();
    int res = dao.update(sql, parameters, hints);
    assertEquals(1, res, 1, "address = 'CTRIP'");
    ClientTestModel model = dao.queryByPk(1, hints);
    Assert.assertTrue(null != model);
    Assert.assertEquals("CTRIP", model.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)

Example 10 with ClientTestModel

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

the class DalTableDaoTestStub method testQueryListAllColumns.

@Test
public void testQueryListAllColumns() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 1, Types.SMALLINT);
    List<ClientTestModel> models = dao.query(builder, new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(3, models.size());
    builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 1, Types.SMALLINT);
    models = dao.query(builder.atPage(1, 1), new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(1, models.size());
    builder = new SelectSqlBuilder().selectAllColumns();
    builder.equal("type", 10, Types.SMALLINT);
    models = dao.query(builder.atPage(1, 10), new DalHints());
    Assert.assertTrue(null != models);
    Assert.assertEquals(0, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) 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