Search in sources :

Example 6 with Status

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

the class DalGroupDbResource method update.

@POST
@Path("update")
public Status update(@Context HttpServletRequest request, @FormParam("groupId") String groupId, @FormParam("dbId") String dbId, @FormParam("comment") String comment) {
    String userNo = RequestUtil.getUserNo(request);
    if (userNo == null || groupId == null || dbId == null) {
        log.error(String.format("Add member failed, caused by illegal parameters: " + "[groupId=%s, dbId=%s]", groupId, dbId));
        Status status = Status.ERROR;
        status.setInfo("Illegal parameters.");
        return status;
    }
    int groupID = -1;
    int dbID = -1;
    try {
        dbID = Integer.parseInt(dbId);
        groupID = Integer.parseInt(groupId);
    } catch (NumberFormatException ex) {
        log.error("Update failed", ex);
        Status status = Status.ERROR;
        status.setInfo("Illegal group id");
        return status;
    }
    if (!this.validatePermision(userNo, groupID)) {
        Status status = Status.ERROR;
        status.setInfo("你没有当前DAL Team的操作权限。");
        return status;
    }
    int ret = SpringBeanGetter.getDaoOfDalGroupDB().updateGroupDB(dbID, comment);
    if (ret <= 0) {
        log.error("Update dal group db failed, caused by db operation failed, pls check the spring log");
        Status status = Status.ERROR;
        status.setInfo("Update operation failed.");
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status)

Example 7 with Status

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

the class DalGroupDbResource method genDefaultDbset.

/**
     * 生成默认的databaseSet和databaseSet Entry
     *
     * @param dbname
     */
public static Status genDefaultDbset(int groupId, String dbname) {
    Status status = Status.OK;
    List<DatabaseSet> exist = SpringBeanGetter.getDaoOfDatabaseSet().getAllDatabaseSetByName(dbname);
    if (exist != null && exist.size() > 0) {
        status = Status.ERROR;
        status.setInfo("数据库" + dbname + "已添加成功。由于已存在名为" + dbname + "的逻辑数据库,所以无法默认生成同名的逻辑库,请到逻辑数据库管理页面中手动添加不同名称的逻辑库。请点击关闭按钮以关闭窗口。");
        return status;
    }
    DatabaseSet dbset = new DatabaseSet();
    dbset.setName(dbname);
    dbset.setProvider("sqlProvider");
    try {
        Connection connection = DataSourceUtil.getConnection(dbname);
        String dbType = connection.getMetaData().getDatabaseProductName();
        if (dbType != null && (!dbType.equals("Microsoft SQL Server"))) {
            dbset.setProvider("mySqlProvider");
        }
    } catch (Exception e) {
        log.warn("", e);
    }
    dbset.setGroupId(groupId);
    int ret = SpringBeanGetter.getDaoOfDatabaseSet().insertDatabaseSet(dbset);
    if (ret > 0) {
        dbset = SpringBeanGetter.getDaoOfDatabaseSet().getAllDatabaseSetByName(dbname).get(0);
        DatabaseSetEntry entry = new DatabaseSetEntry();
        entry.setDatabaseSet_Id(dbset.getId());
        entry.setDatabaseType("Master");
        entry.setName(dbname);
        entry.setConnectionString(dbname);
        SpringBeanGetter.getDaoOfDatabaseSet().insertDatabaseSetEntry(entry);
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) Connection(java.sql.Connection)

Example 8 with Status

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

the class DalGroupDbResource method transferdb.

@POST
@Path("transferdb")
public Status transferdb(@Context HttpServletRequest request, @FormParam("groupId") String groupId, @FormParam("dbId") String dbId) {
    String userNo = RequestUtil.getUserNo(request);
    if (userNo == null || groupId == null || dbId == null) {
        log.error(String.format("transfer db failed, caused by illegal parameters: " + "[groupId=%s, dbId=%s]", groupId, dbId));
        Status status = Status.ERROR;
        status.setInfo("Illegal parameters.");
        return status;
    }
    int groupID = -1;
    int dbID = -1;
    try {
        groupID = Integer.parseInt(groupId);
        dbID = Integer.parseInt(dbId);
    } catch (NumberFormatException ex) {
        log.error("transfer db failed", ex);
        Status status = Status.ERROR;
        status.setInfo("Illegal group id or db id");
        return status;
    }
    if (!this.validateTransferPermision(userNo, dbID)) {
        Status status = Status.ERROR;
        status.setInfo("你没有当前DataBase的操作权限。");
        return status;
    }
    int ret = SpringBeanGetter.getDaoOfDalGroupDB().updateGroupDB(dbID, groupID);
    if (ret <= 0) {
        log.error("transfer db failed, caused by db operation failed, pls check the spring log");
        Status status = Status.ERROR;
        status.setInfo("transfer operation failed.");
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status)

Example 9 with Status

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

the class DalGroupDbSetResource method updateDbset.

@POST
@Path("updateDbset")
public Status updateDbset(@Context HttpServletRequest request, @FormParam("id") int iD, @FormParam("name") String name, @FormParam("provider") String provider, @FormParam("shardingStrategy") String shardingStrategy, @FormParam("groupId") int groupID) {
    String userNo = RequestUtil.getUserNo(request);
    if (userNo == null) {
        log.error(String.format("Update Dbset failed, caused by illegal parameters:[userNo=%s]", userNo));
        Status status = Status.ERROR;
        status.setInfo("Illegal parameters.");
        return status;
    }
    if (!this.validatePermision(userNo, groupID)) {
        Status status = Status.ERROR;
        status.setInfo("你没有当前DAL Team的操作权限.");
        return status;
    }
    if (!validatePermision(userNo, groupID, iD)) {
        Status status = Status.ERROR;
        status.setInfo("你只能操作你们组创建的逻辑数据库.");
        return status;
    }
    List<DatabaseSet> dbsets = SpringBeanGetter.getDaoOfDatabaseSet().getAllDatabaseSetByName(name);
    if (null != dbsets && dbsets.size() > 0) {
        for (DatabaseSet dbset : dbsets) {
            if (dbset.getId() != iD) {
                Status status = Status.ERROR;
                status.setInfo("databaseSet Name --> " + name + "已经存在,请重新命名!");
                return status;
            }
        }
    }
    int ret = -1;
    DatabaseSet dbset = new DatabaseSet();
    dbset.setId(iD);
    dbset.setName(name);
    dbset.setProvider(provider);
    dbset.setShardingStrategy(shardingStrategy);
    dbset.setGroupId(groupID);
    dbset.setUpdate_time(new Timestamp(System.currentTimeMillis()));
    LoginUser user = SpringBeanGetter.getDaoOfLoginUser().getUserByNo(userNo);
    String upNo = user.getUserName() + "(" + userNo + ")";
    dbset.setUpdate_user_no(upNo);
    ret = SpringBeanGetter.getDaoOfDatabaseSet().updateDatabaseSet(dbset);
    if (ret <= 0) {
        log.error("Update database set failed, caused by db operation failed, pls check the spring log");
        Status status = Status.ERROR;
        status.setInfo("Update operation failed.");
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) Timestamp(java.sql.Timestamp)

Example 10 with Status

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

the class DalGroupResource method add.

@POST
@Path("add")
public Status add(@Context HttpServletRequest request, @FormParam("groupName") String groupName, @FormParam("groupComment") String groupComment) {
    String userNo = RequestUtil.getUserNo(request);
    if (userNo == null || groupName == null || groupName.isEmpty()) {
        log.error(String.format("Add dal group failed, caused by illegal parameters: " + "[groupName=%s, groupComment=%s]", groupName, groupComment));
        Status status = Status.ERROR;
        status.setInfo("Illegal parameters.");
        return status;
    }
    if (!this.validate(userNo)) {
        Status status = Status.ERROR;
        status.setInfo("你没有当前DAL Team的操作权限.");
        return status;
    }
    DalGroup group = new DalGroup();
    group.setGroup_name(groupName);
    group.setGroup_comment(groupComment);
    group.setCreate_user_no(userNo);
    group.setCreate_time(new Timestamp(System.currentTimeMillis()));
    int ret = SpringBeanGetter.getDaoOfDalGroup().insertDalGroup(group);
    if (ret <= 0) {
        log.error("Add dal group failed, caused by db operation failed, pls check the spring log");
        Status status = Status.ERROR;
        status.setInfo("Add operation failed.");
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) Timestamp(java.sql.Timestamp)

Aggregations

Status (com.ctrip.platform.dal.daogen.domain.Status)60 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)14 Timestamp (java.sql.Timestamp)12 LoginUser (com.ctrip.platform.dal.daogen.entity.LoginUser)6 SQLException (java.sql.SQLException)6 DalGroupDBDao (com.ctrip.platform.dal.daogen.dao.DalGroupDBDao)5 ConfigTemplate (com.ctrip.platform.dal.daogen.entity.ConfigTemplate)3 Connection (java.sql.Connection)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 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