use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator 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.csharp.CSharpDalGenerator 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;
}
use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpDalGenerator 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;
}
HashSet<String> hashSet = getProjectSqlStyles(id);
if (hashSet.isEmpty()) {
progress.setStatus(ProgressResource.FINISH);
status = Status.ERROR();
status.setInfo(String.format("Language error for project %s", id));
return status;
}
String code = "";
if (hashSet.contains(JAVA)) {
code = JAVA;
DalGenerator generator = new JavaDalGenerator();
CodeGenContext context = generator.createContext(id, true, progress, newPojo, false);
LoggerManager.getInstance().info(String.format("Begin to generate java task for project %s", id));
generateLanguageProject(generator, context);
LoggerManager.getInstance().info(String.format("Java task for project %s generated.", id));
}
if (hashSet.contains(CS)) {
// cs
code = "cs";
DalGenerator generator = new CSharpDalGenerator();
CodeGenContext context = generator.createContext(id, true, progress, newPojo, false);
LoggerManager.getInstance().info(String.format("Begin to generate csharp task for project %s", id));
generateLanguageProject(generator, context);
LoggerManager.getInstance().info(String.format("Csharp task for project %s generated.", id));
}
status = Status.OK();
status.setInfo(code);
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
status = Status.ERROR();
status.setInfo(e.getMessage());
return status;
} finally {
progress.setStatus(ProgressResource.FINISH);
}
return status;
}
Aggregations