Package ome.tools.hibernate
Interface ExtendedMetadata
-
- All Known Implementing Classes:
ExtendedMetadata.Impl
public interface ExtendedMetadata
extension of the model metadata provided bySessionFactory
. During construction, the metadata is created and cached for later use.- Since:
- 3.0-M3
- See Also:
SessionFactory
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ExtendedMetadata.Immutables
static class
ExtendedMetadata.Impl
Sole implementation of ExtendedMetadata.static class
ExtendedMetadata.Locks
inner class which wraps the information (index number, path, etc) related to what fields a particular object can lock.static class
ExtendedMetadata.Relationship
Simple value class to maintain all of the state for use bygetRelationship(String, String)
andgetSQLJoin(String, String, String, String)
.
-
Method Summary
All Methods Instance Methods Abstract 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[][] lockChecks, java.lang.String clause)
Takes the lock checks returned bygetLockChecks(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 implementIAnnotated
java.util.Set<java.lang.Class<ome.model.annotations.Annotation>>
getAnnotationTypes()
Returns all the classes which subclassAnnotation
java.util.Set<java.lang.String>
getClasses()
java.lang.String
getCountQuery(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[][]
getLockCandidateChecks(java.lang.Class<? extends ome.model.IObject> klass, boolean onlyWithGroups)
Rather than iterating over anIObject
likegetLockCandidates(IObject)
this method returns type/field name pairs (likegetLockChecks(Class)
) to allow performing the queries manually.ome.model.IObject[]
getLockCandidates(ome.model.IObject iObject)
walks theIObject
argument non-recursively and gathers allIObject
instances 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.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.java.lang.String
getSQLJoin(java.lang.String fromType, java.lang.String fromAlias, java.lang.String toType, java.lang.String toAlias)
provides the link between two tables similar to {linkgetRelationship(String, String)
.boolean
mayHaveMapProperties(java.lang.Class<? extends ome.model.IObject> iObjectClass)
Check if an object of this class may have map properties.
-
-
-
Method Detail
-
getClasses
java.util.Set<java.lang.String> getClasses()
-
getAnnotatableTypes
java.util.Set<java.lang.Class<ome.model.IAnnotated>> getAnnotatableTypes()
Returns all the classes which implementIAnnotated
- Returns:
- the annotatable types
-
getAnnotationTypes
java.util.Set<java.lang.Class<ome.model.annotations.Annotation>> getAnnotationTypes()
Returns all the classes which subclassAnnotation
- Returns:
- the types of annotation
-
getCountQuery
java.lang.String getCountQuery(java.lang.String field) throws ome.conditions.ApiUsageException
Returns 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- Parameters:
field
- Field name as specified in the class.- Returns:
- String query. Never null.
- Throws:
ome.conditions.ApiUsageException
- if return value would be null.
-
getHibernateClass
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.- Parameters:
table
- a database table name, or simple class name of a model object- Returns:
- the corresponding mapped class
-
getLockCandidates
ome.model.IObject[] getLockCandidates(ome.model.IObject iObject)
walks theIObject
argument non-recursively and gathers allIObject
instances 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)- Parameters:
iObject
- A newly created or updatedIObject
instance which might possibly lock otherIObjects
. A null argument will return an empty array to be checked.- Returns:
- A non-null array of
IObjects
which will be linked to.
-
getLockCandidateChecks
java.lang.String[][] getLockCandidateChecks(java.lang.Class<? extends ome.model.IObject> klass, boolean onlyWithGroups)
Rather than iterating over anIObject
likegetLockCandidates(IObject)
this method returns type/field name pairs (likegetLockChecks(Class)
) to allow performing the queries manually. If onlyWithGroups is true, then only checks which point to non-IGlobal objects will be returned.- Parameters:
klass
- Not null.onlyWithGroups
- if should omit checks that point toIGlobal
s- Returns:
- the lock candidates for checking
-
getLockChecks
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
.- Parameters:
klass
- Non-nullsubclass
ofIObject
- Returns:
- A non-null array of
String
queries which can be used to determine if anIObject
instance can be unlocked.
-
countLocks
java.util.Map<java.lang.String,java.lang.Long> countLocks(org.hibernate.Session session, java.lang.Long id, java.lang.String[][] lockChecks, java.lang.String clause)
Takes the lock checks returned bygetLockChecks(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.
-
getRelationship
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.
-
getSQLJoin
java.lang.String getSQLJoin(java.lang.String fromType, java.lang.String fromAlias, java.lang.String toType, java.lang.String toAlias)
provides the link between two tables similar to {linkgetRelationship(String, String)
. However, whereasgetRelationship(String, String)
needs to be called twice, once for each of the Hibernate directions,getSQLJoin(String, String, String, String)
need only ever be called once since there will be only one correct SQL join. For example, getRelationship("Image", "DatasetImageLink") returns "datasetLinks" while getRelationship("DatasetImageLink", "Image") returns "child". getSQLJoin("Image", "I", "DatasetImageLink", "L"), however, will always return "I.id = L.child" (though the order may be reversed).
-
mayHaveMapProperties
boolean mayHaveMapProperties(java.lang.Class<? extends ome.model.IObject> iObjectClass)
Check if an object of this class may have map properties.- Parameters:
iObjectClass
- a class- Returns:
- if this object or any of its mapped subclasses have any map properties
-
getMapProperties
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.- Parameters:
className
- the name of a class, as fromClass.getName()
- Returns:
- the class' map property names
-
-