public abstract class Dialect extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Dialect.ArraySubQuery
Structured Array Subquery Abstract Class.
|
static class |
Dialect.DialectIdType
Type of id when stored in the database.
|
static class |
Dialect.FulltextMatchInfo
Information needed to express fulltext search with scoring.
|
static class |
Dialect.JDBCInfo |
Modifier and Type | Field and Description |
---|---|
protected boolean |
aclOptimizationsEnabled |
static String |
ARRAY_SEP |
protected boolean |
clusteringEnabled |
static boolean |
DEBUG_REAL_UUIDS |
static boolean |
DEBUG_UUIDS |
protected String |
descending
Store the SQL for descending order
|
static String |
DIALECT_CLASS
System property to override the dialect to use globally instead of the one auto-detected.
|
static Map<String,Class<? extends Dialect>> |
DIALECTS |
protected boolean |
fulltextDisabled |
protected boolean |
fulltextSearchDisabled |
protected static char[] |
HEX_DIGITS |
static String |
NULLS_LAST_ON_DESC_PROP
Property used to disable NULLS LAST usage when sorting DESC.
|
protected boolean |
proxiesEnabled |
protected int |
readAclMaxSize |
protected boolean |
softDeleteEnabled |
protected boolean |
storesUpperCaseIdentifiers |
Constructor and Description |
---|
Dialect(DatabaseMetaData metadata,
RepositoryDescriptor repositoryDescriptor) |
Modifier and Type | Method and Description |
---|---|
String |
addPagingClause(String sql,
long limit,
long offset)
Returns the SQL query with a paging clause
|
String |
castIdToVarchar(String expr)
Casts an id column to a VARCHAR type.
|
abstract List<String> |
checkStoredProcedure(String procName,
String procCreate,
String ddlMode,
Connection connection,
JDBCLogger logger,
Map<String,Serializable> properties)
Checks if a given stored procedure exists and is identical to the passed creation SQL.
|
char |
closeQuote() |
Array |
createArrayOf(int type,
Object[] elements,
Connection connection)
Factory method for creating Array objects, suitable for passing to
PreparedStatement.setArray(int, java.sql.Array) . |
static Dialect |
createDialect(Connection connection,
RepositoryDescriptor repositoryDescriptor)
Creates a
Dialect by connecting to the datasource to check what database is used. |
abstract boolean |
doesUpdateFromRepeatSelf()
When doing an UPDATE t SET ...
|
String |
getAddColumnString() |
String |
getAddForeignKeyConstraintString(String constraintName,
String[] foreignKeys,
String referencedTable,
String[] primaryKeys,
boolean referencesPrimaryKey) |
String |
getAddPrimaryKeyConstraintString(String constraintName) |
String |
getAncestorsIdsSql()
Gets the SQL query to get the ancestors of a set of ids.
|
String |
getArrayElementString(String arrayColumnName,
int arrayElementIndex)
Get SQL Array Element Subscripted string.
|
String |
getArrayIlikeSql(Column arrayColumn,
String refName,
boolean positive,
Table dataHierTable)
Gets the SQL string for an array column ILIKE expression.
|
String |
getArrayInSql(Column arrayColumn,
String cast,
boolean positive,
List<Serializable> params)
Gets the SQL string for an array column IN expression.
|
String |
getArrayLikeSql(Column arrayColumn,
String refName,
boolean positive,
Table dataHierTable)
Gets the SQL string for an array column LIKE expression.
|
Serializable[] |
getArrayResult(Array array)
Gets the array result as a converted array of Serializable.
|
Dialect.ArraySubQuery |
getArraySubQuery(Column arrayColumn,
String subQueryAlias)
Gets the dialect-specific subquery for an array column.
|
String |
getBinaryFulltextSql(List<String> columns)
Return the SQL to get the columns fulltext fields
|
String |
getBlobLengthFunction()
Gets the SQL function that returns the length of a blob, in bytes.
|
Calendar |
getCalendarFromTimestamp(Timestamp value) |
Calendar[] |
getCalendarFromTimestamp(Timestamp[] value) |
String |
getCascadeDropConstraintsString() |
String |
getClobCast(boolean inOrderBy)
When using a CLOB field in an expression, is some casting required and with what pattern?
|
String |
getClusterGetInvalidations()
Gets the SQL to query invalidations for this cluster node.
|
String |
getClusterInsertInvalidations()
Gets the SQL to send an invalidation to the cluster.
|
String |
getColumnName(String name) |
String |
getConnectionSchema(Connection connection)
Gets the schema to use to query metadata about existing tables.
|
abstract String |
getCreateFulltextIndexSql(String indexName,
String quotedIndexName,
Table table,
List<Column> columns,
Model model)
Gets a CREATE INDEX statement for a fulltext index.
|
String |
getCreateIndexSql(String indexName,
Table.IndexType indexType,
Table table,
List<Column> columns,
Model model)
Gets a CREATE INDEX statement for an index.
|
String |
getCustomColumnDefinition(Table table)
Additional column definitions for CREATE TABLE.
|
List<String> |
getCustomPostCreateSqls(Table table,
Model model)
Additional things to execute after CREATE TABLE.
|
String |
getDateCast()
Get the expression to use to cast a column to a DATE type.
|
String |
getDescending()
Gets the SQL descending sort direction with option to sort nulls last.
|
abstract String |
getDialectFulltextQuery(String query)
Get the dialect-specific version of a fulltext query.
|
Collection<? extends String> |
getDumpStart()
Returns the initial DDL statements to add to a DDL dump.
|
Collection<? extends String> |
getDumpStop()
Returns the final DDL statements to add to a DDL dump.
|
String |
getForeignKeyConstraintName(String tableName,
String foreignColumnName,
String foreignTableName) |
String |
getFreeVariableSetterForType(ColumnType type)
Gets the JDBC expression setting a free value for this column type.
|
abstract Serializable |
getFromResultSet(ResultSet rs,
int index,
Column column) |
protected Serializable |
getFromResultSetString(ResultSet rs,
int index,
Column column) |
protected Serializable |
getFromResultSetTimestamp(ResultSet rs,
int index,
Column column) |
abstract int |
getFulltextIndexedColumns()
Specifies what columns of the fulltext table have to be indexed.
|
abstract Dialect.FulltextMatchInfo |
getFulltextScoredMatchInfo(String fulltextQuery,
String indexName,
int nthMatch,
Column mainColumn,
Model model,
Database database)
Gets the SQL information needed to do a a fulltext match, either with a direct expression in the WHERE clause, or
using a join with an additional table.
|
int |
getFulltextType()
Gets the type of a fulltext column has known by JDBC.
|
Serializable |
getGeneratedId(Connection connection)
Gets a generated id if so configured, otherwise returns null.
|
String |
getIdentityGeneratedKeySql(Column column)
Gets the SQL query to execute to retrieve the last generated identity key.
|
Dialect.DialectIdType |
getIdType()
Gets the type of id when stored in the database.
|
List<String> |
getIgnoredColumns(Table table)
Columns ignored if we see them in existing tables.
|
String |
getIndexName(String tableName,
List<String> columnNames) |
abstract String |
getInTreeSql(String idColumnName,
String id)
Gets the expression to use to check tree membership.
|
abstract Dialect.JDBCInfo |
getJDBCTypeAndString(ColumnType type)
Gets the JDBC type and string from Nuxeo's type abstraction.
|
String |
getLikeEscaping()
Gets the SQL fragment to add after a LIKE match to specify the escaping character.
|
String |
getMatchMixinType(Column mixinsColumn,
String mixin,
boolean positive,
String[] returnParam)
Gets the SQL fragment to match a mixin type.
|
abstract boolean |
getMaterializeFulltextSyntheticColumn()
Does the fulltext synthetic column have to be materialized.
|
int |
getMaximumArgsForIn()
Maximum number of values in a IN (?, ?, ...) statement.
|
protected int |
getMaxIndexNameSize() |
protected int |
getMaxNameSize() |
String |
getNoColumnsInsertString(Column idColumn) |
String |
getNullColumnString() |
List<String> |
getPostCreateIdentityColumnSql(Column column)
Gets additional SQL statements to execute after the CREATE TABLE when creating an identity column.
|
String |
getPrepareUserReadAclsSql()
Gets the SQL expression to prepare the user read acls cache.
|
String |
getPrimaryKeyConstraintName(String tableName) |
String |
getReadAclsCheckSql(String userIdCol)
Gets the expression to check if access is allowed using read acls.
|
String |
getRebuildReadAclsSql()
Gets the statement to rebuild the wall read acls
|
abstract String |
getSecurityCheckSql(String idColumnName)
Gets the expression to use to check security.
|
String |
getSoftDeleteCleanupSql()
SQL to clean soft-delete documents.
|
String |
getSoftDeleteSql()
SQL to soft delete documents.
|
String |
getSQLForDump(String sql)
Returns the SQL statement with proper terminator to use in a dump.
|
abstract String |
getSQLStatementsFilename()
Gets the name of the file containing the SQL statements.
|
abstract Map<String,Serializable> |
getSQLStatementsProperties(Model model,
Database database)
Gets the properties to use with the SQL statements.
|
List<String> |
getStartupSqls(Model model,
Database database)
Gets the sql statements to execute after the repository init (at startup).
|
String |
getTableName(String name) |
String |
getTableTypeString(Table table) |
abstract String |
getTestSQLStatementsFilename() |
Timestamp |
getTimestampFromCalendar(Calendar value) |
Timestamp[] |
getTimestampFromCalendar(Serializable[] value) |
String |
getUpdateReadAclsSql()
Gets the statement to update the read acls
|
String |
getValidationQuery()
A query that, when executed, will make at least a round-trip to the server to check that the connection is alive.
|
boolean |
hasIdentityGeneratedKey()
True if the dialect returns the generated key for the identity from the insert statement.
|
boolean |
hasNullEmptyString()
Does the dialect have an empty string identical to NULL (Oracle).
|
boolean |
isAllowedConversion(int expected,
int actual,
String actualName,
int actualSize)
Check mismatches between expected and actual JDBC types read from database introspection.
|
boolean |
isClusteringDeleteNeeded()
Does clustering fetch of invalidations (
getClusterGetInvalidations() ) need a separate delete for them. |
boolean |
isClusteringSupported()
Checks that clustering is supported.
|
boolean |
isConcurrentUpdateException(Throwable t)
Checks if an exception received means that a concurrent update was detected.
|
boolean |
isIdentityAlreadyPrimary()
Checks if an identity column is already defined as a primary key and does not need a separate index added.
|
static Dialect.JDBCInfo |
jdbcInfo(String string,
int jdbcType) |
static Dialect.JDBCInfo |
jdbcInfo(String string,
int length,
int jdbcType) |
static Dialect.JDBCInfo |
jdbcInfo(String string,
int length,
int jdbcType,
String jdbcBaseTypeString,
int jdbcBaseType) |
static Dialect.JDBCInfo |
jdbcInfo(String string,
int jdbcType,
String jdbcBaseTypeString,
int jdbcBaseType) |
protected String |
makeName(String name,
int maxNameSize) |
protected String |
makeName(String prefix,
String string,
String suffix,
int maxNameSize) |
boolean |
needsAliasForDerivedTable()
Whether a derived table (subselect in a FROM statement) needs an alias.
|
boolean |
needsNullsLastOnDescSort()
True if the dialect need an extra NULLS LAST on DESC sort.
|
boolean |
needsOracleJoins()
Whether implicit Oracle joins (instead of explicit ANSI joins) are needed.
|
boolean |
needsOrderByKeysAfterDistinct()
When doing a SELECT DISTINCT that uses a ORDER BY, do the keys along which we order have to be mentioned in the
DISTINCT clause?
|
boolean |
needsOriginalColumnInGroupBy()
Whether a GROUP BY can only be used with the original column name and not an alias.
|
boolean |
needsPrepareUserReadAcls()
The dialect need an extra SQL statement to populate a user read acl cache before running the query.
|
char |
openQuote() |
void |
performAdditionalStatements(Connection connection)
Let the dialect processes additional statements after tables creation and conditional statements.
|
void |
performPostOpenStatements(Connection connection)
Let the dialect perform additional statements just after the connection is opened.
|
boolean |
qualifyIndexName() |
void |
setId(PreparedStatement ps,
int index,
Serializable value)
Sets a prepared statement value that is a Nuxeo main id (usually UUID).
|
void |
setIdLong(PreparedStatement ps,
int index,
Serializable value)
Sets a long id (sequence) from a value that may be a String or already a Long.
|
abstract void |
setToPreparedStatement(PreparedStatement ps,
int index,
Serializable value,
Column column) |
protected void |
setToPreparedStatementString(PreparedStatement ps,
int index,
Serializable value,
Column column) |
void |
setToPreparedStatementTimestamp(PreparedStatement ps,
int index,
Serializable value,
Column column) |
boolean |
storesUpperCaseIdentifiers() |
boolean |
supportsAncestorsTable()
Checks if the dialect supports an ancestors table.
|
boolean |
supportsArrayColumns()
Does the dialect support storing arrays in table columns.
|
boolean |
supportsArrays()
Does the dialect support passing ARRAY values (to stored procedures mostly).
|
boolean |
supportsArraysReturnInsteadOfRows()
Does a stored function returning an result set need to access it as a single array instead of iterating over a
normal result set's rows.
|
boolean |
supportsBatchUpdateCount()
Does the dialect report accurate update counts for batch updates.
|
boolean |
supportsCircularCascadeDeleteConstraints() |
boolean |
supportsFastDescendants()
Checks whether
getInTreeSql(String, String) is optimized for fast results (using an ancestors or
descendants table). |
boolean |
supportsIfExistsAfterTableName() |
boolean |
supportsIfExistsBeforeTableName() |
boolean |
supportsIlike()
Does the dialect support ILIKE operator
|
boolean |
supportsMultipleFulltextIndexes()
SQL Server supports only one fulltext index.
|
boolean |
supportsPaging()
Indicates if dialect supports paging
|
boolean |
supportsReadAcl()
Does the dialect support an optimized read security checks
|
boolean |
supportsScroll()
Does the dialect support an scroll API
|
boolean |
supportsSysNameArray()
Checks if the dialect supports storing arrays of system names (for mixins for instance).
|
abstract boolean |
supportsUpdateFrom()
Does the dialect support UPDATE t SET ...
|
boolean |
supportsWith()
Does the dialect support SQL-99 WITH common table expressions.
|
String |
toBooleanValueString(boolean bool) |
static String |
toHexString(byte[] bytes) |
public static final boolean DEBUG_UUIDS
public static final boolean DEBUG_REAL_UUIDS
public static final String NULLS_LAST_ON_DESC_PROP
protected String descending
public static final String DIALECT_CLASS
protected final boolean storesUpperCaseIdentifiers
protected boolean fulltextDisabled
protected boolean fulltextSearchDisabled
protected final boolean aclOptimizationsEnabled
protected boolean clusteringEnabled
protected boolean softDeleteEnabled
protected boolean proxiesEnabled
protected final int readAclMaxSize
public static final String ARRAY_SEP
protected static final char[] HEX_DIGITS
public Dialect(DatabaseMetaData metadata, RepositoryDescriptor repositoryDescriptor)
public boolean supportsScroll()
public static Dialect.JDBCInfo jdbcInfo(String string, int jdbcType)
public static Dialect.JDBCInfo jdbcInfo(String string, int length, int jdbcType)
public static Dialect.JDBCInfo jdbcInfo(String string, int jdbcType, String jdbcBaseTypeString, int jdbcBaseType)
public static Dialect.JDBCInfo jdbcInfo(String string, int length, int jdbcType, String jdbcBaseTypeString, int jdbcBaseType)
public static Dialect createDialect(Connection connection, RepositoryDescriptor repositoryDescriptor)
Dialect
by connecting to the datasource to check what database is used.public String getConnectionSchema(Connection connection) throws SQLException
SQLException
public abstract Dialect.JDBCInfo getJDBCTypeAndString(ColumnType type)
public boolean isAllowedConversion(int expected, int actual, String actualName, int actualSize)
public Serializable getGeneratedId(Connection connection) throws SQLException
SQLException
public void setId(PreparedStatement ps, int index, Serializable value) throws SQLException
ps
- the prepared statementindex
- the parameter index in the prepared statementvalue
- the value to setSQLException
public void setIdLong(PreparedStatement ps, int index, Serializable value) throws SQLException
SQLException
public abstract void setToPreparedStatement(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException
SQLException
protected void setToPreparedStatementString(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException
SQLException
public void setToPreparedStatementTimestamp(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException
SQLException
public Timestamp getTimestampFromCalendar(Calendar value)
public Timestamp[] getTimestampFromCalendar(Serializable[] value)
public Calendar getCalendarFromTimestamp(Timestamp value)
public Calendar[] getCalendarFromTimestamp(Timestamp[] value)
public abstract Serializable getFromResultSet(ResultSet rs, int index, Column column) throws SQLException
SQLException
protected Serializable getFromResultSetString(ResultSet rs, int index, Column column) throws SQLException
SQLException
protected Serializable getFromResultSetTimestamp(ResultSet rs, int index, Column column) throws SQLException
SQLException
public boolean storesUpperCaseIdentifiers()
public char openQuote()
public char closeQuote()
public String toBooleanValueString(boolean bool)
protected int getMaxNameSize()
protected int getMaxIndexNameSize()
public static String toHexString(byte[] bytes)
public String getTableName(String name)
public String getColumnName(String name)
public String getPrimaryKeyConstraintName(String tableName)
public String getForeignKeyConstraintName(String tableName, String foreignColumnName, String foreignTableName)
public String getIndexName(String tableName, List<String> columnNames)
public String getCreateIndexSql(String indexName, Table.IndexType indexType, Table table, List<Column> columns, Model model)
indexName
- the index name (for fulltext)indexType
- the index typetable
- the tablecolumns
- the columns to indexmodel
- the modelpublic abstract int getFulltextIndexedColumns()
public boolean supportsMultipleFulltextIndexes()
public abstract boolean getMaterializeFulltextSyntheticColumn()
public abstract String getCreateFulltextIndexSql(String indexName, String quotedIndexName, Table table, List<Column> columns, Model model)
public abstract String getDialectFulltextQuery(String query)
query
- the CMIS-syntax-based fulltext query stringpublic abstract Dialect.FulltextMatchInfo getFulltextScoredMatchInfo(String fulltextQuery, String indexName, int nthMatch, Column mainColumn, Model model, Database database)
public String getLikeEscaping()
public String getMatchMixinType(Column mixinsColumn, String mixin, boolean positive, String[] returnParam)
public boolean supportsPaging()
public String addPagingClause(String sql, long limit, long offset)
public int getFulltextType()
This is used for setNull.
public String getFreeVariableSetterForType(ColumnType type)
Needed for columns that need an expression around the value being set, usually for conversion (this is the case
for PostgreSQL fulltext TSVECTOR
columns for instance).
type
- the column typepublic String getNoColumnsInsertString(Column idColumn)
public String getNullColumnString()
public String getTableTypeString(Table table)
public String getAddPrimaryKeyConstraintString(String constraintName)
public String getAddForeignKeyConstraintString(String constraintName, String[] foreignKeys, String referencedTable, String[] primaryKeys, boolean referencesPrimaryKey)
public boolean qualifyIndexName()
public boolean supportsIfExistsBeforeTableName()
public boolean supportsIfExistsAfterTableName()
public String getCascadeDropConstraintsString()
public boolean supportsCircularCascadeDeleteConstraints()
public String getAddColumnString()
public abstract boolean supportsUpdateFrom()
public abstract boolean doesUpdateFromRepeatSelf()
public boolean needsOrderByKeysAfterDistinct()
public boolean needsAliasForDerivedTable()
public boolean needsOriginalColumnInGroupBy()
public boolean needsOracleJoins()
public boolean needsPrepareUserReadAcls()
public boolean needsNullsLastOnDescSort()
public String getClobCast(boolean inOrderBy)
Needed for Derby and H2.
inOrderBy
- true
if the expression is for an ORDER BY columnnull
if no cast is requiredpublic String getDateCast()
public String castIdToVarchar(String expr)
Used for uuid/varchar joins.
public Dialect.DialectIdType getIdType()
public abstract String getSecurityCheckSql(String idColumnName)
idColumnName
- the quoted name of the id column to usepublic boolean supportsAncestorsTable()
public boolean supportsFastDescendants()
getInTreeSql(String, String)
is optimized for fast results (using an ancestors or
descendants table).public abstract String getInTreeSql(String idColumnName, String id)
idColumnName
- the quoted name of the id column to useid
- the id, to check syntax with respect to specialized id column typesnull
if the query cannot matchpublic boolean supportsArrays()
If not, we'll simulate them using a string and a separator.
public boolean supportsArraysReturnInsteadOfRows()
Oracle needs this.
public Serializable[] getArrayResult(Array array) throws SQLException
SQLException
public boolean supportsSysNameArray()
public boolean supportsArrayColumns()
public Dialect.ArraySubQuery getArraySubQuery(Column arrayColumn, String subQueryAlias)
public String getArrayElementString(String arrayColumnName, int arrayElementIndex)
public String getArrayInSql(Column arrayColumn, String cast, boolean positive, List<Serializable> params)
public String getArrayLikeSql(Column arrayColumn, String refName, boolean positive, Table dataHierTable)
public String getArrayIlikeSql(Column arrayColumn, String refName, boolean positive, Table dataHierTable)
public Array createArrayOf(int type, Object[] elements, Connection connection) throws SQLException
PreparedStatement.setArray(int, java.sql.Array)
.
(An equivalent method is defined by JDBC4 on the Connection
class.)
type
- the SQL type of the elementselements
- the elements of the arrayconnection
- the connectionSQLException
public abstract String getSQLStatementsFilename()
public abstract String getTestSQLStatementsFilename()
public abstract Map<String,Serializable> getSQLStatementsProperties(Model model, Database database)
public boolean isClusteringSupported()
public boolean isClusteringDeleteNeeded()
getClusterGetInvalidations()
) need a separate delete for them.public String getClusterInsertInvalidations()
public String getClusterGetInvalidations()
public boolean supportsIlike()
public boolean supportsReadAcl()
public boolean supportsWith()
public boolean hasNullEmptyString()
public int getMaximumArgsForIn()
Beyond this size we'll do the query in several chunks.
PostgreSQL is limited to 65535 values in a prepared statement.
Oracle is limited to 1000 expressions in a list (ORA-01795).
public String getUpdateReadAclsSql()
public String getRebuildReadAclsSql()
public String getReadAclsCheckSql(String userIdCol)
userIdCol
- the quoted name of the aclr_user_map user_id column to usepublic String getPrepareUserReadAclsSql()
public List<String> getStartupSqls(Model model, Database database)
Used for vacuum-like operations.
public boolean isConcurrentUpdateException(Throwable t)
public void performAdditionalStatements(Connection connection) throws SQLException
SQLException
public String getValidationQuery()
The query should throw an error if the connection is dead.
public String getBlobLengthFunction()
public void performPostOpenStatements(Connection connection) throws SQLException
SQLException
public List<String> getPostCreateIdentityColumnSql(Column column)
Oracle needs both a sequence and a trigger.
public boolean isIdentityAlreadyPrimary()
MySQL defines the identity column directly as primary key.
public boolean hasIdentityGeneratedKey()
Oracle needs a separate call to CURRVAL.
public String getIdentityGeneratedKeySql(Column column)
Oracle needs a separate call to CURRVAL.
public String getAncestorsIdsSql()
public String getDescending()
public List<String> getIgnoredColumns(Table table)
public String getCustomColumnDefinition(Table table)
public List<String> getCustomPostCreateSqls(Table table, Model model)
public String getSoftDeleteSql()
public String getSoftDeleteCleanupSql()
public String getBinaryFulltextSql(List<String> columns)
public abstract List<String> checkStoredProcedure(String procName, String procCreate, String ddlMode, Connection connection, JDBCLogger logger, Map<String,Serializable> properties) throws SQLException
There are 3 cases to deal with, and actions to perform:
When there is nothing to do, null
is returned. Otherwise the returned value is a list of SQL statements
to execute. Note that the SQL statements will include also INSERT statements to be executed to remember the
creation SQL itself.
procName
- the stored procedure nameprocCreate
- the creation SQL for the stored procedureddlMode
- the DDL modeconnection
- the connectionlogger
- the loggerproperties
- the statement execution propertiesSQLException
public Collection<? extends String> getDumpStart()
public Collection<? extends String> getDumpStop()
public String getSQLForDump(String sql)
public boolean supportsBatchUpdateCount()
Copyright © 2018 Nuxeo. All rights reserved.