Package dnb

Source Code of dnb.HibernateUtil

package dnb;

import java.io.FileInputStream;
import java.sql.Statement;
import java.util.logging.LogManager;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import dnb.data.impl.ArtistHibernateImpl;
import dnb.data.impl.GenreHibernateImpl;
import dnb.data.impl.LabelHibernateImpl;
import dnb.data.impl.LabelcodeHibernateImpl;

public class HibernateUtil {
  private static final SessionFactory sessionFactory;
  static {
    try {
      LogManager.getLogManager().readConfiguration(new FileInputStream("logging.properties"));
      sessionFactory = new AnnotationConfiguration()
          .addAnnotatedClass(ArtistHibernateImpl.class)
          .addAnnotatedClass(GenreHibernateImpl.class)
          .addAnnotatedClass(LabelHibernateImpl.class)
          .addAnnotatedClass(LabelcodeHibernateImpl.class)
          .configure()
          .buildSessionFactory();
    } catch (Throwable ex) {
      // Log exception!
      throw new ExceptionInInitializerError(ex);
    }
//    Enumeration<String> names = LogManager.getLogManager().getLoggerNames();
//    while(names.hasMoreElements()) {
//      System.out.println(names.nextElement());
//    }
  }
 
  public static SessionFactory getSessionFactory() throws HibernateException {
    return sessionFactory;
  }
 
  public static void shutdown() {
    try {
      Session session = sessionFactory.openSession();
      Statement stmt = session.connection().createStatement();
      stmt.execute("SHUTDOWN");
      session.close();
      sessionFactory.close();
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}
TOP

Related Classes of dnb.HibernateUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.