Class 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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 in
        clsName - 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 uses
        part - 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 string
        model - 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 in
        path - 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 data
        path - path to construct query for
        Returns:
        the constructed query
        Throws:
        java.lang.ClassNotFoundException - if problem processing path
        java.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 data
        q - the query
        qcStart - the QueryClass that contains the reference
        refName - name of reference to qcEnd
        qcEnd - the target QueryClass of refName
        first - true if this is the first constraint added - qcStart needs to be added to the query