Interface Restriction

All Superinterfaces:
QueryElement
All Known Implementing Classes:
AndRestriction, AnnotationBetweenRestriction, AnnotationInRestriction, AnnotationRestriction, AnnotationSet.ProjectSpecificAnnotationsRestriction, AnnotationSimpleRestriction, AnyToAnyRestriction, BetweenRestriction, ConditionalQueryElement, DynamicRestriction, EqRestriction, GteqRestriction, GtRestriction, HasAnnotationRestriction, HqlExpression, IdListRestriction, InRestriction, LikeRestriction, LteqRestriction, LtRestriction, NeqRestriction, NotRestriction, OrRestriction, PermissionRestriction, RlikeRestriction, SharedToRestriction

public interface Restriction extends QueryElement
A restriction query element. This is a query element that can appear in the WHERE and HAVING part of a Query. Typically a restriction consists of a condition which must be true for a row if it should be returned. For example:
SELECT ...
FROM ...
WHERE id = 2

Implementation note! Do not create restrictions that use user input directly in the queries. Always create a parameter (Expressions.parameter(String) and use the Query.setParameter(String, Object, Type) method to specify the value. Using parameters also makes it possible to execute the same query multiple times with different parameter values.

ItemQuery<User> query = User.getQuery();
query.restrict(
   Restrictions.eq(
      Hql.property("name"),
      Expressions.parameter("name")
   )
);

// Generated HQL
SELECT usr
FROM UserData usr
WHERE usr.name = :name

query.setParameter("name", "Nicklas");
List<User%gt; nicklasList = query.list(dc);

query.setParameter("name", "Johan");
List<User> johanList = query.list(dc);

Restrictions can be created by the Restrictions factory class.

Version:
2.0
Author:
Nicklas
See Also:
Last modified
$Date: 2015-04-21 09:59:42 +0200 (ti, 21 apr 2015) $