public abstract class SqlDialect extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
COMMON_SEQ_TABLE_KEY
The table key for a common sequence emulator.
|
static String |
DEFAULT_SCHEMA_SYMBOL
The default schema symbol
|
protected OrmHandler |
ormHandler
The ORM handler
|
| Constructor and Description |
|---|
SqlDialect() |
| Modifier and Type | Method and Description |
|---|---|
Connection |
createConnection(MetaDatabase db)
Create a new database connection
|
InitialContext |
createJndiInitialContext(MetaDatabase db)
Get or create an Initial Context for the JNDI lookup.
|
protected Query |
createSubQuery(CriterionDecoder decoder)
Create a subquery for the DELETE/UPDATE statement
|
protected void |
escape(CharSequence text,
Appendable out)
Escape the special character: "'"
|
protected String |
getAliasColumnName(MetaColumn column)
Returns quoted column name including the alias table
|
protected String |
getColumnType(MetaColumn column)
Returns a database column type
|
String |
getCriterionTemplate(ValueCriterion crit)
Returns an SQL criterion template.
|
SqlDialectEx |
getExtentedDialect()
Get Exted dialect
|
abstract String |
getJdbcDriver()
Returns a JDBC driver class name.
|
abstract String |
getJdbcUrl()
Returns a default JDBC URL
|
Set<String> |
getKeywordSet(Connection conn)
Return database SQL keyword set in the upper case.
|
SqlNameProvider |
getNameProvider()
Returns a name provider
|
protected String |
getQuotedName(CharSequence name)
Prints quoted name (identifier) to SQL - always.
|
SeqTableModel |
getSeqTableModel()
The table model for an internal sequence table support
|
boolean |
isCatalog()
Does the database support a catalog?
The feature supports: MySqlDialect and MSSqlDialect.
|
protected boolean |
isColumnLengthAllowed(MetaColumn column)
Is allowed a column length in a SQL phrase for creating column? The length example can be: NAME CHAR(10)
|
protected boolean |
isFilled(CharSequence text)
Returns true, if the argument text is not null and not empty.
|
boolean |
isMultiRowInsertSupported()
Is supported the
Multirow inserts ?
Default value is true
|
Appendable |
printAlterTableAddColumn(MetaColumn column,
Appendable out)
Print a SQL sript to add a new column to the table
|
Appendable |
printAlterTableColumn(MetaColumn column,
boolean add,
Appendable out)
Print a SQL sript to add a new column to the table
|
Appendable |
printCall(MetaProcedure procedure,
Appendable out)
Print the call of a stored procedure by template:
{? = call procedure_when(?,?)} |
Appendable |
printColumnAlias(ColumnWrapper column,
Appendable out)
Print a full SQL column alias name by sample: TABLE_ALIAS.COLUMN
|
Appendable |
printColumnDeclaration(MetaColumn column,
String aName,
Appendable out)
Print a SQL to create column
|
Appendable |
printComment(MetaColumn column,
Appendable out)
Print a Comment to a database Column
|
Appendable |
printComment(MetaTable table,
Appendable out)
Print a Comment to a database Table
|
Appendable |
printCommit(Appendable out)
Print SQL 'COMMIT'
|
Appendable |
printCreateSchema(String schema,
Appendable out)
Print SQL 'CREATE SCHEMA'
|
ValueCriterion |
printCriterion(ValueCriterion crit,
Appendable out)
Print a conditon phrase from the criterion.
|
protected ValueCriterion |
printCriterionValue(String template,
MetaColumn column,
ValueCriterion crit,
Appendable out)
Write a right value form criterion
|
Appendable |
printDefaultConstraint(MetaColumn column,
StringBuilder out)
Print Default Constraint
|
Appendable |
printDefaultSchema(String schema,
Appendable out)
Deprecated.
|
Appendable |
printDefaultValue(MetaColumn column,
Appendable out)
Print a SQL phrase for the DEFAULT VALUE, for example: DEFAULT 777
|
Appendable |
printDelete(CriterionDecoder decoder,
Appendable out)
Print an SQL DELETE statement.
|
Appendable |
printFKColumnsDeclaration(MetaColumn column,
Appendable out)
Print a SQL to create foreign keys.
|
Appendable |
printForeignKey(MetaColumn column,
MetaTable table,
Appendable out)
Print foreign key for the parameter column
|
void |
printForeignKey(ValueCriterion crit,
ColumnWrapper column,
String template,
Appendable out)
Print all items of the foreign key
|
Appendable |
printFullTableName(MetaTable table,
Appendable out)
Print a full SQL table name by sample: SCHEMA.TABLE
|
Appendable |
printFullTableName(MetaTable table,
boolean printSymbolSchema,
Appendable out)
Print a extended SQL table name by sample: SCHEMA.TABLE
|
Appendable |
printIndex(MetaIndex index,
Appendable out)
Print an INDEX for the parameter column.
|
Appendable |
printInsert(List<? extends OrmUjo> bos,
int idxFrom,
int idxTo,
Appendable out)
Print an SQL INSERT statement.
|
Appendable |
printInsert(OrmUjo bo,
Appendable out)
Print an SQL INSERT statement.
|
Appendable |
printInsertBySelect(List<? extends OrmUjo> bos,
int idxFrom,
int idxTo,
String fromPhrase,
Appendable out)
Print an batch SQL INSERT statement unsing SELECT UNION statejemnt.
|
void |
println(Appendable out)
Print the new line.
|
protected Appendable |
printLockForSelect(Query query,
Appendable out)
Print a 'lock clausule' to the end of SQL SELECT statement to use a pessimistic lock.
|
void |
printOffset(Query query,
Appendable out)
Print an OFFSET of the statement SELECT.
|
Appendable |
printQuotedName(CharSequence name,
Appendable sql)
Prints quoted name (identifier) to SQL according the parameter
MetaParams.QUOTE_SQL_NAMES. |
protected Appendable |
printQuotedNameAlways(CharSequence name,
Appendable sql)
Prints quoted name (identifier) to SQL always.
|
Appendable |
printSelect(TableWrapper table,
Query query,
boolean count,
Appendable out)
Print a SQL SELECT by table model and query
|
protected void |
printSelectOrder(Query query,
Appendable out)
Print SQL ORDER BY
|
protected Appendable |
printSelectTable(Query query,
boolean count,
Appendable out)
Print SQL database SELECT
|
protected void |
printSelectTableBase(Query query,
boolean count,
Appendable out)
Print SQL database SELECT
|
protected Appendable |
printSelectView(TableWrapper table,
Query query,
boolean count,
Appendable out)
Print SQL view SELECT
|
Appendable |
printSequenceCurrentValue(UjoSequencer sequence,
Appendable out)
Print SQL CURRENT SEQUENCE VALUE.
|
Appendable |
printSequenceDeleteById(UjoSequencer sequence,
String id,
Appendable out)
Print SQL DELETE SEQUENCE BY ID.
|
Appendable |
printSequenceInit(UjoSequencer sequence,
Appendable out)
Print SQL CREATE SEQUENCE (insert sequence row).
|
Appendable |
printSequenceInitWithValues(UjoSequencer sequence,
long seq,
int cache,
Appendable out) |
Appendable |
printSequenceNextValue(UjoSequencer sequence,
Appendable out)
Print SQL UPDATE NEXT SEQUENCE value.
|
Appendable |
printSequenceTable(MetaDatabase db,
Appendable out)
Print SQL CREATE SEQUENCE.
|
protected Appendable |
printSequenceTableName(UjoSequencer sequence,
Appendable out)
Prinnt the full sequence table
|
Appendable |
printSetMaxSequence(UjoSequencer sequence,
Appendable out)
Set sequence to the max value.
|
Appendable |
printTable(MetaTable table,
Appendable out)
Print a SQL sript to create table
|
void |
printTableAliasDefinition(TableWrapper table,
Appendable out)
Print a SQL database and table name and an alias definition - by sample: SCHEMA.TABLE ALIAS
|
void |
printTableColumns(Collection<? extends ColumnWrapper> columns,
Appendable values,
Appendable out)
Print table columns
|
Appendable |
printUpdate(List<MetaColumn> changedColumns,
CriterionDecoder decoder,
Appendable out)
Print an SQL UPDATE statement.
|
void |
releaseSavepoint(Connection conn,
Savepoint savepoint,
boolean afterRollback)
Perform the method: {@link Connection#releaseSavepoint(java.sql.Savepoint) ?
|
void |
setHandler(OrmHandler ormHandler)
Set the OrmHandler - the method is for internal call only.
|
public static final String COMMON_SEQ_TABLE_KEY
public static final String DEFAULT_SCHEMA_SYMBOL
protected OrmHandler ormHandler
public void setHandler(OrmHandler ormHandler)
public abstract String getJdbcUrl()
public abstract String getJdbcDriver()
public Connection createConnection(MetaDatabase db) throws Exception
Exceptionpublic InitialContext createJndiInitialContext(MetaDatabase db) throws NamingException
NamingExceptionpublic boolean isCatalog()
false.public Appendable printCreateSchema(String schema, Appendable out) throws IOException
IOException@Deprecated public Appendable printDefaultSchema(String schema, Appendable out) throws IOException
IOExceptionpublic final Appendable printFullTableName(MetaTable table, Appendable out) throws IOException
IOExceptionpublic Appendable printFullTableName(MetaTable table, boolean printSymbolSchema, Appendable out) throws IOException
printSymbolSchema - True parameter replaces a IOExceptionpublic void printTableAliasDefinition(TableWrapper table, Appendable out) throws IOException
IOExceptionpublic Appendable printColumnAlias(ColumnWrapper column, Appendable out) throws IOException
IOExceptionpublic Appendable printTable(MetaTable table, Appendable out) throws IOException
IOExceptionpublic Appendable printAlterTableAddColumn(MetaColumn column, Appendable out) throws IOException
IOExceptionpublic Appendable printAlterTableColumn(MetaColumn column, boolean add, Appendable out) throws IOException
IOExceptionpublic Appendable printDefaultValue(MetaColumn column, Appendable out) throws IOException
IOExceptionpublic Appendable printDefaultConstraint(MetaColumn column, StringBuilder out) throws IOException
IOExceptionpublic Appendable printForeignKey(MetaColumn column, MetaTable table, Appendable out) throws IOException
IOExceptionpublic Appendable printIndex(MetaIndex index, Appendable out) throws IOException
IOExceptionprotected boolean isColumnLengthAllowed(MetaColumn column)
public Appendable printColumnDeclaration(MetaColumn column, String aName, Appendable out) throws IOException
column - Database ColumnaName - The name parameter is not mandatory, the not null value means a foreign key.IOExceptionprotected String getColumnType(MetaColumn column)
public Appendable printFKColumnsDeclaration(MetaColumn column, Appendable out) throws IOException
IOExceptionpublic Appendable printInsert(OrmUjo bo, Appendable out) throws IOException
IOExceptionpublic Appendable printInsert(List<? extends OrmUjo> bos, int idxFrom, int idxTo, Appendable out) throws IOException
bos - Business object listidxFrom - Start index from listidxTo - Finished index from list (excluded)IOExceptionisMultiRowInsertSupported()public Appendable printInsertBySelect(List<? extends OrmUjo> bos, int idxFrom, int idxTo, String fromPhrase, Appendable out) throws IOException
bos - Business object listidxFrom - Start index from listidxTo - Finished index from list (excluded)fromPhrase - For example the Oracla syntax: SELECT 1,2,3 FROM DUAL;IOExceptionisMultiRowInsertSupported()public boolean isMultiRowInsertSupported()
Multi row insertpublic Appendable printUpdate(List<MetaColumn> changedColumns, CriterionDecoder decoder, Appendable out) throws IOException
IOExceptionpublic Appendable printDelete(CriterionDecoder decoder, Appendable out) throws IOException
IOExceptionprotected Query createSubQuery(CriterionDecoder decoder)
public String getCriterionTemplate(ValueCriterion crit)
switch (crit.getOperator()) {
case EQ:
return "{0}={1}";
case NOT_EQ:
return "{0}<>{1}";
case GT:
return "{0}>{1}";
...
public void printTableColumns(Collection<? extends ColumnWrapper> columns, Appendable values, Appendable out) throws IOException
columns - List of tablel columnsvalues - Print columns including its aliases.out - Table columns output.IOExceptionpublic ValueCriterion printCriterion(ValueCriterion crit, Appendable out) throws IOException
IOExceptionprotected ValueCriterion printCriterionValue(String template, MetaColumn column, ValueCriterion crit, Appendable out) throws IOException
false if no righ value was written.IOExceptionprotected String getAliasColumnName(MetaColumn column) throws IOException
IOExceptionpublic void printForeignKey(ValueCriterion crit, ColumnWrapper column, String template, Appendable out) throws IOException
IOExceptionpublic final Appendable printSelect(TableWrapper table, Query query, boolean count, Appendable out) throws IOException
query - The UJO querycount - only count of items is required;IOExceptionprotected Appendable printSelectView(TableWrapper table, Query query, boolean count, Appendable out) throws IOException
query - The UJO querycount - only count of items is required;IOExceptionprotected Appendable printSelectTable(Query query, boolean count, Appendable out) throws IOException
query - The UJO querycount - only count of items is required;IOExceptionprotected void printSelectTableBase(Query query, boolean count, Appendable out) throws IOException
query - The UJO querycount - only count of items is required;IOExceptionprotected Appendable printLockForSelect(Query query, Appendable out) throws IOException, UnsupportedOperationException
query - The UJO queryIOExceptionUnsupportedOperationExceptionprotected void printSelectOrder(Query query, Appendable out) throws IOException
IOExceptionpublic Appendable printCall(MetaProcedure procedure, Appendable out) throws IOException
IOExceptionpublic void printOffset(Query query, Appendable out) throws IOException
IOExceptionprotected Appendable printSequenceTableName(UjoSequencer sequence, Appendable out) throws IOException
IOExceptionpublic Appendable printSequenceTable(MetaDatabase db, Appendable out) throws IOException
IOExceptionpublic Appendable printSequenceInit(UjoSequencer sequence, Appendable out) throws IOException
IOExceptionpublic Appendable printSequenceInitWithValues(UjoSequencer sequence, long seq, int cache, Appendable out) throws IOException
IOExceptionpublic Appendable printSequenceNextValue(UjoSequencer sequence, Appendable out) throws IOException
IOExceptionpublic Appendable printSetMaxSequence(UjoSequencer sequence, Appendable out) throws IOException
IOExceptionpublic Appendable printSequenceCurrentValue(UjoSequencer sequence, Appendable out) throws IOException
IOExceptionpublic Appendable printSequenceDeleteById(UjoSequencer sequence, String id, Appendable out) throws IOException
IOExceptionprotected final boolean isFilled(CharSequence text)
public final void println(Appendable out) throws IOException
IOExceptionpublic Appendable printCommit(Appendable out) throws IOException
IOExceptionpublic Appendable printComment(MetaTable table, Appendable out) throws IOException
IOExceptionpublic Appendable printComment(MetaColumn column, Appendable out) throws IOException
IOExceptionpublic Set<String> getKeywordSet(Connection conn)
protected final void escape(CharSequence text, Appendable out) throws IOException
IOExceptionpublic SeqTableModel getSeqTableModel()
public void releaseSavepoint(Connection conn, Savepoint savepoint, boolean afterRollback) throws SQLException
conn - Database Connectionsavepoint - Required SavepointafterRollback - release is called after a rollback ?SQLExceptionhttp://technet.microsoft.com/en-us/library/ms378791%28v=sql.110%29.aspx,
Connection.releaseSavepoint(java.sql.Savepoint)public final Appendable printQuotedName(CharSequence name, Appendable sql) throws IOException
MetaParams.QUOTE_SQL_NAMES.name - Name (identifier) for quotingsql - Target SQL for printing new quoted nameIOExceptionprotected Appendable printQuotedNameAlways(CharSequence name, Appendable sql) throws IOException
name - Name (identifier) for quotingsql - Target SQL for printing new quoted nameIOExceptionprotected final String getQuotedName(CharSequence name) throws IOException
IOExceptionpublic SqlNameProvider getNameProvider() throws IllegalStateException
IllegalStateException - A problem during creating an instance.public SqlDialectEx getExtentedDialect()
Copyright 2013, Pavel Ponec