use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext 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.CSharpCodeGenContext 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.generator.csharp.CSharpCodeGenContext 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.generator.csharp.CSharpCodeGenContext 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.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.
the class AbstractCSharpDataPreparer method buildTableHost.
protected CSharpTableHost buildTableHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, String table, DatabaseCategory dbCategory, List<StoredProcedure> allSpNames) throws Exception {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
if (!DbUtils.tableExists(tableViewSp.getAllInOneName(), table)) {
throw new Exception(String.format("表 %s 不存在,请编辑DAO再生成", table));
}
// 主键及所有列
List<AbstractParameterHost> allColumnsAbstract = DbUtils.getAllColumnNames(tableViewSp.getAllInOneName(), table, new CsharpColumnNameResultSetExtractor(tableViewSp.getAllInOneName(), table, dbCategory));
List<String> primaryKeyNames = DbUtils.getPrimaryKeyNames(tableViewSp.getAllInOneName(), table);
List<CSharpParameterHost> allColumns = new ArrayList<>();
for (AbstractParameterHost h : allColumnsAbstract) {
allColumns.add((CSharpParameterHost) h);
}
List<CSharpParameterHost> primaryKeys = new ArrayList<>();
for (CSharpParameterHost h : allColumns) {
if (primaryKeyNames.contains(h.getName())) {
h.setPrimary(true);
primaryKeys.add(h);
}
}
Queue<GenTaskBySqlBuilder> _sqlBuilders = ctx.getSqlBuilders();
List<GenTaskBySqlBuilder> currentTableBuilders = filterExtraMethods(_sqlBuilders, tableViewSp.getAllInOneName(), table);
List<CSharpMethodHost> methods = buildSqlBuilderMethodHost(allColumns, currentTableBuilders);
CSharpTableHost tableHost = new CSharpTableHost();
tableHost.setExtraMethods(methods);
tableHost.setNameSpace(ctx.getNamespace());
tableHost.setDatabaseCategory(dbCategory);
tableHost.setDbSetName(tableViewSp.getDatabaseSetName());
tableHost.setTableName(table);
tableHost.setClassName(CommonUtils.normalizeVariable(getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), table)));
tableHost.setTable(true);
tableHost.setSpa(tableViewSp.isCud_by_sp());
// SP方式增删改
if (tableHost.isSpa()) {
tableHost.setSpaInsert(CSharpSpaOperationHost.getSpaOperation(tableViewSp.getAllInOneName(), table, allSpNames, "i"));
tableHost.setSpaUpdate(CSharpSpaOperationHost.getSpaOperation(tableViewSp.getAllInOneName(), table, allSpNames, "u"));
tableHost.setSpaDelete(CSharpSpaOperationHost.getSpaOperation(tableViewSp.getAllInOneName(), table, allSpNames, "d"));
}
tableHost.setPrimaryKeys(primaryKeys);
tableHost.setColumns(allColumns);
tableHost.setHasPagination(tableViewSp.isPagination());
StoredProcedure expectSptI = new StoredProcedure();
expectSptI.setName(String.format("spT_%s_i", table));
StoredProcedure expectSptU = new StoredProcedure();
expectSptU.setName(String.format("spT_%s_u", table));
StoredProcedure expectSptD = new StoredProcedure();
expectSptD.setName(String.format("spT_%s_d", table));
tableHost.setHasSptI(allSpNames.contains(expectSptI));
tableHost.setHasSptU(allSpNames.contains(expectSptU));
tableHost.setHasSptD(allSpNames.contains(expectSptD));
tableHost.setHasSpt(tableHost.isHasSptI() || tableHost.isHasSptU() || tableHost.isHasSptD());
tableHost.setApi_list(tableViewSp.getApi_list());
return tableHost;
}
Aggregations