Search in sources :

Example 61 with Status

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

the class SetupDBResource method connectionTest.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("connectionTest")
public Status connectionTest(@FormParam("dbtype") String dbtype, @FormParam("dbaddress") String dbaddress, @FormParam("dbport") String dbport, @FormParam("dbuser") String dbuser, @FormParam("dbpassword") String dbpassword) throws Exception {
    Status status = Status.OK();
    Connection conn = null;
    ResultSet rs = null;
    try {
        conn = DataSourceUtil.getConnection(dbaddress, dbport, dbuser, dbpassword, DatabaseType.valueOf(dbtype).getValue());
        rs = conn.getMetaData().getCatalogs();
        Set<String> allCatalog = new HashSet<>();
        while (rs.next()) {
            allCatalog.add(rs.getString("TABLE_CAT"));
        }
        status.setInfo(mapper.writeValueAsString(allCatalog));
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
    } finally {
        ResourceUtils.close(rs);
        ResourceUtils.close(conn);
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) HashSet(java.util.HashSet)

Example 62 with Status

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

the class SetupDBResource method setupDbCheck.

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("setupDbCheck")
public Status setupDbCheck() throws Exception {
    Status status = Status.OK();
    if (initialized) {
        status.setInfo("");
        return status;
    }
    try {
        boolean valid = datasourceXmlValid();
        if (!valid) {
            status = Status.ERROR();
            status.setInfo("!valid");
        }
        if (valid && !initialized) {
            synchronized (LOCK) {
                if (!initialized) {
                    initialized = true;
                    dalInitialized = true;
                }
            }
            status.setInfo("initialized");
        }
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status)

Example 63 with Status

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

the class SetupDBResource method initializeDb.

@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("initializeDb")
public Status initializeDb(@Context HttpServletRequest request, @FormParam("dbaddress") String dbaddress, @FormParam("dbport") String dbport, @FormParam("dbuser") String dbuser, @FormParam("dbpassword") String dbpassword, @FormParam("dbcatalog") String dbcatalog, @FormParam("groupName") String groupName, @FormParam("groupComment") String groupComment, @FormParam("adminNo") String adminNo, @FormParam("adminName") String adminName, @FormParam("adminEmail") String adminEmail, @FormParam("adminPass") String adminPass) {
    Status status = Status.OK();
    try {
        boolean result = initializeDatasourceXml(dbaddress, dbport, dbuser, dbpassword, dbcatalog);
        if (!result) {
            status = Status.ERROR();
            status.setInfo("Error occured while initializing the jdbc.properties file.");
            return status;
        }
        boolean isSetupTables = setupTables();
        if (!isSetupTables) {
            status = Status.ERROR();
            status.setInfo("Error occured while setting up the tables.");
            return status;
        }
        DalGroup group = new DalGroup();
        group.setGroup_name(groupName);
        group.setGroup_comment(groupComment);
        LoginUser user = new LoginUser();
        user.setUserNo(adminNo);
        user.setUserName(adminName);
        user.setUserEmail(adminEmail);
        user.setPassword(MD5Util.parseStrToMd5L32(adminPass));
        boolean isSetupAdmin = setupAdmin(group, user);
        if (!isSetupAdmin) {
            status = Status.ERROR();
            status.setInfo("Error occured while setting up the admin.");
            return status;
        }
    } catch (Throwable e) {
        LoggerManager.getInstance().error(e);
        status = Status.ERROR();
        status.setInfo(e.getMessage());
    }
    return status;
}
Also used : Status(com.ctrip.platform.dal.daogen.domain.Status) DalGroup(com.ctrip.platform.dal.daogen.entity.DalGroup) LoginUser(com.ctrip.platform.dal.daogen.entity.LoginUser)

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