use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DaoBySqlBuilder method updateAndGetTasks.
public List<GenTaskBySqlBuilder> updateAndGetTasks(int projectId) throws SQLException {
FreeSelectSqlBuilder<List<GenTaskBySqlBuilder>> builder = new FreeSelectSqlBuilder<>(dbCategory);
StringBuilder sb = new StringBuilder();
sb.append("SELECT id, project_id, db_name,table_name,class_name,method_name,sql_style,crud_type,fields,where_condition,sql_content,`generated`,version,update_user_no,update_time,comment,scalarType,pagination,orderby,approved,approveMsg,hints ");
sb.append("FROM task_auto WHERE project_id=? AND `generated`=FALSE");
builder.setTemplate(sb.toString());
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.set(i++, "project_id", Types.INTEGER, projectId);
builder.mapWith(genTaskBySqlBuilderRowMapper);
DalHints hints = DalHints.createIfAbsent(null).allowPartial();
List<GenTaskBySqlBuilder> list = queryDao.query(builder, parameters, hints);
List<GenTaskBySqlBuilder> result = new ArrayList<>();
if (list == null || list.size() == 0)
return result;
processList(list);
for (GenTaskBySqlBuilder entity : list) {
entity.setGenerated(true);
if (updateTask(entity) > 0) {
result.add(entity);
}
}
return result;
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DaoOfLoginUser method getUserByNo.
public LoginUser getUserByNo(String userNo) throws SQLException {
FreeSelectSqlBuilder<LoginUser> builder = new FreeSelectSqlBuilder<>(dbCategory);
builder.setTemplate("SELECT id, user_no, user_name, user_email, password FROM login_users WHERE user_no = ?");
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.setSensitive(i++, "user_no", Types.VARCHAR, userNo);
builder.mapWith(loginUserRowMapper).requireFirst().nullable();
DalHints hints = DalHints.createIfAbsent(null).allowPartial();
return queryDao.query(builder, parameters, hints);
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DaoOfLoginUser method getUserByGroupId.
public List<LoginUser> getUserByGroupId(int groupId) throws SQLException {
FreeSelectSqlBuilder<List<LoginUser>> builder = new FreeSelectSqlBuilder<>(dbCategory);
builder.setTemplate("SELECT tb2.id, tb2.user_no, tb2.user_name, tb2.user_email, tb2.password, tb1.role, tb1.adduser FROM user_group tb1 LEFT JOIN login_users tb2 ON tb1.user_id = tb2.id WHERE tb1.group_id = ?");
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.setSensitive(i++, "group_id", Types.INTEGER, groupId);
builder.mapWith(loginUserRowMapper);
DalHints hints = DalHints.createIfAbsent(null).allowPartial();
return queryDao.query(builder, parameters, hints);
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DalQueryDaoTestStub method testQueryForObjectSuccess.
/**
* Test query for object success
* @throws SQLException
*/
@Test
public void testQueryForObjectSuccess() throws SQLException {
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
StatementParameters param = new StatementParameters();
DalHints hints = new DalHints();
ClientTestModel model = client.queryForObject(sql, param, hints, mapper);
Assert.assertEquals(1, model.getId().intValue());
FreeSelectSqlBuilder<List<Map<String, Object>>> builder = new FreeSelectSqlBuilder<>();
builder.append("select count(*) as c1, 111 as c2");
builder.mapWith(new DalCustomRowMapper("c1", "c2"));
builder.with(new StatementParameters());
List<Map<String, Object>> l = client.query(builder, hints);
}
use of com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder in project dal by ctripcorp.
the class DalQueryDaoTestStub method testQueryForObjectSuccess.
/**
* Test query for object success
* @throws SQLException
*/
@Test
public void testQueryForObjectSuccess() throws SQLException {
String sql = "SELECT * FROM " + TABLE_NAME + " WHERE id = 1";
StatementParameters param = new StatementParameters();
DalHints hints = new DalHints();
ClientTestModel model = client.queryForObject(sql, param, hints, mapper);
Assert.assertEquals(1, model.getId().intValue());
FreeSelectSqlBuilder<List<Map<String, Object>>> builder = new FreeSelectSqlBuilder<>();
builder.append("select count(*) as c1, 111 as c2");
builder.mapWith(new DalCustomRowMapper("c1", "c2"));
builder.with(new StatementParameters());
List<Map<String, Object>> l = client.query(builder, hints);
}
Aggregations