Search in sources :

Example 66 with DalHints

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

the class BaseDalTabelDaoShardByTableTest method testCrossShardBatchInsertAsync.

@Test
public void testCrossShardBatchInsertAsync() {
    try {
        deleteAllShards();
        ClientTestModel p = new ClientTestModel();
        ClientTestModel[] pList = new ClientTestModel[6];
        p = new ClientTestModel();
        p.setId(1);
        p.setAddress("aaa");
        p.setTableIndex(0);
        pList[0] = p;
        p = new ClientTestModel();
        p.setId(2);
        p.setAddress("aaa");
        p.setTableIndex(1);
        pList[1] = p;
        p = new ClientTestModel();
        p.setId(3);
        p.setAddress("aaa");
        p.setTableIndex(2);
        pList[2] = p;
        p = new ClientTestModel();
        p.setId(4);
        p.setAddress("aaa");
        p.setTableIndex(3);
        pList[3] = p;
        p = new ClientTestModel();
        p.setId(5);
        p.setAddress("aaa");
        p.setTableIndex(4);
        pList[4] = p;
        p = new ClientTestModel();
        p.setId(5);
        p.setAddress("aaa");
        p.setTableIndex(5);
        pList[5] = p;
        DalHints hints = asyncHints();
        int[] res = dao.batchInsert(hints, Arrays.asList(pList));
        assertIntArray(res, hints);
        assertEquals(2, getCount(0));
        assertEquals(2, getCount(1));
        assertEquals(1, getCount(2));
        assertEquals(1, getCount(3));
    } catch (Exception e) {
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 67 with DalHints

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

the class BaseDalTabelDaoShardByTableTest method testQueryFirstWithWhereClauseAsyncCallback.

@Test
public void testQueryFirstWithWhereClauseAsyncCallback() throws SQLException {
    DalHints hints;
    ClientTestModel model = null;
    for (int i = 0; i < mod; i++) {
        String whereClause = "type=?";
        // By tabelShard
        StatementParameters parameters = new StatementParameters();
        parameters.set(1, Types.SMALLINT, 1);
        hints = new DalHints().asyncExecution();
        model = dao.queryFirst(whereClause, parameters, hints.inTableShard(i));
        model = assertModel(model, hints);
        assertEquals(1, model.getId().intValue());
        assertEquals(i, model.getTableIndex().intValue());
        // By tableShardValue
        hints = callbackHints();
        model = dao.queryFirst(whereClause, parameters, hints.setTableShardValue(i));
        model = assertModel(model, hints);
        assertEquals(1, model.getId().intValue());
        assertEquals(i, model.getTableIndex().intValue());
        // By shardColValue
        hints = new DalHints().asyncExecution();
        model = dao.queryFirst(whereClause, parameters, hints.setShardColValue("index", i));
        model = assertModel(model, hints);
        assertEquals(1, model.getId().intValue());
        assertEquals(i, model.getTableIndex().intValue());
        // By shardColValue
        hints = callbackHints();
        model = dao.queryFirst(whereClause, parameters, hints.setShardColValue("tableIndex", i));
        model = assertModel(model, hints);
        assertEquals(1, model.getId().intValue());
        assertEquals(i, model.getTableIndex().intValue());
        // By parameters
        whereClause += " and tableIndex=?";
        parameters = new StatementParameters();
        parameters.set(1, "type", Types.SMALLINT, 1);
        parameters.set(2, "tableIndex", Types.SMALLINT, i);
        model = dao.queryFirst(whereClause, parameters, hints);
        model = assertModel(model, hints);
        assertEquals(1, model.getId().intValue());
        assertEquals(i, model.getTableIndex().intValue());
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 68 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method testQueryTopWithWhereClauseFailed.

private void testQueryTopWithWhereClauseFailed(DalHints hints) throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 10);
    List<ClientTestModel> models;
    try {
        hints = copy(hints);
        models = dao.queryTop(whereClause, parameters, hints, 2);
        models = assertModels(models, hints);
        Assert.fail();
    } catch (Exception e) {
    }
    models = dao.queryTop(whereClause, parameters, new DalHints().inTableShard(1).inShard(0), 2);
    Assert.assertTrue(null != models);
    Assert.assertEquals(0, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) SQLException(java.sql.SQLException)

Example 69 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method testInsertMultipleAsListByField.

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

Example 70 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method testQueryByPkWithEntity.

@Test
public void testQueryByPkWithEntity() throws SQLException {
    testQueryByPkWithEntity(new DalHints());
    testQueryByPkWithEntity(asyncHints());
    testQueryByPkWithEntity(callbackHints());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) 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