FileDocCategorySizeDatePackage
SQLServerPlatform.javaAPI DocGlassfish v2 API22077Tue May 22 16:54:48 BST 2007oracle.toplink.essentials.platform.database

SQLServerPlatform

public class SQLServerPlatform extends DatabasePlatform

Purpose: Provides SQL Server specific behaviour.

Responsibilities:

  • Native SQL for byte[], Date, Time, & Timestamp.
since
TOPLink/Java 1.0

Fields Summary
Constructors Summary
Methods Summary
protected voidappendByteArray(byte[] bytes, java.io.Writer writer)
INTERNAL: If using native SQL then print a byte[] as '0xFF...'

        if (usesNativeSQL() && (!usesByteArrayBinding())) {
            writer.write("0x");
            Helper.writeHexString(bytes, writer);
        } else {
            super.appendByteArray(bytes, writer);
        }
    
protected voidappendCalendar(java.util.Calendar calendar, java.io.Writer writer)
INTERNAL: 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'}.

        if (usesNativeSQL()) {
            appendSybaseCalendar(calendar, writer);
        } else {
            super.appendCalendar(calendar, writer);
        }
    
protected voidappendDate(java.sql.Date date, java.io.Writer writer)
INTERNAL: Answer a platform correct string representation of a Date, suitable for SQL generation. Native format: 'yyyy-mm-dd

        if (usesNativeSQL()) {
            writer.write("'");
            writer.write(Helper.printDate(date));
            writer.write("'");
        } else {
            super.appendDate(date, writer);
        }
    
protected voidappendSybaseCalendar(java.util.Calendar calendar, java.io.Writer writer)
INTERNAL: Write a timestamp in Sybase specific format ( yyyy-mm-dd-hh.mm.ss.fff)

        writer.write("'");
        writer.write(Helper.printCalendar(calendar));
        writer.write("'");
    
protected voidappendSybaseTimestamp(java.sql.Timestamp timestamp, java.io.Writer writer)
INTERNAL: Write a timestamp in Sybase specific format ( yyyy-mm-dd-hh.mm.ss.fff)

        writer.write("'");
        writer.write(Helper.printTimestampWithoutNanos(timestamp));
        writer.write(':");

        // Must truncate the nanos to three decimal places,
        // it is actually a complex algorithm...
        String nanoString = Integer.toString(timestamp.getNanos());
        int numberOfZeros = 0;
        for (int num = Math.min(9 - nanoString.length(), 3); num > 0; num--) {
            writer.write('0");
            numberOfZeros++;
        }
        if ((nanoString.length() + numberOfZeros) > 3) {
            nanoString = nanoString.substring(0, (3 - numberOfZeros));
        }
        writer.write(nanoString);
        writer.write("'");
    
protected voidappendTime(java.sql.Time time, java.io.Writer writer)
INTERNAL: 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'}.

        if (usesNativeSQL()) {
            writer.write("'");
            writer.write(Helper.printTime(time));
            writer.write("'");
        } else {
            super.appendTime(time, writer);
        }
    
protected voidappendTimestamp(java.sql.Timestamp timestamp, java.io.Writer writer)
INTERNAL: 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'}.

        if (usesNativeSQL()) {
            appendSybaseTimestamp(timestamp, writer);
        } else {
            super.appendTimestamp(timestamp, writer);
        }
    
protected java.util.HashtablebuildFieldTypes()

        Hashtable fieldTypeMapping;

        fieldTypeMapping = new Hashtable();
        fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("BIT default 0", false));

        fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("INTEGER", false));
        fieldTypeMapping.put(Long.class, new FieldTypeDefinition("NUMERIC", 19));
        fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT(16)", false));
        fieldTypeMapping.put(Double.class, new FieldTypeDefinition("FLOAT(32)", false));
        fieldTypeMapping.put(Short.class, new FieldTypeDefinition("SMALLINT", false));
        fieldTypeMapping.put(Byte.class, new FieldTypeDefinition("SMALLINT", false));
        fieldTypeMapping.put(java.math.BigInteger.class, new FieldTypeDefinition("NUMERIC", 28));
        fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("NUMERIC", 28).setLimits(28, -19, 19));
        fieldTypeMapping.put(Number.class, new FieldTypeDefinition("NUMERIC", 28).setLimits(28, -19, 19));

        fieldTypeMapping.put(String.class, new FieldTypeDefinition("VARCHAR", 255));
        fieldTypeMapping.put(Character.class, new FieldTypeDefinition("CHAR", 1));
        
        fieldTypeMapping.put(Byte[].class, new FieldTypeDefinition("IMAGE", false));
        fieldTypeMapping.put(Character[].class, new FieldTypeDefinition("TEXT", false));
        fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("IMAGE", false));
        fieldTypeMapping.put(char[].class, new FieldTypeDefinition("TEXT", false));
        fieldTypeMapping.put(java.sql.Blob.class, new FieldTypeDefinition("IMAGE", false));
        fieldTypeMapping.put(java.sql.Clob.class, new FieldTypeDefinition("TEXT", false));
        
        fieldTypeMapping.put(java.sql.Date.class, new FieldTypeDefinition("DATETIME", false));
        fieldTypeMapping.put(java.sql.Time.class, new FieldTypeDefinition("DATETIME", false));
        fieldTypeMapping.put(java.sql.Timestamp.class, new FieldTypeDefinition("DATETIME", false));

        return fieldTypeMapping;
    
public oracle.toplink.essentials.queryframework.ValueReadQuerybuildSelectQueryForNativeSequence()
INTERNAL: Build the identity query for native sequencing.

        ValueReadQuery selectQuery = new ValueReadQuery();
        StringWriter writer = new StringWriter();
        writer.write("SELECT @@IDENTITY");
        selectQuery.setSQLString(writer.toString());
        return selectQuery;
    
public java.lang.StringgetBatchDelimiterString()
INTERNAL: Used for batch writing and sp defs.

        return "";
    
protected java.lang.StringgetCreateTempTableSqlPrefix()
INTERNAL:

        return "CREATE TABLE ";
    
public java.lang.StringgetCreationInOutputProcedureToken()
INTERNAL: This method is used to print the required output parameter token for the specific platform. Used when stored procedures are created.

        return getInOutputProcedureToken();
    
public java.lang.StringgetCreationOutputProcedureToken()
INTERNAL: This method is used to print the required output parameter token for the specific platform. Used when stored procedures are created.

        return "OUTPUT";
    
public java.lang.StringgetInOutputProcedureToken()
INTERNAL: This method is used to print the output parameter token when stored procedures are called

        return "OUT";
    
public intgetMaxFieldNameSize()
INTERNAL: returns the maximum number of characters that can be used in a field name on this platform.

        return 22;
    
public java.util.VectorgetNativeTableInfo(java.lang.String table, java.lang.String creator, oracle.toplink.essentials.internal.sessions.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. Willcards can be passed as arguments.

        // need to filter only tables / views
        String query = "SELECT * FROM sysobjects WHERE table_type <> 'SYSTEM_TABLE'";
        if (table != null) {
            if (table.indexOf('%") != -1) {
                query = query + " AND table_name LIKE " + table;
            } else {
                query = query + " AND table_name = " + table;
            }
        }
        if (creator != null) {
            if (creator.indexOf('%") != -1) {
                query = query + " AND table_owner LIKE " + creator;
            } else {
                query = query + " AND table_owner = " + creator;
            }
        }
        return session.executeSelectingCall(new SQLCall(query));
    
public java.lang.StringgetOutputProcedureToken()
INTERNAL: This method is used to print the output parameter token when stored procedures are called

        return "";
    
public java.lang.StringgetProcedureArgumentString()
INTERNAL: Used for sp defs.

        return "@";
    
public java.lang.StringgetProcedureCallHeader()
INTERNAL: Used for sp calls.

        return "EXECUTE ";
    
public java.lang.StringgetSelectForUpdateString()
INTERNAL:

        return " FOR UPDATE";
    
public java.lang.StringgetStoredProcedureParameterPrefix()
INTERNAL:

        return "@";
    
public java.lang.StringgetStoredProcedureTerminationToken()
INTERNAL: This method returns the delimiter between stored procedures in multiple stored procedure calls.

        return " go";
    
public oracle.toplink.essentials.internal.helper.DatabaseTablegetTempTableForTable(oracle.toplink.essentials.internal.helper.DatabaseTable table)
INTERNAL:

        return new DatabaseTable("#" + table.getName(), table.getTableQualifier());
    
public oracle.toplink.essentials.queryframework.ValueReadQuerygetTimestampQuery()
INTERNAL: This method returns the query to select the timestamp from the server for SQLServer.

        if (timestampQuery == null) {
            timestampQuery = new ValueReadQuery();
            timestampQuery.setSQLString("SELECT GETDATE()");
        }
        return timestampQuery;
    
protected voidinitializePlatformOperators()
INTERNAL: Initialize any platform-specific operators

        super.initializePlatformOperators();
        addOperator(operatorOuterJoin());
        addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.Today, "GETDATE"));
        // GETDATE returns both date and time. It is not the perfect match for 
        // ExpressionOperator.currentDate and ExpressionOperator.currentTime
        // However, there is no known function on sql server that returns just 
        // the date or just the time.
        addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.CurrentDate, "GETDATE"));
        addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.CurrentTime, "GETDATE"));
        addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.Length, "CHAR_LENGTH"));
        addOperator(ExpressionOperator.simpleThreeArgumentFunction(ExpressionOperator.Substring, "SUBSTRING"));
        addOperator(ExpressionOperator.addDate());
        addOperator(ExpressionOperator.dateName());
        addOperator(ExpressionOperator.datePart());
        addOperator(ExpressionOperator.dateDifference());
        addOperator(ExpressionOperator.difference());
        addOperator(ExpressionOperator.charIndex());
        addOperator(ExpressionOperator.charLength());
        addOperator(ExpressionOperator.reverse());
        addOperator(ExpressionOperator.replicate());
        addOperator(ExpressionOperator.right());
        addOperator(ExpressionOperator.cot());
        addOperator(ExpressionOperator.sybaseAtan2Operator());
        addOperator(ExpressionOperator.sybaseAddMonthsOperator());
        addOperator(ExpressionOperator.sybaseInStringOperator());
        // bug 3061144
        addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Nvl, "ISNULL"));
        // CR### TO_NUMBER, TO_CHAR, TO_DATE is CONVERT(type, ?)
        addOperator(ExpressionOperator.sybaseToNumberOperator());
        addOperator(ExpressionOperator.sybaseToDateToStringOperator());
        addOperator(ExpressionOperator.sybaseToDateOperator());
        addOperator(ExpressionOperator.sybaseToCharOperator());
        addOperator(ExpressionOperator.sybaseLocateOperator());
        addOperator(locate2Operator());
        addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.Ceil, "CEILING"));
        addOperator(ExpressionOperator.simpleFunction(ExpressionOperator.Length, "LEN"));
        addOperator(modOperator());
    
public booleanisSQLServer()

        return true;
    
public static oracle.toplink.essentials.expressions.ExpressionOperatorlocate2Operator()
INTERNAL: create the Locate2 Operator for this platform

        ExpressionOperator result = ExpressionOperator.simpleThreeArgumentFunction(ExpressionOperator.Locate2, "CHARINDEX");
        int[] argumentIndices = new int[3];
        argumentIndices[0] = 1;
        argumentIndices[1] = 0;
        argumentIndices[2] = 2;
        result.setArgumentIndices(argumentIndices);
        return result;
    
public java.util.HashtablemaximumNumericValues()
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

        Hashtable values = new Hashtable();

        values.put(Integer.class, new Integer(Integer.MAX_VALUE));
        values.put(Long.class, new Long(Long.MAX_VALUE));
        values.put(Double.class, new Double(0));
        values.put(Short.class, new Short(Short.MAX_VALUE));
        values.put(Byte.class, new Byte(Byte.MAX_VALUE));
        values.put(Float.class, new Float(0));
        values.put(java.math.BigInteger.class, new java.math.BigInteger("9999999999999999999999999999"));
        values.put(java.math.BigDecimal.class, new java.math.BigDecimal("999999999.9999999999999999999"));
        return values;
    
public java.util.HashtableminimumNumericValues()
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

        Hashtable values = new Hashtable();

        values.put(Integer.class, new Integer(Integer.MIN_VALUE));
        values.put(Long.class, new Long(Long.MIN_VALUE));
        values.put(Double.class, new Double((double)-9));
        values.put(Short.class, new Short(Short.MIN_VALUE));
        values.put(Byte.class, new Byte(Byte.MIN_VALUE));
        values.put(Float.class, new Float((float)-9));
        values.put(java.math.BigInteger.class, new java.math.BigInteger("-9999999999999999999999999999"));
        values.put(java.math.BigDecimal.class, new java.math.BigDecimal("-999999999.9999999999999999999"));
        return values;
    
public oracle.toplink.essentials.expressions.ExpressionOperatormodOperator()
INTERNAL: Override the default MOD operator.

        ExpressionOperator result = new ExpressionOperator();
        result.setSelector(ExpressionOperator.Mod);
        Vector v = new Vector();
        v.addElement(" % ");
        result.printsAs(v);
        result.bePostfix();
        result.setNodeClass(oracle.toplink.essentials.internal.expressions.FunctionExpression.class);
        return result;
    
protected oracle.toplink.essentials.expressions.ExpressionOperatoroperatorOuterJoin()
INTERNAL: Create the outer join operator for this platform.

        ExpressionOperator result = new ExpressionOperator();
        result.setSelector(ExpressionOperator.EqualOuterJoin);
        Vector v = new Vector();
        v.addElement(" =* ");
        result.printsAs(v);
        result.bePostfix();
        result.setNodeClass(RelationExpression.class);
        return result;
    
public voidprintFieldIdentityClause(java.io.Writer writer)
INTERNAL: Append the receiver's field 'identity' constraint clause to a writer.

        try {
            writer.write(" IDENTITY");
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
    
public voidprintFieldNullClause(java.io.Writer writer)
INTERNAL: Append the receiver's field 'NULL' constraint clause to a writer.

        try {
            writer.write(" NULL");
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
    
public booleanrequiresProcedureCallBrackets()
INTERNAL: Used for sp calls.

        return false;
    
public booleanrequiresProcedureCallOuputToken()
INTERNAL: Used for sp calls. Sybase must print output after output params.

        return true;
    
public booleanshouldNativeSequenceAcquireValueAfterInsert()
INTERNAL: If native sequencing is being used on Sybase then the values must be retrieved after the insert. This method is to be used *ONLY* by sequencing classes

        return true;
    
public booleanshouldPrintInOutputTokenBeforeType()
INTERNAL: This is required in the construction of the stored procedures with output parameters

        return false;
    
public booleanshouldPrintOuterJoinInWhereClause()
INTERNAL: Some database require outer joins to be given in the where clause, others require it in the from clause.

        return false;
    
public booleanshouldPrintOutputTokenBeforeType()
INTERNAL: This is required in the construction of the stored procedures with output parameters

        return false;
    
public booleanshouldUseJDBCOuterJoinSyntax()
INTERNAL: JDBC defines and outer join syntax, many drivers do not support this. So we normally avoid it.

        return false;
    
public booleansupportsLocalTempTables()
INTERNAL:

        return true;
    
public booleansupportsNativeSequenceNumbers()
INTERNAL: Return true if the receiver uses host sequence numbers, generated on the database. Sybase does through IDENTITY field types.

        return true;
    
public voidwriteUpdateOriginalFromTempTableSql(java.io.Writer writer, oracle.toplink.essentials.internal.helper.DatabaseTable table, java.util.Collection pkFields, java.util.Collection assignedFields)
INTERNAL:

        writer.write("UPDATE ");
        String tableName = table.getQualifiedName();
        writer.write(tableName);
        String tempTableName = getTempTableForTable(table).getQualifiedName();
        writeAutoAssignmentSetClause(writer, null, tempTableName, assignedFields);
        writer.write(" FROM ");
        writer.write(tableName);
        writer.write(", ");
        writer.write(tempTableName);
        writeAutoJoinWhereClause(writer, tableName, tempTableName, pkFields);