FileDocCategorySizeDatePackage
OracleSpecialDBOperation.javaAPI DocGlassfish v2 API17056Fri May 04 22:35:02 BST 2007com.sun.jdo.spi.persistence.support.sqlstore.database.oracle

OracleSpecialDBOperation

public class OracleSpecialDBOperation extends com.sun.jdo.spi.persistence.support.sqlstore.database.BaseSpecialDBOperation
OracleSpecialDBOperation is derived class for Oracle specific operation.
author
Shing Wai Chan
author
Mitesh Meswani

Fields Summary
private static com.sun.jdo.spi.persistence.utility.logging.Logger
logger
The logger
private DBDriverHandlerFactory
dBDriverHandlerFactory
private static final boolean
oracle816ClassesAvailable
private static final boolean
oracle817ClassesAvailable
private static final String
TEST_STATEMENT
The SQL statement used to get implementation type of PreparedStatement.
Constructors Summary
public OracleSpecialDBOperation()


      
    
Methods Summary
public voidbindFixedCharColumn(java.sql.PreparedStatement stmt, int index, java.lang.String strVal, int length)
Implements special handling of char columns on Oracle.

        DBDriverHandler driverHandler =
            dBDriverHandlerFactory.createDBDriverHandler(stmt);
        driverHandler.bindFixedCharColumn(index, strVal, length);
    
public voiddefineColumnTypeForResult(java.sql.PreparedStatement ps, java.util.List columns)
Defines Column type for result for specified ps.

        if(dBDriverHandlerFactory.supportsDefineColumnType()) {
            int size = columns.size();
            if (size > 0) {
                DBDriverHandler driverHandler =
                    dBDriverHandlerFactory.createDBDriverHandler(ps);
                try {
                    for (int i = 0; i < size; i++) {
                        FieldMapping fieldMapping = (FieldMapping) columns.get(i);
                        int type = fieldMapping.getColumnType();
                        if (type == Types.CHAR || type == Types.VARCHAR) {
                            int len = fieldMapping.getColumnLength();
                            if (len > 0) {
                                driverHandler.defineColumnType(i + 1, type, len);
                            } else {
                                driverHandler.defineColumnType(i + 1, type);
                            }
                        } else {
                            driverHandler.defineColumnType(i + 1, type);
                        }
                    }
                } catch (Exception ex) {
                    if (logger.isLoggable(Logger.INFO)) {
                        logger.log(Logger.INFO,
                                   "sqlstore.database.oracle.defineCol", // NOI18N
                                   ex);
                    }
                    driverHandler.clearDefines();
                }
            }
        }
    
public voidinitialize(java.sql.DatabaseMetaData metaData, java.lang.String identifier)
Initializes driver specific behavior classes by determining the characteristics of the jdbc driver used with this DataSource.

        Connection con = metaData.getConnection();
        // Since the PreparedStatement obtained is directly through
        // con, there is no need to unwrap it.
        PreparedStatement testPs = con.prepareStatement(TEST_STATEMENT);

        if (oracle817ClassesAvailable &&
            testPs instanceof oracle.jdbc.OraclePreparedStatement) {
            // This DataSource uses a driver version 8.1.7 or higher.
            // Oracle drivers for version 8.1.7 and higher define interface
            // oracle.jdbc.OraclePreparedStatement.
            // OraclePreparedStaement obtained from these drivers implement this
            // interface. It is possible that in future Oracle might alter
            // implementation class for OraclePreparedStatement. However, they
            // should continue implementing this interface. Hence, this
            // interface should be preferred to communicate with Oracle drivers.
            dBDriverHandlerFactory = new OracleDriverHandlerFactory() {
                public DBDriverHandler createDBDriverHandler(PreparedStatement ps) {
                    return new Oracle817Handler(ps);
                }
            };
        } else if (oracle816ClassesAvailable &&
                    testPs instanceof oracle.jdbc.driver.OraclePreparedStatement) {
            // This DataSource uses a driver version lower than 8.1.7.
            // Currently all Oracle drivers return instance of
            // oracle.jdbc.driver.OraclePreparedStatement for OraclePreparedStatement.
            dBDriverHandlerFactory = new OracleDriverHandlerFactory() {
                public DBDriverHandler createDBDriverHandler(PreparedStatement ps) {
                    return new Oracle816Handler(ps);
                }
            };
        } else {
            // This DataSource uses a non oracle driver.
            dBDriverHandlerFactory = new DBDriverHandlerFactory() {
                public DBDriverHandler createDBDriverHandler(PreparedStatement ps) {
                    return new NonOracleHandler(ps);
                }

                public boolean supportsDefineColumnType() {
                    return false;
                }
            };
            // Warn the user Oracle specific features will be disabled.
            if(logger.isLoggable(logger.CONFIG)) {
                identifier = identifier == null ?
                    "Connection Factory" : identifier;   //NOI18N
                logger.log(logger.CONFIG,
                           "sqlstore.database.oracle.nooracleavailable", //NOI18N
                           identifier);
            }
        }
        testPs.close();
    
private static java.lang.ClassloadClass(java.lang.String className, java.lang.ClassLoader loader)
Loads className using loader inside a previleged block. Returns null if class is not in classpath.

        final ClassLoader finalLoader = loader;
        final String finalClassName = className;
        return  (Class)AccessController.doPrivileged(
            new PrivilegedAction() {
                public Object run() {
                    try {
                        if (finalLoader != null) {
                            return Class.forName(finalClassName, true,
                                finalLoader);
                        } else {
                            return Class.forName(finalClassName);
                        }
                    } catch(Exception e) {
                        return null;
                    }
                }
            }
        );