1 package de.fhdw.wtf.persistence.meta;
2
3 import java.math.BigInteger;
4
5 import de.fhdw.wtf.persistence.exception.PersistenceException;
6 import de.fhdw.wtf.persistence.facade.ObjectFacade;
7
8
9
10
11
12 public class IntegerValue extends Object {
13
14
15
16
17 private static ObjectFacade facade;
18
19
20
21
22
23
24 public static void setObjectFacade(final ObjectFacade objectFacade) {
25 facade = objectFacade;
26 }
27
28
29
30
31 private BigInteger value;
32
33
34
35
36 private Long id;
37
38
39
40
41
42
43
44
45 public IntegerValue(final long id) {
46 super(IntegerType.getInstance());
47 this.id = id;
48 }
49
50
51
52
53
54
55
56
57 public IntegerValue(final BigInteger value) {
58 super(IntegerType.getInstance());
59 this.value = value;
60 }
61
62
63
64
65
66
67
68
69
70 public IntegerValue(final Long id, final BigInteger value) {
71 super(IntegerType.getInstance());
72 this.id = id;
73 this.value = value;
74 }
75
76
77
78
79
80
81 public BigInteger getValue() {
82 if (this.value == null) {
83 try {
84 this.value = facade.getIntForId(this.getId());
85 } catch (final PersistenceException e) {
86 throw new Error(e);
87 }
88 }
89 return this.value;
90 }
91
92
93
94
95 @Override
96 public long getId() {
97 if (this.id == null) {
98 try {
99 this.id = facade.getIdForInteger(this.getValue());
100 } catch (final PersistenceException e) {
101 throw new Error(e);
102 }
103 }
104 return this.id;
105 }
106
107 @Override
108 public boolean isTheSameAs(final java.lang.Object other) {
109 if (!(other instanceof IntegerValue)) {
110 return false;
111 }
112
113 return this.getId() == ((IntegerValue) other).getId();
114 }
115
116 }