KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > impl > jdbcjobstore > PostgreSQLDelegate


1 /*
2  * Copyright 2004-2005 OpenSymphony
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy
6  * of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations
14  * under the License.
15  *
16  */

17
18 /*
19  * Previously Copyright (c) 2001-2004 James House
20  */

21 package org.quartz.impl.jdbcjobstore;
22
23 import java.io.ByteArrayInputStream JavaDoc;
24 import java.io.IOException JavaDoc;
25 import java.io.InputStream JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.sql.ResultSet JavaDoc;
28 import java.sql.SQLException JavaDoc;
29
30 import org.apache.commons.logging.Log;
31
32 /**
33  * <p>
34  * This is a driver delegate for the PostgreSQL JDBC driver.
35  * </p>
36  *
37  * @author <a HREF="mailto:jeff@binaryfeed.org">Jeffrey Wescott</a>
38  */

39 public class PostgreSQLDelegate extends StdJDBCDelegate {
40     /**
41      * <p>
42      * Create new PostgreSQLDelegate instance.
43      * </p>
44      *
45      * @param log
46      * the logger to use during execution
47      * @param tablePrefix
48      * the prefix of all table names
49      */

50     public PostgreSQLDelegate(Log log, String JavaDoc tablePrefix, String JavaDoc instanceId) {
51         super(log, tablePrefix, instanceId);
52     }
53
54     /**
55      * <p>
56      * Create new PostgreSQLDelegate instance.
57      * </p>
58      *
59      * @param log
60      * the logger to use during execution
61      * @param tablePrefix
62      * the prefix of all table names
63      * @param useProperties
64      * use java.util.Properties for storage
65      */

66     public PostgreSQLDelegate(Log log, String JavaDoc tablePrefix, String JavaDoc instanceId,
67             Boolean JavaDoc useProperties) {
68         super(log, tablePrefix, instanceId, useProperties);
69     }
70
71     //---------------------------------------------------------------------------
72
// protected methods that can be overridden by subclasses
73
//---------------------------------------------------------------------------
74

75     /**
76      * <p>
77      * This method should be overridden by any delegate subclasses that need
78      * special handling for BLOBs. The default implementation uses standard
79      * JDBC <code>java.sql.Blob</code> operations.
80      * </p>
81      *
82      * @param rs
83      * the result set, already queued to the correct row
84      * @param colName
85      * the column name for the BLOB
86      * @return the deserialized Object from the ResultSet BLOB
87      * @throws ClassNotFoundException
88      * if a class found during deserialization cannot be found
89      * @throws IOException
90      * if deserialization causes an error
91      */

92     protected Object JavaDoc getObjectFromBlob(ResultSet JavaDoc rs, String JavaDoc colName)
93         throws ClassNotFoundException JavaDoc, IOException JavaDoc, SQLException JavaDoc {
94         InputStream JavaDoc binaryInput = null;
95         byte[] bytes = rs.getBytes(colName);
96         
97         Object JavaDoc obj = null;
98         
99         if(bytes != null && bytes.length != 0) {
100             binaryInput = new ByteArrayInputStream JavaDoc(bytes);
101         
102             ObjectInputStream JavaDoc in = new ObjectInputStream JavaDoc(binaryInput);
103             try {
104                 obj = in.readObject();
105             } finally {
106                 in.close();
107             }
108
109         }
110         
111         return obj;
112     }
113
114     protected Object JavaDoc getJobDetailFromBlob(ResultSet JavaDoc rs, String JavaDoc colName)
115         throws ClassNotFoundException JavaDoc, IOException JavaDoc, SQLException JavaDoc {
116         if (canUseProperties()) {
117             InputStream JavaDoc binaryInput = null;
118             byte[] bytes = rs.getBytes(colName);
119             if(bytes == null || bytes.length == 0) {
120                 return null;
121             }
122             binaryInput = new ByteArrayInputStream JavaDoc(bytes);
123             return binaryInput;
124         }
125         return getObjectFromBlob(rs, colName);
126     }
127 }
128
129 // EOF
130
Popular Tags