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