use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.
the class CSharpDataPreparerOfTableViewSpProcessor method prepareTable.
private List<Callable<ExecuteResult>> prepareTable(final CSharpCodeGenContext ctx, final Progress progress, final GenTaskByTableViewSp tableViewSp, final String[] tableNames, final DatabaseCategory dbCategory, final Queue<CSharpTableHost> _tableViewHosts) throws Exception {
List<Callable<ExecuteResult>> results = new ArrayList<>();
final List<StoredProcedure> allSpNames = DbUtils.getAllSpNames(tableViewSp.getAllInOneName());
for (final String table : tableNames) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
//progress.setOtherMessage("正在整理表 " + table);
ExecuteResult result = new ExecuteResult("Build Table[" + tableViewSp.getAllInOneName() + "." + table + "] Host");
progress.setOtherMessage(result.getTaskName());
CSharpTableHost currentTableHost;
try {
currentTableHost = buildTableHost(ctx, tableViewSp, table, dbCategory, allSpNames);
if (null != currentTableHost) {
_tableViewHosts.add(currentTableHost);
}
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.domain.StoredProcedure in project dal by ctripcorp.
the class CSharpDataPreparerOfTableViewSpProcessor method buildSpHost.
private CSharpTableHost buildSpHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, DatabaseCategory dbCategory, String spName) throws Exception {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
String schema = "dbo";
String realSpName = spName;
if (spName.contains(".")) {
String[] splitSp = StringUtils.split(spName, '.');
schema = splitSp[0];
realSpName = splitSp[1];
}
StoredProcedure currentSp = new StoredProcedure();
currentSp.setSchema(schema);
currentSp.setName(realSpName);
if (!DbUtils.spExists(tableViewSp.getAllInOneName(), currentSp)) {
throw new Exception(String.format("存储过程 %s 不存在,请修改DAO后再试!", currentSp.getName()));
}
List<AbstractParameterHost> params = DbUtils.getSpParams(tableViewSp.getAllInOneName(), currentSp, new CsharpSpParamResultSetExtractor());
List<CSharpParameterHost> realParams = new ArrayList<CSharpParameterHost>();
for (AbstractParameterHost p : params) {
realParams.add((CSharpParameterHost) p);
}
CSharpTableHost tableHost = new CSharpTableHost();
tableHost.setNameSpace(ctx.getNamespace());
tableHost.setDatabaseCategory(dbCategory);
tableHost.setDbSetName(tableViewSp.getDatabaseSetName());
tableHost.setClassName(getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), realSpName.replace("_", "")));
tableHost.setTable(false);
tableHost.setSpName(spName);
tableHost.setSpParams(realParams);
tableHost.setApi_list(tableViewSp.getApi_list());
return tableHost;
}
use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.
the class DatabaseResource method getTableSPNames.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("table_sps")
public Status getTableSPNames(@QueryParam("db_name") String setName) {
Status status = Status.OK;
TableSpNames tableSpNames = new TableSpNames();
List<String> views;
List<String> tables;
List<StoredProcedure> sps;
try {
DatabaseSetEntry databaseSetEntry = SpringBeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(setName);
String dbName = databaseSetEntry.getConnectionString();
views = DbUtils.getAllViewNames(dbName);
tables = DbUtils.getAllTableNames(dbName);
sps = DbUtils.getAllSpNames(dbName);
sps = filterSP(tables, sps);
java.util.Collections.sort(views, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.toLowerCase().compareTo(o2.toLowerCase());
}
});
java.util.Collections.sort(tables, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
return o1.toLowerCase().compareTo(o2.toLowerCase());
}
});
java.util.Collections.sort(sps);
tableSpNames.setSps(sps);
tableSpNames.setViews(views);
tableSpNames.setTables(tables);
tableSpNames.setDbType(DbUtils.getDbType(dbName));
status.setInfo(mapper.writeValueAsString(tableSpNames));
} catch (Exception e1) {
status = Status.ERROR;
status.setInfo(e1.getMessage());
return status;
}
return status;
}
use of com.ctrip.platform.dal.daogen.domain.StoredProcedure in project dal by ctripcorp.
the class JavaDataPreparerOfTableViewSpProcessor method buildSpHost.
private SpHost buildSpHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, String spName) throws Exception {
JavaCodeGenContext ctx = (JavaCodeGenContext) codeGenCtx;
String schema = "dbo";
String realSpName = spName;
if (spName.contains(".")) {
String[] splitSp = StringUtils.split(spName, '.');
schema = splitSp[0];
realSpName = splitSp[1];
}
StoredProcedure currentSp = new StoredProcedure();
currentSp.setSchema(schema);
currentSp.setName(realSpName);
if (!DbUtils.spExists(tableViewSp.getAllInOneName(), currentSp)) {
throw new Exception(String.format("The store procedure[%s, %s] doesn't exist, pls check", tableViewSp.getAllInOneName(), currentSp.getName()));
}
SpHost spHost = new SpHost();
String className = realSpName.replace("_", "");
className = getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), className);
spHost.setPackageName(ctx.getNamespace());
spHost.setDatabaseCategory(getDatabaseCategory(tableViewSp.getAllInOneName()));
spHost.setDbName(tableViewSp.getDatabaseSetName());
spHost.setPojoClassName(className);
spHost.setSpName(spName);
List<AbstractParameterHost> params = DbUtils.getSpParams(tableViewSp.getAllInOneName(), currentSp, new JavaSpParamResultSetExtractor(tableViewSp.getAllInOneName(), currentSp.getName()));
List<JavaParameterHost> realParams = new ArrayList<>();
String callParams = "";
if (null == params) {
throw new Exception(String.format("The sp[%s, %s] parameters is null", tableViewSp.getAllInOneName(), currentSp.getName()));
}
for (AbstractParameterHost p : params) {
callParams += "?,";
realParams.add((JavaParameterHost) p);
}
spHost.setCallParameters(StringUtils.removeEnd(callParams, ","));
spHost.setFields(realParams);
return spHost;
}
Aggregations