Search in sources :

Example 11 with FreeSelectSqlBuilder

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

the class DalQueryDaoTest method testQueryListAllShardsBuilderWhen.

@Test
public void testQueryListAllShardsBuilderWhen() throws SQLException {
    String address = null;
    Integer id = 1;
    FreeSelectSqlBuilder<List<ClientTestModel>> query = new FreeSelectSqlBuilder<>();
    query.selectAll().from(TABLE_NAME).where(like("address ").when(address != null), AND, equal("id").when(id != null));
    query.mapWith(ClientTestModel.class);
    DalQueryDao dao = new DalQueryDao(logicDbName);
    StatementParameters parameters = new StatementParameters();
    parameters.set(1, 1);
    List<ClientTestModel> l = dao.query(query, parameters, new DalHints().inAllShards());
    Assert.assertTrue(l.size() > 0);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 12 with FreeSelectSqlBuilder

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

the class DaoByTableViewSp method getTasksByProjectId.

/**
 * 根据项目主键查询所有任务
 *
 * @param projectId
 * @return
 */
public List<GenTaskByTableViewSp> getTasksByProjectId(int projectId) throws SQLException {
    FreeSelectSqlBuilder<List<GenTaskByTableViewSp>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT id, project_id,db_name,table_names,view_names,sp_names,prefix,suffix, cud_by_sp,pagination,`generated`,version,update_user_no,update_time,comment,sql_style,api_list,approved,approveMsg, mode_type ");
    sb.append("FROM task_table WHERE project_id=? order by id");
    builder.setTemplate(sb.toString());
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "project_id", Types.INTEGER, projectId);
    builder.mapWith(genTaskByTableViewSpRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    List<GenTaskByTableViewSp> list = queryDao.query(builder, parameters, hints);
    processList(list);
    return list;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) ArrayList(java.util.ArrayList) List(java.util.List)

Example 13 with FreeSelectSqlBuilder

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

the class DaoOfDatabaseSet method getAllDatabaseSetEntryByDbsetid.

public List<DatabaseSetEntry> getAllDatabaseSetEntryByDbsetid(Integer databaseSet_Id) throws SQLException {
    FreeSelectSqlBuilder<List<DatabaseSetEntry>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, name, databaseType, sharding, connectionString, databaseSet_Id, update_user_no, update_time FROM databasesetentry WHERE databaseSet_Id = ?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "databaseSet_Id", Types.INTEGER, databaseSet_Id);
    builder.mapWith(databaseSetEntryRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    List<DatabaseSetEntry> list = queryDao.query(builder, parameters, hints);
    processEntryList(list);
    return list;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) List(java.util.List) DatabaseSetEntry(com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)

Example 14 with FreeSelectSqlBuilder

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

the class DaoOfDatabaseSet method getAllDatabaseSetByGroupId.

public List<DatabaseSet> getAllDatabaseSetByGroupId(Integer groupId) throws SQLException {
    FreeSelectSqlBuilder<List<DatabaseSet>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, name, provider, shardingStrategy, groupId, update_user_no, update_time, mode_type FROM databaseset WHERE groupId = ?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "groupId", Types.INTEGER, groupId);
    builder.mapWith(databaseSetRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    List<DatabaseSet> list = queryDao.query(builder, parameters, hints);
    processList(list);
    return list;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) DatabaseSet(com.ctrip.platform.dal.daogen.entity.DatabaseSet) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) List(java.util.List)

Example 15 with FreeSelectSqlBuilder

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

the class DaoOfDatabaseSet method getAllDatabaseSetByName.

public List<DatabaseSet> getAllDatabaseSetByName(String name) throws SQLException {
    FreeSelectSqlBuilder<List<DatabaseSet>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, name, provider, shardingStrategy, groupId, update_user_no, update_time FROM databaseset WHERE name = ?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "name", Types.VARCHAR, name);
    builder.mapWith(databaseSetRowMapper);
    DalHints hints = DalHints.createIfAbsent(null).allowPartial();
    List<DatabaseSet> list = queryDao.query(builder, parameters, hints);
    processList(list);
    return list;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) DatabaseSet(com.ctrip.platform.dal.daogen.entity.DatabaseSet) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) List(java.util.List)

Aggregations

FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)61 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)44 DalHints (com.ctrip.platform.dal.dao.DalHints)38 List (java.util.List)38 ArrayList (java.util.ArrayList)22 Test (org.junit.Test)17 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 DalQueryDao (com.ctrip.platform.dal.dao.DalQueryDao)6 ShortRowMapper (com.ctrip.platform.dal.dao.helper.ShortRowMapper)6 DalDefaultJpaMapper (com.ctrip.platform.dal.dao.helper.DalDefaultJpaMapper)4 DatabaseSet (com.ctrip.platform.dal.daogen.entity.DatabaseSet)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)3 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)3 DalCustomRowMapper (com.ctrip.platform.dal.dao.helper.DalCustomRowMapper)2 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)2 DatabaseSetEntry (com.ctrip.platform.dal.daogen.entity.DatabaseSetEntry)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 Project (com.ctrip.platform.dal.daogen.entity.Project)2 Map (java.util.Map)2 ClientTestModel (com.ctrip.platform.dal.dao.unitbase.ClientTestModel)1