Class QueryGenUtil
- java.lang.Object
-
- org.intermine.objectstore.querygen.QueryGenUtil
-
public final class QueryGenUtil extends java.lang.Object
Utility methods for paths.- Author:
- Kim Rutherford
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
QueryGenUtil.QueryAndClass
Class to allow returning of two arguments from a method.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static void
addReferenceConstraint(Model model, Query q, QueryClass qcStart, java.lang.String refName, QueryClass qcEnd, boolean first)
Add a contains constraint to Query (q) from qcStart from qcEnd via reference refName.static Query
constructQuery(Model model, java.lang.String path)
Construct an objectstore query represented by the given path.protected static QueryGenUtil.QueryAndClass
createClassFindingQuery(Model model, java.lang.String part)
Takes a String representation of a query (a path), and creates a query.static java.util.Set<java.lang.String>
expandPath(ObjectStore os, java.lang.String path)
Given a path return a set of paths replacing a path with a '+' preceding a class name with an additional path for every subclass of that class.protected static java.util.Set<java.lang.String>
getClassNames(ObjectStore os, java.lang.String clsName)
Given a String, perform a one of a set of expansions and return a Set of unqualified class names.static void
validatePath(java.lang.String path, Model model)
Path should be of the form: Class1 ref1 Class2 ref2 Class3 Where the number of elements is greater than one and an odd number.
-
-
-
Method Detail
-
getClassNames
protected static java.util.Set<java.lang.String> getClassNames(ObjectStore os, java.lang.String clsName) throws ObjectStoreException
Given a String, perform a one of a set of expansions and return a Set of unqualified class names. Firstly, if the argument contains commas, it will be split up in the obvious way, and each element will be expanded in one of the following ways:- Plain unqualified class names will be returned unchanged
- An unqualified class name preceded by a "+" will be expanded to include all the subclasses
- A String with dots will be treated as a path to build into a query, and the results taken as a list of classes to include - the path must end with ".class"
- Parameters:
os
- the ObjectStore that the data to be queried is inclsName
- an unqualified class name- Returns:
- a set of class names
- Throws:
ObjectStoreException
- if an error occurs running a query
-
createClassFindingQuery
protected static QueryGenUtil.QueryAndClass createClassFindingQuery(Model model, java.lang.String part)
Takes a String representation of a query (a path), and creates a query. For example, the String "Department.class" will produce the query "SELECT DISTINCT Department.class FROM Department".- Parameters:
model
- the Model that the query usespart
- the String describing the query- Returns:
- a QueryAndClass - the results of the given Query is a list of classes, which should all be decomposed and the constituents filtered to allow only subclasses of the given Class
-
validatePath
public static void validatePath(java.lang.String path, Model model)
Path should be of the form: Class1 ref1 Class2 ref2 Class3 Where the number of elements is greater than one and an odd number. Check that all classes anf references are valid in the model.- Parameters:
path
- the path stringmodel
- the Model use to find meta data- Throws:
java.lang.IllegalArgumentException
- if path not valid
-
expandPath
public static java.util.Set<java.lang.String> expandPath(ObjectStore os, java.lang.String path) throws ObjectStoreException
Given a path return a set of paths replacing a path with a '+' preceding a class name with an additional path for every subclass of that class.- Parameters:
os
- the ObjectStore that the data is stored inpath
- the path to expand- Returns:
- a Set of paths
- Throws:
ObjectStoreException
- if an error occurs while running a query
-
constructQuery
public static Query constructQuery(Model model, java.lang.String path) throws java.lang.ClassNotFoundException
Construct an objectstore query represented by the given path.- Parameters:
model
- the Model use to find meta datapath
- path to construct query for- Returns:
- the constructed query
- Throws:
java.lang.ClassNotFoundException
- if problem processing pathjava.lang.IllegalArgumentException
- if problem processing path
-
addReferenceConstraint
protected static void addReferenceConstraint(Model model, Query q, QueryClass qcStart, java.lang.String refName, QueryClass qcEnd, boolean first)
Add a contains constraint to Query (q) from qcStart from qcEnd via reference refName.- Parameters:
model
- the Model use to find meta dataq
- the queryqcStart
- the QueryClass that contains the referencerefName
- name of reference to qcEndqcEnd
- the target QueryClass of refNamefirst
- true if this is the first constraint added - qcStart needs to be added to the query
-
-