Search in sources :

Example 51 with FreeSelectSqlBuilder

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

the class DaoByFreeSql method updateTask.

public int updateTask(GenTaskByFreeSql task) throws SQLException {
    {
        FreeSelectSqlBuilder<GenTaskByFreeSql> builder = new FreeSelectSqlBuilder<>(dbCategory);
        builder.setTemplate("SELECT * FROM task_sql WHERE id != ? AND project_id=? AND db_name=? AND class_name=? AND method_name=? LIMIT 1");
        StatementParameters parameters = new StatementParameters();
        int i = 1;
        parameters.set(i++, "id", Types.INTEGER, task.getId());
        parameters.set(i++, "project_id", Types.INTEGER, task.getProject_id());
        parameters.set(i++, "db_name", Types.VARCHAR, task.getDatabaseSetName());
        parameters.set(i++, "class_name", Types.VARCHAR, task.getClass_name());
        parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
        builder.mapWith(genTaskByFreeSqlRowMapper).requireFirst().nullable();
        DalHints hints = DalHints.createIfAbsent(null).allowPartial();
        GenTaskByFreeSql entity = queryDao.query(builder, parameters, hints);
        if (entity != null)
            return 0;
    }
    FreeUpdateSqlBuilder builder = new FreeUpdateSqlBuilder(dbCategory);
    StringBuilder sb = new StringBuilder();
    sb.append("UPDATE task_sql SET project_id=?, db_name=?,class_name=?,pojo_name=?,");
    sb.append("method_name=?,crud_type=?,sql_content=?,parameters=?,`generated`=?,");
    sb.append("version=version+1,update_user_no=?,update_time=?,comment=?,");
    sb.append("scalarType=?,pojoType=?,pagination=?,sql_style=?,approved=?,approveMsg=?,hints=? ");
    sb.append(" WHERE id=? AND version=?");
    builder.setTemplate(sb.toString());
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "project_id", Types.INTEGER, task.getProject_id());
    parameters.set(i++, "db_name", Types.VARCHAR, task.getDatabaseSetName());
    parameters.set(i++, "class_name", Types.VARCHAR, task.getClass_name());
    parameters.set(i++, "pojo_name", Types.VARCHAR, task.getPojo_name());
    parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
    parameters.set(i++, "crud_type", Types.VARCHAR, task.getCrud_type());
    parameters.set(i++, "sql_content", Types.LONGVARCHAR, task.getSql_content());
    parameters.set(i++, "parameters", Types.LONGVARCHAR, task.getParameters());
    parameters.set(i++, "generated", Types.BIT, task.getGenerated());
    parameters.set(i++, "update_user_no", Types.VARCHAR, task.getUpdate_user_no());
    parameters.set(i++, "update_time", Types.TIMESTAMP, task.getUpdate_time());
    parameters.set(i++, "comment", Types.LONGVARCHAR, task.getComment());
    parameters.set(i++, "scalarType", Types.VARCHAR, task.getScalarType());
    parameters.set(i++, "pojoType", Types.VARCHAR, task.getPojoType());
    parameters.set(i++, "pagination", Types.BIT, task.getPagination());
    parameters.set(i++, "sql_style", Types.VARCHAR, task.getSql_style());
    parameters.set(i++, "approved", Types.INTEGER, task.getApproved());
    parameters.set(i++, "approveMsg", Types.LONGVARCHAR, task.getApproveMsg());
    parameters.set(i++, "hints", Types.VARCHAR, task.getHints());
    // parameters.set(i++, "length", Types.TINYINT, task.getLength());
    parameters.set(i++, "id", Types.INTEGER, task.getId());
    parameters.set(i++, "version", Types.INTEGER, task.getVersion());
    DalHints hints = DalHints.createIfAbsent(null);
    return queryDao.update(builder, parameters, hints);
}
Also used : FreeSelectSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder) DalHints(com.ctrip.platform.dal.dao.DalHints) FreeUpdateSqlBuilder(com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters) GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)

Example 52 with FreeSelectSqlBuilder

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

the class UserGroupDao method getUserGroupByGroupIdAndUserId.

public List<UserGroup> getUserGroupByGroupIdAndUserId(Integer groupId, Integer userId) throws SQLException {
    FreeSelectSqlBuilder<List<UserGroup>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, user_id, group_id, role, adduser FROM user_group WHERE group_id = ? AND user_id=?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "group_id", Types.INTEGER, groupId);
    parameters.set(i++, "user_id", Types.INTEGER, userId);
    builder.mapWith(userGroupRowMapper);
    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 53 with FreeSelectSqlBuilder

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

the class UserGroupDao method getUserGroupByUserId.

public List<UserGroup> getUserGroupByUserId(Integer userId) throws SQLException {
    FreeSelectSqlBuilder<List<UserGroup>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, user_id, group_id, role, adduser FROM user_group WHERE user_id = ?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "user_id", Types.INTEGER, userId);
    builder.mapWith(userGroupRowMapper);
    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 54 with FreeSelectSqlBuilder

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

the class DaoOfUserProject method getMinUserProjectByProjectId.

public UserProject getMinUserProjectByProjectId(int project_id) throws SQLException {
    FreeSelectSqlBuilder<UserProject> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id,project_id, user_no FROM user_project WHERE id=(SELECT min(id) FROM user_project WHERE project_id = ?)");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "project_id", Types.INTEGER, project_id);
    builder.mapWith(userProjectRowMapper).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) UserProject(com.ctrip.platform.dal.daogen.entity.UserProject) StatementParameters(com.ctrip.platform.dal.dao.StatementParameters)

Example 55 with FreeSelectSqlBuilder

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

the class DaoOfUserProject method getUserProjectsByUser.

public List<UserProject> getUserProjectsByUser(String userNo) throws SQLException {
    FreeSelectSqlBuilder<List<UserProject>> builder = new FreeSelectSqlBuilder<>(dbCategory);
    builder.setTemplate("SELECT id, project_id, user_no FROM user_project WHERE user_no = ?");
    StatementParameters parameters = new StatementParameters();
    int i = 1;
    parameters.set(i++, "user_no", Types.VARCHAR, userNo);
    builder.mapWith(userProjectRowMapper);
    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)

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