use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class DaoBySqlBuilder method updateTask.
public int updateTask(GenTaskBySqlBuilder task) throws SQLException {
{
FreeSelectSqlBuilder<GenTaskBySqlBuilder> builder = new FreeSelectSqlBuilder<>(dbCategory);
builder.setTemplate("SELECT 1 FROM task_auto WHERE id != ? AND project_id=? AND db_name=? AND table_name=? AND method_name=? LIMIT 1");
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.set(i++, "id", Types.INTEGER, task.getId());
parameters.set(i++, "project_id", Types.INTEGER, task.getProject_id());
parameters.set(i++, "db_name", Types.VARCHAR, task.getDatabaseSetName());
parameters.set(i++, "table_name", Types.VARCHAR, task.getTable_name());
parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
builder.mapWith(genTaskBySqlBuilderRowMapper).requireFirst().nullable();
DalHints hints = DalHints.createIfAbsent(null).allowPartial();
GenTaskBySqlBuilder entity = queryDao.query(builder, parameters, hints);
if (entity != null)
return 0;
}
FreeUpdateSqlBuilder builder = new FreeUpdateSqlBuilder(dbCategory);
StringBuilder sb = new StringBuilder();
sb.append("UPDATE task_auto SET project_id=?,db_name=?, table_name=?, class_name=?,method_name=?,");
sb.append("sql_style=?,crud_type=?,fields=?,where_condition=?,sql_content=?,`generated`=?,");
sb.append("version=version+1,update_user_no=?,update_time=?,comment=?,scalarType=?,");
sb.append("pagination=?,orderby=?,approved=?,approveMsg=?,hints=? ");
sb.append("WHERE id=? AND version = ?");
builder.setTemplate(sb.toString());
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.set(i++, "project_id", Types.INTEGER, task.getProject_id());
parameters.set(i++, "db_name", Types.VARCHAR, task.getDatabaseSetName());
parameters.set(i++, "table_name", Types.VARCHAR, task.getTable_name());
parameters.set(i++, "class_name", Types.VARCHAR, task.getClass_name());
parameters.set(i++, "method_name", Types.VARCHAR, task.getMethod_name());
parameters.set(i++, "sql_style", Types.VARCHAR, task.getSql_style());
parameters.set(i++, "crud_type", Types.VARCHAR, task.getCrud_type());
parameters.set(i++, "fields", Types.LONGVARCHAR, task.getFields());
parameters.set(i++, "where_condition", Types.LONGVARCHAR, task.getCondition());
parameters.set(i++, "sql_content", Types.LONGVARCHAR, task.getSql_content());
parameters.set(i++, "generated", Types.BIT, task.getGenerated());
parameters.set(i++, "update_user_no", Types.VARCHAR, task.getUpdate_user_no());
parameters.set(i++, "update_time", Types.TIMESTAMP, task.getUpdate_time());
parameters.set(i++, "comment", Types.LONGVARCHAR, task.getComment());
parameters.set(i++, "scalarType", Types.VARCHAR, task.getScalarType());
parameters.set(i++, "pagination", Types.BIT, task.getPagination());
parameters.set(i++, "orderby", Types.VARCHAR, task.getOrderby());
parameters.set(i++, "approved", Types.INTEGER, task.getApproved());
parameters.set(i++, "approveMsg", Types.LONGVARCHAR, task.getApproveMsg());
parameters.set(i++, "hints", Types.VARCHAR, task.getHints());
// parameters.set(i++, "length", Types.TINYINT, task.getLength());
parameters.set(i++, "id", Types.INTEGER, task.getId());
parameters.set(i++, "version", Types.INTEGER, task.getVersion());
DalHints hints = DalHints.createIfAbsent(null);
return queryDao.update(builder, parameters, hints);
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class DaoBySqlBuilder method updateAndGetTasks.
public List<GenTaskBySqlBuilder> updateAndGetTasks(int projectId) throws SQLException {
FreeSelectSqlBuilder<List<GenTaskBySqlBuilder>> builder = new FreeSelectSqlBuilder<>(dbCategory);
StringBuilder sb = new StringBuilder();
sb.append("SELECT id, project_id, db_name,table_name,class_name,method_name,sql_style,crud_type,fields,where_condition,sql_content,`generated`,version,update_user_no,update_time,comment,scalarType,pagination,orderby,approved,approveMsg,hints ");
sb.append("FROM task_auto WHERE project_id=? AND `generated`=FALSE");
builder.setTemplate(sb.toString());
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.set(i++, "project_id", Types.INTEGER, projectId);
builder.mapWith(genTaskBySqlBuilderRowMapper);
DalHints hints = DalHints.createIfAbsent(null).allowPartial();
List<GenTaskBySqlBuilder> list = queryDao.query(builder, parameters, hints);
List<GenTaskBySqlBuilder> result = new ArrayList<>();
if (list == null || list.size() == 0)
return result;
processList(list);
for (GenTaskBySqlBuilder entity : list) {
entity.setGenerated(true);
if (updateTask(entity) > 0) {
result.add(entity);
}
}
return result;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class JavaDataPreparerOfSqlBuilderProcessor method sqlBuilderBroupBy.
private Map<String, List<GenTaskBySqlBuilder>> sqlBuilderBroupBy(Queue<GenTaskBySqlBuilder> tasks) {
Map<String, List<GenTaskBySqlBuilder>> map = new HashMap<>();
if (tasks == null || tasks.size() == 0)
return map;
for (GenTaskBySqlBuilder task : tasks) {
String key = String.format("%s_%s", task.getAllInOneName(), task.getTable_name());
if (!map.containsKey(key))
map.put(key, new ArrayList<GenTaskBySqlBuilder>());
map.get(key).add(task);
}
return map;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder in project dal by ctripcorp.
the class JavaDataPreparerOfSqlBuilderProcessor method prepareSqlBuilder.
private List<Callable<ExecuteResult>> prepareSqlBuilder(CodeGenContext context) throws Exception {
final JavaCodeGenContext ctx = (JavaCodeGenContext) context;
final Progress progress = ctx.getProgress();
List<Callable<ExecuteResult>> results = new ArrayList<>();
Queue<GenTaskBySqlBuilder> sqlBuilders = ctx.getSqlBuilders();
final Queue<JavaTableHost> tableHosts = ctx.getTableHosts();
if (sqlBuilders.size() > 0) {
Map<String, List<GenTaskBySqlBuilder>> tempSqlBuildres = sqlBuilderBroupBy(sqlBuilders);
for (final Map.Entry<String, List<GenTaskBySqlBuilder>> sqlBuilder : tempSqlBuildres.entrySet()) {
for (final GenTaskBySqlBuilder builder : sqlBuilder.getValue()) {
Callable<ExecuteResult> worker = new Callable<ExecuteResult>() {
@Override
public ExecuteResult call() throws Exception {
ExecuteResult result = new ExecuteResult("Build Extral SQL[" + builder.getAllInOneName() + "." + sqlBuilder.getKey() + "] Host");
progress.setOtherMessage(result.getTaskName());
try {
JavaTableHost extraTableHost = buildExtraSqlBuilderHost(ctx, builder);
if (null != extraTableHost) {
tableHosts.add(extraTableHost);
}
result.setSuccessal(true);
} catch (Throwable e) {
progress.setOtherMessage(e.getMessage());
throw new Exception(String.format("Task Id[%s]:%s\r\n", builder.getId(), e.getMessage()), e);
}
return result;
}
};
results.add(worker);
}
}
}
return results;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskBySqlBuilder 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);
}
}
}
Aggregations