public class P2JH2Dialect extends org.hibernate.dialect.H2Dialect implements P2JDialect
H2Dialect
class to add method
implementations required by the P2JDialect
interface.Modifier and Type | Field and Description |
---|---|
private static java.util.logging.Logger |
LOG
Logger
|
Constructor and Description |
---|
P2JH2Dialect()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
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.
|
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.
|
int |
computeIndexKeySize(BaseDataType value)
Computes the size (in bytes) occupied by this value when stored as index-key in an index.
|
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.
|
SequenceHandler |
createSequenceHandler(java.lang.String ldbName)
Creates and returns a
SequenceHandler for a H2 database. |
boolean |
explicitSetCollation()
Check if the dialect needs to set an explicit collation during schema
DDL generation.
|
java.lang.String |
extractColumnName(java.lang.String expr)
Given a native column name as queried from database metadata, extract the root name of a
column.
|
java.lang.String |
formatDate(date d)
Format a date object as a string which is appropriate for use in an SQL
statement.
|
java.lang.String |
getAlterComputedColumnString(java.lang.String tableName,
org.hibernate.cfg.Configuration config,
java.lang.String implClassName,
java.lang.String colName,
boolean ignoreCase)
Build the DDL to set the formula for the computed columns associated
with an indexed, character column.
|
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(P2JIndex index,
boolean unique,
boolean toFile)
Build the DDL to create an index based upon the specified definition.
|
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.
|
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.util.List<java.lang.String> |
getDatabasePrepareStatements(Database database)
Get a list of database prepare DDL statements.
|
java.lang.String |
getDelimiter()
Get the statement delimiter for this dialect.
|
java.lang.String |
getDropIndexString(P2JIndex index)
Build the DDL to drop an index based upon the specified definition.
|
java.lang.String |
getDropSequenceString(java.lang.String name)
Generate a DDL string which will drop a sequence with given properties.
|
java.sql.Date |
getHighDate()
Retrieve the latest possible date value which is valid for the backing
database.
|
int |
getIndexLengthLimit()
Some dialects do have constraints about the maximum size of fields that compose an index.
|
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.
|
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.
|
static java.util.List<java.lang.String> |
getReservedKeywords()
Get a collection of reserved keywords specific to this dialect.
|
java.lang.String |
getSequenceCurrValString(java.lang.String sequenceName)
Generate the appropriate select statement to retrieve the current
value of a sequence.
|
java.lang.String |
getSequencePrefetchString(java.lang.String sequenceName)
Generate the appropriate select statement to pre-fetch multiple, ascending values from a
sequence.
|
java.lang.String |
getSequenceSetValString(java.lang.String sequenceName,
long newVal)
Generate the appropriate select statement to reset the value of a
sequence.
|
int |
getSyntheticIndexSize(boolean unique)
Returns the size of the synthetic part of the index.
|
boolean |
hasFullSequenceSupport()
Returns
true if this dialect fully support the sequences as
4GL language (most important: bounded values, cycle). |
boolean |
injectComputedColumns()
Report whether the computed columns should be injected on table creating.
|
void |
inlineLimit(boolean on)
Enable/disable limit clause inlining.
|
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.
|
boolean |
isConnectionError(java.lang.Exception exc)
Given an exception, this method will check if it indicates a database
connectivity error.
|
boolean |
isMetadataSortAsc(java.lang.String value)
Check if the given value is an asceding clause for a column index.
|
boolean |
isMetadataSortDesc(java.lang.String value)
Check if the given value is a desceding clause for a column index.
|
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 |
needsComputedColumns()
Indicate whether this dialect requires computed columns to participate
within index definitions, instead of embedded expressions.
|
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.
|
java.lang.String |
prepareMetadataParameter(java.lang.String param)
Prepare the given metadata query parameter by making it uppercase.
|
java.lang.String |
processMetadataResult(java.lang.String value)
Process the given metadata query result, by making it lowercase.
|
boolean |
requiresExplicitCastInsideTernary()
Determines whether substitution parameters should be explicitly casted
to their datatypes inside "then ? else ?" statement.
|
boolean |
supportsBooleanDatatype()
Indicates whether this dialect supports boolean datatype.
|
boolean |
supportsFunctionOverloading()
Indicate whether this dialect natively supports the overloading of user
defined functions by parameter number and data type.
|
bindLimitParametersFirst, bindLimitParametersInReverseOrder, buildSQLExceptionConversionDelegate, doesReadCommittedCauseWritersToBlockReaders, dropTemporaryTableAfterUse, getAddColumnString, getCreateSequenceString, getCreateTemporaryTablePostfix, getCreateTemporaryTableString, getCurrentTimestampSelectString, getForUpdateString, getIdentityColumnString, getIdentityInsertString, getIdentitySelectString, getLimitString, getQuerySequencesString, getSelectSequenceNextValString, getSequenceNextValString, getViolatedConstraintNameExtracter, isCurrentTimestampSelectStringCallable, performTemporaryTableDDLInIsolation, supportsCurrentTimestampSelection, supportsIdentityColumns, supportsIfExistsAfterTableName, supportsLimit, supportsLobValueChangePropogation, supportsPooledSequences, supportsSequences, supportsTemporaryTables, supportsTupleDistinctCounts, supportsUnionAll, supportsUnique
appendIdentitySelectToInsert, appendLockHint, appendLockHint, applyLocksToSql, applySqlLimit, areStringComparisonsCaseInsensitive, buildLimitHandler, buildSQLExceptionConverter, cast, cast, cast, closeQuote, convertToFirstRowValue, createCaseFragment, createOuterJoinFragment, doesRepeatableReadCauseReadersToBlockWriters, dropConstraints, forceLimitUsage, forceLobAsLastValue, forUpdateOfColumns, generateTemporaryTableName, getAddForeignKeyConstraintString, getAddPrimaryKeyConstraintString, getAddUniqueConstraintString, getCascadeConstraintsString, getCaseInsensitiveLike, getCastTypeName, getColumnAliasExtractor, getColumnComment, getCreateMultisetTableString, getCreateSequenceString, getCreateSequenceStrings, getCreateSequenceStrings, getCreateTableString, getCrossJoinSeparator, getCurrentTimestampSQLFunctionName, getDefaultProperties, getDialect, getDialect, getDropForeignKeyString, getDropSequenceStrings, getDropTemporaryTableString, getForUpdateNowaitString, getForUpdateNowaitString, getForUpdateString, getForUpdateString, getForUpdateString, getForUpdateString, getFunctions, getHibernateTypeName, getHibernateTypeName, getIdentityColumnString, getIdentitySelectString, getInExpressionCountLimit, getKeywords, getLimitString, getLobMergeStrategy, getLockingStrategy, getLowercaseFunction, getMaxAliasLength, getNativeIdentifierGeneratorClass, getNoColumnsInsertString, getNullColumnString, getReadLockString, getResultSet, getSelectClauseNullString, getSelectGUIDString, getSqlTypeDescriptorOverride, getTableComment, getTableTypeString, getTypeName, getTypeName, getWriteLockString, hasAlterTable, hasDataTypeInIdentityColumn, hasSelfReferentialForeignKeyBug, isLockTimeoutParameterized, openQuote, qualifyIndexName, quote, registerColumnType, registerColumnType, registerFunction, registerHibernateType, registerHibernateType, registerKeyword, registerResultSetOutParameter, remapSqlTypeDescriptor, replaceResultVariableInOrderByClauseWithPosition, requiresCastingOfParametersInSelectClause, supportsBindAsCallableArgument, supportsCascadeDelete, supportsCaseInsensitiveLike, supportsCircularCascadeDeleteConstraints, supportsColumnCheck, supportsCommentOn, supportsEmptyInList, supportsExistsInSelect, supportsExpectedLobUsagePattern, supportsIfExistsBeforeTableName, supportsInsertSelectIdentity, supportsLimitOffset, supportsLockTimeouts, supportsNotNullUnique, supportsOuterJoinForUpdate, supportsParametersInInsertSelect, supportsResultSetPositionQueryMethodsOnForwardOnlyCursor, supportsRowValueConstructorSyntax, supportsRowValueConstructorSyntaxInInList, supportsSubqueryOnMutatingTable, supportsSubselectAsInPredicateLHS, supportsTableCheck, supportsTupleCounts, supportsUnboundedLobLocatorMaterialization, supportsUniqueConstraintInCreateAlterTable, supportsVariableLimit, toBooleanValueString, toString, transformSelectString, useInputStreamToInsertBlob, useMaxForLimit
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getSequenceNextValString, quote
public P2JH2Dialect()
We provide this constructor to override the superclass' mapping of
Types.VARCHAR
, in order to force this type to map to
PostgreSQL's text
data type.
public static java.util.List<java.lang.String> getReservedKeywords()
NameConverter
uses thes list to create an exclusion
list of names so there will not be schema collisions with identifiers (tables, fields) from
the generated schema.public boolean needsComputedColumns()
needsComputedColumns
in interface P2JDialect
true
to indicate computed columns are required.public java.lang.String getComputedColumnPrefix(boolean caseSensitive)
getComputedColumnPrefix
in interface P2JDialect
caseSensitive
- true
if this is a character field was declared with
CASE-SENSITIVE
attribute.needsComputedColumns()
public boolean supportsFunctionOverloading()
supportsFunctionOverloading
in interface P2JDialect
false
.public boolean supportsBooleanDatatype()
true
and false
literals;
supportsBooleanDatatype
in interface P2JDialect
true
, all the above mentioned items are supported.public 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
.
createContext
in interface P2JDialect
persistence
- Provider of persistence services.null
.public void postTransaction(Persistence persistence, java.lang.Object context, boolean rollback) throws PersistenceException
postTransaction
in interface P2JDialect
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()
getLowDate
in interface P2JDialect
null
, indicating no particular lower limit on
dates.public java.sql.Date getHighDate()
getHighDate
in interface P2JDialect
null
, indicating no particular upper limit on
dates.public java.lang.String formatDate(date d)
formatDate
in interface P2JDialect
d
- Date to be formatted as a string.public java.lang.String extractColumnName(java.lang.String expr)
__my_columnWe are interested only in the
my_column
root name, so we strip away the leading
__
prefix.extractColumnName
in interface P2JDialect
expr
- Column name as natively represented by the database dialect.public java.lang.String getProcessedCharacterColumnName(java.lang.String name, boolean ignoreCase)
getProcessedCharacterColumnName
in interface P2JDialect
name
- Base column name.ignoreCase
- true
to cause case to be ignored, else false
.public boolean isCaseInsensitiveColumn(java.lang.String name)
name
is
already determined to be the appropriate data type for textual data.isCaseInsensitiveColumn
in interface P2JDialect
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.isComputedColumn
in interface P2JDialect
name
- Column name, alias, or expression.true
if name
represents a computed column.public java.lang.String getCreateSequenceString(java.lang.String name, long start)
getCreateSequenceString
in interface P2JDialect
name
- Sequence name.start
- Sequence starting value.null
if not supported.public 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)
getCreateSequenceString
in interface P2JDialect
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 (may be null).maxVal
- Sequence maximum value. Optional (may be null).cycle
- Sequence cycling property. Optional, if missing assumed not cycling.null
if
not supported.public java.lang.String getDropSequenceString(java.lang.String name)
getDropSequenceString
in interface P2JDialect
getDropSequenceString
in class org.hibernate.dialect.H2Dialect
name
- The name of the sequence to be dropped.null
if not supported.public java.lang.String getSequenceSetValString(java.lang.String sequenceName, long newVal)
getSequenceSetValString
in interface P2JDialect
sequenceName
- The name of the sequence.newVal
- The new value to be set.null
if not supported.public java.lang.String getSequenceCurrValString(java.lang.String sequenceName)
getSequenceCurrValString
in interface P2JDialect
sequenceName
- The name of the sequence to be queried.null
if not supported.public 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.hasFullSequenceSupport
in interface P2JDialect
public java.lang.String getSequencePrefetchString(java.lang.String sequenceName)
getSequencePrefetchString
in interface P2JDialect
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 boolean isConnectionError(java.lang.Exception exc)
Currently, as the H2 database is used only for in-memory temp-tables, this method returns false.
isConnectionError
in interface P2JDialect
exc
- The exception to be checked.true
if the exception indicates a database
connectivity error.public 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.
isQueryRangeParameterInlined
in interface P2JDialect
true
to inline range check parameters;
false
to use normal parameter substitution.public void inlineLimit(boolean on)
Dialects are free to treat this method as a hint. This implementation does nothing.
inlineLimit
in interface P2JDialect
on
- true
to enable inlining; false
to
disable it.public boolean requiresExplicitCastInsideTernary()
requiresExplicitCastInsideTernary
in interface P2JDialect
true
.public java.lang.String getDropIndexString(P2JIndex index)
getDropIndexString
in interface P2JDialect
index
- Definition of the index to be dropped.public java.lang.String getCreateIndexString(P2JIndex index, boolean unique, boolean toFile)
When Hibernate decides to support "asc/desc" clauses, this method needs to be modified, as it appends the " desc" suffix to the column name, if the column sort is descending.
getCreateIndexString
in interface P2JDialect
index
- Definition of the index to be created.unique
- If true
, create the index as a unique index,
false
to omit the unique constraint.toFile
- true
if the string will be output to a file or
false
if it will be directly submitted via JDBC.public java.lang.String getAlterComputedColumnString(java.lang.String tableName, org.hibernate.cfg.Configuration config, java.lang.String implClassName, java.lang.String colName, boolean ignoreCase)
The syntax to set the formula for the computed column is:
alter table [table] alter column [column] [type] as [formula]
getAlterComputedColumnString
in interface P2JDialect
tableName
- Table name possible containing backticks.config
- The hibernate's configuration object.implClassName
- The full name of the implementing class for the DMO.colName
- The column name which needs to have a computed version. This is
not the computed column name, but the name of its "parent".ignoreCase
- true
if this is a character field which has the
"ignore case" flag set.public java.lang.String getComputedColumnFormula(java.lang.String colName, boolean ignoreCase)
getComputedColumnFormula
in interface P2JDialect
colName
- The base column name.ignoreCase
- true
if this is a char field which has the "ignore case" flag set.public java.lang.String prepareMetadataParameter(java.lang.String param)
prepareMetadataParameter
in interface P2JDialect
param
- The metadata query parameter.public java.lang.String processMetadataResult(java.lang.String value)
processMetadataResult
in interface P2JDialect
value
- The metadata query result.public boolean isMetadataSortDesc(java.lang.String value)
isMetadataSortDesc
in interface P2JDialect
value
- The value to be checked.true
if the value is the "D" or "d" string.public boolean isMetadataSortAsc(java.lang.String value)
isMetadataSortAsc
in interface P2JDialect
value
- The value to be checked.true
if the value is the "A" or "a" string.public java.util.List<java.lang.String> getDatabasePrepareStatements(Database database)
getDatabasePrepareStatements
in interface P2JDialect
database
- The database which needs to be prepared.public boolean explicitSetCollation()
explicitSetCollation
in interface P2JDialect
true
.public java.lang.String getDelimiter()
getDelimiter
in interface P2JDialect
public void beforeDriverLoad()
The "h2.sortNullsHigh" setting was removed, as it was determined that by forcing the H2 to sort nulls high, it causes a regression in a test where 4GL seems to sort the unknown value at the end of the result set, when an descending sort clause was used (instead of sorting it at the begining of the result set).
TODO: more testing needs to be done to determine exactly how 4GL sorts the unknown value in the temporary database (and permanent DB too). At the time of this comment, H2 has a bug which doesn't enforce the "sort nulls high" setting in cases when the query's result order is determined by the index.
beforeDriverLoad
in interface P2JDialect
public java.lang.String buildRemoteURL(java.lang.String url, Database database) throws PersistenceException
buildRemoteURL
in interface P2JDialect
url
- The URL as received from the remote server. If this indicates an embedded
database, a mixed mode URL which will allow secure (i.e., SSL), remote connections
to that database is generated. The mixed mode port is fixed.database
- The database to which this URL belongs.PersistenceException
- if the specified connection URL is invalid.public SequenceHandler createSequenceHandler(java.lang.String ldbName)
SequenceHandler
for a H2 database.createSequenceHandler
in interface P2JDialect
ldbName
- The logical name of the database to create the SequenceHandler
for.H2SequenceHandler
for respective database.public boolean injectComputedColumns()
injectComputedColumns
in interface P2JDialect
true
for H2 database.public int getIndexLengthLimit()
getIndexLengthLimit
in interface P2JDialect
public int computeIndexKeySize(BaseDataType value)
computeIndexKeySize
in interface P2JDialect
value
- Ignored.public 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.
getSyntheticIndexSize
in interface P2JDialect
unique
- true
if the index is uniquepublic void addRtrimmedExpression(java.lang.String expr, java.lang.StringBuilder sb)
rtrim(expr)The rtrimmed expression is appended to the string builder.
addRtrimmedExpression
in interface P2JDialect
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()
getMaxParameterCount
in interface P2JDialect