<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-88  評論-77  文章-48  trackbacks-0

    package com.zte.hibernate.dao;

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStream;
    import java.util.Properties;

    import org.hibernate.HibernateException;
    import org.hibernate.Session;
    import org.hibernate.cfg.Configuration;

    import com.zte.hibernate.domain.Dept;
    import com.zte.hibernate.domain.Emp;

    /**
    ?* Configures and provides access to Hibernate sessions, tied to the
    ?* current thread of execution.? Follows the Thread Local Session
    ?* pattern, see {@linkhttp://hibernate.org/42.html}.
    ?*/
    public class HibernateSessionFactory {

    ??? /**
    ???? * Location of hibernate.cfg.xml file.
    ???? * NOTICE: Location should be on the classpath as Hibernate uses
    ???? * #resourceAsStream style lookup for its configuration file. That
    ???? * is place the config file in a Java package - the default location
    ???? * is the default Java package.<br><br>
    ???? * Examples: <br>
    ???? * <code>CONFIG_FILE_LOCATION = "/hibernate.conf.xml".
    ???? * CONFIG_FILE_LOCATION = "/com/foo/bar/myhiberstuff.conf.xml".</code>
    ???? */
    ??? private static String CONFIG_FILE_LOCATION = "/com/zte/hibernate/dao/hibernate.cfg.xml";

    ??? /** Holds a single instance of Session */
    ?private static final ThreadLocal threadLocal = new ThreadLocal();

    ??? /** The single instance of hibernate configuration */
    ??? private static final Configuration cfg = new Configuration();

    ??? /** The single instance of hibernate SessionFactory */
    ??? private static org.hibernate.SessionFactory sessionFactory;

    ??? /**
    ???? * Returns the ThreadLocal Session instance.? Lazy initialize
    ???? * the <code>SessionFactory</code> if needed.
    ???? *
    ???? *? @return Session
    ???? *? @throws HibernateException
    ???? */
    ??? public static Session currentSession() throws HibernateException {
    ??????? Session session = (Session) threadLocal.get();
    ??????? Properties p = new Properties();
    ??????? InputStream in;
    ??try {
    ???in = new FileInputStream("src/hibernate.properties");
    ???p.load(in);
    ??} catch (FileNotFoundException e1) {
    ???// TODO Auto-generated catch block
    ???e1.printStackTrace();
    ??} catch (IOException e) {
    ???// TODO Auto-generated catch block
    ???e.printStackTrace();
    ??}
    ???????
    ??if (session == null || !session.isOpen()) {
    ???if (sessionFactory == null) {
    ????try {
    ?????cfg.setProperties(p);
    ?????cfg.addClass(Dept.class);
    ?????cfg.addClass(Emp.class);
    ?????//cfg.configure(CONFIG_FILE_LOCATION);
    ?????sessionFactory = cfg.buildSessionFactory();
    ????} catch (Exception e) {
    ?????System.err
    ???????.println("%%%% Error Creating SessionFactory %%%%");
    ?????e.printStackTrace();
    ????}
    ???}
    ???session = (sessionFactory != null) ? sessionFactory.openSession()
    ?????: null;
    ???threadLocal.set(session);
    ??}

    ??????? return session;
    ??? }

    ??? /**
    ???? *? Close the single hibernate session instance.
    ???? *
    ???? *? @throws HibernateException
    ???? */
    ??? public static void closeSession() throws HibernateException {
    ??????? Session session = (Session) threadLocal.get();
    ??????? threadLocal.set(null);

    ??????? if (session != null) {
    ??????????? session.close();
    ??????? }
    ??? }

    ??? /**
    ???? * Default constructor.
    ???? */
    ??? private HibernateSessionFactory() {
    ??? }

    }

    posted on 2006-05-18 16:50 崛起的程序員 閱讀(679) 評論(0)  編輯  收藏 所屬分類: java
    主站蜘蛛池模板: 一个人免费视频观看在线www| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 国产午夜免费福利红片| 国产精品成人四虎免费视频| 亚洲成网777777国产精品| JLZZJLZZ亚洲乱熟无码| 久久噜噜噜久久亚洲va久| 亚洲一级毛片免费在线观看| 亚洲av永久中文无码精品综合 | 香蕉视频亚洲一级| 好湿好大好紧好爽免费视频| 中文字幕免费高清视频| 免费黄色网址入口| 久久久亚洲精品蜜桃臀 | 亚洲色一色噜一噜噜噜| 婷婷精品国产亚洲AV麻豆不片| 亚洲不卡视频在线观看| 香蕉视频亚洲一级| 久草免费福利视频| 猫咪社区免费资源在线观看| 亚洲精品WWW久久久久久 | 亚洲人成电影福利在线播放| 亚洲综合精品第一页| 9久热精品免费观看视频| 国产成人精品免费午夜app| 免费又黄又爽又猛的毛片| 亚洲视频免费在线观看| 亚洲AV无码一区二区三区性色| 精品无码国产污污污免费网站国产| 每天更新的免费av片在线观看| 在线观看免费为成年视频| 亚洲理论电影在线观看| 亚洲中文字幕无码av永久| 91精品成人免费国产| 好男人视频在线观看免费看片| 亚洲中文字幕无码爆乳AV| 久久综合久久综合亚洲| 免费看黄的成人APP| 国产网站免费观看| 亚洲综合区图片小说区| 一区二区视频在线免费观看|