Commit 6e226c7f authored by Matt Tucker's avatar Matt Tucker Committed by matt

Fixed compiling on JDK 1.6 (JM-755).

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6069 b35dd754-fafc-0310-a699-88a17e54d16e
parent f30c8815
......@@ -11,8 +11,12 @@
package org.jivesoftware.database;
import org.jivesoftware.util.Log;
import java.sql.*;
import java.util.Map;
import java.util.Properties;
import java.lang.reflect.Method;
/**
* An implementation of the Connection interface that wraps an underlying
......@@ -20,7 +24,7 @@ import java.util.Map;
*
* @author Gaston Dombiak
*/
public class AbstractConnection implements Connection {
public abstract class AbstractConnection implements Connection {
protected Connection connection;
......@@ -152,26 +156,29 @@ public class AbstractConnection implements Connection {
}
public Statement createStatement(int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
int resultSetHoldability) throws SQLException
{
return connection.createStatement(resultSetType, resultSetConcurrency,
resultSetHoldability);
}
public PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency, int resultSetHoldability)
throws SQLException {
int resultSetConcurrency, int resultSetHoldability) throws SQLException
{
return connection.prepareStatement(sql, resultSetType, resultSetConcurrency,
resultSetHoldability);
}
public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException {
int resultSetHoldability) throws SQLException
{
return connection.prepareCall(sql, resultSetType, resultSetConcurrency,
resultSetHoldability);
}
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException {
throws SQLException
{
return connection.prepareStatement(sql, autoGeneratedKeys);
}
......@@ -183,4 +190,200 @@ public class AbstractConnection implements Connection {
throws SQLException {
return connection.prepareStatement(sql, columnNames);
}
// JDK 1.6 Methods. We must handle these using reflection so that the code will compile on
// both JDK 1.6 and 1.5.
public Clob createClob() throws SQLException {
try {
Method method = connection.getClass().getMethod("createClob", new Class[] {});
return (Clob)method.invoke(connection);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public Blob createBlob() throws SQLException {
try {
Method method = connection.getClass().getMethod("createBlob", new Class[] {});
return (Blob)method.invoke(connection);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public NClob createNClob() throws SQLException {
try {
Method method = connection.getClass().getMethod("createNClob", new Class[] {});
return (NClob)method.invoke(connection);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public SQLXML createSQLXML() throws SQLException {
try {
Method method = connection.getClass().getMethod("createSQLXML", new Class[] {});
return (SQLXML)method.invoke(connection);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public boolean isValid(int timeout) throws SQLException {
try {
Method method = connection.getClass().getMethod("createClob", Integer.class);
return (Boolean)method.invoke(connection, timeout);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return false;
}
}
public void setClientInfo(String name, String value) throws SQLClientInfoException {
try {
Method method = connection.getClass().getMethod("setClientInfo", String.class, String.class);
method.invoke(connection, name, value);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLClientInfoException)e;
}
// Simply log reflection exceptions.
Log.error(e);
}
}
public void setClientInfo(Properties properties) throws SQLClientInfoException {
try {
Method method = connection.getClass().getMethod("setClientInfo", Properties.class);
method.invoke(connection, properties);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLClientInfoException)e;
}
// Simply log reflection exceptions.
Log.error(e);
}
}
public String getClientInfo(String name) throws SQLException {
try {
Method method = connection.getClass().getMethod("getClientInfo", String.class);
return (String)method.invoke(connection, name);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public Properties getClientInfo() throws SQLException {
try {
Method method = connection.getClass().getMethod("getClientInfo", new Class[] {});
return (Properties)method.invoke(connection);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public Array createArrayOf(String typeName, Object[] elements) throws SQLException {
try {
Method method = connection.getClass().getMethod("createArrayOf", String.class, Object[].class);
return (Array)method.invoke(connection, typeName, elements);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public Struct createStruct(String typeName, Object[] attributes) throws SQLException {
try {
Method method = connection.getClass().getMethod("createStruct", String.class, Object[].class);
return (Struct)method.invoke(connection, typeName, attributes);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public <T> T unwrap(Class<T> iface) throws SQLException {
try {
Method method = connection.getClass().getMethod("unwrap", Class.class);
return (T)method.invoke(connection, iface);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public boolean isWrapperFor(Class<?> iface) throws SQLException {
try {
Method method = connection.getClass().getMethod("isWrapperFor", Class.class);
return (Boolean)method.invoke(connection, iface);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return false;
}
}
}
\ No newline at end of file
......@@ -509,4 +509,224 @@ public abstract class CallableStatementWrapper extends StatementWrapper
public ParameterMetaData getParameterMetaData() throws SQLException {
return cstmt.getParameterMetaData();
}
// JDK 1.6 Methods. Not actually implemented. TODO: use refelection to handle.
public RowId getRowId(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException();
}
public RowId getRowId(String parameterName) throws SQLException {
throw new UnsupportedOperationException();
}
public void setRowId(String parameterName, RowId x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNString(String parameterName, String value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNCharacterStream(String parameterName, Reader value, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setNClob(String parameterName, NClob value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setClob(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBlob(String parameterName, InputStream inputStream, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setNClob(String parameterName, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public NClob getNClob(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException();
}
public NClob getNClob(String parameterName) throws SQLException {
throw new UnsupportedOperationException();
}
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
throw new UnsupportedOperationException();
}
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException();
}
public SQLXML getSQLXML(String parameterName) throws SQLException {
throw new UnsupportedOperationException();
}
public String getNString(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException();
}
public String getNString(String parameterName) throws SQLException {
throw new UnsupportedOperationException();
}
public Reader getNCharacterStream(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException();
}
public Reader getNCharacterStream(String parameterName) throws SQLException {
throw new UnsupportedOperationException();
}
public Reader getCharacterStream(int parameterIndex) throws SQLException {
throw new UnsupportedOperationException();
}
public Reader getCharacterStream(String parameterName) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBlob(String parameterName, Blob x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setClob(String parameterName, Clob x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setAsciiStream(String parameterName, InputStream x, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setBinaryStream(String parameterName, InputStream x, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setCharacterStream(String parameterName, Reader reader, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setAsciiStream(String parameterName, InputStream x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBinaryStream(String parameterName, InputStream x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setCharacterStream(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNCharacterStream(String parameterName, Reader value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setClob(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBlob(String parameterName, InputStream inputStream) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNClob(String parameterName, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
public void setRowId(int parameterIndex, RowId x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNString(int parameterIndex, String value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNCharacterStream(int parameterIndex, Reader value, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setNClob(int parameterIndex, NClob value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
throw new UnsupportedOperationException();
}
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBinaryStream(int parameterIndex, InputStream x, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setCharacterStream(int parameterIndex, Reader reader, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
}
\ No newline at end of file
......@@ -184,4 +184,86 @@ public abstract class PreparedStatementWrapper extends StatementWrapper
public ParameterMetaData getParameterMetaData() throws SQLException {
return pstmt.getParameterMetaData();
}
// JDK 1.6 Methods. Not actually implemented. TODO: use refelection to handle.
public void setRowId(int parameterIndex, RowId x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNString(int parameterIndex, String value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNCharacterStream(int parameterIndex, Reader value, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setNClob(int parameterIndex, NClob value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException {
throw new UnsupportedOperationException();
}
public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBinaryStream(int parameterIndex, InputStream x, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setCharacterStream(int parameterIndex, Reader reader, long length)
throws SQLException
{
throw new UnsupportedOperationException();
}
public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException {
throw new UnsupportedOperationException();
}
public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException {
throw new UnsupportedOperationException();
}
public void setClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException {
throw new UnsupportedOperationException();
}
public void setNClob(int parameterIndex, Reader reader) throws SQLException {
throw new UnsupportedOperationException();
}
}
\ No newline at end of file
......@@ -11,7 +11,10 @@
package org.jivesoftware.database;
import org.jivesoftware.util.Log;
import java.sql.*;
import java.lang.reflect.Method;
/**
* An implementation of the Statement interface that wraps an underlying
......@@ -26,7 +29,7 @@ public abstract class StatementWrapper implements Statement {
/**
* Creates a new StatementWrapper that wraps <tt>stmt</tt>.
*
* @param stmt
* @param stmt the Statement.
*/
public StatementWrapper(Statement stmt) {
this.stmt = stmt;
......@@ -179,4 +182,81 @@ public abstract class StatementWrapper implements Statement {
public int getResultSetHoldability() throws SQLException {
return stmt.getResultSetHoldability();
}
// JDK 1.6 Methods. We must handle these using reflection so that the code will compile on
// both JDK 1.6 and 1.5.
public boolean isClosed() throws SQLException {
try {
Method method = stmt.getClass().getMethod("isClosed");
return (Boolean)method.invoke(stmt);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return false;
}
}
public void setPoolable(boolean poolable) throws SQLException {
try {
Method method = stmt.getClass().getMethod("setPoolable", Boolean.class);
method.invoke(stmt, poolable);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
}
}
public boolean isPoolable() throws SQLException {
try {
Method method = stmt.getClass().getMethod("isPoolable");
return (Boolean)method.invoke(stmt);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return false;
}
}
public <T> T unwrap(Class<T> iface) throws SQLException {
try {
Method method = stmt.getClass().getMethod("unwrap", Class.class);
return (T)method.invoke(stmt, iface);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return null;
}
}
public boolean isWrapperFor(Class<?> iface) throws SQLException {
try {
Method method = stmt.getClass().getMethod("isWrapperFor", Class.class);
return (Boolean)method.invoke(stmt, iface);
}
catch (Exception e) {
if (e instanceof SQLException) {
throw (SQLException)e;
}
// Simply log reflection exceptions.
Log.error(e);
return false;
}
}
}
\ No newline at end of file
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