cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mgen...@apache.org
Subject svn commit: r1090391 - in /cayenne/main/trunk: docs/doc/src/main/resources/ framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/
Date Fri, 08 Apr 2011 18:31:12 GMT
Author: mgentry
Date: Fri Apr  8 18:31:11 2011
New Revision: 1090391

URL: http://svn.apache.org/viewvc?rev=1090391&view=rev
Log:
CAY-1556: Add path construction feature to make constructing paths from constants easier for
queries and orderings.

Modified:
    cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/Cayenne.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.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=1090391&r1=1090390&r2=1090391&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 Fri Apr  8 18:31:11 2011
@@ -13,6 +13,7 @@ Date: 
 ----------------------------------
 Changes/New Features Since 3.1M2:
 
+CAY-1556 Add path construction feature to make constructing paths from constants easier for
queries and orderings
 CAY-1525 CharType: don't trim spaces on the left
 CAY-1544 Remove jdk1.6 module from Cayenne sources
 CAY-1545 cayenne-lifecycle Referenceable handler refactoring

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/Cayenne.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/Cayenne.java?rev=1090391&r1=1090390&r2=1090391&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/Cayenne.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/Cayenne.java
Fri Apr  8 18:31:11 2011
@@ -43,7 +43,7 @@ import org.apache.cayenne.reflect.Proper
  * via this class (or other such Cayenne API) is not a clean design practice in many
  * cases, and sometimes may actually lead to security issues. </i>
  * </p>
- * 
+ *
  * @since 3.1 its predecessor was called DataObjectUtils
  */
 public final class Cayenne {
@@ -83,7 +83,7 @@ public final class Cayenne {
 
     /**
      * Returns property descriptor for specified property.
-     * 
+     *
      * @param properyName path to the property
      * @return property descriptor, <code>null</code> if not found
      */
@@ -233,6 +233,34 @@ public final class Cayenne {
     }
 
     /**
+     * Constructs a dotted path from a list of strings.  Useful for creating
+     * more complex paths while preserving compilation safety.  For example,
+     * instead of saying:
+     * <p>
+     * <pre>orderings.add(new Ordering("department.name", SortOrder.ASCENDING));</pre>
+     * <p>
+     * You can use makePath() with the constants generated by Cayenne Modeler:
+     * <p>
+     * <pre>orderings.add(new Ordering(Cayenne.makePath(USER.DEPARTMENT_PROPERTY, Department.NAME_PROPERTY),
SortOrder.ASCENDING));</pre>
+     * <p>
+     * @param pathParts The varargs list of paths to join.
+     * @return A string of all the paths joined by a "." (used by Cayenne in queries and
orderings).
+     * <p>
+     * @since 3.1
+     */
+    public static String makePath(String...pathParts) {
+        StringBuilder builder   = new StringBuilder();
+        String        separator = "";
+
+        for (String path : pathParts) {
+            builder.append(separator).append(path);
+            separator = ".";
+        }
+
+        return builder.toString();
+    }
+
+    /**
      * Returns an int primary key value for a persistent object. Only works for single
      * column numeric primary keys. If an object is transient or has an ObjectId that can
      * not be converted to an int PK, an exception is thrown.
@@ -326,7 +354,7 @@ public final class Cayenne {
      * If this object is already cached in the ObjectStore, it is returned without a
      * query. Otherwise a query is built and executed against the database.
      * </p>
-     * 
+     *
      * @see #objectForPK(ObjectContext, ObjectId)
      */
     public static <T> T objectForPK(
@@ -344,7 +372,7 @@ public final class Cayenne {
      * If this object is already cached in the ObjectStore, it is returned without a
      * query. Otherwise a query is built and executed against the database.
      * </p>
-     * 
+     *
      * @see #objectForPK(ObjectContext, ObjectId)
      */
     public static <T> T objectForPK(
@@ -362,7 +390,7 @@ public final class Cayenne {
      * If this object is already cached in the ObjectStore, it is returned without a
      * query. Otherwise a query is built and executed against the database.
      * </p>
-     * 
+     *
      * @see #objectForPK(ObjectContext, ObjectId)
      */
     public static <T> T objectForPK(
@@ -386,7 +414,7 @@ public final class Cayenne {
      * If this object is already cached in the ObjectStore, it is returned without a
      * query. Otherwise a query is built and executed against the database.
      * </p>
-     * 
+     *
      * @see #objectForPK(ObjectContext, ObjectId)
      */
     public static Object objectForPK(ObjectContext context, String objEntityName, int pk)
{
@@ -400,7 +428,7 @@ public final class Cayenne {
      * If this object is already cached in the ObjectStore, it is returned without a
      * query. Otherwise a query is built and executed against the database.
      * </p>
-     * 
+     *
      * @see #objectForPK(ObjectContext, ObjectId)
      */
     public static Object objectForPK(
@@ -417,7 +445,7 @@ public final class Cayenne {
      * If this object is already cached in the ObjectStore, it is returned without a
      * query. Otherwise a query is built and executed against the database.
      * </p>
-     * 
+     *
      * @see #objectForPK(ObjectContext, ObjectId)
      */
     public static Object objectForPK(
@@ -435,7 +463,7 @@ public final class Cayenne {
      * Returns an object matching ObjectId. If this object is already cached in the
      * ObjectStore, it is returned without a query. Otherwise a query is built and
      * executed against the database.
-     * 
+     *
      * @return A persistent object that matched the id, null if no matching objects were
      *         found
      * @throws CayenneRuntimeException if more than one object matched ObjectId.

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java?rev=1090391&r1=1090390&r2=1090391&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/CayenneDataObject.java
Fri Apr  8 18:31:11 2011
@@ -107,7 +107,7 @@ public class CayenneDataObject extends P
      * <br>
      * </li>
      * </ul>
-     * 
+     *
      * @since 1.0.5
      */
     public Object readNestedProperty(String path) {
@@ -298,7 +298,7 @@ public class CayenneDataObject extends P
      * by reachability" logic, pulling one of the two objects to a DataConext of another
      * object in case one of the objects is transient. If both objects are persistent, and
      * they don't have the same DataContext, CayenneRuntimeException is thrown.
-     * 
+     *
      * @since 1.2
      */
     protected void willConnect(String relationshipName, Persistent object) {
@@ -323,7 +323,7 @@ public class CayenneDataObject extends P
 
     /**
      * Initializes reverse relationship from object <code>val</code> to this
object.
-     * 
+     *
      * @param relName name of relationship from this object to <code>val</code>.
      */
     protected void setReverseRelationship(String relName, DataObject val) {
@@ -463,7 +463,7 @@ public class CayenneDataObject extends P
 
     /**
      * Returns a version of a DataRow snapshot that was used to create this object.
-     * 
+     *
      * @since 1.1
      */
     public long getSnapshotVersion() {
@@ -478,12 +478,24 @@ public class CayenneDataObject extends P
     }
 
     /**
+     * Convenience method to invoke {@link Cayenne#makePath(String...)} from
+     * within a DataObject subclass to create a dotted path using the generated
+     * string constants for attributes and relationships.
+     *
+     * @see Cayenne#makePath(String...)
+     * @since 3.1
+     */
+    public String makePath(String...pathParts) {
+        return Cayenne.makePath(pathParts);
+    }
+
+    /**
      * Performs property validation of the object, appending any validation failures to
      * the provided validationResult object. This method is invoked from "validateFor.."
      * before committing a NEW or MODIFIED object to the database. Validation includes
      * checking for null values and value sizes. CayenneDataObject subclasses may override
      * this method, calling super.
-     * 
+     *
      * @since 1.1
      */
     protected void validateForSave(ValidationResult validationResult) {
@@ -645,7 +657,7 @@ public class CayenneDataObject extends P
      * Calls {@link #validateForSave(ValidationResult)}. CayenneDataObject subclasses may
      * override it providing validation logic that should be executed for the newly
      * created objects before saving them.
-     * 
+     *
      * @since 1.1
      */
     public void validateForInsert(ValidationResult validationResult) {
@@ -656,7 +668,7 @@ public class CayenneDataObject extends P
      * Calls {@link #validateForSave(ValidationResult)}. CayenneDataObject subclasses may
      * override it providing validation logic that should be executed for the modified
      * objects before saving them.
-     * 
+     *
      * @since 1.1
      */
     public void validateForUpdate(ValidationResult validationResult) {
@@ -667,7 +679,7 @@ public class CayenneDataObject extends P
      * This implementation does nothing. CayenneDataObject subclasses may override it
      * providing validation logic that should be executed for the deleted objects before
      * committing them.
-     * 
+     *
      * @since 1.1
      */
     public void validateForDelete(ValidationResult validationResult) {
@@ -676,7 +688,7 @@ public class CayenneDataObject extends P
 
     /**
      * Encodes object to XML using provided encoder.
-     * 
+     *
      * @since 1.2
      * @deprecated since 3.1 XML serialization package is deprecated and will be removed
      *             in the following releases. It has a number of functional and
@@ -685,6 +697,7 @@ public class CayenneDataObject extends P
      *             recommend the users to implement XML serialization of persistent
      *             objects based JAXB, XStream or other similar frameworks.
      */
+    @Deprecated
     public void encodeAsXML(XMLEncoder encoder) {
         EntityResolver er = getObjectContext().getEntityResolver();
         ObjEntity objectEntity = er.lookupObjEntity(getClass());
@@ -706,6 +719,7 @@ public class CayenneDataObject extends P
      *             recommend the users to implement XML serialization of persistent
      *             objects based JAXB, XStream or other similar frameworks.
      */
+    @Deprecated
     public void decodeFromXML(XMLDecoder decoder) {
 
         Injector injector = CayenneRuntime.getThreadInjector();



Mime
View raw message