1 package de.fhdw.wtf.persistence.meta; 2 3 /** 4 * A class to represent an adhoc Transaction. An Adhoc Transaction is a Transaction, which is not typed and therefore 5 * part of the Model. It can be used to manipulate the Database. 6 * 7 */ 8 public class AdhocTransaction implements Transaction { 9 10 /** 11 * The Database Id of the Transaction. The Id is unique. 12 */ 13 private final long id; 14 15 @Override 16 public long getId() { 17 return this.id; 18 } 19 20 /** 21 * Constructor for a new Adhoc Transaction. This constructor should not be called by any function different to 22 * provideAdhocTransaction in the Object Facade or any JUnit Test Case. Because it must be assured that the id also 23 * exists in the Database. 24 * 25 * @param id 26 * The id of the Adhoc Transaction. The Id is provided by the database. 27 */ 28 public AdhocTransaction(final long id) { 29 super(); 30 this.id = id; 31 } 32 33 @Override 34 public boolean equals(final java.lang.Object obj) { 35 if (obj instanceof Transaction) { 36 return this.customEquals((Transaction) obj); 37 } 38 return false; 39 } 40 41 /** 42 * Provides true, if two Transaction have the same Id. 43 * 44 * @param obj 45 * Any other Transaction, adhoc or not. 46 * @return Provides true if two Transactions are the same. 47 */ 48 private boolean customEquals(final Transaction obj) { 49 return this.getId() == obj.getId(); 50 } 51 52 @Override 53 public int hashCode() { 54 return super.hashCode(); 55 } 56 57 }