public class P2JSQLServer2008Dialect extends Dialect
SQLServer2008Dialect
class to add method implementations
required by the abstract Dialect
base class.
Note: this implementation expects a directory to be available at the time the class is loaded.
Dialect.WeightAggregator
Modifier and Type | Field and Description |
---|---|
private static java.util.Map<java.lang.String,java.lang.String> |
fwd2sql
Mapping between the FWD possible field/column types and their SQL counterparts.
|
private static java.sql.Date |
highDate
Highest date supported by SQL Server 2008 (December 31, 9999)
http://msdn.microsoft.com/en-US/library/ms187819%28v=sql.100%29.aspx
|
(package private) static java.util.Map<java.lang.Class<? extends BaseDataType>,java.lang.Integer> |
indexFieldSizes |
private static ContextLocal<java.lang.Boolean> |
inlineLimit
Flag indicating whether to inline a record limit in an SQL SELECT
|
private static java.util.logging.Logger |
LOG
Logger
|
private static java.sql.Date |
lowDate
datetime is deprecated and it does not align with the SQL Standard. |
private static int |
MAX_INDEX_SIZE
The maximum size of all fields of an index, in bytes.
|
private static int |
MAX_LENGTH
Private constant from SQLServer2005Dialect used in sql types mapping with
registerColumnType().
|
private static int |
MAX_PARAMETER_COUNT
The maximum number of parameters allowed by the SQL Server is a single query.
|
Constructor and Description |
---|
P2JSQLServer2008Dialect()
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.
|
java.sql.Blob |
blobCreator(java.sql.Connection conn,
byte[] bytes)
Create a
Blob instance from the specified bytes. |
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.
|
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.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 SQL Server 2008 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.
|
void |
generateWordTablesDDLImpl(java.lang.String dbName,
java.io.PrintStream out,
java.lang.String eoln,
java.util.Collection<WordTable> wordTables)
Worker method for
generateTriggerDDLs() . |
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(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)
Generate a DDL string which will create a global sequence.
|
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.lang.String |
getCreateTemporaryTablePostfix()
Return the ending of the DDL statement that creates a temporary table.
|
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.
|
java.lang.String |
getDelimiter()
Get the statement delimiter for this dialect.
|
java.lang.String |
getDriverClassName()
Get the name of the JDBC driver class associated with this dialect.
|
java.lang.String |
getDropIndexString(boolean ifExists,
java.lang.String idxName)
Obtain a DDL statement which drops a SQL index.
|
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.
|
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()
MS SQL Server has constraints about the maximum size of fields that compose an index.
|
java.lang.String |
getJdbcDatabaseType()
Get the name of the JDBC database type (as in JBC URL).
|
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.
|
java.lang.String |
getSequenceCurrValString(java.lang.String sequenceName)
Generate the appropriate select statement to retrieve the current value of a sequence.
|
java.lang.String |
getSequenceNextValString(java.lang.String sequenceName)
Generate the appropriate select statement to retrieve the next 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.
|
java.lang.String |
getSqlMappedType(java.lang.String fwdType,
int scale)
Get the SQL mapping for a specific FWD data type.
|
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). |
java.lang.String |
id()
Get dialect id.
|
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 ascending clause for a column index.
|
boolean |
isMetadataSortDesc(java.lang.String value)
Check if the given value is a descending 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 |
isUdfOriginated(java.sql.SQLException e)
Check if the exception was caused by error in UDF.
|
boolean |
needsComputedColumns()
Indicate whether this dialect requires computed columns to participate
within index definitions, instead of embedded expressions.
|
java.lang.String |
prepareMetadataParameter(java.lang.String param)
Prepare the given metadata query parameter.
|
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.
|
ScriptSplitter |
scripSplitter()
Get the splitter for DDL scripts.
|
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.
|
boolean |
useUdf4Contains()
Check if UDF should be used for converted CONTAINS operator
|
beforeDriverLoad, containsUdfName, dialects, getCreateIndexString, getCreateTableString, getDialect, getDialect, getDialect, getLimitString, getSpecificTypeAsString, getSqlMappedType, getUdfErrorMessagePattern, isUdfContains, orderByNulls, postTransaction, quote, supportsVariableLimit, useCTE4Contains, useMixedNode4Contains, weightAggregator
private static final java.util.logging.Logger LOG
private static final ContextLocal<java.lang.Boolean> inlineLimit
private static final java.sql.Date lowDate
datetime
is deprecated and it does not align with the SQL Standard.
We convert p4gl date
-related datatypes using the MSSQL date
and
datetime2
. For both the lower limit is January 1, 001.
date:
msdn.microsoft.com/en-us/library/bb630352(v=sql.100).aspx
datetime2:
msdn.microsoft.com/en-us/library/bb677335(v=sql.100).aspx
private static final java.sql.Date highDate
private static final int MAX_LENGTH
private static final int MAX_INDEX_SIZE
private static final int MAX_PARAMETER_COUNT
private static final java.util.Map<java.lang.String,java.lang.String> fwd2sql
static final java.util.Map<java.lang.Class<? extends BaseDataType>,java.lang.Integer> indexFieldSizes
public P2JSQLServer2008Dialect()
We provide this constructor to override the superclass' mapping of
Types.VARCHAR
and Types.VARBINARY
.
public java.lang.String getDriverClassName()
getDriverClassName
in class Dialect
public java.lang.String getJdbcDatabaseType()
getJdbcDatabaseType
in class Dialect
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 class Dialect
persistence
- Provider of persistence services.null
.public java.sql.Date getLowDate()
getLowDate
in class Dialect
public java.sql.Date getHighDate()
getHighDate
in class Dialect
public java.lang.String formatDate(date d)
formatDate
in class Dialect
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 class Dialect
expr
- Column name as natively represented by the database dialect.public java.lang.String getProcessedCharacterColumnName(java.lang.String name, boolean ignoreCase)
getProcessedCharacterColumnName
in class Dialect
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 class Dialect
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 class Dialect
name
- Column name, alias, or expression.true
if name
represents a computed column.public boolean needsComputedColumns()
needsComputedColumns
in class Dialect
true
to indicate computed columns are required.public java.lang.String getComputedColumnPrefix(boolean caseSensitive)
getComputedColumnPrefix
in class Dialect
caseSensitive
- true
if this is a character field was declared with
CASE-SENSITIVE
attribute.null
to indicate the backing database does not use computed columns.needsComputedColumns()
public boolean supportsFunctionOverloading()
supportsFunctionOverloading
in class Dialect
public boolean supportsBooleanDatatype()
true
and false
literals;
0
and 1
values) as boolean
replacement, this method always returns false
.supportsBooleanDatatype
in class Dialect
false
.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 class Dialect
false
because Server 2008 does not have the concept of a SEQUENCE.
It appeared since SQL Server 2012.public java.lang.String getSequencePrefetchString(java.lang.String sequenceName)
getSequencePrefetchString
in class Dialect
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)
For the SQLServer dialect, 08S01 - common state for disconnect and cancel.
isConnectionError
in class Dialect
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 class Dialect
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.
inlineLimit
in class Dialect
on
- true
to enable inlining; false
to disable it.public boolean requiresExplicitCastInsideTernary()
requiresExplicitCastInsideTernary
in class Dialect
true
for SQL Server dialects.public java.lang.String getDropIndexString(P2JIndex index)
getDropIndexString
in class Dialect
index
- Definition of the index to be dropped.public java.lang.String getCreateIndexString(P2JIndex index, boolean unique, boolean toFile)
getCreateIndexString
in class Dialect
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 getComputedColumnFormula(java.lang.String colName, boolean ignoreCase)
getComputedColumnFormula
in class Dialect
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 java.lang.String prepareMetadataParameter(java.lang.String param)
prepareMetadataParameter
in class Dialect
param
- The metadata query parameter.public java.lang.String processMetadataResult(java.lang.String value)
processMetadataResult
in class Dialect
value
- The metadata query result.public boolean isMetadataSortDesc(java.lang.String value)
isMetadataSortDesc
in class Dialect
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 class Dialect
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 class Dialect
database
- The database which needs to be prepared.public boolean explicitSetCollation()
explicitSetCollation
in class Dialect
true
.public java.lang.String getDelimiter()
getDelimiter
in class Dialect
public java.lang.String buildRemoteURL(java.lang.String url, Database database) throws PersistenceException
buildRemoteURL
in class Dialect
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 java.lang.String getCreateSequenceString(java.lang.String name)
getCreateSequenceString
in class Dialect
name
- Sequence name.null
since this dialect does not support sequences.public java.lang.String getCreateSequenceString(java.lang.String name, long start)
getCreateSequenceString
in class Dialect
name
- Sequence name.start
- Sequence starting value.null
since this dialect does not support sequences.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 class Dialect
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
since this dialect does not support sequences.public java.lang.String getDropSequenceString(java.lang.String name)
getDropSequenceString
in class Dialect
name
- The name of the sequence to be dropped.null
since this dialect does not support sequences.public java.lang.String getSequenceSetValString(java.lang.String sequenceName, long newVal)
getSequenceSetValString
in class Dialect
sequenceName
- The name of the sequence.newVal
- The new value to be set.null
since this dialect does not support sequences.public java.lang.String getSequenceNextValString(java.lang.String sequenceName)
getSequenceNextValString
in class Dialect
sequenceName
- The name of the sequence to be queried.null
since this dialect does not support sequences.public java.lang.String getSequenceCurrValString(java.lang.String sequenceName)
getSequenceCurrValString
in class Dialect
sequenceName
- The name of the sequence to be queried.null
since this dialect does not support sequences.public SequenceHandler createSequenceHandler(java.lang.String ldbName)
SequenceHandler
for a SQL Server 2008 database.createSequenceHandler
in class Dialect
ldbName
- The logical name of the database to create the SequenceHandler
for.null
since this dialect does not support sequences.
It is appeared since SQL Server 2012.public boolean injectComputedColumns()
injectComputedColumns
in class Dialect
true
for SQL Server.public int getIndexLengthLimit()
getIndexLengthLimit
in class Dialect
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 should return 0.computeIndexKeySize
in class Dialect
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 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 class Dialect
unique
- true
if the index is unique, unused.getCreateIndexString()
.public void addRtrimmedExpression(java.lang.String expr, java.lang.StringBuilder sb)
rtrim(expr)The rtrimmed expression is appended to the string builder.
addRtrimmedExpression
in class Dialect
expr
- The expression to be rtrim -med. It's up to the caller if it is
a qualified field name or not or any other kind of character-type expression.sb
- The StringBuilder
to append the trimmed filed to.public int getMaxParameterCount()
getMaxParameterCount
in class Dialect
public java.lang.String getCreateTemporaryTableString(boolean ifNotExist)
getCreateTemporaryTableString
in class Dialect
ifNotExist
- If true
an dialect-specific, optional if not exist
clause is added.public java.lang.String getCreateTemporaryTablePostfix()
getCreateTemporaryTablePostfix
in class Dialect
public java.lang.String getDropIndexString(boolean ifExists, java.lang.String idxName)
getDropIndexString
in class Dialect
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 java.lang.String getDropTableString(boolean ifExists, java.lang.String tableName)
getDropTableString
in class Dialect
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 getSqlMappedType(java.lang.String fwdType, int scale)
getSqlMappedType
in class Dialect
fwdType
- The FWD type.scale
- Optional scale parameter (for decimal
data type).fwdType
.public 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.getAnalyzeString
in class Dialect
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 ScriptSplitter scripSplitter()
scripSplitter
in class Dialect
public java.sql.Blob blobCreator(java.sql.Connection conn, byte[] bytes)
Blob
instance from the specified bytes.blobCreator
in class Dialect
conn
- The JDBC connection.bytes
- The blob data.public java.sql.Clob clobCreator(java.sql.Connection conn, java.lang.String value)
Clob
instance from the specified value.clobCreator
in class Dialect
conn
- The JDBC connection.value
- The clob data.public boolean useUdf4Contains()
useUdf4Contains
in class Dialect
true
if UDF should be used for converted CONTAINS operatorpublic boolean isUdfOriginated(java.sql.SQLException e)
isUdfOriginated
in class Dialect
e
- the exception in questiontrue
if the exception was caused by error in UDF.public 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.generateWordTablesDDLImpl
in class Dialect
dbName
- The target schema.out
- The PrintStream
used for output.eoln
- OS-specific end of line terminator.wordTables
- word tables by name