Search in sources :

Example 1 with GenTaskByTableViewSp

use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp 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 2 with GenTaskByTableViewSp

use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.

the class DaoByTableViewSp method updateAndGetAllTasks.

public List<GenTaskByTableViewSp> updateAndGetAllTasks(int projectId) throws SQLException {
    List<GenTaskByTableViewSp> result = new ArrayList<>();
    List<GenTaskByTableViewSp> list = getTasksByProjectId(projectId);
    if (list == null || list.size() == 0)
        return result;
    for (GenTaskByTableViewSp entity : list) {
        entity.setGenerated(true);
        if (updateTask(entity) > 0) {
            result.add(entity);
        }
    }
    return result;
}
Also used : GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) ArrayList(java.util.ArrayList)

Example 3 with GenTaskByTableViewSp

use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.

the class GenTaskByTableViewResource method addTask.

@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status addTask(@Context HttpServletRequest request, @FormParam("id") int id, @FormParam("project_id") int project_id, @FormParam("db_name") String set_name, @FormParam("table_names") String table_names, @FormParam("view_names") String view_names, @FormParam("sp_names") String sp_names, @FormParam("prefix") String prefix, @FormParam("suffix") String suffix, @FormParam("cud_by_sp") boolean cud_by_sp, @FormParam("pagination") boolean pagination, @FormParam("version") int version, @FormParam("action") String action, @FormParam("comment") String comment, // C#风格或者Java风格 @FormParam("length") boolean length,
@FormParam("sql_style") String sql_style, @FormParam("api_list") String api_list) throws Exception {
    try {
        GenTaskByTableViewSp task = new GenTaskByTableViewSp();
        if (action.equalsIgnoreCase("delete")) {
            task.setId(id);
            if (0 >= BeanGetter.getDaoByTableViewSp().deleteTask(task)) {
                return Status.ERROR();
            }
        } else {
            String userNo = RequestUtil.getUserNo(request);
            LoginUser user = BeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
            task.setProject_id(project_id);
            task.setDatabaseSetName(set_name);
            task.setTable_names(table_names);
            task.setView_names(view_names);
            task.setSp_names(sp_names);
            task.setPrefix(prefix);
            task.setSuffix(suffix);
            task.setCud_by_sp(cud_by_sp);
            task.setPagination(pagination);
            // task.setLength(length);
            task.setUpdate_user_no(user.getUserName() + "(" + userNo + ")");
            task.setUpdate_time(new Timestamp(System.currentTimeMillis()));
            task.setComment(comment);
            task.setSql_style(sql_style);
            task.setApi_list(api_list);
            task.setMode_type(DalClusterUtils.getModeTypeByDbBaseName(set_name));
            if (needApproveTask(project_id, user.getId())) {
                task.setApproved(1);
            } else {
                task.setApproved(2);
            }
            task.setApproveMsg("");
            if (action.equalsIgnoreCase("update")) {
                task.setId(id);
                task.setVersion(BeanGetter.getDaoByTableViewSp().getVersionById(id));
                if (0 >= BeanGetter.getDaoByTableViewSp().updateTask(task)) {
                    return Status.ERROR();
                }
            } else {
                task.setGenerated(false);
                task.setVersion(1);
                if (0 >= BeanGetter.getDaoByTableViewSp().insertTask(task)) {
                    return Status.ERROR();
                }
            }
        }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) LoginUser(com.ctrip.platform.dal.daogen.entity.LoginUser) Timestamp(java.sql.Timestamp)

Example 4 with GenTaskByTableViewSp

use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.

the class JavaDataPreparerOfSqlBuilderProcessor method buildExtraSqlBuilderHost.

private JavaTableHost buildExtraSqlBuilderHost(CodeGenContext context, GenTaskBySqlBuilder sqlBuilder) throws Exception {
    GenTaskByTableViewSp tableViewSp = new GenTaskByTableViewSp();
    tableViewSp.setCud_by_sp(false);
    tableViewSp.setPagination(false);
    tableViewSp.setAllInOneName(sqlBuilder.getAllInOneName());
    tableViewSp.setDatabaseSetName(sqlBuilder.getDatabaseSetName());
    tableViewSp.setPrefix("");
    tableViewSp.setSuffix("");
    // tableViewSp.setLength(sqlBuilder.getLength());
    DatabaseCategory dbCategory = DatabaseCategory.SqlServer;
    String dbType = DbUtils.getDbType(sqlBuilder.getAllInOneName());
    if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
        dbCategory = DatabaseCategory.MySql;
    }
    return buildTableHost(context, tableViewSp, sqlBuilder.getTable_name(), dbCategory);
}
Also used : DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)

Example 5 with GenTaskByTableViewSp

use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.

the class CSharpDataPreparerOfTableViewSpProcessor method prepareDbFromTableViewSp.

private void prepareDbFromTableViewSp(CodeGenContext codeGenCtx, List<GenTaskByTableViewSp> tableViewSps, List<GenTaskBySqlBuilder> sqlBuilders) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    Set<String> existsTable = new HashSet<>();
    Set<String> _tableDaos = ctx.getTableDaos();
    Set<String> _spDaos = ctx.getSpDaos();
    Map<String, DatabaseHost> _dbHosts = ctx.getDbHosts();
    for (GenTaskByTableViewSp task : tableViewSps) {
        for (String table : StringUtils.split(task.getTable_names(), ",")) {
            _tableDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), table));
            existsTable.add(table);
        }
        for (String table : StringUtils.split(task.getView_names(), ",")) {
            _tableDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), table));
        }
        for (String table : StringUtils.split(task.getSp_names(), ",")) {
            String realSpName = table;
            if (table.contains(".")) {
                String[] splitSp = StringUtils.split(table, '.');
                realSpName = splitSp[1];
            }
            _spDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), realSpName.replace("_", "")));
        }
        addDatabaseSet(ctx, task.getDatabaseSetName());
        if (!_dbHosts.containsKey(task.getAllInOneName())) {
            String provider = "sqlProvider";
            String dbType = DbUtils.getDbType(task.getAllInOneName());
            if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
                provider = "mySqlProvider";
            }
            DatabaseHost host = new DatabaseHost();
            host.setAllInOneName(task.getAllInOneName());
            host.setProviderType(provider);
            host.setDatasetName(host.getAllInOneName());
            _dbHosts.put(task.getAllInOneName(), host);
        }
    }
    for (GenTaskBySqlBuilder task : sqlBuilders) {
        if (!existsTable.contains(task.getTable_name())) {
            _tableDaos.add(getPojoClassName("", "", task.getTable_name()));
        }
        addDatabaseSet(ctx, task.getDatabaseSetName());
        if (!_dbHosts.containsKey(task.getAllInOneName())) {
            String provider = "sqlProvider";
            String dbType = DbUtils.getDbType(task.getAllInOneName());
            if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
                provider = "mySqlProvider";
            }
            DatabaseHost host = new DatabaseHost();
            host.setAllInOneName(task.getAllInOneName());
            host.setProviderType(provider);
            host.setDatasetName(host.getAllInOneName());
            _dbHosts.put(task.getAllInOneName(), host);
        }
    }
}
Also used : CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Aggregations

GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)10 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)4 DalHints (com.ctrip.platform.dal.dao.DalHints)3 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)3 ArrayList (java.util.ArrayList)3 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)2 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)2 Progress (com.ctrip.platform.dal.daogen.entity.Progress)2 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)2 List (java.util.List)2 Callable (java.util.concurrent.Callable)2 Status (com.ctrip.platform.dal.daogen.domain.Status)1 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 LoginUser (com.ctrip.platform.dal.daogen.entity.LoginUser)1 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)1 Timestamp (java.sql.Timestamp)1