01: /*
02: * Copyright 2002-2005 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.springframework.orm.toplink;
18:
19: import oracle.toplink.exceptions.TopLinkException;
20: import oracle.toplink.sessions.Session;
21: import oracle.toplink.threetier.ServerSession;
22:
23: /**
24: * Full-fledged default implementation of the SessionFactory interface:
25: * creates ClientSessions for a given ServerSession.
26: *
27: * <p>Can create a special ClientSession subclass for managed Sessions, carrying
28: * an active UnitOfWork that expects to be committed at transaction completion
29: * (just like a plain TopLink Session does within a JTA transaction).
30: *
31: * <p>Can also create a transaction-aware Session reference that returns the
32: * active transactional Session on <code>getActiveSession</code>.
33: *
34: * @author Juergen Hoeller
35: * @since 1.2
36: * @see SingleSessionFactory
37: * @see oracle.toplink.sessions.Session#getActiveUnitOfWork()
38: * @see oracle.toplink.sessions.Session#getActiveSession()
39: */
40: public class ServerSessionFactory extends AbstractSessionFactory {
41:
42: private final ServerSession serverSession;
43:
44: /**
45: * Create a new ServerSessionFactory for the given ServerSession.
46: * @param serverSession the TopLink ServerSession to create ClientSessions for
47: */
48: public ServerSessionFactory(ServerSession serverSession) {
49: this .serverSession = serverSession;
50: }
51:
52: /**
53: * Return this factory's ServerSession as-is.
54: */
55: protected Session getMasterSession() {
56: return this .serverSession;
57: }
58:
59: /**
60: * Create a plain ClientSession for this factory's ServerSession.
61: * @see oracle.toplink.threetier.ServerSession#acquireClientSession()
62: */
63: protected Session createClientSession() throws TopLinkException {
64: return this .serverSession.acquireClientSession();
65: }
66:
67: /**
68: * Shut the pre-configured TopLink ServerSession down.
69: * @see oracle.toplink.sessions.DatabaseSession#logout()
70: * @see oracle.toplink.sessions.Session#release()
71: */
72: public void close() {
73: this.serverSession.logout();
74: this.serverSession.release();
75: }
76:
77: }
|