Interface ForeignKeyConditions
- All Known Subinterfaces:
ForeignKey
A ForeignKey based condition for filtering entities by their relationships.
ForeignKeyConditions enable querying entities based on their references to other entities. They provide type-safe filtering using entity instances or collections of entities, automatically handling primary key extraction and null value cases.
Foreign key conditions are typically created through the ForeignKeyConditions interface, which all ForeignKey instances implement:
// Find albums by specific artist
Entity aliceInChains = connection.selectSingle(
Artist.NAME.equalTo("Alice In Chains"));
List<Entity> aliceInChainsAlbums = connection.select(
Album.ARTIST_FK.equalTo(aliceInChains));
// Find tracks by genre
Entity metal = connection.selectSingle(
Genre.NAME.equalToIgnoreCase("metal"));
List<Entity> metalTracks = connection.select(
Track.GENRE_FK.equalTo(metal));
// Find albums by multiple artists
List<Entity> theArtists = connection.select(
Artist.NAME.like("The %"));
List<Entity> albumsByTheArtists = connection.select(
Album.ARTIST_FK.in(theArtists));
// Find tracks without a genre
List<Entity> uncategorizedTracks = connection.select(
Track.GENRE_FK.isNull());
// Find tracks with a genre
List<Entity> categorizedTracks = connection.select(
Track.GENRE_FK.isNotNull());
// Complex query with foreign key conditions
List<Entity> albums = connection.select(and(
Album.ARTIST_FK.in(theArtists),
Album.ARTIST_FK.notEqualTo(excludedArtist)));
// Using with Select for more control
List<Entity> rockTracks = connection.select(
Select.where(Track.GENRE_FK.equalTo(rock))
.attributes(Track.NAME, Track.ALBUM_FK)
.orderBy(ascending(Track.NAME)));
// Foreign key conditions with null handling
List<Entity> metalOrUncategorized = connection.select(or(
Track.GENRE_FK.equalTo(metal),
Track.GENRE_FK.isNull()));
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ForeignKeyConditionsconditions(ForeignKey foreignKey) Instantiates a newForeignKeyConditionsinstanceReturns an 'equalTo'Conditionor 'isNull' in casevalueis null.Returns an 'in'Condition.in(Collection<Entity> values) Returns an 'in'Condition.Returns an 'isNotNull'Condition.isNull()Returns an 'isNull'Condition.notEqualTo(@Nullable Entity value) Returns a 'notEqualTo'Conditionor 'isNotNull' in casevalueis null.Returns a 'notIn'Condition.notIn(Collection<Entity> values) Returns a 'notIn' condition.
-
Method Details
-
equalTo
-
notEqualTo
-
in
Returns an 'in'Condition.- Parameters:
values- the values to use in the condition- Returns:
- a
Condition - Throws:
NullPointerException- in casevaluesis null or an entity provides no value for a non-nullable referenced column, as one which has not been inserted does notIllegalArgumentException- in casevaluesis empty
-
notIn
Returns a 'notIn'Condition.- Parameters:
values- the values to use in the condition- Returns:
- a
Condition - Throws:
NullPointerException- in casevaluesis null or an entity provides no value for a non-nullable referenced column, as one which has not been inserted does notIllegalArgumentException- in casevaluesis empty
-
in
Returns an 'in'Condition.- Parameters:
values- the values to use in the condition- Returns:
- a
Condition - Throws:
NullPointerException- in casevaluesis null or an entity provides no value for a non-nullable referenced column, as one which has not been inserted does notIllegalArgumentException- in casevaluesis empty
-
notIn
Returns a 'notIn' condition.- Parameters:
values- the values to use in the condition- Returns:
- a
Condition - Throws:
NullPointerException- in casevaluesis null or an entity provides no value for a non-nullable referenced column, as one which has not been inserted does notIllegalArgumentException- in casevaluesis empty
-
isNull
-
isNotNull
-
conditions
Instantiates a newForeignKeyConditionsinstanceUsed by
ForeignKey, which provides these conditions itself, applications create them from the foreign key.- Parameters:
foreignKey- the foreign key- Returns:
- a new
ForeignKeyConditionsinstance
-