Search in sources :

Example 16 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class DatabaseResource method mergeDB.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("merge")
public Status mergeDB(@Context HttpServletRequest request) throws Exception {
    try {
        String userNo = RequestUtil.getUserNo(request);
        Status status = Status.OK();
        LoginUser user = BeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
        List<UserGroup> urGroups = BeanGetter.getDalUserGroupDao().getUserGroupByUserId(user.getId());
        boolean havePersimion = false;
        if (urGroups != null && urGroups.size() > 0) {
            for (UserGroup ug : urGroups) {
                if (ug.getGroup_id() == DalGroupResource.SUPER_GROUP_ID) {
                    havePersimion = true;
                    break;
                }
            }
        }
        if (!havePersimion) {
            status = Status.ERROR();
            status.setInfo("You have no permision, only DAL Admin Team can do this.");
            return status;
        }
        DalGroupDBDao allDbDao = BeanGetter.getDaoOfDalGroupDB();
        Map<String, DalGroupDB> allDbs = new AllInOneConfigParser(Configuration.get("all_in_one")).getDBAllInOneConfig();
        Set<String> keys = allDbs.keySet();
        for (String key : keys) {
            DalGroupDB db = allDbDao.getGroupDBByDbName(key);
            if (db == null) {
                allDbDao.insertDalGroupDB(allDbs.get(key));
            } else {
                DalGroupDB fileDB = allDbs.get(key);
                allDbDao.updateGroupDB(db.getId(), key, fileDB.getDb_address(), fileDB.getDb_port(), fileDB.getDb_user(), fileDB.getDb_password(), fileDB.getDb_catalog(), fileDB.getDb_providerName());
            }
        }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)

Example 17 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class DatabaseResource method addNewAllInOneDB.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("addNewAllInOneDB")
public Status addNewAllInOneDB(@Context HttpServletRequest request, @FormParam("dbtype") String dbtype, @FormParam("allinonename") String allinonename, @FormParam("dbaddress") String dbaddress, @FormParam("dbport") String dbport, @FormParam("dbuser") String dbuser, @FormParam("dbpassword") String dbpassword, @FormParam("dbcatalog") String dbcatalog, @FormParam("addtogroup") boolean addToGroup, @FormParam("dalgroup") String groupId, @FormParam("gen_default_dbset") boolean isGenDefault) throws Exception {
    try {
        Status status = Status.OK();
        DalGroupDBDao allDbDao = BeanGetter.getDaoOfDalGroupDB();
        if (allDbDao.getGroupDBByDbName(allinonename) != null) {
            status = Status.ERROR();
            status.setInfo(allinonename + "已经存在!");
            return status;
        } else {
            DalGroupDB groupDb = new DalGroupDB();
            groupDb.setDbname(allinonename);
            groupDb.setDb_address(dbaddress);
            groupDb.setDb_port(dbport);
            groupDb.setDb_user(dbuser);
            groupDb.setDb_password(dbpassword);
            groupDb.setDb_catalog(dbcatalog);
            groupDb.setDb_providerName(DatabaseType.valueOf(dbtype).getValue());
            groupDb.setDal_group_id(-1);
            // add to current user's group
            if (addToGroup) {
                int gid = -1;
                if (groupId != null && !groupId.isEmpty()) {
                    gid = Integer.parseInt(groupId);
                    groupDb.setDal_group_id(gid);
                } else {
                    LoginUser user = RequestUtil.getUserInfo(request);
                    if (user != null) {
                        int userId = user.getId();
                        List<UserGroup> list = BeanGetter.getDalUserGroupDao().getUserGroupByUserId(userId);
                        if (list != null && list.size() > 0) {
                            gid = list.get(0).getGroup_id();
                            groupDb.setDal_group_id(gid);
                        }
                    }
                }
                // generate default databaseset
                if (isGenDefault) {
                    status = DalGroupDbResource.genDefaultDbset(gid, allinonename, dbtype);
                }
            }
            allDbDao.insertDalGroupDB(groupDb);
        }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroupDBDao(com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)

Example 18 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class GenTaskByFreeSqlResource 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("class_name") String class_name, @FormParam("pojo_name") String pojo_name, @FormParam("method_name") String method_name, @FormParam("crud_type") String crud_type, @FormParam("sql_content") String sql_content, @FormParam("params") String params, @FormParam("version") int version, @FormParam("action") String action, @FormParam("comment") String comment, @FormParam("scalarType") String scalarType, @FormParam("pagination") boolean pagination, // C#风格或者Java风格 @FormParam("length") boolean length,
@FormParam("sql_style") String sql_style, @FormParam("hints") String hints) throws Exception {
    try {
        GenTaskByFreeSql task = new GenTaskByFreeSql();
        if (action.equalsIgnoreCase("delete")) {
            task.setId(id);
            if (0 >= BeanGetter.getDaoByFreeSql().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.setClass_name(class_name);
            task.setPojo_name(pojo_name);
            task.setMethod_name(method_name);
            task.setCrud_type(crud_type);
            task.setSql_content(sql_content);
            task.setParameters(params);
            task.setUpdate_user_no(user.getUserName() + "(" + userNo + ")");
            task.setUpdate_time(new Timestamp(System.currentTimeMillis()));
            task.setComment(comment);
            task.setScalarType(scalarType);
            task.setPagination(pagination);
            // task.setLength(length);
            task.setSql_style(sql_style);
            if ("简单类型".equals(pojo_name)) {
                task.setPojoType("SimpleType");
            } else {
                task.setPojoType("EntityType");
            }
            if (needApproveTask(project_id, user.getId())) {
                task.setApproved(1);
            } else {
                task.setApproved(2);
            }
            task.setApproveMsg("");
            task.setHints(hints);
            if (action.equalsIgnoreCase("update")) {
                task.setId(id);
                task.setVersion(BeanGetter.getDaoByFreeSql().getVersionById(id));
                if (0 >= BeanGetter.getDaoByFreeSql().updateTask(task)) {
                    Status status = Status.ERROR();
                    status.setInfo("更新出错,数据是否合法?或者已经有同名方法?");
                    return status;
                }
            } else {
                task.setGenerated(false);
                task.setVersion(1);
                if (0 >= BeanGetter.getDaoByFreeSql().insertTask(task)) {
                    Status status = Status.ERROR();
                    status.setInfo("新增出错,数据是否合法?或者已经有同名方法?");
                    return status;
                }
            }
        }
        return Status.OK();
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) Timestamp(java.sql.Timestamp)

Example 19 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class GenTaskByFreeSqlResource method buildPagingSQL.

@POST
@Path("buildPagingSQL")
public // dbset// name
Status buildPagingSQL(// dbset// name
@FormParam("db_name") String db_set_name, // C#风格或者Java风格
@FormParam("sql_style") String sql_style, @FormParam("sql_content") String sql_content) {
    try {
        Status status = Status.OK();
        DatabaseSetEntry databaseSetEntry = BeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(db_set_name);
        CurrentLanguage lang = (sql_content.contains("@") || "csharp".equals(sql_style)) ? CurrentLanguage.CSharp : CurrentLanguage.Java;
        String pagingSQL = SqlBuilder.pagingQuerySql(sql_content, DbUtils.getDatabaseCategory(databaseSetEntry.getConnectionString()), lang);
        status.setInfo(pagingSQL);
        return status;
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        Status status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) CurrentLanguage(com.ctrip.platform.dal.daogen.enums.CurrentLanguage)

Example 20 with Status

use of com.ctrip.platform.dal.daogen.domain.Status in project dal by ctripcorp.

the class GenTaskBySqlBuilderResource method buildPagingSQL.

@POST
@Path("buildPagingSQL")
public // dbset
Status buildPagingSQL(// dbset
@FormParam("db_name") String db_set_name, // C#风格或者Java风格
@FormParam("sql_style") String sql_style, @FormParam("sql_content") String sql_content) {
    Status status = Status.OK();
    try {
        DatabaseSetEntry databaseSetEntry = BeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(db_set_name);
        CurrentLanguage lang = "java".equals(sql_style) ? CurrentLanguage.Java : CurrentLanguage.CSharp;
        String pagingSQL = SqlBuilder.pagingQuerySql(sql_content, DbUtils.getDatabaseCategory(databaseSetEntry.getConnectionString()), lang);
        status.setInfo(pagingSQL);
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
        return status;
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) CurrentLanguage(com.ctrip.platform.dal.daogen.enums.CurrentLanguage)

Aggregations

Status (com.ctrip.platform.dal.daogen.domain.Status)63 Timestamp (java.sql.Timestamp)13 SQLException (java.sql.SQLException)7 LoginUser (com.ctrip.platform.dal.daogen.entity.LoginUser)6 DalGroupDBDao (com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 ConfigTemplate (com.ctrip.platform.dal.daogen.entity.ConfigTemplate)3 CurrentLanguage (com.ctrip.platform.dal.daogen.enums.CurrentLanguage)2 DatabaseCategory (com.ctrip.platform.dal.daogen.enums.DatabaseCategory)2 ValidateResult (com.ctrip.platform.dal.daogen.sql.validate.ValidateResult)2 Connection (java.sql.Connection)2 ResultSet (java.sql.ResultSet)2 HashSet (java.util.HashSet)2 EmailException (org.apache.commons.mail.EmailException)2 HtmlEmail (org.apache.commons.mail.HtmlEmail)2 VelocityContext (org.apache.velocity.VelocityContext)2 CodeGenContext (com.ctrip.platform.dal.daogen.CodeGenContext)1 DalGenerator (com.ctrip.platform.dal.daogen.DalGenerator)1 StoredProcedure (com.ctrip.platform.dal.daogen.domain.StoredProcedure)1 TableSpNames (com.ctrip.platform.dal.daogen.domain.TableSpNames)1