Subversion Repositories WebE

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
33 PointedEar 1
/*
2
 * Hibernate, Relational Persistence for Idiomatic Java
3
 *
4
 * Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
5
 * indicated by the @author tags or express copyright attribution
6
 * statements applied by the authors.  All third-party contributions are
7
 * distributed under license by Red Hat Middleware LLC.
8
 *
9
 * This copyrighted material is made available to anyone wishing to use, modify,
10
 * copy, or redistribute it subject to the terms and conditions of the GNU
11
 * Lesser General Public License, as published by the Free Software Foundation.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
16
 * for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this distribution; if not, write to:
20
 * Free Software Foundation, Inc.
21
 * 51 Franklin Street, Fifth Floor
22
 * Boston, MA  02110-1301  USA
23
 *
24
 */
25
package org.hibernate;
26
 
27
import javax.transaction.Synchronization;
28
 
29
/**
30
 * Allows the application to define units of work, while
31
 * maintaining abstraction from the underlying transaction
32
 * implementation (eg. JTA, JDBC).<br>
33
 * <br>
34
 * A transaction is associated with a <tt>Session</tt> and is
35
 * usually instantiated by a call to <tt>Session.beginTransaction()</tt>.
36
 * A single session might span multiple transactions since
37
 * the notion of a session (a conversation between the application
38
 * and the datastore) is of coarser granularity than the notion of
39
 * a transaction. However, it is intended that there be at most one
40
 * uncommitted <tt>Transaction</tt> associated with a particular
41
 * <tt>Session</tt> at any time.<br>
42
 * <br>
43
 * Implementors are not intended to be threadsafe.
44
 *
45
 * @see Session#beginTransaction()
46
 * @see org.hibernate.transaction.TransactionFactory
47
 * @author Anton van Straaten
48
 */
49
public interface Transaction {
50
 
51
        /**
52
         * Begin a new transaction.
53
         */
54
        public void begin() throws HibernateException;
55
 
56
        /**
57
         * Flush the associated <tt>Session</tt> and end the unit of work (unless
58
         * we are in {@link FlushMode#MANUAL}.
59
         * </p>
60
         * This method will commit the underlying transaction if and only
61
         * if the underlying transaction was initiated by this object.
62
         *
63
         * @throws HibernateException
64
         */
65
        public void commit() throws HibernateException;
66
 
67
        /**
68
         * Force the underlying transaction to roll back.
69
         *
70
         * @throws HibernateException
71
         */
72
        public void rollback() throws HibernateException;
73
 
74
        /**
75
         * Was this transaction rolled back or set to rollback only?
76
         * <p/>
77
         * This only accounts for actions initiated from this local transaction.
78
         * If, for example, the underlying transaction is forced to rollback via
79
         * some other means, this method still reports false because the rollback
80
         * was not initiated from here.
81
         *
82
         * @return boolean True if the transaction was rolled back via this
83
         * local transaction; false otherwise.
84
         * @throws HibernateException
85
         */
86
        public boolean wasRolledBack() throws HibernateException;
87
 
88
        /**
89
         * Check if this transaction was successfully committed.
90
         * <p/>
91
         * This method could return <tt>false</tt> even after successful invocation
92
         * of {@link #commit}.  As an example, JTA based strategies no-op on
93
         * {@link #commit} calls if they did not start the transaction; in that case,
94
         * they also report {@link #wasCommitted} as false.
95
         *
96
         * @return boolean True if the transaction was (unequivocally) committed
97
         * via this local transaction; false otherwise.
98
         * @throws HibernateException
99
         */
100
        public boolean wasCommitted() throws HibernateException;
101
 
102
        /**
103
         * Is this transaction still active?
104
         * <p/>
105
         * Again, this only returns information in relation to the
106
         * local transaction, not the actual underlying transaction.
107
         *
108
         * @return boolean Treu if this local transaction is still active.
109
         */
110
        public boolean isActive() throws HibernateException;
111
 
112
        /**
113
         * Register a user synchronization callback for this transaction.
114
         *
115
         * @param synchronization The Synchronization callback to register.
116
         * @throws HibernateException
117
         */
118
        public void registerSynchronization(Synchronization synchronization)
119
        throws HibernateException;
120
 
121
        /**
122
         * Set the transaction timeout for any transaction started by
123
         * a subsequent call to <tt>begin()</tt> on this instance.
124
         *
125
         * @param seconds The number of seconds before a timeout.
126
         */
127
        public void setTimeout(int seconds);
128
}