View Javadoc
1   package de.fhdw.wtf.persistence.meta;
2   
3   /**
4    * A class to represent an object to a user Type.
5    * 
6    */
7   public class UserObject extends Object { // NOPMD: Object != java.lang.Object
8   
9   	/**
10  	 * The identity of a user Object in the Database.
11  	 */
12  	private final long id;
13  	
14  	/**
15  	 * Constructor for a new User Object. It should only be called by the object facade or a junit test to guarantee
16  	 * consistency with the database.
17  	 * 
18  	 * @param id
19  	 *            The Id of this object in the database.
20  	 * @param instanceOf
21  	 *            The Type of this User Object. It must be a user type.
22  	 * @return a UserTransaction when instance of is a transaction type UserObject otherwise.
23  	 */
24  	public static UserObject init(final long id, final Type instanceOf) {
25  		if (instanceOf.isTrans()) {
26  			return new UserTransaction(id, instanceOf);
27  		} else {
28  			return new UserObject(id, instanceOf);
29  		}
30  	}
31  	
32  	/**
33  	 * Constructor for a new User Object. It should only be called by the object facade or a junit test to guarantee
34  	 * consistency with the database.
35  	 * 
36  	 * @param id
37  	 *            The Id of this object in the database.
38  	 * @param instanceOf
39  	 *            The Type of this User Object. It must be a user type.
40  	 */
41  	protected UserObject(final long id, final Type instanceOf) {
42  		super(instanceOf);
43  		this.id = id;
44  	}
45  	
46  	@Override
47  	public long getId() {
48  		return this.id;
49  	}
50  	
51  	@Override
52  	public boolean isTheSameAs(final java.lang.Object other) {
53  		if (!(other instanceof UserObject)) {
54  			return false;
55  		}
56  		
57  		final UserObject uo = (UserObject) other;
58  		
59  		return this.getId() == uo.getId();
60  	}
61  	
62  }