Class SqlQueryExecutor
java.lang.Object
dimstyl.orm.internal.sql.execution.SqlQueryExecutor
Utility class responsible for executing SQL queries related to ORM operations.
This class provides methods for executing SQL queries such as `CREATE TABLE`, `SELECT ALL`, and `DELETE BY ID` while mapping results to entity classes dynamically.
-
Field Summary
FieldsModifier and TypeFieldDescriptionA mapping of primitive types to their corresponding wrapper classes. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Private constructor to prevent instantiation of this utility class. -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
executeCreateTable
(String query, Connection connection) Executes a single `CREATE TABLE` query.static void
executeCreateTableQueries
(List<String> createTableQueries, Connection connection) Executes a list of `CREATE TABLE` SQL queries.static <T> void
executeDeleteByIdQuery
(String query, Connection connection, T id) Executes a `DELETE BY ID` query to remove a record from the database.executeSelectAllQuery
(String query, Connection connection, Class<T> entityClass) Executes a `SELECT ALL` query and maps the results to a list of entity objects.
-
Field Details
-
primitiveToWrapperMap
-
-
Constructor Details
-
SqlQueryExecutor
private SqlQueryExecutor()Private constructor to prevent instantiation of this utility class.
-
-
Method Details
-
executeCreateTableQueries
public static void executeCreateTableQueries(List<String> createTableQueries, Connection connection) throws SqlExecutionException Executes a list of `CREATE TABLE` SQL queries.- Parameters:
createTableQueries
- List of SQL `CREATE TABLE` queries.connection
- The database connection.- Throws:
SqlExecutionException
- If an error occurs while executing the queries.
-
executeSelectAllQuery
public static <T extends Entity> List<T> executeSelectAllQuery(String query, Connection connection, Class<T> entityClass) throws MissingColumnAnnotationException, SqlExecutionException Executes a `SELECT ALL` query and maps the results to a list of entity objects.- Type Parameters:
T
- The type of the entity extendingEntity
.- Parameters:
query
- The SQL `SELECT ALL` query to be executed.connection
- The database connection.entityClass
- The entity class type to map the result set.- Returns:
- A list of mapped entity objects.
- Throws:
MissingColumnAnnotationException
- If a requiredColumn
annotation is missing.SqlExecutionException
- If an error occurs during query execution.
-
executeDeleteByIdQuery
public static <T> void executeDeleteByIdQuery(String query, Connection connection, T id) throws SqlExecutionException Executes a `DELETE BY ID` query to remove a record from the database.- Type Parameters:
T
- The type of the ID (e.g., Integer, Long, String).- Parameters:
query
- The SQL `DELETE` query with a placeholder for the ID.connection
- The database connection.id
- The ID value to use in the query.- Throws:
SqlExecutionException
- If an error occurs while executing the query.
-
executeCreateTable
Executes a single `CREATE TABLE` query.- Parameters:
query
- The `CREATE TABLE` SQL query.connection
- The database connection.- Throws:
SQLException
- If an error occurs during query execution.
-