commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r829642 - in /commons/proper/dbcp/trunk/src: java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java test/org/apache/commons/dbcp/managed/TestBasicManagedDataSource.java
Date Sun, 25 Oct 2009 20:36:15 GMT
Author: psteitz
Date: Sun Oct 25 20:36:14 2009
New Revision: 829642

URL: http://svn.apache.org/viewvc?rev=829642&view=rev
Log:
Improved thread-safety.

Modified:
    commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java
    commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/managed/TestBasicManagedDataSource.java

Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java?rev=829642&r1=829641&r2=829642&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/managed/BasicManagedDataSource.java
Sun Oct 25 20:36:14 2009
@@ -53,11 +53,11 @@
  */
 public class BasicManagedDataSource extends BasicDataSource {
     /** Transaction Registry */
-    protected TransactionRegistry transactionRegistry;
+    private TransactionRegistry transactionRegistry;
     /** Transaction Manager */
-    protected TransactionManager transactionManager;
+    private TransactionManager transactionManager;
     /** XA datasource class name */
-    protected String xaDataSource;
+    private String xaDataSource;
     /** XA datasource instance */
     private XADataSource xaDataSourceInstance;
 
@@ -89,15 +89,23 @@
      * Gets the required transaction manager property.
      * @return the transaction manager used to enlist connections
      */
-    public TransactionManager getTransactionManager() {
+    public synchronized TransactionManager getTransactionManager() {
         return transactionManager;
     }
+    
+    /**
+     * Gets the transaction registry.
+     * @return the transaction registry associating XAResources with managed connections
+     */
+    protected synchronized TransactionRegistry getTransactionRegistry() {
+        return transactionRegistry;
+    }
 
     /**
      * Sets the required transaction manager property.
      * @param transactionManager the transaction manager used to enlist connections
      */
-    public void setTransactionManager(TransactionManager transactionManager) {
+    public synchronized void setTransactionManager(TransactionManager transactionManager)
{
         this.transactionManager = transactionManager;
     }
 
@@ -105,7 +113,7 @@
      * Gets the optional XADataSource class name.
      * @return the optional XADataSource class name
      */
-    public String getXADataSource() {
+    public synchronized String getXADataSource() {
         return xaDataSource;
     }
 
@@ -113,7 +121,7 @@
      * Sets the optional XADataSource class name.
      * @param xaDataSource the optional XADataSource class name
      */
-    public void setXADataSource(String xaDataSource) {
+    public synchronized void setXADataSource(String xaDataSource) {
         this.xaDataSource = xaDataSource;
     }
 

Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/managed/TestBasicManagedDataSource.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/managed/TestBasicManagedDataSource.java?rev=829642&r1=829641&r2=829642&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/managed/TestBasicManagedDataSource.java
(original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp/managed/TestBasicManagedDataSource.java
Sun Oct 25 20:36:14 2009
@@ -63,13 +63,13 @@
         basicManagedDataSource.setMaxIdle(1); 
         // Create and register a connection
         ManagedConnection conn = (ManagedConnection) basicManagedDataSource.getConnection();
-        basicManagedDataSource.transactionRegistry.registerConnection(conn, new LocalXAResource(conn));
+        basicManagedDataSource.getTransactionRegistry().registerConnection(conn, new LocalXAResource(conn));
         // Create another connection and return it to the pool
         ManagedConnection conn2 = (ManagedConnection) basicManagedDataSource.getConnection();
         conn2.close();
         conn.close(); // No room at the inn - this will trigger reallyClose(), which should
unregister
         try {
-            basicManagedDataSource.transactionRegistry.getXAResource(conn);
+            basicManagedDataSource.getTransactionRegistry().getXAResource(conn);
             fail("Expecting SQLException - XAResources orphaned");
         } catch (SQLException ex) {
             // expected



Mime
View raw message