use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.
the class JavaCodeGenContextCreator method process.
@Override
public void process(CodeGenContext context) throws Exception {
JavaCodeGenContext ctx = (JavaCodeGenContext) context;
Project project = SpringBeanGetter.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());
}
use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.
the class JavaDataPreparerOfTableViewSpProcessor method prepareTableViewSp.
private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext codeGenCtx) throws Exception {
final JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
int projectId = ctx.getProjectId();
boolean regenerate = ctx.isRegenerate();
final Progress progress = ctx.getProgress();
List<GenTaskByTableViewSp> tableViewSpTasks;
List<GenTaskBySqlBuilder> sqlBuilderTasks;
if (regenerate) {
tableViewSpTasks = daoByTableViewSp.updateAndGetAllTasks(projectId);
sqlBuilderTasks = daoBySqlBuilder.updateAndGetAllTasks(projectId);
prepareDbFromTableViewSp(ctx, tableViewSpTasks, sqlBuilderTasks);
} else {
tableViewSpTasks = daoByTableViewSp.updateAndGetTasks(projectId);
sqlBuilderTasks = daoBySqlBuilder.updateAndGetTasks(projectId);
prepareDbFromTableViewSp(ctx, daoByTableViewSp.getTasksByProjectId(projectId), daoBySqlBuilder.getTasksByProjectId(projectId));
}
if (!ctx.isIgnoreApproveStatus() && tableViewSpTasks != null && tableViewSpTasks.size() > 0) {
Iterator<GenTaskByTableViewSp> ite = tableViewSpTasks.iterator();
while (ite.hasNext()) {
int approved = ite.next().getApproved();
if (approved != 2 && approved != 0) {
ite.remove();
}
}
}
if (!ctx.isIgnoreApproveStatus() && sqlBuilderTasks != null && sqlBuilderTasks.size() > 0) {
Iterator<GenTaskBySqlBuilder> ite = sqlBuilderTasks.iterator();
while (ite.hasNext()) {
int approved = ite.next().getApproved();
if (approved != 2 && approved != 0) {
ite.remove();
}
}
}
Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
for (GenTaskBySqlBuilder _t : sqlBuilderTasks) {
_sqlBuilders.add(_t);
}
final Queue<JavaTableHost> _tableHosts = ctx.getTableHosts();
final Queue<ViewHost> _viewHosts = ctx.getViewHosts();
final Queue<SpHost> _spHosts = ctx.getSpHosts();
final Map<String, SpDbHost> _spHostMaps = ctx.getSpHostMaps();
List<Callable<ExecuteResult>> results = new ArrayList<>();
for (final GenTaskByTableViewSp tableViewSp : tableViewSpTasks) {
final String[] viewNames = StringUtils.split(tableViewSp.getView_names(), ",");
final String[] tableNames = StringUtils.split(tableViewSp.getTable_names(), ",");
final String[] spNames = StringUtils.split(tableViewSp.getSp_names(), ",");
final DatabaseCategory dbCategory;
String dbType = DbUtils.getDbType(tableViewSp.getAllInOneName());
if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
dbCategory = DatabaseCategory.MySql;
} else {
dbCategory = DatabaseCategory.SqlServer;
}
results.addAll(prepareTable(ctx, progress, _tableHosts, tableViewSp, tableNames, dbCategory));
results.addAll(prepareView(ctx, progress, _viewHosts, tableViewSp, viewNames, dbCategory));
results.addAll(prepareSp(ctx, progress, _spHosts, _spHostMaps, tableViewSp, spNames));
}
return results;
}
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 AbstractJavaDataPreparer method filterExtraMethods.
private List<GenTaskBySqlBuilder> filterExtraMethods(CodeGenContext codeGenCtx, String allInOneName, String tableName) {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
List<GenTaskBySqlBuilder> currentTableBuilders = new ArrayList<>();
Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
Iterator<GenTaskBySqlBuilder> iter = sqlBuilders.iterator();
while (iter.hasNext()) {
GenTaskBySqlBuilder currentSqlBuilder = iter.next();
if (currentSqlBuilder.getAllInOneName().equals(allInOneName) && currentSqlBuilder.getTable_name().equals(tableName)) {
currentTableBuilders.add(currentSqlBuilder);
iter.remove();
}
}
return currentTableBuilders;
}
use of com.ctrip.platform.dal.daogen.generator.java.JavaCodeGenContext in project dal by ctripcorp.
the class CommonJavaCodeGeneratorOfOthersProcessor method process.
@Override
public void process(CodeGenContext context) throws Exception {
JavaCodeGenContext ctx = (JavaCodeGenContext) context;
int projectId = ctx.getProjectId();
File dir = new File(String.format("%s/%s/java", ctx.getGeneratePath(), projectId));
VelocityContext vltCcontext = GenUtils.buildDefaultVelocityContext();
vltCcontext.put("host", ctx.getDalConfigHost());
GenUtils.mergeVelocityContext(vltCcontext, String.format("%s/dal.xml", dir.getAbsolutePath()), "templates/java/Dal.config.java.tpl");
vltCcontext.put("host", ctx.getContextHost());
GenUtils.mergeVelocityContext(vltCcontext, String.format("%s/datasource.xml", dir.getAbsolutePath()), "templates/java/DataSource.java.tpl");
}
Aggregations