01: // Copyright 2007 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.hibernate;
16:
17: import org.hibernate.Session;
18:
19: /**
20: * Manages the Hibernate session for the current thread. This includes creating the session as
21: * needed, allowing the session to checkpoint (commit the current transaction and continue) and
22: * commit the transaction automatically at the end of the request.
23: * <p>
24: * Remember that in Tapestry, action requests and render requests are entirely seperate, and you
25: * will see a seperate request and a seperate transaction for each. Care should be taken to ensure
26: * that entity objects that are retained (in the session, as persistent field values) between
27: * requests are handled correct (they tend to become detached instances).
28: * <p>
29: * This implementation of this service is per-thread.
30: */
31: public interface HibernateSessionManager {
32: /**
33: * Gets the active session for this request, creating it as necessary. When the session is first
34: * created, a transaction is started.
35: *
36: * @return the request's session
37: * @see HibernateSessionSource
38: */
39: Session getSession();
40:
41: /**
42: * Commits the current transaction (which will cause a flush of data to the database), then starts
43: * a new transaction to replace it.
44: */
45: void commit();
46:
47: /**
48: * Aborts the current transaction, and starts a new tranasction to replace it.
49: */
50: void abort();
51: }
|