comparison flys-backend/src/main/java/de/intevation/flys/backend/SessionHolder.java @ 3471:e4250c6e1538 2.8.1

merged flys-backend/2.8.1
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:40 +0200
parents 76c75c8b9ee0
children
comparison
equal deleted inserted replaced
3468:f37e7e8907cb 3471:e4250c6e1538
1 package de.intevation.flys.backend;
2
3 import org.apache.log4j.Logger;
4
5 import org.hibernate.Session;
6 import org.hibernate.SessionFactory;
7
8
9 public class SessionHolder
10 {
11 private static Logger log =
12 Logger.getLogger(SessionHolder.class);
13
14 public static final ThreadLocal<Session> HOLDER =
15 new ThreadLocal<Session>() {
16 @Override
17 protected Session initialValue() {
18 return create();
19 }
20 };
21
22 private SessionHolder() {
23 }
24
25 public synchronized static Session create() {
26 log.debug("create");
27 SessionFactory sessionFactory =
28 SessionFactoryProvider.getSessionFactory();
29 return sessionFactory.openSession();
30 }
31
32 public static Session acquire() {
33 log.debug("acquire");
34 Session session = create();
35 HOLDER.set(session);
36 return session;
37 }
38
39 public static void release() {
40 log.debug("release");
41 HOLDER.remove();
42 }
43 }
44 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org