use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.
the class DaoByTableViewSp method getTasksByProjectId.
/**
* 根据项目主键查询所有任务
*
* @param projectId
* @return
*/
public List<GenTaskByTableViewSp> getTasksByProjectId(int projectId) throws SQLException {
FreeSelectSqlBuilder<List<GenTaskByTableViewSp>> builder = new FreeSelectSqlBuilder<>(dbCategory);
StringBuilder sb = new StringBuilder();
sb.append("SELECT id, project_id,db_name,table_names,view_names,sp_names,prefix,suffix, cud_by_sp,pagination,`generated`,version,update_user_no,update_time,comment,sql_style,api_list,approved,approveMsg, mode_type ");
sb.append("FROM task_table WHERE project_id=? order by id");
builder.setTemplate(sb.toString());
StatementParameters parameters = new StatementParameters();
int i = 1;
parameters.set(i++, "project_id", Types.INTEGER, projectId);
builder.mapWith(genTaskByTableViewSpRowMapper);
DalHints hints = DalHints.createIfAbsent(null).allowPartial();
List<GenTaskByTableViewSp> list = queryDao.query(builder, parameters, hints);
processList(list);
return list;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.
the class DaoByTableViewSp method updateAndGetAllTasks.
public List<GenTaskByTableViewSp> updateAndGetAllTasks(int projectId) throws SQLException {
List<GenTaskByTableViewSp> result = new ArrayList<>();
List<GenTaskByTableViewSp> list = getTasksByProjectId(projectId);
if (list == null || list.size() == 0)
return result;
for (GenTaskByTableViewSp entity : list) {
entity.setGenerated(true);
if (updateTask(entity) > 0) {
result.add(entity);
}
}
return result;
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.
the class GenTaskByTableViewResource method addTask.
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status addTask(@Context HttpServletRequest request, @FormParam("id") int id, @FormParam("project_id") int project_id, @FormParam("db_name") String set_name, @FormParam("table_names") String table_names, @FormParam("view_names") String view_names, @FormParam("sp_names") String sp_names, @FormParam("prefix") String prefix, @FormParam("suffix") String suffix, @FormParam("cud_by_sp") boolean cud_by_sp, @FormParam("pagination") boolean pagination, @FormParam("version") int version, @FormParam("action") String action, @FormParam("comment") String comment, // C#风格或者Java风格 @FormParam("length") boolean length,
@FormParam("sql_style") String sql_style, @FormParam("api_list") String api_list) throws Exception {
try {
GenTaskByTableViewSp task = new GenTaskByTableViewSp();
if (action.equalsIgnoreCase("delete")) {
task.setId(id);
if (0 >= BeanGetter.getDaoByTableViewSp().deleteTask(task)) {
return Status.ERROR();
}
} else {
String userNo = RequestUtil.getUserNo(request);
LoginUser user = BeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
task.setProject_id(project_id);
task.setDatabaseSetName(set_name);
task.setTable_names(table_names);
task.setView_names(view_names);
task.setSp_names(sp_names);
task.setPrefix(prefix);
task.setSuffix(suffix);
task.setCud_by_sp(cud_by_sp);
task.setPagination(pagination);
// task.setLength(length);
task.setUpdate_user_no(user.getUserName() + "(" + userNo + ")");
task.setUpdate_time(new Timestamp(System.currentTimeMillis()));
task.setComment(comment);
task.setSql_style(sql_style);
task.setApi_list(api_list);
task.setMode_type(DalClusterUtils.getModeTypeByDbBaseName(set_name));
if (needApproveTask(project_id, user.getId())) {
task.setApproved(1);
} else {
task.setApproved(2);
}
task.setApproveMsg("");
if (action.equalsIgnoreCase("update")) {
task.setId(id);
task.setVersion(BeanGetter.getDaoByTableViewSp().getVersionById(id));
if (0 >= BeanGetter.getDaoByTableViewSp().updateTask(task)) {
return Status.ERROR();
}
} else {
task.setGenerated(false);
task.setVersion(1);
if (0 >= BeanGetter.getDaoByTableViewSp().insertTask(task)) {
return Status.ERROR();
}
}
}
return Status.OK();
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
Status status = Status.ERROR();
status.setInfo(e.getMessage());
return status;
}
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp in project dal by ctripcorp.
the class JavaDataPreparerOfSqlBuilderProcessor method buildExtraSqlBuilderHost.
private JavaTableHost buildExtraSqlBuilderHost(CodeGenContext context, GenTaskBySqlBuilder sqlBuilder) throws Exception {
GenTaskByTableViewSp tableViewSp = new GenTaskByTableViewSp();
tableViewSp.setCud_by_sp(false);
tableViewSp.setPagination(false);
tableViewSp.setAllInOneName(sqlBuilder.getAllInOneName());
tableViewSp.setDatabaseSetName(sqlBuilder.getDatabaseSetName());
tableViewSp.setPrefix("");
tableViewSp.setSuffix("");
// tableViewSp.setLength(sqlBuilder.getLength());
DatabaseCategory dbCategory = DatabaseCategory.SqlServer;
String dbType = DbUtils.getDbType(sqlBuilder.getAllInOneName());
if (null != dbType && !dbType.equalsIgnoreCase("Microsoft SQL Server")) {
dbCategory = DatabaseCategory.MySql;
}
return buildTableHost(context, tableViewSp, sqlBuilder.getTable_name(), dbCategory);
}
use of com.ctrip.platform.dal.daogen.entity.GenTaskByTableViewSp 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