KickJava   Java API By Example, From Geeks To Geeks.

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


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.ResultSet JavaDoc;
27 import java.sql.SQLException JavaDoc;
28
29 import org.apache.commons.logging.Log;
30
31 /**
32  * <p>
33  * This is a driver delegate for the HSQLDB database.
34  * </p>
35  *
36  * @author James House
37  * @author <a HREF="mailto:jeff@binaryfeed.org">Jeffrey Wescott</a>
38  */

39 public class HSQLDBDelegate extends StdJDBCDelegate {
40     /**
41      * <p>
42      * Create new HSQLDBDelegate 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 HSQLDBDelegate(Log log, String JavaDoc tablePrefix, String JavaDoc instanceId) {
51         super(log, tablePrefix, instanceId);
52     }
53
54     /**
55      * <p>
56      * Create new MSSQLDelegate 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 HSQLDBDelegate(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 = rs.getBinaryStream(colName);
95
96         if(binaryInput == null) {
97             return null;
98         }
99         
100         Object JavaDoc obj = null;
101         
102         ObjectInputStream JavaDoc in = new ObjectInputStream JavaDoc(binaryInput);
103         try {
104             obj = in.readObject();
105         } finally {
106             in.close();
107         }
108
109         return obj;
110     }
111
112     protected Object JavaDoc getJobDetailFromBlob(ResultSet JavaDoc rs, String JavaDoc colName)
113         throws ClassNotFoundException JavaDoc, IOException JavaDoc, SQLException JavaDoc {
114         if (canUseProperties()) {
115             InputStream JavaDoc binaryInput = rs.getBinaryStream(colName);
116             return binaryInput;
117         }
118         return getObjectFromBlob(rs, colName);
119     }
120 }
121
122 // EOF
123
Popular Tags