001: //$Id: Transaction.java 9595 2006-03-10 18:14:21Z steve.ebersole@jboss.com $
002: package org.hibernate;
003:
004: import javax.transaction.Synchronization;
005:
006: /**
007: * Allows the application to define units of work, while
008: * maintaining abstraction from the underlying transaction
009: * implementation (eg. JTA, JDBC).<br>
010: * <br>
011: * A transaction is associated with a <tt>Session</tt> and is
012: * usually instantiated by a call to <tt>Session.beginTransaction()</tt>.
013: * A single session might span multiple transactions since
014: * the notion of a session (a conversation between the application
015: * and the datastore) is of coarser granularity than the notion of
016: * a transaction. However, it is intended that there be at most one
017: * uncommitted <tt>Transaction</tt> associated with a particular
018: * <tt>Session</tt> at any time.<br>
019: * <br>
020: * Implementors are not intended to be threadsafe.
021: *
022: * @see Session#beginTransaction()
023: * @see org.hibernate.transaction.TransactionFactory
024: * @author Anton van Straaten
025: */
026: public interface Transaction {
027:
028: /**
029: * Begin a new transaction.
030: */
031: public void begin() throws HibernateException;
032:
033: /**
034: * Flush the associated <tt>Session</tt> and end the unit of work (unless
035: * we are in {@link FlushMode#NEVER}.
036: * </p>
037: * This method will commit the underlying transaction if and only
038: * if the underlying transaction was initiated by this object.
039: *
040: * @throws HibernateException
041: */
042: public void commit() throws HibernateException;
043:
044: /**
045: * Force the underlying transaction to roll back.
046: *
047: * @throws HibernateException
048: */
049: public void rollback() throws HibernateException;
050:
051: /**
052: * Was this transaction rolled back or set to rollback only?
053: * <p/>
054: * This only accounts for actions initiated from this local transaction.
055: * If, for example, the underlying transaction is forced to rollback via
056: * some other means, this method still reports false because the rollback
057: * was not initiated from here.
058: *
059: * @return boolean True if the transaction was rolled back via this
060: * local transaction; false otherwise.
061: * @throws HibernateException
062: */
063: public boolean wasRolledBack() throws HibernateException;
064:
065: /**
066: * Check if this transaction was successfully committed.
067: * <p/>
068: * This method could return <tt>false</tt> even after successful invocation
069: * of {@link #commit}. As an example, JTA based strategies no-op on
070: * {@link #commit} calls if they did not start the transaction; in that case,
071: * they also report {@link #wasCommitted} as false.
072: *
073: * @return boolean True if the transaction was (unequivocally) committed
074: * via this local transaction; false otherwise.
075: * @throws HibernateException
076: */
077: public boolean wasCommitted() throws HibernateException;
078:
079: /**
080: * Is this transaction still active?
081: * <p/>
082: * Again, this only returns information in relation to the
083: * local transaction, not the actual underlying transaction.
084: *
085: * @return boolean Treu if this local transaction is still active.
086: */
087: public boolean isActive() throws HibernateException;
088:
089: /**
090: * Register a user synchronization callback for this transaction.
091: *
092: * @param synchronization The Synchronization callback to register.
093: * @throws HibernateException
094: */
095: public void registerSynchronization(Synchronization synchronization)
096: throws HibernateException;
097:
098: /**
099: * Set the transaction timeout for any transaction started by
100: * a subsequent call to <tt>begin()</tt> on this instance.
101: *
102: * @param seconds The number of seconds before a timeout.
103: */
104: public void setTimeout(int seconds);
105: }
|