Author: johnthuss Date: Fri Jul 13 22:37:43 2012 New Revision: 1361426 URL: http://svn.apache.org/viewvc?rev=1361426&view=rev Log: CAY-1724 Add 'Property' class for easier and better Expression creation
Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java Modified: cayenne/main/trunk/docs/doc/src/main/resources/RELEASE-NOTES.txt cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm 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=1361426&r1=1361425&r2=1361426&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 Jul 13 22:37:43 2012 @@ -15,8 +15,11 @@ Changes/New Features: CAY-1717 [PATCH] Implement JDBC compatibility layer methods CAY-1718 Remove everything deprecated in 3.1 +CAY-1724 Add 'Property' class for easier and better Expression creation Bug Fixes: CAY-1721 Writing blobs fails (Oracle) CAY-1725 NullPointerException from call to removeToManyTarget +CAY-1719 Modeler - Obj Attribute Java Type editor won't focus sometimes +CAY-1677 Modeler: text fields discard input unless you press enter Added: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java?rev=1361426&view=auto ============================================================================== --- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java (added) +++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/exp/Property.java Fri Jul 13 22:37:43 2012 @@ -0,0 +1,223 @@ +package org.apache.cayenne.exp; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.cayenne.exp.Expression; +import org.apache.cayenne.exp.ExpressionFactory; +import org.apache.cayenne.query.Ordering; +import org.apache.cayenne.query.SortOrder; + +/** + * <p>A property in a DataObject.</p> + * + * <p>Used to construct Expressions quickly and with type-safety, + * and to construct Orderings</p> + * + * <p>Instances of this class are immutable</p> + * + * @param <E> The type this property returns. + */ +public class Property<E> { + + /** + * Name of the property in the object + */ + private final String name; + + /** + * Constructs a new property with the given name. + */ + public Property(String name) { + this.name = name; + } + + /** + * @return Name of the property in the object. + */ + public String getName() { + return name; + } + + /** + * @return Constructs a property path by appending the argument to + * the existing property separated by a dot + */ + public Property<Object> dot(String property) { + return new Property<Object>(getName() + "." + property); + } + + /** + * @return Constructs a property path by appending the argument to + * the existing property separated by a dot + */ + public <T> Property<T> dot(Property<T> property) { + return new Property<T>(getName() + "." + property.getName()); + } + + /** + * @return An expression representing null. + */ + public Expression isNull() { + return ExpressionFactory.matchExp(getName(), null); + } + + /** + * @return An expression representing a non-null value. + */ + public Expression isNotNull() { + return ExpressionFactory.matchExp(getName(), null).notExp(); + } + + /** + * @return An expression representing equality to TRUE. + */ + public Expression isTrue() { + return ExpressionFactory.matchExp(getName(), Boolean.TRUE); + } + + /** + * @return An expression representing equality to FALSE. + */ + public Expression isFalse() { + return ExpressionFactory.matchExp(getName(), Boolean.FALSE); + } + + /** + * @return An expression representing equality to a value. + */ + public Expression eq(E value) { + return ExpressionFactory.matchExp(getName(), value); + } + + /** + * @return An expression representing inequality to a value. + */ + public Expression ne(E value) { + return ExpressionFactory.noMatchExp(getName(), value); + } + + /** + * @return An expression for a Database "Like" query. + */ + public Expression like(E value) { + return ExpressionFactory.likeExp(getName(), value); + } + + /** + * @return An expression for a case insensitive "Like" query. + */ + public Expression likeInsensitive(E value) { + return ExpressionFactory.likeIgnoreCaseExp(getName(), value); + } + + /** + * @return An expression checking for objects between a lower and upper bound inclusive + * + * @param lower The lower bound. + * @param upper The upper bound. + */ + public Expression between(E lower, E upper) { + return ExpressionFactory.betweenExp(getName(), lower, upper); + } + + /** + * @return An expression for finding objects with values in the given set. + */ + public Expression in(E... values) { + return ExpressionFactory.inExp(getName(), values); + } + + /** + * @return A greater than Expression. + */ + public Expression gt(E value) { + return ExpressionFactory.greaterExp(getName(), value); + } + + /** + * @return A greater than or equal to Expression. + */ + public Expression gte(E value) { + return ExpressionFactory.greaterOrEqualExp(getName(), value); + } + + /** + * @return A less than Expression. + */ + public Expression lt(E value) { + return ExpressionFactory.lessExp(getName(), value); + } + + /** + * @return A less than or equal to Expression. + */ + public Expression lte(E value) { + return ExpressionFactory.lessOrEqualExp(getName(), value); + } + + /** + * @return Ascending sort orderings on this property. + */ + public Ordering asc() { + return new Ordering(getName(), SortOrder.ASCENDING); + } + + /** + * @return Ascending sort orderings on this property. + */ + public List<Ordering> ascs() { + List<Ordering> result = new ArrayList<Ordering>(1); + result.add(asc()); + return result; + } + + /** + * @return Ascending case insensitive sort orderings on this property. + */ + public Ordering ascInsensitive() { + return new Ordering(getName(), SortOrder.ASCENDING_INSENSITIVE); + } + + /** + * @return Ascending case insensitive sort orderings on this property. + */ + public List<Ordering> ascInsensitives() { + List<Ordering> result = new ArrayList<Ordering>(1); + result.add(ascInsensitive()); + return result; + } + + /** + * @return Descending sort orderings on this property. + */ + public Ordering desc() { + return new Ordering(getName(), SortOrder.DESCENDING); + } + + /** + * @return Descending sort orderings on this property. + */ + public List<Ordering> descs() { + List<Ordering> result = new ArrayList<Ordering>(1); + result.add(desc()); + return result; + } + + /** + * @return Descending case insensitive sort orderings on this property. + */ + public Ordering descInsensitive() { + return new Ordering(getName(), SortOrder.DESCENDING_INSENSITIVE); + } + + /** + * @return Descending case insensitive sort orderings on this property. + */ + public List<Ordering> descInsensitives() { + List<Ordering> result = new ArrayList<Ordering>(1); + result.add(descInsensitive()); + return result; + } + +} \ No newline at end of file Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm?rev=1361426&r1=1361425&r2=1361426&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm (original) +++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/client-superclass.vm Fri Jul 13 22:37:43 2012 @@ -36,6 +36,7 @@ ${importUtils.setPackage($superPackageName)}## ${importUtils.addReservedType("${$superPackageName}.${superClassName}")}## ${importUtils.addType("${basePackageName}.${baseClassName}")}## +${importUtils.addType('org.apache.cayenne.exp.Property')}## #foreach( $attr in ${object.DeclaredAttributes} ) $importUtils.addType(${attr.Type})## #end @@ -69,6 +70,24 @@ public abstract class ${superClassName} public static final String ${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY = "${rel.Name}"; #end +## Create Properties +#foreach( $attr in ${object.DeclaredAttributes} ) + public static final Property<$importUtils.formatJavaType(${attr.Type}, false)> ${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<$importUtils.formatJavaType(${attr.Type}, false)>(${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY); +#end +#foreach( $rel in ${object.DeclaredRelationships} ) +#if( $rel.ToMany ) +#if ( ${rel.CollectionType} == "java.util.Map") + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)), $importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#else + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#else + public static final Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#end + ## Create ivars #foreach( $attr in ${object.DeclaredAttributes} ) protected $importUtils.formatJavaType(${attr.Type}) ${attr.Name}; Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm?rev=1361426&r1=1361425&r2=1361426&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm (original) +++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-singleclass.vm Fri Jul 13 22:37:43 2012 @@ -38,6 +38,7 @@ ${importUtils.setPackage($subPackageName ${importUtils.addReservedType("${subPackageName}.${subClassName}")}## ${importUtils.addType("${basePackageName}.${baseClassName}")}## ${importUtils.addType("org.apache.cayenne.Persistent")}## +${importUtils.addType('org.apache.cayenne.exp.Property')}## #foreach( $attr in ${object.Attributes} ) $importUtils.addType(${attr.Type})## #end @@ -50,6 +51,11 @@ public abstract class ${subClassName} ex public static final String ${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY = "${attr.Name}"; #end +## Create Properties +#foreach( $attr in ${object.Attributes} ) + public static final Property<$importUtils.formatJavaType(${attr.Type}, false)> ${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<$importUtils.formatJavaType(${attr.Type}, false)>(${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY); +#end + // special properties injected by Cayenne private Persistent owner; private String embeddedProperty; Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm?rev=1361426&r1=1361425&r2=1361426&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm (original) +++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/embeddable-superclass.vm Fri Jul 13 22:37:43 2012 @@ -38,6 +38,7 @@ ${importUtils.setPackage($superPackageNa ${importUtils.addReservedType("${superPackageName}.${superClassName}")}## ${importUtils.addType("${basePackageName}.${baseClassName}")}## ${importUtils.addType("org.apache.cayenne.Persistent")}## +${importUtils.addType('org.apache.cayenne.exp.Property')}## #foreach( $attr in ${object.Attributes} ) $importUtils.addType(${attr.Type})## #end @@ -56,6 +57,11 @@ public abstract class ${superClassName} public static final String ${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY = "${attr.Name}"; #end +## Create Properties +#foreach( $attr in ${object.Attributes} ) + public static final Property<$importUtils.formatJavaType(${attr.Type}, false)> ${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<$importUtils.formatJavaType(${attr.Type}, false)>(${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY); +#end + // special properties injected by Cayenne private Persistent owner; private String embeddedProperty; Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm?rev=1361426&r1=1361425&r2=1361426&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm (original) +++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/light-superclass.vm Fri Jul 13 22:37:43 2012 @@ -36,6 +36,7 @@ ${importUtils.setPackage($superPackageName)}## ${importUtils.addReservedType("${$superPackageName}.${superClassName}")}## ${importUtils.addType("${basePackageName}.${baseClassName}")}## +${importUtils.addType('org.apache.cayenne.exp.Property')}## #foreach( $attr in ${object.DeclaredAttributes} ) $importUtils.addType(${attr.Type})## #end @@ -65,6 +66,24 @@ public abstract class ${superClassName} public static final String ${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY = "${rel.Name}"; #end +## Create Properties +#foreach( $attr in ${object.DeclaredAttributes} ) + public static final Property<$importUtils.formatJavaType(${attr.Type}, false)> ${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<$importUtils.formatJavaType(${attr.Type}, false)>(${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY); +#end +#foreach( $rel in ${object.DeclaredRelationships} ) +#if( $rel.ToMany ) +#if ( ${rel.CollectionType} == "java.util.Map") + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)), $importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#else + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#else + public static final Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#end + ## Create ivars #foreach( $attr in ${object.DeclaredAttributes} ) protected $importUtils.formatJavaType(${attr.Type}) ${attr.Name}; Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm?rev=1361426&r1=1361425&r2=1361426&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm (original) +++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/singleclass.vm Fri Jul 13 22:37:43 2012 @@ -36,6 +36,7 @@ ${importUtils.setPackage($subPackageName)}## ${importUtils.addReservedType("${subPackageName}.${subClassName}")}## ${importUtils.addType("${basePackageName}.${baseClassName}")}## +${importUtils.addType('org.apache.cayenne.exp.Property')}## #foreach( $attr in ${object.DeclaredAttributes} ) $importUtils.addType(${attr.Type})## #end @@ -63,6 +64,24 @@ public#if("true" == "${object.getIsAbstr #end #end +## Create Properties +#foreach( $attr in ${object.DeclaredAttributes} ) + public static final Property<$importUtils.formatJavaType(${attr.Type}, false)> ${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<$importUtils.formatJavaType(${attr.Type}, false)>(${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY); +#end +#foreach( $rel in ${object.DeclaredRelationships} ) +#if( $rel.ToMany ) +#if ( ${rel.CollectionType} == "java.util.Map") + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)), $importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#else + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#else + public static final Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#end + ## Create attribute set/get methods #foreach( $attr in ${object.DeclaredAttributes} ) #if ("true" != "${object.isReadOnly()}") Modified: cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm?rev=1361426&r1=1361425&r2=1361426&view=diff ============================================================================== --- cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm (original) +++ cayenne/main/trunk/framework/cayenne-tools/src/main/resources/templates/v1_2/superclass.vm Fri Jul 13 22:37:43 2012 @@ -35,6 +35,7 @@ ${importUtils.setPackage($superPackageName)}## ${importUtils.addReservedType("${superPackageName}.${superClassName}")}## ${importUtils.addType("${basePackageName}.${baseClassName}")}## +${importUtils.addType('org.apache.cayenne.exp.Property')}## #foreach( $attr in ${object.DeclaredAttributes} ) $importUtils.addType(${attr.Type})## #end @@ -68,6 +69,24 @@ public abstract class ${superClassName} #end #end +## Create Properties +#foreach( $attr in ${object.DeclaredAttributes} ) + public static final Property<$importUtils.formatJavaType(${attr.Type}, false)> ${stringUtils.capitalizedAsConstant($attr.Name)} = new Property<$importUtils.formatJavaType(${attr.Type}, false)>(${stringUtils.capitalizedAsConstant($attr.Name)}_PROPERTY); +#end +#foreach( $rel in ${object.DeclaredRelationships} ) +#if( $rel.ToMany ) +#if ( ${rel.CollectionType} == "java.util.Map") + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($entityUtils.getMapKeyType($rel)), $importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#else + #set( $type = "$importUtils.formatJavaType($rel.CollectionType)<$importUtils.formatJavaType($rel.TargetEntity.ClassName)>" ) + public static final Property<$type> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$type>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#else + public static final Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})> ${stringUtils.capitalizedAsConstant($rel.Name)} = new Property<$importUtils.formatJavaType(${rel.TargetEntity.ClassName})>(${stringUtils.capitalizedAsConstant($rel.Name)}_PROPERTY); +#end +#end + ## Create attribute set/get methods #foreach( $attr in ${object.DeclaredAttributes} ) #if ("true" != "${object.isReadOnly()}")