java.lang.Object
org.litebridge.orm.engine.DeleteEngine
Engine for processing
DELETE statements.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final UpdateMetaDataDefault empty update metadata instance. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final <T extends Result>
TcompileAndExecute(int astCacheKey, QueryNode node, Function<PreparedOperation, @Nullable UpdateMetaData> updateMetaDataCreator, Class<T> resultType, LitebridgeContext litebridgeContext) Compiles and executes the provided query node against the database.static <DTO> QueryNodecreateDeleteNodeChain(Class<DTO> dtoClass, Function<DtoDeleteStart<DTO>, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Creates a chain of update nodes for the specified mapped DTO/entity type and delete logic.static QueryNodecreateDeleteNodeChain(String tableName, Function<SqlDeleteStart, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Creates a chain of update nodes for the specified table name and delete logic.<DTO> UpdateResultdelete(Class<DTO> dtoClass, Function<DtoDeleteStart<DTO>, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Executes a SQLDELETEstatement targeting a mapped DTO/entity class.delete(String tableName, Function<SqlDeleteStart, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Executes a SQLDELETEstatement targeting a specific table.protected final <T extends Result>
Texecute(PreparedSql preparedSql, Class<T> resultType, LitebridgeContext litebridgeContext) Executes the provided prepared SQL statement against the database and returns the result of the operation.protected final <T extends Result>
Texecute(QueryNode node, Function<PreparedOperation, @Nullable UpdateMetaData> updateMetaDataCreator, Class<T> resultType, LitebridgeContext litebridgeContext) Executes a given query node, either by using a cached prepared SQL statement or by compiling and executing it if no cache exists.protected final UpdateResultexecute(QueryNode node, LitebridgeContext litebridgeContext) Executes a given query node within the provided Litebridge context and returns the result of the operation.protected org.slf4j.Loggerlogger()Returns the logger for the engine.protected StringReturns the engine's operation type name, for logging.
-
Field Details
-
EMPTY_UPDATE_META_DATA
Default empty update metadata instance.
-
-
Constructor Details
-
DeleteEngine
public DeleteEngine()
-
-
Method Details
-
delete
public <DTO> UpdateResult delete(Class<DTO> dtoClass, Function<DtoDeleteStart<DTO>, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Executes a SQLDELETEstatement targeting a mapped DTO/entity class.- Type Parameters:
DTO- the mapped DTO/entity type- Parameters:
dtoClass- the mapped DTO/entity type to deletedelete- delete logic; a function that takes aDtoDeleteStartand returns aDeleteTerminallitebridgeContext- Litebridge context- Returns:
- the result of the delete operation
-
delete
public UpdateResult delete(String tableName, Function<SqlDeleteStart, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Executes a SQLDELETEstatement targeting a specific table.- Parameters:
tableName- the name of the table to deletedelete- delete logic; a function that takes aSqlDeleteStartand returns aDeleteTerminallitebridgeContext- Litebridge context- Returns:
- the result of the update operation
-
createDeleteNodeChain
public static <DTO> QueryNode createDeleteNodeChain(Class<DTO> dtoClass, Function<DtoDeleteStart<DTO>, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Creates a chain of update nodes for the specified mapped DTO/entity type and delete logic.- Type Parameters:
DTO- the mapped DTO/entity type- Parameters:
dtoClass- the mapped DTO/entity type to updatedelete- delete logic; a function defining the update operation, which consumes aDtoDeleteStartinstance and returns anDeleteTerminallitebridgeContext- Litebridge context- Returns:
- the terminal
QueryNodeof the constructed delete query chain
-
createDeleteNodeChain
public static QueryNode createDeleteNodeChain(String tableName, Function<SqlDeleteStart, DeleteTerminal> delete, LitebridgeContext litebridgeContext) Creates a chain of update nodes for the specified table name and delete logic.- Parameters:
tableName- the name of the database table to updatedelete- delete logic; a function defining the update operation, which consumes aSqlDeleteStartinstance and returns anDeleteTerminallitebridgeContext- Litebridge context- Returns:
- the terminal
QueryNodeof the constructed update query chain
-
operationTypeName
Returns the engine's operation type name, for logging.- Returns:
- The name of the engine's operation type.
-
logger
protected org.slf4j.Logger logger()Returns the logger for the engine.- Returns:
- the engine's logger instance
-
execute
Executes a given query node within the provided Litebridge context and returns the result of the operation.- Parameters:
node- The query node representing a step in the query chain to be executed.litebridgeContext- Context for the statement execution.- Returns:
- The result of executing the query node, represented as an instance of
UpdateResult, which includes information such as the number of rows affected by the operation. - Throws:
IllegalStateException- If an error occurs during query execution, such as issues with the database or query compilation.
-
execute
protected final <T extends Result> T execute(QueryNode node, Function<PreparedOperation, @Nullable UpdateMetaData> updateMetaDataCreator, Class<T> resultType, LitebridgeContext litebridgeContext) Executes a given query node, either by using a cached prepared SQL statement or by compiling and executing it if no cache exists.The result is returned as an instance of the specified result type.
- Type Parameters:
T- The type of the result extendingUpdateOpResult.- Parameters:
node- The query node to be executed.updateMetaDataCreator- A function to create update metadata for the operation.resultType- The class type of the result to return; must extendUpdateOpResult.litebridgeContext- Context for the statement execution.- Returns:
- The result of executing the query node, represented as an instance of the specified result type. This result contains information about the outcome of the operation, such as the number of rows affected.
- Throws:
IllegalStateException- If an error occurs during SQL execution, including database or query issues.
-
compileAndExecute
protected final <T extends Result> T compileAndExecute(int astCacheKey, QueryNode node, Function<PreparedOperation, @Nullable UpdateMetaData> updateMetaDataCreator, Class<T> resultType, LitebridgeContext litebridgeContext) Compiles and executes the provided query node against the database.- Type Parameters:
T- The type of the result.- Parameters:
astCacheKey- The cache key for the AST.node- The query node to be compiled and executed.updateMetaDataCreator- A function to create update metadata.resultType- The result type to return.litebridgeContext- The context for the statement execution.- Returns:
- The result of the database operation, which is an instance of the specified result type.
- Throws:
IllegalStateException- If the execution of the SQL statement fails, including database or query issues.
-
execute
protected final <T extends Result> T execute(PreparedSql preparedSql, Class<T> resultType, LitebridgeContext litebridgeContext) Executes the provided prepared SQL statement against the database and returns the result of the operation.- Type Parameters:
T- The type of the result.- Parameters:
preparedSql- The prepared SQL statement containing the SQL query and its bind parameters.resultType- The result type to return.litebridgeContext- Context for the statement execution.- Returns:
- The result of the database operation, which is an instance of the specified result type.
- Throws:
IllegalStateException- If the execution of the SQL statement fails, including database or query issues.
-