Clover coverage report - JFox Service-Oriented Application Framework - 1.0-RC3
Coverage timestamp: 星期三 二月 15 2006 18:10:22 CST
file stats: LOC: 119   Methods: 5
NCLOC: 54   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
SessionFactoryServiceImpl.java 75% 88.2% 80% 84.6%
coverage coverage
 1   
 /**
 2   
  * @(#)SessionFactoryServiceImpl.java
 3   
  * 
 4   
  * JFoxSOAF, Service-Oriented Application Framework
 5   
  * 
 6   
  * Copyright(c) JFoxSOAF Team
 7   
  * 
 8   
  * Licensed under the GNU LGPL, Version 2.1 (the "License"); 
 9   
  * you may not use this file except in compliance with the License. 
 10   
  * You may obtain a copy of the License at  
 11   
  * 
 12   
  * http://www.gnu.org/copyleft/lesser.html
 13   
  * 
 14   
  * Unless required by applicable law or agreed to in writing, software
 15   
  * distributed under the License is distributed on an "AS IS" BASIS, 
 16   
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 17   
  * See the License for the specific language governing permissions and 
 18   
  * limitations under the License. 
 19   
  * 
 20   
  * For more information, please visit:
 21   
  * http://sourceforge.net/projects/jfox 
 22   
  */
 23   
 
 24   
 package org.huihoo.jfox.soaf.services.persistence;
 25   
 
 26   
 import java.io.IOException;
 27   
 import java.util.HashMap;
 28   
 import java.util.Iterator;
 29   
 import java.util.Properties;
 30   
 import java.util.Set;
 31   
 
 32   
 import net.sf.hibernate.HibernateException;
 33   
 import net.sf.hibernate.SessionFactory;
 34   
 import net.sf.hibernate.cfg.Configuration;
 35   
 
 36   
 import org.apache.commons.logging.Log;
 37   
 import org.apache.commons.logging.LogFactory;
 38   
 import org.huihoo.jfox.soaf.util.resource.ResourceHelper;
 39   
 import org.picocontainer.Startable;
 40   
 
 41   
 /**
 42   
  * <p>
 43   
  * SessionFactory Service Implementation
 44   
  * </p>
 45   
  * 
 46   
  * @author <a href="mailto:founder_chen@yahoo.com.cn">Peter Cheng </a>
 47   
  * @version $Revision: 1.1 $ $Date: 2006/02/15 08:45:45 $
 48   
  * @version Revision: 1.0
 49   
  */
 50   
 
 51   
 public class SessionFactoryServiceImpl implements SessionFactoryService,
 52   
         Startable {
 53   
     
 54   
     private final Log logger = LogFactory.getLog(getClass());
 55   
 
 56   
     private static String HIBERNATE_MULTI_CONFIG = "hibernate-multi.properties";
 57   
 
 58   
     private static String HIBERNATE_DEFAULT_CONFIG = "hibernate.default";
 59   
 
 60   
     private Properties props;
 61   
 
 62   
     private HashMap hashMap = new HashMap();
 63   
 
 64   
     /**
 65   
      * @see org.huihoo.jfox.soaf.services.persistence.SessionFactoryService#getSessionFactory(java.lang.String)
 66   
      */
 67  5
     public SessionFactory getSessionFactory(String key) {
 68  5
         if (key == null) {
 69  5
             return (SessionFactory) hashMap.get(HIBERNATE_DEFAULT_CONFIG);
 70   
         } else {
 71  0
             return (SessionFactory) hashMap.get(key);
 72   
         }
 73   
     }
 74   
 
 75   
     /**
 76   
      * @see org.picocontainer.Startable#start()
 77   
      */
 78  10
     public void start() {
 79  10
         loadConfig();
 80   
     }
 81   
 
 82   
     /**
 83   
      * Load configuation.
 84   
      */
 85  10
     private void loadConfig() {
 86  10
         try {
 87  10
             props = ResourceHelper
 88   
                     .getResourceAsProperties(HIBERNATE_MULTI_CONFIG);
 89  10
             Set set = props.keySet();
 90  10
             Iterator iter = set.iterator();
 91  10
             while (iter.hasNext()) {
 92  20
                 String key = (String) iter.next();
 93  20
                 String value = props.getProperty(key);
 94  20
                 buildFactory(key, value);
 95   
             }
 96   
         } catch (Exception e) {
 97  0
             logger.error("Hibernate multi configuration initialization failed ", e);
 98   
         }
 99   
     }
 100   
 
 101   
     /**
 102   
      * @param key
 103   
      * @param value
 104   
      * @throws HibernateException
 105   
      */
 106  20
     private void buildFactory(String key, String value)
 107   
             throws HibernateException, IOException {
 108  20
         Configuration config = new Configuration();
 109  20
         config.configure(ResourceHelper.getResourceURL(value));
 110  20
         SessionFactory sessionFactory = config.buildSessionFactory();
 111  20
         hashMap.put(key, sessionFactory);
 112   
     }
 113   
 
 114   
     /**
 115   
      * @see org.picocontainer.Startable#stop()
 116   
      */
 117  0
     public void stop() {
 118   
     }
 119   
 }