use of com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql 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.GenTaskByFreeSql in project dal by ctripcorp.
the class CSharpDataPreparerOfFreeSqlProcessor method prepareDbFromFreeSql.
private void prepareDbFromFreeSql(CodeGenContext codeGenCtx, List<GenTaskByFreeSql> freeSqls) throws Exception {
CSharpCodeGenContext ctx = (CSharpCodeGenContext) codeGenCtx;
Map<String, DatabaseHost> _dbHosts = ctx.getDbHosts();
Set<String> _freeDaos = ctx.getFreeDaos();
for (GenTaskByFreeSql task : freeSqls) {
addDatabaseSet(ctx, task.getDatabaseSetName());
_freeDaos.add(WordUtils.capitalize(task.getClass_name()));
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(task.getDatabaseSetName());
_dbHosts.put(task.getAllInOneName(), host);
}
}
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql in project dal by ctripcorp.
the class CSharpDataPreparerOfFreeSqlProcessor method freeSqlGroupBy.
private Map<String, List<GenTaskByFreeSql>> freeSqlGroupBy(List<GenTaskByFreeSql> tasks) {
Map<String, List<GenTaskByFreeSql>> groupBy = new HashMap<>();
for (GenTaskByFreeSql task : tasks) {
String key = String.format("%s_%s", task.getAllInOneName(), task.getClass_name().toLowerCase());
if (groupBy.containsKey(key)) {
groupBy.get(key).add(task);
} else {
groupBy.put(key, new ArrayList<GenTaskByFreeSql>());
groupBy.get(key).add(task);
}
}
return groupBy;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql in project dal by ctripcorp.
the class DaoByFreeSql method updateAndGetAllTasks.
public List<GenTaskByFreeSql> updateAndGetAllTasks(int projectId) {
final List<GenTaskByFreeSql> tasks = new ArrayList<>();
this.jdbcTemplate.query("SELECT id, project_id,db_name,class_name,pojo_name,method_name,crud_type," + "sql_content,parameters,`generated`,version,update_user_no,update_time,comment," + "scalarType,pojoType,pagination,sql_style,approved,approveMsg,hints" + " FROM task_sql WHERE project_id=?", new Object[] { projectId }, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
GenTaskByFreeSql task = GenTaskByFreeSql.visitRow(rs);
task.setGenerated(true);
if (updateTask(task) > 0) {
tasks.add(task);
}
}
});
return tasks;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskByFreeSql in project dal by ctripcorp.
the class DaoByFreeSql method updateAndGetTasks.
public List<GenTaskByFreeSql> updateAndGetTasks(int projectId) {
final List<GenTaskByFreeSql> tasks = new ArrayList<>();
this.jdbcTemplate.query("SELECT id, project_id,db_name,class_name,pojo_name,method_name,crud_type," + " sql_content,parameters,`generated`,version,update_user_no,update_time," + " comment,scalarType,pojoType,pagination,sql_style,approved,approveMsg,hints" + " FROM task_sql " + " WHERE project_id=? AND `generated`=FALSE", new Object[] { projectId }, new RowCallbackHandler() {
@Override
public void processRow(ResultSet rs) throws SQLException {
GenTaskByFreeSql task = GenTaskByFreeSql.visitRow(rs);
task.setGenerated(true);
if (updateTask(task) > 0) {
tasks.add(task);
}
}
});
return tasks;
}
Aggregations