2.17.2: 2011-06-17

net.sf.basedb.core
Class AnnotationSimpleRestriction

java.lang.Object
  extended by net.sf.basedb.core.AnnotationRestriction
      extended by net.sf.basedb.core.AnnotationSimpleRestriction
All Implemented Interfaces:
QueryElement, Restriction

public class AnnotationSimpleRestriction
extends AnnotationRestriction

Restricts a query using annotation values with a simple expression: annotation operator value.

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

Field Summary
private  Operator operator
           
private  List<ParameterExpression> parameters
           
private  Object value
           
private  List<Object> values
           
 
Fields inherited from class net.sf.basedb.core.AnnotationRestriction
alias, annotationTypeId, includeInheriting, valueType
 
Constructor Summary
AnnotationSimpleRestriction(AnnotationType annotationType, Operator operator, Object value, boolean includeInheriting)
          Deprecated. Use AnnotationSimpleRestriction(String, AnnotationType, Operator, Object, boolean) instead with alias=null
AnnotationSimpleRestriction(int annotationTypeId, Type valueType, Operator operator, Object value, boolean includeInheriting)
          Deprecated. Use AnnotationSimpleRestriction(String, int, Type, Operator, Object, boolean) instead with alias=null
AnnotationSimpleRestriction(String alias, AnnotationType annotationType, Operator operator, Object value, boolean includeInheriting)
          Create a new annotation restriction using a simple expression: annotation operator value.
AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, List<Object> values, boolean includeInheriting)
          Creates a new annotation restriction for a specific valueType.
AnnotationSimpleRestriction(String alias, int annotationTypeId, Type valueType, Operator operator, Object value, boolean includeInheriting)
          Creates a new annotation restriction for a specific valueType.
 
Method Summary
 boolean equals(Object other)
          This restriction is equal to another AnnotationSimpleRestriction if they have the same annotation type, operator, list of values and inheritance setting.
(package private)  String getRestrictionSql(Query query, DbControl dc)
          Get an SQL fragment that includes the actual restriction.
 int hashCode()
           
(package private)  void setRestrictionParameters(org.hibernate.SQLQuery query)
          Set the value for all parameters defined in the SQL fragment returned by AnnotationRestriction.getRestrictionSql(Query, DbControl).
 
Methods inherited from class net.sf.basedb.core.AnnotationRestriction
getChildren, maybeEquals, notAmongSelected, toQl
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

operator

private final Operator operator

value

private final Object value

values

private final List<Object> values

parameters

private List<ParameterExpression> parameters
Constructor Detail

AnnotationSimpleRestriction

public AnnotationSimpleRestriction(AnnotationType annotationType,
                                   Operator operator,
                                   Object value,
                                   boolean includeInheriting)
                            throws InvalidDataException
Deprecated. Use AnnotationSimpleRestriction(String, AnnotationType, Operator, Object, boolean) instead with alias=null

Create a new annotation restriction using a simple expression: annotation operator value. The restriction is applied to the root element of the query.

Throws:
InvalidDataException

AnnotationSimpleRestriction

public AnnotationSimpleRestriction(String alias,
                                   AnnotationType annotationType,
                                   Operator operator,
                                   Object value,
                                   boolean includeInheriting)
                            throws InvalidDataException
Create a new annotation restriction using a simple expression: annotation operator value.

Parameters:
alias - The alias of a joined item where the annotations are located or null to use the root entity of the query
annotationType - The annotation type to use in the query
operator - The operator, it must be one of the expression operators, EQ, NEQ, etc., not a boolean operator, AND, OR, etc.
value - The value to use in the query, it must be of the correct value type for the annotation as defined by the AnnotationType.getValueType() property
includeInheriting - If items inherting the annotation should be returned by the query or not
Throws:
InvalidDataException - If any of the parameters are null or not follow the rules above.
Since:
2.4

AnnotationSimpleRestriction

public AnnotationSimpleRestriction(int annotationTypeId,
                                   Type valueType,
                                   Operator operator,
                                   Object value,
                                   boolean includeInheriting)
                            throws InvalidDataException
Deprecated. Use AnnotationSimpleRestriction(String, int, Type, Operator, Object, boolean) instead with alias=null

Creates a new annotation restriction for a specific valueType. The restriction is applied to the root element of the query.

Throws:
InvalidDataException

AnnotationSimpleRestriction

public AnnotationSimpleRestriction(String alias,
                                   int annotationTypeId,
                                   Type valueType,
                                   Operator operator,
                                   Object value,
                                   boolean includeInheriting)
                            throws InvalidDataException
Creates a new annotation restriction for a specific valueType.

Parameters:
alias - The alias of a joined item where the annotations are located or null to use the root entity of the query
annotationTypeId - the id of the annotation type to use in the query
valueType - the type of values for annotations
operator - The operator, it must be one of the expression operators, EQ, NEQ, etc., not a boolean operator, AND, OR, etc.
value - The value to use in the query, it must be of the correct value type for the annotation as defined by the AnnotationType.getValueType() property
includeInheriting - TRUE if items inheriting the annotation should be returned by the query, FALSE otherwise
Throws:
InvalidDataException - If any of the parameters are null or not follow the rules above
Since:
2.4

AnnotationSimpleRestriction

public AnnotationSimpleRestriction(String alias,
                                   int annotationTypeId,
                                   Type valueType,
                                   Operator operator,
                                   List<Object> values,
                                   boolean includeInheriting)
                            throws InvalidDataException
Creates a new annotation restriction for a specific valueType. The restriction is with a list of values.

Parameters:
alias - The alias of a joined item where the annotations are located or null to use the root entity of the query
annotationTypeId - the id of the annotation type to use in the query
valueType - the type of values for annotations
operator - The operator, it must be one of the expression operators, EQ, NEQ, etc., not a boolean operator, AND, OR, etc.
values - The list of values that should be used in the query, they must be of the correct value type for the annotation as defined by the AnnotationType.getValueType() property.
includeInheriting - TRUE if items inheriting the annotation should be returned by the query, FALSE otherwise
Throws:
InvalidDataException - If any of the parameters are null or not follow the rules above
Since:
2.5
Method Detail

getRestrictionSql

String getRestrictionSql(Query query,
                         DbControl dc)
                   throws BaseException
Description copied from class: AnnotationRestriction
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.

Specified by:
getRestrictionSql in class AnnotationRestriction
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:
AnnotationRestriction.setRestrictionParameters(SQLQuery)

setRestrictionParameters

void setRestrictionParameters(org.hibernate.SQLQuery query)
Description copied from class: AnnotationRestriction
Set the value for all parameters defined in the SQL fragment returned by AnnotationRestriction.getRestrictionSql(Query, DbControl).

Specified by:
setRestrictionParameters in class AnnotationRestriction
Parameters:
query - The Hibernate SQLQuery object which is used to query the database

equals

public boolean equals(Object other)
This restriction is equal to another AnnotationSimpleRestriction if they have the same annotation type, operator, list of values and inheritance setting.

Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class AnnotationRestriction

2.17.2: 2011-06-17