KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > quartz > impl > jdbcjobstore > oracle > weblogic > WebLogicOracleDelegate


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.oracle.weblogic;
22
23 import org.apache.commons.logging.Log;
24 import org.quartz.impl.jdbcjobstore.oracle.OracleDelegate;
25
26 import java.lang.reflect.Method JavaDoc;
27 import java.sql.Blob JavaDoc;
28 import java.sql.ResultSet JavaDoc;
29 import java.sql.SQLException JavaDoc;
30
31 /**
32  * Handle Blobs correctly when Oracle is being used inside of Weblogic 8.1,
33  * as discussed at: http://edocs.bea.com/wls/docs81/jdbc/thirdparty.html#1043705
34  *
35  * @see org.quartz.impl.jdbcjobstore.WebLogicDelegate
36  * @author James House
37  * @author Igor Fedulov <a HREF="mailto:igor@fedulov.com">igor@fedulov.com</a>
38  */

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

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

68     public WebLogicOracleDelegate(Log logger, String JavaDoc tablePrefix,
69             String JavaDoc instanceId, Boolean JavaDoc useProperties) {
70         super(logger, tablePrefix, instanceId, useProperties);
71     }
72
73     /**
74      * Check for the Weblogic Blob wrapper, and handle accordingly...
75      */

76     protected Blob JavaDoc writeDataToBlob(ResultSet JavaDoc rs, int column, byte[] data) throws SQLException JavaDoc {
77         Blob JavaDoc blob = rs.getBlob(column);
78         
79         if (blob == null) {
80             throw new SQLException JavaDoc("Driver's Blob representation is null!");
81         }
82         
83         // handle thin driver's blob
84
if (blob instanceof weblogic.jdbc.vendor.oracle.OracleThinBlob) {
85             ((weblogic.jdbc.vendor.oracle.OracleThinBlob) blob).putBytes(1, data);
86             return blob;
87         } else if(blob.getClass().getPackage().getName().startsWith("weblogic.")) {
88             // (more slowly) handle blob for wrappers of other variations of drivers...
89
try {
90                 // try to find putBytes method...
91
Method JavaDoc m = blob.getClass().getMethod("putBytes", new Class JavaDoc[] {long.class, byte[].class});
92                 m.invoke(blob, new Object JavaDoc[] {new Long JavaDoc(1), data});
93             } catch (Exception JavaDoc e) {
94                 throw new SQLException JavaDoc("Unable to find putBytes(long,byte[]) method on blob: " + e);
95             }
96             return blob;
97         } else {
98             return super.writeDataToBlob(rs, column, data);
99         }
100     }
101 }
Popular Tags