- Enclosing interface:
EntityConnection
public static interface EntityConnection.Select
A class encapsulating select query parameters.
A factory for
EntityConnection.Select.Builder instances via
all(EntityType), where(Condition).
// Simple select with condition
List<Entity> metalTracks = connection.select(
Select.where(Track.GENRE_FK.equalTo(metal))
.build()
);
// Complex select with multiple options
List<Entity> tracks = connection.select(
Select.where(Track.ALBUM_FK.equalTo(album))
.orderBy(OrderBy.ascending(Track.TRACKNO))
.attributes(Track.NAME, Track.MILLISECONDS, Track.COMPOSER)
.limit(50)
.referenceDepth(Track.GENRE_FK, 0) // Don't fetch genre
.referenceDepth(Track.MEDIATYPE_FK, 1) // Fetch media type
.build()
);
// Select for update (row locking)
Entity invoice = connection.selectSingle(
Select.where(Invoice.ID.equalTo(invoiceId))
.forUpdate()
.build()
);
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionall(EntityType entityType) Collection<Attribute<?>> Returns the explicit attributes specified for this select, if any.Collection<Attribute<?>> exclude()Returns the attributes to exclude from the query result.Returns a map containing the number of levels of foreign key values to fetch per foreign key, with 0 meaning no referenced entities should be fetched, -1 no limit.booleanhaving()Collection<Attribute<?>> include()Returns the attributes to include in addition to those specified viaattributes().limit()offset()orderBy()referenceDepth(ForeignKey foreignKey) Returns the number of levels of foreign key values to fetch, with 0 meaning the referenced entity should not be fetched, -1 no limit and an empty Optional if the global limit should be used (referenceDepth()).inttimeout()where()
-
Method Details
-
where
Condition where()- Returns:
- the WHERE condition
-
having
Condition having()- Returns:
- the HAVING condition
-
orderBy
- Returns:
- the
OrderByfor this condition, an empty Optional if none is specified
-
limit
OptionalInt limit()- Returns:
- the LIMIT to use for the given condition, an empty Optional for no limit
-
offset
OptionalInt offset()- Returns:
- the OFFSET to use for the given condition, an empty Optional for no offset
-
forUpdate
boolean forUpdate()- Returns:
- true if this select should lock the result FOR UPDATE
-
timeout
int timeout()- Returns:
- the query timeout
-
referenceDepth
OptionalInt referenceDepth()- Returns:
- the global reference depth limit for this condition, an empty Optional if none has been specified
-
referenceDepth
Returns the number of levels of foreign key values to fetch, with 0 meaning the referenced entity should not be fetched, -1 no limit and an empty Optional if the global limit should be used (referenceDepth()).- Parameters:
foreignKey- the foreign key- Returns:
- the number of levels of foreign key values to fetch
-
foreignKeyReferenceDepths
Map<ForeignKey,Integer> foreignKeyReferenceDepths()Returns a map containing the number of levels of foreign key values to fetch per foreign key, with 0 meaning no referenced entities should be fetched, -1 no limit.- Returns:
- a map containing the number of levels of foreign key values to fetch for each foreign key
-
attributes
Collection<Attribute<?>> attributes()Returns the explicit attributes specified for this select, if any. An empty collection indicates that default attributes should be used (those marked with.selected(true)).The final set of attributes is computed as:
(attributes ∪ include) \ exclude, whereattributesdefaults to the entity's selected attributes when empty.- Returns:
- the explicit attributes to include in the query result, an empty Collection if defaults should be used
- See Also:
-
include
Collection<Attribute<?>> include()Returns the attributes to include in addition to those specified viaattributes(). Ifattributes()is empty, these are added to the default selected attributes.This is useful for including lazy-loaded attributes (
.selected(false)) without having to explicitly list all default attributes.Note that attributes required by included foreign keys cannot be excluded, even if listed in
exclude(), as foreign keys need their reference columns to function.// Include a lazy blob column along with all defaults List<Entity> countries = connection.select( Select.all(Country.TYPE) .include(Country.FLAG) // FLAG is .selected(false) .build() ); // Include lazy column with explicit attributes List<Entity> countries = connection.select( Select.all(Country.TYPE) .attributes(Country.CODE, Country.NAME) .include(Country.FLAG) .build() );- Returns:
- the attributes to include in addition to the base set
- See Also:
-
exclude
Collection<Attribute<?>> exclude()Returns the attributes to exclude from the query result. These are removed from the final attribute set after applyingattributes()andinclude().Note that primary key attributes are always included regardless of exclusions, and attributes required by included foreign keys cannot be excluded.
// Exclude an expensive computed column List<Entity> employees = connection.select( Select.all(Employee.TYPE) .exclude(Employee.COMPUTED_BONUS) .build() ); // Exclude multiple columns List<Entity> employees = connection.select( Select.all(Employee.TYPE) .include(Employee.PHOTO) .exclude(Employee.NOTES, Employee.RESUME) .build() );- Returns:
- the attributes to exclude from the query result
- See Also:
-
all
- Parameters:
entityType- the entity type- Returns:
- a new
EntityConnection.Select.Builderinstance
-
where
- Parameters:
condition- the WHERE condition- Returns:
- a new
EntityConnection.Select.Builderinstance
-
having
- Parameters:
condition- the HAVING condition- Returns:
- a new
EntityConnection.Select.Builderinstance
-