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;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import java.io.*;
import java.sql.*;
import java.io.BufferedReader;
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
......@@ -28,8 +38,7 @@ import java.sql.*;
* or rows that a query should return.
*
* @author Jive Software
*
* @see org.jivesoftware.database.ConnectionProvider
* @see ConnectionProvider
*/
public class DbConnectionManager {
......@@ -175,7 +184,7 @@ public class DbConnectionManager {
* Closes a prepared statement and database connection (returning the connection to
* the connection pool). This method should be called within the finally section of
* your database logic, as in the following example:
*
* <p/>
* <pre>
* Connection con = null;
* PrepatedStatment pstmt = null;
......@@ -211,7 +220,7 @@ public class DbConnectionManager {
* 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
* in the following example:
*
* <p/>
* <pre>
* Connection con = null;
* try {
......@@ -290,8 +299,20 @@ public class DbConnectionManager {
if (isScrollResultsSupported()) {
if (rowNumber > 0) {
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);
}
catch (SQLException e) {
for (int i = 0; i < rowNumber; i++) {
rs.next();
}
}
}
}
// Otherwise, manually scroll to the correct row.
else {
......@@ -348,8 +369,14 @@ public class DbConnectionManager {
Log.error(e);
}
finally {
try { if (con != null) { con.close(); } }
catch (Exception e) { Log.error(e); }
try {
if (con != null) {
con.close();
}
}
catch (Exception e) {
Log.error(e);
}
}
}
// Remember what connection provider we want to use for restarts.
......@@ -431,8 +458,7 @@ public class DbConnectionManager {
* @param value the String to set.
*/
public static void setLargeTextField(PreparedStatement pstmt, int parameterIndex,
String value) throws SQLException
{
String value) throws SQLException {
if (isStreamTextRequired()) {
Reader bodyReader;
try {
......@@ -706,8 +732,14 @@ public class DbConnectionManager {
minorVersion = 0;
}
finally {
try { if (pstmt != null) { pstmt.close(); } }
catch (Exception e) { Log.error(e); }
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
}
if (majorVersion == CURRENT_MAJOR_VERSION && minorVersion == CURRENT_MINOR_VERSION) {
return false;
......@@ -731,13 +763,13 @@ public class DbConnectionManager {
return false;
}
// 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;
Statement stmt;
try {
// Resource will be like "/database/upgrade/2.0_to_2.1/wildfire_hsqldb.sql"
String resourceName = "/database/upgrade/" + CURRENT_MAJOR_VERSION + "." + i +
"_to_" + CURRENT_MAJOR_VERSION + "." + (i+1) + "/wildfire_" +
"_to_" + CURRENT_MAJOR_VERSION + "." + (i + 1) + "/wildfire_" +
databaseType + ".sql";
InputStream resource = DbConnectionManager.class.getResourceAsStream(resourceName);
if (resource == null) {
......@@ -776,10 +808,18 @@ public class DbConnectionManager {
}
}
finally {
try { if (pstmt != null) { pstmt.close(); } }
catch (Exception e) { Log.error(e); }
try {
if (pstmt != null) {
pstmt.close();
}
}
catch (Exception e) {
Log.error(e);
}
if (in != null) {
try { in.close(); }
try {
in.close();
}
catch (Exception e) {
// 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