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;
}
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;
}
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;
}
Aggregations