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

DerbyPlatform

public class DerbyPlatform extends DB2Platform

Purpose: Provides Derby DBMS specific behaviour.

since
TOPLink Essentials 1.0

Fields Summary
Constructors Summary
Methods Summary
protected voidappendByteArray(byte[] bytes, java.io.Writer writer)
INTERNAL: TODO: Need to find out how can byte arrays be inlined in Derby

            super.appendByteArray(bytes, writer);
    
protected java.util.HashtablebuildFieldTypes()

        Hashtable fieldTypeMapping = new Hashtable();

        fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("SMALLINT 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"));
        fieldTypeMapping.put(Double.class, new FieldTypeDefinition("FLOAT", 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("BIGINT", false));
        fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL"));
        fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL"));

        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("CLOB", 64000));
        fieldTypeMapping.put(byte[].class, new FieldTypeDefinition("BLOB", 64000));
        fieldTypeMapping.put(char[].class, new FieldTypeDefinition("CLOB", 64000));
        fieldTypeMapping.put(java.sql.Blob.class, new FieldTypeDefinition("BLOB", 64000));
        fieldTypeMapping.put(java.sql.Clob.class, new FieldTypeDefinition("CLOB", 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("TIMESTAMP", false));

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

        ValueReadQuery selectQuery = new ValueReadQuery();
        selectQuery.setSQLString("values IDENTITY_VAL_LOCAL()");
        return selectQuery;
    
protected java.lang.StringgetCreateTempTableSqlBodyForTable(oracle.toplink.essentials.internal.helper.DatabaseTable table)
INTERNAL:

        // returning null includes fields of the table in body
        // see javadoc of DatabasePlatform#getCreateTempTableSqlBodyForTable(DataBaseTable)
        // for details
        return null;
     
protected java.lang.StringgetCreateTempTableSqlSuffix()
INTERNAL:

        return " ON COMMIT DELETE ROWS NOT LOGGED";
    
public java.lang.StringgetInOutputProcedureToken()
This method is used to print the output parameter token when stored procedures are called

        return "INOUT";
    
public java.util.VectorgetNativeTableInfo(java.lang.String table, java.lang.String creator, oracle.toplink.essentials.internal.sessions.AbstractSession session)

        throw new RuntimeException("Should never reach here");
    
public java.lang.StringgetProcedureBeginString()
Used for stored procedure defs.

        return getBatchBeginString();
    
public java.lang.StringgetProcedureEndString()
Used for stored procedure defs.

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

        if (timestampQuery == null) {
            timestampQuery = new ValueReadQuery();
            timestampQuery.setSQLString("VALUES CURRENT_TIMESTAMP");
        }
        return timestampQuery;

    
public booleanisDB2()

        //This class inhertits from DB2. But it is not DB2
        return false;
    
public booleanisDerby()
INTERNAL: Answers whether platform is Derby

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

        try {
            writer.write(" GENERATED ALWAYS AS IDENTITY");
        } catch (IOException ioException) {
            throw ValidationException.fileError(ioException);
        }
    
public booleanshouldIgnoreException(java.sql.SQLException exception)
Allow for the platform to ignore exceptions.

        // Nothing is ignored.
        return false;
    
public booleanshouldNativeSequenceAcquireValueAfterInsert()
INTERNAL: Indicates whether NativeSequence should retrieve sequence value after the object has been inserted into the db This method is to be used *ONLY* by sequencing classes

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

        //TODO: Check with the reviewer where this is used
        return false;
    
protected booleanshouldTempTableSpecifyPrimaryKeys()
INTERNAL: Indicates whether temporary table can specify primary keys (some platforms don't allow that). Used by writeCreateTempTableSql method.

        return false;
    
public booleansupportsNativeSequenceNumbers()

        return true;
    
public voidwriteUpdateOriginalFromTempTableSql(java.io.Writer writer, oracle.toplink.essentials.internal.helper.DatabaseTable table, java.util.Collection pkFields, java.util.Collection assignedFields)
INTERNAL: May need to override this method if the platform supports temporary tables and the generated sql doesn't work. Write an sql string for updating the original table from the temporary table. Precondition: supportsTempTables() == true. Precondition: pkFields and assignFields don't intersect.

parameter
Writer writer for writing the sql
parameter
DatabaseTable table is original table for which temp table is created.
parameter
Collection pkFields - primary key fields for the original table.
parameter
Collection assignedFields - fields to be assigned a new value.

        writer.write("UPDATE ");
        String tableName = table.getQualifiedName();
        writer.write(tableName);
        writer.write(" SET ");
        
        String tempTableName = getTempTableForTable(table).getQualifiedName();
        boolean isFirst = true;
        Iterator itFields = assignedFields.iterator();
        while(itFields.hasNext()) {
            if(isFirst) {
                isFirst = false;
            } else {
                writer.write(", ");
            }
            DatabaseField field = (DatabaseField)itFields.next();
            String fieldName = field.getName();
            writer.write(fieldName);
            writer.write(" = (SELECT ");
            writer.write(fieldName);
            writer.write(" FROM ");
            writer.write(tempTableName);
            writeAutoJoinWhereClause(writer, null, tableName, pkFields);
            writer.write(")");
        }
        
        writer.write(" WHERE EXISTS(SELECT ");
        writer.write(((DatabaseField)pkFields.iterator().next()).getName());
        writer.write(" FROM ");
        writer.write(tempTableName);
        writeAutoJoinWhereClause(writer, null, tableName, pkFields);
        writer.write(")");