Author: aadamchik
Date: Fri Apr 9 16:40:04 2010
New Revision: 932498
URL: http://svn.apache.org/viewvc?rev=932498&view=rev
Log:
CAY-1402 Ability to use Terminating "@size" in Nested Properties Against Collections
patch by Andrew Lindesay
Modified:
cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
Modified: cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt?rev=932498&r1=932497&r2=932498&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt (original)
+++ cayenne/main/branches/STABLE-3.0/docs/doc/src/main/resources/RELEASE-NOTES.txt Fri Apr
9 16:40:04 2010
@@ -15,6 +15,7 @@ Date:
Bug Fixes Since 3.0-final:
CAY-1354 Wrong Types mapping for selected values in Row Queries
+CAY-1402 Ability to use Terminating "@size" in Nested Properties Against Collections
CAY-1416 ExpressionFactory.noMatchExp.toEJBQL() produces incorrect output
CAY-1417 EJBQL doesn't support null numeric parameters
Modified: cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
URL: http://svn.apache.org/viewvc/cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java?rev=932498&r1=932497&r2=932498&view=diff
==============================================================================
--- cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
(original)
+++ cayenne/main/branches/STABLE-3.0/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
Fri Apr 9 16:40:04 2010
@@ -57,6 +57,15 @@ import org.apache.cayenne.xml.XMLSeriali
*/
public class CayenneDataObject extends PersistentObject implements DataObject, Validating,
XMLSerializable {
+ /**
+ * A special property denoting a size of the to-many collection, when encountered at
+ * the end of the path. This will not be replicated in 3.1 as it has been added to
+ * the Cayenne utilities class.
+ *
+ * @since 3.0.1
+ */
+ final static String PROPERTY_COLLECTION_SIZE = "@size";
+
protected long snapshotVersion = DEFAULT_VERSION;
protected Map<String, Object> values = new HashMap<String, Object>();
@@ -126,6 +135,20 @@ public class CayenneDataObject extends P
tokenIndex);
}
else if (property instanceof Collection) {
+
+ // CAY-1402
+ // This is back-ported from 3.1's trunk and from the Cayenne utility
+ // object. This will allow people to put @size at the end of a property
+ // path and be able to find out the size of a relationship.
+
+ Collection<?> collection = (Collection) property;
+
+ if (tokenIndex < tokenizedPath.length - 1) {
+ if (tokenizedPath[tokenIndex + 1].equals(PROPERTY_COLLECTION_SIZE)) {
+ return collection.size();
+ }
+ }
+
/**
* Support for collection property in the middle of the path
*/
|