Class Ordering
java.lang.Object
ch.tocco.nice2.persist.core.api.query.Ordering
This class specifies the ordering policy of a query. It may be bound to an entity
model, but it doesn't have to. If it is bound to a model, it will check that
the specified fields exist. Ordering objects obtained by
Query.getOrdering()
are always bound. You may also order by fields of a related entity by using the
dot-notation known from the query language: myRelation.myField
. Note that
fields of entities of a one-to-many or many-to-many relation may not be used
for ordering.
This class is designed to reflect the behaviour of table ordering in GUIs.
Example:
Ordering o = new Ordering();
o.append("myField", Direction.ASCENDING);
o.append("myRel.otherField", Direction.valueOf("DESC"+"ENDING"));
o.apply(myQeury);
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
One of ASCENDING, DESCENDINGstatic class
Represents an ordering rule. -
Field Summary
-
Constructor Summary
ConstructorDescriptionOrdering()
Create an unbound ordering object.Ordering
(EntityModel model) Create an ordering object bound to the specified entity model. -
Method Summary
Modifier and TypeMethodDescriptionappend
(Path path, Ordering.Direction direction) Append an ordering rule to the policy.Append ordering rules to the policy.append
(String path, Ordering.Direction direction) Append an ordering rule to the policy.void
Apply this ordering policy to a query in strict mode.void
Apply this ordering policy to a query.clear()
Clear the ordering policy.boolean
getRules()
Get an array of the current ordering rules.int
hashCode()
boolean
isEmpty()
Check whether the ordering policy is empty.static Ordering
Create a new Ordering instance with ordering rules.prepend
(Path path, Ordering.Direction direction) Prepend an ordering rule to the policy.Prepend ordering rules to the policy.prepend
(String path, Ordering.Direction direction) Prepend an ordering rule to the policy.boolean
Remove a field/path from this ordering policy.boolean
Remove a field/path from this ordering policy.boolean
setDirection
(Path path, Ordering.Direction direction) Set the direction of the ordering rule for the specified field/path.boolean
setDirection
(String path, Ordering.Direction direction) Set the direction of the ordering rule for the specified field/path.int
size()
Get the size (field count) of this ordering policy.boolean
truncate
(int maxSize) Truncate the ordering policy to the specified size.
-
Field Details
-
model
-
-
Constructor Details
-
Ordering
public Ordering()Create an unbound ordering object. -
Ordering
Create an ordering object bound to the specified entity model.- Parameters:
model
- The model.
-
-
Method Details
-
of
Create a new Ordering instance with ordering rules.- Parameters:
paths
- The fields/paths to append. All paths are appended withOrdering.Direction.ASCENDING
, unless they're prefixed with a dash ('-').- Returns:
- the new Ordering instance.
-
apply
Apply this ordering policy to a query in strict mode.- Parameters:
query
- The query to apply this ordering policy to.- Throws:
PersistException
- If an error occurs.- See Also:
-
apply
Apply this ordering policy to a query. Thelenient
flag specifies, how unknown or invalid fields will be handled: Iflenient
is set totrue
, unknown or invalid fields will simply be discarded, if it's set tofalse
, an exception will be thrown.- Parameters:
query
- The query to apply this ordering policy to.lenient
-true
, for applying the ordering policy leniently,false
for applying it strictly.- Throws:
PersistException
- If an error occurs or, if applying strictly, an unknown or invalid field was encountered.
-
clear
Clear the ordering policy. -
isEmpty
public boolean isEmpty()Check whether the ordering policy is empty.- Returns:
true
, if the ordering policy is empty.
-
size
public int size()Get the size (field count) of this ordering policy.- Returns:
- The field count.
-
truncate
public boolean truncate(int maxSize) Truncate the ordering policy to the specified size.- Parameters:
maxSize
- The maximum size.- Returns:
true
, if the ordering policy was truncated,false
, if the policy remained unchanged.
-
append
Append an ordering rule to the policy. If the policy already contains a ordering rule for the specified field/path, it will be removed before appending.- Parameters:
path
- The field/path to append.direction
- The orderingdirection
.- Throws:
PersistException
- If an error occurred.
-
append
Append an ordering rule to the policy. If the policy already contains a ordering rule for the specified field/path, it will be removed before appending.- Parameters:
path
- The field/path to append.direction
- The orderingdirection
.- Throws:
PersistException
- If an error occurred.
-
append
Append ordering rules to the policy. If the policy already contains a ordering rule for the specified field/path, it will be removed before appending. All paths are appended withOrdering.Direction.ASCENDING
, unless they're prefixed with a dash ('-').- Parameters:
paths
- The fields/paths to append. All paths are appended withOrdering.Direction.ASCENDING
, unless they're prefixed with a dash ('-').- Throws:
PersistException
- If an error occurred.
-
prepend
Prepend an ordering rule to the policy. If the policy already contains a ordering rule for the specified field/path, the existing will be removed before prepending.- Parameters:
path
- The field/path to append.direction
- The orderingdirection
.- Throws:
PersistException
- If an error occurred.
-
prepend
Prepend an ordering rule to the policy. If the policy already contains a ordering rule for the specified field/path, the existing will be removed before prepending.- Parameters:
path
- The field/path to append.direction
- The orderingdirection
.- Throws:
PersistException
- If an error occurred.
-
prepend
Prepend ordering rules to the policy. If the policy already contains an ordering rule for the specified field/path, the existing will be removed before prepending. All paths are prepended withOrdering.Direction.ASCENDING
, unless they're prefixed with a dash ('-').- Parameters:
paths
- The fields/paths to append. All paths are appended withOrdering.Direction.ASCENDING
, unless they're prefixed with a dash ('-').- Throws:
PersistException
- If an error occurred.
-
remove
Remove a field/path from this ordering policy. If the policy contains no rule for the specified field/path, no action will be taken.- Parameters:
path
- The field/path.- Returns:
true
, if the field/path has been removed.
-
remove
Remove a field/path from this ordering policy. If the policy contains no rule for the specified field/path, no action will be taken.- Parameters:
path
- The field/path.- Returns:
true
, if the field/path has been removed.
-
setDirection
Set the direction of the ordering rule for the specified field/path. If the policy contains no rule for that field/path, no action will be taken.- Parameters:
path
- The path.direction
- The newdirection
.- Returns:
true
, if the direction has been set.
-
setDirection
Set the direction of the ordering rule for the specified field/path. If the policy contains no rule for that field/path, no action will be taken.- Parameters:
path
- The path.direction
- The newdirection
.- Returns:
true
, if the direction has been set.
-
getRules
Get an array of the current ordering rules.- Returns:
- An array of the current ordering rules.
-
equals
-
hashCode
public int hashCode()
-