Search in sources :

Example 6 with DalQueryDao

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

the class SlaveFreshnessScannerMysqlTest method testBelow.

private void testBelow(int freshness) throws SQLException {
    DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
    for (int i = 0; i < 100; i++) {
        String id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints().freshness(freshness), String.class);
        Assert.assertTrue(freshnessMap.get(id) <= freshness);
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao)

Example 7 with DalQueryDao

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

the class SlaveFreshnessScannerMysqlTest method testNoFreshness.

@Test
public void testNoFreshness() throws SQLException {
    DalQueryDao dao = new DalQueryDao(NO_FRESHNESS_DATABASE_NAME);
    String id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints().freshness(10), String.class);
    Assert.assertEquals(NO_FRESHNESS_MASTER, id);
    try {
        dao = new DalQueryDao(NO_FRESHNESS_DATABASE_NAME);
        id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints().freshness(10).slaveOnly(), String.class);
        Assert.fail();
    } catch (Exception e) {
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) SQLException(java.sql.SQLException) Test(org.junit.Test)

Example 8 with DalQueryDao

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

the class SlaveFreshnessScannerMysqlTest method testSlaveOnlyAndFreshness.

@Test
public void testSlaveOnlyAndFreshness() throws SQLException {
    int freshness = 9;
    DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
    for (int i = 0; i < 100; i++) {
        String id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints().freshness(freshness).slaveOnly(), String.class);
        Assert.assertTrue(freshnessMap.get(id) <= freshness);
    }
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao) Test(org.junit.Test)

Example 9 with DalQueryDao

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

the class DalColumnMapRowMapperTest method testDalColumnMapRowMapperList.

@Test
public void testDalColumnMapRowMapperList() {
    try {
        StatementParameters parameters = new StatementParameters();
        DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
        List<Map<String, Object>> result = dao.query(sqlList, parameters, hints, new DalColumnMapRowMapper());
        assertEquals(3, result.size());
    } catch (Exception e) {
        fail();
    }
}
Also used : 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 10 with DalQueryDao

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

the class TaskAdapter method initialize.

public void initialize(DalParser<T> parser) {
    this.client = DalClientFactory.getClient(parser.getDatabaseName());
    this.parser = parser;
    this.logicDbName = parser.getDatabaseName();
    queryDao = new DalQueryDao(parser.getDatabaseName());
    rawTableName = parser.getTableName();
    tableShardingEnabled = isTableShardingEnabled(logicDbName, rawTableName);
    initColumnTypes();
    dbCategory = getDatabaseSet(logicDbName).getDatabaseCategory();
    initDbSpecific();
    initSensitiveColumns();
}
Also used : DalQueryDao(com.ctrip.platform.dal.dao.DalQueryDao)

Aggregations

DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)20 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)19 DalHints (com.ctrip.platform.dal.dao.DalHints)13 Test (org.junit.Test)9 SQLException (java.sql.SQLException)7 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)6 DalDefaultJpaMapper (com.ctrip.platform.dal.dao.helper.DalDefaultJpaMapper)4 DalColumnMapRowMapper (com.ctrip.platform.dal.dao.helper.DalColumnMapRowMapper)3 Map (java.util.Map)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 DalClient (com.ctrip.platform.dal.dao.DalClient)1 HashMap (java.util.HashMap)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BeforeClass (org.junit.BeforeClass)1