use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class GenTaskByFreeSqlResource method getMockValue.
@POST
@Path("getMockValue")
public Status getMockValue(@FormParam("params") String params) {
try {
Status status = Status.OK();
int[] sqlTypes = getSqlTypes(params);
Object[] values = SQLValidation.mockStringValues(sqlTypes);
try {
status.setInfo(mapper.writeValueAsString(values));
} catch (JsonProcessingException e) {
status = Status.ERROR();
status.setInfo("获取mock value异常.");
}
return status;
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
Status status = Status.ERROR();
status.setInfo(e.getMessage());
return status;
}
}
use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class GenTaskBySqlBuilderResource 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_name") String table_name, @FormParam("method_name") String method_name, @FormParam("crud_type") String crud_type, @FormParam("fields") String fields, @FormParam("condition") String condition, @FormParam("sql_content") String sql_content, @FormParam("version") int version, @FormParam("action") String action, @FormParam("params") String params, @FormParam("comment") String comment, @FormParam("scalarType") String scalarType, @FormParam("pagination") boolean pagination, @FormParam("orderby") String orderby, // C#风格或者Java风格
@FormParam("hints") String hints, // C#风格或者Java风格
@FormParam("sql_style") String sql_style) throws // length,
Exception {
try {
Status status = Status.OK();
GenTaskBySqlBuilder task = new GenTaskBySqlBuilder();
if (action.equalsIgnoreCase("delete")) {
task.setId(id);
if (0 >= BeanGetter.getDaoBySqlBuilder().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_name(table_name);
task.setMethod_name(method_name);
task.setSql_style(sql_style);
task.setCrud_type(crud_type);
task.setFields(fields);
task.setCondition(condition);
task.setUpdate_user_no(user.getUserName() + "(" + userNo + ")");
task.setUpdate_time(new Timestamp(System.currentTimeMillis()));
task.setComment(comment);
task.setScalarType(scalarType);
task.setPagination(pagination);
task.setOrderby(orderby);
task.setHints(hints);
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.getDaoBySqlBuilder().getVersionById(id));
task.setSql_content(sql_content);
if (0 >= BeanGetter.getDaoBySqlBuilder().updateTask(task)) {
status = Status.ERROR();
status.setInfo("更新出错,数据是否合法?或者已经有同名方法?");
return status;
}
} else {
task.setGenerated(false);
task.setVersion(1);
task.setSql_content(sql_content);
if (0 >= BeanGetter.getDaoBySqlBuilder().insertTask(task)) {
status = Status.ERROR();
status.setInfo("新增出错,数据是否合法?或者已经有同名方法?");
return status;
}
}
}
return status;
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
Status status = Status.ERROR();
status.setInfo(e.getMessage());
return status;
}
}
use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class GenTaskBySqlBuilderResource method validateSQL.
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("sqlValidate")
public Status validateSQL(@FormParam("db_name") String set_name, @FormParam("table_name") String table_name, @FormParam("crud_type") String crud_type, @FormParam("fields") String fields, @FormParam("condition") String condition, @FormParam("sql_content") String sql_content, @FormParam("pagination") boolean pagination, @FormParam("mockValues") String mockValues) throws Exception {
Status status = Status.OK();
sql_content = sql_content.replaceAll("[@:]\\w+", "?");
int[] sqlTypes = getSqlTypes(set_name, table_name, crud_type, fields, condition);
String[] vals = mockValues.split(";");
DatabaseSetEntry databaseSetEntry = BeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(set_name);
String dbName = databaseSetEntry.getConnectionString();
ValidateResult validResult = null;
String resultPrefix = "The affected rows is ";
try {
if (pagination && "select".equalsIgnoreCase(crud_type)) {
sql_content = SqlBuilder.pagingQuerySql(sql_content, DbUtils.getDatabaseCategory(dbName), CurrentLanguage.Java);
sql_content = String.format(sql_content, 1, 2);
}
if ("select".equalsIgnoreCase(crud_type)) {
validResult = SQLValidation.queryValidate(dbName, sql_content, sqlTypes, vals);
resultPrefix = "The result count is ";
} else {
validResult = SQLValidation.updateValidate(dbName, sql_content, sqlTypes, vals);
}
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
status = Status.ERROR();
status.setInfo(e.getMessage());
return status;
}
if (validResult != null && validResult.isPassed()) {
status.setInfo(resultPrefix + validResult.getAffectRows());
status.setExplanJson(validResult.getMessage());
} else {
status = Status.ERROR();
status.setInfo(validResult.getMessage());
}
return status;
}
use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class ProjectResource method addLackDbset.
/**
* 一键添加project缺失的databaseSet
*
* @param project_id
* @return
*/
@POST
@Path("addLackDbset")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Status addLackDbset(@FormParam("project_id") int project_id) {
try {
int groupId = BeanGetter.getDaoOfProject().getProjectByID(project_id).getDal_group_id();
String info = addLackDb(project_id, groupId);
Set<String> notExistDbset = getLackDbset(groupId, project_id);
for (String dbsetName : notExistDbset) {
List<DatabaseSet> dbsets = BeanGetter.getDaoOfDatabaseSet().getAllDatabaseSetByName(dbsetName);
if (null != dbsets && dbsets.size() > 0) {
info += "<span style='color:red;'>databaseSet Name --> " + dbsetName + " 已经存在,请重新命名,再手动添加!" + "</span><br/>";
} else {
List<String> dbAllinOneNames = BeanGetter.getDaoOfDalGroupDB().getAllDbAllinOneNames();
Set<String> allInOneDbnames = new HashSet<String>(dbAllinOneNames);
if (allInOneDbnames.contains(dbsetName)) {
info += genDefaultDbset(groupId, dbsetName);
} else {
info += "<span style='color:red;'>databaseSet Name --> " + dbsetName + "在数据库中不存在,请手动添加!" + "</span><br/>";
}
}
}
if (!"".equals(info)) {
info += "点击此处添加databaseSet : <a href='dbsetsmanage.jsp' target='_blank'>逻辑数据库管理</a><br/>";
info += "点击此处添加组内database : <a href='dbmanage.jsp' target='_blank'>数据库管理</a><br/>";
Status status = Status.ERROR();
status.setInfo(info);
return status;
} else {
Status status = Status.OK();
status.setInfo("一键补全成功!");
return status;
}
} catch (Throwable e) {
LoggerManager.getInstance().error(e);
Status status = Status.ERROR();
status.setInfo(e.getMessage());
return status;
}
}
use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.
the class ProjectResource method validateDbPermision.
private Status validateDbPermision(int groupId, int project_id) throws SQLException {
Status status = Status.ERROR();
Set<String> notExistDb = getLackDatabase(groupId, project_id);
if (notExistDb == null || notExistDb.size() <= 0) {
return Status.OK();
} else {
String info = "<ul>";
for (String temp : notExistDb) {
info += "<li>" + temp + "</li>";
}
info += "</ul>";
DalGroup group = BeanGetter.getDaoOfDalGroup().getDalGroupById(groupId);
info = "你所在" + group.getGroup_name() + "中不存在以下数据库(database):</br>" + info + "请先添加数据库(database)到你所在DAL Team!</br>" + "点击此处添加组内数据库(database) : <a href='dbmanage.jsp' target='_blank'>数据库管理</a>";
status.setInfo(info);
return status;
}
}
Aggregations