01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.components.cron;
18:
19: import java.sql.Connection;
20: import java.sql.SQLException;
21:
22: import org.apache.avalon.excalibur.datasource.DataSourceComponent;
23: import org.apache.avalon.framework.configuration.ConfigurationException;
24: import org.apache.avalon.framework.service.ServiceException;
25: import org.apache.avalon.framework.service.ServiceManager;
26: import org.apache.avalon.framework.service.ServiceSelector;
27: import org.quartz.utils.ConnectionProvider;
28:
29: /**
30: * Quartz database connection provider that uses the
31: * Excalibur DataSourceComponent service.
32: */
33: public class DataSourceComponentConnectionProvider implements
34: ConnectionProvider {
35:
36: private ServiceManager m_manager;
37: private ServiceSelector m_datasources;
38: private DataSourceComponent m_ds;
39:
40: public DataSourceComponentConnectionProvider(String dsName,
41: ServiceManager manager) throws ConfigurationException {
42: m_manager = manager;
43: try {
44: m_datasources = (ServiceSelector) m_manager
45: .lookup(DataSourceComponent.ROLE + "Selector");
46: m_ds = (DataSourceComponent) m_datasources.select(dsName);
47: } catch (ServiceException e) {
48: throw new ConfigurationException(
49: "No datasource available by that name: " + dsName);
50: }
51: }
52:
53: /*
54: * @see org.quartz.utils.ConnectionProvider#getConnection()
55: */
56: public Connection getConnection() throws SQLException {
57: return m_ds.getConnection();
58: }
59:
60: /*
61: * @see org.quartz.utils.ConnectionProvider#shutdown()
62: */
63: public void shutdown() throws SQLException {
64: if (m_ds != null) {
65: m_datasources.release(m_ds);
66: }
67: if (m_datasources != null) {
68: m_manager.release(m_datasources);
69: }
70: m_ds = null;
71: m_datasources = null;
72: m_manager = null;
73: }
74:
75: }
|