KickJava   Java API By Example, From Geeks To Geeks.

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


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.ByteArrayOutputStream JavaDoc;
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.SQLException JavaDoc;
26
27 import org.apache.commons.logging.Log;
28
29 /**
30  * Quartz JDBC delegate for DB2 v7 databases.
31  * <p>
32  * This differs from the <code>StdJDBCDelegate</code> in that it stores
33  * <code>boolean</code> values in an <code>varchar(1)</code> column, and saves
34  * serialized data in a byte array using
35  * <code>{@link PreparedStatement#setObject(int, java.lang.Object, int)}</code>
36  * rather than <code>{@link PreparedStatement#setBytes(int, byte[])}</code>.
37  * </p>
38  *
39  * @author Blair Jensen
40  */

41 public class DB2v7Delegate extends StdJDBCDelegate {
42
43     public DB2v7Delegate(Log logger, String JavaDoc tablePrefix, String JavaDoc instanceId) {
44         super(logger, tablePrefix, instanceId);
45     }
46
47     public DB2v7Delegate(Log log, String JavaDoc tablePrefix, String JavaDoc instanceId,
48             Boolean JavaDoc useProperties) {
49         super(log, tablePrefix, instanceId, useProperties);
50     }
51     
52     /**
53      * Sets the designated parameter to the byte array of the given
54      * <code>ByteArrayOutputStream</code>. Will set parameter value to null if the
55      * <code>ByteArrayOutputStream</code> is null.
56      * Wraps <code>{@link PreparedStatement#setObject(int, java.lang.Object, int)}</code> rather than
57      * <code>{@link PreparedStatement#setBytes(int, byte[])}</code> as required by the
58      * DB2 v7 database.
59      */

60     protected void setBytes(PreparedStatement JavaDoc ps, int index, ByteArrayOutputStream JavaDoc baos) throws SQLException JavaDoc {
61         ps.setObject(index, ((baos == null) ? null : baos.toByteArray()), java.sql.Types.BLOB);
62     }
63
64     /**
65      * Sets the designated parameter to the given Java <code>boolean</code> value.
66      * This translates the boolean to 1/0 for true/false.
67      */

68     protected void setBoolean(PreparedStatement JavaDoc ps, int index, boolean val) throws SQLException JavaDoc {
69         ps.setString(index, ((val) ? "1" : "0"));
70     }
71     
72 }
73
Popular Tags