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

MySQL4Platform

public class MySQL4Platform extends DatabasePlatform

Purpose: Provides MySQL specific behaviour.

Responsibilities:

  • Native SQL for Date, Time, & Timestamp.
  • Native sequencing.
  • Mapping of class types to database types for the schema framework.
  • Pessimistic locking.
  • Platform specific operators.
since
OracleAS TopLink 10g (10.1.3)

Fields Summary
Constructors Summary
Methods Summary
protected voidappendCalendar(java.util.Calendar calendar, java.io.Writer writer)
INTERNAL: Appends an MySQL specific Timestamp, if usesNativeSQL is true otherwise use the ODBC format. Native Format: 'YYYY-MM-DD HH:MM:SS'

        if (usesNativeSQL()) {
            writer.write("'");
            writer.write(Helper.printCalendarWithoutNanos(calendar));
            writer.write("'");
        } else {
            super.appendCalendar(calendar, writer);
        }
    
protected voidappendDate(java.sql.Date date, java.io.Writer writer)
INTERNAL: Appends an MySQL specific date if usesNativeSQL is true otherwise use the ODBC format. Native FORMAT: 'YYYY-MM-DD'

        if (usesNativeSQL()) {
            writer.write("'");
            writer.write(Helper.printDate(date));
            writer.write("'");
        } else {
            super.appendDate(date, writer);
        }
    
protected voidappendTime(java.sql.Time time, java.io.Writer writer)
INTERNAL: Appends an MySQL specific time if usesNativeSQL is true otherwise use the ODBC format. Native FORMAT: '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: Appends an MySQL specific Timestamp, if usesNativeSQL is true otherwise use the ODBC format. Native Format: 'YYYY-MM-DD HH:MM:SS'

        if (usesNativeSQL()) {
            writer.write("'");
            writer.write(Helper.printTimestampWithoutNanos(timestamp));
            writer.write("'");
        } else {
            super.appendTimestamp(timestamp, writer);
        }
    
protected java.util.HashtablebuildFieldTypes()
INTERNAL: Return the mapping of class types to database types for the schema framework.

        Hashtable fieldTypeMapping;

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

        fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("INTEGER", false));
        fieldTypeMapping.put(Long.class, new FieldTypeDefinition("BIGINT", false));
        fieldTypeMapping.put(Float.class, new FieldTypeDefinition("FLOAT", false));
        fieldTypeMapping.put(Double.class, new FieldTypeDefinition("DOUBLE", false));
        fieldTypeMapping.put(Short.class, new FieldTypeDefinition("SMALLINT", false));
        fieldTypeMapping.put(Byte.class, new FieldTypeDefinition("TINYINT", false));
        fieldTypeMapping.put(java.math.BigInteger.class, new FieldTypeDefinition("BIGINT", false));
        fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL",38));
        fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL",38));

        fieldTypeMapping.put(String.class, new FieldTypeDefinition("VARCHAR", 255));
        fieldTypeMapping.put(Character.class, new FieldTypeDefinition("CHAR", 1));

        fieldTypeMapping.put(Byte[].class, new FieldTypeDefinition("BLOB", 64000));
        fieldTypeMapping.put(Character[].class, new FieldTypeDefinition("TEXT", 64000));
        fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BLOB", 64000));
        fieldTypeMapping.put(char[].class, new FieldTypeDefinition("TEXT", 64000));
        fieldTypeMapping.put(java.sql.Blob.class, new FieldTypeDefinition("BLOB", 64000));
        fieldTypeMapping.put(java.sql.Clob.class, new FieldTypeDefinition("TEXT", 64000));
        
        fieldTypeMapping.put(java.sql.Date.class, new FieldTypeDefinition("DATE", false));
        fieldTypeMapping.put(java.sql.Time.class, new FieldTypeDefinition("TIME", 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 LAST_INSERT_ID()");
        selectQuery.setSQLString(writer.toString());
        return selectQuery;
    
protected oracle.toplink.essentials.expressions.ExpressionOperatordateToStringOperator()
INTERNAL: Build MySQL equivalent to TO_CHAR.

        ExpressionOperator exOperator = new ExpressionOperator();
        exOperator.setType(ExpressionOperator.FunctionOperator);
        exOperator.setSelector(ExpressionOperator.DateToString);
        Vector v = new Vector(2);
        v.addElement("CONVERT(");
        v.addElement(", CHAR)");
        exOperator.printsAs(v);
        exOperator.bePrefix();
        exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
        return exOperator;
    
public java.lang.StringgetConstraintDeletionString()
INTERNAL: Used for constraint deletion.

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

        return "CREATE TEMPORARY TABLE IF NOT EXISTS ";
    
public java.lang.StringgetSelectForUpdateString()
INTERNAL: Used for pessimistic locking.

        return " FOR UPDATE";
    
public oracle.toplink.essentials.queryframework.ValueReadQuerygetTimestampQuery()
INTERNAL: This method returns the query to select the timestamp from the server for MySQL.

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

        super.initializePlatformOperators();
        addOperator(logOperator());
        addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Atan2, "ATAN2"));
        addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Concat, "CONCAT"));
        addOperator(toNumberOperator());
        addOperator(toCharOperator());
        addOperator(toDateOperator());
        addOperator(dateToStringOperator());
        addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Nvl, "IFNULL"));
        addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Trunc, "TRUNCATE"));
        addOperator(leftTrim2());
        addOperator(rightTrim2());
    
public booleanisMySQL()
Answers whether platform is MySQL

        return true;
    
protected oracle.toplink.essentials.expressions.ExpressionOperatorleftTrim2()
INTERNAL: Build MySQL equivalent to LTRIM(string_exp, character). MySQL: TRIM(LEADING character FROM string_exp)

        ExpressionOperator exOperator = new ExpressionOperator();
        exOperator.setType(ExpressionOperator.FunctionOperator);
        exOperator.setSelector(ExpressionOperator.LeftTrim2);
        Vector v = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(5);
        v.addElement("TRIM(LEADING ");
        v.addElement(" FROM ");
        v.addElement(")");
        exOperator.printsAs(v);
        exOperator.bePrefix();
        int[] indices = {1, 0};
        exOperator.setArgumentIndices(indices);
        exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
        return exOperator;
    
protected oracle.toplink.essentials.expressions.ExpressionOperatorlogOperator()
INTERNAL: Create the 10 based log operator for this platform

        ExpressionOperator result = new ExpressionOperator();
        result.setSelector(ExpressionOperator.Log);
        Vector v = new Vector(2);
        v.addElement("LOG(");
        v.addElement(", 10)");
        result.printsAs(v);
        result.bePrefix();
        result.setNodeClass(FunctionExpression.class);
        return result;

    
public voidprintFieldIdentityClause(java.io.Writer writer)
INTERNAL: Append the receiver's field 'identity' constraint clause to a writer

        try {
            writer.write(" AUTO_INCREMENT");
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
    
protected oracle.toplink.essentials.expressions.ExpressionOperatorrightTrim2()
INTERNAL: Build MySQL equivalent to RTRIM(string_exp, character). MySQL: TRIM(TRAILING character FROM string_exp)

        ExpressionOperator exOperator = new ExpressionOperator();
        exOperator.setType(ExpressionOperator.FunctionOperator);
        exOperator.setSelector(ExpressionOperator.RightTrim2);
        Vector v = oracle.toplink.essentials.internal.helper.NonSynchronizedVector.newInstance(5);
        v.addElement("TRIM(TRAILING ");
        v.addElement(" FROM ");
        v.addElement(")");
        exOperator.printsAs(v);
        exOperator.bePrefix();
        int[] indices = {1, 0};
        exOperator.setArgumentIndices(indices);
        exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
        return exOperator;
    
public booleanshouldAlwaysUseTempStorageForModifyAll()
INTERNAL:

        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 booleanshouldUseJDBCOuterJoinSyntax()
INTERNAL: JDBC defines an outer join syntax which many drivers do not support. So we normally avoid it.

        return false;
    
public booleansupportsGlobalTempTables()
INTERNAL:

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

        return true;
    
protected oracle.toplink.essentials.expressions.ExpressionOperatortoCharOperator()
INTERNAL: Build MySQL equivalent to TO_CHAR.

        ExpressionOperator exOperator = new ExpressionOperator();
        exOperator.setType(ExpressionOperator.FunctionOperator);
        exOperator.setSelector(ExpressionOperator.ToChar);
        Vector v = new Vector(2);
        v.addElement("CONVERT(");
        v.addElement(", CHAR)");
        exOperator.printsAs(v);
        exOperator.bePrefix();
        exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
        return exOperator;
    
protected oracle.toplink.essentials.expressions.ExpressionOperatortoDateOperator()
INTERNAL: Build MySQL equivalent to TO_DATE.

        ExpressionOperator exOperator = new ExpressionOperator();
        exOperator.setType(ExpressionOperator.FunctionOperator);
        exOperator.setSelector(ExpressionOperator.ToDate);
        Vector v = new Vector(2);
        v.addElement("CONVERT(");
        v.addElement(", DATETIME)");
        exOperator.printsAs(v);
        exOperator.bePrefix();
        exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
        return exOperator;
    
protected oracle.toplink.essentials.expressions.ExpressionOperatortoNumberOperator()
INTERNAL: Build MySQL equivalent to TO_NUMBER.

        ExpressionOperator exOperator = new ExpressionOperator();
        exOperator.setType(ExpressionOperator.FunctionOperator);
        exOperator.setSelector(ExpressionOperator.ToNumber);
        Vector v = new Vector(2);
        v.addElement("CONVERT(");
        v.addElement(", SIGNED)");
        exOperator.printsAs(v);
        exOperator.bePrefix();
        exOperator.setNodeClass(ClassConstants.FunctionExpression_Class);
        return exOperator;
    
public voidwriteDeleteFromTargetTableUsingTempTableSql(java.io.Writer writer, oracle.toplink.essentials.internal.helper.DatabaseTable table, oracle.toplink.essentials.internal.helper.DatabaseTable targetTable, java.util.Collection pkFields, java.util.Collection targetPkFields)
INTERNAL:

        writer.write("DELETE FROM ");
        String targetTableName = targetTable.getQualifiedName();
        writer.write(targetTableName);
        writer.write(" USING ");
        writer.write(targetTableName);
        writer.write(", ");
        String tempTableName = getTempTableForTable(table).getQualifiedName();
        writer.write(tempTableName);
        writeJoinWhereClause(writer, targetTableName, tempTableName, targetPkFields, pkFields);
    
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);
        writer.write(", ");
        String tempTableName = getTempTableForTable(table).getQualifiedName();
        writer.write(tempTableName);
        writeAutoAssignmentSetClause(writer, tableName, tempTableName, assignedFields);
        writeAutoJoinWhereClause(writer, tableName, tempTableName, pkFields);