Class SqlQueryExecutor

java.lang.Object
dimstyl.orm.internal.sql.execution.SqlQueryExecutor

public final class SqlQueryExecutor extends Object
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 Details

    • primitiveToWrapperMap

      private static final Map<Class<?>,Class<?>> primitiveToWrapperMap
      A mapping of primitive types to their corresponding wrapper classes.

      This is useful when retrieving values from a ResultSet, as JDBC returns wrapper types instead of primitives.

  • 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 extending Entity.
      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 required Column 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

      private static void executeCreateTable(String query, Connection connection) throws SQLException
      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.