com.metamatrix.common.jdbc
Class JDBCPlatform

java.lang.Object
  extended by com.metamatrix.common.jdbc.JDBCPlatform
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
DB2Platform, DerbyPlatform, InformixPlatform, MetaMatrixPlatform, MSSQLPlatform, MySQLPlatform, OraclePlatform, PostgresPlatform, SybasePlatform

public class JDBCPlatform
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

The JDBCPlatform represents a single datasource connection. The default platform is that of MetaMatrix. Use the JDBCPlatformFactory to create a JDBCPlatform that is representive of the type of connection.

See Also:
Serialized Form

Nested Class Summary
static interface JDBCPlatform.TableTypes
           
 
Field Summary
protected static java.lang.String AND
           
protected  java.util.Map classTypes
           
protected static java.lang.String COMMA
           
protected static java.lang.String DELETE_FROM
           
protected static java.lang.String DISTINCT
           
protected static java.lang.String EQUAL
           
protected  java.util.Map fieldTypes
          Holds a hashtable of values used to map JAVA types to database types for table creation
protected static java.lang.String FROM
           
protected static java.lang.String GROUP_BY
           
protected static java.lang.String IN
           
protected static java.lang.String INSERT_INTO
           
protected static java.lang.String INTO
           
protected  boolean isSecure
           
protected static java.lang.String LENGTH
           
protected  java.util.Map maximumValues
           
protected  java.util.Map minimumValues
           
protected static java.lang.String ON
           
protected static java.lang.String ORDER_BY
           
protected static java.lang.String PARAM
           
protected static java.lang.String PERIOD
           
protected  java.util.Map platformOperators
          Operators specific to this platform
protected static java.lang.String SELECT
           
protected static java.lang.String SET
           
protected static java.lang.String SPACE
           
protected  java.lang.String[] tableTypes
           
protected static java.lang.String UPDATE
           
protected  boolean usesStreamsForBlobBinding
          Indicates that streams will be used to store BLOB data.
protected  boolean usesStreamsForClobBinding
           
protected static java.lang.String VALUES
           
protected static java.lang.String WHERE
           
 
Constructor Summary
protected JDBCPlatform()
           
 
Method Summary
protected  void addOperator(ExpressionOperator op)
           
protected  java.util.Map buildClassTypes()
           
protected  java.lang.String buildCommaSeperatedColumns(java.util.Collection columns)
          Takes a columns of Columns and returns a comma seperated string
protected  java.util.Map buildFieldTypes()
           
protected  java.util.Map buildPlatformOperators()
           
protected  java.lang.String buildSetParmClause(java.lang.Object[] setColumns)
           
protected  java.lang.String buildWhereParameterClause(Column[] whereColumns)
           
protected  java.lang.String buildWhereUsingUiqueKeys(java.util.Collection uniqueKeys)
           
 byte[] convertClobToByteArray(java.sql.ResultSet results, java.lang.String columName)
           
protected  byte[] convertToByteArray(java.sql.Blob sourceObject)
           
protected  byte[] convertToByteArray(java.sql.Clob sourceObject)
           
 byte[] convertToByteArray(java.lang.Object sourceObject)
           
 java.lang.String createDeleteStatement(Table table)
          Obtain the statement that may be used to delete records from a table with the specified metadata.
 java.lang.String createDeleteStatement(Table table, Column[] whereColumns, java.lang.String tablePrefix)
           
 java.lang.String createDeleteStatement(Table table, java.lang.String tablePrefix)
           
 java.lang.String createInsertStatement(Table tableMetadata)
          This will create an insert statement that can be used to insert rows using a PreparedStatement.
 java.lang.String createInsertStatement(Table tableMetadata, java.lang.String tablePrefix)
           
 java.lang.String createInsertStatement(Table tableMetadata, java.lang.String[] values)
          This will create an insert statement that will contain the actual values to be inserted into the table.
 java.lang.String createSelectStatement(Table tableMetadata)
          This will create an select statement that can be used to select rows.
 java.lang.String createSelectStatement(Table tableMetadata, java.lang.String tablePrefix)
           
 java.lang.String createSelectStatement(Table tableMetadata, java.lang.String tablePrefix, Column[] whereColumns)
          Create the select SQL string based on the table metadata.
 java.lang.String createTruncateStatement(java.lang.String tablename)
           
 java.lang.String createTruncateStatement(java.lang.String tablename, java.lang.String tablePrefix)
           
 java.lang.String createUpdateStatement(Table tableMetadata)
          Obtain the statement that can be used to update records in a table using a PreparedStatement.
 java.lang.String createUpdateStatement(Table tableMetadata, java.lang.String[] values)
          Obtain the statement which will contain the actual data values to update records in a table.
 java.util.Map getClassTypes()
           
 int getDatabaseColumnSize(java.lang.String tableName, java.lang.String columnName, java.sql.Connection jdbcConnection)
           
 java.util.Map getFieldTypes()
           
 int getMaxFieldNameSize()
           
 java.lang.Number getMaximumValue(java.lang.Class clazz)
          Call to determine what is the maximum value allowed for the current database platform.
 java.lang.Number getMinimumValue(java.lang.Class clazz)
          Call to determine what is the minimum value allowed for the current database platform.
protected  java.util.List getNonExecutableDelimiters()
          These nonexecutable delimiters are words or symbols that cannot be excuted via an execute statement.
 ExpressionOperator getOperator(java.lang.String name)
           
 java.lang.String getPlatformName()
           
 java.util.Map getPlatformOperators()
          Return any platform-specific operators
 java.lang.String[] getTableTypes()
           
 boolean isClosed(java.sql.Connection connection)
           
 boolean isDB2()
           
 boolean isDefault()
           
 boolean isDerby()
           
 boolean isInformix()
           
 boolean isMetaMatrix()
           
 boolean isMSSQL()
           
 boolean isMYSQL()
           
 boolean isOracle()
           
 boolean isPostgres()
           
 boolean isSecure()
           
 boolean isSybase()
           
 java.util.Map maximumNumericValues()
          Builds a table of maximum numeric values keyed on java class.
 java.util.Map minimumNumericValues()
          Builds a table of minimum numeric values keyed on java class.
 java.util.List parseToExecutableStatements(java.io.BufferedReader reader, java.lang.String delimiter)
           
 void setBlob(java.sql.PreparedStatement statement, byte[] data, int column)
           
 int setBlob(java.sql.ResultSet results, byte[] data, java.lang.String columnName)
           
 void setClob(java.sql.PreparedStatement statement, byte[] data, int column)
           
 void setClob(java.sql.ResultSet results, byte[] data, java.lang.String columnName)
           
 void setClob(java.sql.ResultSet results, java.io.InputStream is, java.lang.String columnName)
           
 void setConnection(java.sql.Connection conn)
           
 void setIsSecure(boolean secure)
           
 void setPlatformName(java.lang.String platformName)
           
 boolean usesStreamsForBlobBinding()
           
 boolean usesStreamsForClobBinding()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

usesStreamsForBlobBinding

protected boolean usesStreamsForBlobBinding
Indicates that streams will be used to store BLOB data. NOTE: does not work with ODBC


usesStreamsForClobBinding

protected boolean usesStreamsForClobBinding

isSecure

protected boolean isSecure

fieldTypes

protected transient java.util.Map fieldTypes
Holds a hashtable of values used to map JAVA types to database types for table creation


tableTypes

protected transient java.lang.String[] tableTypes

platformOperators

protected transient java.util.Map platformOperators
Operators specific to this platform


classTypes

protected transient java.util.Map classTypes

minimumValues

protected transient java.util.Map minimumValues

maximumValues

protected transient java.util.Map maximumValues

SPACE

protected static final java.lang.String SPACE
See Also:
Constant Field Values

COMMA

protected static final java.lang.String COMMA
See Also:
Constant Field Values

PARAM

protected static final java.lang.String PARAM
See Also:
Constant Field Values

PERIOD

protected static final java.lang.String PERIOD
See Also:
Constant Field Values

INSERT_INTO

protected static final java.lang.String INSERT_INTO
See Also:
Constant Field Values

DELETE_FROM

protected static final java.lang.String DELETE_FROM
See Also:
Constant Field Values

UPDATE

protected static final java.lang.String UPDATE
See Also:
Constant Field Values

SELECT

protected static final java.lang.String SELECT
See Also:
Constant Field Values

EQUAL

protected static final java.lang.String EQUAL
See Also:
Constant Field Values

FROM

protected static final java.lang.String FROM
See Also:
Constant Field Values

WHERE

protected static final java.lang.String WHERE
See Also:
Constant Field Values

ORDER_BY

protected static final java.lang.String ORDER_BY
See Also:
Constant Field Values

GROUP_BY

protected static final java.lang.String GROUP_BY
See Also:
Constant Field Values

SET

protected static final java.lang.String SET
See Also:
Constant Field Values

ON

protected static final java.lang.String ON
See Also:
Constant Field Values

INTO

protected static final java.lang.String INTO
See Also:
Constant Field Values

IN

protected static final java.lang.String IN
See Also:
Constant Field Values

DISTINCT

protected static final java.lang.String DISTINCT
See Also:
Constant Field Values

VALUES

protected static final java.lang.String VALUES
See Also:
Constant Field Values

AND

protected static final java.lang.String AND
See Also:
Constant Field Values

LENGTH

protected static final java.lang.String LENGTH
See Also:
Constant Field Values
Constructor Detail

JDBCPlatform

protected JDBCPlatform()
Method Detail

setConnection

public void setConnection(java.sql.Connection conn)
                   throws MetaMatrixException
Throws:
MetaMatrixException

isClosed

public boolean isClosed(java.sql.Connection connection)

setIsSecure

public void setIsSecure(boolean secure)

setPlatformName

public void setPlatformName(java.lang.String platformName)

getPlatformName

public java.lang.String getPlatformName()

isOracle

public boolean isOracle()

isDefault

public boolean isDefault()

isMetaMatrix

public boolean isMetaMatrix()

isDB2

public boolean isDB2()

isSybase

public boolean isSybase()

isMSSQL

public boolean isMSSQL()

isMYSQL

public boolean isMYSQL()

isInformix

public boolean isInformix()

isDerby

public boolean isDerby()

isPostgres

public boolean isPostgres()

isSecure

public boolean isSecure()

usesStreamsForBlobBinding

public boolean usesStreamsForBlobBinding()

usesStreamsForClobBinding

public boolean usesStreamsForClobBinding()

setBlob

public int setBlob(java.sql.ResultSet results,
                   byte[] data,
                   java.lang.String columnName)
            throws java.sql.SQLException,
                   java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

setBlob

public void setBlob(java.sql.PreparedStatement statement,
                    byte[] data,
                    int column)
             throws java.sql.SQLException,
                    java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

setClob

public void setClob(java.sql.ResultSet results,
                    byte[] data,
                    java.lang.String columnName)
             throws java.sql.SQLException,
                    java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

setClob

public void setClob(java.sql.ResultSet results,
                    java.io.InputStream is,
                    java.lang.String columnName)
             throws java.sql.SQLException,
                    java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

setClob

public void setClob(java.sql.PreparedStatement statement,
                    byte[] data,
                    int column)
             throws java.sql.SQLException,
                    java.io.IOException
Throws:
java.sql.SQLException
java.io.IOException

createSelectStatement

public java.lang.String createSelectStatement(Table tableMetadata)
This will create an select statement that can be used to select rows.

Parameters:
tableMetadata - the definition of the table in which columns will be used to create the select statement.

createSelectStatement

public java.lang.String createSelectStatement(Table tableMetadata,
                                              java.lang.String tablePrefix)

createSelectStatement

public java.lang.String createSelectStatement(Table tableMetadata,
                                              java.lang.String tablePrefix,
                                              Column[] whereColumns)
Create the select SQL string based on the table metadata. If the table prefix is passed, then prefix the table with this value. Also, if the where columns are passed the sql will build a WHERE clause containing parameters for each column

Parameters:
tabelMetadata - is the table that drives the sql statement
tablePrefix - is a prefix to add to the table; optional and nullable
whereColumns - are columns to use in the where clause; optional and nullable

createInsertStatement

public java.lang.String createInsertStatement(Table tableMetadata)
This will create an insert statement that can be used to insert rows using a PreparedStatement.

Parameters:
tableMetadata - the definition of the table in which records are to be updated; may not be null;

createInsertStatement

public java.lang.String createInsertStatement(Table tableMetadata,
                                              java.lang.String tablePrefix)

createInsertStatement

public java.lang.String createInsertStatement(Table tableMetadata,
                                              java.lang.String[] values)
This will create an insert statement that will contain the actual values to be inserted into the table.

Parameters:
tableMetadata - the definition of the table in which records are to be updated; may not be null;
values - to be inserted

createUpdateStatement

public java.lang.String createUpdateStatement(Table tableMetadata)
Obtain the statement that can be used to update records in a table using a PreparedStatement.

Parameters:
tableMetadata - the definition of the table in which records are to be updated; may not be null;

createUpdateStatement

public java.lang.String createUpdateStatement(Table tableMetadata,
                                              java.lang.String[] values)
Obtain the statement which will contain the actual data values to update records in a table.

Parameters:
tableMetadata - the definition of the table in which records are to be updated; may not be null;
values - to be inserted

buildSetParmClause

protected java.lang.String buildSetParmClause(java.lang.Object[] setColumns)

buildWhereUsingUiqueKeys

protected java.lang.String buildWhereUsingUiqueKeys(java.util.Collection uniqueKeys)

createDeleteStatement

public java.lang.String createDeleteStatement(Table table)
Obtain the statement that may be used to delete records from a table with the specified metadata.

Parameters:
tableMetadata - the definition of the table from which records are to be deleted; may not be null;

createDeleteStatement

public java.lang.String createDeleteStatement(Table table,
                                              java.lang.String tablePrefix)

createDeleteStatement

public java.lang.String createDeleteStatement(Table table,
                                              Column[] whereColumns,
                                              java.lang.String tablePrefix)

createTruncateStatement

public java.lang.String createTruncateStatement(java.lang.String tablename)

createTruncateStatement

public java.lang.String createTruncateStatement(java.lang.String tablename,
                                                java.lang.String tablePrefix)

getMaxFieldNameSize

public int getMaxFieldNameSize()

getTableTypes

public java.lang.String[] getTableTypes()
                                 throws MetaMatrixException
Throws:
MetaMatrixException

getClassTypes

public java.util.Map getClassTypes()

getFieldTypes

public java.util.Map getFieldTypes()

getMaximumValue

public java.lang.Number getMaximumValue(java.lang.Class clazz)
Call to determine what is the maximum value allowed for the current database platform.

Parameters:
clazz - is the java object data type that is of type Number
Returns:
Number that represents the maximum value allowed on the current database platform.

getMinimumValue

public java.lang.Number getMinimumValue(java.lang.Class clazz)
Call to determine what is the minimum value allowed for the current database platform.

Parameters:
clazz - is the java object data type that is of type Number
Returns:
Number that represents the minimum value allowed on the current database platform.

getOperator

public ExpressionOperator getOperator(java.lang.String name)

getPlatformOperators

public java.util.Map getPlatformOperators()
Return any platform-specific operators


buildClassTypes

protected java.util.Map buildClassTypes()

buildFieldTypes

protected java.util.Map buildFieldTypes()

addOperator

protected void addOperator(ExpressionOperator op)

buildPlatformOperators

protected java.util.Map buildPlatformOperators()

maximumNumericValues

public java.util.Map 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


minimumNumericValues

public java.util.Map 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


convertToByteArray

public byte[] convertToByteArray(java.lang.Object sourceObject)
                          throws TransformationException
Throws:
TransformationException

convertToByteArray

protected byte[] convertToByteArray(java.sql.Blob sourceObject)
                             throws TransformationException
Throws:
TransformationException

convertClobToByteArray

public byte[] convertClobToByteArray(java.sql.ResultSet results,
                                     java.lang.String columName)
                              throws TransformationException
Throws:
TransformationException

convertToByteArray

protected byte[] convertToByteArray(java.sql.Clob sourceObject)
                             throws TransformationException
Throws:
TransformationException

buildCommaSeperatedColumns

protected java.lang.String buildCommaSeperatedColumns(java.util.Collection columns)
Takes a columns of Columns and returns a comma seperated string


buildWhereParameterClause

protected java.lang.String buildWhereParameterClause(Column[] whereColumns)

getDatabaseColumnSize

public int getDatabaseColumnSize(java.lang.String tableName,
                                 java.lang.String columnName,
                                 java.sql.Connection jdbcConnection)
                          throws java.sql.SQLException
Throws:
java.sql.SQLException

parseToExecutableStatements

public java.util.List parseToExecutableStatements(java.io.BufferedReader reader,
                                                  java.lang.String delimiter)
                                           throws java.sql.SQLException
Throws:
java.sql.SQLException

getNonExecutableDelimiters

protected java.util.List getNonExecutableDelimiters()
These nonexecutable delimiters are words or symbols that cannot be excuted via an execute statement. These generally are platform specific or are required to be handled by the processing logic (i.e., commit, set spool off, etc.) the extending class should copy this forward and then add to it. Also, make an alpha characters upper case.

Returns:


Copyright © 2009. All Rights Reserved.