2.17.2: 2011-06-17

net.sf.basedb.core
Class AnnotationRestriction

java.lang.Object
  extended by net.sf.basedb.core.AnnotationRestriction
All Implemented Interfaces:
QueryElement, Restriction
Direct Known Subclasses:
AnnotationBetweenRestriction, AnnotationInRestriction, AnnotationSimpleRestriction, HasAnnotationRestriction

abstract class AnnotationRestriction
extends Object
implements Restriction

Base class for creating restrictions based on annotations. Subclasses must implent the getRestrictionSql(Query, DbControl) and setRestrictionParameters(SQLQuery) method.

Version:
2.0
Author:
Nicklas
See Also:
Annotations
Last modified
$Date: 2010-09-27 14:53:33 +0200 (Mon, 27 Sep 2010) $

Field Summary
(package private)  String alias
           
(package private)  int annotationTypeId
           
private static boolean debugSqlEnabled
          So we don't always have to call logSql.debug()
(package private)  boolean includeInheriting
           
private static Logger logSql
          Log all SQL statements.
(package private)  Type valueType
           
 
Constructor Summary
AnnotationRestriction(String alias, AnnotationType annotationType, boolean includeInheriting)
          Create a new annotation restriction for an annotation type.
AnnotationRestriction(String alias, int annotationTypeId, Type valueType, boolean includeInheriting)
          Create a new annotation restriction given the id and value type of an annotation.
 
Method Summary
 Collection<? extends QueryElement> getChildren()
          Get the children of this query element or null if it has no children.
(package private) abstract  String getRestrictionSql(Query query, DbControl dc)
          Get an SQL fragment that includes the actual restriction.
 int hashCode()
           
protected  Boolean maybeEquals(Object other)
          Check as many things as possible to try to determine if the other object is equal to this object.
(package private)  boolean notAmongSelected()
          If the main restriction should match items that had annotations among the selected annotation sets, or not.
(package private) abstract  void setRestrictionParameters(org.hibernate.SQLQuery query)
          Set the value for all parameters defined in the SQL fragment returned by getRestrictionSql(Query, DbControl).
 String toQl(Query query, DbControl dc)
          Create a query language string of the query element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logSql

private static final Logger logSql
Log all SQL statements.


debugSqlEnabled

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


valueType

final Type valueType

annotationTypeId

final int annotationTypeId

includeInheriting

final boolean includeInheriting

alias

final String alias
Constructor Detail

AnnotationRestriction

AnnotationRestriction(String alias,
                      AnnotationType annotationType,
                      boolean includeInheriting)
                throws InvalidDataException
Create a new annotation restriction for an annotation type.

Parameters:
annotationType - The annotation type to use in the query
Throws:
InvalidDataException

AnnotationRestriction

AnnotationRestriction(String alias,
                      int annotationTypeId,
                      Type valueType,
                      boolean includeInheriting)
                throws InvalidDataException
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.

Parameters:
annotationTypeId - The id of the annotation type
valueType - The type of values for annotations
Throws:
InvalidDataException
Method Detail

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
Parameters:
query - The query that is about to be executed
dc - The DbControl object used to execute the query
Throws:
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
Returns:
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.

Returns:
TRUE or FALSE if it is certain or null if more checks are needed

hashCode

public int hashCode()
Overrides:
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.

Parameters:
query - The query object we are about to execute
Returns:
An SQL fragment, or null if no additional restriction is required
Throws:
BaseException
See Also:
setRestrictionParameters(SQLQuery)

setRestrictionParameters

abstract void setRestrictionParameters(org.hibernate.SQLQuery query)
Set the value for all parameters defined in the SQL fragment returned by getRestrictionSql(Query, DbControl).

Parameters:
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.

Returns:
FALSE (default) to match the selected annotation sets, TRUE to match the non-selected annotation sets
Since:
2.7

2.17.2: 2011-06-17