Search in sources :

Example 71 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method testCrossShardDelete.

@Test
public void testCrossShardDelete() {
    testCrossShardDelete(new DalHints());
    testCrossShardDelete(asyncHints());
    testCrossShardDelete(intHints());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) Test(org.junit.Test)

Example 72 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method testBatchUpdateByFields.

@Test
public void testBatchUpdateByFields() throws SQLException {
    testBatchUpdateByFields(new DalHints());
    testBatchUpdateByFields(asyncHints());
    testBatchUpdateByFields(intHints());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) Test(org.junit.Test)

Example 73 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method batchDeleteTest.

private void batchDeleteTest(int shardId, int tableShardId, DalHints oldhints) throws SQLException {
    int count = 1 + tableShardId;
    Assert.assertEquals(count, getCount(shardId, tableShardId));
    DalHints hints = copy(oldhints);
    int[] res = dao.batchDelete(hints, getModels(shardId, tableShardId));
    res = assertIntArray(res, hints);
    int[] exp = new int[count];
    for (int i = 0; i < count; i++) exp[i] = 1;
    assertResEquals(exp, res);
    Assert.assertEquals(0, getCount(shardId, tableShardId));
    hints = copy(oldhints);
    res = dao.insert(hints, create(count));
    res = assertIntArray(res, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints)

Example 74 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method testQueryByPkWithEntity.

private void testQueryByPkWithEntity(int shardId, DalHints oldHints) throws SQLException {
    ClientTestModel pk = null;
    ClientTestModel model = null;
    DalHints hints;
    for (int i = 0; i < tableMod; i++) {
        int id = 1;
        pk = new ClientTestModel();
        pk.setId(1);
        // By tabelShard
        hints = copy(oldHints);
        model = dao.queryByPk(pk, hints.inTableShard(i));
        model = assertModel(model, hints);
        assertQueryByPk(shardId, model, i, id);
        // By tableShardValue
        hints = copy(oldHints);
        model = dao.queryByPk(pk, hints.setTableShardValue(i));
        model = assertModel(model, hints);
        assertQueryByPk(shardId, model, i, id);
        // By shardColValue
        hints = copy(oldHints);
        model = dao.queryByPk(pk, hints.setShardColValue("table", i));
        model = assertModel(model, hints);
        assertQueryByPk(shardId, model, i, id);
        // By shardColValue
        hints = copy(oldHints);
        model = dao.queryByPk(pk, hints.setShardColValue("tableIndex", i));
        model = assertModel(model, hints);
        assertQueryByPk(shardId, model, i, id);
        // By fields
        pk.setTableIndex(i);
        pk.setDbIndex(shardId);
        hints = copy(oldHints);
        model = dao.queryByPk(pk, hints);
        model = assertModel(model, hints);
        assertQueryByPk(shardId, model, i, id);
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints)

Example 75 with DalHints

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

the class BaseDalTableDaoShardByDbTest method testBatchUpdateMultiple.

@Test
public void testBatchUpdateMultiple() throws SQLException {
    DalHints hints = new DalHints();
    List<ClientTestModel> entities = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setId(i + 1);
        model.setAddress("CTRIP");
        entities.add(model);
    }
    int[] ress;
    try {
        ress = dao.batchUpdate(hints, entities);
        fail();
    } catch (Exception e) {
    }
    // By fields same shard
    // holder = createKeyHolder();
    entities.get(0).setTableIndex(0);
    entities.get(0).setAddress("1234");
    entities.get(1).setTableIndex(0);
    entities.get(1).setAddress("1234");
    entities.get(2).setTableIndex(0);
    entities.get(2).setAddress("1234");
    ress = dao.batchUpdate(new DalHints(), entities);
    assertResEquals(3, ress);
    List<ClientTestModel> result = dao.query("1=1", new StatementParameters(), new DalHints().inShard(0));
    for (ClientTestModel m : result) assertEquals("1234", m.getAddress());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) Test(org.junit.Test)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)772 Test (org.junit.Test)532 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)317 SQLException (java.sql.SQLException)298 ArrayList (java.util.ArrayList)132 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)61 List (java.util.List)48 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)45 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)39 Future (java.util.concurrent.Future)32 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)29 SelectionContext (com.ctrip.platform.dal.dao.configure.SelectionContext)27 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)27 DataBase (com.ctrip.platform.dal.dao.configure.DataBase)26 BeforeClass (org.junit.BeforeClass)26 AfterClass (org.junit.AfterClass)25 HashMap (java.util.HashMap)23 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)20 DalClient (com.ctrip.platform.dal.dao.DalClient)18 BatchUpdateTask (com.ctrip.platform.dal.dao.task.BatchUpdateTask)18