View Javadoc

1   package org.minetti.astrodevice.server.hibernate.dao;
2   
3   import javax.persistence.EntityTransaction;
4   import org.minetti.astrodevice.server.core.dao.DaoTransaction;
5   
6   /**
7    * Transaction used to group multiple changing by DAO with Hibernate framework.
8    * @author Jean-Philippe MINETTI
9    */
10  public final class DaoTransactionImpl
11  		implements DaoTransaction {
12  
13  	/**
14  	 * Entity transaction.
15  	 */
16  	private final EntityTransaction transaction;
17  
18  	/**
19  	 * Hidden constructor.
20  	 * @param transaction Entity transaction.
21  	 * @see DaoModuleImpl#newDaoTransaction(org.minetti.astrodevice.server.core.dao.DaoSession)
22  	 */
23  	protected DaoTransactionImpl (final EntityTransaction transaction) {
24  		super();
25  		this.transaction = transaction;
26  	}
27  
28  	/*
29  	 * (non-Javadoc)
30  	 * @see org.minetti.astrodevice.server.core.dao.DaoTransaction#begin()
31  	 */
32  	public void begin () {
33  		this.transaction.begin();
34  	}
35  
36  	/*
37  	 * (non-Javadoc)
38  	 * @see org.minetti.astrodevice.server.core.dao.DaoTransaction#end(boolean)
39  	 */
40  	public void end (boolean committed) {
41  		if (committed) {
42  			this.transaction.commit();
43  		}
44  		else {
45  			this.transaction.rollback();
46  		}
47  	}
48  
49  	/*
50  	 * (non-Javadoc)
51  	 * @see java.lang.Object#toString()
52  	 */
53  	@Override
54  	public String toString () {
55  		return "DaoTransactionImpl[transaction=" + this.transaction + "]";
56  	}
57  
58  }