Search in sources :

Example 11 with DalDefaultJpaParser

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

the class BatchUpdateTaskTestStub method testUpdatableWithVersion.

@Test
public void testUpdatableWithVersion() 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());
    long[] oldVer = new long[3];
    int i = 0;
    for (UpdatableVersionModel model : pojos) {
        model.setAddress("1122334455");
        oldVer[i++] = model.getLastChanged().getTime();
    }
    int[] result = execute(test, hints, pojos);
    assertArrayEquals(new int[] { 1, 1, 1 }, result);
    pojos = dao.query("1=1", new StatementParameters(), new DalHints());
    i = 0;
    for (UpdatableVersionModel model : pojos) {
        assertEquals("1122334455", model.getAddress());
        Assert.assertTrue(oldVer[i++] <= model.getLastChanged().getTime());
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) BatchUpdateTask(com.ctrip.platform.dal.dao.task.BatchUpdateTask) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) DalTableDao(com.ctrip.platform.dal.dao.DalTableDao) Test(org.junit.Test)

Example 12 with DalDefaultJpaParser

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

the class BatchUpdateTaskTestStub method testExcludeColumns.

@Test
public void testExcludeColumns() 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");
    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 13 with DalDefaultJpaParser

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

the class BatchUpdateTaskTestStub method testVersionIncorrect.

@Test
public void testVersionIncorrect() 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");
        Timestamp t = model.getLastChanged();
        t.setTime(t.getTime() + 100);
        model.setLastChanged(t);
    }
    int[] result = execute(test, hints, pojos);
    assertArrayEquals(new int[] { 0, 0, 0 }, result);
    pojos = dao.query("1=1", new StatementParameters(), new DalHints());
    for (UpdatableVersionModel model : pojos) assertEquals("SH INFO", 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) BatchUpdateTask(com.ctrip.platform.dal.dao.task.BatchUpdateTask) Timestamp(java.sql.Timestamp) DalTableDao(com.ctrip.platform.dal.dao.DalTableDao) Test(org.junit.Test)

Example 14 with DalDefaultJpaParser

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

the class BatchUpdateTaskTestStub method testIncludeColumns.

@Test
public void testIncludeColumns() 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().include("address", "quantity");
    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 15 with DalDefaultJpaParser

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

the class BatchUpdateTaskTestStub method testDaoIncludeColumns.

@Test
public void testDaoIncludeColumns() throws SQLException {
    DalParser<UpdatableIntVersionModel> parser = new DalDefaultJpaParser<>(UpdatableIntVersionModel.class, getDbName());
    DalTableDao<UpdatableIntVersionModel> dao = new DalTableDao<>(parser);
    DalHints hints = new DalHints().include("address", "quantity");
    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 = dao.batchUpdate(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) DalTableDao(com.ctrip.platform.dal.dao.DalTableDao) Test(org.junit.Test)

Aggregations

DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)29 DalHints (com.ctrip.platform.dal.dao.DalHints)27 Test (org.junit.Test)26 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)14 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)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 BeforeClass (org.junit.BeforeClass)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