Class AnnotationRestriction

All Implemented Interfaces:
QueryElement, Restriction
Direct Known Subclasses:
AnnotationBetweenRestriction, AnnotationInRestriction, AnnotationSimpleRestriction, HasAnnotationRestriction

public abstract class AnnotationRestriction extends Object implements Restriction
Base class for creating restrictions based on annotations. Subclasses must implent the getRestrictionSql(Query, DbControl) and setRestrictionParameters(NativeQuery) method.
See Also:
Last modified
$Date: 2019-03-12 08:29:06 +0100 (tis, 12 mars 2019) $
  • Field Details

    • logSql

      private static final org.slf4j.Logger logSql
      Log all SQL statements.
    • debugSqlEnabled

      private static final boolean debugSqlEnabled
      So we don't always have to call logSql.debug()
    • annotationType

      private AnnotationType annotationType
    • valueType

      final Type valueType
    • annotationTypeId

      final int annotationTypeId
    • options

    • alias

      final String alias
  • Constructor Details

    • AnnotationRestriction

      AnnotationRestriction(String alias, AnnotationType annotationType, AnnotationRestriction.Options options) throws InvalidDataException
      Create a new annotation restriction for an annotation type.
      annotationType - The annotation type to use in the query
    • AnnotationRestriction

      @Deprecated AnnotationRestriction(String alias, int annotationTypeId, Type valueType, AnnotationRestriction.Options options) throws InvalidDataException
      In 3.11
      Create a new annotation restriction given the id and value type of an annotation. It is not verified that there exists an annotation type with the specified id or that it's value type is the one specified. The only thing that will happen is that the restriction will not match any annotations.
      annotationTypeId - The id of the annotation type
      valueType - The type of values for annotations
  • Method Details

    • toQl

      public String toQl(Query query, DbControl dc) throws BaseException
      Description copied from interface: QueryElement
      Create a query language string of the query element. Use the Query.getQueryType() method to find out which query language is wanted in case the element requires different syntax for different languages.
      Specified by:
      toQl in interface QueryElement
      query - The query that is about to be executed
      dc - The DbControl object used to execute the query
      BaseException - If there is any other error
    • getChildren

      public Collection<? extends QueryElement> getChildren()
      Description copied from interface: QueryElement
      Get the children of this query element or null if it has no children. For example the AddExpression has two children, the expression beeing added.
      Specified by:
      getChildren in interface QueryElement
      Always null
    • maybeEquals

      protected Boolean maybeEquals(Object other)
      Check as many things as possible to try to determine if the other object is equal to this object. This method checks if the other instance is the same instance as this object (returns true), if the other instance is null or not the same class (returns false), if the other instance has a different annotation type, alias or inheritance setting (returns false). Subclasses should do more checks if null is returned.
      TRUE or FALSE if it is certain or null if more checks are needed
    • hashCode

      public int hashCode()
      hashCode in class Object
    • getRestrictionSql

      abstract String getRestrictionSql(Query query, DbControl dc) throws BaseException
      Get an SQL fragment that includes the actual restriction. Use 'v.value' to access the annotation value. Avoid including literal values originating from a user, especially strings, since it may lead to security holes unless the values are checked for dangerous characters. Use a parameter placeholder instead. A parameter placeholder is a colon (:) followed by a name. Example:
      v.value = :theValue
      The setRestrictionParameters method is called to allow the subclass to set the value of the parameters specified in the SQL fragment.
      query - The query object we are about to execute
      An SQL fragment, or null if no additional restriction is required
      See Also:
    • setRestrictionParameters

      abstract void setRestrictionParameters(NativeQuery<?> query)
      Set the value for all parameters defined in the SQL fragment returned by getRestrictionSql(Query, DbControl).
      query - The Hibernate SQLQuery object which is used to query the database
    • notAmongSelected

      boolean notAmongSelected()
      If the main restriction should match items that had annotations among the selected annotation sets, or not.
      FALSE (default) to match the selected annotation sets, TRUE to match the non-selected annotation sets