KickJava   Java API By Example, From Geeks To Geeks.

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


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.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.io.ObjectInputStream JavaDoc;
26 import java.sql.Blob 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 WebLogic JDBC driver.
35  * </p>
36  *
37  * @see org.quartz.impl.jdbcjobstore.oracle.weblogic.WebLogicOracleDelegate
38  * @author <a HREF="mailto:jeff@binaryfeed.org">Jeffrey Wescott</a>
39  */

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

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

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

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

93     protected Object JavaDoc getObjectFromBlob(ResultSet JavaDoc rs, String JavaDoc colName)
94         throws ClassNotFoundException JavaDoc, IOException JavaDoc, SQLException JavaDoc {
95         
96         Object JavaDoc obj = null;
97
98         Blob JavaDoc blobLocator = rs.getBlob(colName);
99         InputStream JavaDoc binaryInput = null;
100         try {
101             if (null != blobLocator && blobLocator.length() > 0) {
102                 binaryInput = blobLocator.getBinaryStream();
103             }
104         } catch (Exception JavaDoc ignore) {
105         }
106
107         if (null != binaryInput) {
108             ObjectInputStream JavaDoc in = new ObjectInputStream JavaDoc(binaryInput);
109             try {
110                 obj = in.readObject();
111             } finally {
112                 in.close();
113             }
114         }
115
116         return obj;
117     }
118
119     protected Object JavaDoc getJobDetailFromBlob(ResultSet JavaDoc rs, String JavaDoc colName)
120         throws ClassNotFoundException JavaDoc, IOException JavaDoc, SQLException JavaDoc {
121         
122         if (canUseProperties()) {
123             Blob JavaDoc blobLocator = rs.getBlob(colName);
124             InputStream JavaDoc binaryInput = null;
125             try {
126                 if (null != blobLocator && blobLocator.length() > 0) {
127                     binaryInput = blobLocator.getBinaryStream();
128                 }
129             } catch (Exception JavaDoc ignore) {
130             }
131             return binaryInput;
132         }
133
134         return getObjectFromBlob(rs, colName);
135     }
136 }
137
138 // EOF
139
Popular Tags