cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r471553 - in /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src: main/java/org/apache/cayenne/property/ test/java/org/apache/cayenne/property/
Date Sun, 05 Nov 2006 22:48:27 GMT
Author: aadamchik
Date: Sun Nov  5 14:48:26 2006
New Revision: 471553

URL: http://svn.apache.org/viewvc?view=rev&rev=471553
Log:
CAY-701: property" package refactoring
(changing property visitor to take AttributeProperty instead of just Property; renamed SimpleProperty
to BaseProperty; got rid of Property.shallowMerge method)

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/MockAccessor.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/AbstractCollectionProperty.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseClassDescriptor.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseProperty.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/PersistentObjectProperty.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/Property.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/ValueHolderProperty.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BaseClassDescriptorTst.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BasePropertyTst.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/AbstractCollectionProperty.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/AbstractCollectionProperty.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/AbstractCollectionProperty.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/AbstractCollectionProperty.java
Sun Nov  5 14:48:26 2006
@@ -34,8 +34,7 @@
         implements CollectionProperty {
 
     public AbstractCollectionProperty(ClassDescriptor owner,
-            ClassDescriptor targetDescriptor, Accessor accessor,
-            String reverseName) {
+            ClassDescriptor targetDescriptor, Accessor accessor, String reverseName) {
         super(owner, targetDescriptor, accessor, reverseName);
     }
 
@@ -98,10 +97,6 @@
 
     public boolean visit(PropertyVisitor visitor) {
         return visitor.visitCollectionArc(this);
-    }
-
-    public void shallowMerge(Object from, Object to) throws PropertyAccessException {
-        // noop
     }
 
     /**

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseClassDescriptor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseClassDescriptor.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseClassDescriptor.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseClassDescriptor.java
Sun Nov  5 14:48:26 2006
@@ -188,18 +188,28 @@
      * Copies object properties from one object to another. Invokes 'shallowCopy' of a
      * super descriptor and then invokes 'shallowCopy' of each declared property.
      */
-    public void shallowMerge(Object from, Object to) throws PropertyAccessException {
+    public void shallowMerge(final Object from, final Object to)
+            throws PropertyAccessException {
 
-        // do super first
-        if (getSuperclassDescriptor() != null) {
-            getSuperclassDescriptor().shallowMerge(from, to);
-        }
+        visitProperties(new PropertyVisitor() {
 
-        Iterator it = declaredProperties.values().iterator();
-        while (it.hasNext()) {
-            Property property = (Property) it.next();
-            property.shallowMerge(from, to);
-        }
+            public boolean visitAttributeProperty(AttributeProperty property) {
+                property.writePropertyDirectly(
+                        to,
+                        property.readPropertyDirectly(to),
+                        property.readPropertyDirectly(from));
+                return true;
+            }
+
+            public boolean visitSingleObjectArc(SingleObjectArcProperty property) {
+                property.invalidate(to);
+                return true;
+            }
+
+            public boolean visitCollectionArc(CollectionProperty property) {
+                return true;
+            }
+        });
     }
 
     public boolean visitProperties(PropertyVisitor visitor) {

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseProperty.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseProperty.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseProperty.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/BaseProperty.java
Sun Nov  5 14:48:26 2006
@@ -67,10 +67,6 @@
         // noop
     }
 
-    public void shallowMerge(Object from, Object to) throws PropertyAccessException {
-        writePropertyDirectly(to, accessor.getValue(to), accessor.getValue(from));
-    }
-
     public Object readPropertyDirectly(Object object) throws PropertyAccessException {
         return accessor.getValue(object);
     }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/PersistentObjectProperty.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/PersistentObjectProperty.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/PersistentObjectProperty.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/PersistentObjectProperty.java
Sun Nov  5 14:48:26 2006
@@ -31,8 +31,7 @@
 public class PersistentObjectProperty extends AbstractSingleObjectArcProperty {
 
     public PersistentObjectProperty(ClassDescriptor owner,
-            ClassDescriptor targetDescriptor, Accessor accessor,
-            String reverseName) {
+            ClassDescriptor targetDescriptor, Accessor accessor, String reverseName) {
         super(owner, targetDescriptor, accessor, reverseName);
     }
 
@@ -40,11 +39,11 @@
         Object target = accessor.getValue(object);
         return target instanceof Fault;
     }
-    
+
     public void invalidate(Object object) {
         Object target = accessor.getValue(object);
-        
-        if(!(target instanceof Fault)) {
+
+        if (!(target instanceof Fault)) {
             accessor.setValue(object, Fault.getToOneFault());
         }
     }
@@ -60,22 +59,5 @@
         }
 
         return value;
-    }
-
-    /**
-     * Copies a property value that is itself a persistent object from one object to
-     * another. If the new value is fault, fault will be copied to the target.
-     */
-    public void shallowMerge(Object from, Object to) throws PropertyAccessException {
-
-        Object fromValue = accessor.getValue(from);
-
-        if (fromValue == null) {
-            writePropertyDirectly(to, accessor.getValue(to), null);
-        }
-        else {
-            writePropertyDirectly(to, accessor.getValue(to), Fault
-                    .getToOneFault());
-        }
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/Property.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/Property.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/Property.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/Property.java
Sun Nov  5 14:48:26 2006
@@ -73,9 +73,4 @@
      * set yet.
      */
     void injectValueHolder(Object object) throws PropertyAccessException;
-
-    /**
-     * Copies a property value from one object to another.
-     */
-    void shallowMerge(Object from, Object to) throws PropertyAccessException;
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/ValueHolderProperty.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/ValueHolderProperty.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/ValueHolderProperty.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/property/ValueHolderProperty.java
Sun Nov  5 14:48:26 2006
@@ -82,10 +82,6 @@
         ensureValueHolderSet(object).setValueDirectly(newValue);
     }
 
-    public void shallowMerge(Object from, Object to) throws PropertyAccessException {
-        // noop
-    }
-
     /**
      * Injects a ValueHolder in the object if it hasn't been done yet.
      */

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BaseClassDescriptorTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BaseClassDescriptorTst.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BaseClassDescriptorTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BaseClassDescriptorTst.java
Sun Nov  5 14:48:26 2006
@@ -28,6 +28,7 @@
 
     public void testConstructor() {
         BaseClassDescriptor d1 = new BaseClassDescriptor(null) {
+
             public ObjEntity getEntity() {
                 return null;
             }
@@ -35,6 +36,7 @@
         assertNull(d1.getSuperclassDescriptor());
 
         BaseClassDescriptor d2 = new BaseClassDescriptor(d1) {
+
             public ObjEntity getEntity() {
                 return null;
             }
@@ -45,6 +47,7 @@
 
     public void testValid() { // by default BaseClassDescriptor is not compiled...
         BaseClassDescriptor d1 = new BaseClassDescriptor(null) {
+
             public ObjEntity getEntity() {
                 return null;
             }
@@ -56,10 +59,9 @@
 
     public void testCopyObjectProperties() {
         BaseClassDescriptor d1 = new MockBaseClassDescriptor();
-        
+
         FieldAccessor accessor = new FieldAccessor(TestBean.class, "string", String.class);
-        BaseProperty property = new MockBaseProperty(d1, accessor);
-       
+        Property property = new SimpleAttributeProperty(d1, accessor, null);
 
         d1.declaredProperties.put(property.getName(), property);
 

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BasePropertyTst.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BasePropertyTst.java?view=diff&rev=471553&r1=471552&r2=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BasePropertyTst.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/BasePropertyTst.java
Sun Nov  5 14:48:26 2006
@@ -18,30 +18,20 @@
  ****************************************************************/
 package org.apache.cayenne.property;
 
-import org.apache.cayenne.unit.util.TestBean;
-
 import junit.framework.TestCase;
 
 public class BasePropertyTst extends TestCase {
 
-    public void testShallowMerge() {
-        ClassDescriptor d = new MockClassDescriptor();
-        BaseProperty property = new BaseProperty(d, new FieldAccessor(
-                TestBean.class,
-                "string",
-                String.class)) {
-
-            public boolean visit(PropertyVisitor visitor) {
-                return false;
-            }
-        };
-
-        TestBean from = new TestBean();
-        from.setString("123");
-
-        TestBean to = new TestBean();
+    public void testGetName() {
+        BaseProperty p = new MockBaseProperty(
+                new MockClassDescriptor(),
+                new MockAccessor() {
+
+                    public String getName() {
+                        return "xyz";
+                    }
+                });
 
-        property.shallowMerge(from, to);
-        assertEquals("123", to.getString());
+        assertEquals("xyz", p.getName());
     }
 }

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/MockAccessor.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/MockAccessor.java?view=auto&rev=471553
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/MockAccessor.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/test/java/org/apache/cayenne/property/MockAccessor.java
Sun Nov  5 14:48:26 2006
@@ -0,0 +1,33 @@
+/*****************************************************************
+ *   Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ ****************************************************************/
+package org.apache.cayenne.property;
+
+public class MockAccessor implements Accessor {
+
+    public String getName() {
+        return null;
+    }
+
+    public Object getValue(Object object) throws PropertyAccessException {
+        return null;
+    }
+
+    public void setValue(Object object, Object newValue) throws PropertyAccessException {
+    }
+}



Mime
View raw message