01: /*
02: * GNetWatch
03: * Copyright 2006, 2007 Alexandre Fenyo
04: * gnetwatch@fenyo.net
05: *
06: * This file is part of GNetWatch.
07: *
08: * GNetWatch is free software; you can redistribute it and/or modify
09: * it under the terms of the GNU General Public License as published by
10: * the Free Software Foundation; either version 2 of the License, or
11: * (at your option) any later version.
12: *
13: * GNetWatch is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: * GNU General Public License for more details.
17: *
18: * You should have received a copy of the GNU General Public License
19: * along with GNetWatch; if not, write to the Free Software
20: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21: */
22:
23: package net.fenyo.gnetwatch;
24:
25: import java.io.*;
26:
27: import org.hibernate.*;
28: import org.hibernate.cfg.*;
29:
30: import org.apache.commons.logging.*;
31:
32: /**
33: * This class maintains object-relational mappings.
34: * @author Alexandre Fenyo
35: * @version $Id: Synchro.java,v 1.5 2007/03/03 00:38:20 fenyo Exp $
36: */
37:
38: public class Synchro {
39: private static Log log = LogFactory.getLog(Synchro.class);
40: private final Config config;
41:
42: /**
43: * Constructor.
44: * Reads the configuration properties from the initialization file.
45: * main thread
46: * @param config configuration.
47: */
48: public Synchro(final Config config) {
49: this .config = config;
50:
51: final SessionFactory sessionFactory;
52:
53: new Configuration().configure(new File("hibernate.cfg.xml"));
54:
55: try {
56: // Création de la SessionFactory à partir de hibernate.cfg.xml
57: sessionFactory = new Configuration().configure(
58: new File("hibernate.cfg.xml"))
59: .buildSessionFactory();
60: } catch (Throwable ex) {
61: // Make sure you log the exception, as it might be swallowed
62: System.err
63: .println("Initial SessionFactory creation failed."
64: + ex);
65: throw new ExceptionInInitializerError(ex);
66: }
67: final ThreadLocal session = new ThreadLocal();
68:
69: }
70: }
|