Coverage report

  %line %branch
org.apache.torque.dsfactory.SharedPoolDataSourceFactory
79% 
86% 

 1  
 package org.apache.torque.dsfactory;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one
 5  
  * or more contributor license agreements.  See the NOTICE file
 6  
  * distributed with this work for additional information
 7  
  * regarding copyright ownership.  The ASF licenses this file
 8  
  * to you under the Apache License, Version 2.0 (the
 9  
  * "License"); you may not use this file except in compliance
 10  
  * with the License.  You may obtain a copy of the License at
 11  
  *
 12  
  *   http://www.apache.org/licenses/LICENSE-2.0
 13  
  *
 14  
  * Unless required by applicable law or agreed to in writing,
 15  
  * software distributed under the License is distributed on an
 16  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 17  
  * KIND, either express or implied.  See the License for the
 18  
  * specific language governing permissions and limitations
 19  
  * under the License.
 20  
  */
 21  
 
 22  
 import javax.sql.ConnectionPoolDataSource;
 23  
 import javax.sql.DataSource;
 24  
 
 25  
 import org.apache.commons.configuration.Configuration;
 26  
 
 27  
 import org.apache.commons.dbcp.datasources.SharedPoolDataSource;
 28  
 
 29  
 import org.apache.commons.logging.Log;
 30  
 import org.apache.commons.logging.LogFactory;
 31  
 
 32  
 import org.apache.torque.Torque;
 33  
 import org.apache.torque.TorqueException;
 34  
 
 35  
 /**
 36  
  * A factory that looks up the DataSource using the JDBC2 pool methods.
 37  
  *
 38  
  * @author <a href="mailto:jmcnally@apache.org">John McNally</a>
 39  
  * @author <a href="mailto:hps@intermeta.de">Henning P. Schmiedehausen</a>
 40  
  * @version $Id: SharedPoolDataSourceFactory.java 476550 2006-11-18 16:08:37Z tfischer $
 41  
  */
 42  100
 public class SharedPoolDataSourceFactory
 43  
     extends AbstractDataSourceFactory
 44  
 {
 45  
 
 46  
     /** The log. */
 47  92
     private static Log log
 48  92
             = LogFactory.getLog(SharedPoolDataSourceFactory.class);
 49  
 
 50  
     /** The wrapped <code>DataSource</code>. */
 51  92
     private SharedPoolDataSource ds = null;
 52  
 
 53  
     /**
 54  
      * @see org.apache.torque.dsfactory.DataSourceFactory#getDataSource
 55  
      */
 56  
     public DataSource getDataSource()
 57  
     {
 58  0
         return ds;
 59  
     }
 60  
 
 61  
     /**
 62  
      * @see org.apache.torque.dsfactory.DataSourceFactory#initialize
 63  
      */
 64  
     public void initialize(Configuration configuration) throws TorqueException
 65  
     {
 66  92
         super.initialize(configuration);
 67  
 
 68  92
         ConnectionPoolDataSource cpds = initCPDS(configuration);
 69  92
         SharedPoolDataSource dataSource = initJdbc2Pool(configuration);
 70  92
         dataSource.setConnectionPoolDataSource(cpds);
 71  92
         this.ds = dataSource;
 72  92
     }
 73  
 
 74  
     /**
 75  
      * Initializes the Jdbc2PoolDataSource.
 76  
      *
 77  
      * @param configuration where to read the settings from
 78  
      * @throws TorqueException if a property set fails
 79  
      * @return a configured <code>Jdbc2PoolDataSource</code>
 80  
      */
 81  
     private SharedPoolDataSource initJdbc2Pool(Configuration configuration)
 82  
         throws TorqueException
 83  
     {
 84  92
         log.debug("Starting initJdbc2Pool");
 85  92
         SharedPoolDataSource dataSource = new SharedPoolDataSource();
 86  92
         Configuration c = Torque.getConfiguration();
 87  
 
 88  92
         if (c == null || c.isEmpty())
 89  
         {
 90  0
             log.warn("Global Configuration not set,"
 91  
                     + " no Default pool data source configured!");
 92  0
         }
 93  
         else
 94  
         {
 95  92
             Configuration conf = c.subset(DEFAULT_POOL_KEY);
 96  92
             applyConfiguration(conf, dataSource);
 97  
         }
 98  
 
 99  92
         Configuration conf = configuration.subset(POOL_KEY);
 100  92
         applyConfiguration(conf, dataSource);
 101  92
         return dataSource;
 102  
     }
 103  
 
 104  
 
 105  
     /**
 106  
      * Closes the pool associated with this factory and releases it.
 107  
      * @throws TorqueException if the pool cannot be closed properly
 108  
      */
 109  
     public void close() throws TorqueException
 110  
     {
 111  
         try
 112  
         {
 113  23
             ds.close();
 114  
         }
 115  23
         catch (Exception e)
 116  
         {
 117  23
             log.error("Exception caught during close()", e);
 118  23
             throw new TorqueException(e);
 119  0
         }
 120  0
         ds = null;
 121  0
     }
 122  
 }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.