ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
Source/Service/ServiceBase/src/com/vci/server/base/persistence/dao/HibernateSessionFactory.java
@@ -1,15 +1,11 @@
package com.vci.server.base.persistence.dao;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;
import java.util.Enumeration;
import java.util.List;
import java.util.ArrayList;
import org.dom4j.Attribute;
import org.dom4j.Document;
import org.dom4j.DocumentException;
@@ -44,8 +40,8 @@
     */
   //private static final Log log = LogFactory.getLog(HibernateSessionFactory.class);
   private static String CONFIG_FILE_LOCATION="properties/hibernate.cfg.xml";
   //private static String MAP_FILE_RESOURCE="/properties/hibernate.map.xml";
   private static String MAP_FILE_RESOURCE="hibernate.map.xml";
   private static String MAP_FILE_RESOURCE="/properties/hibernate.map.xml";
   //private static String MAP_FILE_RESOURCE="hibernate.map.xml";
   
   private static final ThreadLocal<VciSession> threadLocal = new ThreadLocal<VciSession>();
   private static Configuration configuration = new Configuration();  
@@ -61,7 +57,9 @@
         
         configuration.configure(file);
         
         //loadHbmFiles();
         ServerWithLog4j.logger.info("加载Hibernate对象映射:Begin");
         loadHbmFiles();
         ServerWithLog4j.logger.info("加载Hibernate对象映射:End");
         
         sessionFactory = configuration.buildSessionFactory();
      } catch (Exception e) {
@@ -130,7 +128,9 @@
         File file = new File(CONFIG_FILE_LOCATION);
         configuration.configure(file);
         ServerWithLog4j.logger.info("加载Hibernate对象映射:Begin");
         loadHbmFiles();
         ServerWithLog4j.logger.info("加载Hibernate对象映射:End");
           
         sessionFactory = configuration.buildSessionFactory();
      } catch (Exception e) {
@@ -235,16 +235,16 @@
   }
   
   private static void loadHbmFiles() {
      ServerWithLog4j.logger.info("加载Hibernate对象映射");
      try {
         List<InputStream> iss = loadResources(MAP_FILE_RESOURCE, HibernateSessionFactory.class.getClassLoader());
           //InputStream is = HibernateSessionFactory.class.getResourceAsStream(MAP_FILE_RESOURCE);
           //if (is != null)
         for (InputStream is : iss)
         //List<InputStream> iss = loadResources(MAP_FILE_RESOURCE, HibernateSessionFactory.class.getClassLoader());
         //List<InputStream> iss = loadResources(MAP_FILE_RESOURCE, null);
           InputStream is = HibernateSessionFactory.class.getResourceAsStream(MAP_FILE_RESOURCE);
         //for (InputStream is : iss)
           if (is != null)
           {
              SAXReader reader = new SAXReader();
              Document doc;
               doc = reader.read(is);
            doc = reader.read(is);
              Element root = doc.getRootElement();
              List<?> lst = root.elements("mapping");
              
@@ -260,20 +260,19 @@
         // TODO Auto-generated catch block
         e.printStackTrace();
         ServerWithLog4j.logger.error("加载对象映射失败", e);
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }        
   }
   
   private static List<InputStream> loadResources(final String name, final ClassLoader classLoader) throws IOException {
       final List<InputStream> list = new ArrayList<InputStream>();
       final Enumeration<URL> systemResources =
               (classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader)
               .getResources(name);
       while (systemResources.hasMoreElements()) {
           list.add(systemResources.nextElement().openStream());
       }
       return list;
   }
//   private static List<InputStream> loadResources(final String name, final ClassLoader classLoader) throws IOException {
//       final List<InputStream> list = new ArrayList<InputStream>();
//       final Enumeration<URL> systemResources =
//               (classLoader == null ? ClassLoader.getSystemClassLoader() : classLoader)
//               .getResources(name);
//       while (systemResources.hasMoreElements()) {
//          ServerWithLog4j.logger.info(MAP_FILE_RESOURCE + ":" + systemResources.nextElement().getPath());
//
//           list.add(systemResources.nextElement().openStream());
//       }
//       return list;
//   }
}