@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 |
static class |
MetadataTools.NamePatternRec |
Modifier and Type | Field and Description |
---|---|
protected com.haulmont.chile.core.datatypes.DatatypeRegistry |
datatypeRegistry |
protected DynamicAttributesTools |
dynamicAttributesTools |
static java.lang.String |
EMBEDDED_ANN_NAME |
protected java.util.Collection<java.lang.Class> |
enums |
protected GlobalConfig |
globalConfig |
protected Messages |
messages |
protected Metadata |
metadata |
static java.lang.String |
NAME |
static java.lang.String |
PERSISTENT_ANN_NAME |
protected PersistentAttributesLoadChecker |
persistentAttributesLoadChecker |
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 |
protected UserSessionSource |
userSessionSource |
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(com.haulmont.chile.core.model.Instance source,
com.haulmont.chile.core.model.Instance dest)
Make a shallow copy of an instance.
|
<T extends com.haulmont.chile.core.model.Instance> |
copy(T source)
Create a new instance and make it a shallow copy of the instance given.
|
protected static <T> T |
createInstance(java.lang.Class<T> aClass) |
protected static Entity |
createInstanceWithId(java.lang.Class<? extends Entity> entityClass,
java.lang.Object id) |
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,
com.haulmont.chile.core.model.MetaProperty property)
Formats a value according to the property type.
|
java.util.Collection<com.haulmont.chile.core.model.MetaClass> |
getAllEmbeddableMetaClasses() |
java.util.Collection<java.lang.Class> |
getAllEnums() |
java.util.Collection<com.haulmont.chile.core.model.MetaClass> |
getAllPersistentMetaClasses() |
java.lang.String |
getCrossDataStoreReferenceIdProperty(java.lang.String thisStore,
com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaProperty metaProperty) |
java.lang.String |
getDatabaseTable(com.haulmont.chile.core.model.MetaClass metaClass) |
java.lang.String |
getEntityName(java.lang.Class<?> entityClass) |
java.lang.String |
getInstanceName(com.haulmont.chile.core.model.Instance instance) |
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(com.haulmont.chile.core.model.MetaProperty metaProperty,
java.lang.Class metaAnnotationClass) |
java.util.Collection<com.haulmont.chile.core.model.MetaProperty> |
getNamePatternProperties(com.haulmont.chile.core.model.MetaClass metaClass)
Return a collection of properties included into entity's name pattern (see
NamePattern ). |
java.util.Collection<com.haulmont.chile.core.model.MetaProperty> |
getNamePatternProperties(com.haulmont.chile.core.model.MetaClass metaClass,
boolean useOriginal)
Return a collection of properties included into entity's name pattern (see
NamePattern ). |
java.lang.String |
getPrimaryKeyName(com.haulmont.chile.core.model.MetaClass metaClass) |
com.haulmont.chile.core.model.MetaProperty |
getPrimaryKeyProperty(java.lang.Class<?> entityClass) |
com.haulmont.chile.core.model.MetaProperty |
getPrimaryKeyProperty(com.haulmont.chile.core.model.MetaClass metaClass) |
com.haulmont.chile.core.model.MetaClass |
getPropertyEnclosingMetaClass(com.haulmont.chile.core.model.MetaPropertyPath propertyPath)
Get metaclass that contains metaproperty for passed propertyPath.
|
java.util.Collection<com.haulmont.chile.core.model.MetaPropertyPath> |
getPropertyPaths(com.haulmont.chile.core.model.MetaClass metaClass) |
java.util.List<java.lang.String> |
getRelatedProperties(java.lang.Class<?> entityClass,
java.lang.String property) |
java.util.List<java.lang.String> |
getRelatedProperties(com.haulmont.chile.core.model.MetaProperty metaProperty) |
java.lang.String |
getStoreName(com.haulmont.chile.core.model.MetaClass metaClass) |
java.util.Collection<com.haulmont.chile.core.model.MetaPropertyPath> |
getViewPropertyPaths(View view,
com.haulmont.chile.core.model.MetaClass metaClass)
Collects all meta-properties of the given meta-class included to the given view as
MetaPropertyPath s. |
boolean |
hasCompositePrimaryKey(com.haulmont.chile.core.model.MetaClass metaClass) |
protected void |
internalTraverseAttributes(Entity entity,
EntityAttributeVisitor visitor,
java.util.HashSet<java.lang.Object> visited) |
protected void |
internalTraverseAttributesByView(View view,
Entity entity,
EntityAttributeVisitor visitor,
java.util.Map<Entity,java.util.Set<View>> visited,
boolean checkLoaded) |
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(com.haulmont.chile.core.model.MetaClass metaClass,
com.haulmont.chile.core.model.MetaClass other) |
boolean |
isCacheable(com.haulmont.chile.core.model.MetaClass metaClass) |
boolean |
isCascade(com.haulmont.chile.core.model.MetaProperty metaProperty)
Determine whether an object denoted by the given property is merged into persistence context together with the
owning object.
|
boolean |
isEmbeddable(java.lang.Class aClass)
Determine whether the given entity class is persistent embeddable.
|
boolean |
isEmbeddable(com.haulmont.chile.core.model.MetaClass metaClass)
Determine whether the given meta-class is persistent embeddable.
|
boolean |
isEmbedded(com.haulmont.chile.core.model.MetaProperty metaProperty)
Determine whether the given property denotes an embedded object.
|
boolean |
isLob(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaClass metaClass)
Determine whether the given metaclass represents a non-persistent entity.
|
boolean |
isNotPersistent(com.haulmont.chile.core.model.MetaClass metaClass,
com.haulmont.chile.core.model.MetaProperty metaProperty)
Determine whether the given property is not persistent.
|
boolean |
isNotPersistent(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaClass metaClass)
Determine whether the given metaclass represents a persistent entity.
|
boolean |
isPersistent(com.haulmont.chile.core.model.MetaClass metaClass,
com.haulmont.chile.core.model.MetaProperty metaProperty)
Determine whether the given property is persistent, that is managed by ORM.
|
boolean |
isPersistent(com.haulmont.chile.core.model.MetaProperty metaProperty)
Determine whether the given property is persistent, that is managed by ORM.
|
boolean |
isPersistent(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaProperty metaProperty)
Determine whether the given property is system-level.
|
boolean |
isSystemLevel(com.haulmont.chile.core.model.MetaClass metaClass)
Determine whether the given entity is marked as
SystemLevel . |
boolean |
isSystemLevel(com.haulmont.chile.core.model.MetaProperty metaProperty)
Determine whether the given property is marked as
SystemLevel . |
boolean |
isTransient(java.lang.Class aClass)
Deprecated.
|
boolean |
isTransient(com.haulmont.chile.core.model.MetaClass metaClass)
Deprecated.
|
boolean |
isTransient(com.haulmont.chile.core.model.MetaProperty metaProperty)
Deprecated.
|
boolean |
isTransient(java.lang.Object object,
java.lang.String property)
Deprecated.
|
MetadataTools.NamePatternRec |
parseNamePattern(com.haulmont.chile.core.model.MetaClass metaClass)
Parse a name pattern defined by
NamePattern annotation. |
com.haulmont.chile.core.model.MetaPropertyPath |
resolveMetaPropertyPath(com.haulmont.chile.core.model.MetaClass metaClass,
java.lang.String propertyPath)
Returns a
MetaPropertyPath which can include the special MetaProperty for a dynamic attribute. |
com.haulmont.chile.core.model.MetaPropertyPath |
resolveMetaPropertyPathNN(com.haulmont.chile.core.model.MetaClass metaClass,
java.lang.String propertyPath)
Returns a
MetaPropertyPath which can include the special MetaProperty for a dynamic attribute. |
java.util.Collection<com.haulmont.chile.core.model.MetaPropertyPath> |
toPropertyPaths(java.util.Collection<com.haulmont.chile.core.model.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,
com.haulmont.chile.core.model.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
@Inject protected Metadata metadata
@Inject protected Messages messages
@Inject protected DynamicAttributesTools dynamicAttributesTools
@Inject protected UserSessionSource userSessionSource
@Inject protected com.haulmont.chile.core.datatypes.DatatypeRegistry datatypeRegistry
@Inject protected PersistentAttributesLoadChecker persistentAttributesLoadChecker
@Inject protected GlobalConfig globalConfig
protected volatile java.util.Collection<java.lang.Class> enums
public MetadataTools()
public java.lang.String format(@Nullable java.lang.Object value, com.haulmont.chile.core.model.MetaProperty property)
value
- value of the passed property to formatproperty
- propertypublic java.lang.String format(@Nullable java.lang.Object value)
value
- object to formatpublic java.lang.String getInstanceName(com.haulmont.chile.core.model.Instance instance)
instance
- instanceNamePattern
or toString()
.@Nullable public MetadataTools.NamePatternRec parseNamePattern(com.haulmont.chile.core.model.MetaClass metaClass)
NamePattern
annotation.metaClass
- entity meta-class@Nullable public java.lang.String getStoreName(com.haulmont.chile.core.model.MetaClass metaClass)
@Nullable public java.lang.String getPrimaryKeyName(com.haulmont.chile.core.model.MetaClass metaClass)
@Nullable public com.haulmont.chile.core.model.MetaProperty getPrimaryKeyProperty(com.haulmont.chile.core.model.MetaClass metaClass)
@Nullable public com.haulmont.chile.core.model.MetaProperty getPrimaryKeyProperty(java.lang.Class<?> entityClass)
public boolean hasCompositePrimaryKey(com.haulmont.chile.core.model.MetaClass metaClass)
public boolean isAssignableFrom(com.haulmont.chile.core.model.MetaClass metaClass, com.haulmont.chile.core.model.MetaClass other)
public boolean isCascade(com.haulmont.chile.core.model.MetaProperty metaProperty)
public boolean isSoftDeleted(java.lang.Class entityClass)
entityClass
- entity classtrue
if the entity implements SoftDelete
public boolean isSystem(com.haulmont.chile.core.model.MetaProperty metaProperty)
public boolean isPersistent(com.haulmont.chile.core.model.MetaPropertyPath metaPropertyPath)
public boolean isPersistent(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaClass metaClass, com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaProperty metaProperty)
isPersistent(MetaProperty)
.public boolean isNotPersistent(com.haulmont.chile.core.model.MetaClass metaClass, com.haulmont.chile.core.model.MetaProperty metaProperty)
isPersistent(MetaClass, MetaProperty)
.public boolean isEmbedded(com.haulmont.chile.core.model.MetaProperty metaProperty)
Embedded
public boolean isLob(com.haulmont.chile.core.model.MetaProperty metaProperty)
Lob
public boolean isOwningSide(com.haulmont.chile.core.model.MetaProperty metaProperty)
public boolean isSystemLevel(com.haulmont.chile.core.model.MetaClass metaClass)
SystemLevel
.public boolean isSystemLevel(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaClass metaClass)
public boolean isEmbeddable(java.lang.Class aClass)
public boolean isCacheable(com.haulmont.chile.core.model.MetaClass metaClass)
public com.haulmont.chile.core.model.MetaClass getPropertyEnclosingMetaClass(com.haulmont.chile.core.model.MetaPropertyPath propertyPath)
propertyPath
- Property path@Nonnull public java.util.Collection<com.haulmont.chile.core.model.MetaProperty> getNamePatternProperties(com.haulmont.chile.core.model.MetaClass metaClass)
NamePattern
).metaClass
- entity metaclass@Nonnull public java.util.Collection<com.haulmont.chile.core.model.MetaProperty> getNamePatternProperties(com.haulmont.chile.core.model.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<com.haulmont.chile.core.model.MetaPropertyPath> getPropertyPaths(com.haulmont.chile.core.model.MetaClass metaClass)
MetaPropertyPath
s containing one property eachpublic java.util.Collection<com.haulmont.chile.core.model.MetaPropertyPath> toPropertyPaths(java.util.Collection<com.haulmont.chile.core.model.MetaProperty> properties)
MetaPropertyPath
s containing one property eachpublic java.util.Collection<com.haulmont.chile.core.model.MetaPropertyPath> getViewPropertyPaths(View view, com.haulmont.chile.core.model.MetaClass metaClass)
MetaPropertyPath
s.view
- viewmetaClass
- meta-classpublic boolean viewContainsProperty(@Nullable View view, com.haulmont.chile.core.model.MetaPropertyPath propertyPath)
view
- view instance. If null, return false immediately.propertyPath
- property path defining the propertypublic java.util.Collection<com.haulmont.chile.core.model.MetaClass> getAllPersistentMetaClasses()
public java.util.Collection<com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaClass metaClass)
@Nullable public java.lang.String getDatabaseColumn(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaProperty metaProperty)
MetaProperty.related()
or empty list@Nullable public java.lang.String getCrossDataStoreReferenceIdProperty(java.lang.String thisStore, com.haulmont.chile.core.model.MetaProperty metaProperty)
thisStore
- name of a base data storemetaProperty
- property@Nullable public com.haulmont.chile.core.model.MetaPropertyPath resolveMetaPropertyPath(com.haulmont.chile.core.model.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 com.haulmont.chile.core.model.MetaPropertyPath resolveMetaPropertyPathNN(com.haulmont.chile.core.model.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 com.haulmont.chile.core.model.Instance> T copy(T source)
Instance.getMetaClass()
method
which should not return null.source
- source instancepublic void copy(com.haulmont.chile.core.model.Instance source, com.haulmont.chile.core.model.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)
protected void internalTraverseAttributes(Entity entity, EntityAttributeVisitor visitor, java.util.HashSet<java.lang.Object> visited)
protected void internalTraverseAttributesByView(View view, Entity entity, EntityAttributeVisitor visitor, java.util.Map<Entity,java.util.Set<View>> visited, boolean checkLoaded)
protected static <T> T createInstance(java.lang.Class<T> aClass)
protected static Entity createInstanceWithId(java.lang.Class<? extends Entity> entityClass, java.lang.Object id)
@Deprecated public boolean isTransient(com.haulmont.chile.core.model.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(com.haulmont.chile.core.model.MetaProperty metaProperty)
isNotPersistent(MetaProperty)
.