Search in sources :

Example 91 with DalHints

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

the class DalConnectionTest method testApplyHints.

@Test
public void testApplyHints() throws SQLException {
    Connection conn = null;
    try {
        DalConnection test = getConnection();
        DalHints hints = new DalHints();
        hints.setIsolationLevel(Connection.TRANSACTION_SERIALIZABLE);
        test.applyHints(hints);
        conn = test.getConn();
        assertTrue(conn.getTransactionIsolation() == Connection.TRANSACTION_SERIALIZABLE);
        hints.setIsolationLevel(Connection.TRANSACTION_NONE);
        test.applyHints(hints);
        assertTrue(conn.getTransactionIsolation() == Connection.TRANSACTION_NONE);
    } catch (Throwable e) {
        fail();
        e.printStackTrace();
    } finally {
        if (conn != null)
            conn.close();
    }
}
Also used : DalConnection(com.ctrip.platform.dal.dao.client.DalConnection) DalHints(com.ctrip.platform.dal.dao.DalHints) Connection(java.sql.Connection) DalConnection(com.ctrip.platform.dal.dao.client.DalConnection) Test(org.junit.Test)

Example 92 with DalHints

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

the class DalDefaultJpaParserSqlServerTest2 method testBatch.

@Test
public void testBatch() throws SQLException {
    ClientTestModel[] models = new ClientTestModel[ROW_COUNT];
    for (int i = 0; i < ROW_COUNT; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setQuantity(10 + 1 % 3);
        model.setType(((Number) (1 % 3)).shortValue());
        model.setAddress("CTRIP");
        models[i] = model;
    }
    DalHints hints = new DalHints();
    int[] res = dao.batchInsert(hints, Arrays.asList(models));
    Assert.assertEquals(ROW_COUNT, res.length);
    StatementParameters parameters = new StatementParameters();
    List<ClientTestModel> db_models = dao.query("1=1", parameters, hints);
    Assert.assertEquals(ROW_COUNT, db_models.size());
    dao.delete(hints, db_models);
    Assert.assertEquals(0, DalTestHelper.getCount(dao));
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 93 with DalHints

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

the class DalDefaultJpaParserSqlServerTest2 method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() {
    DalHints hints = new DalHints();
    String[] sqls = new String[] { String.format(DROP_TABLE_SQL, parser.getTableName(), parser.getTableName()), String.format(CREATE_TABLE_SQL, parser.getTableName()) };
    try {
        client.batchUpdate(sqls, hints);
    } catch (SQLException e) {
        e.printStackTrace();
        Assert.fail();
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) BeforeClass(org.junit.BeforeClass)

Example 94 with DalHints

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

the class DalDefaultJpaParserMySqlTest2 method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws Exception {
    DalHints hints = new DalHints();
    String[] sqls = new String[] { String.format(DROP_TABLE_SQL, parser.getTableName()), String.format(CREATE_TABLE_SQL, parser.getTableName()) };
    client.batchUpdate(sqls, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) BeforeClass(org.junit.BeforeClass)

Example 95 with DalHints

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

the class DalDefaultJpaParserMySqlTest2 method test.

@Test
public void test() throws SQLException {
    ClientTestModel[] models = new ClientTestModel[ROW_COUNT];
    for (int i = 0; i < ROW_COUNT; i++) {
        ClientTestModel model = new ClientTestModel();
        model.setQuantity(10 + 1 % 3);
        model.setType(((Number) (1 % 3)).shortValue());
        model.setAddress("CTRIP");
        models[i] = model;
    }
    DalHints hints = new DalHints();
    int[] res = dao.insert(hints, Arrays.asList(models));
    assertEquals(ROW_COUNT, res);
    StatementParameters parameters = new StatementParameters();
    List<ClientTestModel> db_models = dao.query("true", parameters, hints);
    Assert.assertNotNull(db_models.get(1).getId());
    Assert.assertTrue(db_models.get(2).getId() > 0);
    Assert.assertEquals(ROW_COUNT, db_models.size());
    res = dao.delete(hints, db_models);
    assertEquals(ROW_COUNT, res);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) 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