001: /*
002: * Copyright 2004-2005 OpenSymphony
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005: * use this file except in compliance with the License. You may obtain a copy
006: * of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012: * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013: * License for the specific language governing permissions and limitations
014: * under the License.
015: *
016: */
017:
018: /*
019: * Previously Copyright (c) 2001-2004 James House
020: */
021: package org.quartz.impl.jdbcjobstore.oracle.weblogic;
022:
023: import org.apache.commons.logging.Log;
024: import org.quartz.impl.jdbcjobstore.oracle.OracleDelegate;
025:
026: import java.lang.reflect.Method;
027: import java.sql.Blob;
028: import java.sql.ResultSet;
029: import java.sql.SQLException;
030:
031: /**
032: * Handle Blobs correctly when Oracle is being used inside of Weblogic 8.1,
033: * as discussed at: http://edocs.bea.com/wls/docs81/jdbc/thirdparty.html#1043705
034: *
035: * @see org.quartz.impl.jdbcjobstore.WebLogicDelegate
036: * @author James House
037: * @author Igor Fedulov <a href="mailto:igor@fedulov.com">igor@fedulov.com</a>
038: */
039: public class WebLogicOracleDelegate extends OracleDelegate {
040:
041: /**
042: * <p>
043: * Create new WebLogicOracleDelegate instance.
044: * </p>
045: *
046: * @param logger
047: * the logger to use during execution
048: * @param tablePrefix
049: * the prefix of all table names
050: */
051: public WebLogicOracleDelegate(Log logger, String tablePrefix,
052: String instanceId) {
053: super (logger, tablePrefix, instanceId);
054: }
055:
056: /**
057: * <p>
058: * Create new WebLogicOracleDelegate instance.
059: * </p>
060: *
061: * @param logger
062: * the logger to use during execution
063: * @param tablePrefix
064: * the prefix of all table names
065: * @param useProperties
066: * use java.util.Properties for storage
067: */
068: public WebLogicOracleDelegate(Log logger, String tablePrefix,
069: String instanceId, Boolean useProperties) {
070: super (logger, tablePrefix, instanceId, useProperties);
071: }
072:
073: /**
074: * Check for the Weblogic Blob wrapper, and handle accordingly...
075: */
076: protected Blob writeDataToBlob(ResultSet rs, int column, byte[] data)
077: throws SQLException {
078: Blob blob = rs.getBlob(column);
079:
080: if (blob == null) {
081: throw new SQLException(
082: "Driver's Blob representation is null!");
083: }
084:
085: // handle thin driver's blob
086: if (blob instanceof weblogic.jdbc.vendor.oracle.OracleThinBlob) {
087: ((weblogic.jdbc.vendor.oracle.OracleThinBlob) blob)
088: .putBytes(1, data);
089: return blob;
090: } else if (blob.getClass().getPackage().getName().startsWith(
091: "weblogic.")) {
092: // (more slowly) handle blob for wrappers of other variations of drivers...
093: try {
094: // try to find putBytes method...
095: Method m = blob.getClass().getMethod("putBytes",
096: new Class[] { long.class, byte[].class });
097: m.invoke(blob, new Object[] { new Long(1), data });
098: } catch (Exception e) {
099: throw new SQLException(
100: "Unable to find putBytes(long,byte[]) method on blob: "
101: + e);
102: }
103: return blob;
104: } else {
105: return super.writeDataToBlob(rs, column, data);
106: }
107: }
108: }
|