@Component(value="core_MetadataTools")
public class MetadataTools
extends java.lang.Object
Implemented as Spring bean to allow for extension in application projects.
Modifier and Type | Class and Description |
---|---|
static class |
MetadataTools.CachingEntitiesHolder
INTERNAL
|
static interface |
MetadataTools.EntitiesHolder
INTERNAL
|
Modifier and Type | Field and Description |
---|---|
protected CurrentAuthentication |
currentAuthentication |
protected DatatypeRegistry |
datatypeRegistry |
static java.lang.String |
DELETED_BY_ANN_NAME |
static java.lang.String |
DELETED_DATE_ANN_NAME |
static java.lang.String |
EMBEDDED_ANN_NAME |
protected java.util.Collection<java.lang.Class<?>> |
enums |
protected ExtendedEntities |
extendedEntities |
protected InstanceNameProvider |
instanceNameProvider |
static java.lang.String |
LAST_MODIFIED_DATE_ANN_NAME |
static java.lang.String |
LENGTH_ANN_NAME |
protected Messages |
messages |
protected Metadata |
metadata |
protected java.util.List<MetadataExtension> |
metadataExtensions |
protected java.util.Collection<MetaPropertyPathResolver> |
metaPropertyPathResolvers |
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.lang.String |
TEMPORAL_ANN_NAME |
static java.lang.String |
UUID_KEY_ANN_NAME
Not applicable for legacy cuba entities
|
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(java.lang.Object source,
java.lang.Object dest)
Make a shallow copy of an instance.
|
<T> T |
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 java.lang.Object |
createInstanceWithId(java.lang.Class<?> entityClass,
java.lang.Object id) |
void |
deepCopy(java.lang.Object source,
java.lang.Object destination,
MetadataTools.EntitiesHolder entitiesHolder)
Copies all property values from source to destination excluding null values.
|
<T> T |
deepCopy(T source)
Makes a deep copy of the source entity.
|
boolean |
fetchPlanContainsProperty(FetchPlan fetchPlan,
MetaPropertyPath propertyPath)
Determine whether the fetch plan contains a property, traversing a fetch plan branch according to the given property path.
|
java.lang.String |
findDeletedByProperty(java.lang.Class<?> clazz) |
java.lang.String |
findDeletedDateProperty(java.lang.Class<?> clazz) |
java.lang.String |
findLastModifiedDateProperty(java.lang.Class<?> clazz) |
protected java.lang.String |
findPropertyByAnnotation(java.lang.Class<?> clazz,
java.lang.String annotationName) |
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.Set<MetaProperty> |
getAdditionalProperties(MetaClass metaClass)
Returns all additional properties which are providing classes implement MetadataExtension interface
|
java.util.Collection<java.lang.Class<?>> |
getAllEnums() |
java.util.Collection<MetaClass> |
getAllJpaEmbeddableMetaClasses() |
java.util.Collection<MetaClass> |
getAllJpaEntityMetaClasses() |
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 |
getDeletedDateProperty(java.lang.Object entity) |
java.util.List<java.lang.String> |
getDependsOnProperties(java.lang.Class<?> entityClass,
java.lang.String property) |
java.util.List<java.lang.String> |
getDependsOnProperties(MetaProperty metaProperty) |
java.util.Collection<MetaPropertyPath> |
getFetchPlanPropertyPaths(FetchPlan fetchPlan,
MetaClass metaClass)
Collects all meta-properties of the given meta-class included to the given fetchPlan as
MetaPropertyPath s. |
java.lang.String |
getInstanceName(java.lang.Object instance) |
java.util.Collection<MetaProperty> |
getInstanceNameRelatedProperties(MetaClass metaClass)
Return a collection of properties included into entity's name pattern (see
InstanceName ). |
java.util.Collection<MetaProperty> |
getInstanceNameRelatedProperties(MetaClass metaClass,
boolean useOriginal)
Return a collection of properties included into entity's name pattern (see
InstanceName ). |
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.lang.String |
getPrimaryKeyName(MetaClass metaClass) |
MetaProperty |
getPrimaryKeyProperty(java.lang.Class<?> entityClass) |
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> |
getSoftDeleteProperties(java.lang.Class<?> clazz) |
java.util.List<java.lang.String> |
getSystemProperties(MetaClass metaClass)
System Properties - is important properties used for identification, audit, soft-delete and optimistic lock
purposes
More formally, it is properties with annotations:
Id ,
JmixId ,
EmbeddedId
JmixGeneratedValue
CreatedDate
CreatedBy
LastModifiedDate
LastModifiedBy
DeletedDate
DeletedBy
Version
|
java.lang.String |
getUuidPropertyName(java.lang.Class<?> clazz) |
boolean |
hasCompositePrimaryKey(MetaClass metaClass) |
boolean |
hasDbGeneratedPrimaryKey(MetaClass metaClass) |
boolean |
hasUuid(MetaClass metaClass)
Checks whether an entity has uuid key (primary or not)
|
protected void |
internalTraverseAttributes(Entity entity,
EntityAttributeVisitor visitor,
java.util.HashSet<java.lang.Object> visited) |
protected void |
internalTraverseAttributesByFetchPlan(FetchPlan fetchPlan,
java.lang.Object entity,
EntityAttributeVisitor visitor,
java.util.Map<java.lang.Object,java.util.Set<FetchPlan>> visited,
boolean checkLoaded) |
boolean |
isAdditionalProperty(MetaClass metaClass,
java.lang.String propertyName) |
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 |
isEmbedded(MetaProperty metaProperty)
Determine whether the given property denotes an embedded object.
|
boolean |
isJpa(MetaProperty metaProperty)
Determine whether the given property is a persistent attribute of a JPA entity or embeddable.
|
boolean |
isJpa(MetaPropertyPath metaPropertyPath)
Determine whether all the properties defined by the given property path are persistent attributes
of JPA entities or embeddables.
|
boolean |
isJpaEmbeddable(java.lang.Class<?> aClass)
Determine whether the given entity class is JPA embeddable.
|
boolean |
isJpaEmbeddable(MetaClass metaClass)
Determine whether the given meta-class is JPA embeddable.
|
boolean |
isJpaEntity(java.lang.Class<?> aClass)
Determine whether the given class represents a JPA entity.
|
boolean |
isJpaEntity(MetaClass metaClass)
Determine whether the given meta-class represents a JPA entity.
|
boolean |
isLob(MetaProperty metaProperty)
Determine whether the given property is a LOB.
|
boolean |
isOwningSide(MetaProperty metaProperty)
Determine whether the given property is on the owning side of an association.
|
boolean |
isSoftDeletable(java.lang.Class<?> entityClass)
Determine whether the entity supports Soft Deletion.
|
boolean |
isSystem(MetaProperty metaProperty)
Determine whether the given property is system.
|
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 . |
MetaPropertyPath |
resolveMetaPropertyPath(MetaClass metaClass,
java.lang.String propertyPath)
Returns a
MetaPropertyPath which can include the special MetaProperty for a dynamic attribute. |
MetaPropertyPath |
resolveMetaPropertyPathOrNull(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(java.lang.Object entity,
EntityAttributeVisitor visitor)
Depth-first traversal of the object graph starting from the specified entity instance.
|
void |
traverseAttributesByFetchPlan(FetchPlan fetchPlan,
java.lang.Object entity,
boolean checkLoaded,
EntityAttributeVisitor visitor)
Depth-first traversal of the object graph by the fetch plan starting from the specified entity instance.
|
void |
traverseAttributesByFetchPlan(FetchPlan fetchPlan,
java.lang.Object entity,
EntityAttributeVisitor visitor)
Depth-first traversal of the object graph by the fetch plan starting from the specified entity instance.
|
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.lang.String LENGTH_ANN_NAME
public static final java.lang.String UUID_KEY_ANN_NAME
public static final java.lang.String DELETED_DATE_ANN_NAME
public static final java.lang.String DELETED_BY_ANN_NAME
public static final java.lang.String LAST_MODIFIED_DATE_ANN_NAME
@Autowired protected Metadata metadata
@Autowired protected ExtendedEntities extendedEntities
@Autowired protected Messages messages
@Autowired protected InstanceNameProvider instanceNameProvider
@Autowired(required=false) protected java.util.List<MetadataExtension> metadataExtensions
@Autowired protected CurrentAuthentication currentAuthentication
@Autowired protected DatatypeRegistry datatypeRegistry
@Autowired protected PersistentAttributesLoadChecker persistentAttributesLoadChecker
@Autowired(required=false) protected java.util.Collection<MetaPropertyPathResolver> metaPropertyPathResolvers
protected volatile java.util.Collection<java.lang.Class<?>> enums
public MetadataTools()
public java.lang.String format(@Nullable java.lang.Object value, 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(java.lang.Object instance)
instance
- instanceInstanceName
or toString()
.@Nullable public java.lang.String getPrimaryKeyName(MetaClass metaClass)
@Nullable public MetaProperty getPrimaryKeyProperty(MetaClass metaClass)
@Nullable public MetaProperty getPrimaryKeyProperty(java.lang.Class<?> entityClass)
public boolean hasCompositePrimaryKey(MetaClass metaClass)
public boolean hasDbGeneratedPrimaryKey(MetaClass metaClass)
public boolean isAssignableFrom(MetaClass metaClass, MetaClass other)
public boolean isCascade(MetaProperty metaProperty)
public boolean isSoftDeletable(java.lang.Class<?> entityClass)
entityClass
- entity classtrue
if the entity has @DeletedDate
fieldpublic boolean isSystem(MetaProperty metaProperty)
Id
JmixId
JmixGeneratedValue
Version
CreatedDate
CreatedBy
LastModifiedDate
LastModifiedBy
DeletedDate
DeletedBy
public java.util.List<java.lang.String> getSystemProperties(MetaClass metaClass)
Id
,JmixId
,EmbeddedId
JmixGeneratedValue
CreatedDate
CreatedBy
LastModifiedDate
LastModifiedBy
DeletedDate
DeletedBy
Version
metaClass
parameterpublic boolean isJpa(MetaPropertyPath metaPropertyPath)
public boolean isJpa(MetaProperty metaProperty)
public boolean isEmbedded(MetaProperty metaProperty)
Embedded
,
EmbeddedId
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 isJpaEntity(MetaClass metaClass)
public boolean isJpaEntity(java.lang.Class<?> aClass)
public boolean isJpaEmbeddable(MetaClass metaClass)
public boolean isJpaEmbeddable(java.lang.Class<?> aClass)
public boolean isCacheable(MetaClass metaClass)
public MetaClass getPropertyEnclosingMetaClass(MetaPropertyPath propertyPath)
propertyPath
- Property path@Nonnull public java.util.Collection<MetaProperty> getInstanceNameRelatedProperties(MetaClass metaClass)
InstanceName
).metaClass
- entity metaclass@Nonnull public java.util.Collection<MetaProperty> getInstanceNameRelatedProperties(MetaClass metaClass, boolean useOriginal)
InstanceName
).metaClass
- entity metaclassuseOriginal
- if true, and if the given metaclass doesn't define a InstanceName
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> getFetchPlanPropertyPaths(FetchPlan fetchPlan, MetaClass metaClass)
MetaPropertyPath
s.fetchPlan
- fetch planmetaClass
- meta-classpublic boolean fetchPlanContainsProperty(@Nullable FetchPlan fetchPlan, MetaPropertyPath propertyPath)
fetchPlan
- fetch plan instance. If null, return false immediately.propertyPath
- property path defining the propertypublic java.util.Collection<MetaClass> getAllJpaEntityMetaClasses()
public java.util.Collection<MetaClass> getAllJpaEmbeddableMetaClasses()
public java.util.Collection<java.lang.Class<?>> getAllEnums()
@Nullable public java.lang.String getDatabaseTable(MetaClass metaClass)
@Nullable public java.lang.String getDatabaseColumn(MetaProperty metaProperty)
public java.util.List<java.lang.String> getDependsOnProperties(java.lang.Class<?> entityClass, java.lang.String property)
DependsOnProperties
or empty listpublic java.util.List<java.lang.String> getDependsOnProperties(MetaProperty metaProperty)
DependsOnProperties
or empty listpublic java.lang.String getDeletedDateProperty(java.lang.Object entity) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if entity has no @DeletedDate
field@Nullable public java.lang.String findDeletedDateProperty(java.lang.Class<?> clazz)
@Nullable public java.lang.String findDeletedByProperty(java.lang.Class<?> clazz)
@Nullable public java.lang.String findLastModifiedDateProperty(java.lang.Class<?> clazz)
@Nullable protected java.lang.String findPropertyByAnnotation(java.lang.Class<?> clazz, java.lang.String annotationName)
public java.util.List<java.lang.String> getSoftDeleteProperties(java.lang.Class<?> clazz)
DeletedDate
, @DeletedBy
property names if present.public boolean hasUuid(MetaClass metaClass)
EntityEntry
implements EntityEntryHasUuid
@Nullable public java.lang.String getUuidPropertyName(java.lang.Class<?> clazz)
@Nullable public java.lang.String getCrossDataStoreReferenceIdProperty(java.lang.String thisStore, MetaProperty metaProperty)
thisStore
- name of a base data storemetaProperty
- property@Nullable public MetaPropertyPath resolveMetaPropertyPathOrNull(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 resolveMetaPropertyPath(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(java.lang.Object entity, EntityAttributeVisitor visitor)
entity
- entity graph entry pointvisitor
- the attribute visitor implementationpublic void traverseAttributesByFetchPlan(FetchPlan fetchPlan, java.lang.Object entity, EntityAttributeVisitor visitor)
fetchPlan
- fetchPlan instanceentity
- entity graph entry pointvisitor
- the attribute visitor implementationpublic void traverseAttributesByFetchPlan(FetchPlan fetchPlan, java.lang.Object entity, boolean checkLoaded, EntityAttributeVisitor visitor)
fetchPlan
- fetchPlan instanceentity
- entity graph entry pointcheckLoaded
- if true, skips not loaded attributesvisitor
- the attribute visitor implementationpublic <T> T copy(T source)
This method copies attributes according to the metadata.
source
- source instancepublic void copy(java.lang.Object source, java.lang.Object dest)
This method copies attributes according to the metadata.
The source and destination instances don't have to be of the same Java class or metaclass. Copying is performed in the following scenario: get each source property and copy the value to the destination if it contains a property with the same name and it is not read-only.
source
- source instancedest
- destination instancepublic <T> T deepCopy(T source)
public void deepCopy(java.lang.Object source, java.lang.Object destination, MetadataTools.EntitiesHolder entitiesHolder)
protected void internalTraverseAttributes(Entity entity, EntityAttributeVisitor visitor, java.util.HashSet<java.lang.Object> visited)
protected void internalTraverseAttributesByFetchPlan(FetchPlan fetchPlan, java.lang.Object entity, EntityAttributeVisitor visitor, java.util.Map<java.lang.Object,java.util.Set<FetchPlan>> visited, boolean checkLoaded)
protected static <T> T createInstance(java.lang.Class<T> aClass)
protected static java.lang.Object createInstanceWithId(java.lang.Class<?> entityClass, java.lang.Object id)
public java.util.Set<MetaProperty> getAdditionalProperties(MetaClass metaClass)
metaClass
- instance MetaClass for getting additional propertiespublic boolean isAdditionalProperty(MetaClass metaClass, java.lang.String propertyName)
metaClass
- propertyName
-