Class AbstractTableQuery<T extends AbstractTableQuery<T>>
java.lang.Object
com.github.darksoulq.abyssallib.common.database.relational.AbstractTableQuery<T>
- Type Parameters:
T- The implementation type used for fluent chaining, allowing methods to return the specific subclass type.
- Direct Known Subclasses:
TableQuery, TableQuery, TableQuery, TableQuery, TableQuery
An abstract base class providing a fluent interface for table-level CRUD operations.
It supports standard INSERT, REPLACE, UPDATE, and DELETE operations, as well as complex
SELECT queries with mapping, ordering, and pagination.
-
Constructor Summary
ConstructorsConstructorDescriptionAbstractTableQuery(Connection connection, String table, ExecutorService asyncPool) Constructs a new AbstractTableQuery with the required execution context. -
Method Summary
Modifier and TypeMethodDescriptionlongcount()Executes a COUNT(*) query based on the current where clause configuration.delete()Sets the query operation mode to DELETE.intexecute()Executes the built data modification query synchronously.Asynchronously executes the currently built data modification operation.booleanexists()Determines if at least one row matches the query criteria.<R> Rfirst(ResultMapper<R> mapper) Fetches the first row from the result set and transforms it using the provided mapper.insert()Sets the query operation mode to INSERT.limit(int limit) Sets the maximum number of rows to be returned by the query.offset(int offset) Sets the starting offset for the result set, primarily used for pagination.Sets the ordering criteria for the resulting data set.replace()Sets the query operation mode to REPLACE.<R> List<R> select(ResultMapper<R> mapper) Selects all columns (*) from the table and maps the results.<R> List<R> select(ResultMapper<R> mapper, String... columns) Selects specific columns and maps the resulting rows into a list of objects.<R> CompletableFuture<List<R>> selectAsync(ResultMapper<R> mapper) Asynchronously selects all columns and maps the results.<R> CompletableFuture<List<R>> selectAsync(ResultMapper<R> mapper, String... columns) Asynchronously selects specific columns and maps the results.update()Sets the query operation mode to UPDATE.Adds a column-value pair to be used for INSERT, REPLACE, or UPDATE operations.Configures the filtering criteria for the query using a WHERE clause.
-
Constructor Details
-
AbstractTableQuery
Constructs a new AbstractTableQuery with the required execution context.- Parameters:
connection- The JDBC connection to be used for executing SQL statements.table- The name of the target database table.asyncPool- The executor service for handling asynchronous tasks.
-
-
Method Details
-
insert
Sets the query operation mode to INSERT.- Returns:
- The fluent instance cast to the implementation type
T.
-
replace
Sets the query operation mode to REPLACE.- Returns:
- The fluent instance cast to the implementation type
T.
-
update
Sets the query operation mode to UPDATE.- Returns:
- The fluent instance cast to the implementation type
T.
-
delete
Sets the query operation mode to DELETE.- Returns:
- The fluent instance cast to the implementation type
T.
-
value
-
where
Configures the filtering criteria for the query using a WHERE clause.- Parameters:
clause- The SQL string for the where clause, using '?' for parameter placeholders.params- The objects to bind to the placeholders in the provided clause.- Returns:
- The fluent instance cast to the implementation type
T.
-
orderBy
-
limit
Sets the maximum number of rows to be returned by the query.- Parameters:
limit- The maximum number of results.- Returns:
- The fluent instance cast to the implementation type
T.
-
offset
Sets the starting offset for the result set, primarily used for pagination.- Parameters:
offset- The number of rows to skip.- Returns:
- The fluent instance cast to the implementation type
T.
-
execute
public int execute()Executes the built data modification query synchronously.- Returns:
- The number of rows affected by the execution.
- Throws:
RuntimeException- If aSQLExceptionoccurs during execution.
-
executeAsync
Asynchronously executes the currently built data modification operation.- Returns:
- A
CompletableFuturecontaining the number of rows affected.
-
count
public long count()Executes a COUNT(*) query based on the current where clause configuration.- Returns:
- The total count of rows matching the query criteria.
- Throws:
RuntimeException- If aSQLExceptionoccurs.
-
exists
public boolean exists()Determines if at least one row matches the query criteria.- Returns:
- True if the matching count is greater than zero, false otherwise.
-
first
Fetches the first row from the result set and transforms it using the provided mapper.- Type Parameters:
R- The type of the resulting object.- Parameters:
mapper- TheResultMapperused to convert theResultSetrow into type R.- Returns:
- The mapped object, or
nullif no matching rows were found.
-
select
Selects all columns (*) from the table and maps the results.- Type Parameters:
R- The type of the resulting objects.- Parameters:
mapper- The mapper used for object transformation.- Returns:
- A list of mapped results.
-
select
Selects specific columns and maps the resulting rows into a list of objects.- Type Parameters:
R- The type of the resulting objects.- Parameters:
mapper- The mapper used for object transformation.columns- The column names to be included in the selection.- Returns:
- A list of transformed result objects.
- Throws:
RuntimeException- If an error occurs during execution or mapping.
-
selectAsync
Asynchronously selects all columns and maps the results.- Type Parameters:
R- The target result type.- Parameters:
mapper- The mapper for object conversion.- Returns:
- A
CompletableFuturecontaining the list of results.
-
selectAsync
Asynchronously selects specific columns and maps the results.- Type Parameters:
R- The target result type.- Parameters:
mapper- The mapper for object conversion.columns- The column names to select.- Returns:
- A
CompletableFuturecontaining the list of results.
-