Class SQLServerPlatform

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

    public class SQLServerPlatform
    extends DatabasePlatform

    Purpose: Provides SQL Server specific behavior.

    Responsibilities:

    • Native SQL for byte[], Date, Time, & Timestamp.
    • Native sequencing using @@IDENTITY.
    Since:
    TOPLink/Java 1.0
    See Also:
    Serialized Form
    • Constructor Detail

      • SQLServerPlatform

        public SQLServerPlatform()
    • Method Detail

      • initializeConnectionData

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

        public void setDriverSupportsOffsetDateTime​(boolean driverSupportsOffsetDateTime)
        Allow user to turn off ODT support, in case they rely on the old behavior.
      • appendByteArray

        protected void appendByteArray​(byte[] bytes,
                                       java.io.Writer writer)
                                throws java.io.IOException
        If using native SQL then print a byte[] as '0xFF...'
        Overrides:
        appendByteArray in class DatabasePlatform
        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. Native format: 'yyyy-mm-dd
        Overrides:
        appendDate in class DatabasePlatform
        Throws:
        java.io.IOException
      • appendSybaseTimestamp

        protected void appendSybaseTimestamp​(java.sql.Timestamp timestamp,
                                             java.io.Writer writer)
                                      throws java.io.IOException
        Write a timestamp in Sybase specific format ( yyyy-mm-dd-hh.mm.ss.fff)
        Throws:
        java.io.IOException
      • appendSybaseCalendar

        protected void appendSybaseCalendar​(java.util.Calendar calendar,
                                            java.io.Writer writer)
                                     throws java.io.IOException
        Write a timestamp in Sybase specific format ( yyyy-mm-dd-hh.mm.ss.fff)
        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'}.
        Overrides:
        appendTime in class DatabasePlatform
        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 date is printed in the ODBC platform independent format {d'YYYY-MM-DD'}.
        Overrides:
        appendTimestamp in class DatabasePlatform
        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, suitable for SQL generation. The date is printed in the ODBC platform independent format {d'YYYY-MM-DD'}.
        Overrides:
        appendCalendar in class DatabasePlatform
        Throws:
        java.io.IOException
      • buildFieldTypes

        protected java.util.Hashtable buildFieldTypes()
        Description copied from class: DatabasePlatform
        Return the mapping of class types to database types for the schema framework.
        Overrides:
        buildFieldTypes in class DatabasePlatform
      • buildSelectQueryForSequenceObject

        public ValueReadQuery buildSelectQueryForSequenceObject​(java.lang.String qualifiedSeqName,
                                                                java.lang.Integer size)
        INTERNAL: Produce a DataReadQuery which updates(!) the sequence number in the database and returns it.
        Overrides:
        buildSelectQueryForSequenceObject in class DatasourcePlatform
        Parameters:
        qualifiedSeqName - a defined database sequence
      • dontBindUpdateAllQueryUsingTempTables

        public boolean dontBindUpdateAllQueryUsingTempTables()
        INTERNAL: In SQLServer local temporary table created by one PreparedStatement can't be used in another PreparedStatement. Workaround is to use Statement instead of PreparedStatement.
        Overrides:
        dontBindUpdateAllQueryUsingTempTables in class DatabasePlatform
      • getCreationInOutputProcedureToken

        public java.lang.String getCreationInOutputProcedureToken()
        This method is used to print the required output parameter token for the specific platform. Used when stored procedures are created.
        Overrides:
        getCreationInOutputProcedureToken in class DatabasePlatform
      • getCreationOutputProcedureToken

        public java.lang.String getCreationOutputProcedureToken()
        This method is used to print the required output parameter token for the specific platform. Used when stored procedures are created.
        Overrides:
        getCreationOutputProcedureToken in class DatabasePlatform
      • getInOutputProcedureToken

        public java.lang.String getInOutputProcedureToken()
        This method is used to print the output parameter token when stored procedures are called
        Overrides:
        getInOutputProcedureToken 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
      • getNativeTableInfo

        public java.util.Vector getNativeTableInfo​(java.lang.String table,
                                                   java.lang.String creator,
                                                   AbstractSession session)
        Return the catalog information through using the native SQL catalog selects. This is required because many JDBC driver do not support meta-data. Willcards can be passed as arguments.
      • getOutputProcedureToken

        public java.lang.String getOutputProcedureToken()
        This method is used to print the output parameter token when stored procedures are called
        Overrides:
        getOutputProcedureToken in class DatabasePlatform
      • getSelectForUpdateString

        public java.lang.String getSelectForUpdateString()
        INTERNAL: Lock. UPDLOCK seems like the correct table hint to use: HOLDLOCK is too weak - doesn't lock out another read with HOLDLOCK, XLOCK is too strong - locks out another read which doesn't use any locks. UPDLOCK seems to behave exactly like Oracle's FOR UPDATE: locking out updates and other reads with FOR UPDATE but allowing other reads without locks. SQLServer seems to decide itself on the granularity of the lock - it could lock more than the returned rows (for instance a page). It could be forced to obtain to make sure to obtain row level lock: WITH (UPDLOCK, ROWLOCK) However this approach is strongly discouraged because it can consume too much resources: selecting 900 rows from and requiring a "personal" lock for each row may not be feasible because of not enough memory available at the moment - in that case SQLServer will wait until the resource becomes available.
        Overrides:
        getSelectForUpdateString in class DatabasePlatform
      • shouldPrintLockingClauseAfterWhereClause

        public boolean shouldPrintLockingClauseAfterWhereClause()
        INTERNAL: Indicates whether locking clause should be printed after where clause by SQLSelectStatement. Example: on Oracle platform (method returns true): SELECT ADDRESS_ID, ... FROM ADDRESS WHERE (ADDRESS_ID = ?) FOR UPDATE on SQLServer platform (method returns false): SELECT ADDRESS_ID, ... FROM ADDRESS WITH (UPDLOCK) WHERE (ADDRESS_ID = ?)
        Overrides:
        shouldPrintLockingClauseAfterWhereClause in class DatabasePlatform
      • extractOperator

        protected static ExpressionOperator extractOperator()
        INTERNAL: Derby does not support EXTRACT, but does have DATEPART.
      • trimOperator

        protected static ExpressionOperator trimOperator()
        INTERNAL: Use RTRIM(LTRIM(?)) function for trim.
      • trim2Operator

        protected static ExpressionOperator trim2Operator()
        INTERNAL: Build Trim operator.
      • modOperator

        protected ExpressionOperator modOperator()
        Override the default MOD operator.
      • singleArgumentSubstringOperator

        protected static ExpressionOperator singleArgumentSubstringOperator()
        Override the default SubstringSingleArg operator.
      • locate2Operator

        protected static ExpressionOperator locate2Operator()
        INTERNAL: create the Locate2 Operator for this platform
      • addMonthsOperator

        protected static ExpressionOperator addMonthsOperator()
        INTERNAL: Function, to add months to a date.
      • inStringOperator

        protected static ExpressionOperator inStringOperator()
        INTERNAL: Build instring operator
      • toNumberOperator

        protected static ExpressionOperator toNumberOperator()
        INTERNAL: Build Sybase equivalent to TO_NUMBER.
      • toDateToStringOperator

        protected static ExpressionOperator toDateToStringOperator()
        INTERNAL: Build Sybase equivalent to TO_CHAR.
      • toDateOperator

        protected static ExpressionOperator toDateOperator()
        INTERNAL: Build Sybase equivalent to TO_DATE.
      • toCharOperator

        protected static ExpressionOperator toCharOperator()
        INTERNAL: Build Sybase equivalent to TO_CHAR.
      • locateOperator

        protected static ExpressionOperator locateOperator()
        INTERNAL: Build the Sybase equivalent to Locate
      • isOutputAllowWithResultSet

        public boolean isOutputAllowWithResultSet()
        INTERNAL: Return true if output parameters can be built with result sets.
        Overrides:
        isOutputAllowWithResultSet in class DatabasePlatform
      • maximumNumericValues

        public java.util.Hashtable maximumNumericValues()
        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 java.util.Hashtable minimumNumericValues()
        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
      • shouldPrintOutputTokenBeforeType

        public boolean shouldPrintOutputTokenBeforeType()
        This is required in the construction of the stored procedures with output parameters
        Overrides:
        shouldPrintOutputTokenBeforeType in class DatabasePlatform
      • shouldUseJDBCOuterJoinSyntax

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

        public boolean supportsIdentity()
        INTERNAL: Indicates whether the platform supports identity. SQLServer does through IDENTITY field types. This method is to be used *ONLY* by sequencing classes
        Overrides:
        supportsIdentity in class DatasourcePlatform
      • writeUpdateOriginalFromTempTableSql

        public void writeUpdateOriginalFromTempTableSql​(java.io.Writer writer,
                                                        DatabaseTable table,
                                                        java.util.Collection pkFields,
                                                        java.util.Collection assignedFields)
                                                 throws java.io.IOException
        INTERNAL:
        Overrides:
        writeUpdateOriginalFromTempTableSql in class DatabasePlatform
        Throws:
        java.io.IOException
      • getObjectFromResultSet

        public java.lang.Object getObjectFromResultSet​(java.sql.ResultSet resultSet,
                                                       int columnNumber,
                                                       int type,
                                                       AbstractSession session)
                                                throws java.sql.SQLException
        Description copied from class: DatabasePlatform
        INTERNAL: Get the object from the JDBC Result set. Added to allow other platforms to override.
        Overrides:
        getObjectFromResultSet in class DatabasePlatform
        Throws:
        java.sql.SQLException
        See Also:
        org.eclipse.persistence.oraclespecific.Oracle9Platform
      • setParameterValueInDatabaseCall

        public void setParameterValueInDatabaseCall​(java.lang.Object parameter,
                                                    java.sql.PreparedStatement statement,
                                                    int index,
                                                    AbstractSession session)
                                             throws java.sql.SQLException
        Description copied from class: DatabasePlatform
        INTERNAL Set the parameter in the JDBC statement at the given index. This support a wide range of different parameter types, and is heavily optimized for common types.
        Overrides:
        setParameterValueInDatabaseCall in class DatabasePlatform
        Throws:
        java.sql.SQLException
      • setParameterValueInDatabaseCall

        public void setParameterValueInDatabaseCall​(java.lang.Object parameter,
                                                    java.sql.CallableStatement statement,
                                                    java.lang.String name,
                                                    AbstractSession session)
                                             throws java.sql.SQLException
        Description copied from class: DatabasePlatform
        INTERNAL Set the parameter in the JDBC statement with the given name. This support a wide range of different parameter types, and is heavily optimized for common types.
        Overrides:
        setParameterValueInDatabaseCall in class DatabasePlatform
        Throws:
        java.sql.SQLException