comparison flys-backend/src/main/java/de/intevation/flys/backend/SessionHolder.java @ 3333:76c75c8b9ee0

SedDB: Make access to SedDB configurable over conf.xml and provide access to sessions. flys-backend/trunk@4666 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Thu, 14 Jun 2012 15:39:42 +0000
parents 8bd50b41dea6
children
comparison
equal deleted inserted replaced
3332:aa8ed778c8cc 3333:76c75c8b9ee0
6 import org.hibernate.SessionFactory; 6 import org.hibernate.SessionFactory;
7 7
8 8
9 public class SessionHolder 9 public class SessionHolder
10 { 10 {
11 private static Logger logger = 11 private static Logger log =
12 Logger.getLogger(SessionHolder.class); 12 Logger.getLogger(SessionHolder.class);
13 13
14 public static final ThreadLocal<Session> HOLDER = 14 public static final ThreadLocal<Session> HOLDER =
15 new ThreadLocal<Session>() { 15 new ThreadLocal<Session>() {
16 @Override
16 protected Session initialValue() { 17 protected Session initialValue() {
17 return create(); 18 return create();
18 } 19 }
19 }; 20 };
20 21
21 private SessionHolder() { 22 private SessionHolder() {
22 } 23 }
23 24
24 public synchronized static Session create() { 25 public synchronized static Session create() {
25 logger.debug("create"); 26 log.debug("create");
26 SessionFactory sessionFactory = 27 SessionFactory sessionFactory =
27 SessionFactoryProvider.getSessionFactory(); 28 SessionFactoryProvider.getSessionFactory();
28 return sessionFactory.openSession(); 29 return sessionFactory.openSession();
29 } 30 }
30 31
31 public static Session acquire() { 32 public static Session acquire() {
32 logger.debug("acquire"); 33 log.debug("acquire");
33 Session session = create(); 34 Session session = create();
34 HOLDER.set(session); 35 HOLDER.set(session);
35 return session; 36 return session;
36 } 37 }
37 38
38 public static void release() { 39 public static void release() {
39 logger.debug("release"); 40 log.debug("release");
40 HOLDER.remove(); 41 HOLDER.remove();
41 } 42 }
42 } 43 }
43 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 44 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org