Search in sources :

Example 1 with DalDefaultJpaParser

use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.

the class SingleUpdateTaskTestStub method testNotUpdatableVersion.

@Test
public void testNotUpdatableVersion() throws SQLException {
    SingleUpdateTask<NonUpdatableVersionModel> test = new SingleUpdateTask<>();
    DalParser<NonUpdatableVersionModel> parser = new DalDefaultJpaParser<>(NonUpdatableVersionModel.class, getDbName());
    test.initialize(parser);
    DalHints hints = new DalHints();
    NonUpdatableVersionModel model = getAll(NonUpdatableVersionModel.class).get(0);
    model.setAddress("1122334455");
    int result = test.execute(hints, getFields(model), model);
    assertIntEquals(1, result);
    model = getDao(NonUpdatableVersionModel.class).queryByPk(model, new DalHints());
    assertEquals("1122334455", model.getAddress());
}
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 2 with DalDefaultJpaParser

use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.

the class SingleUpdateTaskTestStub method testVersionNotSet.

@Test
public void testVersionNotSet() throws SQLException {
    SingleUpdateTask<UpdatableVersionModel> test = new SingleUpdateTask<>();
    DalParser<UpdatableVersionModel> parser = new DalDefaultJpaParser<>(UpdatableVersionModel.class, getDbName());
    test.initialize(parser);
    DalHints hints = new DalHints();
    UpdatableVersionModel model = getAll(UpdatableVersionModel.class).get(0);
    model.setAddress("1122334455");
    model.setLastChanged(null);
    try {
        test.execute(hints, getFields(model), model);
        fail();
    } catch (SQLException e) {
        assertEquals(ErrorCode.ValidateVersion.getMessage(), e.getMessage());
    }
    model = getDao(UpdatableVersionModel.class).queryByPk(model, new DalHints());
    assertEquals("SH INFO", model.getAddress());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) SingleUpdateTask(com.ctrip.platform.dal.dao.task.SingleUpdateTask) Test(org.junit.Test)

Example 3 with DalDefaultJpaParser

use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.

the class SingleUpdateTaskTestStub method testIncludeExcludeColumns.

@Test
public void testIncludeExcludeColumns() 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.include("dbIndex", "type", "quantity").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 4 with DalDefaultJpaParser

use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.

the class SingleUpdateTaskTestStub method testUpdatableWithVersionByDao.

@Test
public void testUpdatableWithVersionByDao() throws SQLException {
    DalParser<UpdatableVersionModel> parser = new DalDefaultJpaParser<>(UpdatableVersionModel.class, getDbName());
    DalTableDao<UpdatableVersionModel> dao = new DalTableDao<>(parser);
    DalHints hints = new DalHints();
    UpdatableVersionModel model = dao.query("1=1", new StatementParameters(), new DalHints()).get(0);
    model.setAddress("1122334455");
    model.getLastChanged().setTime(model.getLastChanged().getTime() + 100);
    int result = dao.update(hints, model);
    assertIntEquals(0, result);
    model = dao.queryByPk(model, new DalHints());
    assertEquals("SH INFO", model.getAddress());
    model = dao.query("1=1", new StatementParameters(), new DalHints()).get(0);
    model.setAddress("1122334455");
    result = dao.update(hints, model);
    assertIntEquals(1, result);
    model = dao.queryByPk(model, new DalHints());
    assertEquals("1122334455", model.getAddress());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) DalTableDao(com.ctrip.platform.dal.dao.DalTableDao) Test(org.junit.Test)

Example 5 with DalDefaultJpaParser

use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser in project dal by ctripcorp.

the class SingleUpdateTaskTestStub method testUpdatableWithVersion.

@Test
public void testUpdatableWithVersion() throws SQLException {
    SingleUpdateTask<UpdatableVersionModel> test = new SingleUpdateTask<>();
    DalParser<UpdatableVersionModel> parser = new DalDefaultJpaParser<>(UpdatableVersionModel.class, getDbName());
    test.initialize(parser);
    DalHints hints = new DalHints();
    UpdatableVersionModel model = getAll(UpdatableVersionModel.class).get(0);
    model.setAddress("1122334455");
    int result = test.execute(hints, getFields(model), model);
    assertIntEquals(1, result);
    model = getDao(UpdatableVersionModel.class).queryByPk(model, new DalHints());
    assertEquals("1122334455", model.getAddress());
}
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)

Aggregations

DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)27 Test (org.junit.Test)26 DalHints (com.ctrip.platform.dal.dao.DalHints)25 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)13 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)13 BatchUpdateTask (com.ctrip.platform.dal.dao.task.BatchUpdateTask)8 SingleUpdateTask (com.ctrip.platform.dal.dao.task.SingleUpdateTask)8 SQLException (java.sql.SQLException)5 Map (java.util.Map)4 Timestamp (java.sql.Timestamp)3 BatchInsertTask (com.ctrip.platform.dal.dao.task.BatchInsertTask)2 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)1 CombinedInsertTask (com.ctrip.platform.dal.dao.task.CombinedInsertTask)1 SingleInsertTask (com.ctrip.platform.dal.dao.task.SingleInsertTask)1 BeforeClass (org.junit.BeforeClass)1