All Implemented Interfaces:
Serializable, Cloneable, CorePlatform<ConversionManager>, Platform
Direct Known Subclasses:
DB2MainframePlatform, DB2ZPlatform, DerbyPlatform

public class DB2Platform extends DatabasePlatform

Purpose: Provides DB2 specific behavior.

Responsibilities:

  • Support for schema creation.
  • Native SQL for byte[], Date, Time, & Timestamp.
  • Support for table qualified names.
  • Support for stored procedures.
  • Support for temp tables.
  • Support for casting.
  • Support for database functions.
  • Support for identity sequencing.
  • Support for SEQUENCE sequencing.
Since:
TOPLink/Java 1.0
See Also:
  • Constructor Details

    • DB2Platform

      public DB2Platform()
  • Method Details

    • initializeConnectionData

      public void initializeConnectionData(Connection connection) throws SQLException
      Description copied from class: DatabasePlatform
      INTERNAL: Allow initialization from the connection.
      Overrides:
      initializeConnectionData in class DatabasePlatform
      Throws:
      SQLException
    • appendByteArray

      protected void appendByteArray(byte[] bytes, Writer writer) throws IOException
      INTERNAL: Append a byte[] in native DB@ format BLOB(hexString) if usesNativeSQL(), otherwise use ODBC format from DatabasePLatform.
      Overrides:
      appendByteArray in class DatabasePlatform
      Throws:
      IOException
    • appendDate

      protected void appendDate(Date date, Writer writer) throws IOException
      INTERNAL: Appends the Date in native format if usesNativeSQL() otherwise use ODBC format from DatabasePlatform. Native format: 'mm/dd/yyyy'
      Overrides:
      appendDate in class DatabasePlatform
      Throws:
      IOException
    • appendDB2Date

      protected void appendDB2Date(Date date, Writer writer) throws IOException
      INTERNAL: Write a timestamp in DB2 specific format (mm/dd/yyyy).
      Throws:
      IOException
    • appendDB2Timestamp

      protected void appendDB2Timestamp(Timestamp timestamp, Writer writer) throws IOException
      INTERNAL: Write a timestamp in DB2 specific format (yyyy-mm-dd-hh.mm.ss.ffffff).
      Throws:
      IOException
    • appendDB2Calendar

      protected void appendDB2Calendar(Calendar calendar, Writer writer) throws IOException
      Write a timestamp in DB2 specific format (yyyy-mm-dd-hh.mm.ss.ffffff).
      Throws:
      IOException
    • appendTime

      protected void appendTime(Time time, Writer writer) throws IOException
      INTERNAL: Append the Time in Native format if usesNativeSQL() otherwise use ODBC format from DAtabasePlatform. Native Format: 'hh:mm:ss'
      Overrides:
      appendTime in class DatabasePlatform
      Throws:
      IOException
    • appendTimestamp

      protected void appendTimestamp(Timestamp timestamp, Writer writer) throws IOException
      INTERNAL: Append the Timestamp in native format if usesNativeSQL() is true otherwise use ODBC format from DatabasePlatform. Native format: 'YYYY-MM-DD-hh.mm.ss.SSSSSS'
      Overrides:
      appendTimestamp in class DatabasePlatform
      Throws:
      IOException
    • appendCalendar

      protected void appendCalendar(Calendar calendar, Writer writer) throws IOException
      INTERNAL: Append the Timestamp in native format if usesNativeSQL() is true otherwise use ODBC format from DatabasePlatform. Native format: 'YYYY-MM-DD-hh.mm.ss.SSSSSS'
      Overrides:
      appendCalendar in class DatabasePlatform
      Throws:
      IOException
    • buildFieldTypes

      protected Hashtable<Class<?>,FieldTypeDefinition> buildFieldTypes()
      Description copied from class: DatabasePlatform
      Return the mapping of class types to database types for the schema framework.
      Overrides:
      buildFieldTypes in class DatabasePlatform
    • getMaxFieldNameSize

      public int getMaxFieldNameSize()
      INTERNAL: returns the maximum number of characters that can be used in a field name on this platform.
      Overrides:
      getMaxFieldNameSize in class DatabasePlatform
    • getMaxForeignKeyNameSize

      public int getMaxForeignKeyNameSize()
      INTERNAL: returns the maximum number of characters that can be used in a foreign key name on this platform.
      Overrides:
      getMaxForeignKeyNameSize in class DatabasePlatform
    • getMaxUniqueKeyNameSize

      public int getMaxUniqueKeyNameSize()
      INTERNAL: returns the maximum number of characters that can be used in a unique key name on this platform.
      Overrides:
      getMaxUniqueKeyNameSize in class DatabasePlatform
    • getNativeTableInfo

      public Vector getNativeTableInfo(String table, String creator, AbstractSession session)
      INTERNAL: Return the catalog information through using the native SQL catalog selects. This is required because many JDBC driver do not support meta-data. Wildcards can be passed as arguments. This is currently not used.
    • getProcedureCallHeader

      public String getProcedureCallHeader()
      INTERNAL: Used for sp calls.
      Overrides:
      getProcedureCallHeader in class DatabasePlatform
    • getSelectForUpdateString

      public String getSelectForUpdateString()
      INTERNAL: Used for pessimistic locking in DB2. Without the "WITH RS" the lock is not held.
      Overrides:
      getSelectForUpdateString in class DatabasePlatform
    • getProcedureEndString

      public String getProcedureEndString()
      INTERNAL: Used for stored procedure defs.
      Overrides:
      getProcedureEndString in class DatabasePlatform
    • getProcedureBeginString

      public String getProcedureBeginString()
      Used for stored procedure defs.
      Overrides:
      getProcedureBeginString in class DatabasePlatform
    • getProcedureAsString

      public String getProcedureAsString()
      INTERNAL: Used for stored procedure defs.
      Overrides:
      getProcedureAsString in class DatabasePlatform
    • getProcedureArgument

      public String getProcedureArgument(String name, Object parameter, DatasourceCall.ParameterType parameterType, StoredProcedureCall call, AbstractSession session)
      Obtain the platform specific argument string
      Overrides:
      getProcedureArgument in class DatabasePlatform
    • shouldPrintOutputTokenAtStart

      public boolean shouldPrintOutputTokenAtStart()
      INTERNAL: This is required in the construction of the stored procedures with output parameters.
      Overrides:
      shouldPrintOutputTokenAtStart in class DatabasePlatform
    • shouldBindPartialParameters

      public boolean shouldBindPartialParameters()
      Used to determine if the platform should perform partial parameter binding or not Enabled for DB2 and DB2 for zOS to add support for partial binding
      Overrides:
      shouldBindPartialParameters in class DatabasePlatform
    • getTimestampQuery

      public ValueReadQuery getTimestampQuery()
      INTERNAL: This method returns the query to select the timestamp from the server for DB2.
      Specified by:
      getTimestampQuery in interface Platform
      Overrides:
      getTimestampQuery in class DatasourcePlatform
    • initializePlatformOperators

      protected void initializePlatformOperators()
      INTERNAL: Initialize any platform-specific operators
      Overrides:
      initializePlatformOperators in class DatasourcePlatform
    • disableAllBindingExpression

      protected static ExpressionOperator disableAllBindingExpression()
      Create an ExpressionOperator that disables all parameter binding
    • disableAtLeast1BindingExpression

      protected static ExpressionOperator disableAtLeast1BindingExpression()
      Create an ExpressionOperator that requires at least 1 typed argument
    • ascendingOperator

      protected ExpressionOperator ascendingOperator()
      Disable binding support.

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X34: There is a ? parameter in the select list. This is not allowed.
    • descendingOperator

      protected ExpressionOperator descendingOperator()
      Disable binding support.

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X34: There is a ? parameter in the select list. This is not allowed.
    • concatOperator

      protected ExpressionOperator concatOperator()
      INTERNAL: The concat operator is of the form .... VARCHAR ( <operand1> || <operand2> )
    • count

      protected ExpressionOperator count()
      Disable binding support.

      With binding enabled, DB2 will throw an error:

      Db2 cannot determine how to implicitly cast the arguments between string and 
       numeric data types. DB2 SQL Error: SQLCODE=-245, SQLSTATE=428F5

      With binding enabled, DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X36: The 'COUNT' operator is not allowed to take a ? parameter as an operand.
    • max

      protected ExpressionOperator max()
      Disable binding support.

      With binding enabled, DB2 will throw an error:

      Db2 cannot determine how to implicitly cast the arguments between string and 
       numeric data types. DB2 SQL Error: SQLCODE=-245, SQLSTATE=428F5

      With binding enabled, DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X36: The 'MAX' operator is not allowed to take a ? parameter as an operand.
    • min

      protected ExpressionOperator min()
      Disable binding support.

      With binding enabled, DB2 will throw an error:

      Db2 cannot determine how to implicitly cast the arguments between string and 
       numeric data types. DB2 SQL Error: SQLCODE=-245, SQLSTATE=428F5

      With binding enabled, DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X36: The 'MIN' operator is not allowed to take a ? parameter as an operand.
    • distinct

      protected ExpressionOperator distinct()
      Disable binding support.

      With binding enabled, DB2 will throw an error:

      Db2 cannot determine how to implicitly cast the arguments between string and 
       numeric data types. DB2 SQL Error: SQLCODE=-245, SQLSTATE=428F5

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X34: There is a ? parameter in the select list.  This is not allowed.
    • caseOperator

      protected ExpressionOperator caseOperator()
      DB2 does not allow untyped parameter binding for the THEN & ELSE 'result-expressions' of CASE expressions

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610
      Examples of places where parameter markers cannot be used:
      • In a result-expression in any CASE expression when all the other result-expressions are either NULL or untyped parameter markers

      With binding enabled, Derby will throw an error:

      ERROR 42X87: At least one result expression (THEN or ELSE) of the CASE expression must have a known type.
    • caseConditionOperator

      protected ExpressionOperator caseConditionOperator()
      DB2 does not allow untyped parameter binding for the THEN & ELSE 'result-expressions' of CASE expressions

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610
      Examples of places where parameter markers cannot be used:
      • In a result-expression in any CASE expression when all the other result-expressions are either NULL or untyped parameter markers

      With binding enabled, Derby will throw an error:

      ERROR 42X87: At least one result expression (THEN or ELSE) of the CASE expression must have a known type.
    • lengthOperator

      protected ExpressionOperator lengthOperator()
      Disable binding support.

      With binding enabled, DB2 will throw an error:

      Db2 cannot determine how to implicitly cast the arguments between string and 
       numeric data types. DB2 SQL Error: SQLCODE=-245, SQLSTATE=428F5

      With binding enabled, DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X36: The 'length' operator is not allowed to take a ? parameter as an operand.
    • nullifOperator

      protected ExpressionOperator nullifOperator()
      DB2 requires that at least one argument be a known type

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, Derby will throw an error:

      ERROR 42X35: It is not allowed for both operands of '=' to be ? parameters.
    • coalesceOperator

      protected ExpressionOperator coalesceOperator()
      DB2 requires that at least one argument be a known type

      With binding enabled, DB2 will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      With binding enabled, DB2 z/OS will throw an error:

      The statement string specified as the object of a PREPARE contains a 
       predicate or expression where parameter markers have been used as operands of 
       the same operator—for example: ? > ?. DB2 SQL Error: SQLCODE=-417, SQLSTATE=42609

      With binding enabled, Derby will throw an error:

      ERROR 42610: All the arguments to the COALESCE/VALUE function cannot be parameters. The function needs at least one argument that is not a parameter.
    • trim2

      protected ExpressionOperator trim2()
      DB2 does not support untyped parameter binding for <operand2>

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610
    • ltrim2Operator

      protected ExpressionOperator ltrim2Operator()
      DB2 does not support untyped parameter binding for <operand2>

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610
    • rtrim2Operator

      protected ExpressionOperator rtrim2Operator()
      DB2 does not support untyped parameter binding for <operand2>

      With binding enabled, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610
    • roundOperator

      protected ExpressionOperator roundOperator()
      DB2 requires that at least one argument be a known type

      With binding enabled, DB2 will throw an error:

      Db2 cannot determine how to implicitly cast the arguments between string and 
       numeric data types. DB2 SQL Error: SQLCODE=-245, SQLSTATE=428F5
    • isDB2

      public boolean isDB2()
      Specified by:
      isDB2 in interface Platform
      Overrides:
      isDB2 in class DatasourcePlatform
    • maximumNumericValues

      public Hashtable<Class<? extends Number>,? super Number> maximumNumericValues()
      INTERNAL: Builds a table of maximum numeric values keyed on java class. This is used for type testing but might also be useful to end users attempting to sanitize values.

      NOTE: BigInteger & BigDecimal maximums are dependent upon their precision & Scale

      Overrides:
      maximumNumericValues in class DatabasePlatform
    • minimumNumericValues

      public Hashtable<Class<? extends Number>,? super Number> minimumNumericValues()
      INTERNAL: Builds a table of minimum numeric values keyed on java class. This is used for type testing but might also be useful to end users attempting to sanitize values.

      NOTE: BigInteger & BigDecimal minimums are dependent upon their precision & Scale

      Overrides:
      minimumNumericValues in class DatabasePlatform
    • shouldIgnoreException

      public boolean shouldIgnoreException(SQLException exception)
      INTERNAL: Allow for the platform to ignore exceptions. This is required for DB2 which throws no-data modified as an exception.
      Overrides:
      shouldIgnoreException in class DatabasePlatform
    • shouldUseJDBCOuterJoinSyntax

      public boolean shouldUseJDBCOuterJoinSyntax()
      INTERNAL: JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.
      Overrides:
      shouldUseJDBCOuterJoinSyntax in class DatabasePlatform
    • buildSelectQueryForIdentity

      public ValueReadQuery buildSelectQueryForIdentity()
      INTERNAL: Build the identity query for native sequencing.
      Overrides:
      buildSelectQueryForIdentity in class DatasourcePlatform
    • printFieldIdentityClause

      public void printFieldIdentityClause(Writer writer) throws ValidationException
      INTERNAL: Append the receiver's field 'identity' constraint clause to a writer. Used by table creation with sequencing.
      Overrides:
      printFieldIdentityClause in class DatabasePlatform
      Throws:
      ValidationException
    • printFieldTypeSize

      protected void printFieldTypeSize(Writer writer, FieldDefinition field, FieldTypeDefinition ftd) throws IOException
      Overrides:
      printFieldTypeSize in class DatabasePlatform
      Throws:
      IOException
    • supportsIdentity

      public boolean supportsIdentity()
      INTERNAL: Indicates whether the platform supports identity. DB2 does through AS IDENTITY field types. This is used by sequencing.
      Overrides:
      supportsIdentity in class DatasourcePlatform
    • supportsGlobalTempTables

      public boolean supportsGlobalTempTables()
      INTERNAL: DB2 supports temp tables. This is used by UpdateAllQuerys.
      Overrides:
      supportsGlobalTempTables in class DatabasePlatform
    • getCreateTempTableSqlPrefix

      protected String getCreateTempTableSqlPrefix()
      INTERNAL: DB2 temp table syntax. This is used by UpdateAllQuerys.
      Overrides:
      getCreateTempTableSqlPrefix in class DatabasePlatform
    • getTempTableForTable

      public DatabaseTable getTempTableForTable(DatabaseTable table)
      INTERNAL: DB2 temp table syntax. This is used by UpdateAllQuerys.
      Overrides:
      getTempTableForTable in class DatabasePlatform
      Parameters:
      table - is original table for which temp table is created.
      Returns:
      temporary table
    • getCreateTempTableSqlSuffix

      protected String getCreateTempTableSqlSuffix()
      INTERNAL: DB2 temp table syntax. This is used by UpdateAllQuerys.
      Overrides:
      getCreateTempTableSqlSuffix in class DatabasePlatform
    • getCreateTempTableSqlBodyForTable

      protected String getCreateTempTableSqlBodyForTable(DatabaseTable table)
      INTERNAL: DB2 allows LIKE to be used to create temp tables, which avoids having to know the types. This is used by UpdateAllQuerys.
      Overrides:
      getCreateTempTableSqlBodyForTable in class DatabasePlatform
      Parameters:
      table - is original table for which temp table is created.
      Returns:
      String
    • getNoWaitString

      public String getNoWaitString()
      INTERNAL: DB2 does not support NOWAIT.
      Overrides:
      getNoWaitString in class DatabasePlatform
    • dontBindUpdateAllQueryUsingTempTables

      public boolean dontBindUpdateAllQueryUsingTempTables()
      INTERNAL: DB2 has issues with binding with temp table queries. This is used by UpdateAllQuerys.
      Overrides:
      dontBindUpdateAllQueryUsingTempTables in class DatabasePlatform
    • isNullAllowedInSelectClause

      public boolean isNullAllowedInSelectClause()
      INTERNAL: DB2 does not allow NULL in select clause. This is used by UpdateAllQuerys.
      Overrides:
      isNullAllowedInSelectClause in class DatabasePlatform
    • isDynamicSQLRequiredForFunctions

      public boolean isDynamicSQLRequiredForFunctions()
      INTERNAL DB2 has some issues with using parameters on certain functions and relations. This allows statements to disable binding only in these cases. If users set casting on, then casting is used instead of dynamic SQL.
      Overrides:
      isDynamicSQLRequiredForFunctions in class DatabasePlatform
    • allowBindingForSelectClause

      public boolean allowBindingForSelectClause()
      INTERNAL: DB2 does not allow stand alone, untyped parameter markers in select clause.
      Overrides:
      allowBindingForSelectClause in class DatabasePlatform
      See Also:
    • writeParameterMarker

      public void writeParameterMarker(Writer writer, ParameterExpression parameter, AbstractRecord record, DatabaseCall call) throws IOException
      INTERNAL: DB2 requires casting on certain operations, such as the CONCAT function, and parameterized queries of the form, ":param = :param". This method will write CAST operation to parameters if the type is known. This is not used by default, only if isCastRequired is set to true, by default dynamic SQL is used to avoid the issue in only the required cases.
      Overrides:
      writeParameterMarker in class DatabasePlatform
      Throws:
      IOException
    • supportsLockingQueriesWithMultipleTables

      public boolean supportsLockingQueriesWithMultipleTables()
      INTERNAL: DB2 does not seem to allow FOR UPDATE on queries with multiple tables. This is only used by testing to exclude these tests.
      Overrides:
      supportsLockingQueriesWithMultipleTables in class DatabasePlatform
    • buildSelectQueryForSequenceObject

      public ValueReadQuery buildSelectQueryForSequenceObject(String qualifiedSeqName, Integer size)
      INTERNAL: DB2 added SEQUENCE support as of (I believe) v8.
      Overrides:
      buildSelectQueryForSequenceObject in class DatasourcePlatform
    • supportsSequenceObjects

      public boolean supportsSequenceObjects()
      INTERNAL: DB2 added SEQUENCE support as of (I believe) v8.
      Overrides:
      supportsSequenceObjects in class DatasourcePlatform
    • supportsOrderByParameters

      public boolean supportsOrderByParameters()
      DB2 disables single parameter usage in ORDER BY clause.

      If a parameter marker is used, DB2 & DB2 z/OS will throw an error:

      The statement cannot be executed because a parameter marker has been used 
       in an invalid way. DB2 SQL Error: SQLCODE=-418, SQLSTATE=42610

      If a parameter marker is used, Derby will throw an error:

      ERROR 42X34: There is a ? parameter in the select list.  This is not allowed.
      Overrides:
      supportsOrderByParameters in class DatabasePlatform
    • isAlterSequenceObjectSupported

      public boolean isAlterSequenceObjectSupported()
      INTERNAL: DB2 added SEQUENCE support as of (I believe) v8.
      Overrides:
      isAlterSequenceObjectSupported in class DatabasePlatform
    • shouldPrintForUpdateClause

      public boolean shouldPrintForUpdateClause()
      Overrides:
      shouldPrintForUpdateClause in class DatabasePlatform
    • printSQLSelectStatement

      public void printSQLSelectStatement(DatabaseCall call, ExpressionSQLPrinter printer, SQLSelectStatement statement)
      INTERNAL: Print the SQL representation of the statement on a stream, storing the fields in the DatabaseCall. This implementation works MaxRows and FirstResult into the SQL using DB2's ROWNUMBER() OVER() to filter values if shouldUseRownumFiltering is true.
      Overrides:
      printSQLSelectStatement in class DatabasePlatform