comparison backend/src/main/java/org/dive4elements/river/backend/SessionHolder.java @ 8567:9bbce0edd36b

(issue1797) Increase session debug output
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 24 Feb 2015 18:32:18 +0100
parents fe7e9da6312a
children 5c53b7de04d9
comparison
equal deleted inserted replaced
8566:fe7e9da6312a 8567:9bbce0edd36b
21 21
22 public static final ThreadLocal<Session> HOLDER = 22 public static final ThreadLocal<Session> HOLDER =
23 new ThreadLocal<Session>() { 23 new ThreadLocal<Session>() {
24 @Override 24 @Override
25 protected Session initialValue() { 25 protected Session initialValue() {
26 return create(); 26 Session session = create();
27 log.debug("Initial session value: " + session.hashCode());
28 return session;
27 } 29 }
28 }; 30 };
29 31
30 protected SessionHolder() { 32 protected SessionHolder() {
31 } 33 }
36 SessionFactoryProvider.getSessionFactory(); 38 SessionFactoryProvider.getSessionFactory();
37 return sessionFactory.openSession(); 39 return sessionFactory.openSession();
38 } 40 }
39 41
40 public static Session acquire() { 42 public static Session acquire() {
41 log.debug("acquire");
42 Session session = create(); 43 Session session = create();
44 log.debug("acquired session: " + session.hashCode());
43 HOLDER.set(session); 45 HOLDER.set(session);
44 return session; 46 return session;
45 } 47 }
46 48
47 public static void release() { 49 public static void release() {
48 log.debug("release");
49 Session session = HOLDER.get(); 50 Session session = HOLDER.get();
50 if (session != null) { 51 if (session != null) {
52 log.debug("releasing session: " + session.hashCode());
51 try { 53 try {
52 if (!session.isOpen()) { 54 if (!session.isOpen()) {
53 /* If this check really works in all cases why does hibernate 55 /* If this check really works in all cases why does hibernate
54 * does not use it when you call close anyway. */ 56 * does not use it when you call close anyway. */
55 log.debug("Session is not open. Calling close anyway."); 57 log.debug("Session is not open. Calling close anyway.");
61 * According to doc this should only throw a HibernateException but 63 * According to doc this should only throw a HibernateException but
62 * we definetely get NPE's here. 64 * we definetely get NPE's here.
63 */ 65 */
64 log.error("Exception caught on session close! Session already closed?" + e.getMessage()); 66 log.error("Exception caught on session close! Session already closed?" + e.getMessage());
65 } 67 }
68 } else {
69 log.debug("release called on NULL session.");
66 } 70 }
67 HOLDER.remove(); 71 HOLDER.remove();
68 } 72 }
69 } 73 }
70 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 74 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org