Search in sources :

Example 11 with DalHints

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

the class PartialQueryTableDaoUnitTest method testDetectFieldNotExist.

@Test
public void testDetectFieldNotExist() throws Exception {
    DalTableDao<PersonWithoutName> client = new DalTableDao<>(new DalDefaultJpaParser<>(PersonWithoutName.class));
    List<Integer> peopleIds = new ArrayList<>();
    peopleIds.add(1);
    peopleIds.add(2);
    peopleIds.add(3);
    List<Integer> cityIds = new ArrayList<>();
    cityIds.add(1);
    cityIds.add(2);
    cityIds.add(3);
    SelectSqlBuilder builder = new SelectSqlBuilder();
    builder.select("DataChange_LastTime", "CityID", "Name", "ProvinceID", "PeopleID", "CountryID");
    builder.in("PeopleID", peopleIds, Types.INTEGER, false);
    builder.and();
    builder.in("CityID", cityIds, Types.INTEGER, false);
    try {
        client.query(builder, new DalHints().inAllShards().inTableShard(1));
        Assert.fail();
    } catch (DalException e) {
        e.printStackTrace();
        assertEquals(ErrorCode.FieldNotExists.getCode(), e.getErrorCode());
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) DalException(com.ctrip.platform.dal.exceptions.DalException) ArrayList(java.util.ArrayList) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) DalTableDao(com.ctrip.platform.dal.dao.DalTableDao) Test(org.junit.Test)

Example 12 with DalHints

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

the class DalColumnMapRowMapperTest method tearDownAfterClass.

@AfterClass
public static void tearDownAfterClass() throws Exception {
    DalHints hints = new DalHints();
    StatementParameters parameters = new StatementParameters();
    String[] sqls = new String[] { DROP_TABLE_SQL };
    for (int i = 0; i < sqls.length; i++) {
        client.update(sqls[i], parameters, hints);
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) AfterClass(org.junit.AfterClass)

Example 13 with DalHints

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

the class DalColumnMapRowMapperTest method setUp.

@Before
public void setUp() throws Exception {
    DalHints hints = new DalHints();
    String[] insertSqls = new String[] { "SET IDENTITY_INSERT " + TABLE_NAME + " ON", "INSERT INTO " + TABLE_NAME + "(Id, quantity,type,address)" + " VALUES(1, 10, 1, 'SH INFO')", "INSERT INTO " + TABLE_NAME + "(Id, quantity,type,address)" + " VALUES(2, 11, 1, 'BJ INFO')", "INSERT INTO " + TABLE_NAME + "(Id, quantity,type,address)" + " VALUES(3, 12, 2, 'SZ INFO')", "SET IDENTITY_INSERT " + TABLE_NAME + " OFF" };
    client.batchUpdate(insertSqls, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) Before(org.junit.Before)

Example 14 with DalHints

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperEmpty.

@Test
public void testDalColumnMapRowMapperEmpty() {
    try {
        StatementParameters parameters = new StatementParameters();
        DalClient client = DalClientFactory.getClient(DATABASE_NAME);
        List<Map<String, Object>> result1 = client.query(sqlNoResult, parameters, new DalHints(), new DalRowMapperExtractor<Map<String, Object>>(new DalColumnMapRowMapper()));
        assertEquals(0, result1.size());
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlNoResult, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(0, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : DalClient(com.ctrip.platform.dal.dao.DalClient) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalColumnMapRowMapper(com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Map(java.util.Map) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 15 with DalHints

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

the class MySqlHelperTest method tearDownAfterClass.

@AfterClass
public static void tearDownAfterClass() throws Exception {
    DalHints hints = new DalHints();
    String[] sqls = new String[] { DROP_TABLE_SQL_MYSQL_TPL };
    clientMySql.batchUpdate(sqls, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) AfterClass(org.junit.AfterClass)

Aggregations

DalHints (com.ctrip.platform.dal.dao.DalHints)621 Test (org.junit.Test)473 SQLException (java.sql.SQLException)278 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)245 ArrayList (java.util.ArrayList)113 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)57 Future (java.util.concurrent.Future)32 KeyHolder (com.ctrip.platform.dal.dao.KeyHolder)27 DataBase (com.ctrip.platform.dal.dao.configure.DataBase)26 DatabaseSelector (com.ctrip.platform.dal.dao.configure.DatabaseSelector)26 DalDefaultJpaParser (com.ctrip.platform.dal.dao.helper.DalDefaultJpaParser)25 AfterClass (org.junit.AfterClass)23 BeforeClass (org.junit.BeforeClass)23 List (java.util.List)22 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)20 BatchUpdateTask (com.ctrip.platform.dal.dao.task.BatchUpdateTask)18 After (org.junit.After)17 Before (org.junit.Before)17 HashMap (java.util.HashMap)16 Map (java.util.Map)16