openjpa-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fayw...@apache.org
Subject svn commit: r739448 - in /openjpa/trunk: openjpa-kernel/src/main/java/org/apache/openjpa/kernel/ openjpa-kernel/src/main/java/org/apache/openjpa/meta/ openjpa-persistence/src/main/java/org/apache/openjpa/persistence/
Date Fri, 30 Jan 2009 23:06:30 GMT
Author: faywang
Date: Fri Jan 30 23:06:29 2009
New Revision: 739448

URL: http://svn.apache.org/viewvc?rev=739448&view=rev
Log:
OPENJPA-870: rollback r739155 to re-use the code path
of @Dependent and @ElementDependent for orphanRemoval.

Removed:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/OrphanRemovalManager.java
Modified:
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/InverseManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SaveFieldManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
    openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
    openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/InverseManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/InverseManager.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/InverseManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/InverseManager.java
Fri Jan 30 23:06:29 2009
@@ -18,21 +18,17 @@
  */
 package org.apache.openjpa.kernel;
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
 import org.apache.openjpa.conf.OpenJPAConfiguration;
 import org.apache.openjpa.datacache.DataCache;
-import org.apache.openjpa.enhance.PersistenceCapable;
 import org.apache.openjpa.lib.conf.Configurable;
 import org.apache.openjpa.lib.conf.Configuration;
 import org.apache.openjpa.lib.log.Log;
 import org.apache.openjpa.lib.util.Localizer;
-import org.apache.openjpa.meta.ClassMetaData;
 import org.apache.openjpa.meta.FieldMetaData;
 import org.apache.openjpa.meta.JavaTypes;
 import org.apache.openjpa.meta.ValueMetaData;
@@ -152,43 +148,23 @@
         // clear any restorable relations
         clearInverseRelations(sm, fmd, inverses, value);
 
-        // create inverse relations
-        createInverseRelations(sm, fmd, inverses, value);
+        if (value != null) {
+            StoreContext ctx = sm.getContext();
+            switch (fmd.getDeclaredTypeCode()) {
+                case JavaTypes.PC:
+                    createInverseRelations(ctx, sm.getManagedInstance(),
+                        value, fmd, inverses);
+                    break;
+                case JavaTypes.COLLECTION:
+                    for (Iterator itr = ((Collection) value).iterator();
+                        itr.hasNext();)
+                        createInverseRelations(ctx, sm.getManagedInstance(),
+                            itr.next(), fmd, inverses);
+                    break;
+            }
+        }
     }
 
-    protected void createInverseRelations(OpenJPAStateManager sm,
-        FieldMetaData fmd, FieldMetaData[] inverses, Object value) {
-        if (value == null) 
-            return;
-        StoreContext ctx = sm.getContext();
-        if (isEmbedded(sm))
-            return;
-        Object obj = sm.getManagedInstance();
-        createInverseRelations(ctx, obj, fmd, inverses, value);
-    }
-    
-    protected void createInverseRelations(StoreContext ctx, Object obj,
-        FieldMetaData fmd, FieldMetaData[] inverses, Object value) {
-        switch (fmd.getDeclaredTypeCode()) {
-        case JavaTypes.PC:
-            createInverseRelations(ctx, obj, value, fmd, inverses);
-            break;
-        case JavaTypes.COLLECTION:
-            for (Iterator itr = ((Collection) value).iterator();
-            itr.hasNext();)
-                createInverseRelations(ctx, obj, itr.next(), fmd, inverses);
-            break;
-        }        
-    }
-    
-    protected boolean isEmbedded(OpenJPAStateManager sm) {
-        ClassMetaData meta = sm.getMetaData();
-        ValueMetaData owner = meta.getEmbeddingMetaData();
-        if (owner != null)
-            return true;
-        return false;
-    }
-    
     /**
      * Create the inverse relations for all the given inverse fields.
      * A relation exists from <code>fromRef</code> to <code>toRef</code>;
this
@@ -320,10 +296,7 @@
                 case JavaTypes.PC:
                     if (!owned || inverses[i].getCascadeDelete()
                         == ValueMetaData.CASCADE_AUTO)
-                        if (fmd.getOrphanRemoval() || fmd.getElement().getOrphanRemoval())
-                            ((StateManagerImpl)other).delete();
-                        else
-                            storeNull(other, inverses[i], sm.getManagedInstance()); 
+                        storeNull(other, inverses[i], sm.getManagedInstance());
                     break;
                 case JavaTypes.COLLECTION:
                     if (!owned || inverses[i].getElement().getCascadeDelete()

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SaveFieldManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SaveFieldManager.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SaveFieldManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SaveFieldManager.java
Fri Jan 30 23:06:29 2009
@@ -113,12 +113,11 @@
                 mutable = true;
         }
 
-        // if this is not an inverse field or a field subject to orphanRemoval
-        // and the proper restore flag is not set, skip it
+        // if this is not an inverse field and the proper restore flag is
+        // not set, skip it
 
-        if ((_sm.getBroker().getInverseManager() == null
-            || fmd.getInverseMetaDatas().length == 0) && 
-            (fmd.getOrphanRemovalMetaDatas().length == 0)) {
+        if (_sm.getBroker().getInverseManager() == null
+            || fmd.getInverseMetaDatas().length == 0) {
             // use sm's restore directive, not broker's
             int restore = _sm.getBroker().getRestoreState();
             if (restore == RestoreState.RESTORE_NONE

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/SingleFieldManager.java
Fri Jan 30 23:06:29 2009
@@ -479,19 +479,8 @@
 
         // manage inverses
         InverseManager manager = _broker.getInverseManager();
-        FieldMetaData[] inverses = fmd.getInverseMetaDatas();
-        
-        // if there is bi-di relation and InverseManager is on,
-        // use InverseManager to remove the orphans. 
-        // for uni-directional relation or InverseManager is not on,
-        // we need to use OrphanRemovalManager to remove the orphans
-        if (manager != null && inverses.length > 0)
+        if (manager != null)
             manager.correctRelations(_sm, fmd, objval);
-        else {
-            FieldMetaData[] orphans = fmd.getOrphanRemovalMetaDatas();
-            if (orphans.length > 0)
-                OrphanRemovalManager.correctRelations(_sm, fmd, objval);
-        }
         return ret;
     }
 

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/kernel/StateManagerImpl.java
Fri Jan 30 23:06:29 2009
@@ -105,7 +105,6 @@
     private static final int FLAG_VERSION_CHECK = 2 << 14;
     private static final int FLAG_VERSION_UPDATE = 2 << 15;
     private static final int FLAG_DETACHING = 2 << 16;
-    private static final int FLAG_ORPHAN_REMOVAL = 2 << 17;
 
     private static final Localizer _loc = Localizer.forPackage
         (StateManagerImpl.class);
@@ -307,10 +306,6 @@
             if (_broker.getInverseManager() != null
                 && fmds[i].getInverseMetaDatas().length > 0)
                 _flags |= FLAG_INVERSES;
-            // record whether there are any managed fields subject to
-            // orphan removal
-            if (fmds[i].getOrphanRemovalMetaDatas().length > 0)
-                _flags |= FLAG_ORPHAN_REMOVAL;
         }
 
         pc.pcSetDetachedState(null);
@@ -864,12 +859,9 @@
 
     public Object fetchInitialField(int field) {
         FieldMetaData fmd = _meta.getField(field);
-        boolean hasInverse = (_flags & FLAG_INVERSES) != 0
-            && fmd.getInverseMetaDatas().length > 0;
-        boolean hasOrphanRemoval = (_flags & FLAG_ORPHAN_REMOVAL) != 0
-            && fmd.getOrphanRemovalMetaDatas().length > 0;
         if (_broker.getRestoreState() == RestoreState.RESTORE_NONE
-            && (!hasInverse && !hasOrphanRemoval))
+            && ((_flags & FLAG_INVERSES) == 0
+            || fmd.getInverseMetaDatas().length == 0))
             throw new InvalidStateException(_loc.get("restore-unset"));
 
         switch (fmd.getDeclaredTypeCode()) {
@@ -881,7 +873,8 @@
             case JavaTypes.OBJECT:
                 // if we're not saving mutable types, throw an exception
                 if (_broker.getRestoreState() != RestoreState.RESTORE_ALL
-                    && (!hasInverse && !hasOrphanRemoval)) 
+                    && ((_flags & FLAG_INVERSES) == 0
+                    || fmd.getInverseMetaDatas().length == 0))
                     throw new InvalidStateException(_loc.get
                         ("mutable-restore-unset"));
         }
@@ -2679,8 +2672,7 @@
      */
     void saveFields(boolean immediate) {
         if (_broker.getRestoreState() == RestoreState.RESTORE_NONE
-            && (((_flags & FLAG_INVERSES) == 0) 
-            || ((_flags & FLAG_ORPHAN_REMOVAL) == 0))) 
+            && (_flags & FLAG_INVERSES) == 0)
             return;
 
         _flags |= FLAG_SAVE;
@@ -2708,12 +2700,8 @@
 
         // if this is a managed inverse field, load it so we're sure to have
         // the original value
-        FieldMetaData fmd = _meta.getField(field);
-        boolean hasInverse = (_flags & FLAG_INVERSES) != 0
-            && fmd.getInverseMetaDatas().length > 0;
-        boolean hasOrphanRemoval = (_flags & FLAG_ORPHAN_REMOVAL) != 0
-            && fmd.getOrphanRemovalMetaDatas().length > 0;
-        if (!_loaded.get(field) && (hasInverse || hasOrphanRemoval))
+        if (!_loaded.get(field) && ((_flags & FLAG_INVERSES) != 0
+            && _meta.getField(field).getInverseMetaDatas().length > 0))
             loadField(field, LockLevels.LOCK_NONE, false, false);
 
         // don't bother creating the save field manager if we're not going to

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/FieldMetaData.java
Fri Jan 30 23:06:29 2009
@@ -210,7 +210,6 @@
     // indicate if this field is used by other field as "order by" value 
     private boolean _usedInOrderBy = false;
     private boolean _isElementCollection = false;
-    private FieldMetaData[] _orphanRemoves = null;
 
     /**
      * Constructor.
@@ -982,72 +981,6 @@
     }
 
     /**
-     * Return all orphanRemoval meta data of this field.
-     */
-    public FieldMetaData[] getOrphanRemovalMetaDatas() {
-        if (_orphanRemoves == null) {
-            // get the metadata for the type on the other side of this relation
-            ClassMetaData meta = null;
-            switch (getTypeCode()) {
-            case JavaTypes.PC:
-                meta = getTypeMetaData();
-                break;
-            case JavaTypes.ARRAY:
-            case JavaTypes.COLLECTION:
-            case JavaTypes.MAP:
-                meta = _elem.getTypeMetaData();
-                break;
-            }
-            Collection orphanRemoves = null;
-            if (meta != null) {
-                // scan rel type for fields that name this field as an inverse
-                FieldMetaData[] fields = meta.getFields();
-                Class type = getOwnerType();
-                //Class type = getDeclaringMetaData().getDescribedType();
-                for (int i = 0; i < fields.length; i++) {
-                    // skip fields that aren't compatible with our owning class
-                    switch (fields[i].getTypeCode()) {
-                    case JavaTypes.PC:
-                        if (!type.isAssignableFrom(fields[i].getType()))
-                            continue;
-                        break;
-                    case JavaTypes.COLLECTION:
-                    case JavaTypes.ARRAY:
-                        if (!type.isAssignableFrom(fields[i].
-                                getElement().getType()))
-                            continue;
-                        break;
-                    default:
-                        continue;
-                    }
-
-                    if (orphanRemoves == null)
-                        orphanRemoves = new ArrayList(3);
-                    if (!orphanRemoves.contains(fields[i]))
-                        orphanRemoves.add(fields[i]);
-                }
-            }
-
-            MetaDataRepository repos = getRepository();
-            if (orphanRemoves == null)
-                _orphanRemoves = repos.EMPTY_FIELDS;
-            else
-                _orphanRemoves = (FieldMetaData[]) orphanRemoves.toArray
-                (repos.newFieldMetaDataArray(orphanRemoves.size()));
-        }
-        return _orphanRemoves;
-    }
-    
-    public Class getOwnerType() {
-        ClassMetaData owner = getDefiningMetaData(); 
-        ValueMetaData vm = owner.getEmbeddingMetaData();
-        if (vm == null)
-            return owner.getDescribedType();
-        FieldMetaData fmd = vm.getFieldMetaData();
-        return fmd.getOwnerType();
-    }
-    
-    /**
      * The strategy to use for insert value generation.
      * One of the constants from {@link ValueStrategies}.
      */
@@ -2065,14 +1998,6 @@
     public void setCascadeDelete(int delete) {
         _val.setCascadeDelete(delete);
     }
-    
-    public boolean getOrphanRemoval() {
-        return _val.getOrphanRemoval();
-    }
-    
-    public void setOrphanRemoval(boolean orphanRemoval) {
-        _val.setOrphanRemoval(orphanRemoval);
-    }
 
     public int getCascadePersist() {
         return _val.getCascadePersist();

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaData.java
Fri Jan 30 23:06:29 2009
@@ -302,14 +302,4 @@
      * information.
      */
     public void copy(ValueMetaData vmd);
-    
-    /**
-     * Whether this value is subject to orphanRemoval.
-     */
-    public void setOrphanRemoval(boolean orphanRemoval);
-    
-    /**
-     * Whether this value is subject to orphanRemoval.
-     */
-    public boolean getOrphanRemoval();
 }

Modified: openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
(original)
+++ openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/meta/ValueMetaDataImpl.java
Fri Jan 30 23:06:29 2009
@@ -57,7 +57,6 @@
     private int _resMode = MODE_NONE;
     private String _mappedBy = null;
     private FieldMetaData _mappedByMeta = null;
-    private boolean _orphanRemoval = false;
 
     protected ValueMetaDataImpl(FieldMetaData owner) {
         _owner = owner;
@@ -228,14 +227,6 @@
         _delete = delete;
     }
 
-    public boolean getOrphanRemoval() {
-        return _orphanRemoval;
-    }
-
-    public void setOrphanRemoval(boolean orphanRemoval) {
-        _orphanRemoval = orphanRemoval;
-    }
-
     public int getCascadePersist() {
         if (_owner.getManagement() != FieldMetaData.MANAGE_PERSISTENT)
             return CASCADE_NONE;

Modified: openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
URL: http://svn.apache.org/viewvc/openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java?rev=739448&r1=739447&r2=739448&view=diff
==============================================================================
--- openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
(original)
+++ openjpa/trunk/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
Fri Jan 30 23:06:29 2009
@@ -1566,9 +1566,8 @@
         }
     }
     private void setOrphanRemoval(ValueMetaData vmd, boolean orphanRemoval) {
-        vmd.setOrphanRemoval(orphanRemoval);
-        if (orphanRemoval)
-            setCascades(vmd, new CascadeType[] {CascadeType.REMOVE});
+        if (orphanRemoval) 
+            vmd.setCascadeDelete(ValueMetaData.CASCADE_AUTO);
     }
 
     /**



Mime
View raw message