Class DatabasePlatform
- java.lang.Object
-
- io.ebean.config.dbplatform.DatabasePlatform
-
- Direct Known Subclasses:
BaseMySqlPlatform
,ClickHousePlatform
,DB2Platform
,H2Platform
,HanaPlatform
,HsqldbPlatform
,NuoDbPlatform
,OraclePlatform
,PostgresPlatform
,SqlAnywherePlatform
,SQLitePlatform
,SqlServer16Platform
,SqlServer17Platform
public class DatabasePlatform extends Object
Database platform specific settings.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DatabasePlatform.OnQueryOnly
Behavior used when ending a query only transaction (at read committed isolation level).
-
Constructor Summary
Constructors Constructor Description DatabasePlatform()
Instantiates a new database platform.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
completeSql(String sql, Query<?> query)
void
configure(PlatformConfig config)
Configure the platform given the server configuration.String
convertQuotedIdentifiers(String dbName)
Convert backticks to the platform specific open quote and close quotevoid
createSchemaIfNotExists(String dbSchema, Connection connection)
Create the DB schema if it does not exist.PlatformIdGenerator
createSequenceIdGenerator(BackgroundExecutor be, DataSource ds, int stepSize, String seqName)
Return a DB Sequence based IdGenerator.String
escapeLikeString(String value)
Escapes the like string for this DB-PlatformString
fromForUpdate(Query.LockWait lockWait)
For update hint on the FROM clause (SQL server only).BasicSqlLimiter
getBasicSqlLimiter()
Return the BasicSqlLimiter for limit/offset of SqlQuery queries.int
getBlobDbType()
Return the data type that should be used for Blob.int
getBooleanDbType()
Return the JDBC type used to store booleans.int
getClobDbType()
Return the data type that should be used for Clob.String
getCloseQuote()
Return the close quote for quoted identifiers.String
getColumnAliasPrefix()
Return the column alias prefix.DbDefaultValue
getDbDefaultValue()
Return the mapping for DB column default values.DbEncrypt
getDbEncrypt()
Return the DbEncrypt handler for this DB platform.DbIdentity
getDbIdentity()
Return the DB identity/sequence features for this platform.DbPlatformTypeMapping
getDbTypeMap()
Return the mapping of JDBC to DB types.DbHistorySupport
getHistorySupport()
Return the history support for this database platform.String
getLikeClause(boolean rawLikeExpression)
Returns the like clause used by this database platform.int
getMaxConstraintNameLength()
Return the maximum constraint name allowed for the platform.int
getMaxTableNameLength()
Return the maximum table name length.String
getName()
Return the name of the underlying Platform in lowercase.DatabasePlatform.OnQueryOnly
getOnQueryOnly()
Return the behaviour to use when ending a read only transaction.String
getOpenQuote()
Return the open quote for quoted identifiers.io.ebean.annotation.PersistBatch
getPersistBatchOnCascade()
Return the platform default JDBC batch mode for persist cascade.io.ebean.annotation.Platform
getPlatform()
Return the platform key.SqlLimiter
getSqlLimiter()
Return the SqlLimiter used to apply additional sql around a query to limit its results.boolean
isCaseSensitiveCollation()
Return true if the collation is case sensitive.boolean
isDdlAutoCommit()
Normally not needed - overridden in CockroachPlatform.boolean
isForwardOnlyHintOnFindIterate()
Return true if the ResultSet TYPE_FORWARD_ONLY Hint should be used on findIterate() and findVisit() PreparedStatements.boolean
isIdInExpandedForm()
Return true if a compound ID in (...) type expression needs to be in expanded form of (a=? and b=?) or (a=? and b=?) or ...boolean
isInlineSqlUpdateLimit()
Return true if the platform supports LIMIT with sql update.boolean
isNativeArrayType()
So no except for Postgres and CockroachDB.boolean
isNativeUuidType()
Return true if the DB supports native UUID.boolean
isPlatform(io.ebean.annotation.Platform platform)
Return true if this matches the given platform.boolean
isSelectCountWithAlias()
Set to true if select count against anonymous view requires an alias.boolean
isSelectCountWithColumnAlias()
Return true if select count with subquery needs column alias (SQL Server).boolean
isSequenceBatchMode()
Return true if we are using Sequence batch mode rather than STEP.boolean
isSupportsDeleteTableAlias()
Return true if the platform supports delete statements with table alias.boolean
isSupportsNativeIlike()
Return true if this database platform supports native ILIKE expression.boolean
isSupportsResultSetConcurrencyModeUpdatable()
Return true if the ResultSet CONCUR_UPDATABLE Hint should be used on createNativeSqlTree() PreparedStatements.boolean
isSupportsSavepointId()
Return true if the platform supports SavepointId values.boolean
isTreatEmptyStringsAsNull()
Return true if empty strings should be treated as null.boolean
schemaExists(String dbSchema, Connection connection)
Return true if the schema exists.void
setColumnAliasPrefix(String columnAliasPrefix)
Set the column alias prefix.void
setDbEncrypt(DbEncrypt dbEncrypt)
Set the DbEncrypt handler for this DB platform.void
setDbFalseLiteral(String dbFalseLiteral)
Set the DB FALSE literal (from the registered boolean ScalarType)void
setDbTrueLiteral(String dbTrueLiteral)
Set the DB TRUE literal (from the registered boolean ScalarType)void
setForwardOnlyHintOnFindIterate(boolean forwardOnlyHintOnFindIterate)
Set to true if the ResultSet TYPE_FORWARD_ONLY Hint should be used by default on findIterate PreparedStatements.void
setHistorySupport(DbHistorySupport historySupport)
Set the history support for this database platform.void
setOnQueryOnly(DatabasePlatform.OnQueryOnly onQueryOnly)
Set the behaviour to use when ending a read only transaction.void
setSequenceBatchMode(boolean sequenceBatchMode)
Set to false to not use sequence batch mode but instead STEP mode.void
setSupportsResultSetConcurrencyModeUpdatable(boolean supportsResultSetConcurrencyModeUpdatable)
Set to true if the ResultSet CONCUR_UPDATABLE Hint should be used by default on createNativeSqlTree() PreparedStatements.boolean
tableExists(Connection connection, String catalog, String schema, String table)
Return true if the table exists.String
tablePartitionInit(String tableName, io.ebean.annotation.PartitionMode mode, String property, String singlePrimaryKey)
Return the SQL to create an initial partition for the given table.boolean
tablePartitionsExist(Connection connection, String table)
Return true if partitions exist for the given table.javax.persistence.PersistenceException
translate(String message, SQLException e)
Translate the SQLException into a specific persistence exception if possible.String
truncateStatement(String table)
Return a statement to truncate a table.String
unQuote(String dbName)
Remove quoted identifier quotes from the table or column name if present.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.
-
-
-
Constructor Detail
-
DatabasePlatform
public DatabasePlatform()
Instantiates a new database platform.
-
-
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.
-
isPlatform
public boolean isPlatform(io.ebean.annotation.Platform platform)
Return true if this matches the given platform.
-
getPlatform
public io.ebean.annotation.Platform getPlatform()
Return the platform key.
-
getName
public String getName()
Return the name of the underlying Platform in lowercase."generic" is returned when no specific database platform has been set or found.
-
isSequenceBatchMode
public boolean isSequenceBatchMode()
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.
-
isSupportsNativeIlike
public boolean isSupportsNativeIlike()
Return true if this database platform supports native ILIKE expression.
-
isSupportsDeleteTableAlias
public boolean isSupportsDeleteTableAlias()
Return true if the platform supports delete statements with table alias.
-
isCaseSensitiveCollation
public boolean isCaseSensitiveCollation()
Return true if the collation is case sensitive.This is expected to be used for testing only.
-
isSupportsSavepointId
public boolean isSupportsSavepointId()
Return true if the platform supports SavepointId values.
-
isInlineSqlUpdateLimit
public boolean isInlineSqlUpdateLimit()
Return true if the platform supports LIMIT with sql update.
-
getMaxTableNameLength
public int getMaxTableNameLength()
Return the maximum table name length.This is used when deriving names of intersection tables.
-
getMaxConstraintNameLength
public int getMaxConstraintNameLength()
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
-
getOnQueryOnly
public DatabasePlatform.OnQueryOnly getOnQueryOnly()
Return the behaviour to use when ending a read only transaction.
-
setOnQueryOnly
public void setOnQueryOnly(DatabasePlatform.OnQueryOnly onQueryOnly)
Set the behaviour to use when ending a read only transaction.
-
getDbEncrypt
public DbEncrypt getDbEncrypt()
Return the DbEncrypt handler for this DB platform.
-
setDbEncrypt
public void setDbEncrypt(DbEncrypt dbEncrypt)
Set the DbEncrypt handler for this DB platform.
-
getHistorySupport
public DbHistorySupport getHistorySupport()
Return the history support for this database platform.
-
setHistorySupport
public void setHistorySupport(DbHistorySupport historySupport)
Set the history support for this database platform.
-
isNativeArrayType
public boolean isNativeArrayType()
So no except for Postgres and CockroachDB.
-
isNativeUuidType
public boolean isNativeUuidType()
Return true if the DB supports native UUID.
-
getDbTypeMap
public DbPlatformTypeMapping getDbTypeMap()
Return the mapping of JDBC to DB types.- Returns:
- the db type map
-
getDbDefaultValue
public DbDefaultValue getDbDefaultValue()
Return the mapping for DB column default values.
-
getColumnAliasPrefix
public String getColumnAliasPrefix()
Return the column alias prefix.
-
setColumnAliasPrefix
public void setColumnAliasPrefix(String columnAliasPrefix)
Set the column alias prefix.
-
getCloseQuote
public String getCloseQuote()
Return the close quote for quoted identifiers.
-
getOpenQuote
public String getOpenQuote()
Return the open quote for quoted identifiers.
-
getBooleanDbType
public int getBooleanDbType()
Return the JDBC type used to store booleans.
-
getBlobDbType
public int getBlobDbType()
Return the data type that should be used for Blob.This is typically Types.BLOB but for Postgres is Types.LONGVARBINARY for example.
-
getClobDbType
public int getClobDbType()
Return the data type that should be used for Clob.This is typically Types.CLOB but for Postgres is Types.VARCHAR.
-
isTreatEmptyStringsAsNull
public boolean isTreatEmptyStringsAsNull()
Return true if empty strings should be treated as null.- Returns:
- true, if checks if is treat empty strings as null
-
isIdInExpandedForm
public boolean isIdInExpandedForm()
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 ((?,?),(?,?),...);
-
isForwardOnlyHintOnFindIterate
public boolean isForwardOnlyHintOnFindIterate()
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.
-
isSupportsResultSetConcurrencyModeUpdatable
public boolean isSupportsResultSetConcurrencyModeUpdatable()
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.
-
isDdlAutoCommit
public boolean isDdlAutoCommit()
Normally not needed - overridden in CockroachPlatform.
-
getDbIdentity
public DbIdentity getDbIdentity()
Return the DB identity/sequence features for this platform.- Returns:
- the db identity
-
getSqlLimiter
public SqlLimiter getSqlLimiter()
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
-
getBasicSqlLimiter
public BasicSqlLimiter getBasicSqlLimiter()
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.
-
isSelectCountWithAlias
public boolean isSelectCountWithAlias()
Set to true if select count against anonymous view requires an alias.
-
isSelectCountWithColumnAlias
public boolean isSelectCountWithColumnAlias()
Return true if select count with subquery needs column alias (SQL Server).
-
completeSql
public String completeSql(String sql, Query<?> query)
-
fromForUpdate
public String fromForUpdate(Query.LockWait lockWait)
For update hint on the FROM clause (SQL server only).
-
getLikeClause
public String getLikeClause(boolean rawLikeExpression)
Returns the like clause used by this database platform.This may include an escape clause to disable a default escape character.
-
getPersistBatchOnCascade
public io.ebean.annotation.PersistBatch getPersistBatchOnCascade()
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
-
tableExists
public boolean tableExists(Connection connection, String catalog, String schema, String table) throws SQLException
Return true if the table exists.- Throws:
SQLException
-
tablePartitionsExist
public boolean tablePartitionsExist(Connection connection, String table) throws SQLException
Return true if partitions exist for the given table.- Throws:
SQLException
-
tablePartitionInit
public String tablePartitionInit(String tableName, io.ebean.annotation.PartitionMode mode, String property, String singlePrimaryKey)
Return the SQL to create an initial partition for the given table.
-
escapeLikeString
public String escapeLikeString(String value)
Escapes the like string for this DB-Platform
-
-