org.apache.cayenne

## Class DataObjectUtils

- java.lang.Object
- - org.apache.cayenne.DataObjectUtils

- Deprecated.
  since 3.1 `Cayenne` class is used instead

      @Deprecated
      public final class DataObjectUtils
      extends Object

  A collection of utility methods to work with DataObjects.

  DataObjects and Primary Keys: All methods that allow to extract primary key values or use primary keys to find objects are provided for convenience. Still the author's belief is that integer sequential primary keys are meaningless in the object model and are pure database artifacts. Therefore relying heavily on direct access to PK provided 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.

  Since:
    1.1

- - ### Method Summary

    All Methods Static Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static Map<String,Object>` | `compoundPKForObject(Persistent dataObject)` Deprecated. Returns a primary key map for a persistent object.
    `static int` | `intPKForObject(Persistent dataObject)` Deprecated. Returns an int primary key value for a persistent object.
    `static long` | `longPKForObject(Persistent dataObject)` Deprecated. Returns an int primary key value for a persistent object.
    `static <T> T` | `objectForPK(ObjectContext context, Class<T> dataObjectClass, int pk)` Deprecated. Returns an object matching an int primary key.
    `static <T> T` | `objectForPK(ObjectContext context, Class<T> dataObjectClass, Map<String,?> pk)` Deprecated. Returns an object matching a primary key.
    `static <T> T` | `objectForPK(ObjectContext context, Class<T> dataObjectClass, Object pk)` Deprecated. Returns an object matching an Object primary key.
    `static Object` | `objectForPK(ObjectContext context, ObjectId id)` Deprecated. Returns an object matching ObjectId.
    `static Object` | `objectForPK(ObjectContext context, String objEntityName, int pk)` Deprecated. Returns an object matching an int primary key.
    `static Object` | `objectForPK(ObjectContext context, String objEntityName, Map<String,?> pk)` Deprecated. Returns an object matching a primary key.
    `static Object` | `objectForPK(ObjectContext context, String objEntityName, Object pk)` Deprecated. Returns an object matching an Object primary key.
    `static Object` | `objectForQuery(ObjectContext context, Query query)` Deprecated. Returns an object or a DataRow that is a result of a given query.
    `static Object` | `pkForObject(Persistent dataObject)` Deprecated. Returns a primary key value for a persistent object.

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

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

- - ### Method Detail

    - #### longPKForObject

          public static long longPKForObject(Persistent dataObject)

      Deprecated.
      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.
      Since:
        3.0

    - #### intPKForObject

          public static int intPKForObject(Persistent dataObject)

      Deprecated.
      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.

    - #### pkForObject

          public static Object pkForObject(Persistent dataObject)

      Deprecated.
      Returns a primary key value for a persistent object. Only works for single column primary keys. If an object is transient or has a compound ObjectId, an exception is thrown.

    - #### compoundPKForObject

          public static Map<String,Object> compoundPKForObject(Persistent dataObject)

      Deprecated.
      Returns a primary key map for a persistent object. This method is the most generic out of all methods for primary key retrieval. It will work for all possible types of primary keys. If an object is transient, an exception is thrown.

    - #### objectForPK

          public static <T> T objectForPK(ObjectContext context,
                                          Class<T> dataObjectClass,
                                          int pk)

      Deprecated.
      Returns an object matching an int primary key. If the object is mapped to use non-integer PK or a compound PK, CayenneRuntimeException is thrown.

      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.

      See Also:
        `objectForPK(ObjectContext, ObjectId)`

    - #### objectForPK

          public static <T> T objectForPK(ObjectContext context,
                                          Class<T> dataObjectClass,
                                          Object pk)

      Deprecated.
      Returns an object matching an Object primary key. If the object is mapped to use a compound PK, CayenneRuntimeException is thrown.

      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.

      See Also:
        `objectForPK(ObjectContext, ObjectId)`

    - #### objectForPK

          public static <T> T objectForPK(ObjectContext context,
                                          Class<T> dataObjectClass,
                                          Map<String,?> pk)

      Deprecated.
      Returns an object matching a primary key. PK map parameter should use database PK column names as keys.

      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.

      See Also:
        `objectForPK(ObjectContext, ObjectId)`

    - #### objectForPK

          public static Object objectForPK(ObjectContext context,
                                           String objEntityName,
                                           int pk)

      Deprecated.
      Returns an object matching an int primary key. If the object is mapped to use non-integer PK or a compound PK, CayenneRuntimeException is thrown.

      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.

      See Also:
        `objectForPK(ObjectContext, ObjectId)`

    - #### objectForPK

          public static Object objectForPK(ObjectContext context,
                                           String objEntityName,
                                           Object pk)

      Deprecated.
      Returns an object matching an Object primary key. If the object is mapped to use a compound PK, CayenneRuntimeException is thrown.

      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.

      See Also:
        `objectForPK(ObjectContext, ObjectId)`

    - #### objectForPK

          public static Object objectForPK(ObjectContext context,
                                           String objEntityName,
                                           Map<String,?> pk)

      Deprecated.
      Returns an object matching a primary key. PK map parameter should use database PK column names as keys.

      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.

      See Also:
        `objectForPK(ObjectContext, ObjectId)`

    - #### objectForPK

          public static Object objectForPK(ObjectContext context,
                                           ObjectId id)

      Deprecated.
      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.
      Returns:
        A persistent object that matched the id, null if no matching objects were found
      Throws:
        `CayenneRuntimeException` - if more than one object matched ObjectId.

    - #### objectForQuery

          public static Object objectForQuery(ObjectContext context,
                                              Query query)

      Deprecated.
      Returns an object or a DataRow that is a result of a given query. If query returns more than one object, an exception is thrown. If query returns no objects, null is returned.
      Since:
        1.2

Copyright © 2001–2018 Apache Cayenne. All rights reserved.