use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.
the class AbstractCSharpDataPreparer method addDatabaseSet.
protected void addDatabaseSet(CodeGenContext codeGenCtx, String databaseSetName) {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
List<DatabaseSet> sets = daoOfDatabaseSet.getAllDatabaseSetByName(databaseSetName);
if (null == sets || sets.isEmpty()) {
// exist", databaseSetName));
return;
}
DalConfigHost dalConfigHost = ctx.getDalConfigHost();
dalConfigHost.addDatabaseSet(sets);
for (DatabaseSet databaseSet : sets) {
List<DatabaseSetEntry> entries = daoOfDatabaseSet.getAllDatabaseSetEntryByDbsetid(databaseSet.getId());
if (null == entries || entries.isEmpty()) {
// any entries", databaseSet.getId()));
continue;
}
dalConfigHost.addDatabaseSetEntry(entries);
}
}
use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext 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;
}
use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.
the class CSharpDataPreparerOfTableViewSpProcessor method buildViewHost.
private CSharpTableHost buildViewHost(CodeGenContext codeGenCtx, GenTaskByTableViewSp tableViewSp, DatabaseCategory dbCategory, String view) throws Exception {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
if (!DbUtils.viewExists(tableViewSp.getAllInOneName(), view)) {
throw new Exception(String.format("视图 %s 不存在,请编辑DAO再生成", view));
}
List<AbstractParameterHost> allColumnsAbstract = DbUtils.getAllColumnNames(tableViewSp.getAllInOneName(), view, new CsharpColumnNameResultSetExtractor(tableViewSp.getAllInOneName(), view, dbCategory));
List<CSharpParameterHost> allColumns = new ArrayList<>();
for (AbstractParameterHost h : allColumnsAbstract) {
allColumns.add((CSharpParameterHost) h);
}
CSharpTableHost tableHost = new CSharpTableHost();
tableHost.setNameSpace(ctx.getNamespace());
tableHost.setDatabaseCategory(dbCategory);
tableHost.setDbSetName(tableViewSp.getDatabaseSetName());
tableHost.setTableName(view);
tableHost.setClassName(CommonUtils.normalizeVariable(getPojoClassName(tableViewSp.getPrefix(), tableViewSp.getSuffix(), view)));
tableHost.setTable(false);
tableHost.setSpa(false);
tableHost.setColumns(allColumns);
tableHost.setHasPagination(tableViewSp.isPagination());
return tableHost;
}
use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext in project dal by ctripcorp.
the class CSharpDataPreparerOfTableViewSpProcessor method prepareDbFromTableViewSp.
private void prepareDbFromTableViewSp(CodeGenContext codeGenCtx, List<GenTaskByTableViewSp> tableViewSps, List<GenTaskBySqlBuilder> sqlBuilders) throws Exception {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
Set<String> existsTable = new HashSet<>();
Set<String> _tableDaos = ctx.getTableDaos();
Set<String> _spDaos = ctx.getSpDaos();
Map<String, DatabaseHost> _dbHosts = ctx.getDbHosts();
for (GenTaskByTableViewSp task : tableViewSps) {
for (String table : StringUtils.split(task.getTable_names(), ",")) {
_tableDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), table));
existsTable.add(table);
}
for (String table : StringUtils.split(task.getView_names(), ",")) {
_tableDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), table));
}
for (String table : StringUtils.split(task.getSp_names(), ",")) {
String realSpName = table;
if (table.contains(".")) {
String[] splitSp = StringUtils.split(table, '.');
realSpName = splitSp[1];
}
_spDaos.add(getPojoClassName(task.getPrefix(), task.getSuffix(), realSpName.replace("_", "")));
}
addDatabaseSet(ctx, task.getDatabaseSetName());
if (!_dbHosts.containsKey(task.getAllInOneName())) {
String provider = "sqlProvider";
String dbType = DbUtils.getDbType(task.getAllInOneName());
if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
provider = "mySqlProvider";
}
DatabaseHost host = new DatabaseHost();
host.setAllInOneName(task.getAllInOneName());
host.setProviderType(provider);
host.setDatasetName(host.getAllInOneName());
_dbHosts.put(task.getAllInOneName(), host);
}
}
for (GenTaskBySqlBuilder task : sqlBuilders) {
if (!existsTable.contains(task.getTable_name())) {
_tableDaos.add(getPojoClassName("", "", task.getTable_name()));
}
addDatabaseSet(ctx, task.getDatabaseSetName());
if (!_dbHosts.containsKey(task.getAllInOneName())) {
String provider = "sqlProvider";
String dbType = DbUtils.getDbType(task.getAllInOneName());
if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
provider = "mySqlProvider";
}
DatabaseHost host = new DatabaseHost();
host.setAllInOneName(task.getAllInOneName());
host.setProviderType(provider);
host.setDatasetName(host.getAllInOneName());
_dbHosts.put(task.getAllInOneName(), host);
}
}
}
use of com.ctrip.platform.dal.daogen.generator.csharp.CSharpCodeGenContext 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;
}
Aggregations