Package ome.tools.hibernate
Class ExtendedMetadata.Impl
- java.lang.Object
-
- ome.tools.spring.OnContextRefreshedEventListener
-
- ome.tools.hibernate.ExtendedMetadata.Impl
-
- All Implemented Interfaces:
java.util.EventListener,ExtendedMetadata,org.springframework.beans.factory.Aware,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationListener<org.springframework.context.event.ContextRefreshedEvent>
- Enclosing interface:
- ExtendedMetadata
public static class ExtendedMetadata.Impl extends OnContextRefreshedEventListener implements ExtendedMetadata
Sole implementation of ExtendedMetadata. The separation is intended to make unit testing without a fullExtendedMetadatapossible.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ome.tools.hibernate.ExtendedMetadata
ExtendedMetadata.Immutables, ExtendedMetadata.Impl, ExtendedMetadata.Locks, ExtendedMetadata.Relationship
-
-
Constructor Summary
Constructors Constructor Description Impl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Long>countLocks(org.hibernate.Session session, java.lang.Long id, java.lang.String[][] checks, java.lang.String clause)Takes the lock checks returned byExtendedMetadata.getLockChecks(Class)and performs the actual check returning a map from class to total number of locks.java.util.Set<java.lang.Class<ome.model.IAnnotated>>getAnnotatableTypes()Returns all the classes which implementIAnnotatedjava.util.Set<java.lang.Class<ome.model.annotations.Annotation>>getAnnotationTypes()Returns all the classes which subclassAnnotationjava.util.Set<java.lang.String>getClasses()java.lang.StringgetCountQuery(java.lang.String field)Returns the query for obtaining the number of collection items to a particular instance.java.lang.Class<ome.model.IObject>getHibernateClass(java.lang.String table)Given the name of a database table or alternatively the simple class name (non-fully qualified) of an IObject, this method returns the class which Hibernate will map that table to.java.lang.String[]getImmutableFields(java.lang.Class<? extends ome.model.IObject> klass)java.lang.String[][]getLockCandidateChecks(java.lang.Class<? extends ome.model.IObject> k, boolean onlyWithGroups)Rather than iterating over anIObjectlikeExtendedMetadata.getLockCandidates(IObject)this method returns type/field name pairs (likeExtendedMetadata.getLockChecks(Class)) to allow performing the queries manually.ome.model.IObject[]getLockCandidates(ome.model.IObject iObject)walks theIObjectargument non-recursively and gathers allIObjectinstances which will be linked to by the creation or updating of the argument.java.lang.String[][]getLockChecks(java.lang.Class<? extends ome.model.IObject> klass)returns all class/field name pairs which may possibly link to an object of typeklass.java.util.Set<java.lang.String>getMapProperties(java.lang.String className)Get the names of any String→RString map properties this class has, otherwise an empty set if none.java.lang.StringgetRelationship(java.lang.String from, java.lang.String to)Walks the data on what locks what for "from" argument to see if there is any direct relationship to the "to" argument.java.lang.StringgetSQLJoin(java.lang.String fromType, java.lang.String fromAlias, java.lang.String toType, java.lang.String toAlias)Note: this implementation does not yet take into account the mapping of joined subclasses like Job -> UpdateJob.java.lang.Class<ome.model.IObject>getTargetType(java.lang.String field)Returns theIObjecttype which a given field points to.voidhandleContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent cre)Listener method which waits for aContextRefreshedEventand then extracts theSessionFactoryfrom theApplicationContextand pases it tosetSessionFactory(SessionFactory).booleanmayHaveMapProperties(java.lang.Class<? extends ome.model.IObject> iObjectClass)Check if an object of this class may have map properties.voidsetSessionFactory(org.hibernate.SessionFactory sessionFactory)Initializes the metadata needed by this instance.-
Methods inherited from class ome.tools.spring.OnContextRefreshedEventListener
onApplicationEvent, setApplicationContext
-
-
-
-
Method Detail
-
handleContextRefreshedEvent
public void handleContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent cre)
Listener method which waits for aContextRefreshedEventand then extracts theSessionFactoryfrom theApplicationContextand pases it tosetSessionFactory(SessionFactory).- Specified by:
handleContextRefreshedEventin classOnContextRefreshedEventListener
-
setSessionFactory
public void setSessionFactory(org.hibernate.SessionFactory sessionFactory)
Initializes the metadata needed by this instance.- Parameters:
sessionFactory- the Hibernate session factory- See Also:
SessionFactory.getAllClassMetadata()
-
getClasses
public java.util.Set<java.lang.String> getClasses()
- Specified by:
getClassesin interfaceExtendedMetadata
-
getHibernateClass
public java.lang.Class<ome.model.IObject> getHibernateClass(java.lang.String table)
Description copied from interface:ExtendedMetadataGiven the name of a database table or alternatively the simple class name (non-fully qualified) of an IObject, this method returns the class which Hibernate will map that table to.- Specified by:
getHibernateClassin interfaceExtendedMetadata- Parameters:
table- a database table name, or simple class name of a model object- Returns:
- the corresponding mapped class
-
getRelationship
public java.lang.String getRelationship(java.lang.String from, java.lang.String to)Walks the data on what locks what for "from" argument to see if there is any direct relationship to the "to" argument. If there is, the name will be returned. Otherwise, null.- Specified by:
getRelationshipin interfaceExtendedMetadata
-
getSQLJoin
public java.lang.String getSQLJoin(java.lang.String fromType, java.lang.String fromAlias, java.lang.String toType, java.lang.String toAlias)Note: this implementation does not yet take into account the mapping of joined subclasses like Job -> UpdateJob.- Specified by:
getSQLJoinin interfaceExtendedMetadata
-
getAnnotatableTypes
public java.util.Set<java.lang.Class<ome.model.IAnnotated>> getAnnotatableTypes()
Description copied from interface:ExtendedMetadataReturns all the classes which implementIAnnotated- Specified by:
getAnnotatableTypesin interfaceExtendedMetadata- Returns:
- the annotatable types
-
getAnnotationTypes
public java.util.Set<java.lang.Class<ome.model.annotations.Annotation>> getAnnotationTypes()
Description copied from interface:ExtendedMetadataReturns all the classes which subclassAnnotation- Specified by:
getAnnotationTypesin interfaceExtendedMetadata- Returns:
- the types of annotation
-
getLockCandidates
public ome.model.IObject[] getLockCandidates(ome.model.IObject iObject)
walks theIObjectargument non-recursively and gathers allIObjectinstances which will be linked to by the creation or updating of the argument. (Previously this was called "locking" since a flag was set on the object to mark it as linked, but this was removed in 4.2)- Specified by:
getLockCandidatesin interfaceExtendedMetadata- Parameters:
iObject- A newly created or updatedIObjectinstance which might possibly lock otherIObjects. A null argument will return an empty array to be checked.- Returns:
- A non-null array of
IObjectswhich will be linked to.
-
getLockCandidateChecks
public java.lang.String[][] getLockCandidateChecks(java.lang.Class<? extends ome.model.IObject> k, boolean onlyWithGroups)Description copied from interface:ExtendedMetadataRather than iterating over anIObjectlikeExtendedMetadata.getLockCandidates(IObject)this method returns type/field name pairs (likeExtendedMetadata.getLockChecks(Class)) to allow performing the queries manually. If onlyWithGroups is true, then only checks which point to non-IGlobal objects will be returned.- Specified by:
getLockCandidateChecksin interfaceExtendedMetadata- Parameters:
k- Not null.onlyWithGroups- if should omit checks that point toIGlobals- Returns:
- the lock candidates for checking
-
getLockChecks
public java.lang.String[][] getLockChecks(java.lang.Class<? extends ome.model.IObject> klass)
returns all class/field name pairs which may possibly link to an object of typeklass.- Specified by:
getLockChecksin interfaceExtendedMetadata- Parameters:
klass- Non-nullsubclassofIObject- Returns:
- A non-null array of
Stringqueries which can be used to determine if anIObjectinstance can be unlocked.
-
countLocks
public java.util.Map<java.lang.String,java.lang.Long> countLocks(org.hibernate.Session session, java.lang.Long id, java.lang.String[][] checks, java.lang.String clause)Description copied from interface:ExtendedMetadataTakes the lock checks returned byExtendedMetadata.getLockChecks(Class)and performs the actual check returning a map from class to total number of locks. The key "*" contains the total value. If the id argument is null, then checks will be against all rows rather than individual objects, e.g.select count(x) from Linker x, Linked y where x.$FIELD.id = y.id $CLAUSE;
otherwiseselect count(x) from Linker x where x.$FIELD.id = :id $CLAUSE'
If the clause argument is null or empty it will be omitted.- Specified by:
countLocksin interfaceExtendedMetadata
-
getImmutableFields
public java.lang.String[] getImmutableFields(java.lang.Class<? extends ome.model.IObject> klass)
-
getCountQuery
public java.lang.String getCountQuery(java.lang.String field) throws ome.conditions.ApiUsageExceptionReturns the query for obtaining the number of collection items to a particular instance. All such queries will return a ResultSet with rows of the form: 0 (Long) id of the locked class 1 (Long) count of the instances locking that class- Specified by:
getCountQueryin interfaceExtendedMetadata- Parameters:
field- Field name as specified in the class.- Returns:
- String query. Never null.
- Throws:
ome.conditions.ApiUsageException- if return value would be null.
-
getTargetType
public java.lang.Class<ome.model.IObject> getTargetType(java.lang.String field) throws ome.conditions.ApiUsageExceptionReturns theIObjecttype which a given field points to. E.g. getTargetType(ImageAnnotation.IMAGE) returns Image.class.- Throws:
ome.conditions.ApiUsageException
-
mayHaveMapProperties
public boolean mayHaveMapProperties(java.lang.Class<? extends ome.model.IObject> iObjectClass)
Description copied from interface:ExtendedMetadataCheck if an object of this class may have map properties.- Specified by:
mayHaveMapPropertiesin interfaceExtendedMetadata- Parameters:
iObjectClass- a class- Returns:
- if this object or any of its mapped subclasses have any map properties
-
getMapProperties
public java.util.Set<java.lang.String> getMapProperties(java.lang.String className)
Description copied from interface:ExtendedMetadataGet the names of any String→RString map properties this class has, otherwise an empty set if none.- Specified by:
getMapPropertiesin interfaceExtendedMetadata- Parameters:
className- the name of a class, as fromClass.getName()- Returns:
- the class' map property names
-
-