Package net.sf.basedb.core
Class AnnotationRestriction
java.lang.Object
net.sf.basedb.core.AnnotationRestriction
- All Implemented Interfaces:
QueryElement
,Restriction
- Direct Known Subclasses:
AnnotationBetweenRestriction
,AnnotationInRestriction
,AnnotationSimpleRestriction
,HasAnnotationRestriction
Base class for creating restrictions based on annotations.
Subclasses must implent the
getRestrictionSql(Query, DbControl)
and setRestrictionParameters(NativeQuery)
method.- Version:
- 2.0
- Author:
- Nicklas
- See Also:
- Last modified
- $Date: 2019-03-12 08:29:06 +0100 (tis, 12 mars 2019) $
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Options that specify which annotations to consider when searching. -
Field Summary
Modifier and TypeFieldDescription(package private) final String
private AnnotationType
(package private) final int
private static final boolean
So we don't always have to call logSql.debug()private static final Logger
Log all SQL statements.(package private) final AnnotationRestriction.Options
(package private) final Type
-
Constructor Summary
ConstructorDescriptionAnnotationRestriction
(String alias, int annotationTypeId, Type valueType, AnnotationRestriction.Options options) Deprecated.In 3.11AnnotationRestriction
(String alias, AnnotationType annotationType, AnnotationRestriction.Options options) Create a new annotation restriction for an annotation type. -
Method Summary
Modifier and TypeMethodDescriptionCollection<? extends QueryElement>
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
If the main restriction should match items that had annotations among the selected annotation sets, or not.(package private) abstract void
setRestrictionParameters
(NativeQuery<?> query) Set the value for all parameters defined in the SQL fragment returned bygetRestrictionSql(Query, DbControl)
.Create a query language string of the query element.
-
Field Details
-
logSql
Log all SQL statements. -
debugSqlEnabled
private static final boolean debugSqlEnabledSo we don't always have to call logSql.debug() -
annotationType
-
valueType
-
annotationTypeId
final int annotationTypeId -
options
-
alias
-
-
Constructor Details
-
AnnotationRestriction
AnnotationRestriction(String alias, AnnotationType annotationType, AnnotationRestriction.Options options) throws InvalidDataException Create a new annotation restriction for an annotation type.- Parameters:
annotationType
- The annotation type to use in the query- Throws:
InvalidDataException
-
AnnotationRestriction
@Deprecated AnnotationRestriction(String alias, int annotationTypeId, Type valueType, AnnotationRestriction.Options options) throws InvalidDataException Deprecated.In 3.11Create 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 typevalueType
- The type of values for annotations- Throws:
InvalidDataException
-
-
Method Details
-
toQl
Description copied from interface:QueryElement
Create a query language string of the query element. Use theQuery.getQueryType()
method to find out which query language is wanted in case the element requires different syntax for different languages.- Specified by:
toQl
in interfaceQueryElement
- Parameters:
query
- The query that is about to be executeddc
- TheDbControl
object used to execute the query- Throws:
BaseException
- If there is any other error
-
getChildren
Description copied from interface:QueryElement
Get the children of this query element or null if it has no children. For example theAddExpression
has two children, the expression beeing added.- Specified by:
getChildren
in interfaceQueryElement
- Returns:
- Always null
-
maybeEquals
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() -
getRestrictionSql
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
ThesetRestrictionParameters
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
Set the value for all parameters defined in the SQL fragment returned bygetRestrictionSql(Query, DbControl)
.- Parameters:
query
- The HibernateSQLQuery
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
-