001/*
002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
006 * which accompanies this distribution.  The Eclipse Public License is available
007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
008 * is available at http://www.eclipse.org/org/documents/edl-v10.php.
009 */
010package javax.persistence;
011
012/**
013 * Interface used to control transactions on resource-local entity
014 * managers.  The {@link EntityManager#getTransaction
015 * EntityManager.getTransaction()} method returns the
016 * <code>EntityTransaction</code> interface.
017 *
018 * @since Java Persistence 1.0
019 */
020public interface EntityTransaction {
021
022  /**
023   * Start a resource transaction.
024   *
025   * @throws IllegalStateException if <code>isActive()</code> is true
026   */
027  public void begin();
028
029  /**
030   * Commit the current resource transaction, writing any
031   * unflushed changes to the database.
032   *
033   * @throws IllegalStateException if <code>isActive()</code> is false
034   * @throws RollbackException     if the commit fails
035   */
036  public void commit();
037
038  /**
039   * Roll back the current resource transaction.
040   *
041   * @throws IllegalStateException if <code>isActive()</code> is false
042   * @throws PersistenceException  if an unexpected error
043   *                               condition is encountered
044   */
045  public void rollback();
046
047  /**
048   * Mark the current resource transaction so that the only
049   * possible outcome of the transaction is for the transaction
050   * to be rolled back.
051   *
052   * @throws IllegalStateException if <code>isActive()</code> is false
053   */
054  public void setRollbackOnly();
055
056  /**
057   * Determine whether the current resource transaction has been
058   * marked for rollback.
059   *
060   * @return boolean indicating whether the transaction has been
061   * marked for rollback
062   * @throws IllegalStateException if <code>isActive()</code> is false
063   */
064  public boolean getRollbackOnly();
065
066  /**
067   * Indicate whether a resource transaction is in progress.
068   *
069   * @return boolean indicating whether transaction is
070   * in progress
071   * @throws PersistenceException if an unexpected error
072   *                              condition is encountered
073   */
074  public boolean isActive();
075}