use of com.ctrip.platform.dal.daogen.entity.Progress in project dal by ctripcorp.
the class ProgressResource method poll.
@Path("/poll")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Progress poll(@Context HttpServletRequest request, @QueryParam("project_id") int project_id, @QueryParam("regenerate") boolean regen, @QueryParam("language") String language, @QueryParam("random") String random) {
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
String userNo = RequestUtil.getUserNo(request);
Progress progress = getProgress(userNo, project_id, random);
if (FINISH.equals(progress.getStatus())) {
release(progress);
Progress success = new Progress();
success.setPercent(100);
success.setStatus(FINISH);
success.setOtherMessage(SUCCESS_MESSAGE);
return success;
}
updatePercent(progress);
return progress;
}
use of com.ctrip.platform.dal.daogen.entity.Progress in project dal by ctripcorp.
the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.
private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext codeGenCtx) {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
final Queue<CSharpTableHost> _tableViewHosts = ctx.getTableViewHosts();
if (_sqlBuilders.size() > 0) {
Map<String, GenTaskBySqlBuilder> _TempSqlBuildres = sqlBuilderBroupBy(_sqlBuilders);
for (final Map.Entry<String, GenTaskBySqlBuilder> _table : _TempSqlBuildres.entrySet()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
/*progress.setOtherMessage("正在整理表 "
+ _table.getValue().getClass_name());*/
ExecuteResult result = new ExecuteResult("Build Extral SQL[" + _table.getValue().getAllInOneName() + "." + _table.getKey() + "] Host");
progress.setOtherMessage(result.getTaskName());
CSharpTableHost extraTableHost;
try {
extraTableHost = buildExtraSqlBuilderHost(ctx, _table.getValue());
if (null != extraTableHost) {
_tableViewHosts.add(extraTableHost);
}
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 CSharpCodeGeneratorOfSpProcessor method generateSpDao.
private List<Callable<ExecuteResult>> generateSpDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Queue<CSharpTableHost> _spHosts = ctx.getSpHosts();
for (final CSharpTableHost host : _spHosts) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() {
//progress.setOtherMessage("正在生成 " + host.getClassName());
ExecuteResult result = new ExecuteResult("Generate SP[" + host.getClassName() + "] 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/DAOBySp.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/PojoBySp.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/SpTest.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), host.getClassName()), "templates/csharp/test/SpUnitTest.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 CSharpDataPreparerOfFreeSqlProcessor method prepareFreeSql.
private List<Callable<ExecuteResult>> prepareFreeSql(CodeGenContext codeGenCtx) throws Exception {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
int projectId = ctx.getProjectId();
boolean regenerate = ctx.isRegenerate();
final Progress progress = ctx.getProgress();
final String namespace = ctx.getNamespace();
List<GenTaskByFreeSql> freeSqlTasks;
if (regenerate) {
freeSqlTasks = daoByFreeSql.updateAndGetAllTasks(projectId);
prepareDbFromFreeSql(ctx, freeSqlTasks);
} else {
freeSqlTasks = daoByFreeSql.updateAndGetTasks(projectId);
prepareDbFromFreeSql(ctx, daoByFreeSql.getTasksByProjectId(projectId));
}
if (!ctx.isIgnoreApproveStatus() && freeSqlTasks != null && freeSqlTasks.size() > 0) {
Iterator<GenTaskByFreeSql> ite = freeSqlTasks.iterator();
while (ite.hasNext()) {
int approved = ite.next().getApproved();
if (approved != 2 && approved != 0) {
ite.remove();
}
}
}
// 首先按照DbName以及ClassName做一次GroupBy,且ClassName不区分大小写
final Map<String, List<GenTaskByFreeSql>> groupBy = freeSqlGroupBy(freeSqlTasks);
List<Callable<ExecuteResult>> results = new ArrayList<>();
final Map<String, CSharpFreeSqlPojoHost> _freeSqlPojoHosts = ctx.getFreeSqlPojoHosts();
final Queue<CSharpFreeSqlHost> _freeSqlHosts = ctx.getFreeSqlHosts();
// 随后,以DbName以及ClassName为维度,为每个维度生成一个DAO类
for (final Map.Entry<String, List<GenTaskByFreeSql>> entry : groupBy.entrySet()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Build Free SQL[" + entry.getKey() + "] Host");
progress.setOtherMessage(result.getTaskName());
try {
List<GenTaskByFreeSql> currentTasks = entry.getValue();
if (currentTasks.size() < 1)
return result;
CSharpFreeSqlHost host = new CSharpFreeSqlHost();
host.setDbSetName(currentTasks.get(0).getDatabaseSetName());
host.setClassName(CommonUtils.normalizeVariable(WordUtils.capitalize(currentTasks.get(0).getClass_name())));
host.setNameSpace(namespace);
host.setDatabaseCategory(getDatabaseCategory(currentTasks.get(0).getAllInOneName()));
List<CSharpMethodHost> methods = new ArrayList<>();
// 每个Method可能就有一个Pojo
for (GenTaskByFreeSql task : currentTasks) {
CSharpMethodHost method = buildFreeSqlMethodHost(ctx, task);
if (!_freeSqlPojoHosts.containsKey(task.getPojo_name()) && method.getPojoName() != null && !method.getPojoName().isEmpty() && (!method.isFirstOrSingle() || !method.isSampleType()) && !"update".equalsIgnoreCase(task.getCrud_type())) {
CSharpFreeSqlPojoHost freeSqlPojoHost = buildFreeSqlPojoHost(ctx, task);
if (null != freeSqlPojoHost) {
_freeSqlPojoHosts.put(task.getPojo_name(), freeSqlPojoHost);
}
}
methods.add(method);
}
host.setMethods(methods);
_freeSqlHosts.add(host);
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 CSharpCodeGeneratorOfFreeSqlProcessor method generateFreeSqlDao.
private List<Callable<ExecuteResult>> generateFreeSqlDao(CodeGenContext codeGenCtx, final File mavenLikeDir) {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Map<String, CSharpFreeSqlPojoHost> _freeSqlPojoHosts = ctx.getFreeSqlPojoHosts();
for (final CSharpFreeSqlPojoHost host : _freeSqlPojoHosts.values()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() {
//progress.setOtherMessage("正在生成 " + host.getClassName());
ExecuteResult result = new ExecuteResult("Generate Free SQL[" + host.getClassName() + "] Pojo");
progress.setOtherMessage(result.getTaskName());
try {
VelocityContext context = GenUtils.buildDefaultVelocityContext();
context.put("host", host);
GenUtils.mergeVelocityContext(context, String.format("%s/Entity/%s.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), ctx.isNewPojo() ? "templates/csharp/PojoNew.cs.tpl" : "templates/csharp/Pojo.cs.tpl");
result.setSuccessal(true);
} catch (Exception e) {
log.error(result.getTaskName() + "exception", e);
}
return result;
}
};
results.add(worker);
}
ProgressResource.addDoneFiles(progress, _freeSqlPojoHosts.size());
Queue<CSharpFreeSqlHost> _freeSqlHosts = ctx.getFreeSqlHosts();
for (final CSharpFreeSqlHost host : _freeSqlHosts) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() {
//progress.setOtherMessage("正在生成 " + host.getClassName());
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.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/dao/freesql/FreeSqlDAO.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sTest.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/test/FreeSqlTest.cs.tpl");
GenUtils.mergeVelocityContext(context, String.format("%s/Test/%sUnitTest.cs", mavenLikeDir.getAbsolutePath(), CommonUtils.normalizeVariable(host.getClassName())), "templates/csharp/test/FreeSqlUnitTest.cs.tpl");
result.setSuccessal(true);
} catch (Exception e) {
log.error(result.getTaskName() + "exception", e);
}
return result;
}
};
results.add(worker);
}
return results;
}
Aggregations