KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > orm > toplink > ServerSessionFactory


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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     /**
46      * Create a new ServerSessionFactory for the given ServerSession.
47      * @param serverSession the TopLink ServerSession to create ClientSessions for
48      */

49     public ServerSessionFactory(ServerSession serverSession) {
50         this.serverSession = serverSession;
51     }
52
53
54     /**
55      * Return this factory's ServerSession as-is.
56      */

57     protected Session getMasterSession() {
58         return this.serverSession;
59     }
60
61     /**
62      * Create a plain ClientSession for this factory's ServerSession.
63      * @see oracle.toplink.threetier.ServerSession#acquireClientSession()
64      */

65     protected Session createClientSession() throws TopLinkException {
66         return this.serverSession.acquireClientSession();
67     }
68
69
70     /**
71      * Shut the pre-configured TopLink ServerSession down.
72      * @see oracle.toplink.sessions.DatabaseSession#logout()
73      * @see oracle.toplink.sessions.Session#release()
74      */

75     public void close() {
76         this.serverSession.logout();
77         this.serverSession.release();
78     }
79
80 }
81
Popular Tags