Class AbstractSqlGenerator

java.lang.Object
org.litebridge.db.spi.impl.sql.AbstractSqlGenerator
Direct Known Subclasses:
DeleteSqlGenerator, InsertSqlGenerator, SelectSqlGenerator, UpdateSqlGenerator

public abstract class AbstractSqlGenerator extends Object
Abstract base class for SQL generators.
  • Field Details

    • typeConverter

      protected final TypeConverter typeConverter
      The type converter used for mapping between database and Java types.
    • columnIdentifierGenerator

      protected final ColumnIdentifierGenerator columnIdentifierGenerator
      The generator for column identifiers.
  • Constructor Details

    • AbstractSqlGenerator

      public AbstractSqlGenerator(TypeConverter typeConverter, ColumnIdentifierGenerator columnIdentifierGenerator, BiFunction<Table,ConnectionProvider,TableMetaData> ensureTableMetaData)
      Constructs a new AbstractSqlGenerator.
      Parameters:
      typeConverter - The type converter to use.
      columnIdentifierGenerator - The column identifier generator to use.
      ensureTableMetaData - The function to ensure table metadata is available.
  • Method Details

    • createCondition

      protected PreparedSql createCondition(Condition condition, Operation operation, ConnectionProvider connectionProvider)
      Generate a SQL condition string based on the given Condition. This method constructs the SQL fragment by combining the column, operator, and value (if applicable) for the provided condition.
      Parameters:
      condition - the Condition object specifying the column, operator, and value for the SQL condition
      operation - the current database operation
      connectionProvider - the connection provider
      Returns:
      a PreparedSql representing the constructed SQL condition fragment
    • mapOperator

      protected String mapOperator(Operator operator)
      Map an Operator enum to its corresponding string representation used in logical or database operations.
      Parameters:
      operator - the Operator enum to be mapped
      Returns:
      the string representation of the provided Operator
    • appendTable

      protected StringBuilder appendTable(StringBuilder sql, Table table)
      Appends a table name to the SQL builder, quoting identifiers.
      Parameters:
      sql - The SQL builder.
      table - The table to append.
      Returns:
      The SQL builder.
    • appendTable

      protected StringBuilder appendTable(StringBuilder sql, @Nullable String schema, String table)
      Appends a table name to the SQL builder, quoting identifiers.
      Parameters:
      sql - The SQL builder.
      schema - The schema name.
      table - The table name.
      Returns:
      The SQL builder.
    • getExpressionValue

      protected @Nullable Object getExpressionValue(SelectExpression selectExpression)
      Extracts the value from a select expression.
      Parameters:
      selectExpression - The select expression.
      Returns:
      The extracted value.
    • ensureTableMetaData

      protected TableMetaData ensureTableMetaData(Table table, ConnectionProvider connectionProvider)
      Ensures that table metadata is available for the specified table.
      Parameters:
      table - The table.
      connectionProvider - The connection provider.
      Returns:
      The table metadata.
    • ensureColumnMetaData

      protected ColumnMetaData ensureColumnMetaData(Column column, ConnectionProvider connectionProvider)
      Ensures that column metadata is available for the specified column.
      Parameters:
      column - The column.
      connectionProvider - The connection provider.
      Returns:
      The column metadata.
    • createBindValue

      protected BindValue createBindValue(@Nullable Column column, @Nullable Object rawValue, ConnectionProvider connectionProvider)
      Creates a bind value for a column and raw value.
      Parameters:
      column - The column.
      rawValue - The raw value.
      connectionProvider - The connection provider.
      Returns:
      The bind value.
    • appendConditionsAndSubgroups

      protected void appendConditionsAndSubgroups(StringBuilder sql, ConditionGroup conditionGroup, List<@Nullable BindValue> bindValues, Operation operation, ConnectionProvider connectionProvider)
      Appends conditions and subgroups to the SQL builder.
      Parameters:
      sql - The SQL builder.
      conditionGroup - The condition group.
      bindValues - The list of bind values to populate.
      operation - The current database operation.
      connectionProvider - The connection provider.