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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations