You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2007/09/10 18:04:23 UTC
svn commit: r574290 -
/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/
Author: skitching
Date: Mon Sep 10 09:04:22 2007
New Revision: 574290
URL: http://svn.apache.org/viewvc?rev=574290&view=rev
Log:
Remove listener functionality from ConnectionManagerDataSource.
Removed:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/AbstractConnectionManagerListener.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/ConnectionManagerListener.java
Modified:
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/ConnectionManagerDataSource.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnection.java
myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnectionFactory.java
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/ConnectionManagerDataSource.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/ConnectionManagerDataSource.java?rev=574290&r1=574289&r2=574290&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/ConnectionManagerDataSource.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/ConnectionManagerDataSource.java Mon Sep 10 09:04:22 2007
@@ -44,6 +44,13 @@
* Of course all code should return its connections; this is only a workaround/hack useful when the
* real problem cannot be fixed. This is particularly useful for JPA implementations that do not free
* their connection again after a lazy-init.
+ * <p>
+ * If a proxy's underlying connection has been returned to the database (either via the
+ * leak-detection, or by explicitly calling close) then invoking any method on the proxy
+ * will transparently cause a new connection to be retrieved from the underlying datasource.
+ * This means that a Connection returned by this datasource works somewhat differently than
+ * a normal one: for a normal connection, close() followed by prepareStatement() would cause
+ * an exception to be thrown, but works when this datasource is used.
*
* @see org.apache.myfaces.orchestra.connectionManager.DisconnectableConnection
*/
@@ -51,7 +58,6 @@
{
private DataSource dataSource;
private String jndiName;
- private ConnectionManagerListener[] listeners;
// List of connections that have been borrowed by this thread but not returned.
// When using a threadpool, it is required that the releaseAllBorrowedConnections
@@ -72,25 +78,6 @@
void onAfterBorrowConnection(Connection con)
{
((Set) borrowedConnections.get()).add(con);
-
- if (listeners != null)
- {
- for (int i = 0; i<listeners.length; i++)
- {
- listeners[i].borrowConnection(con);
- }
- }
- }
-
- public void onBeforeReleaseConnection(Connection con)
- {
- if (listeners != null)
- {
- for (int i = 0; i<listeners.length; i++)
- {
- listeners[i].releaseConnection(con);
- }
- }
}
void onAfterReleaseConnection(Connection con)
@@ -98,6 +85,18 @@
((Set) borrowedConnections.get()).remove(con);
}
+ /**
+ * If the calling thread has allocated connections via this datasource, then return the
+ * underlying real connections to the underlying datasource.
+ * <p>
+ * To code that holds references to the proxy connection returned by this datasource,
+ * this operation is generally transparent. They continue to hold a reference to the
+ * proxy, and if a method is ever called on that proxy in the future then the proxy
+ * will transparently allocate a new underlying Connection at that time.
+ * <p>
+ * This is expected to be called just before a thread is returned to a threadpool,
+ * eg via a ServletFilter just before returning from processing a request.
+ */
public static void releaseAllBorrowedConnections()
{
DisconnectableConnection[] connections = new DisconnectableConnection[((Set) borrowedConnections.get()).size()];
@@ -112,16 +111,24 @@
((Set) borrowedConnections.get()).clear();
}
- public void setListeners(ConnectionManagerListener[] listeners)
- {
- this.listeners = listeners;
- }
-
+ /**
+ * Set the underlying datasource via an explicit call.
+ * See also method setJndiName.
+ */
public void setDataSource(DataSource dataSource)
{
this.dataSource = dataSource;
}
+ /**
+ * Return the underlying datasource for this wrapper.
+ * <p>
+ * If method setJndiName was used to specify the datasource, then it is retrieved
+ * from JNDI if necessary.
+ *
+ * @throw IllegalArgumentException if neither setDataSource nor setJndiName was called.
+ * @throw IllegalArgumentException if an invalid jndi name was specified.
+ */
public DataSource getDataSource()
{
if (dataSource != null)
@@ -142,41 +149,63 @@
return dataSource;
}
+ /**
+ * Specify that the underlying datasource should be retrieved via JNDI.
+ */
public void setJndiName(String jndiName)
{
this.jndiName = jndiName;
}
+ /**
+ * Return a proxy that wraps a connection of the underlying datasource.
+ */
public Connection getConnection() throws SQLException
{
return DisconnectableConnectionFactory.create(this);
}
+ /**
+ * Not supported. Always throws UnsupportedOperationException.
+ */
public Connection getConnection(String username, String password) throws SQLException
{
throw new UnsupportedOperationException();
}
+ /** @inherited */
public PrintWriter getLogWriter() throws SQLException
{
return getDataSource().getLogWriter();
}
+ /** @inherited */
public void setLogWriter(PrintWriter out) throws SQLException
{
getDataSource().setLogWriter(out);
}
+ /** @inherited */
public void setLoginTimeout(int seconds) throws SQLException
{
getDataSource().setLoginTimeout(seconds);
}
+ /** @inherited */
public int getLoginTimeout() throws SQLException
{
return getDataSource().getLoginTimeout();
}
+ /**
+ * Always throws UnsupportedOperationException.
+ * <p>
+ * Note that this method was only introduced in java 1.6, and therefore
+ * cannot be implemented on platforms earlier than this without using
+ * reflection. Orchestra supports pre-1.6 JVMs, and this is a very
+ * rarely used method so currently no support is offered for this
+ * method.
+ */
public Object unwrap(Class iface) throws SQLException
{
throw new UnsupportedOperationException();
@@ -206,6 +235,10 @@
*/
}
+ /**
+ * Always throws UnsupportedOperationException.
+ * See method unwrap.
+ */
public boolean isWrapperFor(Class iface) throws SQLException
{
throw new UnsupportedOperationException();
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnection.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnection.java?rev=574290&r1=574289&r2=574290&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnection.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnection.java Mon Sep 10 09:04:22 2007
@@ -21,15 +21,22 @@
import java.sql.Connection;
/**
- * A workaround to the lazy-init-in-view problem.<br />
- *
- * We hand out DisconnectableConnections to the JPA-implementation, now,
- * if a lazy-init happens during the view rendering we are able to disconnect it again
- * at the end of the request (using a servlet filter). Once the JPA-implementation would like to
- * do something with the connection again, we simply request a new from the connection pool
+ * The interface for objects returned by the getConnection method of ConnectionManagerDataSource.
+ * <p>
+ * Implementations of this interface are expected to hold a reference to an underlying Connection.
*/
public interface DisconnectableConnection extends Connection
{
+ /**
+ * Close the underlying connection object.
+ * <p>
+ * Note that if methods are called on this object that require a connection, then a
+ * fresh connection will transparently be allocated and cached.
+ */
public void disconnect();
+
+ /**
+ * Get the real underlying Connection object.
+ */
public Connection getConnection();
}
Modified: myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnectionFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnectionFactory.java?rev=574290&r1=574289&r2=574290&view=diff
==============================================================================
--- myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnectionFactory.java (original)
+++ myfaces/orchestra/trunk/core/src/main/java/org/apache/myfaces/orchestra/connectionManager/DisconnectableConnectionFactory.java Mon Sep 10 09:04:22 2007
@@ -68,7 +68,6 @@
{
try
{
- connectionManager.onBeforeReleaseConnection((Connection) proxy);
if (connection != null)
{
connection.close();
@@ -83,7 +82,6 @@
}
else if ("disconnect".equals(method.getName())) // NON-NLS
{
- connectionManager.onBeforeReleaseConnection((Connection) proxy);
try
{
if (connection != null)