Errai 3.0.1-SNAPSHOT

org.jboss.errai.jpa.client.local
Class Key<X,T>

java.lang.Object
  extended by org.jboss.errai.jpa.client.local.Key<X,T>
Type Parameters:
X - The entity's Java type
T - The entity's identity type

public class Key<X,T>
extends Object

Holder class for a storage key: a tuple of type and identity value.

Instances of this class are immutable.

Author:
Jonathan Fuerth

Constructor Summary
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).
 
Method Summary
 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()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Key

public 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).

Parameters:
entityType - The type of the entity. Must not be null.
id - The ID of the entity. Must not be null.
Throws:
NullPointerException - if either argument is null.
Method Detail

get

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

Parameters:
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.
Returns:
A Key instance for the given entity type and ID value.
Throws:
NullPointerException - if any argument is null.
IllegalArgumentException - if entityClass is not a known JPA entity type.

getEntityType

public ErraiManagedType<X> getEntityType()
Returns the managed type this key refers to.

Returns:
the entity type of the key. Never null.

getId

public T getId()
Returns the ID value for this key.

Returns:
the ID value of the key. Never null.

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

toJson

public String toJson()
Returns a JSON string representation of this key which can be turned back into a Key instance via fromJson(ErraiEntityManager, String, boolean).

Returns:
a JSON-formatted string. Never null.
See Also:
toJsonObject()

toJsonObject

public 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).

Returns:
a JSON object that represents this key. Never null.
See Also:
toJson()

fromJson

public static Key<?,?> fromJson(ErraiEntityManager em,
                                String key,
                                boolean failIfNotFound)
Returns a Key instance based on the given JSON string.

Parameters:
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.
Returns:
An instance of Key that corresponds with the entity type and ID of the given JSON string.

fromJsonObject

public static Key<?,?> fromJsonObject(ErraiEntityManager em,
                                      com.google.gwt.json.client.JSONObject key,
                                      boolean failIfNotFound)
Returns a Key instance based on the given JSON object.

Parameters:
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.
Returns:
An instance of Key that corresponds with the entity type and ID of the given JSON object.

Errai 3.0.1-SNAPSHOT

Copyright © 2013-2014 JBoss, a division of Red Hat. All Rights Reserved.