Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/backend/SessionHolder.java @ 2877:f0a67bc0e777 2.7
merged flys-backend/2.7
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:31 +0200 |
parents | 8bd50b41dea6 |
children | 76c75c8b9ee0 |
comparison
equal
deleted
inserted
replaced
2793:6310b1582f2d | 2877:f0a67bc0e777 |
---|---|
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 logger = | |
12 Logger.getLogger(SessionHolder.class); | |
13 | |
14 public static final ThreadLocal<Session> HOLDER = | |
15 new ThreadLocal<Session>() { | |
16 protected Session initialValue() { | |
17 return create(); | |
18 } | |
19 }; | |
20 | |
21 private SessionHolder() { | |
22 } | |
23 | |
24 public synchronized static Session create() { | |
25 logger.debug("create"); | |
26 SessionFactory sessionFactory = | |
27 SessionFactoryProvider.getSessionFactory(); | |
28 return sessionFactory.openSession(); | |
29 } | |
30 | |
31 public static Session acquire() { | |
32 logger.debug("acquire"); | |
33 Session session = create(); | |
34 HOLDER.set(session); | |
35 return session; | |
36 } | |
37 | |
38 public static void release() { | |
39 logger.debug("release"); | |
40 HOLDER.remove(); | |
41 } | |
42 } | |
43 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |