Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/context/SessionCallContextListener.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/context/SessionCallContextListener.java@94c176fdcb89 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.context; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import org.w3c.dom.Document; | |
6 import org.w3c.dom.Node; | |
7 | |
8 import org.hibernate.Session; | |
9 | |
10 import org.dive4elements.river.backend.SessionHolder; | |
11 | |
12 import org.dive4elements.artifacts.CallContext; | |
13 import org.dive4elements.artifacts.CallContext.Listener; | |
14 | |
15 | |
16 /** | |
17 * This CallContextListener is used to initialize a ThreadLocal variable in | |
18 * each CallContext (for each request) that holds Sessions. | |
19 * | |
20 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
21 */ | |
22 public class SessionCallContextListener implements Listener { | |
23 | |
24 public static final String SESSION_KEY = "context.session"; | |
25 | |
26 /** The logger that is used in this class.*/ | |
27 private static Logger logger = | |
28 Logger.getLogger(SessionCallContextListener.class); | |
29 | |
30 | |
31 public SessionCallContextListener() { | |
32 } | |
33 | |
34 | |
35 public void setup(Document config, Node listenerConfig) { | |
36 // nothing to do here | |
37 } | |
38 | |
39 | |
40 /** | |
41 * Initializes a ThreadLocal variable that is used to hold sessions. | |
42 * | |
43 * @param context The CallContext. | |
44 */ | |
45 public void init(CallContext context) { | |
46 logger.debug("SessionCallContextListener.init"); | |
47 | |
48 Session session = SessionHolder.acquire(); | |
49 | |
50 context.putContextValue(SESSION_KEY, session); | |
51 } | |
52 | |
53 | |
54 /** | |
55 * Closes open sessions of the ThreadLocal variable opened in init(). | |
56 * | |
57 * @param context The CallContext. | |
58 */ | |
59 public void close(CallContext context) { | |
60 logger.debug("SessionCallContextListener.close"); | |
61 | |
62 Session session = (Session)context.getContextValue(SESSION_KEY); | |
63 session.close(); | |
64 | |
65 SessionHolder.release(); | |
66 } | |
67 } | |
68 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |