[exo-jcr-commits] exo-jcr SVN: r5821 - kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Mar 6 09:26:18 EST 2012


Author: tolusha
Date: 2012-03-06 09:26:18 -0500 (Tue, 06 Mar 2012)
New Revision: 5821

Modified:
   kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/DataSourceProviderImpl.java
Log:
EXOJCR-1763: avoid inconsistency in lock cache

Modified: kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/DataSourceProviderImpl.java
===================================================================
--- kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/DataSourceProviderImpl.java	2012-03-06 14:25:34 UTC (rev 5820)
+++ kernel/branches/2.4.x/exo.kernel.component.common/src/main/java/org/exoplatform/services/jdbc/impl/DataSourceProviderImpl.java	2012-03-06 14:26:18 UTC (rev 5821)
@@ -22,6 +22,8 @@
 import org.exoplatform.container.xml.ValueParam;
 import org.exoplatform.container.xml.ValuesParam;
 import org.exoplatform.services.jdbc.DataSourceProvider;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
 import org.exoplatform.services.transaction.TransactionService;
 
 import java.util.HashSet;
@@ -47,6 +49,11 @@
 {
 
    /**
+    * Logger
+    */
+   private static final Log LOG = ExoLogger.getLogger("exo.kernel.component.common.DataSourceProviderImpl");
+
+   /**
     * The name of the parameter to know if the tx has to be checked or not.
     */
    protected static final String PARAM_CHECK_TX = "check-tx-active";
@@ -137,9 +144,24 @@
     */
    public DataSource getDataSource(String dataSourceName) throws NamingException
    {
-      DataSource ds = (DataSource)new InitialContext().lookup(dataSourceName);
-      // wrap the data source object if it is managed
-      return isManaged(dataSourceName) ? new ManagedDataSource(ds, tm, checkIfTxActive) : ds;
+      InitialContext ctx = new InitialContext();
+      try
+      {
+         DataSource ds = (DataSource)ctx.lookup(dataSourceName);
+         // wrap the data source object if it is managed
+         return isManaged(dataSourceName) ? new ManagedDataSource(ds, tm, checkIfTxActive) : ds;
+      }
+      finally
+      {
+         try
+         {
+            ctx.close();
+         }
+         catch (NamingException e)
+         {
+            LOG.warn("Failed to close naming context.", e);
+         }
+      }
    }
    
    /**



More information about the exo-jcr-commits mailing list