Search in sources :

Example 86 with DalHints

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

the class BaseDalTableDaoShardByDbTableTest method deleteAllShards.

public void deleteAllShards(int shardId) throws SQLException {
    for (int i = 0; i < tableMod; i++) {
        int j = 1;
        dao.delete("1=1", new StatementParameters(), new DalHints().inShard(shardId).inTableShard(i));
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters)

Example 87 with DalHints

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

the class BaseDalTableDaoShardByDbTest method testCrossShardDelete.

@Test
public void testCrossShardDelete() {
    try {
        int[] res;
        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(1);
        p.setAddress("aaa");
        p.setTableIndex(1);
        pList[1] = p;
        p = new ClientTestModel();
        p.setId(2);
        p.setAddress("aaa");
        p.setTableIndex(2);
        pList[2] = p;
        p = new ClientTestModel();
        p.setId(2);
        p.setAddress("aaa");
        p.setTableIndex(3);
        pList[3] = p;
        p = new ClientTestModel();
        p.setId(3);
        p.setAddress("aaa");
        p.setTableIndex(5);
        pList[4] = p;
        p = new ClientTestModel();
        p.setId(3);
        p.setAddress("aaa");
        p.setTableIndex(6);
        pList[5] = p;
        DalHints hints = new DalHints();
        res = dao.batchDelete(hints, Arrays.asList(pList));
        assertEquals(0, getCountByDb(dao, 0));
        assertEquals(0, getCountByDb(dao, 1));
        assertResEquals(new int[] { 1, 1, 1, 1, 1, 1 }, res);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 88 with DalHints

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

the class BaseDalTableDaoShardByDbTest method testUpdatePlainAllShardsAsync.

@Test
public void testUpdatePlainAllShardsAsync() throws SQLException {
    String sql = "UPDATE " + TABLE_NAME + " SET address = 'CTRIP' WHERE id = 1";
    StatementParameters parameters = new StatementParameters();
    DalHints hints = new DalHints().asyncExecution();
    int res;
    // By allShards
    sql = "UPDATE " + TABLE_NAME + " SET address = 'CTRIP' WHERE id = 1";
    res = dao.update(sql, parameters, hints.inAllShards());
    assertEquals(0, res);
    res = getInt(hints);
    assertResEquals(2, res);
    assertEquals("CTRIP", dao.queryByPk(1, new DalHints().inShard(0)).getAddress());
    assertEquals("CTRIP", dao.queryByPk(1, new DalHints().inShard(1)).getAddress());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 89 with DalHints

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

the class BaseDalTableDaoShardByDbTest method testBatchUpdateMultipleCallback.

public void testBatchUpdateMultipleCallback() 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");
    IntCallback callback = new IntCallback();
    hints = new DalHints().callbackWith(callback);
    ress = dao.batchUpdate(hints, entities);
    assertNull(ress);
    ress = callback.getIntArray();
    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)

Example 90 with DalHints

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

the class ConnectionActionTest method testStart.

@Test
public void testStart() {
    TestConnectionAction test = new TestConnectionAction();
    test.initLogEntry(connectionString, new DalHints());
    test.start();
    assertTrue(test.start > 0);
}
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