Search in sources :

Example 16 with BatchUpdateTask

use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.

the class BatchUpdateTaskTestStub method testVersionNotSet.

@Test
public void testVersionNotSet() throws SQLException {
    BatchUpdateTask<UpdatableVersionModel> test = new BatchUpdateTask<>();
    DalParser<UpdatableVersionModel> parser = new DalDefaultJpaParser<>(UpdatableVersionModel.class, getDbName());
    test.initialize(parser);
    DalTableDao<UpdatableVersionModel> dao = new DalTableDao<UpdatableVersionModel>(parser);
    DalHints hints = new DalHints();
    List<UpdatableVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
    for (UpdatableVersionModel model : pojos) {
        model.setAddress("1122334455");
        model.setLastChanged(null);
    }
    try {
        execute(test, hints, pojos);
        fail();
    } catch (SQLException e) {
        assertEquals(ErrorCode.ValidateVersion.getMessage(), e.getMessage());
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) BatchUpdateTask(com.ctrip.platform.dal.dao.task.BatchUpdateTask) DalTableDao(com.ctrip.platform.dal.dao.DalTableDao) Test(org.junit.Test)

Example 17 with BatchUpdateTask

use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.

the class BatchUpdateTaskTestStub method testIgnorNullField.

@Test
public void testIgnorNullField() {
    BatchUpdateTask<ClientTestModel> test = new BatchUpdateTask<>();
    test.initialize(getParser());
    DalHints hints = new DalHints();
    try {
        List<ClientTestModel> pojos = getAll();
        for (ClientTestModel model : pojos) {
            model.setAddress("1122334455");
            model.setType((Short) null);
            model.setQuantity(null);
            model.setDbIndex(null);
            model.setLastChanged(null);
            model.setTableIndex(null);
        }
        int[] result = execute(test, hints, pojos);
        assertEquals(3, result.length);
        assertEquals(3, getCount());
        pojos = getAll();
        for (ClientTestModel model : pojos) {
            assertEquals("1122334455", model.getAddress());
            assertNotNull(model.getQuantity());
            assertNotNull(model.getType());
            assertNotNull(model.getDbIndex());
            assertNotNull(model.getLastChanged());
            assertNotNull(model.getTableIndex());
        }
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) BatchUpdateTask(com.ctrip.platform.dal.dao.task.BatchUpdateTask) Test(org.junit.Test)

Example 18 with BatchUpdateTask

use of com.ctrip.platform.dal.dao.task.BatchUpdateTask in project dal by ctripcorp.

the class BatchUpdateTaskTestStub method testIncludeExcludeColumns.

@Test
public void testIncludeExcludeColumns() throws SQLException {
    BatchUpdateTask<UpdatableIntVersionModel> test = new BatchUpdateTask<>();
    DalParser<UpdatableIntVersionModel> parser = new DalDefaultJpaParser<>(UpdatableIntVersionModel.class, getDbName());
    test.initialize(parser);
    DalTableDao<UpdatableIntVersionModel> dao = new DalTableDao<>(parser);
    DalHints hints = new DalHints().exclude("dbIndex").include("quantity", "dbIndex", "address");
    List<UpdatableIntVersionModel> pojos = dao.query("1=1", new StatementParameters(), new DalHints());
    for (UpdatableIntVersionModel model : pojos) {
        model.setQuantity(500);
        model.setDbIndex(100);
        model.setAddress("1122334455");
    }
    int[] result = execute(test, hints, pojos);
    assertArrayEquals(new int[] { 1, 1, 1 }, result);
    pojos = dao.query("1=1", new StatementParameters(), new DalHints());
    for (UpdatableIntVersionModel model : pojos) {
        assertEquals("1122334455", model.getAddress());
        assertEquals(500, model.getQuantity().intValue());
        assertEquals(0, model.getDbIndex().intValue());
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) BatchUpdateTask(com.ctrip.platform.dal.dao.task.BatchUpdateTask) DalTableDao(com.ctrip.platform.dal.dao.DalTableDao) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)18 BatchUpdateTask (com.ctrip.platform.dal.dao.task.BatchUpdateTask)18 Test (org.junit.Test)18 SQLException (java.sql.SQLException)11 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)8 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)8 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)8 Timestamp (java.sql.Timestamp)1