Search in sources :

Example 86 with SelectSqlBuilder

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

the class BaseDalTabelDaoShardByTableTest method testQueryListBySimpleTypeInTableShards.

@Test
public void testQueryListBySimpleTypeInTableShards() throws SQLException {
    Set<String> tableShards = new HashSet<>();
    tableShards.add("0");
    // expected 1 record
    SelectSqlBuilder ssb1 = new SelectSqlBuilder();
    ssb1.selectAll().from(TABLE_NAME).where(" id = 1 ");
    List<Integer> list1 = dao.query(ssb1, new DalHints().inTableShards(tableShards), Integer.class);
    assertEquals(1, list1.size());
    // expected 2 records
    tableShards.add("1");
    List<Integer> list2 = dao.query(ssb1, new DalHints().inTableShards(tableShards), Integer.class);
    assertEquals(2, list2.size());
    // expected 3 records
    tableShards.add("2");
    List<Integer> list3 = dao.query(ssb1, new DalHints().inTableShards(tableShards), Integer.class);
    assertEquals(3, list3.size());
    // expected 4 records
    tableShards.add("3");
    List<Integer> list4 = dao.query(ssb1, new DalHints().inTableShards(tableShards), Integer.class);
    assertEquals(4, list4.size());
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 87 with SelectSqlBuilder

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

the class BaseDalTabelDaoShardByTableTest method testCountTableShardBy2.

@Test
public void testCountTableShardBy2() throws SQLException {
    int index = 1;
    List<Integer> list = new ArrayList<>();
    list.add(0);
    list.add(1);
    StatementParameters parameters = new StatementParameters();
    parameters.setInParameter(index, "tableIndex", Types.BIGINT, list);
    SelectSqlBuilder ssb1 = new SelectSqlBuilder();
    ssb1.selectAll().from(TABLE_NAME).where(" tableIndex in (?) ").with(parameters).selectCount();
    Number count1 = dao.count(ssb1, new DalHints().tableShardBy("tableIndex"));
    assertEquals(3L, count1);
}
Also used : ArrayList(java.util.ArrayList) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder) Test(org.junit.Test)

Example 88 with SelectSqlBuilder

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

the class DaoByFreeSql method getAllTasks.

public List<GenTaskByFreeSql> getAllTasks() throws SQLException {
    DalHints hints = DalHints.createIfAbsent(null);
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAll();
    List<GenTaskByFreeSql> list = client.query(builder, hints);
    processList(list);
    return list;
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)

Example 89 with SelectSqlBuilder

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

the class DaoOfLoginUser method getAllUsers.

public List<LoginUser> getAllUsers() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAll();
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    return client.query(builder, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)

Example 90 with SelectSqlBuilder

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

the class ConfigTemplateDao method getAllConfigTemplates.

public List<ConfigTemplate> getAllConfigTemplates() throws SQLException {
    SelectSqlBuilder builder = new SelectSqlBuilder().selectAll();
    DalHints hints = DalHints.createIfAbsent(null);
    return client.query(builder, hints);
}
Also used : DalHints(com.ctrip.platform.dal.dao.DalHints) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) SelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)

Aggregations

SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)93 Test (org.junit.Test)71 ArrayList (java.util.ArrayList)35 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)28 DalHints (com.ctrip.platform.dal.dao.DalHints)15 SQLException (java.sql.SQLException)15 ClientTestModel (com.ctrip.platform.dal.dao.unitbase.ClientTestModel)5 HashSet (java.util.HashSet)5 DalTableDao (com.ctrip.platform.dal.dao.DalTableDao)4 DalException (com.ctrip.platform.dal.exceptions.DalException)4 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)3 ClientTestModel (test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel)3 LocalDalPropertiesProvider (com.ctrip.platform.dal.dao.configure.LocalDalPropertiesProvider)1 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)1 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)1