You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by aa...@apache.org on 2012/04/26 20:06:59 UTC

svn commit: r1331002 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/ framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/ framework/cay...

Author: aadamchik
Date: Thu Apr 26 18:06:58 2012
New Revision: 1331002

URL: http://svn.apache.org/viewvc?rev=1331002&view=rev
Log:
CAY-1698 ObjectIdRelationship support for AuditableChild

better documentation for the available annotation options;
making 'value' optional;
removing dependency on commons-lang... Unfortunately it indirectly imported via Velocity,
but trying to keep the core code free from this dep

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableChild.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableFilter.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationship.java
    cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/AuditableChildUuid.java

Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=1331002&r1=1331001&r2=1331002&view=diff
==============================================================================
--- cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt Thu Apr 26 18:06:58 2012
@@ -54,6 +54,7 @@ CAY-1684 Upgrade commons-collections dep
 CAY-1686 StringIdQuery - a query providing an optimized fetch for objects based on 1..N String IDs. 
 CAY-1688 [PATCH] rename DataDomain.getNode to getDataNode
 CAY-1693 Initial support for bitwise operators in Expression and SelectQuery - MySQL
+CAY-1698 ObjectIdRelationship support for AuditableChild
 
 Bug Fixes Since 3.1M3:
 

Modified: cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableChild.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableChild.java?rev=1331002&r1=1331001&r2=1331002&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableChild.java (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableChild.java Thu Apr 26 18:06:58 2012
@@ -28,7 +28,9 @@ import java.lang.annotation.Target;
 /**
  * A built-in annotation used to tag an object that is not auditable on its own, but whose
  * changes should be tracked together with changes of another ("parent") object. This
- * annotation allows to group changes in a closely related subtree of objects.
+ * annotation allows to group changes in a closely related subtree of objects. Either
+ * {@link #value()} or {@link #objectIdRelationship()} must be set to a non-empty String,
+ * so that a processor of AuditableChild could find the parent of the annotated object.
  * 
  * @since 3.1
  */
@@ -42,9 +44,13 @@ public @interface AuditableChild {
      * Returns the name of a to-one relationship from an annotated object to the "parent"
      * object that should be audited when annotated object is changed.
      */
-    String value();
-    
-    String[] ignoredProperties() default {};
+    String value() default "";
 
+    /**
+     * Returns the name of the property of the annotated entity of the relationship that
+     * stores a String "FK" of a related "parent" entity.
+     */
     String objectIdRelationship() default "";
+
+    String[] ignoredProperties() default {};
 }

Modified: cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableFilter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableFilter.java?rev=1331002&r1=1331001&r2=1331002&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableFilter.java (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/audit/AuditableFilter.java Thu Apr 26 18:06:58 2012
@@ -36,7 +36,6 @@ import org.apache.cayenne.lifecycle.chan
 import org.apache.cayenne.map.EntityResolver;
 import org.apache.cayenne.map.ObjEntity;
 import org.apache.cayenne.query.Query;
-import org.apache.commons.lang.StringUtils;
 
 /**
  * A {@link DataChannelFilter} that enables audit of entities annotated with
@@ -183,17 +182,23 @@ public class AuditableFilter implements 
             throw new IllegalArgumentException("No 'AuditableChild' annotation found");
         }
 
-        String propertyPath = StringUtils.isNotEmpty(annotation.value())
-                              ? annotation.value()
+        String propertyPath = annotation.value();
+
+        if (propertyPath == null || propertyPath.equals("")) {
+            propertyPath = objectIdRelationshipName(annotation.objectIdRelationship());
+        }
+
+        if (propertyPath == null || propertyPath.equals("")) {
+            throw new IllegalStateException(
+                    "Either 'value' or 'objectIdRelationship' of @AuditableChild must be set");
+        }
 
-                              : objectIdRelationshipName(annotation.objectIdRelationship());
         return dataObject.readNestedProperty(propertyPath);
     }
 
-    /**
-     * It's a temporary clone method of  {@link org.apache.cayenne.lifecycle.relationship.ObjectIdRelationshipHandler#objectIdRelationshipName(String)}
-     * //todo Needs to be encapsulated to some separate class to avoid a code duplication
-     */
+    // TODO: It's a temporary clone method of {@link
+    // org.apache.cayenne.lifecycle.relationship.ObjectIdRelationshipHandler#objectIdRelationshipName(String)}.
+    // Needs to be encapsulated to some separate class to avoid a code duplication
     private String objectIdRelationshipName(String uuidPropertyName) {
         return "cay:related:" + uuidPropertyName;
     }

Modified: cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationship.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationship.java?rev=1331002&r1=1331001&r2=1331002&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationship.java (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/main/java/org/apache/cayenne/lifecycle/relationship/ObjectIdRelationship.java Thu Apr 26 18:06:58 2012
@@ -26,9 +26,9 @@ import java.lang.annotation.RetentionPol
 import java.lang.annotation.Target;
 
 /**
- * Defines a "virtual" read-only to-one relationship based on an FK that is a character
+ * Defines a "virtual" read-only to-one relationship based on an FK that is a String
  * representation of Cayenne ObjectId. A target object of this relationship can be of any
- * entity type. 
+ * entity type.
  * 
  * @since 3.1
  */
@@ -41,8 +41,8 @@ import java.lang.annotation.Target;
 public @interface ObjectIdRelationship {
 
     /**
-     * Returns the name of the property of the source entity of the relationship that
-     * stores a UUID "FK" of a related entity.
+     * Returns the name of the property of the annotated entity that stores a String "FK"
+     * of a related entity.
      */
     String value() default "";
 }

Modified: cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/AuditableChildUuid.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/AuditableChildUuid.java?rev=1331002&r1=1331001&r2=1331002&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/AuditableChildUuid.java (original)
+++ cayenne/main/trunk/framework/cayenne-lifecycle/src/test/java/org/apache/cayenne/lifecycle/db/AuditableChildUuid.java Thu Apr 26 18:06:58 2012
@@ -5,6 +5,6 @@ import org.apache.cayenne.lifecycle.db.a
 import org.apache.cayenne.lifecycle.relationship.ObjectIdRelationship;
 
 @ObjectIdRelationship(_AuditableChildUuid.UUID_PROPERTY)
-@AuditableChild(value = "", objectIdRelationship = _AuditableChildUuid.UUID_PROPERTY)
+@AuditableChild(objectIdRelationship = _AuditableChildUuid.UUID_PROPERTY)
 public class AuditableChildUuid extends _AuditableChildUuid {
 }