openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fa...@apache.org
Subject svn commit: r704674 - in /openjpa/branches/1.2.x: openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/ openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/ openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/
Date Tue, 14 Oct 2008 20:45:40 GMT
Author: fancy
Date: Tue Oct 14 13:45:40 2008
New Revision: 704674

URL: http://svn.apache.org/viewvc?rev=704674&view=rev
Log:
OPENJPA-744
Reverting change to perform additional testing on the 1.2.x branch

Modified:
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
    openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
    openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestInverseEagerSQL.java

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java?rev=704674&r1=704673&r2=704674&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
(original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/kernel/JDBCStoreManager.java
Tue Oct 14 13:45:40 2008
@@ -35,7 +35,6 @@
 
 import javax.sql.DataSource;
 
-import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.event.OrphanedKeyAction;
 import org.apache.openjpa.jdbc.conf.JDBCConfiguration;
 import org.apache.openjpa.jdbc.conf.QuerySQLCacheValue;
@@ -355,19 +354,7 @@
                     getMappedByFieldMapping();
                 Object mappedByObject = info.result.getMappedByValue();
                 if (mappedByFieldMapping != null && mappedByObject != null)
-                    if (mappedByObject instanceof OpenJPAId)
-                        // The inverse relation can not be set since
-                        // we are eagerly loading this sm for
-                        // a sm owner that is still in the process of 
-                        // initializing itself.
-                        // Remember owner oid by setIntermediate().
-                        // The inverse relation is set later by
-                        // setInverseRelation() when the sm owner is fully
-                        // initialized.
-                        sm.setIntermediate(mappedByFieldMapping.getIndex(),
-                            mappedByObject);
-                    else
-                        setMappedBy(sm, mappedByFieldMapping, mappedByObject);
+                    setMappedBy(sm, mappedByFieldMapping, mappedByObject);
             }
             // load the selected mappings into the given state manager
             if (res != null) {
@@ -375,7 +362,6 @@
                 mapping = (ClassMapping) sm.getMetaData();
                 load(mapping, sm, fetch, res);
                 getVersion(mapping, sm, res);
-                setInverseRelation(sm, mapping, res);
             }
             return true;
         } finally {
@@ -384,47 +370,6 @@
         }
     }
 
-    private void setInverseRelation(OpenJPAStateManager owner,
-        ClassMapping mapping, Result res) {
-        FieldMapping[] fms = mapping.getFieldMappings();
-
-        // At this point, the owner is fully initialized.
-        // Check if the owner has eagerly loaded ToMany relations.
-        for (int i = 0; i < fms.length; i++) {
-            if (res.getEager(fms[i]) != null) {
-                Object coll =  owner.fetchObject(fms[i].getIndex());
-                if (coll instanceof Collection && 
-                    ((Collection) coll).size() > 0) {
-                    // Found eagerly loaded collection.
-                    // Publisher (1) <==>  (M) Magazine
-                    //    publisher has a EAGER OneToMany relation
-                    //    magazine has a EAGER or LAZY ManyToOne publisher
-                    // For each member (Magazine) in the collection, 
-                    // set its inverse relation (Publisher).
-                    for (Iterator itr = ((Collection) coll).iterator();
-                        itr.hasNext();) {
-                        PersistenceCapable pc = (PersistenceCapable) itr.next();
-                        OpenJPAStateManager sm = (OpenJPAStateManager) pc.
-                            pcGetStateManager();
-                        FieldMapping[] fmd = ((ClassMapping) sm.getMetaData()).
-                            getFieldMappings();
-                        for (int j = 0; j < fmd.length; j++) {
-                            Object oid = sm.getIntermediate(fmd[j].getIndex());
-                            // if oid was setIntermediate() previously
-                            // and it is the same as the owner,
-                            // then set the inverse relation
-                            if (oid != null &&
-                                oid.equals(owner.getObjectId())) {
-                                sm.storeObject(fmd[j].getIndex(),
-                                    owner.getPersistenceCapable());
-                            }
-                        }
-                    }
-                }
-            }
-        }
-    }
-
     protected void setMappedBy(OpenJPAStateManager sm,
         FieldMapping mappedByFieldMapping, Object mappedByObject) {
         ClassMapping mapping = (ClassMapping) sm.getMetaData();
@@ -969,29 +914,9 @@
         ConnectionInfo info = new ConnectionInfo();
         info.result = result;
         info.mapping = mapping;
-
-        // if inverse relation is known, exclude loading during find
-        exclude = excludeInverseRelation(mapping, info, exclude);
         return _ctx.find(oid, fetch, exclude, info, 0);
     }
 
-    private BitSet excludeInverseRelation(ClassMapping mapping,
-        ConnectionInfo info, BitSet exclude) {
-        FieldMapping inverse = info.result.getMappedByFieldMapping();
-        if (inverse != null) {
-            FieldMapping[] fms = mapping.getDefinedFieldMappings();
-            if (exclude == null)
-                exclude = new BitSet(fms.length);
-            for (int i = 0; i < fms.length; i++) {
-                if (fms[i] == inverse) {
-                    exclude.set(fms[i].getIndex());
-                    break;
-                }
-            }
-        }
-        return exclude;
-    }
-
     /**
      * Load the given state manager with data from the result set. Only
      * mappings originally selected will be loaded.

Modified: openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java?rev=704674&r1=704673&r2=704674&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
(original)
+++ openjpa/branches/1.2.x/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/strats/StoreCollectionFieldStrategy.java
Tue Oct 14 13:45:40 2008
@@ -312,8 +312,8 @@
             if (field.getOrderColumn() != null)
                 seq = res.getInt(field.getOrderColumn(), orderJoins) + 1;
 
-            // for inverse relation field
-            setMappedBy(oid, res);
+            // for inverseEager field
+            setMappedBy(oid, sm, coll, res);
             Object val = loadElement(null, store, fetch, res, dataJoins);
             add(store, coll, val);
         }
@@ -322,23 +322,6 @@
         return rels;
     }
 
-    private void setMappedBy(Object oid, Result res) {
-        //  for inverse toOne relation field
-        FieldMapping mappedByFieldMapping = field.getMappedByMapping();
-        
-        if (mappedByFieldMapping != null) {
-            ValueMapping val = mappedByFieldMapping.getValueMapping();
-            ClassMetaData decMeta = val.getTypeMetaData();
-            // this inverse field does not have corresponding classMapping
-            // its value may be a collection/map etc.
-            if (decMeta == null) 
-                return;
-            
-            res.setMappedByFieldMapping(mappedByFieldMapping);
-            res.setMappedByValue(oid);
-        }
-    }
-
     private void setMappedBy(Object oid, OpenJPAStateManager sm, Object coll,
         Result res) {
         // for inverseEager field

Modified: openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestInverseEagerSQL.java
URL: http://svn.apache.org/viewvc/openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestInverseEagerSQL.java?rev=704674&r1=704673&r2=704674&view=diff
==============================================================================
--- openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestInverseEagerSQL.java
(original)
+++ openjpa/branches/1.2.x/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/relations/TestInverseEagerSQL.java
Tue Oct 14 13:45:40 2008
@@ -21,16 +21,12 @@
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Set;
-
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 
 import junit.textui.TestRunner;
 import org.apache.openjpa.persistence.OpenJPAEntityManager;
 import org.apache.openjpa.persistence.OpenJPAQuery;
-import org.apache.openjpa.persistence.query.Magazine;
-import org.apache.openjpa.persistence.query.Publisher;
 import org.apache.openjpa.persistence.test.SQLListenerTestCase;
 
 
@@ -40,8 +36,7 @@
     public void setUp() {
         setUp(Customer.class, Customer.CustomerKey.class, Order.class, 
         	EntityAInverseEager.class, EntityA1InverseEager.class, EntityA2InverseEager.class,

-        	EntityBInverseEager.class, EntityCInverseEager.class, EntityDInverseEager.class,
-            Publisher.class, Magazine.class);
+        	EntityBInverseEager.class, EntityCInverseEager.class, EntityDInverseEager.class);
         
         EntityManager em = emf.createEntityManager();
         em.getTransaction().begin();
@@ -98,29 +93,7 @@
             c1.setD(d1);
             d1.setC(c1);
         }
-
-        Publisher p1 = new Publisher();
-        p1.setName("publisher1");
-        em.persist(p1);
-   
-        for (int i = 0; i < 4; i++) {
-            Magazine magazine = new Magazine();
-            magazine.setIdPublisher(p1);
-            magazine.setName("magagine"+i+"_"+p1.getName());
-            em.persist(magazine);
-        }
-
-        Publisher p2 = new Publisher();
-        p2.setName("publisher2");
-        em.persist(p2);
-   
-        for (int i = 0; i < 4; i++) {
-            Magazine magazine = new Magazine();
-            magazine.setIdPublisher(p2);
-            magazine.setName("magagine"+i+"_"+p2.getName());
-            em.persist(magazine);
-        }
-
+        
         em.flush();
         em.getTransaction().commit();
         em.close();
@@ -224,33 +197,6 @@
         em.close();
     }
 
-    public void testOneToManyEagerInverseLazyQuery() {
-        sql.clear();
-
-        OpenJPAEntityManager em = emf.createEntityManager();
-        String query = "select p FROM Publisher p";
-        Query q = em.createQuery(query);
-        List list = q.getResultList();
-        assertEquals(2, list.size());
-        assertEquals(2, sql.size());
-
-        sql.clear();
-        em.clear();
-        for (int i = 0; i < list.size(); i++) {
-            Publisher p = (Publisher) list.get(i);
-            Set<Magazine> magazines = p.getMagazineCollection();
-            assertEquals(4, magazines.size());
-            for (Iterator iter = magazines.iterator(); iter.hasNext();) {
-                Magazine m = (Magazine) iter.next();
-                Publisher mp = m.getIdPublisher();
-                assertEquals(p, mp);
-            }
-        }
-
-        assertEquals(0, sql.size());
-        em.close();
-    }
-
     public static void main(String[] args) {
         TestRunner.run(TestInverseEagerSQL.class);
     }



Mime
View raw message