Search in sources :

Example 26 with FreeSelectSqlBuilder

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;
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Example 27 with FreeSelectSqlBuilder

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);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) LoginUser(com.ctrip.platform.dal.daogen.entity.LoginUser)

Example 28 with FreeSelectSqlBuilder

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

Example 29 with FreeSelectSqlBuilder

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);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) ClientTestModel(com.ctrip.platform.dal.dao.unitbase.ClientTestModel) DalCustomRowMapper(com.ctrip.platform.dal.dao.helper.DalCustomRowMapper) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 30 with FreeSelectSqlBuilder

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);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) ClientTestModel(test.com.ctrip.platform.dal.dao.unitbase.ClientTestModel) DalCustomRowMapper(com.ctrip.platform.dal.dao.helper.DalCustomRowMapper) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

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