use of com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost 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() {
//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 (Exception e) {
log.error(result.getTaskName() + "exception", 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() {
//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 (Exception e) {
log.error(result.getTaskName() + "exception", e);
}
return result;
}
};
results.add(worker);
}
return results;
}
use of com.ctrip.platform.dal.daogen.host.csharp.CSharpFreeSqlHost in project dal by ctripcorp.
the class GenTaskResource method buildFreesqlTaskMethodParam.
private String buildFreesqlTaskMethodParam(GenTaskByFreeSql 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<FreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
FreeSqlHost freeSqlHost = null;
while ((freeSqlHost = freeSqlHosts.poll()) != null) {
List<JavaMethodHost> methods = freeSqlHost.getMethods();
for (JavaMethodHost method : methods) {
if (task.getMethod_name().equalsIgnoreCase(method.getName())) {
String param = method.getParameterDeclaration();
param = param.replaceAll("<", "<");
param = param.replaceAll(">", ">");
return param;
}
}
}
} else {
generator = new CSharpDalGenerator();
context = generator.createContext(task.getProject_id(), true, progress, true, true);
generator.prepareData(context);
CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
Queue<CSharpFreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
CSharpFreeSqlHost freeSqlHost = null;
while ((freeSqlHost = freeSqlHosts.poll()) != null) {
List<CSharpMethodHost> methods = freeSqlHost.getMethods();
for (CSharpMethodHost method : methods) {
if (task.getMethod_name().equalsIgnoreCase(method.getName())) {
String param = method.getParameterDeclaration();
param = param.replaceAll("<", "<");
param = param.replaceAll(">", ">");
return param;
}
}
}
}
} catch (Exception e) {
}
return null;
}
Aggregations