Class DatabasePlatform

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, CorePlatform<ConversionManager>, Platform
    Direct Known Subclasses:
    DatabasePlatform

    public class DatabasePlatform
    extends DatasourcePlatform
    DatabasePlatform is private to EclipseLink. It encapsulates behavior specific to a database platform (eg. Oracle, Sybase, DBase), and provides protocol for EclipseLink to access this behavior. The behavior categories which require platform specific handling are SQL generation and sequence behavior. While database platform currently provides sequence number retrieval behavior, this will move to a sequence manager (when it is implemented).
    Since:
    TOPLink/Java 1.0
    See Also:
    AccessPlatform, DB2Platform, DBasePlatform, OraclePlatform, SybasePlatform, Serialized Form
    • Field Detail

      • fieldTypes

        protected transient java.util.Map<java.lang.Class,​FieldTypeDefinition> fieldTypes
        Holds a map of values used to map JAVA types to database types for table creation
      • usesNativeSQL

        protected boolean usesNativeSQL
        Indicates that native SQL should be used for literal values instead of ODBC escape format Only used with Oracle, Sybase & DB2
      • usesByteArrayBinding

        protected boolean usesByteArrayBinding
        Indicates that binding will be used for BLOB data. NOTE: does not work well with ODBC.
      • usesBatchWriting

        protected boolean usesBatchWriting
        Batch all write statements
      • shouldBindAllParameters

        protected java.lang.Boolean shouldBindAllParameters
        Bind all arguments to any SQL statement.
      • shouldForceBindAllParameters

        protected boolean shouldForceBindAllParameters
        Bind all arguments to any SQL statement.
      • shouldBindPartialParameters

        protected boolean shouldBindPartialParameters
        Bind some arguments to any SQL statement.
      • shouldCacheAllStatements

        protected boolean shouldCacheAllStatements
        Cache all prepared statements, this requires full parameter binding as well.
      • statementCacheSize

        protected int statementCacheSize
        The statement cache size for prepare parameterized statements.
      • shouldForceFieldNamesToUpperCase

        protected boolean shouldForceFieldNamesToUpperCase
        Can be used if the app expects upper case but the database is not return consistent case, i.e. different databases.
      • shouldTrimStrings

        protected boolean shouldTrimStrings
        Indicates (if true) to remove blanks characters from the right of CHAR strings.
      • usesStreamsForBinding

        protected boolean usesStreamsForBinding
        Indicates that streams will be used to store BLOB data. NOTE: does not work with ODBC
      • stringBindingSize

        protected int stringBindingSize
        Indicates the size above which strings will be bound NOTE: does not work with ODBC
      • usesStringBinding

        protected boolean usesStringBinding
        Indicates that strings will above the stringBindingSize will be bound NOTE: does not work with ODBC
      • maxBatchWritingSize

        protected int maxBatchWritingSize
        Allow for the batch size to be set as many database have strict limits.
      • castSizeForVarcharParameter

        protected int castSizeForVarcharParameter
        used for casting of input parameters in certain DBs
      • usesJDBCBatchWriting

        protected boolean usesJDBCBatchWriting
        Allow for our batch writing support to be used in JDK 1.2.
      • usesNativeBatchWriting

        protected boolean usesNativeBatchWriting
        bug 4241441: Allow custom batch writing to enable batching with optimistic locking.
      • batchWritingMechanism

        protected BatchWritingMechanism batchWritingMechanism
        Allow for a custom batch writing mechanism.
      • printOuterJoinInWhereClause

        protected java.lang.Boolean printOuterJoinInWhereClause
        Allow configuration option to use Where clause outer joining or From clause joining.
      • printInnerJoinInWhereClause

        protected java.lang.Boolean printInnerJoinInWhereClause
        Allow configuration option to use Where clause joining or From clause joining.
      • cursorCode

        protected int cursorCode
        Allow for the code that is used for preparing cursored outs for a storedprocedure to be settable.
      • transactionIsolation

        protected int transactionIsolation
        The transaction isolation level to be set on the connection (optional).
      • supportsAutoCommit

        protected boolean supportsAutoCommit
        Some JDBC drivers do not support AutoCommit in the way EclipseLink expects. (e.g. Attunity Connect, JConnect)
      • shouldOptimizeDataConversion

        protected boolean shouldOptimizeDataConversion
        Allow for driver level data conversion optimization to be disabled, required because some drivers can loose precision.
      • classTypes

        protected transient java.util.Map<java.lang.String,​java.lang.Class> classTypes
        Stores mapping of class types to database types for schema creation.
      • shouldIgnoreCaseOnFieldComparisons

        public static boolean shouldIgnoreCaseOnFieldComparisons
        Allow for case in field names to be ignored as some databases are not case sensitive and when using custom this can be an issue.
      • DEFAULT_MAX_BATCH_WRITING_SIZE

        public static final int DEFAULT_MAX_BATCH_WRITING_SIZE
        Bug#3214927 The default is 32000 for DynamicSQLBatchWritingMechanism. It would become 100 when switched to ParameterizedSQLBatchWritingMechanism.
        See Also:
        Constant Field Values
      • DEFAULT_PARAMETERIZED_MAX_BATCH_WRITING_SIZE

        public static final int DEFAULT_PARAMETERIZED_MAX_BATCH_WRITING_SIZE
        See Also:
        Constant Field Values
      • IS_VALID_TIMEOUT

        public static final int IS_VALID_TIMEOUT
        Timeout used is isValid() check for dead connections.
        See Also:
        Constant Field Values
      • pingSQL

        protected java.lang.String pingSQL
        This attribute will store the SQL query that will be used to 'ping' the database connection in order to check the health of a connection.
      • structConverters

        protected java.util.Map<java.lang.String,​StructConverter> structConverters
        The following two maps, provide two ways of looking up StructConverters. They can be looked up by java Class or by Struct type
      • typeConverters

        protected java.util.Map<java.lang.Class,​StructConverter> typeConverters
      • useRownumFiltering

        protected boolean useRownumFiltering
        Some platforms allow a query's maxRows and FirstResult settings to be specified in SQL. This setting allows it to be enabled/disabled
      • isCastRequired

        protected boolean isCastRequired
        Allow platform specific cast to be enabled.
      • shouldBindLiterals

        protected boolean shouldBindLiterals
        Allow user to require literals to be bound.
      • tableCreationSuffix

        protected java.lang.String tableCreationSuffix
        String used on all table creation statements generated from the DefaultTableGenerator with a session using this project. This value will be appended to CreationSuffix strings stored within the DatabaseTable creationSuffix.
      • storedProcedureTerminationToken

        protected java.lang.String storedProcedureTerminationToken
        The delimiter between stored procedures in multiple stored procedure calls.
      • partitioningCallback

        protected DataPartitioningCallback partitioningCallback
        Used to integrate with data partitioning in an external DataSource such as UCP.
      • shouldCreateIndicesOnForeignKeys

        protected boolean shouldCreateIndicesOnForeignKeys
        Allows auto-indexing for foreign keys to be set.
      • useJDBCStoredProcedureSyntax

        protected java.lang.Boolean useJDBCStoredProcedureSyntax
      • driverName

        protected java.lang.String driverName
      • driverSupportsNationalCharacterVarying

        protected boolean driverSupportsNationalCharacterVarying
        True if the current jdbc driver supports get/setNString methods
      • useNationalCharacterVarying

        protected boolean useNationalCharacterVarying
        If true, the platform should map String columns to a type that supports national characters.
    • Constructor Detail

      • DatabasePlatform

        public DatabasePlatform()
        Creates an instance of default database platform.
    • Method Detail

      • hasPartitioningCallback

        public boolean hasPartitioningCallback()
        Check if has callback. Used to integrate with data partitioning in an external DataSource such as UCP.
      • getPartitioningCallback

        public DataPartitioningCallback getPartitioningCallback()
        Return callback. Used to integrate with data partitioning in an external DataSource such as UCP.
      • setPartitioningCallback

        public void setPartitioningCallback​(DataPartitioningCallback partitioningCallback)
        Set callback. Used to integrate with data partitioning in an external DataSource such as UCP.
      • isCastRequired

        public boolean isCastRequired()
        Return if casting is enabled for platforms that support it. Allow platform specific cast to be disabled.
      • setIsCastRequired

        public void setIsCastRequired​(boolean isCastRequired)
        Set if casting is enabled for platforms that support it. Allow platform specific cast to be disabled.
      • getStructConverters

        public java.util.Map<java.lang.String,​StructConverter> getStructConverters()
        INTERNAL: Get the map of StructConverters that will be used to preprocess STRUCT data as it is read
      • getTableCreationSuffix

        public java.lang.String getTableCreationSuffix()
        PUBLIC: Get the String used on all table creation statements generated from the DefaultTableGenerator with a session using this project (DDL generation). This value will be appended to CreationSuffix strings stored on the DatabaseTable or TableDefinition.
      • getTypeConverters

        public java.util.Map<java.lang.Class,​StructConverter> getTypeConverters()
        INTERNAL: Get the map of TypeConverters This map indexes StructConverters by the Java Class they are meant to convert
      • addStructConverter

        public void addStructConverter​(StructConverter converter)
        PUBLIC: Add a StructConverter to this DatabasePlatform This StructConverter will be invoked for all writes to the database for the class returned by its getJavaType() method and for all reads from the database for the Structs described by its getStructName() method
        Parameters:
        converter -
      • addBatch

        public int addBatch​(java.sql.PreparedStatement statement)
                     throws java.sql.SQLException
        INTERNAL: This gets called on each iteration to add parameters to the batch Needs to be implemented so that it returns the number of rows successfully modified by this statement for optimistic locking purposes (if useNativeBatchWriting is enabled, and the call uses optimistic locking). Is used with parameterized SQL
        Returns:
        - number of rows modified/deleted by this statement if it was executed (0 if it wasn't)
        Throws:
        java.sql.SQLException
      • allowsSizeInProcedureArguments

        public boolean allowsSizeInProcedureArguments()
        Used for stored procedure definitions.
      • appendBoolean

        protected void appendBoolean​(java.lang.Boolean bool,
                                     java.io.Writer writer)
                              throws java.io.IOException
        Appends a Boolean value as a number
        Throws:
        java.io.IOException
      • appendByteArray

        protected void appendByteArray​(byte[] bytes,
                                       java.io.Writer writer)
                                throws java.io.IOException
        Append the ByteArray in ODBC literal format ({b hexString}). This limits the amount of Binary data by the length of the SQL. Binding should increase this limit.
        Throws:
        java.io.IOException
      • appendDate

        protected void appendDate​(java.sql.Date date,
                                  java.io.Writer writer)
                           throws java.io.IOException
        Answer a platform correct string representation of a Date, suitable for SQL generation. The date is printed in the ODBC platform independent format {d 'yyyy-mm-dd'}.
        Throws:
        java.io.IOException
      • appendNumber

        protected void appendNumber​(java.lang.Number number,
                                    java.io.Writer writer)
                             throws java.io.IOException
        Write number to SQL string. This is provided so that database which do not support Exponential format can customize their printing.
        Throws:
        java.io.IOException
      • appendLiteralToCall

        public void appendLiteralToCall​(Call call,
                                        java.io.Writer writer,
                                        java.lang.Object literal,
                                        java.lang.Boolean canBind)
        INTERNAL: In case shouldBindLiterals is true, instead of null value a DatabaseField value may be passed (so that it's type could be used for binding null).
      • appendLiteralToCallWithBinding

        protected void appendLiteralToCallWithBinding​(Call call,
                                                      java.io.Writer writer,
                                                      java.lang.Object literal)
        INTERNAL: Override this method in case the platform needs to do something special for binding literals. Note that instead of null value a DatabaseField value may be passed (so that it's type could be used for binding null).
      • appendParameter

        public void appendParameter​(Call call,
                                    java.io.Writer writer,
                                    java.lang.Object parameter)
        Write a database-friendly representation of the given parameter to the writer. Determine the class of the object to be written, and invoke the appropriate print method for that object. The default is "toString". The platform may decide to bind some types, such as byte arrays and large strings. Should only be called in case binding is not used.
        Specified by:
        appendParameter in interface Platform
        Overrides:
        appendParameter in class DatasourcePlatform
      • appendParameterInternal

        public int appendParameterInternal​(Call call,
                                           java.io.Writer writer,
                                           java.lang.Object parameter)
        Returns the number of parameters that used binding. Should only be called in case binding is not used.
      • appendString

        protected void appendString​(java.lang.String string,
                                    java.io.Writer writer)
                             throws java.io.IOException
        Write the string. Quotes must be double quoted.
        Throws:
        java.io.IOException
      • appendTime

        protected void appendTime​(java.sql.Time time,
                                  java.io.Writer writer)
                           throws java.io.IOException
        Answer a platform correct string representation of a Time, suitable for SQL generation. The time is printed in the ODBC platform independent format {t'hh:mm:ss'}.
        Throws:
        java.io.IOException
      • appendTimestamp

        protected void appendTimestamp​(java.sql.Timestamp timestamp,
                                       java.io.Writer writer)
                                throws java.io.IOException
        Answer a platform correct string representation of a Timestamp, suitable for SQL generation. The timestamp is printed in the ODBC platform independent timestamp format {ts'YYYY-MM-DD HH:MM:SS.NNNNNNNNN'}.
        Throws:
        java.io.IOException
      • appendCalendar

        protected void appendCalendar​(java.util.Calendar calendar,
                                      java.io.Writer writer)
                               throws java.io.IOException
        Answer a platform correct string representation of a Calendar as a Timestamp, suitable for SQL generation. The calendar is printed in the ODBC platform independent timestamp format {ts'YYYY-MM-DD HH:MM:SS.NNNNNNNNN'}.
        Throws:
        java.io.IOException
      • autoCommit

        public void autoCommit​(DatabaseAccessor accessor)
                        throws java.sql.SQLException
        Used by JDBC drivers that do not support autocommit so simulate an autocommit.
        Throws:
        java.sql.SQLException
      • beginTransaction

        public void beginTransaction​(DatabaseAccessor accessor)
                              throws java.sql.SQLException
        Used for jdbc drivers which do not support autocommit to explicitly begin a transaction This method is a no-op for databases which implement autocommit as expected.
        Throws:
        java.sql.SQLException
      • buildBatchCriteriaForComplexId

        public Expression buildBatchCriteriaForComplexId​(ExpressionBuilder builder,
                                                         java.util.List<Expression> fields)
        INTERNAL: Return the selection criteria used to IN batch fetching.
      • buildCallWithReturning

        public DatabaseCall buildCallWithReturning​(SQLCall sqlCall,
                                                   java.util.Vector returnFields)
        INTERNAL Returns null unless the platform supports call with returning
      • buildClassTypes

        protected java.util.Map<java.lang.String,​java.lang.Class> buildClassTypes()
        Return the mapping of class types to database types for the schema framework.
      • buildFieldTypes

        protected java.util.Hashtable buildFieldTypes()
        Return the mapping of class types to database types for the schema framework.
      • shouldUseGetSetNString

        public boolean shouldUseGetSetNString()
        Returns true iff:
      • tThe current driver supports calling get/setNString
      • Strings are globally mapped to a national character varying type (useNationalCharacterVarying()).