Module is.codion.framework.domain
Interface CustomCondition
- All Superinterfaces:
Condition
A custom Condition based on a ConditionProvider.
Custom conditions are used to create query conditions that can not be created with the
Condition, ColumnCondition or ForeignKeyCondition APIs, for example
conditions using JOINs or native DBMS functionality.
A ConditionType is associated with a ConditionProvider, which is responsible
for creating the condition string via ConditionProvider.toString(List, List).
// Custom condition with values
Track.TYPE.define(
...
).condition(Track.NOT_IN_PLAYLIST, (columns, values) ->
new StringBuilder("""
trackid NOT IN (
SELECT trackid
FROM chinook.playlisttrack
WHERE playlistid IN ("""
)
.append(String.join(", ",
Collections.nCopies(values.size(), "?")))
.append(")\n")
.append(")")
.toString());
Condition condition =
Track.NOT_IN_PLAYLIST.get(Playlist.ID, List.of(42L, 43L));
// Custom condition without values
Track.TYPE.define(
...
).condition(Track.EXCLUDED, (columns, values) ->
"trackid not in (select trackid from chinook.excluded_tracks)");
Condition condition = Track.EXCLUDED.get();
List<Entity> tracks = connection.select(
Condition.and(Track.NAME.like("The%"), condition));
The ? substitute character is replaced with the condition values when when the statement is prepared.
That relies on the columns List for the value data type, and assumes it contains the Column associated
with each value at the same index. If the columns List is empty, no value substitution is performed.
-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.framework.domain.entity.condition.Condition
Condition.All, Condition.Combination -
Method Summary
Methods inherited from interface is.codion.framework.domain.entity.condition.Condition
columns, entityType, toString, values
-
Method Details
-
conditionType
ConditionType conditionType()- Returns:
- the condition type
-