1 package org.splat.dal.dao.kernel;
4 * @author Daniel Brunier-Coulin
5 * @copyright OPEN CASCADE 2012
8 import org.hibernate.Session;
9 import org.hibernate.SessionFactory;
10 import org.springframework.beans.BeansException;
11 import org.springframework.context.ApplicationContext;
12 import org.springframework.context.ApplicationContextAware;
13 import org.apache.log4j.Logger;
16 public abstract class Database implements ApplicationContextAware {
19 * The ApplicationContext.
21 private static ApplicationContext _context = null;
24 * Spring will call this method for initialize the applicationContext.
25 * @param ctx the application context
26 * @throws BeansException the BeanException
28 public void setApplicationContext(final ApplicationContext ctx) throws BeansException {
33 * Static for getting the context.
34 * @return ApplicationContext the application context
36 public static ApplicationContext getContext() {
40 // private static String CONFIG_FILE = "/hibernate.cfg.xml";
41 private static SessionFactory mySessionFactory = null;
43 protected final static Logger logger = Logger.getLogger(Database.class);
45 // ==============================================================================================================================
47 // ==============================================================================================================================
49 public static Session getSession () {
50 // -----------------------------------
51 return getInstance().getCurrentSession();
54 // ==============================================================================================================================
56 // ==============================================================================================================================
58 protected String getSchemaVersion () {
59 // ------------------------------------
60 return null;//TODO: Get schema version into specific object/table: getIDPool().getSchemaVersion();
63 protected void setSchemaVersion (String version) {
64 // ------------------------------------------------
65 //TODO: Set schema version into specific object/table: myIDpool = new IDPool(version);
66 // getSession().save(myIDpool);
69 // ==============================================================================================================================
71 // ==============================================================================================================================
73 private static SessionFactory getInstance () {
74 // --------------------------------------------
75 if (mySessionFactory == null) {
76 // org.hibernate.cfg.Configuration cfg = new org.hibernate.cfg.Configuration();
78 mySessionFactory = getContext().getBean(SessionFactory.class);
79 // cfg.configure(); // The configuration file (hibernate.cfg.xml)) is supposed to be on the classpath
80 // mySessionFactory = cfg.buildSessionFactory();
82 catch (Exception error) {
83 logger.fatal("Could not initialize the Hibernate configuration, reason:", error);
86 return mySessionFactory;