KickJava   Java API By Example, From Geeks To Geeks.

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


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 MSSQL JDBC driver.
34  * </p>
35  *
36  * @author <a HREF="mailto:jeff@binaryfeed.org">Jeffrey Wescott</a>
37  */

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

49     public MSSQLDelegate(Log log, String JavaDoc tablePrefix, String JavaDoc instanceId) {
50         super(log, tablePrefix, instanceId);
51     }
52
53     public MSSQLDelegate(Log log, String JavaDoc tablePrefix, String JavaDoc instanceId, Boolean JavaDoc useProperties) {
54         super(log, tablePrefix, instanceId, useProperties);
55     }
56
57     //---------------------------------------------------------------------------
58
// protected methods that can be overridden by subclasses
59
//---------------------------------------------------------------------------
60

61     /**
62      * <p>
63      * This method should be overridden by any delegate subclasses that need
64      * special handling for BLOBs. The default implementation uses standard
65      * JDBC <code>java.sql.Blob</code> operations.
66      * </p>
67      *
68      * @param rs
69      * the result set, already queued to the correct row
70      * @param colName
71      * the column name for the BLOB
72      * @return the deserialized Object from the ResultSet BLOB
73      * @throws ClassNotFoundException
74      * if a class found during deserialization cannot be found
75      * @throws IOException
76      * if deserialization causes an error
77      */

78     protected Object JavaDoc getObjectFromBlob(ResultSet JavaDoc rs, String JavaDoc colName)
79         throws ClassNotFoundException JavaDoc, IOException JavaDoc, SQLException JavaDoc {
80         InputStream JavaDoc binaryInput = rs.getBinaryStream(colName);
81
82         if(binaryInput == null) {
83             return null;
84         }
85
86         Object JavaDoc obj = null;
87
88         ObjectInputStream JavaDoc in = new ObjectInputStream JavaDoc(binaryInput);
89         try {
90             obj = in.readObject();
91         } finally {
92             in.close();
93         }
94
95         return obj;
96     }
97
98     protected Object JavaDoc getJobDetailFromBlob(ResultSet JavaDoc rs, String JavaDoc colName)
99         throws ClassNotFoundException JavaDoc, IOException JavaDoc, SQLException JavaDoc {
100         if (canUseProperties()) {
101             InputStream JavaDoc binaryInput = rs.getBinaryStream(colName);
102             return binaryInput;
103         }
104         return getObjectFromBlob(rs, colName);
105     }
106 }
107
108 // EOF
109
Popular Tags