📄 setup-datasource-standard.jsp
字号:
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%--
- $RCSfile$
- $Revision: 1772 $
- $Date: 2005-08-11 12:56:15 -0700 (Thu, 11 Aug 2005) $
--%>
<%@ page import="org.jivesoftware.database.DbConnectionManager,
org.jivesoftware.database.DefaultConnectionProvider,
org.jivesoftware.util.ClassUtils,
org.jivesoftware.util.JiveGlobals,
org.jivesoftware.util.Log,
org.jivesoftware.util.ParamUtils,
org.jivesoftware.wildfire.XMPPServer,
java.io.File,
java.lang.Double,
java.lang.Exception,
java.lang.Integer,
java.lang.String"
%>
<%@ page import="java.lang.Throwable"%>
<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.SQLException" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt_rt" prefix="fmt" %>
<%
// Redirect if we've already run setup:
if (!XMPPServer.getInstance().isSetupMode()) {
response.sendRedirect("setup-completed.jsp");
return;
}
%>
<%!
boolean testConnection(Map<String,String> errors) {
boolean success = true;
Connection con = null;
try {
con = DbConnectionManager.getConnection();
if (con == null) {
success = false;
errors.put("general","A connection to the database could not be "
+ "made. View the error message by opening the "
+ "\"" + File.separator + "logs" + File.separator + "error.log\" log "
+ "file, then go back to fix the problem.");
}
else {
// See if the Jive db schema is installed.
try {
Statement stmt = con.createStatement();
// Pick an arbitrary table to see if it's there.
stmt.executeQuery("SELECT * FROM jiveID");
stmt.close();
}
catch (SQLException sqle) {
success = false;
sqle.printStackTrace();
errors.put("general","The Wildfire database schema does not "
+ "appear to be installed. Follow the installation guide to "
+ "fix this error.");
}
}
}
catch (Exception ignored) {}
finally {
try {
con.close();
} catch (Exception ignored) {}
}
return success;
}
%>
<% // Get parameters
String driver = ParamUtils.getParameter(request,"driver");
String serverURL = ParamUtils.getParameter(request,"serverURL");
String username = ParamUtils.getParameter(request,"username",true);
String password = ParamUtils.getParameter(request,"password",true);
int minConnections = ParamUtils.getIntParameter(request,"minConnections",-1);
int maxConnections = ParamUtils.getIntParameter(request,"maxConnections",-1);
double connectionTimeout = ParamUtils.getDoubleParameter(request,"connectionTimeout",0.0);
boolean doContinue = request.getParameter("continue") != null;
// handle a continue request
Map<String,String> errors = new HashMap<String,String>();
if (doContinue) {
// Error check
if (driver == null || "sun.jdbc.odbc.JdbcOdbcDriver".equals(driver)
|| "com.internetcds.jdbc.tds.Driver".equals(driver))
{
errors.put("driver","Please enter a valid JDBC driver class.");
}
else {
try {
ClassUtils.forName(driver);
}
catch (Throwable t) {
errors.put("driver","Unable to load the specified JDBC driver. Please verify the " +
"name of the driver is correct and that the driver is in the classpath " +
"of this server (usually the 'lib' directory). If you add a driver to " +
"your classpath you will neeed to restart the server.");
}
}
if (serverURL == null) {
errors.put("serverURL", "Please enter a valid JDBC URL.");
}
if (minConnections < 3) {
errors.put("minConnections","The minimum connection pool size is three connections.");
}
if (maxConnections < minConnections) {
errors.put("maxConnections","The maximum number of connections cannot be less than the minimum.");
}
if (connectionTimeout <= 0.0) {
errors.put("connectionTimeout","Please enter a valid connection timeout value.");
}
// if there were no errors, continue
if (errors.size() == 0) {
// set properties, test connection, etc
// Force the standard jive connection provider to be used by deleting the current setting:
JiveGlobals.setXMLProperty("connectionProvider.className",
"org.jivesoftware.database.DefaultConnectionProvider");
DefaultConnectionProvider conProvider = new DefaultConnectionProvider();
try {
conProvider.setDriver(driver);
conProvider.setConnectionTimeout(connectionTimeout);
conProvider.setMinConnections(minConnections);
conProvider.setMaxConnections(maxConnections);
conProvider.setServerURL(serverURL);
conProvider.setUsername(username);
conProvider.setPassword(password);
JiveGlobals.setXMLProperty("database.defaultProvider.driver", driver);
JiveGlobals.setXMLProperty("database.defaultProvider.serverURL", serverURL);
JiveGlobals.setXMLProperty("database.defaultProvider.username", username);
JiveGlobals.setXMLProperty("database.defaultProvider.password", password);
JiveGlobals.setXMLProperty("database.defaultProvider.minConnections",
Integer.toString(minConnections));
JiveGlobals.setXMLProperty("database.defaultProvider.maxConnections",
Integer.toString(maxConnections));
JiveGlobals.setXMLProperty("database.defaultProvider.connectionTimeout",
Double.toString(connectionTimeout));
}
catch (Exception e) {
errors.put("general","Setting connection properties failed - please see the error "
+ "log located in home/logs for more details.");
Log.error(e);
}
// No errors setting the properties, so test the connection
DbConnectionManager.setConnectionProvider(conProvider);
if (testConnection(errors)) {
// Success, move on
response.sendRedirect("setup-profile-settings.jsp");
return;
}
}
}
if (!doContinue) {
// reset values of jdbc driver from props file
driver = JiveGlobals.getXMLProperty("database.defaultProvider.driver");
serverURL = JiveGlobals.getXMLProperty("database.defaultProvider.serverURL");
username = JiveGlobals.getXMLProperty("database.defaultProvider.username");
password = JiveGlobals.getXMLProperty("database.defaultProvider.password");
try {
minConnections = Integer.parseInt(
JiveGlobals.getXMLProperty("database.defaultProvider.minConnections"));
}
catch (Exception e) {
minConnections = 5;
}
try {
maxConnections = Integer.parseInt(
JiveGlobals.getXMLProperty("database.defaultProvider.maxConnections"));
}
catch (Exception e) {
maxConnections = 15;
}
try {
connectionTimeout = Double.parseDouble(
JiveGlobals.getXMLProperty("database.defaultProvider.connectionTimeout"));
}
catch (Exception e) {
connectionTimeout = 1.0;
}
}
%>
<html>
<head>
<title><fmt:message key="setup.datasource.standard.title" /></title>
<meta name="currentStep" content="2"/>
</head>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -