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