cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r893477 - in /cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src: main/java/org/apache/cayenne/access/ main/java/org/apache/cayenne/access/dbsync/ test/java/org/apache/cayenne/access/dbsync/
Date Wed, 23 Dec 2009 11:34:36 GMT
Author: oltka
Date: Wed Dec 23 11:34:36 2009
New Revision: 893477

URL: http://svn.apache.org/viewvc?rev=893477&view=rev
Log:
CAY-1344

(cherry picked from commit db69bc14c14fec4d5d1cfc942319732d3bc28968)

Modified:
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/BaseSchemaUpdateStrategy.java
    cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/dbsync/SchemaUpdateStrategyTest.java

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java?rev=893477&r1=893476&r2=893477&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/DataNode.java
Wed Dec 23 11:34:36 2009
@@ -245,11 +245,6 @@
         Connection connection = null;
 
         try {
-            
-            if (schemaUpdateStrategy != null) {
-                schemaUpdateStrategy.updateSchema(this);
-            }
-            
             connection = this.getDataSource().getConnection();
         }
         catch (Exception globalEx) {
@@ -356,7 +351,11 @@
         final String CONNECTION_RESOURCE_PREFIX = "DataNode.Connection.";
 
         public Connection getConnection() throws SQLException {
+            if (schemaUpdateStrategy != null) {
+                schemaUpdateStrategy.updateSchema(DataNode.this);
+            }
             Transaction t = Transaction.getThreadTransaction();
+            
             if (t != null) {
                 String key = CONNECTION_RESOURCE_PREFIX + name;
                 Connection c = t.getConnection(key);
@@ -372,12 +371,15 @@
                 return new TransactionConnectionDecorator(c);
             }
 
+           
             return dataSource.getConnection();
         }
 
         public Connection getConnection(String username, String password)
                 throws SQLException {
-
+            if (schemaUpdateStrategy != null) {
+                schemaUpdateStrategy.updateSchema(DataNode.this);
+            }
             Transaction t = Transaction.getThreadTransaction();
             if (t != null) {
                 String key = CONNECTION_RESOURCE_PREFIX + name;

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/BaseSchemaUpdateStrategy.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/BaseSchemaUpdateStrategy.java?rev=893477&r1=893476&r2=893477&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/BaseSchemaUpdateStrategy.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/access/dbsync/BaseSchemaUpdateStrategy.java
Wed Dec 23 11:34:36 2009
@@ -28,16 +28,29 @@
 public abstract class BaseSchemaUpdateStrategy implements SchemaUpdateStrategy {
 
     protected volatile boolean run;
+    protected volatile ThreadLocal<Boolean> threadRunInProgress;
+
+    public BaseSchemaUpdateStrategy() {
+        super();
+        threadRunInProgress = new ThreadLocal<Boolean>();
+    }
 
     /**
      * @since 3.0
      */
     public void updateSchema(DataNode dataNode) throws SQLException {
-        if (!run) {
+
+        if (!run && (threadRunInProgress.get() == null || !threadRunInProgress.get()))
{
             synchronized (this) {
                 if (!run) {
-                    processSchemaUpdate(dataNode);
-                    run = true;
+                    try {
+                        threadRunInProgress.set(true);
+                        processSchemaUpdate(dataNode);
+                        run = true;
+                    }
+                    finally {
+                        threadRunInProgress.set(false);
+                    }
                 }
             }
         }

Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/dbsync/SchemaUpdateStrategyTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/dbsync/SchemaUpdateStrategyTest.java?rev=893477&r1=893476&r2=893477&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/dbsync/SchemaUpdateStrategyTest.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/test/java/org/apache/cayenne/access/dbsync/SchemaUpdateStrategyTest.java
Wed Dec 23 11:34:36 2009
@@ -44,6 +44,7 @@
 import org.apache.cayenne.query.Query;
 import org.apache.cayenne.query.SQLTemplate;
 import org.apache.cayenne.unit.CayenneCase;
+import org.apache.cayenne.unit.CayenneResources;
 import org.xml.sax.InputSource;
 
 public class SchemaUpdateStrategyTest extends CayenneCase {
@@ -140,7 +141,7 @@
         try {
             dataNode.performQueries(Collections.singletonList((Query) query), observer);
             Map<String, Boolean> nameTables = getNameTablesInDB(dataNode);
-            assertTrue(nameTables.get("sus1")!=null || nameTables.get("SUS1")!=null );
+            assertTrue(nameTables.get("sus1") != null || nameTables.get("SUS1") != null);
             int sizeDB2 = getNameTablesInDB(dataNode).size();
             assertEquals(2, sizeDB2 - sizeDB);
             dataNode.performQueries(Collections.singletonList((Query) query), observer);
@@ -274,7 +275,7 @@
         DataNode dataNode = new DataNode();
         dataNode.setDataMaps(colection);
         dataNode.setAdapter(adapter);
-        dataNode.setDataSource(getNode().getDataSource());
+        dataNode.setDataSource(CayenneResources.getResources().getDataSource());
         dataNode.setDataSourceFactory(getNode().getDataSourceFactory());
         dataNode.setSchemaUpdateStrategyName(getNode().getSchemaUpdateStrategyName());
         dataNode.setEntityResolver(new EntityResolver(colection));
@@ -300,14 +301,8 @@
             dataNode.setSchemaUpdateStrategy((SchemaUpdateStrategy) Class.forName(
                     dataNode.getSchemaUpdateStrategyName()).newInstance());
         }
-        catch (InstantiationException e) {
-            e.printStackTrace();
-        }
-        catch (IllegalAccessException e) {
-            e.printStackTrace();
-        }
-        catch (ClassNotFoundException e) {
-            e.printStackTrace();
+        catch (Exception e) {
+            throw new CayenneRuntimeException(e);
         }
     }
 
@@ -343,14 +338,14 @@
             rs.close();
         }
         catch (SQLException e) {
-            e.printStackTrace();
+            throw new CayenneRuntimeException(e);
         }
         finally {
             try {
                 con.close();
             }
             catch (SQLException e) {
-                e.printStackTrace();
+                throw new CayenneRuntimeException(e);
             }
         }
         return nameTables;



Mime
View raw message