1 16 package org.apache.cocoon.components.cron; 17 18 import java.sql.Connection ; 19 import java.sql.SQLException ; 20 21 import org.apache.avalon.excalibur.datasource.DataSourceComponent; 22 import org.apache.avalon.framework.configuration.ConfigurationException; 23 import org.apache.avalon.framework.service.ServiceException; 24 import org.apache.avalon.framework.service.ServiceManager; 25 import org.apache.avalon.framework.service.ServiceSelector; 26 import org.quartz.utils.ConnectionProvider; 27 28 32 public class DataSourceComponentConnectionProvider implements ConnectionProvider { 33 34 private ServiceManager m_manager; 35 private ServiceSelector m_datasources; 36 private DataSourceComponent m_ds; 37 38 public DataSourceComponentConnectionProvider(String dsName, ServiceManager manager) throws ConfigurationException { 39 m_manager = manager; 40 try { 41 m_datasources = (ServiceSelector) m_manager.lookup(DataSourceComponent.ROLE + "Selector"); 42 m_ds = (DataSourceComponent) m_datasources.select(dsName); 43 } 44 catch (ServiceException e) { 45 throw new ConfigurationException("No datasource available by that name: " + dsName); 46 } 47 } 48 49 52 public Connection getConnection() throws SQLException { 53 return m_ds.getConnection(); 54 } 55 56 59 public void shutdown() throws SQLException { 60 if (m_ds != null) { 61 m_datasources.release(m_ds); 62 } 63 if (m_datasources != null) { 64 m_manager.release(m_datasources); 65 } 66 m_ds = null; 67 m_datasources = null; 68 m_manager = null; 69 } 70 71 } 72 | Popular Tags |