Search in sources :

Example 6 with ExecuteResult

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

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

the class JavaCodeGeneratorOfTableProcessor method generateTableDao.

private List<Callable<ExecuteResult>> generateTableDao(CodeGenContext context, final File mavenLikeDir) {
    JavaCodeGenContext ctx = (JavaCodeGenContext) context;
    final Progress progress = ctx.getProgress();
    Queue<JavaTableHost> tableHosts = ctx.getTableHosts();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final JavaTableHost host : tableHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Generate Table[" + host.getDbSetName() + "." + host.getTableName() + "] Dao, Pojo, Test");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/dao/standard/DAO.java.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/Pojo.java.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/test/DaoUnitTests.java.tpl");
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : Progress(com.ctrip.platform.dal.daogen.entity.Progress) VelocityContext(org.apache.velocity.VelocityContext) JavaTableHost(com.ctrip.platform.dal.daogen.host.java.JavaTableHost) ArrayList(java.util.ArrayList) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 8 with ExecuteResult

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

the class CSharpCodeGeneratorOfTableProcessor method generateTableDao.

private List<Callable<ExecuteResult>> generateTableDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Queue<CSharpTableHost> _tableViewHosts = ctx.getTableViewHosts();
    for (final CSharpTableHost host : _tableViewHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                // progress.setOtherMessage("正在生成 " + host.getClassName());
                ExecuteResult result = new ExecuteResult("Generate Table[" + host.getTableName() + "] Dao");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/dao/standard/DAO.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), ctx.isNewPojo() ? "templates/csharp/PojoNew.cs.tpl" : "templates/csharp/Pojo.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/IDao/I%sDao.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/dao/standard/IDAO.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/DAOTest.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/DAOUnitTest.cs.tpl");
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    return results;
}
Also used : CSharpTableHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost) Progress(com.ctrip.platform.dal.daogen.entity.Progress) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable)

Example 9 with ExecuteResult

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

the class JavaDataPreparerOfTableViewSpProcessor method prepareView.

private List<Callable<ExecuteResult>> prepareView(final JavaCodeGenContext ctx, final Progress progress, final Queue<ViewHost> _viewHosts, final GenTaskByTableViewSp tableViewSp, final String[] viewNames, final DatabaseCategory dbCategory) {
    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 {
                    ViewHost vhost = buildViewHost(ctx, tableViewSp, dbCategory, view);
                    if (null != vhost)
                        _viewHosts.add(vhost);
                    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 10 with ExecuteResult

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

the class JavaDataPreparerOfTableViewSpProcessor method prepareSp.

private List<Callable<ExecuteResult>> prepareSp(final JavaCodeGenContext context, final Progress progress, final Queue<SpHost> spHosts, final Map<String, SpDbHost> spHostMaps, final GenTaskByTableViewSp tableViewSp, final String[] spNames) {
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final String spName : spNames) {
        Callable<ExecuteResult> spWorker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                ExecuteResult result = new ExecuteResult("Build SP[" + tableViewSp.getAllInOneName() + "." + spName + "] Host");
                progress.setOtherMessage(result.getTaskName());
                try {
                    SpHost spHost = buildSpHost(context, tableViewSp, spName);
                    if (null != spHost) {
                        if (!spHostMaps.containsKey(spHost.getDbName())) {
                            SpDbHost spDbHost = new SpDbHost(spHost.getDbName(), spHost.getPackageName());
                            spHostMaps.put(spHost.getDbName(), spDbHost);
                        }
                        spHostMaps.get(spHost.getDbName()).addSpHost(spHost);
                        spHosts.add(spHost);
                    }
                    result.setSuccessal(true);
                } catch (Exception e) {
                    progress.setOtherMessage(e.getMessage());
                    throw new Exception(String.format("Task Id[%s]:%s\r\n", tableViewSp.getId(), e.getMessage()), e);
                }
                return result;
            }
        };
        results.add(spWorker);
    }
    return results;
}
Also used : ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) Callable(java.util.concurrent.Callable) 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