Commit 7274e07a authored by Matt Tucker's avatar Matt Tucker Committed by matt

Work on using dynamic proxies.

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@6090 b35dd754-fafc-0310-a699-88a17e54d16e
parent d0b38e27
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.database;
import java.sql.*;
import java.math.BigDecimal;
import java.io.InputStream;
import java.io.Reader;
import java.util.Calendar;
import java.net.URL;
/**
* An implementation of the PreparedStatement interface that wraps an underlying
* PreparedStatement object.
*
* @author Gaston Dombiak
*/
public abstract class PreparedStatementWrapper extends StatementWrapper
implements PreparedStatement {
protected PreparedStatement pstmt;
public PreparedStatementWrapper(PreparedStatement pstmt) {
super(pstmt);
this.pstmt = pstmt;
}
public ResultSet executeQuery() throws SQLException {
return pstmt.executeQuery();
}
public int executeUpdate() throws SQLException {
return pstmt.executeUpdate();
}
public void setNull(int parameterIndex, int sqlType) throws SQLException {
pstmt.setNull(parameterIndex, sqlType);
}
public void setBoolean(int parameterIndex, boolean x) throws SQLException {
pstmt.setBoolean(parameterIndex, x);
}
public void setByte(int parameterIndex, byte x) throws SQLException {
pstmt.setByte(parameterIndex, x);
}
public void setShort(int parameterIndex, short x) throws SQLException {
pstmt.setShort(parameterIndex, x);
}
public void setInt(int parameterIndex, int x) throws SQLException {
pstmt.setInt(parameterIndex, x);
}
public void setLong(int parameterIndex, long x) throws SQLException {
pstmt.setLong(parameterIndex, x);
}
public void setFloat(int parameterIndex, float x) throws SQLException {
pstmt.setFloat(parameterIndex, x);
}
public void setDouble(int parameterIndex, double x) throws SQLException {
pstmt.setDouble(parameterIndex, x);
}
public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException {
pstmt.setBigDecimal(parameterIndex, x);
}
public void setString(int parameterIndex, String x) throws SQLException {
pstmt.setString(parameterIndex, x);
}
public void setBytes(int parameterIndex, byte x[]) throws SQLException {
pstmt.setBytes(parameterIndex, x);
}
public void setDate(int parameterIndex, Date x) throws SQLException {
pstmt.setDate(parameterIndex, x);
}
public void setTime(int parameterIndex, Time x) throws SQLException {
pstmt.setTime(parameterIndex, x);
}
public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException {
pstmt.setTimestamp(parameterIndex, x);
}
public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException {
pstmt.setAsciiStream(parameterIndex, x, length);
}
@Deprecated public void setUnicodeStream(int parameterIndex, InputStream x, int length)
throws SQLException {
pstmt.setUnicodeStream(parameterIndex, x, length);
}
public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException {
pstmt.setBinaryStream(parameterIndex, x, length);
}
public void clearParameters() throws SQLException {
pstmt.clearParameters();
}
public void setObject(int parameterIndex, Object x, int targetSqlType, int scale)
throws SQLException {
pstmt.setObject(parameterIndex, x, targetSqlType, scale);
}
public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException {
pstmt.setObject(parameterIndex, x, targetSqlType);
}
public void setObject(int parameterIndex, Object x) throws SQLException {
pstmt.setObject(parameterIndex, x);
}
public boolean execute() throws SQLException {
return pstmt.execute();
}
public void addBatch() throws SQLException {
pstmt.addBatch();
}
public void setCharacterStream(int parameterIndex, Reader reader, int length)
throws SQLException {
pstmt.setCharacterStream(parameterIndex, reader, length);
}
public void setRef(int i, Ref x) throws SQLException {
pstmt.setRef(i, x);
}
public void setBlob(int i, Blob x) throws SQLException {
pstmt.setBlob(i, x);
}
public void setClob(int i, Clob x) throws SQLException {
pstmt.setClob(i, x);
}
public void setArray(int i, Array x) throws SQLException {
pstmt.setArray(i, x);
}
public ResultSetMetaData getMetaData() throws SQLException {
return pstmt.getMetaData();
}
public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException {
pstmt.setDate(parameterIndex, x, cal);
}
public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException {
pstmt.setTime(parameterIndex, x, cal);
}
public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException {
pstmt.setTimestamp(parameterIndex, x, cal);
}
public void setNull(int paramIndex, int sqlType, String typeName) throws SQLException {
pstmt.setNull(paramIndex, sqlType, typeName);
}
public void setURL(int parameterIndex, URL x) throws SQLException {
pstmt.setURL(parameterIndex, x);
}
public ParameterMetaData getParameterMetaData() throws SQLException {
return pstmt.getParameterMetaData();
}
}
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2004 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
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
* Statement object.
*
* @author Gaston Dombiak
*/
public abstract class StatementWrapper implements Statement {
protected Statement stmt;
/**
* Creates a new StatementWrapper that wraps <tt>stmt</tt>.
*
* @param stmt the Statement.
*/
public StatementWrapper(Statement stmt) {
this.stmt = stmt;
}
public ResultSet executeQuery(String sql) throws SQLException {
return stmt.executeQuery(sql);
}
public int executeUpdate(String sql) throws SQLException {
return stmt.executeUpdate(sql);
}
public void close() throws SQLException {
stmt.close();
}
public int getMaxFieldSize() throws SQLException {
return stmt.getMaxFieldSize();
}
public void setMaxFieldSize(int max) throws SQLException {
stmt.setMaxFieldSize(max);
}
public int getMaxRows() throws SQLException {
return stmt.getMaxRows();
}
public void setMaxRows(int max) throws SQLException {
stmt.setMaxRows(max);
}
public void setEscapeProcessing(boolean enable) throws SQLException {
stmt.setEscapeProcessing(enable);
}
public int getQueryTimeout() throws SQLException {
return stmt.getQueryTimeout();
}
public void setQueryTimeout(int seconds) throws SQLException {
stmt.setQueryTimeout(seconds);
}
public void cancel() throws SQLException {
stmt.cancel();
}
public SQLWarning getWarnings() throws SQLException {
return stmt.getWarnings();
}
public void clearWarnings() throws SQLException {
stmt.clearWarnings();
}
public void setCursorName(String name) throws SQLException {
stmt.setCursorName(name);
}
public boolean execute(String sql) throws SQLException {
return stmt.execute(sql);
}
public ResultSet getResultSet() throws SQLException {
return stmt.getResultSet();
}
public int getUpdateCount() throws SQLException {
return stmt.getUpdateCount();
}
public boolean getMoreResults() throws SQLException {
return stmt.getMoreResults();
}
public void setFetchDirection(int direction) throws SQLException {
stmt.setFetchDirection(direction);
}
public int getFetchDirection() throws SQLException {
return stmt.getFetchDirection();
}
public void setFetchSize(int rows) throws SQLException {
stmt.setFetchSize(rows);
}
public int getFetchSize() throws SQLException {
return stmt.getFetchSize();
}
public int getResultSetConcurrency() throws SQLException {
return stmt.getResultSetConcurrency();
}
public int getResultSetType() throws SQLException {
return stmt.getResultSetType();
}
public void addBatch(String sql) throws SQLException {
stmt.addBatch(sql);
}
public void clearBatch() throws SQLException {
stmt.clearBatch();
}
public int[] executeBatch() throws SQLException {
return stmt.executeBatch();
}
public Connection getConnection() throws SQLException {
return stmt.getConnection();
}
public boolean getMoreResults(int current) throws SQLException {
return stmt.getMoreResults(current);
}
public ResultSet getGeneratedKeys() throws SQLException {
return stmt.getGeneratedKeys();
}
public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
return stmt.executeUpdate(sql, autoGeneratedKeys);
}
public int executeUpdate(String sql, int columnIndexes[]) throws SQLException {
return stmt.executeUpdate(sql, columnIndexes);
}
public int executeUpdate(String sql, String columnNames[]) throws SQLException {
return stmt.executeUpdate(sql, columnNames);
}
public boolean execute(String sql, int autoGeneratedKeys) throws SQLException {
return stmt.execute(sql, autoGeneratedKeys);
}
public boolean execute(String sql, int columnIndexes[]) throws SQLException {
return stmt.execute(sql, columnIndexes);
}
public boolean execute(String sql, String columnNames[]) throws SQLException {
return stmt.execute(sql, columnNames);
}
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
......@@ -105,7 +105,7 @@
<h3><fmt:message key="server.db_stats.settings" /></h3>
<form action="server-db-stats.jsp">
<table cellpadding="3" cellspacing="1" border="0" width="730">
<table cellpadding="3" cellspacing="5" border="0">
<tr>
<td>
<fmt:message key="server.db_stats.refresh" />:
......@@ -139,33 +139,33 @@
</div>
<h3><fmt:message key="server.db_stats.select_stats" /></h3>
<b><fmt:message key="server.db_stats.select_stats" /></b>
<ul>
<table bgcolor="#aaaaaa" cellpadding="0" cellspacing="0" border="0" width="730">
<table bgcolor="#aaaaaa" cellpadding="0" cellspacing="0" border="0" width="600">
<tr><td>
<table bgcolor="#aaaaaa" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.operations" /></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.SELECT)) %></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.Type.select)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_time" /></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.SELECT)) %></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.Type.select)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.avg_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.SELECT)) %></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.Type.select)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.SELECT)) %></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.Type.select)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.queries" /></td>
<td bgcolor="#ffffff"><%
ProfiledConnectionEntry[] list = ProfiledConnection.getSortedQueries(ProfiledConnection.SELECT, doSortByTime);
ProfiledConnectionEntry[] list = ProfiledConnection.getSortedQueries(ProfiledConnection.Type.select, doSortByTime);
if (list == null || list.length < 1) {
out.println(LocaleUtils.getLocalizedString("server.db_stats.no_queries"));
......@@ -180,7 +180,7 @@
<br />
<table bgcolor="#aaaaaa" cellpadding="0" cellspacing="0" border="0" width="730">
<table bgcolor="#aaaaaa" cellpadding="0" cellspacing="0" border="0" width="600">
<tr><td>
<table bgcolor="#aaaaaa" cellpadding="3" cellspacing="0" border="0" width="100%">
<tr bgcolor="#ffffff"><td>
......@@ -204,7 +204,7 @@
</td></tr>
</table>
</ul>
<b><fmt:message key="server.db_stats.insert_stats" /></b>
......@@ -215,24 +215,24 @@
<table bgcolor="#aaaaaa" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.operations" /></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.INSERT)) %></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.Type.insert)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_time" /></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.INSERT)) %></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.Type.insert)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.avg_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.INSERT)) %></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.Type.insert)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.INSERT)) %></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.Type.insert)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.queries" /></td>
<td bgcolor="#ffffff"><%
list = ProfiledConnection.getSortedQueries(ProfiledConnection.INSERT, doSortByTime);
list = ProfiledConnection.getSortedQueries(ProfiledConnection.Type.insert, doSortByTime);
if (list == null || list.length < 1) {
out.println(LocaleUtils.getLocalizedString("server.db_stats.no_queries"));
......@@ -282,24 +282,24 @@
<table bgcolor="#aaaaaa" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.operations" /></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.UPDATE)) %></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.Type.update)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_time" /></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.UPDATE)) %></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.Type.update)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.avg_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.UPDATE)) %></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.Type.update)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.UPDATE)) %></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.Type.update)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.queries" /></td>
<td bgcolor="#ffffff"><%
list = ProfiledConnection.getSortedQueries(ProfiledConnection.UPDATE, doSortByTime);
list = ProfiledConnection.getSortedQueries(ProfiledConnection.Type.update, doSortByTime);
if (list == null || list.length < 1) {
out.println(LocaleUtils.getLocalizedString("server.db_stats.no_queries"));
......@@ -349,24 +349,24 @@
<table bgcolor="#aaaaaa" cellpadding="3" cellspacing="1" border="0" width="100%">
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.operations" /></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.DELETE)) %></td>
<td><%= intFormat.format(ProfiledConnection.getQueryCount(ProfiledConnection.Type.delete)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_time" /></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.DELETE)) %></td>
<td><%= intFormat.format(ProfiledConnection.getTotalQueryTime(ProfiledConnection.Type.delete)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.avg_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.DELETE)) %></td>
<td><%= decFormat.format(ProfiledConnection.getAverageQueryTime(ProfiledConnection.Type.delete)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.total_rate" /></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.DELETE)) %></td>
<td><%= decFormat.format(ProfiledConnection.getQueriesPerSecond(ProfiledConnection.Type.delete)) %></td>
</tr>
<tr bgcolor="#ffffff">
<td><fmt:message key="server.db_stats.queries" /></td>
<td bgcolor="#ffffff"><%
list = ProfiledConnection.getSortedQueries(ProfiledConnection.DELETE, doSortByTime);
list = ProfiledConnection.getSortedQueries(ProfiledConnection.Type.delete, doSortByTime);
if (list == null || list.length < 1) {
out.println(LocaleUtils.getLocalizedString("server.db_stats.no_queries"));
......
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