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("<", "<");
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<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("<", "<");
param = param.replaceAll(">", ">");
return param;
}
}
}
}
} catch (Exception e) {
}
return null;
}
use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfFreeSqlProcessor method generateFreeSqlDao.
private List<Callable<ExecuteResult>> generateFreeSqlDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Map<String, JavaMethodHost> freeSqlPojoHosts = ctx.get_freeSqlPojoHosts();
for (final JavaMethodHost host : freeSqlPojoHosts.values()) {
if (host.isSampleType())
continue;
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getPojoClassName() + "] Pojo");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), host.getPojoClassName()), "templates/java/Pojo.java.tpl");
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
Queue<FreeSqlHost> freeSqlHosts = ctx.getFreeSqlHosts();
for (final FreeSqlHost host : freeSqlHosts) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
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.java", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/java/dao/freesql/FreeSqlDAO.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/java/test/FreeSqlDaoUnitTest.java.tpl");
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfSpProcessor method process.
@Override
public void process(CodeGenContext context) throws Exception {
try {
JavaCodeGenContext ctx = (JavaCodeGenContext) context;
int projectId = ctx.getProjectId();
File dir = new File(String.format("%s/%s/java", ctx.getGeneratePath(), projectId));
List<Callable<ExecuteResult>> spCallables = generateSpDao(ctx, dir);
TaskUtils.invokeBatch(spCallables);
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
throw e;
}
}
use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfSpProcessor method generateSpDao.
private List<Callable<ExecuteResult>> generateSpDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
Map<String, SpDbHost> _spHostMaps = ctx.getSpHostMaps();
List<Callable<ExecuteResult>> results = new ArrayList<Callable<ExecuteResult>>();
for (final SpDbHost host : _spHostMaps.values()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Generate SP[" + host.getDbSetName() + "] Dao, Pojo, Test");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sSpDao.java", mavenLikeDir.getAbsolutePath(), host.getDbSetName()), "templates/java/DAOBySp.java.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sSpDaoUnitTest.java", mavenLikeDir.getAbsolutePath(), host.getDbSetName()), "templates/java/test/DAOBySpUnitTest.java.tpl");
for (SpHost sp : host.getSpHosts()) {
sp.setDbSetName(host.getDbSetName());
context.put("host", sp);
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.java", mavenLikeDir.getAbsolutePath(), sp.getPojoClassName()), "templates/java/Pojo.java.tpl");
}
result.setSuccessal(true);
} catch (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.
the class JavaCodeGeneratorOfViewProcessor method process.
@Override
public void process(CodeGenContext context) throws Exception {
try {
JavaCodeGenContext ctx = (JavaCodeGenContext) context;
int projectId = ctx.getProjectId();
File dir = new File(String.format("%s/%s/java", ctx.getGeneratePath(), projectId));
List<Callable<ExecuteResult>> viewCallables = generateViewDao(ctx, dir);
TaskUtils.invokeBatch(viewCallables);
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
throw e;
}
}
Aggregations