FileDocCategorySizeDatePackage
DatasourcePlatform.javaAPI DocGlassfish v2 API21136Tue May 22 16:54:20 BST 2007oracle.toplink.essentials.internal.databaseaccess

DatasourcePlatform

public class DatasourcePlatform extends Object implements Platform
DatasourcePlatform is private to TopLink. It encapsulates behavior specific to a datasource platform (eg. Oracle, Sybase, DB2, Attunity, MQSeries), and provides protocol for TopLink to access this behavior.
see
DatabasePlatform
see
oracle.toplink.essentials.eis.EISPlatform
see
oracle.toplink.essentials.xml.XMLPlatform
see
oracle.toplink.essentials.sdk.SDKPlatform
since
OracleAS TopLink 10g (10.0.3)

Fields Summary
protected String
tableQualifier
Supporting name scopes in database by prefixing the table names with the table qualifier/creator.
protected transient ConversionManager
conversionManager
Allow for conversion to be customized in the platform.
protected ValueReadQuery
timestampQuery
Store the query use to query the current server time.
protected transient Map
platformOperators
Operators specific to this platform
protected Hashtable
dataTypesConvertedFromAClass
Store the list of Classes that can be converted to from the key.
protected Hashtable
dataTypesConvertedToAClass
Store the list of Classes that can be converted from to the key.
protected Sequence
defaultSequence
Store default sequence
protected Map
sequences
Store map of sequence names to sequences
Constructors Summary
public DatasourcePlatform()

        this.tableQualifier = "";
    
Methods Summary
protected voidaddOperator(oracle.toplink.essentials.expressions.ExpressionOperator operator)

        platformOperators.put(new Integer(operator.getSelector()), operator);
    
public voidaddSequence(oracle.toplink.essentials.sequencing.Sequence sequence)
Add sequence corresponding to the name

        if (getSequences() == null) {
            createSequences();
        }
        getSequences().put(sequence.getName(), sequence);
    
public voidappendParameter(oracle.toplink.essentials.queryframework.Call call, java.io.Writer writer, java.lang.Object parameter)
Add the parameter. Convert the parameter to a string and write it.

        String parameterValue = (String)getConversionManager().convertObject(parameter, ClassConstants.STRING);
        if (parameterValue == null) {
            parameterValue = "";
        }
        try {
            writer.write(parameterValue);
        } catch (IOException exception) {
            throw ValidationException.fileError(exception);
        }
    
public java.lang.Objectclone()

        try {
            DatasourcePlatform clone = (DatasourcePlatform)super.clone();
            clone.sequencesAfterCloneCleanup();
            return clone;
        } catch (CloneNotSupportedException exception) {
            ;//Do nothing
        }

        return null;
    
public java.lang.ObjectconvertObject(java.lang.Object sourceObject, java.lang.Class javaClass)
Convert the object to the appropriate type by invoking the appropriate ConversionManager method

param
object - the object that must be converted
param
javaClass - the class that the object must be converted to
exception
- ConversionException, all exceptions will be thrown as this type.
return
- the newly converted object

        return getConversionManager().convertObject(sourceObject, javaClass);
    
public voidcopyInto(oracle.toplink.essentials.internal.databaseaccess.Platform platform)
Copy the state into the new platform.

        if (!(platform instanceof DatasourcePlatform)) {
            return;
        }
        DatasourcePlatform datasourcePlatform = (DatasourcePlatform)platform;
        datasourcePlatform.setTableQualifier(getTableQualifier());
        datasourcePlatform.setTimestampQuery(this.timestampQuery);
        datasourcePlatform.setConversionManager(getConversionManager());
        if (hasDefaultSequence()) {
            datasourcePlatform.setDefaultSequence(getDefaultSequence());
        }
        datasourcePlatform.setSequences(getSequences());
    
protected oracle.toplink.essentials.sequencing.SequencecreatePlatformDefaultSequence()
INTERNAL: Create platform-default Sequence

        throw ValidationException.createPlatformDefaultSequenceUndefined(Helper.getShortClassName(this));
    
protected synchronized voidcreateSequences()

        if (getSequences() == null) {
            setSequences(new HashMap());
        }
    
public oracle.toplink.essentials.internal.helper.ConversionManagergetConversionManager()
The platform hold its own instance of conversion manager to allow customization.

        // Lazy init for serialization.
        if (conversionManager == null) {
            //Clone the default to allow customers to easily override the conversion manager
            conversionManager = (ConversionManager)ConversionManager.getDefaultManager().clone();
        }
        return conversionManager;
    
public java.lang.ObjectgetCustomModifyValueForCall(oracle.toplink.essentials.queryframework.Call call, java.lang.Object value, oracle.toplink.essentials.internal.helper.DatabaseField field, boolean shouldBind)
Allow for the platform to handle the representation of parameters specially.

        return value;
    
public java.util.VectorgetDataTypesConvertedFrom(java.lang.Class javaClass)
PUBLIC: Return the list of Classes that can be converted to from the passed in javaClass.

param
javaClass - the class that is converted from
return
- a vector of classes

        return getConversionManager().getDataTypesConvertedFrom(javaClass);
    
public java.util.VectorgetDataTypesConvertedTo(java.lang.Class javaClass)
PUBLIC: Return the list of Classes that can be converted from to the passed in javaClass.

param
javaClass - the class that is converted to
return
- a vector of classes

        return getConversionManager().getDataTypesConvertedTo(javaClass);
    
public oracle.toplink.essentials.sequencing.SequencegetDefaultSequence()
Get default sequence

        if (!hasDefaultSequence()) {
            setDefaultSequence(createPlatformDefaultSequence());
        }
        return defaultSequence;
    
public oracle.toplink.essentials.sequencing.SequencegetDefaultSequenceToWrite()
INTERNAL: Used only for writing into XML or Java.

        if (usesPlatformDefaultSequence()) {
            return null;
        } else {
            return getDefaultSequence();
        }
    
public oracle.toplink.essentials.expressions.ExpressionOperatorgetOperator(int selector)
Return the operator for the operator constant defined in ExpressionOperator.

        return (ExpressionOperator)getPlatformOperators().get(new Integer(selector));
    
public synchronized java.util.MapgetPlatformOperators()
Return any platform-specific operators

        if (platformOperators == null) {
            initializePlatformOperators();
        }
        return platformOperators;
    
public oracle.toplink.essentials.sequencing.SequencegetSequence(java.lang.String seqName)
Get sequence corresponding to the name

        if (seqName == null) {
            return getDefaultSequence();
        } else {
            if (getSequences() != null) {
                return (Sequence)getSequences().get(seqName);
            } else {
                return null;
            }
        }
    
public intgetSequencePreallocationSize()

        return getDefaultSequence().getPreallocationSize();
    
public java.util.MapgetSequences()
INTERNAL: Returns a map of sequence names to Sequences (may be null).

        return sequences;
    
public java.util.MapgetSequencesToWrite()
INTERNAL: Used only for writing into XML or Java.

        if ((getSequences() == null) || getSequences().isEmpty()) {
            return null;
        }
        Map sequencesToWrite = new HashMap();
        Iterator it = getSequences().values().iterator();
        while (it.hasNext()) {
            Sequence sequence = (Sequence)it.next();
            if (!(sequence instanceof DefaultSequence) || ((DefaultSequence)sequence).hasPreallocationSize()) {
                sequencesToWrite.put(sequence.getName(), sequence);
            }
        }
        return sequencesToWrite;
    
public java.lang.StringgetTableQualifier()
Return the qualifier for the table. Required by some databases such as Oracle and DB2

        return tableQualifier;
    
public java.sql.TimestampgetTimestampFromServer(oracle.toplink.essentials.internal.sessions.AbstractSession session, java.lang.String sessionName)
Answer the timestamp from the server.

        if (getTimestampQuery() == null) {
            return new java.sql.Timestamp(System.currentTimeMillis());
        } else {
            getTimestampQuery().setSessionName(sessionName);
            return (java.sql.Timestamp)session.executeQuery(getTimestampQuery());
        }
    
public oracle.toplink.essentials.queryframework.ValueReadQuerygetTimestampQuery()
This method can be overridden by subclasses to return a query that will return the timestamp from the server. return null if the time should be the local time.

        return timestampQuery;
    
public booleanhasDefaultSequence()
Get default sequence

        return defaultSequence != null;
    
protected voidinitializePlatformOperators()
Initialize any platform-specific operators

        this.platformOperators = new HashMap();

        // Outer join
        addOperator(ExpressionOperator.equalOuterJoin());

        // General
        addOperator(ExpressionOperator.toUpperCase());
        addOperator(ExpressionOperator.toLowerCase());
        addOperator(ExpressionOperator.chr());
        addOperator(ExpressionOperator.concat());
        addOperator(ExpressionOperator.hexToRaw());
        addOperator(ExpressionOperator.initcap());
        addOperator(ExpressionOperator.instring());
        addOperator(ExpressionOperator.soundex());
        addOperator(ExpressionOperator.leftPad());
        addOperator(ExpressionOperator.leftTrim());
        addOperator(ExpressionOperator.leftTrim2());
        addOperator(ExpressionOperator.replace());
        addOperator(ExpressionOperator.rightPad());
        addOperator(ExpressionOperator.rightTrim());
        addOperator(ExpressionOperator.rightTrim2());
        addOperator(ExpressionOperator.substring());
        addOperator(ExpressionOperator.toNumber());
        addOperator(ExpressionOperator.toChar());
        addOperator(ExpressionOperator.toCharWithFormat());
        addOperator(ExpressionOperator.translate());
        addOperator(ExpressionOperator.trim());
        addOperator(ExpressionOperator.trim2());
        addOperator(ExpressionOperator.ascii());
        addOperator(ExpressionOperator.length());
        addOperator(ExpressionOperator.locate());
        addOperator(ExpressionOperator.locate2());

        // Date
        addOperator(ExpressionOperator.addMonths());
        addOperator(ExpressionOperator.dateToString());
        addOperator(ExpressionOperator.lastDay());
        addOperator(ExpressionOperator.monthsBetween());
        addOperator(ExpressionOperator.nextDay());
        addOperator(ExpressionOperator.roundDate());
        addOperator(ExpressionOperator.toDate());
        addOperator(ExpressionOperator.today());
        addOperator(ExpressionOperator.currentDate());
        addOperator(ExpressionOperator.currentTime());

        // Math
        addOperator(ExpressionOperator.simpleMath(ExpressionOperator.Add, "+"));
        addOperator(ExpressionOperator.simpleMath(ExpressionOperator.Subtract, "-"));
        addOperator(ExpressionOperator.simpleMath(ExpressionOperator.Multiply, "*"));
        addOperator(ExpressionOperator.simpleMath(ExpressionOperator.Divide, "/"));

        addOperator(ExpressionOperator.ceil());
        addOperator(ExpressionOperator.cos());
        addOperator(ExpressionOperator.cosh());
        addOperator(ExpressionOperator.abs());
        addOperator(ExpressionOperator.acos());
        addOperator(ExpressionOperator.asin());
        addOperator(ExpressionOperator.atan());
        addOperator(ExpressionOperator.exp());
        addOperator(ExpressionOperator.sqrt());
        addOperator(ExpressionOperator.floor());
        addOperator(ExpressionOperator.ln());
        addOperator(ExpressionOperator.log());
        addOperator(ExpressionOperator.mod());
        addOperator(ExpressionOperator.power());
        addOperator(ExpressionOperator.round());
        addOperator(ExpressionOperator.sign());
        addOperator(ExpressionOperator.sin());
        addOperator(ExpressionOperator.sinh());
        addOperator(ExpressionOperator.tan());
        addOperator(ExpressionOperator.tanh());
        addOperator(ExpressionOperator.trunc());
        addOperator(ExpressionOperator.greatest());
        addOperator(ExpressionOperator.least());

        // Object-relational
        addOperator(ExpressionOperator.deref());
        addOperator(ExpressionOperator.ref());
        addOperator(ExpressionOperator.refToHex());
        addOperator(ExpressionOperator.value());
    
public booleanisAccess()

        return false;
    
public booleanisAttunity()

        return false;
    
public booleanisCloudscape()

        return false;
    
public booleanisDB2()

        return false;
    
public booleanisDBase()

        return false;
    
public booleanisDerby()

        return false;
    
public booleanisHSQL()

        return false;
    
public booleanisInformix()

        return false;
    
public booleanisMySQL()

        return false;
    
public booleanisODBC()

        return false;
    
public booleanisOracle()

        return false;
    
public booleanisPointBase()

        return false;
    
public booleanisPostgreSQL()

        return false;
    
public booleanisSQLAnywhere()

        return false;
    
public booleanisSQLServer()

        return false;
    
public booleanisSybase()

        return false;
    
public booleanisTimesTen()

        return false;
    
public voidplatformSpecificSequencingInitialization(oracle.toplink.essentials.sessions.DatabaseSession session)
INTERNAL: Platform specific sequencing initialization. This internal method should only be called by SequencingManager. By default does nothing.

    
public voidremoveAllSequences()
Remove all sequences, but the default one.

        sequences = null;
    
public oracle.toplink.essentials.sequencing.SequenceremoveSequence(java.lang.String seqName)
Remove sequence corresponding to name. Doesn't remove default sequence.

        if (getSequences() != null) {
            return (Sequence)getSequences().remove(seqName);
        } else {
            return null;
        }
    
protected voidsequencesAfterCloneCleanup()

        Sequence defaultSequenceClone = null;
        if (hasDefaultSequence()) {
            defaultSequenceClone = (Sequence)getDefaultSequence().clone();
            setDefaultSequence(defaultSequenceClone);
        }
        HashMap sequencesDeepClone = null;
        if (getSequences() != null) {
            sequencesDeepClone = new HashMap(getSequences().size());
            Iterator it = getSequences().values().iterator();
            while (it.hasNext()) {
                Sequence sequence = (Sequence)it.next();
                if ((defaultSequenceClone != null) && (sequence == getDefaultSequence())) {
                    sequencesDeepClone.put(defaultSequenceClone.getName(), defaultSequenceClone);
                } else {
                    Sequence sequenceClone = (Sequence)sequence.clone();
                    if (sequenceClone instanceof DefaultSequence) {
                        if (!((DefaultSequence)sequenceClone).hasPreallocationSize()) {
                            continue;
                        }
                    }
                    sequencesDeepClone.put(sequenceClone.getName(), sequenceClone);
                }
            }
            this.setSequences(sequencesDeepClone);
        }
    
public voidsetConversionManager(oracle.toplink.essentials.internal.helper.ConversionManager conversionManager)
The platform hold its own instance of conversion manager to allow customization.

        this.conversionManager = conversionManager;
    
public voidsetDefaultSequence(oracle.toplink.essentials.sequencing.Sequence sequence)
Set default sequence. In case the passed sequence is of type DefaultSequence - use platformDefaultSequence with name and size of the passed sequence.

        if (sequence instanceof DefaultSequence) {
            Sequence platformDefaultSequence = createPlatformDefaultSequence();
            if (platformDefaultSequence != null) {
                platformDefaultSequence.setName(sequence.getName());
                if (((DefaultSequence)sequence).hasPreallocationSize()) {
                    platformDefaultSequence.setPreallocationSize(sequence.getPreallocationSize());
                }
            }
            defaultSequence = platformDefaultSequence;
        } else {
            defaultSequence = sequence;
        }
    
public voidsetSequences(java.util.Map sequences)
INTERNAL: Sets sequences - for XML support only

        this.sequences = sequences;
    
public voidsetTableQualifier(java.lang.String qualifier)
Set the qualifier for the table. Required by some databases such as Oracle and DB2

        tableQualifier = qualifier;
    
public voidsetTimestampQuery(oracle.toplink.essentials.queryframework.ValueReadQuery tsQuery)
Can override the default query for returning a timestamp from the server. See: getTimestampFromServer

        timestampQuery = tsQuery;
    
public booleanshouldUseCustomModifyForCall(oracle.toplink.essentials.internal.helper.DatabaseField field)
Used by SQLCall.appendModify(..) If the field should be passed to customModifyInDatabaseCall, retun true, otherwise false. Methods shouldCustomModifyInDatabaseCall and customModifyInDatabaseCall should be kept in sync: shouldCustomModifyInDatabaseCall should return true if and only if the field is handled by customModifyInDatabaseCall.

        return false;
    
public java.lang.StringtoString()

        return Helper.getShortClassName(this.getClass());
    
public booleanusesPlatformDefaultSequence()
INTERNAL: Indicates whether defaultSequence is the same as platform default sequence.

        if (!hasDefaultSequence()) {
            return true;
        } else {
            return getDefaultSequence().equals(createPlatformDefaultSequence());
        }