Commit 34cafa49 authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

LIVE-1096 "Browse Agent" page only shows first page.

JM-512 Retrieving next batch of users in User Manager throws exception in SqlServer.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3280 b35dd754-fafc-0310-a699-88a17e54d16e
parent b661b2e1
...@@ -16,8 +16,18 @@ import org.jivesoftware.util.ClassUtils; ...@@ -16,8 +16,18 @@ import org.jivesoftware.util.ClassUtils;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log; import org.jivesoftware.util.Log;
import java.io.*; import java.io.BufferedReader;
import java.sql.*; import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
/** /**
* Central manager of database connections. All methods are static so that they * Central manager of database connections. All methods are static so that they
...@@ -28,8 +38,7 @@ import java.sql.*; ...@@ -28,8 +38,7 @@ import java.sql.*;
* or rows that a query should return. * or rows that a query should return.
* *
* @author Jive Software * @author Jive Software
* * @see ConnectionProvider
* @see org.jivesoftware.database.ConnectionProvider
*/ */
public class DbConnectionManager { public class DbConnectionManager {
...@@ -175,7 +184,7 @@ public class DbConnectionManager { ...@@ -175,7 +184,7 @@ public class DbConnectionManager {
* Closes a prepared statement and database connection (returning the connection to * Closes a prepared statement and database connection (returning the connection to
* the connection pool). This method should be called within the finally section of * the connection pool). This method should be called within the finally section of
* your database logic, as in the following example: * your database logic, as in the following example:
* * <p/>
* <pre> * <pre>
* Connection con = null; * Connection con = null;
* PrepatedStatment pstmt = null; * PrepatedStatment pstmt = null;
...@@ -211,7 +220,7 @@ public class DbConnectionManager { ...@@ -211,7 +220,7 @@ public class DbConnectionManager {
* statements associated with the connection should be closed before calling this method. * statements associated with the connection should be closed before calling this method.
* This method should be called within the finally section of your database logic, as * This method should be called within the finally section of your database logic, as
* in the following example: * in the following example:
* * <p/>
* <pre> * <pre>
* Connection con = null; * Connection con = null;
* try { * try {
...@@ -290,8 +299,20 @@ public class DbConnectionManager { ...@@ -290,8 +299,20 @@ public class DbConnectionManager {
if (isScrollResultsSupported()) { if (isScrollResultsSupported()) {
if (rowNumber > 0) { if (rowNumber > 0) {
rs.setFetchDirection(ResultSet.FETCH_FORWARD); rs.setFetchDirection(ResultSet.FETCH_FORWARD);
// We will attempt to do a relative fetch. This may fail in SQL Server if
// <resultset-navigation-strategy> is set to absolute. It would need to be
// set to looping to work correctly.
// If so, manually scroll to the correct row.
try {
rs.relative(rowNumber); rs.relative(rowNumber);
} }
catch (SQLException e) {
for (int i = 0; i < rowNumber; i++) {
rs.next();
}
}
}
} }
// Otherwise, manually scroll to the correct row. // Otherwise, manually scroll to the correct row.
else { else {
...@@ -348,8 +369,14 @@ public class DbConnectionManager { ...@@ -348,8 +369,14 @@ public class DbConnectionManager {
Log.error(e); Log.error(e);
} }
finally { finally {
try { if (con != null) { con.close(); } } try {
catch (Exception e) { Log.error(e); } if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
} }
} }
// Remember what connection provider we want to use for restarts. // Remember what connection provider we want to use for restarts.
...@@ -431,8 +458,7 @@ public class DbConnectionManager { ...@@ -431,8 +458,7 @@ public class DbConnectionManager {
* @param value the String to set. * @param value the String to set.
*/ */
public static void setLargeTextField(PreparedStatement pstmt, int parameterIndex, public static void setLargeTextField(PreparedStatement pstmt, int parameterIndex,
String value) throws SQLException String value) throws SQLException {
{
if (isStreamTextRequired()) { if (isStreamTextRequired()) {
Reader bodyReader; Reader bodyReader;
try { try {
...@@ -706,8 +732,14 @@ public class DbConnectionManager { ...@@ -706,8 +732,14 @@ public class DbConnectionManager {
minorVersion = 0; minorVersion = 0;
} }
finally { finally {
try { if (pstmt != null) { pstmt.close(); } } try {
catch (Exception e) { Log.error(e); } if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
} }
if (majorVersion == CURRENT_MAJOR_VERSION && minorVersion == CURRENT_MINOR_VERSION) { if (majorVersion == CURRENT_MAJOR_VERSION && minorVersion == CURRENT_MINOR_VERSION) {
return false; return false;
...@@ -731,13 +763,13 @@ public class DbConnectionManager { ...@@ -731,13 +763,13 @@ public class DbConnectionManager {
return false; return false;
} }
// Run all upgrade scripts until we're up to the latest schema. // Run all upgrade scripts until we're up to the latest schema.
for (int i=minorVersion; i<CURRENT_MINOR_VERSION; i++) { for (int i = minorVersion; i < CURRENT_MINOR_VERSION; i++) {
BufferedReader in = null; BufferedReader in = null;
Statement stmt; Statement stmt;
try { try {
// Resource will be like "/database/upgrade/2.0_to_2.1/wildfire_hsqldb.sql" // Resource will be like "/database/upgrade/2.0_to_2.1/wildfire_hsqldb.sql"
String resourceName = "/database/upgrade/" + CURRENT_MAJOR_VERSION + "." + i + String resourceName = "/database/upgrade/" + CURRENT_MAJOR_VERSION + "." + i +
"_to_" + CURRENT_MAJOR_VERSION + "." + (i+1) + "/wildfire_" + "_to_" + CURRENT_MAJOR_VERSION + "." + (i + 1) + "/wildfire_" +
databaseType + ".sql"; databaseType + ".sql";
InputStream resource = DbConnectionManager.class.getResourceAsStream(resourceName); InputStream resource = DbConnectionManager.class.getResourceAsStream(resourceName);
if (resource == null) { if (resource == null) {
...@@ -776,10 +808,18 @@ public class DbConnectionManager { ...@@ -776,10 +808,18 @@ public class DbConnectionManager {
} }
} }
finally { finally {
try { if (pstmt != null) { pstmt.close(); } } try {
catch (Exception e) { Log.error(e); } if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
if (in != null) { if (in != null) {
try { in.close(); } try {
in.close();
}
catch (Exception e) { catch (Exception e) {
// Ignore. // Ignore.
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment