Search in sources :

Example 11 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpDataPreparerOfTableViewSpProcessor method buildSpHost.

private CSharpTableHost buildSpHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, DatabaseCategory dbCategory, String spName) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    String schema = "dbo";
    String realSpName = spName;
    if (spName.contains(".")) {
        String[] splitSp = StringUtils.split(spName, '.');
        schema = splitSp[0];
        realSpName = splitSp[1];
    }
    StoredProcedure currentSp = new StoredProcedure();
    currentSp.setSchema(schema);
    currentSp.setName(realSpName);
    if (!DbUtils.spExists(tableViewSp.getAllInOneName(), currentSp)) {
        throw new Exception(String.format("存储过程 %s 不存在,请修改DAO后再试!", currentSp.getName()));
    }
    List<AbstractParameterHost> params = DbUtils.getSpParams(tableViewSp.getAllInOneName(), currentSp, new CsharpSpParamResultSetExtractor());
    List<CSharpParameterHost> realParams = new ArrayList<CSharpParameterHost>();
    for (AbstractParameterHost p : params) {
        realParams.add((CSharpParameterHost) p);
    }
    CSharpTableHost tableHost = new CSharpTableHost();
    tableHost.setNameSpace(ctx.getNamespace());
    tableHost.setDatabaseCategory(dbCategory);
    tableHost.setDbSetName(tableViewSp.getDatabaseSetName());
    tableHost.setClassName(getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), realSpName.replace("_", "")));
    tableHost.setTable(false);
    tableHost.setSpName(spName);
    tableHost.setSpParams(realParams);
    tableHost.setApi_list(tableViewSp.getApi_list());
    return tableHost;
}
Also used : AbstractParameterHost(com.ctrip.platform.dal.daogen.host.AbstractParameterHost) StoredProcedure(com.ctrip.platform.dal.daogen.domain.StoredProcedure) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) SQLException(java.sql.SQLException)

Example 12 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpDirectoryPreparerProcessor method process.

@Override
public void process(CodeGenContext context) throws Exception {
    CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
    int projectId = ctx.getProjectId();
    boolean regenerate = ctx.isRegenerate();
    File mavenLikeDir = new File(String.format("%s/%s/cs", ctx.getGeneratePath(), projectId));
    try {
        if (mavenLikeDir.exists() && regenerate) {
            FileUtils.forceDelete(mavenLikeDir);
        }
        File idaoDir = new File(mavenLikeDir, "IDao");
        File daoDir = new File(mavenLikeDir, "Dao");
        File entityDir = new File(mavenLikeDir, "Entity");
        File testDir = new File(mavenLikeDir, "Test");
        File configDir = new File(mavenLikeDir, "Config");
        if (!idaoDir.exists()) {
            FileUtils.forceMkdir(idaoDir);
        }
        if (!daoDir.exists()) {
            FileUtils.forceMkdir(daoDir);
        }
        if (!entityDir.exists()) {
            FileUtils.forceMkdir(entityDir);
        }
        if (!testDir.exists()) {
            FileUtils.forceMkdir(testDir);
        }
        if (!configDir.exists()) {
            FileUtils.forceMkdir(configDir);
        }
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
}
Also used : CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) File(java.io.File)

Example 13 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpCodeGenContextCreator method process.

@Override
public void process(CodeGenContext context) throws Exception {
    try {
        CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
        Project project = BeanGetter.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());
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
}
Also used : Project(com.ctrip.platform.dal.daogen.entity.Project) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) DalConfigHost(com.ctrip.platform.dal.daogen.host.DalConfigHost)

Example 14 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpCodeGeneratorOfFreeSqlProcessor method process.

@Override
public void process(CodeGenContext context) throws Exception {
    try {
        CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
        int projectId = ctx.getProjectId();
        final File dir = new File(String.format("%s/%s/cs", ctx.getGeneratePath(), projectId));
        List<Callable<ExecuteResult>> freeCallables = generateFreeSqlDao(ctx, dir);
        TaskUtils.invokeBatch(freeCallables);
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        throw e;
    }
}
Also used : CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) File(java.io.File) Callable(java.util.concurrent.Callable)

Example 15 with CSharpCodeGenContext

use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.

the class CSharpCodeGeneratorOfFreeSqlProcessor method generateFreeSqlDao.

private List<Callable<ExecuteResult>> generateFreeSqlDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
    final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
    final Progress progress = ctx.getProgress();
    List<Callable<ExecuteResult>> results = new ArrayList<>();
    Map<String, CSharpFreeSqlPojoHost> _freeSqlPojoHosts = ctx.getFreeSqlPojoHosts();
    for (final CSharpFreeSqlPojoHost host : _freeSqlPojoHosts.values()) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                // progress.setOtherMessage("正在生成 " + host.getClassName());
                ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getClassName() + "] Pojo");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), ctx.isNewPojo() ? "templates/csharp/PojoNew.cs.tpl" : "templates/csharp/Pojo.cs.tpl");
                    result.setSuccessal(true);
                } catch (Throwable e) {
                    throw e;
                }
                return result;
            }
        };
        results.add(worker);
    }
    ProgressResource.addDoneFiles(progress, _freeSqlPojoHosts.size());
    Queue<CSharpFreeSqlHost> _freeSqlHosts = ctx.getFreeSqlHosts();
    for (final CSharpFreeSqlHost host : _freeSqlHosts) {
        Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {

            @Override
            public ExecuteResult call() throws Exception {
                // progress.setOtherMessage("正在生成 " + host.getClassName());
                ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getClassName() + "] Dap, Test");
                progress.setOtherMessage(result.getTaskName());
                try {
                    VelocityContext context = GenUtils.buildDefaultVelocityContext();
                    context.put("host", host);
                    GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/dao/freesql/FreeSqlDAO.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/test/FreeSqlTest.cs.tpl");
                    GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/test/FreeSqlUnitTest.cs.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) CSharpCodeGenContext(com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext) CSharpFreeSqlPojoHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlPojoHost) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) ExecuteResult(com.ctrip.platform.dal.daogen.entity.ExecuteResult) CSharpFreeSqlHost(com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost)

Aggregations

CSharpCodeGenContext (com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext)20 Callable (java.util.concurrent.Callable)9 Progress (com.ctrip.platform.dal.daogen.entity.Progress)8 SQLException (java.sql.SQLException)6 ExecuteResult (com.ctrip.platform.dal.daogen.entity.ExecuteResult)5 File (java.io.File)5 GenTaskBySqlBuilder (com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder)4 CSharpTableHost (com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost)4 VelocityContext (org.apache.velocity.VelocityContext)4 AbstractParameterHost (com.ctrip.platform.dal.daogen.host.AbstractParameterHost)3 ArrayList (java.util.ArrayList)3 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)2 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)2 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)2 GenTaskByFreeSql (com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql)2 GenTaskByTableViewSp (com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp)2 CSharpDalGenerator (com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator)2 JavaCodeGenContext (com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext)2 JavaDalGenerator (com.ctrip.platform.dal.daogen.generator.java.JavaDalGenerator)2 DalConfigHost (com.ctrip.platform.dal.daogen.host.DalConfigHost)2