1 package de.fhdw.wtf.persistence.meta;
2
3 /**
4 * A class to represent an association between an owning user type and a object.
5 *
6 */
7 public abstract class Association extends ModelItem {
8
9 /**
10 * The Owning side of the association.
11 */
12 private final UserType owner;
13
14 /**
15 *
16 * The target side of the association.
17 */
18 private final Type target;
19
20 /**
21 * A boolean flag, indicating whether a modification of the objects, which are instances of this association should
22 * be affecting the owner of this association.
23 */
24 private final boolean essential;
25
26 /**
27 * A boolean flag indicating whether this association is set-valued. If it is false it is possible to have more than
28 * links, which are instance of this and have the same owner.
29 */
30 private final boolean unique;
31
32 /**
33 * Getter for essential.
34 *
35 * @return Provides true whether this association has an essential flag.
36 */
37 public boolean isEssential() {
38 return this.essential;
39 }
40
41 /**
42 * Getter for unique.
43 *
44 * @return Provides true whether this association has an unique flag.
45 */
46 public boolean isUnique() {
47 return this.unique;
48 }
49
50 /**
51 * Getter for the owner of the association.
52 *
53 * @return Provides the owner type of the association.
54 */
55 public UserType getOwner() {
56 return this.owner;
57 }
58
59 /**
60 * Getter for the target of the association.
61 *
62 * @return Provides the target type of the association.
63 */
64 public Type getTarget() {
65 return this.target;
66 }
67
68 /**
69 * Constructor for a new association. It should only be calles by the class facade or unit tests because the Ids are
70 * provided by the database.
71 *
72 * @param id
73 * The Id of the association in the database.
74 * @param name
75 * The name of the UnidirectionalAssociation.
76 * @param owner
77 * The Owner type of the association.
78 * @param target
79 * The target type of the association.
80 * @param essential
81 * A flag indicating whether this association essential-
82 * @param unique
83 * A flag indicating whether the association is set-valued or not.
84 */
85 public Association(final long id,
86 final String name,
87 final UserType owner,
88 final Type target,
89 final boolean essential,
90 final boolean unique) {
91 super(id, name);
92 this.owner = owner;
93 this.target = target;
94 this.essential = essential;
95 this.unique = unique;
96 }
97
98 @Override
99 public boolean isTheSameAs(final java.lang.Object other) {
100 if (!(other instanceof Association)) {
101 return false;
102 }
103
104 final Association asso = (Association) other;
105
106 // id because owner/target(/key) takes to long time and the id is unique for all associations.
107 return this.getId() == asso.getId();
108 }
109
110 }