public class Cayenne extends Object
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.
Modifier | Constructor and Description |
---|---|
protected |
Cayenne() |
Modifier and Type | Method and Description |
---|---|
static Map<String,Object> |
compoundPKForObject(Persistent dataObject)
Returns a primary key map for a persistent object.
|
static ClassDescriptor |
getClassDescriptor(Persistent object)
Returns class descriptor for the object or null if the object is not
registered with an ObjectContext or descriptor was not found.
|
static ObjEntity |
getObjEntity(Persistent p)
Returns mapped ObjEntity for object.
|
static PropertyDescriptor |
getProperty(Persistent object,
String properyName)
Returns property descriptor for specified property.
|
static int |
intPKForObject(Persistent dataObject)
Returns an int primary key value for a persistent object.
|
static long |
longPKForObject(Persistent dataObject)
Returns an int primary key value for a persistent object.
|
static String |
makePath(String... pathParts)
Constructs a dotted path from a list of strings.
|
static <T> T |
objectForPK(ObjectContext context,
Class<T> dataObjectClass,
int pk)
Returns an object matching an int primary key.
|
static <T> T |
objectForPK(ObjectContext context,
Class<T> dataObjectClass,
Map<String,?> pk)
Returns an object matching a primary key.
|
static <T> T |
objectForPK(ObjectContext context,
Class<T> dataObjectClass,
Object pk)
Returns an object matching an Object primary key.
|
static Object |
objectForPK(ObjectContext context,
ObjectId id)
Returns an object matching ObjectId.
|
static Object |
objectForPK(ObjectContext context,
String objEntityName,
int pk)
Returns an object matching an int primary key.
|
static Object |
objectForPK(ObjectContext context,
String objEntityName,
Map<String,?> pk)
Returns an object matching a primary key.
|
static Object |
objectForPK(ObjectContext context,
String objEntityName,
Object pk)
Returns an object matching an Object primary key.
|
static Object |
objectForQuery(ObjectContext context,
Query query)
Returns an object or a DataRow that is a result of a given query.
|
static Object |
pkForObject(Persistent dataObject)
Returns a primary key value for a persistent object.
|
static Object |
readNestedProperty(Object o,
String path)
Returns a value of the property identified by a property path.
|
public static ObjEntity getObjEntity(Persistent p)
public static ClassDescriptor getClassDescriptor(Persistent object)
public static PropertyDescriptor getProperty(Persistent object, String properyName)
properyName
- path to the propertynull
if not foundpublic static Object readNestedProperty(Object o, String path)
Property path (or nested property) is a dot-separated path used to
traverse object relationships until the final object is found. If a null
object found while traversing path, null is returned. If a list is
encountered in the middle of the path, CayenneRuntimeException is thrown.
Unlike DataObject.readPropertyDirectly(String)
, this method will resolve an
object if it is HOLLOW.
Examples:
String name = (String)Cayenne.readNestedProperty(artist, "name");
Gallery g = (Gallery)Cayenne.readNestedProperty(paintingInfo, "toPainting.toGallery");
String name = (String)Cayenne.readNestedProperty(painting, "toArtist.artistName");
List exhibits = (List)Cayenne.readNestedProperty(painting, "toGallery.exhibitArray");
List<String> names = (List<String>)Cayenne.readNestedProperty(artist, "paintingArray.paintingName");
public static String makePath(String... pathParts)
orderings.add(new Ordering("department.name", SortOrder.ASCENDING));
You can use makePath() with the constants generated by Cayenne Modeler:
orderings.add(new Ordering(Cayenne.makePath(USER.DEPARTMENT_PROPERTY, Department.NAME_PROPERTY), SortOrder.ASCENDING));
pathParts
- The varargs list of paths to join.public static long longPKForObject(Persistent dataObject)
public static int intPKForObject(Persistent dataObject)
public static Object pkForObject(Persistent dataObject)
public static Map<String,Object> compoundPKForObject(Persistent dataObject)
public static <T> T objectForPK(ObjectContext context, Class<T> dataObjectClass, int pk)
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.
objectForPK(ObjectContext, ObjectId)
public static <T> T objectForPK(ObjectContext context, Class<T> dataObjectClass, Object pk)
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.
objectForPK(ObjectContext, ObjectId)
public static <T> T objectForPK(ObjectContext context, Class<T> dataObjectClass, Map<String,?> pk)
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.
objectForPK(ObjectContext, ObjectId)
public static Object objectForPK(ObjectContext context, String objEntityName, int pk)
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.
objectForPK(ObjectContext, ObjectId)
public static Object objectForPK(ObjectContext context, String objEntityName, Object pk)
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.
objectForPK(ObjectContext, ObjectId)
public static Object objectForPK(ObjectContext context, String objEntityName, Map<String,?> pk)
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.
objectForPK(ObjectContext, ObjectId)
public static Object objectForPK(ObjectContext context, ObjectId id)
CayenneRuntimeException
- if more than one object matched ObjectId.public static Object objectForQuery(ObjectContext context, Query query)
Copyright © 2001–2019 Apache Cayenne. All rights reserved.