Search in sources :

Example 1 with GenTaskBySqlBuilder

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

the class DaoBySqlBuilder method updateTask.

public int updateTask(GenTaskBySqlBuilder task) throws SQLException {
    {
        FreeSelectSqlBuilder<GenTaskBySqlBuilder> builder = new FreeSelectSqlBuilder<>(dbCategory);
        builder.setTemplate("SELECT 1 FROM task_auto WHERE id != ? AND project_id=? AND db_name=? AND table_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++, "table_name", Types.VARCHAR, task.getTable_name());
        parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
        builder.mapWith(genTaskBySqlBuilderRowMapper).requireFirst().nullable();
        DalHints hints = DalHints.createIfAbsent(null).allowPartial();
        GenTaskBySqlBuilder entity = queryDao.query(builder, parameters, hints);
        if (entity != null)
            return 0;
    }
    FreeUpdateSqlBuilder builder = new FreeUpdateSqlBuilder(dbCategory);
    StringBuilder sb = new StringBuilder();
    sb.append("UPDATE task_auto SET project_id=?,db_name=?, table_name=?, class_name=?,method_name=?,");
    sb.append("sql_style=?,crud_type=?,fields=?,where_condition=?,sql_content=?,`generated`=?,");
    sb.append("version=version+1,update_user_no=?,update_time=?,comment=?,scalarType=?,");
    sb.append("pagination=?,orderby=?,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++, "table_name", Types.VARCHAR, task.getTable_name());
    parameters.set(i++, "class_name", Types.VARCHAR, task.getClass_name());
    parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
    parameters.set(i++, "sql_style", Types.VARCHAR, task.getSql_style());
    parameters.set(i++, "crud_type", Types.VARCHAR, task.getCrud_type());
    parameters.set(i++, "fields", Types.LONGVARCHAR, task.getFields());
    parameters.set(i++, "where_condition", Types.LONGVARCHAR, task.getCondition());
    parameters.set(i++, "sql_content", Types.LONGVARCHAR, task.getSql_content());
    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++, "pagination", Types.BIT, task.getPagination());
    parameters.set(i++, "orderby", Types.VARCHAR, task.getOrderby());
    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) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Example 2 with GenTaskBySqlBuilder

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

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

the class JavaDataPreparerOfSqlBuilderProcessor method sqlBuilderBroupBy.

private Map<String, List<GenTaskBySqlBuilder>> sqlBuilderBroupBy(Queue<GenTaskBySqlBuilder> tasks) {
    Map<String, List<GenTaskBySqlBuilder>> map = new HashMap<>();
    if (tasks == null || tasks.size() == 0)
        return map;
    for (GenTaskBySqlBuilder task : tasks) {
        String key = String.format("%s_%s", task.getAllInOneName(), task.getTable_name());
        if (!map.containsKey(key))
            map.put(key, new ArrayList<GenTaskBySqlBuilder>());
        map.get(key).add(task);
    }
    return map;
}
Also used : GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)

Example 4 with GenTaskBySqlBuilder

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

the class JavaDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.

private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext context) throws Exception {
    final JavaCodeGenContext ctx = (JavaCodeGenContext) context;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
    final Queue<JavaTableHost> tableHosts = ctx.getTableHosts();
    if (sqlBuilders.size() > 0) {
        Map<String, List<GenTaskBySqlBuilder>> tempSqlBuildres = sqlBuilderBroupBy(sqlBuilders);
        for (final Map.Entry<String, List<GenTaskBySqlBuilder>> sqlBuilder : tempSqlBuildres.entrySet()) {
            for (final GenTaskBySqlBuilder builder : sqlBuilder.getValue()) {
                Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

                    @Override
                    public ExecuteResult call() throws Exception {
                        ExecuteResult result = new ExecuteResult("Build Extral SQL[" + builder.getAllInOneName() + "." + sqlBuilder.getKey() + "] Host");
                        progress.setOtherMessage(result.getTaskName());
                        try {
                            JavaTableHost extraTableHost = buildExtraSqlBuilderHost(ctx, builder);
                            if (null != extraTableHost) {
                                tableHosts.add(extraTableHost);
                            }
                            result.setSuccessal(true);
                        } catch (Throwable e) {
                            progress.setOtherMessage(e.getMessage());
                            throw new Exception(String.format("Task Id[%s]:%s\r\n", builder.getId(), e.getMessage()), e);
                        }
                        return result;
                    }
                };
                results.add(worker);
            }
        }
    }
    return results;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) JavaTableHost(com.ctrip.platform.dal.daogen.host.java.JavaTableHost) Callable(java.util.concurrent.Callable) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 5 with GenTaskBySqlBuilder

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

GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)19 DalHints (com.ctrip.platform.dal.dao.DalHints)5 FreeSelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeSelectSqlBuilder)4 Progress (com.ctrip.platform.dal.daogen.entity.Progress)4 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)4 Callable (java.util.concurrent.Callable)4 StatementParameters (com.ctrip.platform.dal.dao.StatementParameters)3 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)3 ArrayList (java.util.ArrayList)3 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)2 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)2 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)2 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)2 List (java.util.List)2 Matcher (java.util.regex.Matcher)2 FreeUpdateSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder)1 SelectSqlBuilder (com.ctrip.platform.dal.dao.sqlbuilder.SelectSqlBuilder)1 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