View Javadoc

1   /*
2    * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3    * the spring framework, http://el4j.sf.net
4    * Copyright (C) 2005 by ELCA Informatique SA, Av. de la Harpe 22-24,
5    * 1000 Lausanne, Switzerland, http://www.elca.ch
6    *
7    * EL4J is published under the GNU Lesser General Public License (LGPL)
8    * Version 2.1. See http://www.gnu.org/licenses/
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13   * GNU Lesser General Public License for more details.
14   *
15   * For alternative licensing, please contact info@elca.ch
16   */
17  
18  package ch.elca.el4j.services.persistence.generic.dto;
19  
20  import java.io.Serializable;
21  
22  import javax.persistence.Column;
23  import javax.persistence.MappedSuperclass;
24  import javax.persistence.Version;
25  
26  /**
27   * This is an abstract class for optimistic locking. The used version type is an
28   * integer.
29   * In java code the update count must be checked to know if the version number
30   * on database has been increased. If yes, the version number of dto must be
31   * increased too.<br>
32   * <br>
33   * <b>Java code:</b>
34   * <pre><code>
35   * ...
36   *     MyTableDto myDto = ...
37   *     SqlMapClientTemplate smc = ...
38   *     int count = smc.update("updateMyTable", myDto);
39   *     if (count == 1) {
40   *         myDto.increaseOptimisticLockingVersion();
41   *     }
42   * ...
43   * </code></pre>
44   *
45   *
46   * @svnLink $Revision: 3873 $;$Date: 2009-08-04 13:59:45 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/core/src/main/java/ch/elca/el4j/services/persistence/generic/dto/AbstractIntOptimisticLockingDto.java $
47   *
48   * @author Martin Zeltner (MZE)
49   */
50  @MappedSuperclass
51  public abstract class AbstractIntOptimisticLockingDto
52  	implements Serializable, OptimisticLockingObject {
53  	/**
54  	 * Is the optimistic locking version number. Initial optimistic locking
55  	 * version number is zero.
56  	 */
57  	private int m_optimisticLockingVersion = 0;
58  
59  	/**
60  	 * @return Returns the optimistic locking version.
61  	 */
62  	@Version
63  	@Column(name = "OPTIMISTICLOCKINGVERSION")
64  	public int getOptimisticLockingVersion() {
65  		return m_optimisticLockingVersion;
66  	}
67  
68  	/**
69  	 * @param optimisticLockingVersion
70  	 *            The optimistic locking version to set.
71  	 */
72  	public void setOptimisticLockingVersion(
73  		int optimisticLockingVersion) {
74  		m_optimisticLockingVersion = optimisticLockingVersion;
75  	}
76  	
77  	/**
78  	 * Method to increase the int optimistic locking version number.
79  	 */
80  	public void increaseOptimisticLockingVersion() {
81  		m_optimisticLockingVersion++;
82  	}
83  }