Search in sources :

Example 26 with DalDefaultJpaParser

use of com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser 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)

Example 27 with DalDefaultJpaParser

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

the class SingleInsertTaskTestStub method testExecuteWithNonInsertable.

@Test
public void testExecuteWithNonInsertable() throws SQLException {
    SingleInsertTask<NonInsertableVersionModel> test = new SingleInsertTask<>();
    DalParser<NonInsertableVersionModel> parser = new DalDefaultJpaParser<>(NonInsertableVersionModel.class, getDbName());
    test.initialize(parser);
    DalHints hints = new DalHints();
    int result = test.execute(hints, getAllMap().get(0), null);
    assertEquals(3 + 1, getCount());
    Map<Integer, Map<String, ?>> pojos = getAllMap();
    for (Map<String, ?> pojo : pojos.values()) {
        assertNotNull(pojo.get("last_changed"));
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SingleInsertTask(com.ctrip.platform.dal.dao.task.SingleInsertTask) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) Map(java.util.Map) 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