Mercurial > dive4elements > river
comparison flys-backend/src/main/java/de/intevation/flys/backend/SedDBSessionHolder.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 public class SedDBSessionHolder | |
9 { | |
10 private static Logger log = | |
11 Logger.getLogger(SedDBSessionHolder.class); | |
12 | |
13 public static final ThreadLocal<Session> HOLDER = | |
14 new ThreadLocal<Session>() { | |
15 @Override | |
16 protected Session initialValue() { | |
17 return create(); | |
18 } | |
19 }; | |
20 | |
21 private SedDBSessionHolder() { | |
22 } | |
23 | |
24 public synchronized static Session create() { | |
25 log.debug("create"); | |
26 SessionFactory sessionFactory = | |
27 SessionFactoryProvider.getSedDBSessionFactory(); | |
28 return sessionFactory.openSession(); | |
29 } | |
30 | |
31 public static Session acquire() { | |
32 log.debug("acquire"); | |
33 Session session = create(); | |
34 HOLDER.set(session); | |
35 return session; | |
36 } | |
37 | |
38 public static void release() { | |
39 log.debug("release"); | |
40 HOLDER.remove(); | |
41 } | |
42 } | |
43 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |