java.lang.Object
org.litebridge.db.spi.impl.sql.AbstractSqlGenerator
- Direct Known Subclasses:
DeleteSqlGenerator,InsertSqlGenerator,SelectSqlGenerator,UpdateSqlGenerator
Abstract base class for SQL generators.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ColumnIdentifierGeneratorThe generator for column identifiers.protected final TypeConverterThe type converter used for mapping between database and Java types. -
Constructor Summary
ConstructorsConstructorDescriptionAbstractSqlGenerator(TypeConverter typeConverter, ColumnIdentifierGenerator columnIdentifierGenerator, BiFunction<Table, ConnectionProvider, TableMetaData> ensureTableMetaData) Constructs a newAbstractSqlGenerator. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendConditionsAndSubgroups(StringBuilder sql, ConditionGroup conditionGroup, List<@Nullable BindValue> bindValues, Operation operation, ConnectionProvider connectionProvider) Appends conditions and subgroups to the SQL builder.protected StringBuilderappendTable(StringBuilder sql, @Nullable String schema, String table) Appends a table name to the SQL builder, quoting identifiers.protected StringBuilderappendTable(StringBuilder sql, Table table) Appends a table name to the SQL builder, quoting identifiers.protected BindValuecreateBindValue(@Nullable Column column, @Nullable Object rawValue, ConnectionProvider connectionProvider) Creates a bind value for a column and raw value.protected PreparedSqlcreateCondition(Condition condition, Operation operation, ConnectionProvider connectionProvider) Generate a SQL condition string based on the givenCondition.protected ColumnMetaDataensureColumnMetaData(Column column, ConnectionProvider connectionProvider) Ensures that column metadata is available for the specified column.protected TableMetaDataensureTableMetaData(Table table, ConnectionProvider connectionProvider) Ensures that table metadata is available for the specified table.protected @Nullable ObjectgetExpressionValue(SelectExpression selectExpression) Extracts the value from a select expression.protected StringmapOperator(Operator operator) Map anOperatorenum to its corresponding string representation used in logical or database operations.
-
Field Details
-
typeConverter
The type converter used for mapping between database and Java types. -
columnIdentifierGenerator
The generator for column identifiers.
-
-
Constructor Details
-
AbstractSqlGenerator
public AbstractSqlGenerator(TypeConverter typeConverter, ColumnIdentifierGenerator columnIdentifierGenerator, BiFunction<Table, ConnectionProvider, TableMetaData> ensureTableMetaData) Constructs a newAbstractSqlGenerator.- 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 givenCondition. This method constructs the SQL fragment by combining the column, operator, and value (if applicable) for the provided condition.- Parameters:
condition- theConditionobject specifying the column, operator, and value for the SQL conditionoperation- the current database operationconnectionProvider- the connection provider- Returns:
- a
PreparedSqlrepresenting the constructed SQL condition fragment
-
mapOperator
Map anOperatorenum 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
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
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
Extracts the value from a select expression.- Parameters:
selectExpression- The select expression.- Returns:
- The extracted value.
-
ensureTableMetaData
Ensures that table metadata is available for the specified table.- Parameters:
table- The table.connectionProvider- The connection provider.- Returns:
- The table metadata.
-
ensureColumnMetaData
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.
-