X
- The entity's Java typeT
- The entity's identity typepublic class Key<X,T> extends Object
Instances of this class are immutable.
Constructor and Description |
---|
Key(ErraiManagedType<X> entityType,
T id)
Creates a key that uniquely identifies an entity of a particular type (the
entity with this identity does not necessarily exist, but if it did, this
would be its identity).
|
Modifier and Type | Method and Description |
---|---|
boolean |
equals(Object obj) |
static Key<?,?> |
fromJson(ErraiEntityManager em,
String key,
boolean failIfNotFound)
Returns a Key instance based on the given JSON string.
|
static Key<?,?> |
fromJsonObject(ErraiEntityManager em,
com.google.gwt.json.client.JSONObject key,
boolean failIfNotFound)
Returns a Key instance based on the given JSON object.
|
static <X,T> Key<X,T> |
get(ErraiEntityManager em,
Class<X> entityClass,
T id)
Returns a Key instance for the entity type of the given class.
|
ErraiManagedType<X> |
getEntityType()
Returns the managed type this key refers to.
|
T |
getId()
Returns the ID value for this key.
|
int |
hashCode() |
String |
toJson()
Returns a JSON string representation of this key which can be turned back
into a Key instance via
fromJson(ErraiEntityManager, String, boolean) . |
com.google.gwt.json.client.JSONObject |
toJsonObject()
Returns a JSONObject representation of this key which can be turned back
into a Key instance via
fromJsonObject(ErraiEntityManager, JSONObject, boolean) . |
String |
toString() |
public Key(ErraiManagedType<X> entityType, T id)
entityType
- The type of the entity. Must not be null.id
- The ID of the entity. Must not be null.NullPointerException
- if either argument is null.public static <X,T> Key<X,T> get(ErraiEntityManager em, Class<X> entityClass, T id)
em
- The entity manager (required for looking up the EntityType for the
given class). Must not be null.entityClass
- The class of the entity for the key. Must not be null.id
- The ID value for the entity. Must not be null.NullPointerException
- if any argument is null.IllegalArgumentException
- if entityClass
is not a known JPA entity type.public ErraiManagedType<X> getEntityType()
public T getId()
public String toJson()
fromJson(ErraiEntityManager, String, boolean)
.toJsonObject()
public com.google.gwt.json.client.JSONObject toJsonObject()
fromJsonObject(ErraiEntityManager, JSONObject, boolean)
.toJson()
public static Key<?,?> fromJson(ErraiEntityManager em, String key, boolean failIfNotFound)
em
- The entity manager that can be used to look up the entity type
corresponding with the key.key
- The key to parse.failIfNotFound
- If true, and the entity type given in key
is not known to
em
, an IllegalArgumentException will be thrown.public static Key<?,?> fromJsonObject(ErraiEntityManager em, com.google.gwt.json.client.JSONObject key, boolean failIfNotFound)
em
- The entity manager that can be used to look up the entity type
corresponding with the key.key
- The properties of the key to create.failIfNotFound
- If true, and the entity type given in key
is not known to
em
, an IllegalArgumentException will be thrown.Copyright © 2013-2015 JBoss, a division of Red Hat. All Rights Reserved.