cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r479180 - /incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/
Date Sat, 25 Nov 2006 19:55:48 GMT
Author: aadamchik
Date: Sat Nov 25 11:55:48 2006
New Revision: 479180

URL: http://svn.apache.org/viewvc?view=rev&rev=479180
Log:
refactoring enhanced POJO property handlers, extracting fault handling in a helper class

Added:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java
Modified:
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToManyProperty.java
    incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToOneProperty.java

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java?view=diff&rev=479180&r1=479179&r2=479180
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoDescriptorFactory.java
Sat Nov 25 11:55:48 2006
@@ -26,7 +26,6 @@
 import org.apache.cayenne.reflect.ClassDescriptor;
 import org.apache.cayenne.reflect.ClassDescriptorFactory;
 import org.apache.cayenne.reflect.ClassDescriptorMap;
-import org.apache.cayenne.reflect.FieldAccessor;
 import org.apache.cayenne.reflect.PersistentDescriptor;
 import org.apache.cayenne.reflect.PersistentDescriptorFactory;
 
@@ -38,7 +37,6 @@
  */
 public class EnhancedPojoDescriptorFactory extends PersistentDescriptorFactory {
 
-    static final String FAULT_FIELD_PREFIX = "$cay_faultResolved_";
     static final String PERSISTENCE_STATE_FIELD = "$cay_persistenceState";
 
     public EnhancedPojoDescriptorFactory(ClassDescriptorMap descriptorMap) {
@@ -67,16 +65,12 @@
                 .getTargetEntityName());
         String reverseName = relationship.getReverseRelationshipName();
 
-        Accessor faultFlagAccessor = createFaultFlagAccessor(descriptor, relationship
-                .getName());
-
         Accessor accessor = createAccessor(descriptor, relationship.getName(), List.class);
         descriptor.addDeclaredProperty(new EnhancedPojoToManyProperty(
                 descriptor,
                 targetDescriptor,
                 accessor,
-                reverseName,
-                faultFlagAccessor));
+                reverseName));
     }
 
     protected void createToOneProperty(
@@ -87,9 +81,6 @@
                 .getTargetEntityName());
         String reverseName = relationship.getReverseRelationshipName();
 
-        Accessor faultFlagAccessor = createFaultFlagAccessor(descriptor, relationship
-                .getName());
-
         Accessor accessor = createAccessor(
                 descriptor,
                 relationship.getName(),
@@ -98,12 +89,6 @@
                 descriptor,
                 targetDescriptor,
                 accessor,
-                reverseName,
-                faultFlagAccessor));
-    }
-
-    Accessor createFaultFlagAccessor(PersistentDescriptor descriptor, String propertyName)
{
-        return new FieldAccessor(descriptor.getObjectClass(), FAULT_FIELD_PREFIX
-                + propertyName, Boolean.TYPE);
+                reverseName));
     }
 }

Added: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java?view=auto&rev=479180
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java
(added)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoPropertyFaultHandler.java
Sat Nov 25 11:55:48 2006
@@ -0,0 +1,52 @@
+/*****************************************************************
+ *   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.reflect.pojo;
+
+import org.apache.cayenne.reflect.Accessor;
+import org.apache.cayenne.reflect.FieldAccessor;
+
+/**
+ * Handles property fault resolving.
+ * 
+ * @since 3.0
+ * @author Andrus Adamchik
+ */
+class EnhancedPojoPropertyFaultHandler {
+
+    static final String FAULT_FIELD_PREFIX = "$cay_faultResolved_";
+
+    private Accessor faultResolvedFlagAccessor;
+
+    EnhancedPojoPropertyFaultHandler(Class objectClass, String propertyName) {
+        this.faultResolvedFlagAccessor = new FieldAccessor(
+                objectClass,
+                FAULT_FIELD_PREFIX + propertyName,
+                Boolean.TYPE);
+    }
+
+    boolean isFaultProperty(Object object) {
+        return !((Boolean) faultResolvedFlagAccessor.getValue(object)).booleanValue();
+    }
+
+    void setFaultProperty(Object object, boolean flag) {
+        // note that we need to negate "fault" property value to get "fault resolved"
+        // value stored in the object.
+        faultResolvedFlagAccessor.setValue(object, flag ? Boolean.FALSE : Boolean.TRUE);
+    }
+}

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToManyProperty.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToManyProperty.java?view=diff&rev=479180&r1=479179&r2=479180
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToManyProperty.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToManyProperty.java
Sat Nov 25 11:55:48 2006
@@ -28,15 +28,21 @@
  */
 class EnhancedPojoToManyProperty extends ListProperty {
 
-    private Accessor faultResolvedFlagAccessor;
+    private EnhancedPojoPropertyFaultHandler faultHandler;
 
     EnhancedPojoToManyProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
-            Accessor accessor, String reverseName, Accessor faultResolvedFlagAccessor) {
+            Accessor accessor, String reverseName) {
         super(owner, targetDescriptor, accessor, reverseName);
-        this.faultResolvedFlagAccessor = faultResolvedFlagAccessor;
+        this.faultHandler = new EnhancedPojoPropertyFaultHandler(
+                owner.getObjectClass(),
+                getName());
     }
 
     public void invalidate(Object object) {
-        faultResolvedFlagAccessor.setValue(object, Boolean.FALSE);
+        faultHandler.setFaultProperty(object, true);
+    }
+    
+    public boolean isFault(Object object) {
+        return faultHandler.isFaultProperty(object);
     }
 }

Modified: incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToOneProperty.java
URL: http://svn.apache.org/viewvc/incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToOneProperty.java?view=diff&rev=479180&r1=479179&r2=479180
==============================================================================
--- incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToOneProperty.java
(original)
+++ incubator/cayenne/main/trunk/core/cayenne-jdk1.4/src/main/java/org/apache/cayenne/reflect/pojo/EnhancedPojoToOneProperty.java
Sat Nov 25 11:55:48 2006
@@ -35,20 +35,22 @@
  */
 class EnhancedPojoToOneProperty extends BaseToOneProperty {
 
-    protected Accessor faultResolvedFlagAccessor;
+    protected EnhancedPojoPropertyFaultHandler faultHandler;
 
     EnhancedPojoToOneProperty(ClassDescriptor owner, ClassDescriptor targetDescriptor,
-            Accessor accessor, String reverseName, Accessor faultResolvedFlagAccessor) {
+            Accessor accessor, String reverseName) {
         super(owner, targetDescriptor, accessor, reverseName);
-        this.faultResolvedFlagAccessor = faultResolvedFlagAccessor;
+        this.faultHandler = new EnhancedPojoPropertyFaultHandler(
+                owner.getObjectClass(),
+                getName());
     }
 
     public boolean isFault(Object source) {
-        return !((Boolean) faultResolvedFlagAccessor.getValue(source)).booleanValue();
+        return faultHandler.isFaultProperty(source);
     }
 
     public void invalidate(Object object) {
-        faultResolvedFlagAccessor.setValue(object, Boolean.FALSE);
+        faultHandler.setFaultProperty(object, true);
     }
 
     void resolveFault(Object object) {
@@ -57,7 +59,7 @@
                     (Persistent) object,
                     getName());
             writePropertyDirectly(object, null, target);
-            faultResolvedFlagAccessor.setValue(object, Boolean.TRUE);
+            faultHandler.setFaultProperty(object, false);
         }
     }
 



Mime
View raw message