public abstract class Dialect
extends java.lang.Object
Dialect
class
to add methods required by the P2J persistence framework. The
implementations of these methods are necessarily specific to the backing
database and may be different for different database vendors.
NOTE: a longer term goal is to eliminate this interface by merging these
methods back into the mainstream Hibernate Dialect
class.
Modifier and Type | Class and Description |
---|---|
static interface |
Dialect.WeightAggregator
Helper interface for weights' aggregation
|
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,Dialect> |
dialectByJdbcType |
private static java.util.Map<java.lang.String,Dialect> |
knownDialects
Map of known/loaded dialect instances
|
private static java.util.logging.Logger |
log
Logger
|
(package private) static java.lang.String |
SCALE_TOK
Token used to mark a placeholder for the scale when generating the DDL for creating/altering a decimal
column in a table.
|
Constructor and Description |
---|
Dialect() |
Modifier and Type | Method and Description |
---|---|
abstract void |
addRtrimmedExpression(java.lang.String expr,
java.lang.StringBuilder sb)
Composes a rtrim equivalent call for a specified expression.
|
void |
beforeDriverLoad()
Set any database parameters before, to be available when the database
driver is loaded.
|
abstract java.sql.Blob |
blobCreator(java.sql.Connection conn,
byte[] bytes)
Create a
Blob instance from the specified bytes. |
abstract java.lang.String |
buildRemoteURL(java.lang.String url,
Database database)
Build the URL to be used for a remote connection, based on the given URL and database.
|
abstract java.sql.Clob |
clobCreator(java.sql.Connection conn,
java.lang.String value)
Create a
Clob instance from the specified value. |
int |
computeIndexKeySize(java.lang.Class<? extends BaseDataType> type,
java.lang.Object val)
Computes the size (in bytes) occupied by this value when stored as index-key in an index.
|
java.lang.String |
containsUdfName()
Return the name of the CONTAINS UDF
|
java.lang.Object |
createContext(Persistence persistence)
Create a data object, the purpose of which is specific to a particular
dialect implementation, to be stored as a context-local object.
|
abstract SequenceHandler |
createSequenceHandler(java.lang.String ldbName)
Creates and returns a
SequenceHandler for a database. |
static java.util.Map<java.lang.String,Dialect> |
dialects()
Get known dialects by name
|
abstract boolean |
explicitSetCollation()
Check if the dialect needs to set an explicit collation during schema DDL generation.
|
abstract java.lang.String |
extractColumnName(java.lang.String expr)
Given a column expression as queried from database metadata, extract the root name of a
column.
|
abstract java.lang.String |
formatDate(date d)
Format a date object as a string which is appropriate for use in an SQL statement.
|
abstract void |
generateWordTablesDDLImpl(java.lang.String dbName,
java.io.PrintStream out,
java.lang.String eoln,
java.util.Collection<WordTable> wordTables)
Worker method for
generateTriggerDDLs() . |
abstract java.lang.String |
getAnalyzeString(java.lang.String table)
Construct and return a string which represents the
analyze or similar statements
for this dialect. |
java.lang.String |
getComputedColumnFormula(java.lang.String colName,
boolean ignoreCase)
Returns the formula for character computed columns.
|
java.lang.String |
getComputedColumnPrefix(boolean caseSensitive)
Get the prefix, if any, which should be prepended to computed column and/or property names.
|
java.lang.String |
getCreateIndexString(boolean unique)
Returns the beginning of the DDL statement for creating an index.
|
java.lang.String |
getCreateIndexString(P2JIndex index,
boolean unique,
boolean toFile)
Build the DDL to create an index based upon the specified definition.
|
abstract java.lang.String |
getCreateSequenceString(java.lang.String name)
Generate a DDL string which will create a global sequence.
|
abstract java.lang.String |
getCreateSequenceString(java.lang.String name,
long start)
Generate a DDL string which will create a global sequence with the given starting value.
|
abstract java.lang.String |
getCreateSequenceString(java.lang.String name,
java.lang.Long init,
java.lang.Long increment,
java.lang.Long minVal,
java.lang.Long maxVal,
java.lang.Boolean cycle)
Generate a DDL string which will create a sequence with given properties.
|
java.lang.String |
getCreateTableString()
Returns the beginning of the DDL statement for creating a permanent table.
|
abstract java.lang.String |
getCreateTemporaryTablePostfix()
Return the ending of the DDL statement that creates a temporary table.
|
abstract java.lang.String |
getCreateTemporaryTableString(boolean ifNotExist)
Return the beginning of the DDL statement that creates a temporary table.
|
java.util.List<java.lang.String> |
getDatabasePrepareStatements(Database database)
Get a list of database prepare DDL statements.
|
abstract java.lang.String |
getDelimiter()
Get the statement delimiter for this dialect.
|
static Dialect |
getDialect(Database database)
Get the instance of a concrete subclass of this class which is associated with the given
database.
|
static Dialect |
getDialect(Settings settings)
Get the instance of a concrete subclass of this class, as specified in the given settings.
|
static Dialect |
getDialect(java.lang.String jdbcType)
Get the instance of a concrete subclass of this class which is associated with the given
JDBC database type.
|
abstract java.lang.String |
getDriverClassName()
Get the name of the JDBC driver class associated with this dialect.
|
abstract java.lang.String |
getDropIndexString(boolean ifExists,
java.lang.String idxName)
Obtain a DDL statement which drops a SQL index.
|
abstract java.lang.String |
getDropIndexString(P2JIndex index)
Build the DDL to drop an index based upon the specified definition.
|
abstract java.lang.String |
getDropSequenceString(java.lang.String name)
Generate a DDL string which will drop a sequence.
|
abstract java.lang.String |
getDropTableString(boolean ifExists,
java.lang.String tableName)
Obtain a DDL statement which drops a SQL table.
|
java.sql.Date |
getHighDate()
Retrieve the latest possible date value which is valid for the backing database.
|
int |
getIndexLengthLimit()
Some dialects have constraints about the maximum size of fields that compose an index.
|
abstract java.lang.String |
getJdbcDatabaseType()
Get the name of the JDBC database type (as in JBC URL).
|
java.lang.String |
getLimitString(java.lang.String sql,
int offset,
int limit)
Get the limit string for the given limit and offset.
|
java.sql.Date |
getLowDate()
Retrieve the earliest possible date value which is valid for the backing database.
|
int |
getMaxParameterCount()
Obtain the number of parameters a query of this dialect is allowed by the SQL server.
|
abstract java.lang.String |
getProcessedCharacterColumnName(java.lang.String name,
boolean ignoreCase)
Adjust a character column name appropriate to this dialect, such that it
can be inserted into an index.
|
abstract java.lang.String |
getSequenceCurrValString(java.lang.String sequenceName)
Generate the appropriate select statement to retrieve the current value of a sequence.
|
abstract java.lang.String |
getSequenceNextValString(java.lang.String sequenceName)
Generate the appropriate select statement to retrieve the next value of a sequence.
|
abstract java.lang.String |
getSequencePrefetchString(java.lang.String sequenceName)
Generate the appropriate select statement to pre-fetch multiple, ascending values from a sequence.
|
abstract java.lang.String |
getSequenceSetValString(java.lang.String sequenceName,
long newVal)
Generate the appropriate select statement to reset the value of a sequence.
|
java.lang.String |
getSpecificTypeAsString(FqlType type)
Converts and return the specified
FqlType to a string representation which can be used in a
SQL query (cast or other construct). |
java.lang.String |
getSqlMappedType(java.lang.Class<?> fwdType,
int scale)
Get the SQL mapping for a specific FWD data type.
|
java.lang.String |
getSqlMappedType(java.lang.String fwdType,
int scale)
Get the SQL mapping for a specific FWD data type.
|
abstract int |
getSyntheticIndexSize(boolean unique)
Returns the size of the synthetic part of the index.
|
java.util.regex.Pattern |
getUdfErrorMessagePattern()
Get regex Pattern for parsing message cased by error raised by UDF.
|
abstract boolean |
hasFullSequenceSupport()
Returns
true if this dialect fully support the sequences as 4GL language (most important:
bounded values, cycle). |
abstract java.lang.String |
id()
Get dialect id.
|
abstract boolean |
injectComputedColumns()
Report whether the computed columns should be injected on table creating.
|
abstract void |
inlineLimit(boolean on)
Enable/disable limit clause inlining.
|
abstract boolean |
isCaseInsensitiveColumn(java.lang.String name)
Report whether the given column name represents an alias or an expression which indicates
the column is case insensitive.
|
boolean |
isComputedColumn(java.lang.String name)
Report whether the given column name represents an alias or an expression which indicates
the column is computed.
|
abstract boolean |
isConnectionError(java.lang.Exception exc)
Given an exception, this method will check if it indicates a database connectivity error.
|
abstract boolean |
isMetadataSortAsc(java.lang.String value)
Check if the given value is a descending clause for a column index.
|
abstract boolean |
isMetadataSortDesc(java.lang.String value)
Check if the given value is an ascending clause for a column index.
|
abstract boolean |
isQueryRangeParameterInlined()
Indicate whether a query parameter which is part of a range check should
be inlined into the where clause, or whether it should be substituted
into a prepared statement.
|
boolean |
isUdfContains(java.lang.String name)
Check if the provided name is the name of the CONTAINS UDF
|
boolean |
isUdfOriginated(java.sql.SQLException e)
Check if the exception was caused by error in UDF.
|
abstract boolean |
needsComputedColumns()
Indicate whether this dialect requires computed columns to participate
within index definitions, instead of embedded expressions.
|
java.lang.String |
orderByNulls(boolean asc)
Determine if the sort component or index needs to be augmented with a NULLS FIRST/LAST option.
|
void |
postTransaction(Persistence persistence,
java.lang.Object context,
boolean rollback)
A dialect-specific callback hook which is invoked by the persistence runtime framework
after a transaction is complete.
|
abstract java.lang.String |
prepareMetadataParameter(java.lang.String param)
Prepare the given metadata query parameter.
|
abstract java.lang.String |
processMetadataResult(java.lang.String value)
Process the given metadata query result.
|
java.lang.String |
quote(java.lang.String expr)
Apply dialect-specific quoting.
|
abstract boolean |
requiresExplicitCastInsideTernary()
Determines whether substitution parameters should be explicitly casted
to their datatypes inside "then ? else ?" statement.
|
abstract ScriptSplitter |
scripSplitter()
Get the splitter for DDL scripts.
|
abstract boolean |
supportsBooleanDatatype()
Indicates whether this dialect supports boolean datatype.
|
abstract boolean |
supportsFunctionOverloading()
Indicate whether this dialect natively supports the overloading of user
defined functions by parameter number and data type.
|
boolean |
supportsVariableLimit()
Indicate whether a variable limit is supported by this dialect.
|
boolean |
useCTE4Contains()
Check if Common Table Expressions should be used for converted CONTAINS operator
|
boolean |
useMixedNode4Contains()
Check if mixed mode re-write should be used for converted CONTAINS operator
|
abstract boolean |
useUdf4Contains()
Check if UDF should be used for converted CONTAINS operator
|
java.util.Optional<Dialect.WeightAggregator> |
weightAggregator()
Get the WeightAggregator instance for the dialect if defined
|
static final java.lang.String SCALE_TOK
private static final java.util.logging.Logger log
private static final java.util.Map<java.lang.String,Dialect> knownDialects
private static java.util.Map<java.lang.String,Dialect> dialectByJdbcType
public static Dialect getDialect(java.lang.String jdbcType)
jdbcType
- Database jdbc type.public static Dialect getDialect(Database database)
There is one instance per subclass type; they are stateless and shared.
database
- Database identifier.null
if no dialect has
been configured for the database.public static java.util.Map<java.lang.String,Dialect> dialects()
public static Dialect getDialect(Settings settings)
null
is returned.
There is one instance per subclass type; they are stateless and shared.
settings
- Settings object which should contain a dialect entry.null
.public abstract ScriptSplitter scripSplitter()
public abstract java.sql.Blob blobCreator(java.sql.Connection conn, byte[] bytes)
Blob
instance from the specified bytes.conn
- The JDBC connection.bytes
- The blob data.public abstract java.sql.Clob clobCreator(java.sql.Connection conn, java.lang.String value)
Clob
instance from the specified value.conn
- The JDBC connection.value
- The clob data.public abstract java.lang.String getDriverClassName()
public abstract java.lang.String getJdbcDatabaseType()
public abstract java.lang.String id()
public abstract boolean useUdf4Contains()
true
if UDF should be used for converted CONTAINS operatorpublic boolean isUdfOriginated(java.sql.SQLException e)
e
- the exception in questiontrue
if the exception was caused by error in UDF.public java.util.regex.Pattern getUdfErrorMessagePattern()
public boolean useCTE4Contains()
true
if Common Table Expressions should be used for converted CONTAINS operatorpublic boolean useMixedNode4Contains()
true
if mixed mode re-write should be usedpublic boolean isUdfContains(java.lang.String name)
name
- name to be checkedtrue
if the provided name is the name of the CONTAINS UDFpublic java.lang.String containsUdfName()
public abstract void generateWordTablesDDLImpl(java.lang.String dbName, java.io.PrintStream out, java.lang.String eoln, java.util.Collection<WordTable> wordTables)
generateTriggerDDLs()
. It generates the DDLs needed to create all
triggers in a database with a specific schema and using a certain dialect.dbName
- The target schema.out
- The PrintStream
used for output.eoln
- OS-specific end of line terminator.wordTables
- word tables by namepublic java.lang.Object createContext(Persistence persistence)
Since the context-local data is specific to a particular dialect
implementation, it is optional. Dialect implementations which do not
have a need for this data should simply return null
.
persistence
- Provider of persistence services.null
.public void postTransaction(Persistence persistence, java.lang.Object context, boolean rollback) throws PersistenceException
Default implementation does nothing.
persistence
- Provider of persistence services.context
- Optional, context-local data created previously by createContext(com.goldencode.p2j.persist.Persistence)
.rollback
- true
if transaction ended with a rollback;
false
if transaction ended with a commit.PersistenceException
- if any persistence-related error occurs.public java.sql.Date getLowDate()
null
to indicate no
particular restriction.public java.sql.Date getHighDate()
null
to indicate no
particular restriction.public abstract java.lang.String formatDate(date d)
d
- Date to be formatted as a string.public abstract java.lang.String extractColumnName(java.lang.String expr)
upper(rtrim("key"::text))We are interested only in the
key
root name, so we strip away the upper()
and rtrim()
functions, the double quotes, and the ::text
suffix.expr
- Expression containing column name as natively represented by
the database dialect.public abstract java.lang.String getProcessedCharacterColumnName(java.lang.String name, boolean ignoreCase)
name
- Base column name.ignoreCase
- true
to cause case to be ignored, else false
.public abstract boolean isCaseInsensitiveColumn(java.lang.String name)
name
is
already determined to be the appropriate data type for textual data.name
- Column name, alias, or expression.true
if name
represents case-insensitive data.public boolean isComputedColumn(java.lang.String name)
name
is already
determined to be the appropriate data type for textual data.name
- Column name, alias, or expression.true
if name
represents a computed column. Default implementation
returns false
.public abstract boolean needsComputedColumns()
true
to indicate computed columns are required;
false
if the backing database can embed an
expression within an index definition.public java.lang.String getComputedColumnPrefix(boolean caseSensitive)
caseSensitive
- true
if this is a character field was declared with
CASE-SENSITIVE
attribute. In each case the column name will be
name-decorated differently.null
if the
backing database does not use computed columns.needsComputedColumns()
public abstract boolean supportsFunctionOverloading()
true
if the backing database natively supports
overloading, else false
.public abstract boolean supportsBooleanDatatype()
true
and false
literals;
true
if the above mentioned items are supported or false
if they
are handled by a replacement datatype (integer).public abstract java.lang.String getCreateSequenceString(java.lang.String name)
name
- Sequence name.null
if not supported.public abstract java.lang.String getCreateSequenceString(java.lang.String name, long start)
name
- Sequence name.start
- Sequence starting value.null
if not supported.public abstract java.lang.String getCreateSequenceString(java.lang.String name, java.lang.Long init, java.lang.Long increment, java.lang.Long minVal, java.lang.Long maxVal, java.lang.Boolean cycle)
name
- Sequence name. Mandatory not null.init
- Sequence starting value. Mandatory not null.increment
- Sequence incrementing value. Mandatory not null.minVal
- Sequence minimum value. Optional.maxVal
- Sequence maximum value. Optional.cycle
- Sequence cycling property. Optional, if missing assumed not cycling.null
if not supported.public abstract java.lang.String getDropSequenceString(java.lang.String name)
name
- The name of the sequence to be dropped.null
if not supported.public abstract java.lang.String getSequenceSetValString(java.lang.String sequenceName, long newVal)
sequenceName
- The name of the sequence.newVal
- The new value to be set.null
if not supported.public abstract java.lang.String getSequenceNextValString(java.lang.String sequenceName)
sequenceName
- The name of the sequence to be queried.null
if not supported.public abstract java.lang.String getSequenceCurrValString(java.lang.String sequenceName)
sequenceName
- The name of the sequence to be queried.null
if not supported.public abstract boolean hasFullSequenceSupport()
true
if this dialect fully support the sequences as 4GL language (most important:
bounded values, cycle). If not fully supported, additional code is needed in P2J sequence class
implementation to fix this.true
if this dialect fully support 4GL sequencespublic abstract java.lang.String getSequencePrefetchString(java.lang.String sequenceName)
sequenceName
- The name of the sequence from which the values are to be retrieved.null
if this feature is not supported by the
dialect.public abstract boolean isConnectionError(java.lang.Exception exc)
exc
- The exception to be checked.true
if the exception indicates a database connectivity error.public abstract boolean isQueryRangeParameterInlined()
where value ≥ ? and id = ?along with respective substitution parameters of 45 and 100, the inlined version would read:
where value ≥ 45 and id = ?Only the
id
substitution parameter of 100 would be
substituted into the prepared statement.
Inlining in such a way can give some database dialects the opportunity to choose a better query plan, than if the parameter being tested with a range check were to be substituted at statement execution time.
Note: this serves as a hint which may be overridden by runtime logic or other configuration settings.
true
to inline range check parameters;
false
to use normal parameter substitution.public abstract void inlineLimit(boolean on)
Dialects are free to treat this method as a hint.
on
- true
to enable inlining; false
to
disable it.public abstract boolean requiresExplicitCastInsideTernary()
true
if they should be casted.public java.lang.String getLimitString(java.lang.String sql, int offset, int limit)
sql
- Base select statement SQL without the limit/offset clause.offset
- Starting offset.limit
- Number of records to return.public boolean supportsVariableLimit()
false
; should be overridden by dialects which support a variable (i.e.,
not inlined) limit string.public abstract java.lang.String getDropIndexString(P2JIndex index)
index
- Definition of the index to be dropped.public java.lang.String getCreateIndexString(P2JIndex index, boolean unique, boolean toFile)
It is expected that this method is NOT used at runtime, as it has a dependency on conversion project configuration being available.
index
- Definition of the index to be created.unique
- If true
, create the index as a unique index, otherwise omit the unique
constraint.toFile
- true
if the string will be output to a file. Otherwise it will be directly
submitted via JDBC.
TODO: this parameter seems to be unused. Drop it?public java.lang.String getComputedColumnFormula(java.lang.String colName, boolean ignoreCase)
colName
- The base column name.ignoreCase
- true
if this is a char field which has the "ignore case" flag set.null
if the dialect does not support
computed columns.public abstract java.lang.String prepareMetadataParameter(java.lang.String param)
param
- The metadata query parameter.public abstract java.lang.String processMetadataResult(java.lang.String value)
value
- The metadata query result.public abstract boolean isMetadataSortDesc(java.lang.String value)
value
- The value to be checked.true
if the value is the "ascending" clause.public abstract boolean isMetadataSortAsc(java.lang.String value)
value
- The value to be checked.true
if the value is the "descending" clause.public java.util.List<java.lang.String> getDatabasePrepareStatements(Database database)
database
- The database which needs to be prepared.public abstract boolean explicitSetCollation()
true
if the collation needs to be explicitly set.public abstract java.lang.String getDelimiter()
public void beforeDriverLoad()
public abstract java.lang.String buildRemoteURL(java.lang.String url, Database database) throws PersistenceException
url
- The URL as received from the remote server.database
- The database to which this URL belongs.PersistenceException
- if the specified connection URL is invalid.public abstract SequenceHandler createSequenceHandler(java.lang.String ldbName)
SequenceHandler
for a database.ldbName
- The logical name of the database to create the SequenceHandler
for.SequenceHandler
for respective database.public abstract boolean injectComputedColumns()
true
if the computed columns should be injected on table creating
else false
.public java.lang.String quote(java.lang.String expr)
expr
- String expression.public int getIndexLengthLimit()
public int computeIndexKeySize(java.lang.Class<? extends BaseDataType> type, java.lang.Object val)
getIndexLengthLimit()
returns
positive values.
If this dialect does not have index-size constraints then this method does not need to be
overridden.type
- The type to be analyzed.val
- The actual value. Except for the char datatype, only the type of value
is used, the actual value is not needed to determine the size occupied by the
value as index-key.public abstract int getSyntheticIndexSize(boolean unique)
id
of the record may be additionally added to an index to add custom properties (eg uniqueness)
but other fields could be added. This part of the index is not visible using index
reflection routines from IndexHelper
. The synthetic components may differ
between unique and non-unique indexes.unique
- true
if the index is uniquepublic abstract void addRtrimmedExpression(java.lang.String expr, java.lang.StringBuilder sb)
rtrim(expr)The rtrim-med expression is appended to the string builder. The return value (the number of occurrences of the initial expr added to sb) should be use by caller to count the number of possible parameters from a query.
expr
- The expression to be rtrim -med. It's up to the caller if it is
a qualified field or not or any other kind of character-type expression.sb
- The StringBuilder
to append the trimmed filed to.public int getMaxParameterCount()
public java.lang.String getCreateTableString()
public abstract java.lang.String getCreateTemporaryTableString(boolean ifNotExist)
ifNotExist
- If true
an dialect-specific, optional if not exist
clause is added.public abstract java.lang.String getCreateTemporaryTablePostfix()
public java.lang.String getCreateIndexString(boolean unique)
unique
- true
for unique indexes.public abstract java.lang.String getDropIndexString(boolean ifExists, java.lang.String idxName)
ifExists
- Flag that requires that the DDL include an optional IF EXIST
clause.idxName
- The name of the index to be dropped by this DDL.public abstract java.lang.String getDropTableString(boolean ifExists, java.lang.String tableName)
ifExists
- Flag that requires that the DDL include an optional IF EXIST
clause.tableName
- The name of the table to be dropped by this DDL.public java.lang.String getSpecificTypeAsString(FqlType type)
FqlType
to a string representation which can be used in a
SQL query (cast
or other construct).type
- The type to be converted to string.public java.lang.String getSqlMappedType(java.lang.Class<?> fwdType, int scale)
fwdType
- The FWD type.scale
- Optional scale parameter (for decimal
data type).fwdType
.public java.lang.String getSqlMappedType(java.lang.String fwdType, int scale)
fwdType
- The class name of the FWD datatype.scale
- Optional scale parameter (for decimal
data type).fwdType
.public abstract java.lang.String getAnalyzeString(java.lang.String table)
analyze
or similar statements
for this dialect. If the table
is not null
the statement will analyze only
the respective table. Otherwise, all the tables are analyzed.table
- The name of the table to be analyzed. If null
, all tables from the database
will be analyzed, if possible.analyze
statement in the form requested null
is returned.public java.lang.String orderByNulls(boolean asc)
asc
- The sort direction.public java.util.Optional<Dialect.WeightAggregator> weightAggregator()