use of com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost 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.host.csharp.CSharpTableHost 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() throws Exception {
// 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 (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
use of com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost in project dal by ctripcorp.
the class CSharpDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.
private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext context) {
final CSharpCodeGenContext ctx = (CSharpCodeGenContext) context;
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> sqlBuilder : tempSqlBuildres.entrySet()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Build Extral SQL[" + sqlBuilder.getValue().getAllInOneName() + "." + sqlBuilder.getKey() + "] Host");
progress.setOtherMessage(result.getTaskName());
CSharpTableHost extraTableHost;
try {
extraTableHost = buildExtraSqlBuilderHost(ctx, sqlBuilder.getValue());
if (null != extraTableHost) {
tableViewHosts.add(extraTableHost);
}
result.setSuccessal(true);
} catch (Throwable e) {
throw new Exception(String.format("Task Id[%s]:%s\r\n", sqlBuilder.getValue().getId(), e.getMessage()), e);
}
return result;
}
};
results.add(worker);
}
}
return results;
}
use of com.ctrip.platform.dal.daogen.host.csharp.CSharpTableHost 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() throws Exception {
// 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 (Throwable e) {
throw e;
}
return result;
}
};
results.add(worker);
}
return results;
}
Aggregations