@Component(value="cuba_MetadataTools")
public class MetadataTools
extends java.lang.Object
Metadata.getTools()
.Modifier and Type | Class and Description |
---|---|
static class |
MetadataTools.CachingEntitiesHolder |
static interface |
MetadataTools.EntitiesHolder |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
EMBEDDED_ANN_NAME |
static java.lang.String |
NAME |
static java.lang.String |
PERSISTENT_ANN_NAME |
static java.lang.String |
PRIMARY_KEY_ANN_NAME |
static java.lang.String |
STORE_ANN_NAME |
static java.lang.String |
SYSTEM_ANN_NAME |
static java.util.List<java.lang.Class> |
SYSTEM_INTERFACES |
static java.lang.String |
TEMPORAL_ANN_NAME |
Constructor and Description |
---|
MetadataTools()
Default constructor used by container at runtime and in server-side integration tests.
|
Modifier and Type | Method and Description |
---|---|
void |
copy(Instance source,
Instance dest)
Make a shallow copy of an instance.
|
<T extends Instance> |
copy(T source)
Create a new instance and make it a shallow copy of the instance given.
|
void |
deepCopy(Entity source,
Entity destination,
MetadataTools.EntitiesHolder entitiesHolder)
Copies all property values from source to destination excluding null values.
|
<T extends Entity> |
deepCopy(T source)
Makes a deep copy of the source entity.
|
java.lang.String |
format(java.lang.Object value)
Formats a value according to the value type.
|
java.lang.String |
format(java.lang.Object value,
MetaProperty property)
Formats a value according to the property type.
|
java.util.Collection<MetaClass> |
getAllEmbeddableMetaClasses() |
java.util.Collection<java.lang.Class> |
getAllEnums() |
java.util.Collection<MetaClass> |
getAllPersistentMetaClasses() |
java.lang.String |
getCrossDataStoreReferenceIdProperty(java.lang.String thisStore,
MetaProperty metaProperty)
If the given property is a reference to an entity from different data store, returns the name of a persistent
property which stores the identifier of the related entity.
|
java.lang.String |
getDatabaseColumn(MetaProperty metaProperty) |
java.lang.String |
getDatabaseTable(MetaClass metaClass) |
java.lang.String |
getEntityName(java.lang.Class<?> entityClass) |
java.util.Map<java.lang.String,java.lang.Object> |
getMetaAnnotationAttributes(java.util.Map<java.lang.String,java.lang.Object> metaAnnotations,
java.lang.Class metaAnnotationClass) |
<T> T |
getMetaAnnotationValue(MetaProperty metaProperty,
java.lang.Class metaAnnotationClass) |
java.util.Collection<MetaProperty> |
getNamePatternProperties(MetaClass metaClass)
Return a collection of properties included into entity's name pattern (see
NamePattern ). |
java.util.Collection<MetaProperty> |
getNamePatternProperties(MetaClass metaClass,
boolean useOriginal)
Return a collection of properties included into entity's name pattern (see
NamePattern ). |
java.lang.String |
getPrimaryKeyName(MetaClass metaClass) |
MetaProperty |
getPrimaryKeyProperty(MetaClass metaClass) |
MetaClass |
getPropertyEnclosingMetaClass(MetaPropertyPath propertyPath)
Get metaclass that contains metaproperty for passed propertyPath.
|
java.util.Collection<MetaPropertyPath> |
getPropertyPaths(MetaClass metaClass) |
java.util.List<java.lang.String> |
getRelatedProperties(java.lang.Class<?> entityClass,
java.lang.String property) |
java.util.List<java.lang.String> |
getRelatedProperties(MetaProperty metaProperty) |
java.lang.String |
getStoreName(MetaClass metaClass) |
java.util.Collection<MetaPropertyPath> |
getViewPropertyPaths(View view,
MetaClass metaClass)
Collects all meta-properties of the given meta-class included to the given view as
MetaPropertyPath s. |
boolean |
hasCompositePrimaryKey(MetaClass metaClass) |
boolean |
isAnnotationPresent(java.lang.Class javaClass,
java.lang.String property,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Determine whether the given annotation is present in the object's class or in any of its superclasses.
|
boolean |
isAnnotationPresent(java.lang.Object object,
java.lang.String property,
java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
Determine whether the given annotation is present in the object's class or in any of its superclasses.
|
boolean |
isAssignableFrom(MetaClass metaClass,
MetaClass other) |
boolean |
isCacheable(MetaClass metaClass) |
boolean |
isCascade(MetaProperty metaProperty)
Determine whether an object denoted by the given property is merged into persistence context together with the
owning object.
|
boolean |
isEmbeddable(MetaClass metaClass)
Determine whether the given metaclass is embeddable.
|
boolean |
isEmbedded(MetaProperty metaProperty)
Determine whether the given property denotes an embedded object.
|
boolean |
isLob(MetaProperty metaProperty)
Determine whether the given property is a LOB.
|
boolean |
isNotPersistent(java.lang.Class aClass)
Determine whether the given class represents a non-persistent entity.
|
boolean |
isNotPersistent(MetaClass metaClass)
Determine whether the given metaclass represents a non-persistent entity.
|
boolean |
isNotPersistent(MetaClass metaClass,
MetaProperty metaProperty)
Determine whether the given property is not persistent.
|
boolean |
isNotPersistent(MetaProperty metaProperty)
Determine whether the given property is not persistent.
|
boolean |
isNotPersistent(java.lang.Object object,
java.lang.String property)
Determine whether the given property is not persistent.
|
boolean |
isOwningSide(MetaProperty metaProperty)
Determine whether the given property is on the owning side of an association.
|
boolean |
isPersistent(java.lang.Class aClass)
Determine whether the given class represents a persistent entity.
|
boolean |
isPersistent(MetaClass metaClass)
Determine whether the given metaclass represents a persistent entity.
|
boolean |
isPersistent(MetaClass metaClass,
MetaProperty metaProperty)
Determine whether the given property is persistent, that is managed by ORM.
|
boolean |
isPersistent(MetaProperty metaProperty)
Determine whether the given property is persistent, that is managed by ORM.
|
boolean |
isPersistent(MetaPropertyPath metaPropertyPath)
Determine whether all the properties defined by the given property path are persistent.
|
boolean |
isSoftDeleted(java.lang.Class entityClass)
Determine whether the entity supports Soft Deletion.
|
boolean |
isSystem(MetaProperty metaProperty)
Determine whether the given property is system-level.
|
boolean |
isSystemLevel(MetaClass metaClass)
Determine whether the given entity is marked as
SystemLevel . |
boolean |
isSystemLevel(MetaProperty metaProperty)
Determine whether the given property is marked as
SystemLevel . |
boolean |
isTransient(java.lang.Class aClass)
Deprecated.
|
boolean |
isTransient(MetaClass metaClass)
Deprecated.
|
boolean |
isTransient(MetaProperty metaProperty)
Deprecated.
|
boolean |
isTransient(java.lang.Object object,
java.lang.String property)
Deprecated.
|
MetaPropertyPath |
resolveMetaPropertyPath(MetaClass metaClass,
java.lang.String propertyPath)
Returns a
MetaPropertyPath which can include the special MetaProperty for a dynamic attribute. |
MetaPropertyPath |
resolveMetaPropertyPathNN(MetaClass metaClass,
java.lang.String propertyPath)
Returns a
MetaPropertyPath which can include the special MetaProperty for a dynamic attribute. |
java.util.Collection<MetaPropertyPath> |
toPropertyPaths(java.util.Collection<MetaProperty> properties)
Converts a collection of properties to collection of
MetaPropertyPath s containing one property each |
void |
traverseAttributes(Entity entity,
EntityAttributeVisitor visitor)
Depth-first traversal of the object graph starting from the specified entity instance.
|
void |
traverseAttributesByView(View view,
Entity entity,
EntityAttributeVisitor visitor)
Depth-first traversal of the object graph by the view starting from the specified entity instance.
|
void |
traverseLoadedAttributesByView(View view,
Entity entity,
EntityAttributeVisitor visitor)
Depth-first traversal of the object graph by the view starting from the specified entity instance.
|
boolean |
viewContainsProperty(View view,
MetaPropertyPath propertyPath)
Determine whether the view contains a property, traversing a view branch according to the given property path.
|
public static final java.lang.String NAME
public static final java.lang.String PERSISTENT_ANN_NAME
public static final java.lang.String PRIMARY_KEY_ANN_NAME
public static final java.lang.String EMBEDDED_ANN_NAME
public static final java.lang.String TEMPORAL_ANN_NAME
public static final java.lang.String SYSTEM_ANN_NAME
public static final java.lang.String STORE_ANN_NAME
public static final java.util.List<java.lang.Class> SYSTEM_INTERFACES
public MetadataTools()
public java.lang.String format(@Nullable java.lang.Object value, MetaProperty property)
value
- object to formatproperty
- metadatapublic java.lang.String format(@Nullable java.lang.Object value)
value
- object to format@Nullable public java.lang.String getStoreName(MetaClass metaClass)
@Nullable public java.lang.String getPrimaryKeyName(MetaClass metaClass)
@Nullable public MetaProperty getPrimaryKeyProperty(MetaClass metaClass)
public boolean hasCompositePrimaryKey(MetaClass metaClass)
public boolean isAssignableFrom(MetaClass metaClass, MetaClass other)
public boolean isCascade(MetaProperty metaProperty)
public boolean isSoftDeleted(java.lang.Class entityClass)
entityClass
- entity classtrue
if the entity implements SoftDelete
public boolean isSystem(MetaProperty metaProperty)
public boolean isPersistent(MetaPropertyPath metaPropertyPath)
public boolean isPersistent(MetaProperty metaProperty)
A property is persistent if it is defined in a class registered in persistence.xml and the corresponding
attribute is managed by ORM, i.e. has an annotation like @Column
, @JoinColumn
, etc.
Note that for properties of non-persistent classes inherited from base classes like BaseUuidEntity
this method returns true. This is because a meta-property belongs to a class where it is defined, and this method
has no input identifying the real class of interest.
E.g. if you have class Foo extends BaseUuidEntity
, then for the Foo.id
attribute the method
returns true even if the Foo
is defined in metadata.xml and hence not persistent.
If you need a strict check of whether a certain attribute of an entity is stored in the database via ORM, use
isPersistent(MetaClass, MetaProperty)
.
public boolean isPersistent(MetaClass metaClass, MetaProperty metaProperty)
public boolean isNotPersistent(java.lang.Object object, java.lang.String property)
isPersistent(MetaClass, MetaProperty)
.
For objects and properties not registered in metadata this method returns true
.
public boolean isNotPersistent(MetaProperty metaProperty)
isPersistent(MetaProperty)
.public boolean isNotPersistent(MetaClass metaClass, MetaProperty metaProperty)
isPersistent(MetaClass, MetaProperty)
.public boolean isEmbedded(MetaProperty metaProperty)
Embedded
public boolean isLob(MetaProperty metaProperty)
Lob
public boolean isOwningSide(MetaProperty metaProperty)
public boolean isSystemLevel(MetaClass metaClass)
SystemLevel
.public boolean isSystemLevel(MetaProperty metaProperty)
SystemLevel
.public java.util.Map<java.lang.String,java.lang.Object> getMetaAnnotationAttributes(java.util.Map<java.lang.String,java.lang.Object> metaAnnotations, java.lang.Class metaAnnotationClass)
public <T> T getMetaAnnotationValue(MetaProperty metaProperty, java.lang.Class metaAnnotationClass)
public boolean isAnnotationPresent(java.lang.Object object, java.lang.String property, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
object
- entity instanceproperty
- property nameannotationClass
- annotation classpublic boolean isAnnotationPresent(java.lang.Class javaClass, java.lang.String property, java.lang.Class<? extends java.lang.annotation.Annotation> annotationClass)
javaClass
- entity classproperty
- property nameannotationClass
- annotation classpublic boolean isPersistent(MetaClass metaClass)
A persistent entity is an entity that is managed by ORM (i.e. registered in a persistence.xml file) and is not a MappedSuperclass or Embeddable.
public boolean isPersistent(java.lang.Class aClass)
A persistent entity is an entity that is managed by ORM (i.e. registered in a persistence.xml file) and is not a MappedSuperclass or Embeddable.
public boolean isNotPersistent(MetaClass metaClass)
A non-persistent entity is not managed by ORM (i.e. registered in a metadata.xml file).
Note that isNotPersistent()
is not the same as !isPersistent()
, because the latter does not
include MappedSuperclass and Embeddable entities that a still managed by ORM.
public boolean isNotPersistent(java.lang.Class aClass)
A non-persistent entity is not managed by ORM (i.e. registered in a metadata.xml file).
Note that isNotPersistent()
is not the same as !isPersistent()
, because the latter does not
include MappedSuperclass and Embeddable entities that a still managed by ORM.
public boolean isEmbeddable(MetaClass metaClass)
public boolean isCacheable(MetaClass metaClass)
public MetaClass getPropertyEnclosingMetaClass(MetaPropertyPath propertyPath)
propertyPath
- Property path@Nonnull public java.util.Collection<MetaProperty> getNamePatternProperties(MetaClass metaClass)
NamePattern
).metaClass
- entity metaclass@Nonnull public java.util.Collection<MetaProperty> getNamePatternProperties(MetaClass metaClass, boolean useOriginal)
NamePattern
).metaClass
- entity metaclassuseOriginal
- if true, and if the given metaclass doesn't define a NamePattern
and if it is an
extended entity, this method tries to find a name pattern in an original entitypublic java.util.Collection<MetaPropertyPath> getPropertyPaths(MetaClass metaClass)
MetaPropertyPath
s containing one property eachpublic java.util.Collection<MetaPropertyPath> toPropertyPaths(java.util.Collection<MetaProperty> properties)
MetaPropertyPath
s containing one property eachpublic java.util.Collection<MetaPropertyPath> getViewPropertyPaths(View view, MetaClass metaClass)
MetaPropertyPath
s.view
- viewmetaClass
- meta-classpublic boolean viewContainsProperty(@Nullable View view, MetaPropertyPath propertyPath)
view
- view instance. If null, return false immediately.propertyPath
- property path defining the propertypublic java.util.Collection<MetaClass> getAllPersistentMetaClasses()
public java.util.Collection<MetaClass> getAllEmbeddableMetaClasses()
public java.util.Collection<java.lang.Class> getAllEnums()
public java.lang.String getEntityName(java.lang.Class<?> entityClass)
entityClass
- entity classEntity
annotation@Nullable public java.lang.String getDatabaseTable(MetaClass metaClass)
@Nullable public java.lang.String getDatabaseColumn(MetaProperty metaProperty)
public java.util.List<java.lang.String> getRelatedProperties(java.lang.Class<?> entityClass, java.lang.String property)
MetaProperty.related()
or empty listpublic java.util.List<java.lang.String> getRelatedProperties(MetaProperty metaProperty)
MetaProperty.related()
or empty list@Nullable public java.lang.String getCrossDataStoreReferenceIdProperty(java.lang.String thisStore, MetaProperty metaProperty)
thisStore
- name of a base data storemetaProperty
- property@Nullable public MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, java.lang.String propertyPath)
MetaPropertyPath
which can include the special MetaProperty for a dynamic attribute.metaClass
- originating meta-classpropertyPath
- path to the attributepublic MetaPropertyPath resolveMetaPropertyPathNN(MetaClass metaClass, java.lang.String propertyPath)
MetaPropertyPath
which can include the special MetaProperty for a dynamic attribute.
Throws an IllegalArgumentException if MetaPropertyPath can't be resolved.metaClass
- originating meta-classpropertyPath
- path to the attributepublic void traverseAttributes(Entity entity, EntityAttributeVisitor visitor)
entity
- entity graph entry pointvisitor
- the attribute visitor implementationpublic void traverseAttributesByView(View view, Entity entity, EntityAttributeVisitor visitor)
view
- view instanceentity
- entity graph entry pointvisitor
- the attribute visitor implementationpublic void traverseLoadedAttributesByView(View view, Entity entity, EntityAttributeVisitor visitor)
view
- view instanceentity
- entity graph entry pointvisitor
- the attribute visitor implementationpublic <T extends Instance> T copy(T source)
Instance.getMetaClass()
method
which should not return null.source
- source instancepublic void copy(Instance source, Instance dest)
Instance.getMetaClass()
method which should not return null for both
objects. source
- source instancedest
- destination instancepublic <T extends Entity> T deepCopy(T source)
public void deepCopy(Entity source, Entity destination, MetadataTools.EntitiesHolder entitiesHolder)
@Deprecated public boolean isTransient(MetaClass metaClass)
isNotPersistent(MetaClass)
.@Deprecated public boolean isTransient(java.lang.Class aClass)
isNotPersistent(Class)
.@Deprecated public boolean isTransient(java.lang.Object object, java.lang.String property)
isNotPersistent(Object, String)
.@Deprecated public boolean isTransient(MetaProperty metaProperty)
isNotPersistent(MetaProperty)
.