db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arm...@apache.org
Subject svn commit: r504396 - in /db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg: Image.java ObjectEnvelope.java
Date Wed, 07 Feb 2007 01:07:56 GMT
Author: arminw
Date: Tue Feb  6 17:07:56 2007
New Revision: 504396

URL: http://svn.apache.org/viewvc?view=rev&rev=504396
Log:
make object state-detection configurable, fix bug, minor improvements

Modified:
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/Image.java
    db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/Image.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/Image.java?view=diff&rev=504396&r1=504395&r2=504396
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/Image.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/Image.java Tue Feb  6 17:07:56
2007
@@ -48,13 +48,14 @@
 public abstract class Image
 {
     static Logger log = LoggerFactory.getLogger(Image.class);
+
     private long timestamp = System.currentTimeMillis();
 
     private Image()
     {
     }
 
-    boolean illegalImageComparison(Image oldImage)
+    boolean illegalImageComparison(final Image oldImage)
     {
         return timestamp < oldImage.timestamp;
     }
@@ -65,7 +66,7 @@
 
     abstract void referenceProcessing(Image oldImage);
 
-    public void performReferenceDetection(Image oldImage)
+    public void performReferenceDetection(final Image oldImage)
     {
         if(illegalImageComparison(oldImage))
         {
@@ -77,13 +78,13 @@
     //===================================================================
     // inner class
     //===================================================================
-    public static class MultipleRef extends Image implements CollectionProxyListener
+    public static final class MultipleRef extends Image implements CollectionProxyListener
     {
         static final int IS_NORMAL_OBJECT = 11;
         static final int IS_MATERIALIZED_PROXY = 13;
         static final int IS_UNMATERIALIZED_PROXY = 17;
 
-        private ImageListener listener;
+        private final ImageListener listener;
         private final CollectionDescriptor cod;
         private final Object collectionOrArray;
         private Map references;
@@ -91,7 +92,7 @@
         private boolean hasTransientIdentity;
         private boolean isRefreshed;
 
-        public MultipleRef(ImageListener listener, CollectionDescriptor cod, Object collectionOrArray)
+        public MultipleRef(final ImageListener listener, final CollectionDescriptor cod,
final Object collectionOrArray)
         {
             this.listener = listener;
             this.cod = cod;
@@ -135,7 +136,7 @@
             }
         }
 
-        void handleReferencedObjects(Iterator it)
+        void handleReferencedObjects(final Iterator it)
         {
             if(it == null) return;
             references = new HashMap();
@@ -155,7 +156,7 @@
             }
         }
 
-        public void cleanup(boolean reuse)
+        public void cleanup(final boolean reuse)
         {
             if(log.isDebugEnabled()) log.debug("Cleanup collection image, reuse=" + reuse);
             if(reuse)
@@ -175,7 +176,7 @@
             }
         }
 
-        void referenceProcessing(Image oldImage)
+        void referenceProcessing(final Image oldImage)
         {
             MultipleRef oldRefs = (MultipleRef) oldImage;
             if(incommensurableProxies(oldRefs))
@@ -232,7 +233,7 @@
          * E.g. if the user exchange one another the unmaterialized proxy collection objects
of two main objects,
          * then both proxy need to be materialized to assign the changed FK field values.
          */
-        private boolean incommensurableProxies(MultipleRef oldImage)
+        private boolean incommensurableProxies(final MultipleRef oldImage)
         {
             boolean result = false;
             // deleted objects
@@ -276,12 +277,12 @@
          * Always return 'false', because changed 1:n or m:n references do not
          * affect the main object.
          */
-        public boolean modified(Image other)
+        public boolean modified(final Image other)
         {
             return false;
         }
 
-        boolean containsReference(Identity oid)
+        boolean containsReference(final Identity oid)
         {
             if(!isRefreshed) refreshIdentities();
             return references.containsKey(oid);
@@ -306,12 +307,12 @@
 
         // CollectionProxy Listener methods
         //---------------------------------
-        public void beforeLoading(CollectionProxyDefaultImpl colProxy)
+        public void beforeLoading(final CollectionProxyDefaultImpl colProxy)
         {
             //noop
         }
 
-        public void afterLoading(CollectionProxyDefaultImpl colProxy)
+        public void afterLoading(final CollectionProxyDefaultImpl colProxy)
         {
             if(status == IS_UNMATERIALIZED_PROXY)
             {
@@ -331,21 +332,21 @@
     //===================================================================
     // inner class
     //===================================================================
-    public static class SingleRef extends Image
+    public static final class SingleRef extends Image
     {
         private Object referenceObjOrProxy;
         private Identity oid = null;
         private final ImageListener listener;
         private final ObjectReferenceDescriptor ord;
 
-        public SingleRef(ImageListener listener, ObjectReferenceDescriptor ord, Object reference)
+        public SingleRef(final ImageListener listener, final ObjectReferenceDescriptor ord,
final Object reference)
         {
             this.listener = listener;
             this.ord = ord;
             this.referenceObjOrProxy = reference;
         }
 
-        public void cleanup(boolean reuse)
+        public void cleanup(final boolean reuse)
         {
             if(!reuse)
             {
@@ -353,7 +354,7 @@
             }
         }
 
-        void referenceProcessing(Image oldImage)
+        void referenceProcessing(final Image oldImage)
         {
             SingleRef oldRef = (SingleRef) oldImage;
             boolean isSame = getReferenceObjectOrProxy() == oldRef.getReferenceObjectOrProxy();
@@ -407,10 +408,10 @@
          * If a 1:1 reference has changed it will
          * affects the main object (FK needs update).
          */
-        public boolean modified(Image toCompare)
+        public boolean modified(final Image toCompare)
         {
             boolean modified = false;
-            if(!(this == toCompare))
+            if(this != toCompare)
             {
                 if(toCompare instanceof Image.SingleRef)
                 {
@@ -432,35 +433,31 @@
     //===================================================================
     // inner class
     //===================================================================
-    public static class Field extends Image
+    public static final class Field extends Image
     {
         private final FieldType type;
         private final Object value;
 
-        public Field(FieldType type, Object value)
+        public Field(final FieldType type, final Object value)
         {
             this.type = type;
             this.value = value;
         }
 
-        public void cleanup(boolean reuse)
+        public void cleanup(final boolean reuse)
         {
         }
 
-        void referenceProcessing(Image oldImage)
+        void referenceProcessing(final Image oldImage)
         {
             // nothing to do
         }
 
         /** If a field value has changed return 'true'. */
-        public boolean modified(Image other)
+        public boolean modified(final Image other)
         {
             boolean result = false;
-            if(this == other)
-            {
-                result = true;
-            }
-            else
+            if(this != other)
             {
                 if(other instanceof Field)
                 {

Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java?view=diff&rev=504396&r1=504395&r2=504396
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/odmg/ObjectEnvelope.java Tue Feb
 6 17:07:56 2007
@@ -397,7 +397,10 @@
         // register 1:1 references in image
         buildImageForSingleReferences(imageMap, cld);
         // put object values to image map, skip this for new objects
-        if(!isNew) buildImageForFields(imageMap, cld);
+        if(!isNew)
+        {
+            buildImageForFields(imageMap, cld);
+        }
         // register 1:n and m:n references in image
         buildImageForCollectionReferences(imageMap, cld);
         return imageMap;
@@ -440,19 +443,30 @@
 
     private void buildImageForFields(Map imageMap, ClassDescriptor cld)
     {
-        // register all non reference fields of object (with inherited fields)
-        FieldDescriptor[] fieldDescs = cld.getFieldDescriptor(true);
-        for(int i = 0; i < fieldDescs.length; i++)
+        if(cld.isStateDetection() && cld.getRepository().isStateDetection())
         {
-            addFieldImage(imageMap, fieldDescs[i]);
+            // register all non reference fields of object (with inherited fields)
+            FieldDescriptor[] fieldDescs = cld.getFieldDescriptor(true);
+            for(int i = 0; i < fieldDescs.length; i++)
+            {
+                addFieldImage(imageMap, fieldDescs[i]);
+            }
         }
     }
 
     private void addFieldImage(Map imageMap, FieldDescriptor fld)
     {
-        // register copies of all field values
-        Object value = fld.getCopyOfValue(getRealObject());
-        imageMap.put(fld.getPersistentField().getName(), new Image.Field(fld.getJdbcType().getFieldType(),
value));
+        // register copies of all fields, except the fields with
+        // disbaled state detection
+        if(fld.isStateDetection())
+        {
+            Object value = fld.getCopyOfValue(getRealObject());
+            imageMap.put(fld.getPersistentField().getName(), new Image.Field(fld.getJdbcType().getFieldType(),
value));
+        }
+        else
+        {
+            // field indicate that this field shouldn't included in object state detection
+        }
     }
 
     private void buildImageForCollectionReferences(Map imageMap, ClassDescriptor cld)
@@ -859,7 +873,7 @@
                 }
                 else
                 {
-                    // when cascade 'true' we remove all dependent objects, so no need
+                    // if cascade 'true', we remove all dependent objects, so no need
                     // to unlink, else we have to unlink all referenced objects of this
                     // object
                     if(!cascade)



---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message