Search in sources :

Example 1 with CombinedInsertTask

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

the class CombinedInsertTaskTestStub method testExecute.

@Test
public void testExecute() {
    CombinedInsertTask<ClientTestModel> test = new CombinedInsertTask<>();
    test.initialize(new ClientTestDalParser(getDbName()));
    DalHints hints = new DalHints();
    if (enableKeyHolder)
        hints.setKeyHolder(new KeyHolder());
    try {
        execute(test, hints, getAllMap(), getAll());
        if (enableKeyHolder) {
            // You have to merge before get size
            assertEquals(3, hints.getKeyHolder().size());
        }
        assertEquals(3 + 3, getCount());
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) CombinedInsertTask(com.ctrip.platform.dal.dao.task.CombinedInsertTask) KeyHolder(com.ctrip.platform.dal.dao.KeyHolder) Test(org.junit.Test)

Example 2 with CombinedInsertTask

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

the class CombinedInsertTaskTestStub method testExecuteWithId.

@Test
public void testExecuteWithId() {
    CombinedInsertTask<ClientTestModel> test = new CombinedInsertTask<>();
    test.initialize(new ClientTestDalParser(getDbName()));
    DalHints hints = new DalHints().enableIdentityInsert();
    if (enableKeyHolder)
        hints.setKeyHolder(new KeyHolder());
    try {
        if (this instanceof CombinedInsertTaskSqlSvrTest)
            SqlServerTestInitializer.turnOnIdentityInsert();
        List<ClientTestModel> pojos = getAll();
        int i = 111;
        for (ClientTestModel pojo : pojos) {
            pojo.setId(new Integer(i++));
        }
        execute(test, hints, null, pojos);
        assertEquals(6, getCount());
        pojos = getAll();
        Set<Integer> ids = new HashSet<>();
        for (ClientTestModel pojo : pojos) {
            ids.add(pojo.getId());
        }
        assertTrue(ids.contains(111));
        assertTrue(ids.contains(112));
        assertTrue(ids.contains(113));
        if (enableKeyHolder) {
            // You have to merge before get size
            assertEquals(3, hints.getKeyHolder().size());
        }
        assertEquals(3 + 3, getCount());
        if (this instanceof CombinedInsertTaskSqlSvrTest)
            SqlServerTestInitializer.turnOffIdentityInsert();
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) CombinedInsertTask(com.ctrip.platform.dal.dao.task.CombinedInsertTask) KeyHolder(com.ctrip.platform.dal.dao.KeyHolder) SQLException(java.sql.SQLException) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with CombinedInsertTask

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

the class CombinedInsertTaskTestStub method testExecuteWithNonInsertable.

@Test
public void testExecuteWithNonInsertable() throws SQLException {
    CombinedInsertTask<NonInsertableVersionModel> test = new CombinedInsertTask<>();
    DalParser<NonInsertableVersionModel> parser = new DalDefaultJpaParser<>(NonInsertableVersionModel.class, getDbName());
    test.initialize(parser);
    DalHints hints = new DalHints();
    if (enableKeyHolder)
        hints.setKeyHolder(new KeyHolder());
    try {
        execute(test, hints, getAllMap(), getAll(NonInsertableVersionModel.class));
        if (enableKeyHolder) {
            // You have to merge before get size
            assertEquals(3, hints.getKeyHolder().size());
        }
        assertEquals(3 + 3, getCount());
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
    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) SQLException(java.sql.SQLException) CombinedInsertTask(com.ctrip.platform.dal.dao.task.CombinedInsertTask) KeyHolder(com.ctrip.platform.dal.dao.KeyHolder) DalDefaultJpaParser(com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser) Map(java.util.Map) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)3 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)3 CombinedInsertTask (com.ctrip.platform.dal.dao.task.CombinedInsertTask)3 SQLException (java.sql.SQLException)3 Test (org.junit.Test)3 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1