org.apache.openjpa.persistence.meta
Class AbstractManagedType<X>

java.lang.Object
  extended by org.apache.openjpa.persistence.meta.Types.BaseType<X>
      extended by org.apache.openjpa.persistence.meta.AbstractManagedType<X>
Type Parameters:
X - the
All Implemented Interfaces:
ManagedType<X>, Type<X>
Direct Known Subclasses:
Types.Embeddable, Types.Identifiable, Types.PseudoEntity

public abstract class AbstractManagedType<X>
extends Types.BaseType<X>
implements ManagedType<X>

Implements the managed persistent type and its attributes. Provides identity and version attribute facilities for Identifiable type but does not implement it.

Author:
Pinaki Poddar

Nested Class Summary
static class AbstractManagedType.AttributeNameFilter<X>
           
static class AbstractManagedType.AttributeTypeFilter<X,Y>
          Selects if the attribute type matches the given Java class.
static class AbstractManagedType.DeclaredAttributeFilter<X>
           
static class AbstractManagedType.ElementTypeFilter<X,E>
          Selects plural attribute of given element type.
static class AbstractManagedType.EntryTypeFilter<X,K,V>
           
static interface AbstractManagedType.Filter<T>
          Affirms if a given element satisfy a condition.
static class AbstractManagedType.IdAttributeFilter<X>
           
static class AbstractManagedType.PluralCategoryFilter<X>
           
static class AbstractManagedType.SingularAttributeFilter<X>
          Affirms if the given attribute is a Singular attribute.
static class AbstractManagedType.VersionAttributeFilter<X>
           
 
Nested classes/interfaces inherited from interface javax.persistence.metamodel.Type
Type.PersistenceType
 
Field Summary
 ClassMetaData meta
           
 MetamodelImpl model
           
 
Fields inherited from class org.apache.openjpa.persistence.meta.Types.BaseType
cls
 
Constructor Summary
protected AbstractManagedType(Class<X> cls, MetamodelImpl model)
          A protected constructor for creating psudo-managed types.
  AbstractManagedType(ClassMetaData meta, MetamodelImpl model)
          Construct a managed type.
 
Method Summary
(package private)  void assertType(String msg, FieldMetaData fmd, Class<?> actual, Class<?> expected)
           
(package private) static
<T,C extends Collection<E>,E>
C
filter(Collection<T> original, C result, AbstractManagedType.Filter<T> f1)
           
(package private) static
<T,C extends Collection<E>,E>
C
filter(Collection<T> original, C result, AbstractManagedType.Filter<T> f1, AbstractManagedType.Filter<T> f2)
           
(package private) static
<T,C extends Collection<E>,E>
C
filter(Collection<T> original, C result, AbstractManagedType.Filter<T> f1, AbstractManagedType.Filter<T> f2, AbstractManagedType.Filter<T> f3)
           
static
<T,C extends Collection<E>,E>
C
filter(Collection<T> original, C result, AbstractManagedType.Filter<T> f1, AbstractManagedType.Filter<T> f2, AbstractManagedType.Filter<T> f3, AbstractManagedType.Filter<T> f4)
          Applies chain of filters ANDed on the given collection to populate the given result.
 Attribute<? super X,?> getAttribute(String name)
          Returns the attribute of the given name of any type.
<Y> Attribute<? super X,Y>
getAttribute(String name, Class<Y> type)
          Returns the attribute of the given name and Java type.
 Set<Attribute<? super X,?>> getAttributes()
          Returns all the attributes of the managed type including attributes of the super type.
 CollectionAttribute<? super X,?> getCollection(String name)
          Returns the attribute of the given name and of type java.util.Collection.
<E> CollectionAttribute<? super X,E>
getCollection(String name, Class<E> elementType)
          Returns the attribute of the given name, of type java.util.Collection and contains the given element type.
 Attribute<X,?> getDeclaredAttribute(String name)
          Returns the declared attribute of the given name of any type.
<Y> Attribute<X,Y>
getDeclaredAttribute(String name, Class<Y> type)
          Returns the declared attribute of the given name and Java type.
 Set<Attribute<X,?>> getDeclaredAttributes()
          Returns all the attributes declared by this managed type only.
 CollectionAttribute<X,?> getDeclaredCollection(String name)
          Returns the declared attribute of the given name and of type java.util.Collection.
<E> CollectionAttribute<X,E>
getDeclaredCollection(String name, Class<E> elementType)
          Returns the declared attribute of the given name, of type java.util.Collection and contains the given element type.
<Y> SingularAttribute<X,Y>
getDeclaredId(Class<Y> type)
          Returns the declared attribute of given type that corresponds to the id attribute of this identifiable managed type.
 ListAttribute<X,?> getDeclaredList(String name)
          Returns the declared attribute of the given name and of type java.util.List.
<E> ListAttribute<X,E>
getDeclaredList(String name, Class<E> elementType)
          Returns the declared attribute of the given name, of type java.util.List and contains the given element type.
 MapAttribute<X,?,?> getDeclaredMap(String name)
          Returns the declared attribute of the given name and of type java.util.Map.
<K,V> MapAttribute<X,K,V>
getDeclaredMap(String name, Class<K> keyType, Class<V> valueType)
          Returns the declared attribute of the given name, of type java.util.Map and contains the given key/value type.
 Set<PluralAttribute<X,?,?>> getDeclaredPluralAttributes()
          Return all collection-valued attributes declared by the managed type.
 SetAttribute<X,?> getDeclaredSet(String name)
          Returns the declared attribute of the given name and of type java.util.Set.
<E> SetAttribute<X,E>
getDeclaredSet(String name, Class<E> elementType)
          Returns the declared attribute of the given name, of type java.util.Set and contains the given element type.
 SingularAttribute<X,?> getDeclaredSingularAttribute(String name)
          Returns the declared, single-valued attribute of the given name of any type.
<Y> SingularAttribute<X,Y>
getDeclaredSingularAttribute(String name, Class<Y> type)
          Returns the declared single-valued attribute of the given name and Java type.
 Set<SingularAttribute<X,?>> getDeclaredSingularAttributes()
          Returns the single-valued attributes declared by the managed type.
<Y> SingularAttribute<X,Y>
getDeclaredVersion(Class<Y> type)
          Returns the declared attribute of given type that corresponds to the version attribute of this managed type.
(package private)  FieldMetaData getField(String name)
           
(package private)  FieldMetaData getField(String name, Class type)
           
(package private)  FieldMetaData getField(String name, Class<?> type, Class<?> elementType, Class<?> keyType, boolean decl)
          Get the field of the given name after validating the conditions.
(package private)  FieldMetaData getField(String name, Class type, boolean declaredOnly)
           
<Y> SingularAttribute<? super X,Y>
getId(Class<Y> type)
          Returns the attribute of given type that corresponds to the id attribute of this identifiable managed type.
 Set<SingularAttribute<? super X,?>> getIdClassAttributes()
          Returns the attributes corresponding to the id class of the identifiable type.
 ListAttribute<? super X,?> getList(String name)
          Returns the attribute of the given name and of type java.util.List.
<E> ListAttribute<? super X,E>
getList(String name, Class<E> elementType)
          Returns the attribute of the given name, of type java.util.List and contains the given element type.
 MapAttribute<? super X,?,?> getMap(String name)
          Returns the attribute of the given name and of type java.util.Map.
<K,V> MapAttribute<? super X,K,V>
getMap(String name, Class<K> keyType, Class<V> valueType)
          Returns the attribute of the given name, of type java.util.Map and contains the given key/value type.
 Set<PluralAttribute<? super X,?,?>> getPluralAttributes()
          Returns all collection-valued attributes of the managed type.
 SetAttribute<? super X,?> getSet(String name)
          Returns the attribute of the given name and of type java.util.Set.
<E> SetAttribute<? super X,E>
getSet(String name, Class<E> elementType)
          Returns the attribute of the given name, of type java.util.Set and contains the given element type.
 SingularAttribute<? super X,?> getSingularAttribute(String name)
          Returns the single-valued attribute of the given name of any type.
<Y> SingularAttribute<? super X,Y>
getSingularAttribute(String name, Class<Y> type)
          Returns the single-valued attribute of the given name and Java type.
 Set<SingularAttribute<? super X,?>> getSingularAttributes()
          Returns the single-valued attributes of the managed type.
<Y> SingularAttribute<? super X,Y>
getVersion(Class<Y> type)
          Returns the attribute of given type that corresponds to the version attribute of this managed type.
(package private) static
<T> T
pick(Collection<T> original, AbstractManagedType.Filter<T> f1)
           
(package private) static
<T> T
pick(Collection<T> original, AbstractManagedType.Filter<T> f1, AbstractManagedType.Filter<T> f2)
           
(package private) static
<T> T
pick(Collection<T> original, AbstractManagedType.Filter<T> f1, AbstractManagedType.Filter<T> f2, AbstractManagedType.Filter<T> f3)
           
static
<T> T
pick(Collection<T> original, AbstractManagedType.Filter<T> f1, AbstractManagedType.Filter<T> f2, AbstractManagedType.Filter<T> f3, AbstractManagedType.Filter<T> f4)
          Applies chain of filters ANDed on the given collection to pick a single element.
(package private)  Class<?> wrap(Class<?> c)
           
 
Methods inherited from class org.apache.openjpa.persistence.meta.Types.BaseType
getJavaType, 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
getJavaType, getPersistenceType
 

Field Detail

model

public final MetamodelImpl model

meta

public final ClassMetaData meta
Constructor Detail

AbstractManagedType

protected AbstractManagedType(Class<X> cls,
                              MetamodelImpl model)
A protected constructor for creating psudo-managed types.


AbstractManagedType

public AbstractManagedType(ClassMetaData meta,
                           MetamodelImpl model)
Construct a managed type. The supplied metadata must be resolved i.e. all its fields populated. Because this receiver will populate its attributes corresponding to the available fields of the metadata.

Method Detail

getAttributes

public Set<Attribute<? super X,?>> getAttributes()
Returns all the attributes of the managed type including attributes of the super type.

Specified by:
getAttributes in interface ManagedType<X>

getDeclaredAttributes

public Set<Attribute<X,?>> getDeclaredAttributes()
Returns all the attributes declared by this managed type only.

Specified by:
getDeclaredAttributes in interface ManagedType<X>

getSingularAttributes

public Set<SingularAttribute<? super X,?>> getSingularAttributes()
Returns the single-valued attributes of the managed type.

Specified by:
getSingularAttributes in interface ManagedType<X>

getDeclaredSingularAttributes

public Set<SingularAttribute<X,?>> getDeclaredSingularAttributes()
Returns the single-valued attributes declared by the managed type.

Specified by:
getDeclaredSingularAttributes in interface ManagedType<X>

getAttribute

public <Y> Attribute<? super X,Y> getAttribute(String name,
                                               Class<Y> type)
Returns the attribute of the given name and Java type.

Throws:
IllegalArgumentException - if no such attribute exists

getSingularAttribute

public <Y> SingularAttribute<? super X,Y> getSingularAttribute(String name,
                                                               Class<Y> type)
Returns the single-valued attribute of the given name and Java type.

Specified by:
getSingularAttribute in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredAttribute

public <Y> Attribute<X,Y> getDeclaredAttribute(String name,
                                               Class<Y> type)
Returns the declared attribute of the given name and Java type.

Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredSingularAttribute

public <Y> SingularAttribute<X,Y> getDeclaredSingularAttribute(String name,
                                                               Class<Y> type)
Returns the declared single-valued attribute of the given name and Java type.

Specified by:
getDeclaredSingularAttribute in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getPluralAttributes

public Set<PluralAttribute<? super X,?,?>> getPluralAttributes()
Returns all collection-valued attributes of the managed type.

Specified by:
getPluralAttributes in interface ManagedType<X>

getDeclaredPluralAttributes

public Set<PluralAttribute<X,?,?>> getDeclaredPluralAttributes()
Return all collection-valued attributes declared by the managed type.

Specified by:
getDeclaredPluralAttributes in interface ManagedType<X>

getCollection

public <E> CollectionAttribute<? super X,E> getCollection(String name,
                                                          Class<E> elementType)
Returns the attribute of the given name, of type java.util.Collection and contains the given element type.

Specified by:
getCollection in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getSet

public <E> SetAttribute<? super X,E> getSet(String name,
                                            Class<E> elementType)
Returns the attribute of the given name, of type java.util.Set and contains the given element type.

Specified by:
getSet in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getList

public <E> ListAttribute<? super X,E> getList(String name,
                                              Class<E> elementType)
Returns the attribute of the given name, of type java.util.List and contains the given element type.

Specified by:
getList in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getMap

public <K,V> MapAttribute<? super X,K,V> getMap(String name,
                                                Class<K> keyType,
                                                Class<V> valueType)
Returns the attribute of the given name, of type java.util.Map and contains the given key/value type.

Specified by:
getMap in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredCollection

public <E> CollectionAttribute<X,E> getDeclaredCollection(String name,
                                                          Class<E> elementType)
Returns the declared attribute of the given name, of type java.util.Collection and contains the given element type.

Specified by:
getDeclaredCollection in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredSet

public <E> SetAttribute<X,E> getDeclaredSet(String name,
                                            Class<E> elementType)
Returns the declared attribute of the given name, of type java.util.Set and contains the given element type.

Specified by:
getDeclaredSet in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredList

public <E> ListAttribute<X,E> getDeclaredList(String name,
                                              Class<E> elementType)
Returns the declared attribute of the given name, of type java.util.List and contains the given element type.

Specified by:
getDeclaredList in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredMap

public <K,V> MapAttribute<X,K,V> getDeclaredMap(String name,
                                                Class<K> keyType,
                                                Class<V> valueType)
Returns the declared attribute of the given name, of type java.util.Map and contains the given key/value type.

Specified by:
getDeclaredMap in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getAttribute

public Attribute<? super X,?> getAttribute(String name)
Returns the attribute of the given name of any type.

Specified by:
getAttribute in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredAttribute

public Attribute<X,?> getDeclaredAttribute(String name)
Returns the declared attribute of the given name of any type.

Specified by:
getDeclaredAttribute in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getSingularAttribute

public SingularAttribute<? super X,?> getSingularAttribute(String name)
Returns the single-valued attribute of the given name of any type.

Specified by:
getSingularAttribute in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredSingularAttribute

public SingularAttribute<X,?> getDeclaredSingularAttribute(String name)
Returns the declared, single-valued attribute of the given name of any type.

Specified by:
getDeclaredSingularAttribute in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getCollection

public CollectionAttribute<? super X,?> getCollection(String name)
Returns the attribute of the given name and of type java.util.Collection.

Specified by:
getCollection in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getSet

public SetAttribute<? super X,?> getSet(String name)
Returns the attribute of the given name and of type java.util.Set.

Specified by:
getSet in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getList

public ListAttribute<? super X,?> getList(String name)
Returns the attribute of the given name and of type java.util.List.

Specified by:
getList in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getMap

public MapAttribute<? super X,?,?> getMap(String name)
Returns the attribute of the given name and of type java.util.Map.

Specified by:
getMap in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredCollection

public CollectionAttribute<X,?> getDeclaredCollection(String name)
Returns the declared attribute of the given name and of type java.util.Collection.

Specified by:
getDeclaredCollection in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredSet

public SetAttribute<X,?> getDeclaredSet(String name)
Returns the declared attribute of the given name and of type java.util.Set.

Specified by:
getDeclaredSet in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredList

public ListAttribute<X,?> getDeclaredList(String name)
Returns the declared attribute of the given name and of type java.util.List.

Specified by:
getDeclaredList in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredMap

public MapAttribute<X,?,?> getDeclaredMap(String name)
Returns the declared attribute of the given name and of type java.util.Map.

Specified by:
getDeclaredMap in interface ManagedType<X>
Throws:
IllegalArgumentException - if no such attribute exists

getIdClassAttributes

public final Set<SingularAttribute<? super X,?>> getIdClassAttributes()
Returns the attributes corresponding to the id class of the identifiable type.

Throws:
IllegalArgumentException - if the this type is not using an id class

getId

public final <Y> SingularAttribute<? super X,Y> getId(Class<Y> type)
Returns the attribute of given type that corresponds to the id attribute of this identifiable managed type.

Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredId

public final <Y> SingularAttribute<X,Y> getDeclaredId(Class<Y> type)
Returns the declared attribute of given type that corresponds to the id attribute of this identifiable managed type.

Throws:
IllegalArgumentException - if no such attribute exists

getVersion

public <Y> SingularAttribute<? super X,Y> getVersion(Class<Y> type)
Returns the attribute of given type that corresponds to the version attribute of this managed type.

Throws:
IllegalArgumentException - if no such attribute exists

getDeclaredVersion

public <Y> SingularAttribute<X,Y> getDeclaredVersion(Class<Y> type)
Returns the declared attribute of given type that corresponds to the version attribute of this managed type.

Throws:
IllegalArgumentException - if no such attribute exists

getField

FieldMetaData getField(String name)

getField

FieldMetaData getField(String name,
                       Class type)

getField

FieldMetaData getField(String name,
                       Class type,
                       boolean declaredOnly)

getField

FieldMetaData getField(String name,
                       Class<?> type,
                       Class<?> elementType,
                       Class<?> keyType,
                       boolean decl)
Get the field of the given name after validating the conditions. null value on any condition implies not to validate.

Parameters:
name - simple name i.e. without the class name
type - the expected type of the field.
element - the expected element type of the field.
key - the expected key type of the field.
declared - is this field declared in this receiver
Throws:
IllegalArgumentException - if any of the validation fails.

assertType

void assertType(String msg,
                FieldMetaData fmd,
                Class<?> actual,
                Class<?> expected)

wrap

Class<?> wrap(Class<?> c)

filter

public static <T,C extends Collection<E>,E> C filter(Collection<T> original,
                                                     C result,
                                                     AbstractManagedType.Filter<T> f1,
                                                     AbstractManagedType.Filter<T> f2,
                                                     AbstractManagedType.Filter<T> f3,
                                                     AbstractManagedType.Filter<T> f4)
Applies chain of filters ANDed on the given collection to populate the given result. A null filter evaluates always TRUE. The arguments are not passed as variable argument list to suppress warnings in in the caller for generic varargs array construction.


pick

public static <T> T pick(Collection<T> original,
                         AbstractManagedType.Filter<T> f1,
                         AbstractManagedType.Filter<T> f2,
                         AbstractManagedType.Filter<T> f3,
                         AbstractManagedType.Filter<T> f4)
Applies chain of filters ANDed on the given collection to pick a single element. A null filter evaluates always TRUE. The arguments are not passed as variable argument list to suppress warnings in in the caller for generic varargs array construction.


filter

static <T,C extends Collection<E>,E> C filter(Collection<T> original,
                                              C result,
                                              AbstractManagedType.Filter<T> f1)

filter

static <T,C extends Collection<E>,E> C filter(Collection<T> original,
                                              C result,
                                              AbstractManagedType.Filter<T> f1,
                                              AbstractManagedType.Filter<T> f2)

filter

static <T,C extends Collection<E>,E> C filter(Collection<T> original,
                                              C result,
                                              AbstractManagedType.Filter<T> f1,
                                              AbstractManagedType.Filter<T> f2,
                                              AbstractManagedType.Filter<T> f3)

pick

static <T> T pick(Collection<T> original,
                  AbstractManagedType.Filter<T> f1)

pick

static <T> T pick(Collection<T> original,
                  AbstractManagedType.Filter<T> f1,
                  AbstractManagedType.Filter<T> f2)

pick

static <T> T pick(Collection<T> original,
                  AbstractManagedType.Filter<T> f1,
                  AbstractManagedType.Filter<T> f2,
                  AbstractManagedType.Filter<T> f3)


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.