use of com.ctrip.platform.dal.daogen.entity.Progress 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.entity.Progress in project dal by ctripcorp.
the class CSharpCodeGeneratorOfSpProcessor method process.
@Override
public void process(CodeGenContext context) throws Exception {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
int projectId = ctx.getProjectId();
Progress progress = ctx.getProgress();
final File dir = new File(String.format("%s/%s/cs", ctx.getGeneratePath(), projectId));
List<Callable<ExecuteResult>> spCallables = generateSpDao(ctx, dir);
TaskUtils.invokeBatch(log, spCallables);
ProgressResource.addDoneFiles(progress, ctx.getSpHosts().size());
}
use of com.ctrip.platform.dal.daogen.entity.Progress in project dal by ctripcorp.
the class CSharpCodeGeneratorOfTableProcessor method process.
@Override
public void process(CodeGenContext context) throws Exception {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
int projectId = ctx.getProjectId();
Progress progress = ctx.getProgress();
final File dir = new File(String.format("%s/%s/cs", ctx.getGeneratePath(), projectId));
List<Callable<ExecuteResult>> tableCallables = generateTableDao(ctx, dir);
TaskUtils.invokeBatch(log, tableCallables);
ProgressResource.addDoneFiles(progress, ctx.getTableViewHosts().size());
}
use of com.ctrip.platform.dal.daogen.entity.Progress in project dal by ctripcorp.
the class CSharpCodeGeneratorOfTableProcessor method generateTableDao.
private List<Callable<ExecuteResult>> generateTableDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Queue<CSharpTableHost> _tableViewHosts = ctx.getTableViewHosts();
for (final CSharpTableHost host : _tableViewHosts) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() {
//progress.setOtherMessage("正在生成 " + host.getClassName());
ExecuteResult result = new ExecuteResult("Generate Table[" + host.getTableName() + "] Dao");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Dao/%sDao.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/dao/standard/DAO.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), ctx.isNewPojo() ? "templates/csharp/PojoNew.cs.tpl" : "templates/csharp/Pojo.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/IDao/I%sDao.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/dao/standard/IDAO.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/DAOTest.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/DAOUnitTest.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.entity.Progress in project dal by ctripcorp.
the class CSharpDataPreparerOfTableViewSpProcessor method prepareTableViewSp.
private List<Callable<ExecuteResult>> prepareTableViewSp(CodeGenContext codeGenCtx) throws Exception {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) 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<CSharpTableHost> _spHosts = ctx.getSpHosts();
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;
}
final Queue<CSharpTableHost> _tableViewHosts = ctx.getTableViewHosts();
results.addAll(prepareTable(ctx, progress, tableViewSp, tableNames, dbCategory, _tableViewHosts));
results.addAll(prepareView(ctx, progress, tableViewSp, viewNames, dbCategory, _tableViewHosts));
results.addAll(prepareSp(ctx, progress, _spHosts, tableViewSp, spNames, dbCategory));
}
return results;
}
Aggregations