Search in sources :

Example 11 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class JavaCodeGenContextCreator method process.

@Override
public void process(CodeGenContext context) throws Exception {
    JavaCodeGenContext ctx = (JavaCodeGenContext) context;
    Project project = SpringBeanGetter.getDaoOfProject().getProjectByID(ctx.getProjectId());
    DalConfigHost dalConfigHost = null;
    if (project.getDal_config_name() != null && !project.getDal_config_name().isEmpty()) {
        dalConfigHost = new DalConfigHost(project.getDal_config_name());
    } else if (project.getNamespace() != null && !project.getNamespace().isEmpty()) {
        dalConfigHost = new DalConfigHost(project.getNamespace());
    } else {
        dalConfigHost = new DalConfigHost("");
    }
    ctx.setDalConfigHost(dalConfigHost);
    ctx.setNamespace(project.getNamespace());
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 12 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class JavaDataPreparerOfTableViewSpProcessor method prepareTableViewSp.

private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext codeGenCtx) throws Exception {
    final JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
    int projectId = ctx.getProjectId();
    boolean regenerate = ctx.isRegenerate();
    final Progress progress = ctx.getProgress();
    List<GenTaskByTableViewSp> tableViewSpTasks;
    List<GenTaskBySqlBuilder> sqlBuilderTasks;
    if (regenerate) {
        tableViewSpTasks = daoByTableViewSp.updateAndGetAllTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetAllTasks(projectId);
        prepareDbFromTableViewSp(ctx, tableViewSpTasks, sqlBuilderTasks);
    } else {
        tableViewSpTasks = daoByTableViewSp.updateAndGetTasks(projectId);
        sqlBuilderTasks = daoBySqlBuilder.updateAndGetTasks(projectId);
        prepareDbFromTableViewSp(ctx, daoByTableViewSp.getTasksByProjectId(projectId), daoBySqlBuilder.getTasksByProjectId(projectId));
    }
    if (!ctx.isIgnoreApproveStatus() && tableViewSpTasks != null && tableViewSpTasks.size() > 0) {
        Iterator<GenTaskByTableViewSp> ite = tableViewSpTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    if (!ctx.isIgnoreApproveStatus() && sqlBuilderTasks != null && sqlBuilderTasks.size() > 0) {
        Iterator<GenTaskBySqlBuilder> ite = sqlBuilderTasks.iterator();
        while (ite.hasNext()) {
            int approved = ite.next().getApproved();
            if (approved != 2 && approved != 0) {
                ite.remove();
            }
        }
    }
    Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
    for (GenTaskBySqlBuilder _t : sqlBuilderTasks) {
        _sqlBuilders.add(_t);
    }
    final Queue<JavaTableHost> _tableHosts = ctx.getTableHosts();
    final Queue<ViewHost> _viewHosts = ctx.getViewHosts();
    final Queue<SpHost> _spHosts = ctx.getSpHosts();
    final Map<String, SpDbHost> _spHostMaps = ctx.getSpHostMaps();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    for (final GenTaskByTableViewSp tableViewSp : tableViewSpTasks) {
        final String[] viewNames = StringUtils.split(tableViewSp.getView_names(), ",");
        final String[] tableNames = StringUtils.split(tableViewSp.getTable_names(), ",");
        final String[] spNames = StringUtils.split(tableViewSp.getSp_names(), ",");
        final DatabaseCategory dbCategory;
        String dbType = DbUtils.getDbType(tableViewSp.getAllInOneName());
        if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
            dbCategory = DatabaseCategory.MySql;
        } else {
            dbCategory = DatabaseCategory.SqlServer;
        }
        results.addAll(prepareTable(ctx, progress, _tableHosts, tableViewSp, tableNames, dbCategory));
        results.addAll(prepareView(ctx, progress, _viewHosts, tableViewSp, viewNames, dbCategory));
        results.addAll(prepareSp(ctx, progress, _spHosts, _spHostMaps, tableViewSp, spNames));
    }
    return results;
}
Also used : GenTaskByTableViewSp(com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp) GenTaskBySqlBuilder(com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder) Callable(java.util.concurrent.Callable) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext) Progress(com.ctrip.platform.dal.daogen.entity.Progress) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory)

Example 13 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class GenTaskResource method buildAutoTaskMethodParam.

private String buildAutoTaskMethodParam(GenTaskBySqlBuilder task) {
    try {
        DalGenerator generator = null;
        CodeGenContext context = null;
        Progress progress = new Progress();
        if ("java".equalsIgnoreCase(task.getSql_style())) {
            generator = new JavaDalGenerator();
            context = generator.createContext(task.getProject_id(), true, progress, true, true);
            generator.prepareData(context);
            JavaCodeGenContext ctx = (JavaCodeGenContext) context;
            Queue<JavaTableHost> tableHosts = ctx.getTableHosts();
            JavaTableHost tableHost = null;
            while ((tableHost = tableHosts.poll()) != null) {
                List<JavaMethodHost> methods = tableHost.getMethods();
                for (JavaMethodHost method : methods) {
                    if (task.getMethod_name().equalsIgnoreCase(method.getName())) {
                        String param = method.getParameterDeclaration();
                        param = param.replaceAll("<", "&lt;");
                        param = param.replaceAll(">", "&gt;");
                        return param;
                    }
                }
            }
        } else {
            generator = new CSharpDalGenerator();
            context = generator.createContext(task.getProject_id(), true, progress, true, true);
            generator.prepareData(context);
            CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
            Queue<CSharpTableHost> tableHosts = ctx.getTableViewHosts();
            CSharpTableHost tableHost = null;
            while ((tableHost = tableHosts.poll()) != null) {
                List<CSharpMethodHost> methods = tableHost.getExtraMethods();
                for (CSharpMethodHost method : methods) {
                    if (task.getMethod_name().equalsIgnoreCase(method.getName())) {
                        String param = method.getParameterDeclaration();
                        param = param.replaceAll("<", "&lt;");
                        param = param.replaceAll(">", "&gt;");
                        return param;
                    }
                }
            }
        }
    } catch (Exception e) {
    }
    return null;
}
Also used : CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator) DalGenerator(com.ctrip.platform.dal.daogen.DalGenerator) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) CodeGenContext(com.ctrip.platform.dal.daogen.CodeGenContext) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext) JavaTableHost(com.ctrip.platform.dal.daogen.host.java.JavaTableHost) JavaDalGenerator(com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator) JavaMethodHost(com.ctrip.platform.dal.daogen.host.java.JavaMethodHost) EmailException(org.apache.commons.mail.EmailException) CSharpTableHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost) CSharpDalGenerator(com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator) CSharpMethodHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 14 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class AbstractJavaDataPreparer method filterExtraMethods.

private List<GenTaskBySqlBuilder> filterExtraMethods(CodeGenContext codeGenCtx, String allInOneName, String tableName) {
    JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
    List<GenTaskBySqlBuilder> currentTableBuilders = new ArrayList<>();
    Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
    Iterator<GenTaskBySqlBuilder> iter = sqlBuilders.iterator();
    while (iter.hasNext()) {
        GenTaskBySqlBuilder currentSqlBuilder = iter.next();
        if (currentSqlBuilder.getAllInOneName().equals(allInOneName) && currentSqlBuilder.getTable_name().equals(tableName)) {
            currentTableBuilders.add(currentSqlBuilder);
            iter.remove();
        }
    }
    return currentTableBuilders;
}
Also used : JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Example 15 with JavaCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.

the class CommonJavaCodeGeneratorOfOthersProcessor method process.

@Override
public void process(CodeGenContext context) throws Exception {
    JavaCodeGenContext ctx = (JavaCodeGenContext) context;
    int projectId = ctx.getProjectId();
    File dir = new File(String.format("%s/%s/java", ctx.getGeneratePath(), projectId));
    VelocityContext vltCcontext = GenUtils.buildDefaultVelocityContext();
    vltCcontext.put("host", ctx.getDalConfigHost());
    GenUtils.mergeVelocityContext(vltCcontext, String.format("%s/dal.xml", dir.getAbsolutePath()), "templates/java/Dal.config.java.tpl");
    vltCcontext.put("host", ctx.getContextHost());
    GenUtils.mergeVelocityContext(vltCcontext, String.format("%s/datasource.xml", dir.getAbsolutePath()), "templates/java/DataSource.java.tpl");
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) File(java.io.File) JavaCodeGenContext(com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)

Aggregations

JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)22 Callable (java.util.concurrent.Callable)11 Progress (com.ctrip.platform.dal.daogen.entity.Progress)7 File (java.io.File)7 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)6 VelocityContext (org.apache.velocity.VelocityContext)6 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)4 JavaMethodHost (com.ctrip.platform.dal.daogen.host.java.JavaMethodHost)4 ArrayList (java.util.ArrayList)4 FreeSqlHost (com.ctrip.platform.dal.daogen.host.java.FreeSqlHost)3 JavaTableHost (com.ctrip.platform.dal.daogen.host.java.JavaTableHost)3 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)2 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)2 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)2 CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)2 CSharpDalGenerator (com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator)2 JavaDalGenerator (com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator)2 DalConfigHost (com.ctrip.platform.dal.daogen.host.DalConfigHost)2 CSharpMethodHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpMethodHost)2 EmailException (org.apache.commons.mail.EmailException)2