Search in sources :

Example 21 with StatementParameters

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

the class DalTabelDaoShardByTableMySqlTest method tearDown.

@After
public void tearDown() throws Exception {
    String sql = "DELETE FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    DalHints hints = new DalHints();
    try {
        for (int i = 0; i < mod; i++) {
            clientMySql.update(sql + "_" + i, parameters, hints);
        }
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) After(org.junit.After)

Example 22 with StatementParameters

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

the class DalTableDaoShardByDbOracleTest method tearDown.

@After
public void tearDown() throws Exception {
    String sql = "DELETE FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    DalHints hints = new DalHints();
    try {
        for (int i = 0; i < mod; i++) {
            client.update(sql, parameters, hints.inShard(i));
        }
    } catch (SQLException e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) After(org.junit.After)

Example 23 with StatementParameters

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

the class DalTableDaoShardByDbSqlSvrTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    DalClientFactory.initClientFactory();
    clientSqlSvr = DalClientFactory.getClient(DATABASE_NAME_SQLSVR);
    DalHints hints = new DalHints();
    String[] sqls = null;
    // For SQL server
    hints = new DalHints();
    StatementParameters parameters = new StatementParameters();
    for (int i = 0; i < mod; i++) {
        sqls = new String[] { DROP_TABLE_SQL_SQLSVR_TPL, CREATE_TABLE_SQL_SQLSVR_TPL };
        for (int j = 0; j < sqls.length; j++) {
            clientSqlSvr.update(sqls[j], parameters, hints.inShard(i));
        }
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) BeforeClass(org.junit.BeforeClass)

Example 24 with StatementParameters

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

the class DalTableDaoShardByDbTableSqlSvrTest method tearDown.

@After
public void tearDown() throws SQLException {
    String sql = "DELETE FROM " + TABLE_NAME;
    StatementParameters parameters = new StatementParameters();
    DalHints hints = new DalHints();
    sql = "DELETE FROM " + TABLE_NAME;
    parameters = new StatementParameters();
    hints = new DalHints();
    try {
        for (int j = 0; j < mod; j++) {
            for (int i = 0; i < tableMod; i++) {
                clientSqlSvr.update(sql + "_" + i, parameters, hints.inShard(j));
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) After(org.junit.After)

Example 25 with StatementParameters

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

the class BaseDalTabelDaoShardByTableTest method testQueryTopWithWhereClauseFailedCallback.

@Test
public void testQueryTopWithWhereClauseFailedCallback() throws SQLException {
    String whereClause = "type=?";
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, Types.SMALLINT, 10);
    List<ClientTestModel> models;
    DefaultResultCallback callback = new DefaultResultCallback();
    DalHints hints = new DalHints().callbackWith(callback);
    models = dao.queryTop(whereClause, parameters, hints, 2);
    try {
        callback.waitForDone();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    assertTrue(!callback.isSuccess());
    assertNull(callback.getResult());
    assertNotNull(callback.getError());
    models = dao.queryTop(whereClause, parameters, new DalHints().inTableShard(1), 2);
    assertTrue(null != models);
    assertEquals(0, models.size());
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DefaultResultCallback(com.ctrip.platform.dal.dao.helper.DefaultResultCallback) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Aggregations

StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)360 DalHints (com.ctrip.platform.dal.dao.DalHints)317 Test (org.junit.Test)209 SQLException (java.sql.SQLException)102 ArrayList (java.util.ArrayList)51 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)40 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)40 List (java.util.List)29 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)20 DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)19 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)17 After (org.junit.After)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)15 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)14 ResultSet (java.sql.ResultSet)10 DalClient (com.ctrip.platform.dal.dao.DalClient)9 AfterClass (org.junit.AfterClass)9 BeforeClass (org.junit.BeforeClass)9 AbstractFreeSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.AbstractFreeSqlBuilder)8 Map (java.util.Map)8