KickJava   Java API By Example, From Geeks To Geeks.

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


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.sql.Connection JavaDoc;
24 import java.sql.PreparedStatement JavaDoc;
25 import java.sql.ResultSet JavaDoc;
26 import java.sql.SQLException JavaDoc;
27
28 import org.apache.commons.logging.Log;
29
30 /**
31  * Quartz JDBC delegate for DB2 v6 databases. <code>select count(name)</code>
32  * had to be replaced with <code>select count(*)</code>.
33  *
34  * @author Martin Renner
35  * @author James House
36  */

37 public class DB2v6Delegate extends StdJDBCDelegate {
38     public static final String JavaDoc SELECT_NUM_JOBS = "SELECT COUNT(*) FROM "
39             + TABLE_PREFIX_SUBST + TABLE_JOB_DETAILS;
40
41     public static final String JavaDoc SELECT_NUM_TRIGGERS_FOR_JOB = "SELECT COUNT(*) FROM "
42             + TABLE_PREFIX_SUBST
43             + TABLE_TRIGGERS
44             + " WHERE "
45             + COL_JOB_NAME
46             + " = ? AND " + COL_JOB_GROUP + " = ?";
47
48     public static final String JavaDoc SELECT_NUM_TRIGGERS = "SELECT COUNT(*) FROM "
49             + TABLE_PREFIX_SUBST + TABLE_TRIGGERS;
50
51     public static final String JavaDoc SELECT_NUM_CALENDARS = "SELECT COUNT(*) FROM "
52             + TABLE_PREFIX_SUBST + TABLE_CALENDARS;
53
54     public DB2v6Delegate(Log logger, String JavaDoc tablePrefix, String JavaDoc instanceId) {
55         super(logger, tablePrefix, instanceId);
56     }
57
58     public DB2v6Delegate(Log logger, String JavaDoc tablePrefix, String JavaDoc instanceId,
59             Boolean JavaDoc useProperties) {
60         super(logger, tablePrefix, instanceId, useProperties);
61     }
62
63     public int selectNumJobs(Connection JavaDoc conn) throws SQLException JavaDoc {
64         PreparedStatement JavaDoc ps = null;
65         ResultSet JavaDoc rs = null;
66
67         try {
68             int count = 0;
69             ps = conn.prepareStatement(rtp(SELECT_NUM_JOBS));
70             rs = ps.executeQuery();
71
72             if (rs.next()) {
73                 count = rs.getInt(1);
74             }
75
76             return count;
77         } finally {
78             closeStatement(ps);
79         }
80     }
81
82     public int selectNumTriggersForJob(Connection JavaDoc conn, String JavaDoc jobName,
83             String JavaDoc groupName) throws SQLException JavaDoc {
84         PreparedStatement JavaDoc ps = null;
85         ResultSet JavaDoc rs = null;
86
87         try {
88             ps = conn.prepareStatement(rtp(SELECT_NUM_TRIGGERS_FOR_JOB));
89             ps.setString(1, jobName);
90             ps.setString(2, groupName);
91             rs = ps.executeQuery();
92
93             if (rs.next()) {
94                 return rs.getInt(1);
95             } else {
96                 return 0;
97             }
98         } finally {
99             closeStatement(ps);
100         }
101     }
102
103     public int selectNumTriggers(Connection JavaDoc conn) throws SQLException JavaDoc {
104         PreparedStatement JavaDoc ps = null;
105         ResultSet JavaDoc rs = null;
106
107         try {
108             int count = 0;
109             ps = conn.prepareStatement(rtp(SELECT_NUM_TRIGGERS));
110             rs = ps.executeQuery();
111
112             if (rs.next()) {
113                 count = rs.getInt(1);
114             }
115
116             return count;
117         } finally {
118             closeStatement(ps);
119         }
120     }
121
122     public int selectNumCalendars(Connection JavaDoc conn) throws SQLException JavaDoc {
123         PreparedStatement JavaDoc ps = null;
124         ResultSet JavaDoc rs = null;
125
126         try {
127             int count = 0;
128             ps = conn.prepareStatement(rtp(SELECT_NUM_CALENDARS));
129             rs = ps.executeQuery();
130
131             if (rs.next()) {
132                 count = rs.getInt(1);
133             }
134
135             return count;
136         } finally {
137             closeStatement(ps);
138         }
139     }
140 }
141
142 // EOF
143
Popular Tags