Errai 3.0.1-SNAPSHOT

org.jboss.errai.jpa.client.local
Class ErraiManagedType<X>

java.lang.Object
  extended by org.jboss.errai.jpa.client.local.ErraiManagedType<X>
Type Parameters:
X - The actual type described by this metatype.
All Implemented Interfaces:
javax.persistence.metamodel.ManagedType<X>, javax.persistence.metamodel.Type<X>
Direct Known Subclasses:
ErraiIdentifiableType

public abstract class ErraiManagedType<X>
extends Object
implements javax.persistence.metamodel.ManagedType<X>

Errai implementation of the JPA ManagedType metamodel interface. Defines the attributes common to all managed types (which are entity, mapped superclass, and embeddable types).

Author:
Jonathan Fuerth

Nested Class Summary
 
Nested classes/interfaces inherited from interface javax.persistence.metamodel.Type
javax.persistence.metamodel.Type.PersistenceType
 
Field Summary
protected  Class<X> javaType
           
 
Constructor Summary
ErraiManagedType(Class<X> javaType)
           
 
Method Summary
<Y> void
addAttribute(javax.persistence.metamodel.Attribute<X,Y> attribute)
           
abstract  X fromJson(javax.persistence.EntityManager em, com.google.gwt.json.client.JSONValue jsonValue)
          Converts the given JSONValue, which represents an instance of this entity type, into the actual instance of this entity type that exists in the given EntityManager's persistence context.
 ErraiAttribute<? super X,?> getAttribute(String name)
          Return the attribute of the managed type that corresponds to the specified name.
 Set<javax.persistence.metamodel.Attribute<? super X,?>> getAttributes()
          Return the attributes of the managed type.
 javax.persistence.metamodel.CollectionAttribute<? super X,?> getCollection(String name)
          Return the Collection-valued attribute of the managed type that corresponds to the specified name.
<E> javax.persistence.metamodel.CollectionAttribute<? super X,E>
getCollection(String name, Class<E> elementType)
          Return the Collection-valued attribute of the managed type that corresponds to the specified name and Java element type.
 javax.persistence.metamodel.Attribute<X,?> getDeclaredAttribute(String name)
          Return the attribute declared by the managed type that corresponds to the specified name.
 Set<javax.persistence.metamodel.Attribute<X,?>> getDeclaredAttributes()
          Return the attributes declared by the managed type.
 javax.persistence.metamodel.CollectionAttribute<X,?> getDeclaredCollection(String name)
          Return the Collection-valued attribute declared by the managed type that corresponds to the specified name.
<E> javax.persistence.metamodel.CollectionAttribute<X,E>
getDeclaredCollection(String name, Class<E> elementType)
          Return the Collection-valued attribute declared by the managed type that corresponds to the specified name and Java element type.
 javax.persistence.metamodel.ListAttribute<X,?> getDeclaredList(String name)
          Return the List-valued attribute declared by the managed type that corresponds to the specified name.
<E> javax.persistence.metamodel.ListAttribute<X,E>
getDeclaredList(String name, Class<E> elementType)
          Return the List-valued attribute declared by the managed type that corresponds to the specified name and Java element type.
 javax.persistence.metamodel.MapAttribute<X,?,?> getDeclaredMap(String name)
          Return the Map-valued attribute declared by the managed type that corresponds to the specified name.
<K,V> javax.persistence.metamodel.MapAttribute<X,K,V>
getDeclaredMap(String name, Class<K> keyType, Class<V> valueType)
          Return the Map-valued attribute declared by the managed type that corresponds to the specified name and Java key and value types.
 Set<javax.persistence.metamodel.PluralAttribute<X,?,?>> getDeclaredPluralAttributes()
          Return all multi-valued attributes (Collection-, Set-, List-, and Map-valued attributes) declared by the managed type.
 javax.persistence.metamodel.SetAttribute<X,?> getDeclaredSet(String name)
          Return the Set-valued attribute declared by the managed type that corresponds to the specified name.
<E> javax.persistence.metamodel.SetAttribute<X,E>
getDeclaredSet(String name, Class<E> elementType)
          Return the Set-valued attribute declared by the managed type that corresponds to the specified name and Java element type.
 javax.persistence.metamodel.SingularAttribute<X,?> getDeclaredSingularAttribute(String name)
          Return the single-valued attribute declared by the managed type that corresponds to the specified name.
<Y> javax.persistence.metamodel.SingularAttribute<X,Y>
getDeclaredSingularAttribute(String name, Class<Y> type)
          Return the single-valued attribute declared by the managed type that corresponds to the specified name and Java type.
 Set<javax.persistence.metamodel.SingularAttribute<X,?>> getDeclaredSingularAttributes()
          Return the single-valued attributes declared by the managed type.
 Class<X> getJavaType()
          Return the represented Java type.
 javax.persistence.metamodel.ListAttribute<? super X,?> getList(String name)
          Return the List-valued attribute of the managed type that corresponds to the specified name.
<E> javax.persistence.metamodel.ListAttribute<? super X,E>
getList(String name, Class<E> elementType)
          Return the List-valued attribute of the managed type that corresponds to the specified name and Java element type.
 javax.persistence.metamodel.MapAttribute<? super X,?,?> getMap(String name)
          Return the Map-valued attribute of the managed type that corresponds to the specified name.
<K,V> javax.persistence.metamodel.MapAttribute<? super X,K,V>
getMap(String name, Class<K> keyType, Class<V> valueType)
          Return the Map-valued attribute of the managed type that corresponds to the specified name and Java key and value types.
 Set<javax.persistence.metamodel.PluralAttribute<? super X,?,?>> getPluralAttributes()
          Return all multi-valued attributes (Collection-, Set-, List-, and Map-valued attributes) of the managed type.
 javax.persistence.metamodel.SetAttribute<? super X,?> getSet(String name)
          Return the Set-valued attribute of the managed type that corresponds to the specified name.
<E> javax.persistence.metamodel.SetAttribute<? super X,E>
getSet(String name, Class<E> elementType)
          Return the Set-valued attribute of the managed type that corresponds to the specified name and Java element type.
 javax.persistence.metamodel.SingularAttribute<? super X,?> getSingularAttribute(String name)
          Return the single-valued attribute of the managed type that corresponds to the specified name.
<Y> ErraiSingularAttribute<? super X,Y>
getSingularAttribute(String name, Class<Y> type)
          Return the single-valued attribute of the managed type that corresponds to the specified name and Java type.
 Set<javax.persistence.metamodel.SingularAttribute<? super X,?>> getSingularAttributes()
          Return the single-valued attributes of the managed type.
 Collection<ErraiManagedType<X>> getSubtypes()
          Returns the collection of entity types that are subclasses of this managed type.
 boolean isSuperclassOf(javax.persistence.metamodel.ManagedType<?> other)
          Returns true if this managed type represents the same Java class or a superclass of the given type.
 void mergeState(ErraiEntityManager em, X targetEntity, X sourceEntity)
          Copies the state of the attributes in sourceEntity into targetEntity.
 X newInstance()
          Creates and returns a new instance of the represented type.
protected
<Y> void
parseInlineJson(X targetEntity, ErraiAttribute<? super X,Y> attr, com.google.gwt.json.client.JSONValue attrJsonValue, ErraiEntityManager eem)
           
protected
<C,E> void
parsePluralJsonReference(X targetEntity, ErraiPluralAttribute<? super X,C,E> attr, com.google.gwt.json.client.JSONArray attrJsonValues, ErraiEntityManager eem)
           
protected
<Y> void
parseSingularJsonReference(X targetEntity, ErraiSingularAttribute<? super X,Y> attr, com.google.gwt.json.client.JSONValue attrJsonValue, ErraiEntityManager eem)
           
 com.google.gwt.json.client.JSONValue toJson(javax.persistence.EntityManager em, X sourceEntity)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.persistence.metamodel.Type
getPersistenceType
 

Field Detail

javaType

protected final Class<X> javaType
Constructor Detail

ErraiManagedType

public ErraiManagedType(Class<X> javaType)
Method Detail

addAttribute

public <Y> void addAttribute(javax.persistence.metamodel.Attribute<X,Y> attribute)

newInstance

public X newInstance()
Creates and returns a new instance of the represented type. This implementation always throws an exception; subclasses that represent instantiable types should override this method with one that creates a new instance of that type.

Returns:
a new instance of type X.
Throws:
UnsupportedOperationException - if the represented type is abstract.

isSuperclassOf

public boolean isSuperclassOf(javax.persistence.metamodel.ManagedType<?> other)
Returns true if this managed type represents the same Java class or a superclass of the given type.

Parameters:
other - the ManagedType to check
Returns:
true if the Java type of this managed is a superclass of the Java type of the other managed type.

getSubtypes

public Collection<ErraiManagedType<X>> getSubtypes()
Returns the collection of entity types that are subclasses of this managed type. The returned collection includes this type itself (the trivial subtype)!

Returns:

fromJson

public abstract X fromJson(javax.persistence.EntityManager em,
                           com.google.gwt.json.client.JSONValue jsonValue)
Converts the given JSONValue, which represents an instance of this entity type, into the actual instance of this entity type that exists in the given EntityManager's persistence context. References to other identifiable objects are recursively retrieved from the EntityManager.

Parameters:
em - The EntityManager that owns this entity type and houses the persistence context.
jsonValue - A value that represents an instance of this entity type.
Returns:
A managed entity that is in the given EntityManager's persistence context.

toJson

public com.google.gwt.json.client.JSONValue toJson(javax.persistence.EntityManager em,
                                                   X sourceEntity)

mergeState

public void mergeState(ErraiEntityManager em,
                       X targetEntity,
                       X sourceEntity)
Copies the state of the attributes in sourceEntity into targetEntity. Related entities are resolved from the given entity manager before the state is copied.

Parameters:
em - The entity manager that sourceEntity and targetEntity exist in.
targetEntity - The entity whose attributes' state will be written to. Not null.
sourceEntity - The entity whose attributes' state will be read from. Not null.

parseInlineJson

protected <Y> void parseInlineJson(X targetEntity,
                                   ErraiAttribute<? super X,Y> attr,
                                   com.google.gwt.json.client.JSONValue attrJsonValue,
                                   ErraiEntityManager eem)

parseSingularJsonReference

protected <Y> void parseSingularJsonReference(X targetEntity,
                                              ErraiSingularAttribute<? super X,Y> attr,
                                              com.google.gwt.json.client.JSONValue attrJsonValue,
                                              ErraiEntityManager eem)

parsePluralJsonReference

protected <C,E> void parsePluralJsonReference(X targetEntity,
                                              ErraiPluralAttribute<? super X,C,E> attr,
                                              com.google.gwt.json.client.JSONArray attrJsonValues,
                                              ErraiEntityManager eem)

getAttributes

public Set<javax.persistence.metamodel.Attribute<? super X,?>> getAttributes()
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the attributes of the managed type.

Specified by:
getAttributes in interface javax.persistence.metamodel.ManagedType<X>
Returns:
attributes of the managed type

getDeclaredAttributes

public Set<javax.persistence.metamodel.Attribute<X,?>> getDeclaredAttributes()
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the attributes declared by the managed type. Returns empty set if the managed type has no declared attributes.

Specified by:
getDeclaredAttributes in interface javax.persistence.metamodel.ManagedType<X>
Returns:
declared attributes of the managed type

getSingularAttribute

public <Y> ErraiSingularAttribute<? super X,Y> getSingularAttribute(String name,
                                                                    Class<Y> type)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the single-valued attribute of the managed type that corresponds to the specified name and Java type.

Specified by:
getSingularAttribute in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
type - the type of the represented attribute
Returns:
single-valued attribute with given name and type

getDeclaredSingularAttribute

public <Y> javax.persistence.metamodel.SingularAttribute<X,Y> getDeclaredSingularAttribute(String name,
                                                                                           Class<Y> type)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the single-valued attribute declared by the managed type that corresponds to the specified name and Java type.

Specified by:
getDeclaredSingularAttribute in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
type - the type of the represented attribute
Returns:
declared single-valued attribute of the given name and type

getSingularAttributes

public Set<javax.persistence.metamodel.SingularAttribute<? super X,?>> getSingularAttributes()
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the single-valued attributes of the managed type. Returns empty set if the managed type has no single-valued attributes.

Specified by:
getSingularAttributes in interface javax.persistence.metamodel.ManagedType<X>
Returns:
single-valued attributes

getDeclaredSingularAttributes

public Set<javax.persistence.metamodel.SingularAttribute<X,?>> getDeclaredSingularAttributes()
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the single-valued attributes declared by the managed type. Returns empty set if the managed type has no declared single-valued attributes.

Specified by:
getDeclaredSingularAttributes in interface javax.persistence.metamodel.ManagedType<X>
Returns:
declared single-valued attributes

getCollection

public <E> javax.persistence.metamodel.CollectionAttribute<? super X,E> getCollection(String name,
                                                                                      Class<E> elementType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Collection-valued attribute of the managed type that corresponds to the specified name and Java element type.

Specified by:
getCollection in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
elementType - the element type of the represented attribute
Returns:
CollectionAttribute of the given name and element type

getDeclaredCollection

public <E> javax.persistence.metamodel.CollectionAttribute<X,E> getDeclaredCollection(String name,
                                                                                      Class<E> elementType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Collection-valued attribute declared by the managed type that corresponds to the specified name and Java element type.

Specified by:
getDeclaredCollection in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
elementType - the element type of the represented attribute
Returns:
declared CollectionAttribute of the given name and element type

getSet

public <E> javax.persistence.metamodel.SetAttribute<? super X,E> getSet(String name,
                                                                        Class<E> elementType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Set-valued attribute of the managed type that corresponds to the specified name and Java element type.

Specified by:
getSet in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
elementType - the element type of the represented attribute
Returns:
SetAttribute of the given name and element type

getDeclaredSet

public <E> javax.persistence.metamodel.SetAttribute<X,E> getDeclaredSet(String name,
                                                                        Class<E> elementType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Set-valued attribute declared by the managed type that corresponds to the specified name and Java element type.

Specified by:
getDeclaredSet in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
elementType - the element type of the represented attribute
Returns:
declared SetAttribute of the given name and element type

getList

public <E> javax.persistence.metamodel.ListAttribute<? super X,E> getList(String name,
                                                                          Class<E> elementType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the List-valued attribute of the managed type that corresponds to the specified name and Java element type.

Specified by:
getList in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
elementType - the element type of the represented attribute
Returns:
ListAttribute of the given name and element type

getDeclaredList

public <E> javax.persistence.metamodel.ListAttribute<X,E> getDeclaredList(String name,
                                                                          Class<E> elementType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the List-valued attribute declared by the managed type that corresponds to the specified name and Java element type.

Specified by:
getDeclaredList in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
elementType - the element type of the represented attribute
Returns:
declared ListAttribute of the given name and element type

getMap

public <K,V> javax.persistence.metamodel.MapAttribute<? super X,K,V> getMap(String name,
                                                                            Class<K> keyType,
                                                                            Class<V> valueType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Map-valued attribute of the managed type that corresponds to the specified name and Java key and value types.

Specified by:
getMap in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
keyType - the key type of the represented attribute
valueType - the value type of the represented attribute
Returns:
MapAttribute of the given name and key and value types

getDeclaredMap

public <K,V> javax.persistence.metamodel.MapAttribute<X,K,V> getDeclaredMap(String name,
                                                                            Class<K> keyType,
                                                                            Class<V> valueType)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Map-valued attribute declared by the managed type that corresponds to the specified name and Java key and value types.

Specified by:
getDeclaredMap in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
keyType - the key type of the represented attribute
valueType - the value type of the represented attribute
Returns:
declared MapAttribute of the given name and key and value types

getPluralAttributes

public Set<javax.persistence.metamodel.PluralAttribute<? super X,?,?>> getPluralAttributes()
Description copied from interface: javax.persistence.metamodel.ManagedType
Return all multi-valued attributes (Collection-, Set-, List-, and Map-valued attributes) of the managed type. Returns empty set if the managed type has no multi-valued attributes.

Specified by:
getPluralAttributes in interface javax.persistence.metamodel.ManagedType<X>
Returns:
Collection-, Set-, List-, and Map-valued attributes

getDeclaredPluralAttributes

public Set<javax.persistence.metamodel.PluralAttribute<X,?,?>> getDeclaredPluralAttributes()
Description copied from interface: javax.persistence.metamodel.ManagedType
Return all multi-valued attributes (Collection-, Set-, List-, and Map-valued attributes) declared by the managed type. Returns empty set if the managed type has no declared multi-valued attributes.

Specified by:
getDeclaredPluralAttributes in interface javax.persistence.metamodel.ManagedType<X>
Returns:
declared Collection-, Set-, List-, and Map-valued attributes

getAttribute

public ErraiAttribute<? super X,?> getAttribute(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the attribute of the managed type that corresponds to the specified name.

Specified by:
getAttribute in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
attribute with given name

getDeclaredAttribute

public javax.persistence.metamodel.Attribute<X,?> getDeclaredAttribute(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the attribute declared by the managed type that corresponds to the specified name.

Specified by:
getDeclaredAttribute in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
attribute with given name

getSingularAttribute

public javax.persistence.metamodel.SingularAttribute<? super X,?> getSingularAttribute(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the single-valued attribute of the managed type that corresponds to the specified name.

Specified by:
getSingularAttribute in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
single-valued attribute with the given name

getDeclaredSingularAttribute

public javax.persistence.metamodel.SingularAttribute<X,?> getDeclaredSingularAttribute(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the single-valued attribute declared by the managed type that corresponds to the specified name.

Specified by:
getDeclaredSingularAttribute in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
declared single-valued attribute of the given name

getCollection

public javax.persistence.metamodel.CollectionAttribute<? super X,?> getCollection(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Collection-valued attribute of the managed type that corresponds to the specified name.

Specified by:
getCollection in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
CollectionAttribute of the given name

getDeclaredCollection

public javax.persistence.metamodel.CollectionAttribute<X,?> getDeclaredCollection(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Collection-valued attribute declared by the managed type that corresponds to the specified name.

Specified by:
getDeclaredCollection in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
declared CollectionAttribute of the given name

getSet

public javax.persistence.metamodel.SetAttribute<? super X,?> getSet(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Set-valued attribute of the managed type that corresponds to the specified name.

Specified by:
getSet in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
SetAttribute of the given name

getDeclaredSet

public javax.persistence.metamodel.SetAttribute<X,?> getDeclaredSet(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Set-valued attribute declared by the managed type that corresponds to the specified name.

Specified by:
getDeclaredSet in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
declared SetAttribute of the given name

getList

public javax.persistence.metamodel.ListAttribute<? super X,?> getList(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the List-valued attribute of the managed type that corresponds to the specified name.

Specified by:
getList in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
ListAttribute of the given name

getDeclaredList

public javax.persistence.metamodel.ListAttribute<X,?> getDeclaredList(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the List-valued attribute declared by the managed type that corresponds to the specified name.

Specified by:
getDeclaredList in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
declared ListAttribute of the given name

getMap

public javax.persistence.metamodel.MapAttribute<? super X,?,?> getMap(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Map-valued attribute of the managed type that corresponds to the specified name.

Specified by:
getMap in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
MapAttribute of the given name

getDeclaredMap

public javax.persistence.metamodel.MapAttribute<X,?,?> getDeclaredMap(String name)
Description copied from interface: javax.persistence.metamodel.ManagedType
Return the Map-valued attribute declared by the managed type that corresponds to the specified name.

Specified by:
getDeclaredMap in interface javax.persistence.metamodel.ManagedType<X>
Parameters:
name - the name of the represented attribute
Returns:
declared MapAttribute of the given name

getJavaType

public Class<X> getJavaType()
Description copied from interface: javax.persistence.metamodel.Type
Return the represented Java type.

Specified by:
getJavaType in interface javax.persistence.metamodel.Type<X>
Returns:
Java type

toString

public String toString()
Overrides:
toString in class Object

Errai 3.0.1-SNAPSHOT

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