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;
}
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;
}
}
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;
}
}
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;
}
}
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;
}
Aggregations