java.lang.Object
org.litebridge.db.spi.impl.sql.AbstractSqlGenerator
- Direct Known Subclasses:
DeleteSqlGenerator,InsertSqlGenerator,MergeSqlGenerator,SelectSqlGenerator,UpdateSqlGenerator
Abstract base class for SQL generators.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final LabelGeneratorprotected final MathOperationGenerator -
Constructor Summary
ConstructorsConstructorDescriptionAbstractSqlGenerator(LabelGenerator labelGenerator, MathOperationGenerator mathOperationGenerator, BiFunction<Table, ConnectionProvider, TableMetaData> ensureTableMetaData) Constructs a newAbstractSqlGenerator. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidappendConditionsAndSubgroups(StringBuilder sql, ConditionGroup conditionGroup, ClauseType clauseType, Operation operation, ConnectionProvider connectionProvider) Appends conditions and subgroups to the SQL builder.protected StringBuilderappendTable(StringBuilder sql, Table table) Appends a table name to the SQL builder, quoting identifiers.protected voidappendValues(StringBuilder sql, Values values, Operation operation) protected StringcreateCondition(Condition condition, ClauseType clauseType, Operation operation, ConnectionProvider connectionProvider) Generate a SQL condition string based on the givenCondition.protected StringcreateMathOperation(String column, MathOperator mathOperator) Creates a SQL representation of a math operation.protected ColumnMetaDataensureColumnMetaData(Column column, ConnectionProvider connectionProvider) Ensures that column metadata is available for the specified column.protected StringgetColumnValueFragment(UpdateColumn updateColumn, ClauseType clauseType, Operation operation) protected StringmapOperator(Operator operator) Map anOperatorenum to its corresponding string representation used in logical or database operations.
-
Field Details
-
labelGenerator
-
mathOperationGenerator
-
-
Constructor Details
-
AbstractSqlGenerator
public AbstractSqlGenerator(LabelGenerator labelGenerator, MathOperationGenerator mathOperationGenerator, BiFunction<Table, ConnectionProvider, TableMetaData> ensureTableMetaData) Constructs a newAbstractSqlGenerator.- Parameters:
labelGenerator- the label generator for rendering aliases/identifiersensureTableMetaData- The function to ensure table metadata is available.
-
-
Method Details
-
createCondition
protected String createCondition(Condition condition, ClauseType clauseType, 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 conditionclauseType- the current SQL clause type (e.g., WHERE, HAVING)`operation- 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
-
createMathOperation
Creates a SQL representation of a math operation.- Parameters:
column- the columnmathOperator- the math operation- Returns:
- the SQL representation of the math operation
-
appendTable
Appends a table name to the SQL builder, quoting identifiers.- Parameters:
sql- The SQL builder.table- The table to append.
-
appendValues
-
ensureColumnMetaData
Ensures that column metadata is available for the specified column.- Parameters:
column- The column.connectionProvider- The connection provider.- Returns:
- The column metadata.
-
appendConditionsAndSubgroups
protected void appendConditionsAndSubgroups(StringBuilder sql, ConditionGroup conditionGroup, ClauseType clauseType, Operation operation, ConnectionProvider connectionProvider) Appends conditions and subgroups to the SQL builder.- Parameters:
sql- The SQL builder.conditionGroup- The condition group.clauseType- the current SQL clause type (e.g., WHERE, HAVING)`operation- The current database operation.connectionProvider- The connection provider.
-
getColumnValueFragment
protected String getColumnValueFragment(UpdateColumn updateColumn, ClauseType clauseType, Operation operation)
-