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) 2008 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  package ch.elca.el4j.util.objectwrapper.impl;
18  
19  import java.io.Serializable;
20  
21  import ch.elca.el4j.services.persistence.generic.dto.AbstractIntKeyIntOptimisticLockingDto;
22  import ch.elca.el4j.util.objectwrapper.ObjectWrapperRTException;
23  import ch.elca.el4j.util.objectwrapper.interfaces.KeyedVersioned;
24  
25  /**
26   * Implementation of KeyedVersioned that uses the provided methods of the EL4J base class. Thus, it is more efficient.
27   *
28   * @svnLink $Revision: 3879 $;$Date: 2009-08-04 15:13:46 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/hibernate/src/main/java/ch/elca/el4j/util/objectwrapper/impl/KeyedVersionedEl4jImpl.java $
29   *
30   * @author David Bernhard (DBD)
31   */
32  public class KeyedVersionedEl4jImpl extends AbstractWrapper implements KeyedVersioned {
33  
34  	/**
35  	 * The target cast to the correct class.
36  	 */
37  	private AbstractIntKeyIntOptimisticLockingDto m_targetDto;
38  	
39  	/** {@inheritDoc} */
40  	@Override
41  	public void create() throws ObjectWrapperRTException {
42  		if (!(m_target instanceof AbstractIntKeyIntOptimisticLockingDto)) {
43  			throw new ObjectWrapperRTException("This implementation is only for the "
44  				+ "AbstractIntKeyIntOptimisticLockingDto class.");
45  		}
46  		m_targetDto = (AbstractIntKeyIntOptimisticLockingDto) m_target;
47  	}
48  
49  	/** {@inheritDoc} */
50  	public Serializable getKey() {
51  		return m_targetDto.getKey();
52  	}
53  
54  	/** {@inheritDoc} */
55  	public Class<?> getKeyClass() {
56  		return Integer.class;
57  	}
58  
59  	/** {@inheritDoc} */
60  	public Serializable getVersion() {
61  		return m_targetDto.getOptimisticLockingVersion();
62  	}
63  
64  	/** {@inheritDoc} */
65  	public Class<?> getVersionClass() {
66  		return Integer.class;
67  	}
68  
69  	/** {@inheritDoc} */
70  	public void setKey(Serializable key) {
71  		if (key instanceof Integer) {
72  			Integer i = (Integer) key;
73  			m_targetDto.setKey(i);
74  		} else {
75  			throw new ObjectWrapperRTException("The target class requires integer keys.");
76  		}
77  	}
78  
79  	/** {@inheritDoc} */
80  	public void setVersion(Serializable version) {
81  		if (version instanceof Integer) {
82  			Integer i = (Integer) version;
83  			m_targetDto.setOptimisticLockingVersion(i);
84  		} else {
85  			throw new ObjectWrapperRTException("The target class requires integer versions.");
86  		}
87  	}
88  
89  }