You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openjpa.apache.org by mi...@apache.org on 2008/12/09 17:15:45 UTC

svn commit: r724768 - in /openjpa/branches/1.3.x: ./ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/ openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-persistence-jdbc/src...

Author: mikedd
Date: Tue Dec  9 08:15:45 2008
New Revision: 724768

URL: http://svn.apache.org/viewvc?rev=724768&view=rev
Log:
OPENJPA-817 merged to 1.3.x

Added:
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/Employee.java
      - copied unchanged from r724765, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/Employee.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/Story.java
      - copied unchanged from r724765, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/Story.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/Task.java
      - copied unchanged from r724765, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/Task.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/TestInsertOrder.java
      - copied unchanged from r724765, openjpa/trunk/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/jdbc/kernel/TestInsertOrder.java
Modified:
    openjpa/branches/1.3.x/   (props changed)
    openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ConstraintUpdateManager.java
    openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowManagerImpl.java
    openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
    openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java

Propchange: openjpa/branches/1.3.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Dec  9 08:15:45 2008
@@ -1 +1 @@
-/openjpa/trunk:712928,719698,720521,720529
+/openjpa/trunk:712928,719698,720521,720529,724765

Modified: openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ConstraintUpdateManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ConstraintUpdateManager.java?rev=724768&r1=724767&r2=724768&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ConstraintUpdateManager.java (original)
+++ openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ConstraintUpdateManager.java Tue Dec  9 08:15:45 2008
@@ -58,7 +58,7 @@
         (ConstraintUpdateManager.class);
 
     public boolean orderDirty() {
-        return false;
+        return true;
     }
 
     protected PreparedStatementManager newPreparedStatementManager
@@ -84,9 +84,10 @@
         flush(rmimpl.getAllRowUpdates(), psMgr);
 
         // analyze foreign keys
-        Collection inserts = rmimpl.getInserts();
-        Collection updates = rmimpl.getUpdates();
-        Collection deletes = rmimpl.getDeletes();
+        Collection<PrimaryRow> inserts = rmimpl.getInserts();
+        Collection<PrimaryRow> updates = rmimpl.getUpdates();
+        Collection<PrimaryRow> deletes = rmimpl.getDeletes();
+    
         Graph[] graphs = new Graph[2];    // insert graph, delete graph
         analyzeForeignKeys(inserts, updates, deletes, rmimpl, graphs);
 

Modified: openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowManagerImpl.java?rev=724768&r1=724767&r2=724768&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowManagerImpl.java (original)
+++ openjpa/branches/1.3.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/sql/RowManagerImpl.java Tue Dec  9 08:15:45 2008
@@ -22,7 +22,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -39,17 +39,17 @@
 public class RowManagerImpl
     implements RowManager {
 
-    private Map _inserts = null;
-    private Map _updates = null;
-    private Map _deletes = null;
-    private Collection _secondaryUpdates = null;
-    private Collection _secondaryDeletes = null;
-    private Collection _allRowUpdates = null;
-    private Collection _allRowDeletes = null;
+    private Map<Key, PrimaryRow> _inserts = null;
+    private Map<Key, PrimaryRow> _updates = null;
+    private Map<Key, PrimaryRow> _deletes = null;
+    private Collection<SecondaryRow> _secondaryUpdates = null;
+    private Collection<SecondaryRow> _secondaryDeletes = null;
+    private Collection<Row> _allRowUpdates = null;
+    private Collection<Row> _allRowDeletes = null;
 
     // we maintain a list of the order of all primary rows if the user
     // wants to be able to fetch them in order
-    private final List _primaryOrder;
+    private final List<PrimaryRow> _primaryOrder;
 
     // track whether we're dealing with any auto-inc columns
     private boolean _auto = false;
@@ -66,7 +66,7 @@
      * @param order whether to keep track of the order in which rows are added
      */
     public RowManagerImpl(boolean order) {
-        _primaryOrder = (order) ? new ArrayList() : null;
+        _primaryOrder = (order) ? new ArrayList<PrimaryRow>() : null;
     }
 
     /**
@@ -80,61 +80,98 @@
      * Return the ordered primary rows. Only available if ordering requested
      * on construction.
      */
-    public List getOrdered() {
-        return (_primaryOrder == null) ? Collections.EMPTY_LIST : _primaryOrder;
+    public List<PrimaryRow> getOrdered() {
+        if(_primaryOrder == null ) { 
+            return Collections.emptyList();
+        }
+        else { 
+            return _primaryOrder;
+        }
     }
 
     /**
      * Return all inserted primary rows.
      */
-    public Collection getInserts() {
-        return (_inserts == null) ? Collections.EMPTY_LIST : _inserts.values();
+    public Collection<PrimaryRow> getInserts() {
+        if(_inserts == null ) {
+            return Collections.emptyList();
+        }
+        else {
+            return _inserts.values();
+        }
     }
 
     /**
      * Return all updated primary rows.
      */
-    public Collection getUpdates() {
-        return (_updates == null) ? Collections.EMPTY_LIST : _updates.values();
+    public Collection<PrimaryRow> getUpdates() {
+        if(_updates == null ){ 
+            return Collections.emptyList();
+        }
+        else { 
+            return _updates.values();
+        }
     }
 
     /**
      * Return all deleted primary rows.
      */
-    public Collection getDeletes() {
-        return (_deletes == null) ? Collections.EMPTY_LIST : _deletes.values();
+    public Collection<PrimaryRow> getDeletes() {
+        if(_deletes == null) { 
+            return Collections.emptyList();
+        }
+        else {
+            return _deletes.values();
+        }
     }
 
     /**
      * Return all inserted and updated secondary rows.
      */
-    public Collection getSecondaryUpdates() {
-        return (_secondaryUpdates == null) ? Collections.EMPTY_LIST
-            : _secondaryUpdates;
+    public Collection<SecondaryRow> getSecondaryUpdates() {
+        if(_secondaryUpdates == null) { 
+            return Collections.emptyList();
+        }
+        else { 
+            return _secondaryUpdates;
+        }
     }
 
     /**
      * Return all deleted secondary rows.
      */
-    public Collection getSecondaryDeletes() {
-        return (_secondaryDeletes == null) ? Collections.EMPTY_LIST
-            : _secondaryDeletes;
+    public Collection<SecondaryRow> getSecondaryDeletes() {
+        if(_secondaryDeletes == null) { 
+            return Collections.emptyList();
+        }
+        else { 
+            return _secondaryDeletes;
+        }
     }
 
     /**
      * Return any 'all row' updates.
      */
-    public Collection getAllRowUpdates() {
-        return (_allRowUpdates == null) ? Collections.EMPTY_LIST
-            : _allRowUpdates;
+    public Collection<Row> getAllRowUpdates() {
+        if(_allRowUpdates == null) { 
+            return Collections.emptyList();
+        }
+        else { 
+            return _allRowUpdates;
+        }
     }
 
     /**
      * Return any 'all row' deletes.
      */
-    public Collection getAllRowDeletes() {
-        return (_allRowDeletes == null) ? Collections.EMPTY_LIST
-            : _allRowDeletes;
+    public Collection<Row> getAllRowDeletes() {
+        if(_allRowDeletes == null) { 
+            return Collections.emptyList();
+        }
+        else { 
+            return _allRowDeletes;
+        }
+        
     }
 
     public Row getSecondaryRow(Table table, int action) {
@@ -149,12 +186,12 @@
         SecondaryRow srow = (SecondaryRow) row;
         if (srow.getAction() == Row.ACTION_DELETE) {
             if (_secondaryDeletes == null)
-                _secondaryDeletes = new ArrayList();
-            _secondaryDeletes.add(srow.clone());
+                _secondaryDeletes = new ArrayList<SecondaryRow>();
+            _secondaryDeletes.add((SecondaryRow) srow.clone());
         } else {
             if (_secondaryUpdates == null)
-                _secondaryUpdates = new ArrayList();
-            _secondaryUpdates.add(srow.clone());
+                _secondaryUpdates = new ArrayList<SecondaryRow>();
+            _secondaryUpdates.add((SecondaryRow) srow.clone());
         }
     }
 
@@ -169,12 +206,12 @@
         switch (row.getAction()) {
             case Row.ACTION_UPDATE:
                 if (_allRowUpdates == null)
-                    _allRowUpdates = new ArrayList();
+                    _allRowUpdates = new ArrayList<Row>();
                 _allRowUpdates.add(row);
                 break;
             case Row.ACTION_DELETE:
                 if (_allRowDeletes == null)
-                    _allRowDeletes = new ArrayList();
+                    _allRowDeletes = new ArrayList<Row>();
                 _allRowDeletes.add(row);
                 break;
             default:
@@ -192,25 +229,25 @@
             && _row != null && _row.getAction() == action)
             return _row;
 
-        Map map;
+        Map<Key, PrimaryRow> map;
         if (action == Row.ACTION_DELETE) {
             if (_deletes == null && create)
-                _deletes = new HashMap();
+                _deletes = new LinkedHashMap<Key, PrimaryRow>();
             map = _deletes;
         } else if (action == Row.ACTION_INSERT) {
             if (_inserts == null && create)
-                _inserts = new HashMap();
+                _inserts = new LinkedHashMap<Key, PrimaryRow>();
             map = _inserts;
         } else {
             if (_updates == null && create)
-                _updates = new HashMap();
+                _updates = new LinkedHashMap<Key, PrimaryRow>();
             map = _updates;
         }
         if (map == null)
             return null;
 
         _key = new Key(table, sm);
-        _row = (PrimaryRow) map.get(_key);
+        _row = map.get(_key);
 
         if (_row == null && create) {
             _row = new PrimaryRow(table, action, sm);

Modified: openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java?rev=724768&r1=724767&r2=724768&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java (original)
+++ openjpa/branches/1.3.x/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/BrokerImpl.java Tue Dec  9 08:15:45 2008
@@ -32,10 +32,13 @@
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.LinkedHashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.locks.ReentrantLock;
+
 import javax.transaction.Status;
 import javax.transaction.Synchronization;
 
@@ -61,7 +64,6 @@
 import org.apache.openjpa.lib.util.ReferenceHashMap;
 import org.apache.openjpa.lib.util.ReferenceHashSet;
 import org.apache.openjpa.lib.util.ReferenceMap;
-import java.util.concurrent.locks.ReentrantLock;
 import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.MetaDataRepository;
@@ -3310,7 +3312,7 @@
             Object obj;
             StateManagerImpl sm;
             ClassMetaData meta;
-            Collection sms = new HashSet(objs.size());
+            Collection sms = new LinkedHashSet(objs.size());
             List exceps = null;
             for (Iterator itr = objs.iterator(); itr.hasNext();) {
                 obj = itr.next();
@@ -3637,7 +3639,7 @@
         try {
             assertActiveTransaction();
 
-            Collection sms = new HashSet(objs.size());
+            Collection sms = new LinkedHashSet(objs.size());
             Object obj;
             StateManagerImpl sm;
             for (Iterator itr = objs.iterator(); itr.hasNext();) {
@@ -3815,7 +3817,7 @@
     protected Collection getPendingTransactionalStates() {
         if (_pending == null)
             return Collections.EMPTY_SET;
-        return new HashSet(_pending);
+        return new LinkedHashSet(_pending);
     }
 
     /**
@@ -4508,7 +4510,7 @@
             // size may not be entirely accurate due to refs expiring, so
             // manually copy each object; doesn't matter this way if size too
             // big by some
-            Set copy = new HashSet(size());
+            Set copy = new LinkedHashSet(size());
             if (_dirty != null)
                 for (Iterator itr = _dirty.iterator(); itr.hasNext();)
                     copy.add(itr.next());
@@ -4524,7 +4526,7 @@
         public Collection copyDirty() {
             if (_dirty == null || _dirty.isEmpty())
                 return Collections.EMPTY_SET;
-            return new HashSet(_dirty);
+            return new LinkedHashSet(_dirty);
         }
 
         /**

Modified: openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java?rev=724768&r1=724767&r2=724768&view=diff
==============================================================================
--- openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java (original)
+++ openjpa/branches/1.3.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/test/SQLListenerTestCase.java Tue Dec  9 08:15:45 2008
@@ -21,7 +21,6 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.ArrayList;
-import java.util.Map;
 
 import org.apache.openjpa.lib.jdbc.AbstractJDBCListener;
 import org.apache.openjpa.lib.jdbc.JDBCEvent;
@@ -34,7 +33,7 @@
  */
 public abstract class SQLListenerTestCase
     extends SingleEMFTestCase {
-
+    private static String _nl = System.getProperty("line.separator");
     protected List<String> sql = new ArrayList<String>();
     protected int sqlCount;
     
@@ -130,4 +129,28 @@
             }
 		}
 	}
+    
+    public void assertSQLOrder(String... expected) {
+        int hits = 0;
+
+        for (String executedSQL : sql) {
+            if (executedSQL.matches(expected[hits])) {
+                hits++;
+            }
+        }
+
+        if (hits != expected.length) {
+            StringBuilder sb = new StringBuilder();
+            sb.append("Did not find SQL in expected order : ").append(_nl);
+            for (String s : expected) {
+                sb.append(s).append(_nl);
+            }
+
+            sb.append("SQL Statements issued : ");
+            for (String s : sql) {
+                sb.append(s).append(_nl);
+            }
+            fail(sb.toString());
+        }
+    }
 }