- java.lang.Object
-
- io.ebean.config.dbplatform.DatabasePlatform
-
public class DatabasePlatform extends Object
Database platform specific settings.
-
-
Field Summary
Fields Modifier and Type Field Description protected booleanallQuotedIdentifiersWhen set to true all db column names and table names use quoted identifiers.protected BasicSqlLimiterbasicSqlLimiterLimit/offset support for SqlQuery only.protected intblobDbTypeThe JDBC type to map Blob to.protected intbooleanDbTypeThe JDBC type to map booleans to (by default).protected booleancaseSensitiveCollationprotected intclobDbTypeThe JDBC type to map Clob to.protected StringcloseQuoteThe close quote used by quoted identifiers.protected StringcolumnAliasPrefixprotected DbDefaultValuedbDefaultValueDefault values for DB columns.protected DbEncryptdbEncryptprotected DbIdentitydbIdentityDefines DB identity/sequence features.protected DbPlatformTypeMappingdbTypeMapMapping of JDBC to Database types.protected SqlExceptionTranslatorexceptionTranslatorprotected booleanforwardOnlyHintOnFindIterateIf set then use the FORWARD ONLY hint when creating ResultSets for findIterate() and findVisit().protected DbHistorySupporthistorySupportThe history support for this database platform.protected booleanidInExpandedFormprotected booleaninlineSqlUpdateLimitSet true if the Database support LIMIT clause on sql update.protected StringlikeClauseEscapedEscaped like clause for startsWith, endsWith and contains.protected StringlikeClauseRawThe non-escaped like clause (to stop slash being escaped on some platforms).protected charlikeEscapeCharEscape character used for startsWith, endsWith and contains.protected char[]likeSpecialCharactersCharacters escaped for startsWith, endsWith and contains.protected intmaxConstraintNameLengthA value of 60 is a reasonable default for all databases except Oracle (limited to 30) and DB2 (limited to 18).protected intmaxInBindingprotected intmaxTableNameLengthThe maximum length of table names - used specifically when derived default table names for intersection tables.protected booleannativeUuidTypeSet to true if the DB has native UUID type support.protected StringopenQuoteThe open quote used by quoted identifiers.protected io.ebean.annotation.PersistBatchpersistBatchOnCascadeBy default we use JDBC batch when cascading (except for SQL Server and HANA).protected io.ebean.annotation.PlatformplatformThe database platform name.protected booleanselectCountWithAliasprotected booleanselectCountWithColumnAliasprotected booleansequenceBatchModeprotected intsequenceBatchSizeprotected SqlLimitersqlLimiterFor limit/offset, row_number etc limiting of SQL queries.protected booleansupportsDeleteTableAliasprotected booleansupportsNativeIlikeprotected booleansupportsNativeJavaTimeCan we use native java time API objects inResultSet.getObject(int, Class)andPreparedStatement.setObject(int, Object).protected booleansupportsResultSetConcurrencyModeUpdatableIf set then use the CONCUR_UPDATABLE hint when creating ResultSets.protected booleansupportsSavepointIdprotected StringtruncateTableprotected booleanuseExtraTransactionOnIterateSecondaryQueriesSet to true for MySql, no other jdbc drivers need this workaround.protected booleanuseMigrationStoredProcedures
-
Constructor Summary
Constructors Constructor Description DatabasePlatform()Instantiates a new database platform.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddGeoTypes(int srid)BasicSqlLimiterbasicSqlLimiter()Return the BasicSqlLimiter for limit/offset of SqlQuery queries.intblobDbType()Return the data type that should be used for Blob.intbooleanDbType()Return the JDBC type used to store booleans.booleancaseSensitiveCollation()Return true if the collation is case-sensitive.intclobDbType()Return the data type that should be used for Clob.StringcloseQuote()Return the close quote for quoted identifiers.StringcolumnAliasPrefix()Return the column alias prefix.StringcompleteSql(String sql, Query<?> query)voidconfigure(PlatformConfig config)Configure the platform given the server configuration.protected voidconfigure(PlatformConfig config, boolean allQuotedIdentifiers)Configure UUID Storage etc based on DatabaseConfig settings.protected voidconfigureIdType(IdType idType)StringconvertQuotedIdentifiers(String dbName)Convert backticks to the platform specific open quote and close quotevoidcreateSchemaIfNotExists(String dbSchema, Connection connection)Create the DB schema if it does not exist.PlatformIdGeneratorcreateSequenceIdGenerator(BackgroundExecutor be, DataSource ds, int stepSize, String seqName)Return a DB Sequence based IdGenerator.DbDefaultValuedbDefaultValue()Return the mapping for DB column default values.DbEncryptdbEncrypt()Return the DbEncrypt handler for this DB platform.DbIdentitydbIdentity()Return the DB identity/sequence features for this platform.DbPlatformTypeMappingdbTypeMap()Return the mapping of JDBC to DB types.protected voidescapeLikeCharacter(char ch, StringBuilder sb)StringescapeLikeString(String value)Escapes the like string for this DB-PlatformbooleanforwardOnlyHintOnFindIterate()Return true if the ResultSet TYPE_FORWARD_ONLY Hint should be used on findIterate() and findVisit() PreparedStatements.StringfromForUpdate(Query.LockWait lockWait)For update hint on the FROM clause (SQL server only).DbHistorySupporthistorySupport()Return the history support for this database platform.booleanidInExpandedForm()Return true if a compound ID in (...) type expression needs to be in expanded form of (a=? and b=?) or (a=? and b=?) or ...booleaninlineSqlUpdateLimit()Return true if the platform supports LIMIT with sql update.booleanisPlatform(io.ebean.annotation.Platform platform)Return true if this matches the given platform.StringlikeClause(boolean rawLikeExpression)Returns the like clause used by this database platform.intmaxConstraintNameLength()Return the maximum constraint name allowed for the platform.intmaxInBinding()Return the maximum number of bind values this database platform allows or zero for no limit.intmaxTableNameLength()Return the maximum table name length.Stringname()Return the name of the underlying Platform in lowercase.booleannativeArrayType()So no except for Postgres and CockroachDB.booleannativeUuidType()Return true if the DB supports native UUID.StringopenQuote()Return the open quote for quoted identifiers.io.ebean.annotation.PersistBatchpersistBatchOnCascade()Return the platform default JDBC batch mode for persist cascade.io.ebean.annotation.Platformplatform()Return the platform key.booleanschemaExists(String dbSchema, Connection connection)Return true if the schema exists.booleanselectCountWithAlias()Set to true if select count against anonymous view requires an alias.booleanselectCountWithColumnAlias()Return true if select count with subquery needs column alias (SQL Server).booleansequenceBatchMode()Return true if we are using Sequence batch mode rather than STEP.voidsetColumnAliasPrefix(String columnAliasPrefix)Set the column alias prefix.voidsetDbEncrypt(DbEncrypt dbEncrypt)Set the DbEncrypt handler for this DB platform.voidsetDbFalseLiteral(String dbFalseLiteral)Set the DB FALSE literal (from the registered boolean ScalarType)voidsetDbTrueLiteral(String dbTrueLiteral)Set the DB TRUE literal (from the registered boolean ScalarType)voidsetForwardOnlyHintOnFindIterate(boolean forwardOnlyHintOnFindIterate)Set to true if the ResultSet TYPE_FORWARD_ONLY Hint should be used by default on findIterate PreparedStatements.voidsetHistorySupport(DbHistorySupport historySupport)Set the history support for this database platform.voidsetSequenceBatchMode(boolean sequenceBatchMode)Set to false to not use sequence batch mode but instead STEP mode.voidsetSupportsResultSetConcurrencyModeUpdatable(boolean supportsResultSetConcurrencyModeUpdatable)Set to true if the ResultSet CONCUR_UPDATABLE Hint should be used by default on createNativeSqlTree() PreparedStatements.voidsetUseMigrationStoredProcedures(boolean useMigrationStoredProcedures)SqlLimitersqlLimiter()Return the SqlLimiter used to apply additional sql around a query to limit its results.booleansupportsDeleteTableAlias()Return true if the platform supports delete statements with table alias.booleansupportsNativeIlike()Return true if this database platform supports native ILIKE expression.booleansupportsNativeJavaTime()booleansupportsResultSetConcurrencyModeUpdatable()Return true if the ResultSet CONCUR_UPDATABLE Hint should be used on createNativeSqlTree() PreparedStatements.booleansupportsSavepointId()Return true if the platform supports SavepointId values.javax.persistence.PersistenceExceptiontranslate(String message, SQLException e)Translate the SQLException into a specific persistence exception if possible.StringtruncateStatement(String table)Return a statement to truncate a table.StringunQuote(String dbName)Remove quoted identifier quotes from the table or column name if present.booleanuseExtraTransactionOnIterateSecondaryQueries()Return true if the JDBC driver does not allow additional queries to execute when a resultSet is being 'streamed' as is the case with findEach() etc.booleanuseMigrationStoredProcedures()Return true if migrations should use stored procedures.protected StringwithForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType)
-
-
-
Field Detail
-
useExtraTransactionOnIterateSecondaryQueries
protected boolean useExtraTransactionOnIterateSecondaryQueries
Set to true for MySql, no other jdbc drivers need this workaround.
-
supportsDeleteTableAlias
protected boolean supportsDeleteTableAlias
-
supportsSavepointId
protected boolean supportsSavepointId
-
useMigrationStoredProcedures
protected boolean useMigrationStoredProcedures
-
supportsNativeJavaTime
protected boolean supportsNativeJavaTime
Can we use native java time API objects inResultSet.getObject(int, Class)andPreparedStatement.setObject(int, Object).Not all drivers (DB2 e.g.) will support this.
-
openQuote
protected String openQuote
The open quote used by quoted identifiers.
-
closeQuote
protected String closeQuote
The close quote used by quoted identifiers.
-
allQuotedIdentifiers
protected boolean allQuotedIdentifiers
When set to true all db column names and table names use quoted identifiers.
-
caseSensitiveCollation
protected boolean caseSensitiveCollation
-
inlineSqlUpdateLimit
protected boolean inlineSqlUpdateLimit
Set true if the Database support LIMIT clause on sql update.
-
sqlLimiter
protected SqlLimiter sqlLimiter
For limit/offset, row_number etc limiting of SQL queries.
-
basicSqlLimiter
protected BasicSqlLimiter basicSqlLimiter
Limit/offset support for SqlQuery only.
-
dbTypeMap
protected DbPlatformTypeMapping dbTypeMap
Mapping of JDBC to Database types.
-
dbDefaultValue
protected DbDefaultValue dbDefaultValue
Default values for DB columns.
-
nativeUuidType
protected boolean nativeUuidType
Set to true if the DB has native UUID type support.
-
dbIdentity
protected DbIdentity dbIdentity
Defines DB identity/sequence features.
-
sequenceBatchMode
protected boolean sequenceBatchMode
-
sequenceBatchSize
protected int sequenceBatchSize
-
historySupport
protected DbHistorySupport historySupport
The history support for this database platform.
-
booleanDbType
protected int booleanDbType
The JDBC type to map booleans to (by default).
-
blobDbType
protected int blobDbType
The JDBC type to map Blob to.
-
clobDbType
protected int clobDbType
The JDBC type to map Clob to.
-
platform
protected io.ebean.annotation.Platform platform
The database platform name.
-
truncateTable
protected String truncateTable
-
columnAliasPrefix
protected String columnAliasPrefix
-
likeClauseRaw
protected String likeClauseRaw
The non-escaped like clause (to stop slash being escaped on some platforms). Used for the 'raw like' expression but not for startsWith, endsWith and contains expressions.
-
likeClauseEscaped
protected String likeClauseEscaped
Escaped like clause for startsWith, endsWith and contains.
-
likeEscapeChar
protected char likeEscapeChar
Escape character used for startsWith, endsWith and contains.
-
likeSpecialCharacters
protected char[] likeSpecialCharacters
Characters escaped for startsWith, endsWith and contains.
-
dbEncrypt
protected DbEncrypt dbEncrypt
-
idInExpandedForm
protected boolean idInExpandedForm
-
selectCountWithAlias
protected boolean selectCountWithAlias
-
selectCountWithColumnAlias
protected boolean selectCountWithColumnAlias
-
forwardOnlyHintOnFindIterate
protected boolean forwardOnlyHintOnFindIterate
If set then use the FORWARD ONLY hint when creating ResultSets for findIterate() and findVisit().
-
supportsResultSetConcurrencyModeUpdatable
protected boolean supportsResultSetConcurrencyModeUpdatable
If set then use the CONCUR_UPDATABLE hint when creating ResultSets.This is
falsefor HANA
-
persistBatchOnCascade
protected io.ebean.annotation.PersistBatch persistBatchOnCascade
By default we use JDBC batch when cascading (except for SQL Server and HANA).
-
maxInBinding
protected int maxInBinding
-
maxTableNameLength
protected int maxTableNameLength
The maximum length of table names - used specifically when derived default table names for intersection tables.
-
maxConstraintNameLength
protected int maxConstraintNameLength
A value of 60 is a reasonable default for all databases except Oracle (limited to 30) and DB2 (limited to 18).
-
supportsNativeIlike
protected boolean supportsNativeIlike
-
exceptionTranslator
protected SqlExceptionTranslator exceptionTranslator
-
-
Method Detail
-
translate
public javax.persistence.PersistenceException translate(String message, SQLException e)
Translate the SQLException into a specific persistence exception if possible.
-
configure
public void configure(PlatformConfig config)
Configure the platform given the server configuration.
-
configure
protected void configure(PlatformConfig config, boolean allQuotedIdentifiers)
Configure UUID Storage etc based on DatabaseConfig settings.
-
configureIdType
protected void configureIdType(IdType idType)
-
addGeoTypes
protected void addGeoTypes(int srid)
-
isPlatform
public boolean isPlatform(io.ebean.annotation.Platform platform)
Return true if this matches the given platform.
-
platform
public io.ebean.annotation.Platform platform()
Return the platform key.
-
name
public String name()
Return the name of the underlying Platform in lowercase."generic" is returned when no specific database platform has been set or found.
-
sequenceBatchMode
public boolean sequenceBatchMode()
Return true if we are using Sequence batch mode rather than STEP.
-
setSequenceBatchMode
public void setSequenceBatchMode(boolean sequenceBatchMode)
Set to false to not use sequence batch mode but instead STEP mode.
-
supportsNativeIlike
public boolean supportsNativeIlike()
Return true if this database platform supports native ILIKE expression.
-
supportsDeleteTableAlias
public boolean supportsDeleteTableAlias()
Return true if the platform supports delete statements with table alias.
-
caseSensitiveCollation
public boolean caseSensitiveCollation()
Return true if the collation is case-sensitive.This is expected to be used for testing only.
-
supportsSavepointId
public boolean supportsSavepointId()
Return true if the platform supports SavepointId values.
-
useMigrationStoredProcedures
public boolean useMigrationStoredProcedures()
Return true if migrations should use stored procedures.
-
inlineSqlUpdateLimit
public boolean inlineSqlUpdateLimit()
Return true if the platform supports LIMIT with sql update.
-
maxInBinding
public int maxInBinding()
Return the maximum number of bind values this database platform allows or zero for no limit.
-
maxTableNameLength
public int maxTableNameLength()
Return the maximum table name length.This is used when deriving names of intersection tables.
-
maxConstraintNameLength
public int maxConstraintNameLength()
Return the maximum constraint name allowed for the platform.
-
useExtraTransactionOnIterateSecondaryQueries
public boolean useExtraTransactionOnIterateSecondaryQueries()
Return true if the JDBC driver does not allow additional queries to execute when a resultSet is being 'streamed' as is the case with findEach() etc.Honestly, this is a workaround for a stupid MySql JDBC driver limitation.
-
createSequenceIdGenerator
public PlatformIdGenerator createSequenceIdGenerator(BackgroundExecutor be, DataSource ds, int stepSize, String seqName)
Return a DB Sequence based IdGenerator.- Parameters:
be- the BackgroundExecutor that can be used to load the sequence if desiredds- the DataSourcestepSize- the sequence allocation size as defined by mapping (defaults to 50)seqName- the name of the sequence
-
dbEncrypt
public DbEncrypt dbEncrypt()
Return the DbEncrypt handler for this DB platform.
-
setDbEncrypt
public void setDbEncrypt(DbEncrypt dbEncrypt)
Set the DbEncrypt handler for this DB platform.
-
historySupport
public DbHistorySupport historySupport()
Return the history support for this database platform.
-
setHistorySupport
public void setHistorySupport(DbHistorySupport historySupport)
Set the history support for this database platform.
-
nativeArrayType
public boolean nativeArrayType()
So no except for Postgres and CockroachDB.
-
nativeUuidType
public boolean nativeUuidType()
Return true if the DB supports native UUID.
-
dbTypeMap
public DbPlatformTypeMapping dbTypeMap()
Return the mapping of JDBC to DB types.- Returns:
- the db type map
-
dbDefaultValue
public DbDefaultValue dbDefaultValue()
Return the mapping for DB column default values.
-
columnAliasPrefix
public String columnAliasPrefix()
Return the column alias prefix.
-
setColumnAliasPrefix
public void setColumnAliasPrefix(String columnAliasPrefix)
Set the column alias prefix.
-
closeQuote
public String closeQuote()
Return the close quote for quoted identifiers.
-
openQuote
public String openQuote()
Return the open quote for quoted identifiers.
-
booleanDbType
public int booleanDbType()
Return the JDBC type used to store booleans.
-
blobDbType
public int blobDbType()
Return the data type that should be used for Blob.This is typically Types.BLOB but for Postgres is Types.LONGVARBINARY for example.
-
clobDbType
public int clobDbType()
Return the data type that should be used for Clob.This is typically Types.CLOB but for Postgres is Types.VARCHAR.
-
idInExpandedForm
public boolean idInExpandedForm()
Return true if a compound ID in (...) type expression needs to be in expanded form of (a=? and b=?) or (a=? and b=?) or ... rather than (a,b) in ((?,?),(?,?),...);
-
forwardOnlyHintOnFindIterate
public boolean forwardOnlyHintOnFindIterate()
Return true if the ResultSet TYPE_FORWARD_ONLY Hint should be used on findIterate() and findVisit() PreparedStatements.This specifically is required for MySql when processing large results.
-
setForwardOnlyHintOnFindIterate
public void setForwardOnlyHintOnFindIterate(boolean forwardOnlyHintOnFindIterate)
Set to true if the ResultSet TYPE_FORWARD_ONLY Hint should be used by default on findIterate PreparedStatements.
-
supportsResultSetConcurrencyModeUpdatable
public boolean supportsResultSetConcurrencyModeUpdatable()
Return true if the ResultSet CONCUR_UPDATABLE Hint should be used on createNativeSqlTree() PreparedStatements.This specifically is required for Hana which doesn't support CONCUR_UPDATABLE
-
setSupportsResultSetConcurrencyModeUpdatable
public void setSupportsResultSetConcurrencyModeUpdatable(boolean supportsResultSetConcurrencyModeUpdatable)
Set to true if the ResultSet CONCUR_UPDATABLE Hint should be used by default on createNativeSqlTree() PreparedStatements.
-
setUseMigrationStoredProcedures
public void setUseMigrationStoredProcedures(boolean useMigrationStoredProcedures)
-
dbIdentity
public DbIdentity dbIdentity()
Return the DB identity/sequence features for this platform.- Returns:
- the db identity
-
sqlLimiter
public SqlLimiter sqlLimiter()
Return the SqlLimiter used to apply additional sql around a query to limit its results.Basically add the clauses for limit/offset, rownum, row_number().
- Returns:
- the sql limiter
-
basicSqlLimiter
public BasicSqlLimiter basicSqlLimiter()
Return the BasicSqlLimiter for limit/offset of SqlQuery queries.
-
setDbTrueLiteral
public void setDbTrueLiteral(String dbTrueLiteral)
Set the DB TRUE literal (from the registered boolean ScalarType)
-
setDbFalseLiteral
public void setDbFalseLiteral(String dbFalseLiteral)
Set the DB FALSE literal (from the registered boolean ScalarType)
-
convertQuotedIdentifiers
public String convertQuotedIdentifiers(String dbName)
Convert backticks to the platform specific open quote and close quoteSpecific plugins may implement this method to cater for platform specific naming rules.
- Parameters:
dbName- the db table or column name- Returns:
- the db table or column name with potentially platform specific quoted identifiers
-
unQuote
public String unQuote(String dbName)
Remove quoted identifier quotes from the table or column name if present.
-
selectCountWithAlias
public boolean selectCountWithAlias()
Set to true if select count against anonymous view requires an alias.
-
selectCountWithColumnAlias
public boolean selectCountWithColumnAlias()
Return true if select count with subquery needs column alias (SQL Server).
-
fromForUpdate
public String fromForUpdate(Query.LockWait lockWait)
For update hint on the FROM clause (SQL server only).
-
withForUpdate
protected String withForUpdate(String sql, Query.LockWait lockWait, Query.LockType lockType)
-
likeClause
public String likeClause(boolean rawLikeExpression)
Returns the like clause used by this database platform.This may include an escape clause to disable a default escape character.
-
persistBatchOnCascade
public io.ebean.annotation.PersistBatch persistBatchOnCascade()
Return the platform default JDBC batch mode for persist cascade.
-
truncateStatement
public String truncateStatement(String table)
Return a statement to truncate a table.
-
createSchemaIfNotExists
public void createSchemaIfNotExists(String dbSchema, Connection connection) throws SQLException
Create the DB schema if it does not exist.- Throws:
SQLException
-
schemaExists
public boolean schemaExists(String dbSchema, Connection connection) throws SQLException
Return true if the schema exists.- Throws:
SQLException
-
escapeLikeString
public String escapeLikeString(String value)
Escapes the like string for this DB-Platform
-
escapeLikeCharacter
protected void escapeLikeCharacter(char ch, StringBuilder sb)
-
supportsNativeJavaTime
public boolean supportsNativeJavaTime()
-
-