Search in sources :

Example 21 with Status

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

the class DalUserResource method delete.

@POST
@Path("delete")
public Status delete(@FormParam("userId") int userId) {
    try {
        int result = SpringBeanGetter.getDaoOfLoginUser().deleteUser(userId);
        if (result < 1) {
            log.error("Delete user failed, caused by db operation failed, pls check the log.");
            Status status = Status.ERROR;
            status.setInfo("Delete operation failed.");
            return status;
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        Status status = Status.ERROR;
        status.setInfo(e.getMessage());
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status)

Example 22 with Status

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

the class DalUserResource method update.

@POST
@Path("update")
public Status update(@FormParam("userId") int userId, @FormParam("userNo") String userNo, @FormParam("userName") String userName, @FormParam("userEmail") String userEmail) {
    if (userNo == null) {
        log.error(String.format("Update user failed, caused by illegal parameters:userNo=%s", userNo));
        Status status = Status.ERROR;
        status.setInfo("Illegal parameters.");
        return status;
    }
    if (userName == null) {
        log.error(String.format("Update user failed, caused by illegal parameters:userName=%s", userName));
        Status status = Status.ERROR;
        status.setInfo("Illegal parameters.");
        return status;
    }
    if (userEmail == null) {
        log.error(String.format("Update user failed, caused by illegal parameters:userEmail=%s", userEmail));
        Status status = Status.ERROR;
        status.setInfo("Illegal parameters.");
        return status;
    }
    LoginUser user = new LoginUser();
    user.setId(userId);
    user.setUserNo(userNo);
    user.setUserName(userName);
    user.setUserEmail(userEmail);
    try {
        int result = SpringBeanGetter.getDaoOfLoginUser().updateUser(user);
        if (result < 1) {
            log.error("Update user failed, caused by db operation failed, pls check the log.");
            Status status = Status.ERROR;
            status.setInfo("Update operation failed.");
            return status;
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        Status status = Status.ERROR;
        status.setInfo(e.getMessage());
        return status;
    }
    return Status.OK;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) LoginUser(com.ctrip.platform.dal.daogen.entity.LoginUser)

Example 23 with Status

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

the class GenTaskBySqlBuilderResource method getMockValue.

@POST
@Path("getMockValue")
public Status getMockValue(@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("pagination") boolean pagination) throws Exception {
    Status status = Status.OK;
    int[] sqlTypes = getSqlTypes(set_name, table_name, crud_type, fields, condition);
    Object[] values = SQLValidation.mockStringValues(sqlTypes);
    try {
        status.setInfo(mapper.writeValueAsString(values));
    } catch (JsonProcessingException e) {
        status = Status.ERROR;
        status.setInfo("获取mock value异常.");
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 24 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 = SpringBeanGetter.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 (Exception 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) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 25 with Status

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

the class GenTaskBySqlBuilderResource method getDatabaseCategory.

@POST
@Path("getDatabaseCategory")
public Status getDatabaseCategory(@FormParam("db_set_name") String db_set_name) {
    Status status = Status.OK;
    DatabaseSetEntry databaseSetEntry = SpringBeanGetter.getDaoOfDatabaseSet().getMasterDatabaseSetEntryByDatabaseSetName(db_set_name);
    try {
        DatabaseCategory category = DbUtils.getDatabaseCategory(databaseSetEntry.getConnectionString());
        if (DatabaseCategory.MySql == category) {
            status.setInfo("MySql");
        } else {
            status.setInfo("SqlServer");
        }
    } catch (Exception e) {
        status = Status.ERROR;
        status.setInfo(e.getMessage());
        return status;
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DatabaseCategory(com.ctrip.platform.dal.daogen.enums.DatabaseCategory) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

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