java.lang.Object
org.litebridge.orm.engine.SelectEngineTerminal
Executes SQL
SELECT statements.-
Constructor Summary
ConstructorsConstructorDescriptionSelectEngineTerminal(DtoConstructor dtoConstructor) Creates a newSelectEngineTerminalinstance. -
Method Summary
Modifier and TypeMethodDescription<DTO> Optional<DTO> fetchFirst(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns the first row if present.<DTO> @Nullable DTOfetchFirstOrNull(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns the first row if present, ornullif no row matches.<DTO> DTOfetchFirstOrThrow(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns the first row.<DTO,X extends Throwable>
DTOfetchFirstOrThrow(QueryNode node, LitebridgeContext litebridgeContext, Supplier<? extends X> exceptionSupplier) Executes the query and returns the first row.<DTO> List<DTO> fetchList(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns a list of results.<DTO> Optional<DTO> fetchOne(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns exactly one result.<DTO> @Nullable DTOfetchOneOrNull(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns exactly one result, ornullif no row matches.<DTO> DTOfetchOneOrThrow(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns exactly one result.<DTO,X extends Throwable>
DTOfetchOneOrThrow(QueryNode node, LitebridgeContext litebridgeContext, Supplier<? extends X> exceptionSupplier) Executes the query and returns exactly one result.<DTO> Stream<DTO> fetchStream(QueryNode node, LitebridgeContext litebridgeContext) Executes the query and returns results as aStream.generateSql(QueryNode node, LitebridgeContext litebridgeContext) Generates SQL for the query without executing it.
-
Constructor Details
-
SelectEngineTerminal
Creates a newSelectEngineTerminalinstance.- Parameters:
dtoConstructor- theDtoConstructorused to construct DTOs
-
-
Method Details
-
fetchOne
public <DTO> Optional<DTO> fetchOne(QueryNode node, LitebridgeContext litebridgeContext) throws NonUniqueResultException Executes the query and returns exactly one result.The returned
Optionalis empty when no row matches. If more than one row matches, anIllegalStateExceptionis thrown.- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- an
Optionalcontaining the single result, if present - Throws:
NonUniqueResultException- if the query returns more than one result
-
fetchOneOrNull
public <DTO> @Nullable DTO fetchOneOrNull(QueryNode node, LitebridgeContext litebridgeContext) throws NonUniqueResultException Executes the query and returns exactly one result, ornullif no row matches.If more than one row matches, an
NonUniqueResultExceptionis thrown.- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- the single result, or
nullwhen no row matches - Throws:
NonUniqueResultException- if more than one row matches
-
fetchOneOrThrow
Executes the query and returns exactly one result.If no row matches, an
NoSuchElementExceptionis thrown. If more than one row matches, anNonUniqueResultExceptionis thrown.- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- the single result
- Throws:
NoSuchElementException- if no row matchesNonUniqueResultException- if more than one row matches
-
fetchOneOrThrow
public <DTO,X extends Throwable> DTO fetchOneOrThrow(QueryNode node, LitebridgeContext litebridgeContext, Supplier<? extends X> exceptionSupplier) throws X Executes the query and returns exactly one result.If no row matches, the supplied exception is thrown. If more than one row matches, an
NonUniqueResultExceptionis thrown.- Type Parameters:
DTO- the result typeX- exception type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge contextexceptionSupplier- supplier used to create the exception to throw when the result is not exactly one row- Returns:
- the single result
- Throws:
X- if no row matches or more than one row matchesNonUniqueResultException- if more than one row matches
-
fetchFirst
Executes the query and returns the first row if present.Unlike
fetchOne(QueryNode, LitebridgeContext), this method does not require uniqueness; if multiple rows match, only the first is returned (according to the effective ordering, if any).- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- an
Optionalwith the first result, if present
-
fetchFirstOrNull
Executes the query and returns the first row if present, ornullif no row matches.- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- the first result, or
nullif no row matches
-
fetchFirstOrThrow
Executes the query and returns the first row.If no row matches, an
NoSuchElementExceptionis thrown.- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- the first result
- Throws:
NoSuchElementException- if no row matches
-
fetchFirstOrThrow
public <DTO,X extends Throwable> DTO fetchFirstOrThrow(QueryNode node, LitebridgeContext litebridgeContext, Supplier<? extends X> exceptionSupplier) throws X Executes the query and returns the first row.If no row matches, the supplied exception is thrown.
- Type Parameters:
DTO- the result typeX- exception type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge contextexceptionSupplier- supplier used to create the exception to throw when no row matches- Returns:
- the first result
- Throws:
X- if no row matches
-
fetchStream
Executes the query and returns results as aStream.- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- a stream of results
-
fetchList
Executes the query and returns a list of results.- Type Parameters:
DTO- the result type- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- list of all matching results (possibly empty)
-
generateSql
Generates SQL for the query without executing it.- Parameters:
node- the AST query node representing the querylitebridgeContext- the Litebridge context- Returns:
- The generated SQL, bind values and query metadata.
-