Search in sources :

Example 41 with StatementParameters

use of com.ctrip.platform.dal.dao.StatementParameters 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 42 with StatementParameters

use of com.ctrip.platform.dal.dao.StatementParameters 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)

Example 43 with StatementParameters

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

the class DalDefaultJpaParserSqlServerTest 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 44 with StatementParameters

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

the class BaseDalTabelDaoShardByTableTest method testQueryWithWhereClauseAsymcCallback.

@Test
public void testQueryWithWhereClauseAsymcCallback() throws SQLException {
    List<ClientTestModel> models = null;
    DalHints hints;
    for (int i = 0; i < mod; i++) {
        String whereClause = "type=? and id=?";
        StatementParameters parameters = new StatementParameters();
        parameters.set(1, Types.SMALLINT, 1);
        parameters.set(2, Types.INTEGER, 1);
        // By tabelShard
        hints = new DalHints().asyncExecution();
        models = dao.query(whereClause, parameters, hints.inTableShard(i));
        models = assertModels(models, hints);
        assertEquals(1, models.size());
        assertEquals("SH INFO", models.get(0).getAddress());
        assertEquals(models.get(0).getTableIndex(), new Integer(i));
        // By tableShardValue
        hints = callbackHints();
        models = dao.query(whereClause, parameters, hints.setTableShardValue(i));
        models = assertModels(models, hints);
        assertEquals(1, models.size());
        assertEquals("SH INFO", models.get(0).getAddress());
        assertEquals(models.get(0).getTableIndex(), new Integer(i));
        // By shardColValue
        hints = new DalHints().asyncExecution();
        models = dao.query(whereClause, parameters, hints.setShardColValue("index", i));
        models = assertModels(models, hints);
        assertEquals(1, models.size());
        assertEquals("SH INFO", models.get(0).getAddress());
        assertEquals(models.get(0).getTableIndex(), new Integer(i));
        // By shardColValue
        hints = callbackHints();
        models = dao.query(whereClause, parameters, hints.setShardColValue("tableIndex", i));
        models = assertModels(models, hints);
        assertEquals(1, models.size());
        assertEquals("SH INFO", models.get(0).getAddress());
        assertEquals(models.get(0).getTableIndex(), new Integer(i));
        // By parameters
        hints = new DalHints().asyncExecution();
        whereClause += " and tableIndex=?";
        parameters = new StatementParameters();
        parameters.set(1, "type", Types.SMALLINT, 1);
        parameters.set(2, "id", Types.SMALLINT, i + 1);
        parameters.set(3, "tableIndex", Types.SMALLINT, i);
        models = dao.query(whereClause, parameters, hints);
        models = assertModels(models, hints);
        assertEquals(1, models.size());
        assertEquals("SH INFO", models.get(0).getAddress());
        assertEquals(models.get(0).getTableIndex(), new Integer(i));
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) Test(org.junit.Test)

Example 45 with StatementParameters

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

the class MarkdownAndUpIntergration method testQuery.

private void testQuery(String logicName) throws SQLException {
    DalClient client = DalClientFactory.getClient(logicName);
    client.query("SELECT 1", new StatementParameters(), new DalHints(), new DalResultSetExtractor<Integer>() {

        @Override
        public Integer extract(ResultSet rs) throws SQLException {
            return null;
        }
    });
}
Also used : DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) SQLException(java.sql.SQLException) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ResultSet(java.sql.ResultSet)

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