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;
022:
023: import java.io.IOException;
024: import java.io.InputStream;
025: import java.io.ObjectInputStream;
026: import java.sql.Blob;
027: import java.sql.ResultSet;
028: import java.sql.SQLException;
029:
030: import org.apache.commons.logging.Log;
031:
032: /**
033: * <p>
034: * This is a driver delegate for the WebLogic JDBC driver.
035: * </p>
036: *
037: * @see org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate
038: * @author <a href="mailto:jeff@binaryfeed.org">Jeffrey Wescott</a>
039: */
040: public class WebLogicDelegate extends StdJDBCDelegate {
041: /**
042: * <p>
043: * Create new WebLogicDelegate instance.
044: * </p>
045: *
046: * @param log
047: * the logger to use during execution
048: * @param tablePrefix
049: * the prefix of all table names
050: */
051: public WebLogicDelegate(Log log, String tablePrefix,
052: String instanceId) {
053: super (log, tablePrefix, instanceId);
054: }
055:
056: /**
057: * <p>
058: * Create new WebLogicDelegate instance.
059: * </p>
060: *
061: * @param log
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 WebLogicDelegate(Log log, String tablePrefix,
069: String instanceId, Boolean useProperties) {
070: super (log, tablePrefix, instanceId, useProperties);
071: }
072:
073: //---------------------------------------------------------------------------
074: // protected methods that can be overridden by subclasses
075: //---------------------------------------------------------------------------
076:
077: /**
078: * <p>
079: * This method should be overridden by any delegate subclasses that need
080: * special handling for BLOBs. The default implementation uses standard
081: * JDBC <code>java.sql.Blob</code> operations.
082: * </p>
083: *
084: * @param rs
085: * the result set, already queued to the correct row
086: * @param colName
087: * the column name for the BLOB
088: * @return the deserialized Object from the ResultSet BLOB
089: * @throws ClassNotFoundException
090: * if a class found during deserialization cannot be found
091: * @throws IOException
092: * if deserialization causes an error
093: */
094: protected Object getObjectFromBlob(ResultSet rs, String colName)
095: throws ClassNotFoundException, IOException, SQLException {
096:
097: Object obj = null;
098:
099: Blob blobLocator = rs.getBlob(colName);
100: InputStream binaryInput = null;
101: try {
102: if (null != blobLocator && blobLocator.length() > 0) {
103: binaryInput = blobLocator.getBinaryStream();
104: }
105: } catch (Exception ignore) {
106: }
107:
108: if (null != binaryInput) {
109: ObjectInputStream in = new ObjectInputStream(binaryInput);
110: try {
111: obj = in.readObject();
112: } finally {
113: in.close();
114: }
115: }
116:
117: return obj;
118: }
119:
120: protected Object getJobDetailFromBlob(ResultSet rs, String colName)
121: throws ClassNotFoundException, IOException, SQLException {
122:
123: if (canUseProperties()) {
124: Blob blobLocator = rs.getBlob(colName);
125: InputStream binaryInput = null;
126: try {
127: if (null != blobLocator && blobLocator.length() > 0) {
128: binaryInput = blobLocator.getBinaryStream();
129: }
130: } catch (Exception ignore) {
131: }
132: return binaryInput;
133: }
134:
135: return getObjectFromBlob(rs, colName);
136: }
137: }
138:
139: // EOF
|