Package org.apache.cayenne.exp.property

# Class PropertyFactory

java.lang.Object
org.apache.cayenne.exp.property.PropertyFactory

public class PropertyFactory extends Object
Factory class that produces all property types.

Since:
  4.2
See Also:
  - `org.apache.cayenne.exp.property`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final NumericProperty<Long>`
  `COUNT`
  Property that can be used to select `COUNT(*)`
  `static final DateProperty<LocalDateTime>`
  `NOW`
  Property that corresponds to SQL function `NOW()`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PropertyFactory()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> BaseProperty<T>`
  `createBase(String name, Class<T> type)`
  Create base property
  `static <T> BaseProperty<T>`
  `createBase(String name, Expression expression, Class<T> type)`
  Create base property
  `static <T> BaseProperty<T>`
  `createBase(Expression expression, Class<T> type)`
  Create base property
  `static <T> BaseIdProperty<T>`
  `createBaseId(String attribute, String entityName, Class<T> propertyType)`
  `static <T> BaseIdProperty<T>`
  `createBaseId(String attribute, String path, String entityName, Class<T> propertyType)`
  `static <T> DateProperty<T>`
  `createDate(String name, Class<T> type)`
  Create date property
  `static <T> DateProperty<T>`
  `createDate(String name, Expression expression, Class<T> type)`
  Create date property
  `static <T> DateProperty<T>`
  `createDate(Expression expression, Class<T> type)`
  Create date property
  `static <T extends EmbeddableObject>
  EmbeddableProperty<T>`
  `createEmbeddable(String name, Class<T> embeddableType)`
  Create property that represents embeddable
  `static <T extends EmbeddableObject>
  EmbeddableProperty<T>`
  `createEmbeddable(String name, Expression exp, Class<T> embeddableType)`
  Create property that represents embeddable
  `static <T extends Persistent>
  EntityProperty<T>`
  `createEntity(String name, Class<T> type)`
  Create entity property
  `static <T extends Persistent>
  EntityProperty<T>`
  `createEntity(String name, Expression expression, Class<T> entityType)`
  Create entity property
  `static <T extends Persistent>
  EntityProperty<T>`
  `createEntity(Expression expression, Class<T> type)`
  Create entity property
  `static <T extends Persistent>
  ListProperty<T>`
  `createList(String name, Class<T> entityType)`
  Create to-many relationship mapped on list property
  `static <T extends Persistent>
  ListProperty<T>`
  `createList(String name, Expression expression, Class<T> entityType)`
  Create to-many relationship mapped on list property
  `static <K, V extends Persistent>
  MapProperty<K,V>`
  `createMap(String name, Class<K> keyType, Class<V> entityType)`
  Create to-many relationship mapped on map property
  `static <K, V extends Persistent>
  MapProperty<K,V>`
  `createMap(String name, Expression expression, Class<K> keyType, Class<V> entityType)`
  Create to-many relationship mapped on map property
  `static <T extends Number>
  NumericProperty<T>`
  `createNumeric(String name, Class<T> type)`
  Create numeric property
  `static <T extends Number>
  NumericProperty<T>`
  `createNumeric(String name, Expression expression, Class<T> type)`
  Create numeric property
  `static <T extends Number>
  NumericProperty<T>`
  `createNumeric(Expression expression, Class<T> type)`
  Create numeric property
  `static <T extends Number>
  NumericIdProperty<T>`
  `createNumericId(String attribute, String entityName, Class<T> propertyType)`
  `static <T extends Number>
  NumericIdProperty<T>`
  `createNumericId(String attribute, String path, String entityName, Class<T> propertyType)`
  `static <T extends Persistent>
  EntityProperty<T>`
  `createSelf(Class<T> type)`
  Self property allows to create column queries that return full objects along with custom column set.
  `static <T extends Persistent>
  EntityProperty<T>`
  `createSelf(Expression expression, Class<T> type)`
  Self property allows to create column queries that return full objects along with custom column set.
  `static <T extends Persistent>
  SetProperty<T>`
  `createSet(String name, Class<T> entityType)`
  Create to-many relationship mapped on set property
  `static <T extends Persistent>
  SetProperty<T>`
  `createSet(String name, Expression expression, Class<T> entityType)`
  Create to-many relationship mapped on set property
  `static <T extends CharSequence>
  StringProperty<T>`
  `createString(String name, Class<T> type)`
  Create string property
  `static <T extends CharSequence>
  StringProperty<T>`
  `createString(String name, Expression expression, Class<T> type)`
  Create string property
  `static <T extends CharSequence>
  StringProperty<T>`
  `createString(Expression expression, Class<T> type)`
  Create string property

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### COUNT

    public static final NumericProperty<Long> COUNT
    Property that can be used to select `COUNT(*)`

    Usage:

         ObjectSelect.columnQuery(Artist.class, Artist.ARTIST_NAME, PropertyFactory.COUNT);

    See Also:
      - `ObjectSelect.selectCount(ObjectContext)`

  - ### NOW

    public static final DateProperty<LocalDateTime> NOW
    Property that corresponds to SQL function `NOW()`

    Usage:

         ObjectSelect.query(Artist.class).where(Artist.DATE_OF_BIRTH.year().lt(PropertyFactory.NOW.year().sub(100)));

- ## Constructor Details

  - ### PropertyFactory

    public PropertyFactory()

- ## Method Details

  - ### createBase

    public static <T> BaseProperty<T> createBase(String name, Expression expression, Class<T> type)
    Create base property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression

  - ### createBase

    public static <T> BaseProperty<T> createBase(String name, Class<T> type)
    Create base property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property, will be used as value for path expression
      `type` - type of represented attribute
    Returns:
      new path property

  - ### createBase

    public static <T> BaseProperty<T> createBase(Expression expression, Class<T> type)
    Create base property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression without name

  - ### createString

    public static <T extends CharSequence> StringProperty<T> createString(String name, Expression expression, Class<T> type)
    Create string property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression

  - ### createString

    public static <T extends CharSequence> StringProperty<T> createString(String name, Class<T> type)
    Create string property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property, will be used as value for path expression
      `type` - type of represented attribute
    Returns:
      new path property

  - ### createString

    public static <T extends CharSequence> StringProperty<T> createString(Expression expression, Class<T> type)
    Create string property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression without name

  - ### createNumeric

    public static <T extends Number> NumericProperty<T> createNumeric(String name, Expression expression, Class<T> type)
    Create numeric property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression

  - ### createNumeric

    public static <T extends Number> NumericProperty<T> createNumeric(String name, Class<T> type)
    Create numeric property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property, will be used as value for path expression
      `type` - type of represented attribute
    Returns:
      new path property

  - ### createNumeric

    public static <T extends Number> NumericProperty<T> createNumeric(Expression expression, Class<T> type)
    Create numeric property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression without name

  - ### createDate

    public static <T> DateProperty<T> createDate(String name, Expression expression, Class<T> type)
    Create date property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression

  - ### createDate

    public static <T> DateProperty<T> createDate(String name, Class<T> type)
    Create date property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property, will be used as value for path expression
      `type` - type of represented attribute
    Returns:
      new path property

  - ### createDate

    public static <T> DateProperty<T> createDate(Expression expression, Class<T> type)
    Create date property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `expression` - that property will use
      `type` - type of represented attribute
    Returns:
      new property with custom expression without name

  - ### createEntity

    public static <T extends Persistent> EntityProperty<T> createEntity(String name, Expression expression, Class<T> entityType)
    Create entity property
    Type Parameters:
      `T` - type of represented relationship entity
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `entityType` - type of represented relationship entity
    Returns:
      new property with custom expression

  - ### createEntity

    public static <T extends Persistent> EntityProperty<T> createEntity(String name, Class<T> type)
    Create entity property
    Type Parameters:
      `T` - type of represented relationship entity
    Parameters:
      `name` - of the property, will be used as value for path expression
      `type` - type of represented relationship entity
    Returns:
      new path property

  - ### createEntity

    public static <T extends Persistent> EntityProperty<T> createEntity(Expression expression, Class<T> type)
    Create entity property
    Type Parameters:
      `T` - type of represented relationship entity
    Parameters:
      `expression` - that property will use
      `type` - type of represented relationship entity
    Returns:
      new property with custom expression without name

  - ### createSelf

    public static <T extends Persistent> EntityProperty<T> createSelf(Class<T> type)
    Self property allows to create column queries that return full objects along with custom column set.

    Usage example, query will return object with dependent objects count:

          List<Object[]> result = ObjectSelect.columnQuery(Artist.class,
                  PropertyFactory.createSelf(Artist.class),
                  Artist.PAINTING_ARRAY.count())
              .select(context);

    Type Parameters:
      `T` - type of represented entity
    Parameters:
      `type` - of represented entity
    Returns:
      new 'self' property

  - ### createSelf

    public static <T extends Persistent> EntityProperty<T> createSelf(Expression expression, Class<T> type)
    Self property allows to create column queries that return full objects along with custom column set.

    This method is not much useful, as to-one property can be used as is in this case, example is purely for demonstration purpose only. See `EntityProperty` usage examples.

    Usage example, query will return object with dependent objects count:

          List<Object[]> result = ObjectSelect.columnQuery(Painting.class,
                  Painting.PAINTING_TITLE,
                  PropertyFactory.createSelf(Painting.TO_ARTIST.getExpression(), Painting.class))
              .select(context);

    Type Parameters:
      `T` - type of represented entity
    Parameters:
      `expression` - expression to be used for this property (usually it will be path from other property)
      `type` - of represented entity
    Returns:
      new 'self' property

  - ### createList

    public static <T extends Persistent> ListProperty<T> createList(String name, Expression expression, Class<T> entityType)
    Create to-many relationship mapped on list property
    Type Parameters:
      `T` - type of represented relationship entity
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `entityType` - type of represented relationship entity
    Returns:
      new property with custom expression

  - ### createList

    public static <T extends Persistent> ListProperty<T> createList(String name, Class<T> entityType)
    Create to-many relationship mapped on list property
    Type Parameters:
      `T` - type of represented relationship entity
    Parameters:
      `name` - of the property, will be used as value for path expression
      `entityType` - type of represented relationship entity
    Returns:
      new path property

  - ### createSet

    public static <T extends Persistent> SetProperty<T> createSet(String name, Expression expression, Class<T> entityType)
    Create to-many relationship mapped on set property
    Type Parameters:
      `T` - type of represented attribute
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `entityType` - type of represented attribute
    Returns:
      new property with custom expression

  - ### createSet

    public static <T extends Persistent> SetProperty<T> createSet(String name, Class<T> entityType)
    Create to-many relationship mapped on set property
    Type Parameters:
      `T` - type of represented relationship entity
    Parameters:
      `name` - of the property, will be used as value for path expression
      `entityType` - type of represented relationship entity
    Returns:
      new path property

  - ### createMap

    public static <K, V extends Persistent> MapProperty<K,V> createMap(String name, Expression expression, Class<K> keyType, Class<V> entityType)
    Create to-many relationship mapped on map property
    Type Parameters:
      `K` - type of represented relationship keys
      `V` - type of represented relationship values
    Parameters:
      `name` - of the property
      `expression` - that property will use
      `keyType` - type of represented relationship keys
      `entityType` - type of represented relationship values
    Returns:
      new property with custom expression

  - ### createMap

    public static <K, V extends Persistent> MapProperty<K,V> createMap(String name, Class<K> keyType, Class<V> entityType)
    Create to-many relationship mapped on map property
    Type Parameters:
      `K` - type of represented relationship keys
      `V` - type of represented relationship values
    Parameters:
      `name` - of the property, will be used as value for path expression
      `keyType` - type of represented relationship keys
      `entityType` - type of represented relationship values
    Returns:
      new path property

  - ### createEmbeddable

    public static <T extends EmbeddableObject> EmbeddableProperty<T> createEmbeddable(String name, Class<T> embeddableType)
    Create property that represents embeddable
    Type Parameters:
      `T` - type of represented embeddable entity
    Parameters:
      `name` - of the property, will be used as value for path expression
      `embeddableType` - type of represented embeddable entity
    Returns:
      new path property

  - ### createEmbeddable

    public static <T extends EmbeddableObject> EmbeddableProperty<T> createEmbeddable(String name, Expression exp, Class<T> embeddableType)
    Create property that represents embeddable
    Type Parameters:
      `T` - type of represented embeddable entity
    Parameters:
      `name` - of the property, will be used as value for path expression
      `exp` - that property will use
      `embeddableType` - type of represented embeddable entity
    Returns:
      new path property

  - ### createBaseId

    public static <T> BaseIdProperty<T> createBaseId(String attribute, String entityName, Class<T> propertyType)

  - ### createBaseId

    public static <T> BaseIdProperty<T> createBaseId(String attribute, String path, String entityName, Class<T> propertyType)

  - ### createNumericId

    public static <T extends Number> NumericIdProperty<T> createNumericId(String attribute, String entityName, Class<T> propertyType)

  - ### createNumericId

    public static <T extends Number> NumericIdProperty<T> createNumericId(String attribute, String path, String entityName, Class<T> propertyType)