Search in sources :

Example 11 with SingleUpdateTask

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

the class SingleUpdateTaskTestStub method testExcludeColumns.

@Test
public void testExcludeColumns() throws SQLException {
    //Table Index and Address is not updatable
    SingleUpdateTask<NonUpdatableModel> test = new SingleUpdateTask<>();
    DalParser<NonUpdatableModel> parser = new DalDefaultJpaParser<>(NonUpdatableModel.class, getDbName());
    test.initialize(parser);
    DalHints hints = new DalHints();
    NonUpdatableModel model = getAll(NonUpdatableModel.class).get(0);
    String oldAddr = model.getAddress();
    Integer oldTableIndex = model.getTableIndex();
    Integer oldQuantity = model.getQuantity();
    model.setDbIndex(-100);
    model.setAddress("1122334455");
    model.setTableIndex(100);
    model.setQuantity(500);
    model.setType((short) 8);
    int result = test.execute(hints.exclude("quantity"), getFields(model), model);
    assertIntEquals(1, result);
    model = getDao(NonUpdatableModel.class).queryByPk(model, new DalHints());
    assertEquals(oldAddr, model.getAddress());
    assertEquals(oldTableIndex, model.getTableIndex());
    assertEquals(oldQuantity, model.getQuantity());
    assertEquals(-100, model.getDbIndex().intValue());
    assertEquals(8, model.getType().shortValue());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) SingleUpdateTask(com.ctrip.platform.dal.dao.task.SingleUpdateTask) Test(org.junit.Test)

Example 12 with SingleUpdateTask

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

the class SingleUpdateTaskTestStub method testExecuteUpdatableEntityNoChange.

@Test
public void testExecuteUpdatableEntityNoChange() throws SQLException {
    SingleUpdateTask<UpdatableClientTestModel> test = new SingleUpdateTask<>();
    DalParser<UpdatableClientTestModel> parser = getParser(UpdatableClientTestModel.class);
    test.initialize(parser);
    DalHints hints = new DalHints();
    try {
        UpdatableClientTestModel model = getAll(UpdatableClientTestModel.class).get(0);
        int result = test.execute(hints, parser.getFields(model), model);
        assertEquals(0, result);
        result = getDao(UpdatableClientTestModel.class).update(hints, model);
        assertEquals(0, result);
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) SingleUpdateTask(com.ctrip.platform.dal.dao.task.SingleUpdateTask) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)12 SingleUpdateTask (com.ctrip.platform.dal.dao.task.SingleUpdateTask)12 Test (org.junit.Test)12 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)8 SQLException (java.sql.SQLException)5 Timestamp (java.sql.Timestamp)2