Package com.gengoai.sql
Class SQLDialect
- java.lang.Object
-
- com.gengoai.sql.SQLDialect
-
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
PostgreSQLDialect
,SQLiteDialect
public abstract class SQLDialect extends Object implements Serializable
The type Sql dialect 2.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description SQLDialect()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected String
addColumn(AlterTableAction.AddColumn alterColumn)
Add column string.protected String
alterColumn(AlterTableAction.AlterColumn alterColumn)
Alter column string.protected String
alterTable(AlterTable alterTable)
Alter table string.protected String
between(Between between)
Between string.protected String
binaryOperator(@NonNull InfixBinaryOperator binaryOperator)
Binary operator string.protected void
checkConstraint(CheckConstraint checkConstraint, boolean isTableConstraint, StringBuilder builder)
Check constraint.protected String
cleanUnderScores(String str)
Clean under scores string.protected String
conflictClause(ConflictClause conflictClause)
Generates the SQL for defining what happens on conflictprotected String
createIndex(Create createStatement)
Create index string.protected String
createTable(Create statement)
Create table string.protected String
createTrigger(Create createStatement)
Create trigger string.String
deferrable(Deferrable deferrable)
Deferrable string.protected abstract void
defineColumn(Column column, StringBuilder builder)
Generates the SQL needed to define a column for creating or altering a table.protected void
defineConstraint(Constraint constraint, boolean isTableConstraint, StringBuilder builder)
Define constraint.protected String
delete(Delete delete)
Generates the SQL to delete from a table.protected String
drop(Drop drop)
Generates the SQL to drop an objectprotected String
dropColumn(AlterTableAction.DropColumn dropColumn)
Drop column string.static String
escape(@NonNull String string)
Static helper method for properly escaping SQL strings.String
foreignKeyAction(ForeignKeyAction action)
Foreign key action string.protected void
foreignKeyConstraint(ForeignKeyConstraint fkc, boolean isTableConstraint, StringBuilder builder)
Foreign key constraint.protected String
function(@NonNull SQLFunction function)
Generates the SQL for a call to a predefined function.protected String
insert(Insert insert)
Generates the SQL to insert a row into a tableprotected String
insertType(InsertType insertType)
Insert type string.protected String
join(@NonNull Join join)
Generates the SQL defining a join operationprotected String
join(@NonNull String delimiter, @NonNull Collection<? extends SQLElement> items)
Joins one or moreSQLElement
as SQL with the given delimiterprotected String
joinType(JoinType joinType)
Join type string.protected void
notNullConstraint(NotNullConstraint notNullConstraint, boolean isTableConstraint, StringBuilder builder)
Not null constraint.protected String
postfixUnaryOperator(@NonNull PostfixUnaryOperator op)
Postfix unary operator string.protected String
prefixUnaryOperator(@NonNull PrefixUnaryOperator op)
Prefix unary operator string.protected void
primaryKeyConstraint(PrimaryKeyConstraint primaryKeyConstraint, boolean isTableConstraint, StringBuilder builder)
Primary key constraint.protected String
queryOperator(QueryOperator queryOperator)
Generates the SQL for defining a query operator (UNION, EXCLUDE, etc.)protected String
renameColumn(AlterTableAction.RenameColumn renameColumn)
Rename column string.protected String
renameTable(AlterTableAction.RenameTable renameTable)
Rename table string.String
render(@NonNull SQLElement sqlElement)
Render string.protected String
select(@NonNull Select select)
Generates the SQL for select statementprotected String
sqlDMLOperation(SQLDMLOperation operation)
Sql dml operation string.protected String
translate(String keyword)
Provides dialect specific translations of keywords and symbolsprotected String
triggerTime(TriggerTime triggerTime)
Trigger time string.protected void
uniqueConstraint(UniqueConstraint uniqueConstraint, boolean isTableConstraint, StringBuilder builder)
Unique constraint.protected String
update(Update update)
Generates the SQL For an update statementprotected String
updateType(UpdateType updateType)
Update type string.protected String
upsertAction(UpsertAction upsertAction)
Upsert action string.protected String
upsertClause(@NonNull UpsertClause upsertClause)
Generates the SQL for an upsert clause
-
-
-
Field Detail
-
LOG_LEVEL
@NonNull public static @NonNull Level LOG_LEVEL
Controls the log level for previewing generated SQL
-
-
Method Detail
-
escape
public static String escape(@NonNull @NonNull String string)
Static helper method for properly escaping SQL strings.- Parameters:
string
- the string to escape- Returns:
- the escaped string
-
addColumn
protected String addColumn(AlterTableAction.AddColumn alterColumn)
Add column string.- Parameters:
alterColumn
- the alter column- Returns:
- the string
-
alterColumn
protected String alterColumn(AlterTableAction.AlterColumn alterColumn)
Alter column string.- Parameters:
alterColumn
- the alter column- Returns:
- the string
-
alterTable
protected String alterTable(AlterTable alterTable)
Alter table string.- Parameters:
alterTable
- the alter table- Returns:
- the string
-
between
protected String between(Between between)
Between string.- Parameters:
between
- the between- Returns:
- the string
-
binaryOperator
protected String binaryOperator(@NonNull @NonNull InfixBinaryOperator binaryOperator)
Binary operator string.- Parameters:
binaryOperator
- the binary operator- Returns:
- the string
-
checkConstraint
protected void checkConstraint(CheckConstraint checkConstraint, boolean isTableConstraint, StringBuilder builder)
Check constraint.- Parameters:
checkConstraint
- the check constraintisTableConstraint
- the is table constraintbuilder
- the builder
-
cleanUnderScores
protected String cleanUnderScores(String str)
Clean under scores string.- Parameters:
str
- the str- Returns:
- the string
-
conflictClause
protected String conflictClause(ConflictClause conflictClause)
Generates the SQL for defining what happens on conflict- Parameters:
conflictClause
- the conflict clause- Returns:
- the SQL
-
createIndex
protected String createIndex(Create createStatement)
Create index string.- Parameters:
createStatement
- the create statement- Returns:
- the string
-
createTable
protected String createTable(Create statement)
Create table string.- Parameters:
statement
- the statement- Returns:
- the string
-
createTrigger
protected String createTrigger(Create createStatement)
Create trigger string.- Parameters:
createStatement
- the create statement- Returns:
- the string
-
deferrable
public String deferrable(Deferrable deferrable)
Deferrable string.- Parameters:
deferrable
- the deferrable- Returns:
- the string
-
defineColumn
protected abstract void defineColumn(Column column, StringBuilder builder)
Generates the SQL needed to define a column for creating or altering a table.- Parameters:
column
- the column definitionbuilder
- the StringBuilder to add the definition to
-
defineConstraint
protected final void defineConstraint(Constraint constraint, boolean isTableConstraint, StringBuilder builder)
Define constraint.- Parameters:
constraint
- the constraintisTableConstraint
- the is table constraintbuilder
- the builder
-
delete
protected String delete(Delete delete)
Generates the SQL to delete from a table.- Parameters:
delete
- the delete object- Returns:
- the SQL
-
drop
protected String drop(Drop drop)
Generates the SQL to drop an object- Parameters:
drop
- the drop object- Returns:
- the SQL
-
dropColumn
protected String dropColumn(AlterTableAction.DropColumn dropColumn)
Drop column string.- Parameters:
dropColumn
- the drop column- Returns:
- the string
-
foreignKeyAction
public String foreignKeyAction(ForeignKeyAction action)
Foreign key action string.- Parameters:
action
- the action- Returns:
- the string
-
foreignKeyConstraint
protected void foreignKeyConstraint(ForeignKeyConstraint fkc, boolean isTableConstraint, StringBuilder builder)
Foreign key constraint.- Parameters:
fkc
- the fkcisTableConstraint
- the is table constraintbuilder
- the builder
-
function
protected String function(@NonNull @NonNull SQLFunction function)
Generates the SQL for a call to a predefined function.- Parameters:
function
- the function call- Returns:
- the SQL
-
insert
protected String insert(Insert insert)
Generates the SQL to insert a row into a table- Parameters:
insert
- the insert object- Returns:
- the SQL
-
insertType
protected String insertType(InsertType insertType)
Insert type string.- Parameters:
insertType
- the insert type- Returns:
- the string
-
join
protected String join(@NonNull @NonNull String delimiter, @NonNull @NonNull Collection<? extends SQLElement> items)
Joins one or moreSQLElement
as SQL with the given delimiter- Parameters:
delimiter
- the delimiter to use to separate the SQLElementsitems
- the items to join- Returns:
- the SQL
-
join
protected String join(@NonNull @NonNull Join join)
Generates the SQL defining a join operation- Parameters:
join
- the join- Returns:
- the SQL
-
joinType
protected String joinType(JoinType joinType)
Join type string.- Parameters:
joinType
- the join type- Returns:
- the string
-
notNullConstraint
protected void notNullConstraint(NotNullConstraint notNullConstraint, boolean isTableConstraint, StringBuilder builder)
Not null constraint.- Parameters:
notNullConstraint
- the not null constraintisTableConstraint
- the is table constraintbuilder
- the builder
-
postfixUnaryOperator
protected String postfixUnaryOperator(@NonNull @NonNull PostfixUnaryOperator op)
Postfix unary operator string.- Parameters:
op
- the op- Returns:
- the string
-
prefixUnaryOperator
protected String prefixUnaryOperator(@NonNull @NonNull PrefixUnaryOperator op)
Prefix unary operator string.- Parameters:
op
- the op- Returns:
- the string
-
primaryKeyConstraint
protected void primaryKeyConstraint(PrimaryKeyConstraint primaryKeyConstraint, boolean isTableConstraint, StringBuilder builder)
Primary key constraint.- Parameters:
primaryKeyConstraint
- the primary key constraintisTableConstraint
- the is table constraintbuilder
- the builder
-
queryOperator
protected String queryOperator(QueryOperator queryOperator)
Generates the SQL for defining a query operator (UNION, EXCLUDE, etc.)- Parameters:
queryOperator
- the query operator- Returns:
- the SQL
-
renameColumn
protected String renameColumn(AlterTableAction.RenameColumn renameColumn)
Rename column string.- Parameters:
renameColumn
- the rename column- Returns:
- the string
-
renameTable
protected String renameTable(AlterTableAction.RenameTable renameTable)
Rename table string.- Parameters:
renameTable
- the rename table- Returns:
- the string
-
render
public final String render(@NonNull @NonNull SQLElement sqlElement)
Render string.- Parameters:
sqlElement
- the sql element- Returns:
- the string
-
select
protected String select(@NonNull @NonNull Select select)
Generates the SQL for select statement- Parameters:
select
- the select statement- Returns:
- the SQL
-
sqlDMLOperation
protected String sqlDMLOperation(SQLDMLOperation operation)
Sql dml operation string.- Parameters:
operation
- the operation- Returns:
- the string
-
translate
protected String translate(String keyword)
Provides dialect specific translations of keywords and symbols- Parameters:
keyword
- the keyword- Returns:
- the tranlsation
-
triggerTime
protected String triggerTime(TriggerTime triggerTime)
Trigger time string.- Parameters:
triggerTime
- the trigger time- Returns:
- the string
-
uniqueConstraint
protected void uniqueConstraint(UniqueConstraint uniqueConstraint, boolean isTableConstraint, StringBuilder builder)
Unique constraint.- Parameters:
uniqueConstraint
- the unique constraintisTableConstraint
- the is table constraintbuilder
- the builder
-
update
protected String update(Update update)
Generates the SQL For an update statement- Parameters:
update
- the update statement- Returns:
- the SQL
-
updateType
protected String updateType(UpdateType updateType)
Update type string.- Parameters:
updateType
- the update type- Returns:
- the string
-
upsertAction
protected String upsertAction(UpsertAction upsertAction)
Upsert action string.- Parameters:
upsertAction
- the upsert action- Returns:
- the string
-
upsertClause
protected String upsertClause(@NonNull @NonNull UpsertClause upsertClause)
Generates the SQL for an upsert clause- Parameters:
upsertClause
- the upser object- Returns:
- the SQL
-
-