Search in sources :

Example 11 with ExecuteResult

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

the class JavaDataPreparerOfTableViewSpProcessor method prepareTable.

private List<Callable<ExecuteResult>> prepareTable(final JavaCodeGenContext ctx, final Progress progress, final Queue<JavaTableHost> _tableHosts, final GenTaskByTableViewSp tableViewSp, final String[] tableNames, final DatabaseCategory dbCategory) {
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final String tableName : tableNames) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build Table[" + tableViewSp.getAllInOneName() + "." + tableName + "] Host");
                progress.setOtherMessage(result.getTaskName());
                try {
                    JavaTableHost tableHost = buildTableHost(ctx, tableViewSp, tableName, dbCategory);
                    result.setSuccessal(true);
                    if (null != tableHost)
                        _tableHosts.add(tableHost);
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw new Exception(String.format("Task Id[%s]:%s\r\n", tableViewSp.getId(), e.getMessage()), e);
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable) SQLException(java.sql.SQLException)

Example 12 with ExecuteResult

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

the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.

private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext context) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
    final Queue<CSharpTableHost> tableViewHosts = ctx.getTableViewHosts();
    if (sqlBuilders.size() > 0) {
        Map<String, GenTaskBySqlBuilder> tempSqlBuildres = sqlBuilderBroupBy(sqlBuilders);
        for (final Map.Entry<String, GenTaskBySqlBuilder> sqlBuilder : tempSqlBuildres.entrySet()) {
            Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

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

Example 13 with ExecuteResult

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

the class CSharpDataPreparerOfTableViewSpProcessor method prepareView.

private List<Callable<ExecuteResult>> prepareView(final CSharpCodeGenContext ctx, final Progress progress, final GenTaskByTableViewSp tableViewSp, final String[] viewNames, final DatabaseCategory dbCategory, final Queue<CSharpTableHost> tableViewHosts) {
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final String view : viewNames) {
        Callable<ExecuteResult> viewWorker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build View[" + tableViewSp.getAllInOneName() + "." + view + "] Host");
                progress.setOtherMessage(result.getTaskName());
                try {
                    CSharpTableHost currentViewHost = buildViewHost(ctx, tableViewSp, dbCategory, view);
                    if (null != currentViewHost) {
                        tableViewHosts.add(currentViewHost);
                    }
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw new Exception(String.format("Task Id[%s]:%s\r\n", tableViewSp.getId(), e.getMessage()), e);
                }
                return result;
            }
        };
        results.add(viewWorker);
    }
    return results;
}
Also used : ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable) SQLException(java.sql.SQLException)

Example 14 with ExecuteResult

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

the class JavaDataPreparerOfFreeSqlProcessor method prepareFreeSql.

private List<Callable<ExecuteResult>> prepareFreeSql(CodeGenContext codeGenCtx) throws Exception {
    final JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
    int projectId = ctx.getProjectId();
    final Progress progress = ctx.getProgress();
    final String namespace = ctx.getNamespace();
    final Map<String, JavaMethodHost> freeSqlPojoHosts = ctx.get_freeSqlPojoHosts();
    final Queue<FreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
    final String userName = ctx.getUserName();
    DaoByFreeSql daoByFreeSql = BeanGetter.getDaoByFreeSql();
    List<GenTaskByFreeSql> freeSqlTasks;
    if (ctx.isRegenerate()) {
        freeSqlTasks = daoByFreeSql.updateAndGetAllTasks(projectId);
        prepareDbFromFreeSql(ctx, freeSqlTasks);
    } else {
        freeSqlTasks = daoByFreeSql.updateAndGetTasks(projectId);
        prepareDbFromFreeSql(ctx, daoByFreeSql.getTasksByProjectId(projectId));
    }
    if (!ctx.isIgnoreApproveStatus() && freeSqlTasks != null && freeSqlTasks.size() > 0) {
        Iterator<GenTaskByFreeSql> ite = freeSqlTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    final Map<String, List<GenTaskByFreeSql>> groupBy = freeSqlGroupBy(freeSqlTasks);
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final Map.Entry<String, List<GenTaskByFreeSql>> entry : groupBy.entrySet()) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build  Free SQL[" + entry.getKey() + "] Host");
                progress.setOtherMessage(result.getTaskName());
                List<GenTaskByFreeSql> currentTasks = entry.getValue();
                if (currentTasks.size() < 1)
                    return result;
                FreeSqlHost host = new FreeSqlHost();
                host.setDbSetName(currentTasks.get(0).getDatabaseSetName());
                host.setClassName(currentTasks.get(0).getClass_name());
                host.setPackageName(namespace);
                host.setDatabaseCategory(getDatabaseCategory(currentTasks.get(0).getAllInOneName()));
                host.setUserName(ctx.getUserName());
                // host.setLength(currentTasks.get(0).getLength());
                List<JavaMethodHost> methods = new ArrayList<>();
                for (GenTaskByFreeSql task : currentTasks) {
                    try {
                        processMethodHost(task, namespace, methods, freeSqlPojoHosts, userName);
                    } catch (Throwable e) {
                        progress.setOtherMessage(e.getMessage());
                        throw new Exception(String.format("Task Id[%s]:%s\r\n", task.getId(), e.getMessage()), e);
                    }
                }
                host.setMethods(methods);
                freeSqlHosts.add(host);
                result.setSuccessal(true);
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) DaoByFreeSql(com.ctrip.platform.dal.daogen.dao.DaoByFreeSql) FreeSqlHost(com.ctrip.platform.dal.daogen.host.java.FreeSqlHost) GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql) JavaMethodHost(com.ctrip.platform.dal.daogen.host.java.JavaMethodHost) Callable(java.util.concurrent.Callable) SQLException(java.sql.SQLException) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 15 with ExecuteResult

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

the class CSharpDataPreparerOfFreeSqlProcessor method prepareFreeSql.

private List<Callable<ExecuteResult>> prepareFreeSql(CodeGenContext codeGenCtx) throws Exception {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    int projectId = ctx.getProjectId();
    boolean regenerate = ctx.isRegenerate();
    final Progress progress = ctx.getProgress();
    final String namespace = ctx.getNamespace();
    List<GenTaskByFreeSql> freeSqlTasks;
    if (regenerate) {
        freeSqlTasks = daoByFreeSql.updateAndGetAllTasks(projectId);
        prepareDbFromFreeSql(ctx, freeSqlTasks);
    } else {
        freeSqlTasks = daoByFreeSql.updateAndGetTasks(projectId);
        prepareDbFromFreeSql(ctx, daoByFreeSql.getTasksByProjectId(projectId));
    }
    if (!ctx.isIgnoreApproveStatus() && freeSqlTasks != null && freeSqlTasks.size() > 0) {
        Iterator<GenTaskByFreeSql> ite = freeSqlTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    // 首先按照DbName以及ClassName做一次GroupBy,且ClassName不区分大小写
    final Map<String, List<GenTaskByFreeSql>> groupBy = freeSqlGroupBy(freeSqlTasks);
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    final Map<String, CSharpFreeSqlPojoHost> _freeSqlPojoHosts = ctx.getFreeSqlPojoHosts();
    final Queue<CSharpFreeSqlHost> _freeSqlHosts = ctx.getFreeSqlHosts();
    // 随后,以DbName以及ClassName为维度,为每个维度生成一个DAO类
    for (final Map.Entry<String, List<GenTaskByFreeSql>> entry : groupBy.entrySet()) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build  Free SQL[" + entry.getKey() + "] Host");
                progress.setOtherMessage(result.getTaskName());
                try {
                    List<GenTaskByFreeSql> currentTasks = entry.getValue();
                    if (currentTasks.size() < 1)
                        return result;
                    CSharpFreeSqlHost host = new CSharpFreeSqlHost();
                    host.setDbSetName(currentTasks.get(0).getDatabaseSetName());
                    host.setClassName(CommonUtils.normalizeVariable(WordUtils.capitalize(currentTasks.get(0).getClass_name())));
                    host.setNameSpace(namespace);
                    host.setDatabaseCategory(getDatabaseCategory(currentTasks.get(0).getAllInOneName()));
                    List<CSharpMethodHost> methods = new ArrayList<>();
                    // 每个Method可能就有一个Pojo
                    for (GenTaskByFreeSql task : currentTasks) {
                        try {
                            CSharpMethodHost method = buildFreeSqlMethodHost(ctx, task);
                            if (!_freeSqlPojoHosts.containsKey(task.getPojo_name()) && method.getPojoName() != null && !method.getPojoName().isEmpty() && (!method.isFirstOrSingle() || !method.isSampleType()) && !"update".equalsIgnoreCase(task.getCrud_type())) {
                                CSharpFreeSqlPojoHost freeSqlPojoHost = buildFreeSqlPojoHost(ctx, task);
                                if (null != freeSqlPojoHost) {
                                    _freeSqlPojoHosts.put(task.getPojo_name(), freeSqlPojoHost);
                                }
                            } else if ("update".equalsIgnoreCase(task.getCrud_type())) {
                                DbUtils.testUpdateSql(task.getAllInOneName(), task.getSql_content(), task.getParameters());
                            }
                            methods.add(method);
                        } catch (Throwable e) {
                            progress.setOtherMessage(e.getMessage());
                            throw new Exception(String.format("Task Id[%s]:%s\r\n", task.getId(), e.getMessage()), e);
                        }
                    }
                    host.setMethods(methods);
                    _freeSqlHosts.add(host);
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : GenTaskByFreeSql(com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql) Callable(java.util.concurrent.Callable) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) SQLException(java.sql.SQLException)

Aggregations

ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)19 Callable (java.util.concurrent.Callable)17 Progress (com.ctrip.platform.dal.daogen.entity.Progress)11 SQLException (java.sql.SQLException)8 ArrayList (java.util.ArrayList)8 VelocityContext (org.apache.velocity.VelocityContext)7 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)6 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)5 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)3 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)2 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 FreeSqlHost (com.ctrip.platform.dal.daogen.host.java.FreeSqlHost)2 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)2 JavaTableHost (com.ctrip.platform.dal.daogen.host.java.JavaTableHost)2 DaoByFreeSql (com.ctrip.platform.dal.daogen.dao.DaoByFreeSql)1 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 CSharpFreeSqlHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)1 CSharpFreeSqlPojoHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost)1 SpDbHost (com.ctrip.platform.dal.daogen.host.java.SpDbHost)1 SpHost (com.ctrip.platform.dal.daogen.host.java.SpHost)1