use of com.ctrip.platform.dal.daogen.DalGenerator 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.DalGenerator in project dal by ctripcorp.
the class ProjectResource method generateProject.
@POST
@Path("generate")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status generateProject(@Context HttpServletRequest request, @FormParam("project_id") int id, @FormParam("regenerate") boolean regen, @FormParam("language") String language, @FormParam("newPojo") boolean newPojo, @FormParam("random") String random) {
Status status = null;
Progress progress = null;
try {
String userNo = RequestUtil.getUserNo(request);
progress = ProgressResource.getProgress(userNo, id, random);
status = validatePermision(userNo, id);
if (status.getCode().equals(Status.ERROR.getCode())) {
progress.setStatus(ProgressResource.FINISH);
return status;
}
log.info(String.format("begain generate project: [id=%s; regen=%s; language=%s]", id, true, language));
DalGenerator generator = null;
CodeGenContext context = null;
HashSet<String> hashSet = getProjectSqlStyles(id);
String code = "";
if (hashSet.contains(JAVA)) {
code = JAVA;
generator = new JavaDalGenerator();
context = generator.createContext(id, true, progress, newPojo, false);
generateLanguageProject(generator, context);
}
if (hashSet.contains(CS)) {
// cs
code = "cs";
generator = new CSharpDalGenerator();
context = generator.createContext(id, true, progress, newPojo, false);
generateLanguageProject(generator, context);
}
status = Status.OK;
status.setInfo(code);
log.info(String.format("generate project[%s] completed.", id));
} catch (Exception e) {
status = Status.ERROR;
status.setInfo(e.getMessage());
progress.setOtherMessage(e.getMessage());
log.error(String.format("generate project[%s] failed.", id), e);
} finally {
progress.setStatus(ProgressResource.FINISH);
}
return status;
}
use of com.ctrip.platform.dal.daogen.DalGenerator 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