1 package org.minetti.astrodevice.server.hibernate.object;
2
3 import java.io.Serializable;
4 import java.util.HashMap;
5 import java.util.Map;
6 import javax.persistence.Column;
7 import javax.persistence.Entity;
8 import javax.persistence.GeneratedValue;
9 import javax.persistence.Id;
10 import javax.persistence.Lob;
11 import javax.persistence.NamedQueries;
12 import javax.persistence.NamedQuery;
13 import javax.persistence.Table;
14 import javax.persistence.Transient;
15 import org.hibernate.annotations.Index;
16 import org.minetti.astrodevice.common.device.DeviceSignature;
17 import org.minetti.astrodevice.server.core.object.DeviceSpecification;
18 import org.minetti.astrodevice.server.plugin.device.BaseDeviceSignature;
19
20
21
22
23
24 @Table(name = "DEVICE")
25 @org.hibernate.annotations.Table(appliesTo = "DEVICE", indexes = { @Index(name = "K_DEVICE_SIGNATURE", columnNames = { "BUS", "PRODUCT_ID", "PRODUCT_DESCRIPTION",
26 "PRODUCT_VERSION", "SERIAL_NUMBER" }) })
27 @NamedQueries({
28 @NamedQuery(name = "allDeviceSpecificationQuery", query = "FROM DeviceSpecificationImpl t ORDER BY t.name"),
29 @NamedQuery(name = "pluginDeviceSpecificationQuery", query = "FROM DeviceSpecificationImpl t WHERE (t.pluginClassName=:pluginClassName) ORDER BY t.name"),
30 @NamedQuery(name = "sameProductDeviceSpecificationQuery", query = "FROM DeviceSpecificationImpl t WHERE (t.bus=:bus) and (t.productId=:productId) and (t.productDescription=:productDescription) and (t.productVersion=:productVersion) ORDER BY t.name"),
31 @NamedQuery(name = "sameProductDeviceSpecificationQueryWithNullVersion", query = "FROM DeviceSpecificationImpl t WHERE (t.bus=:bus) and (t.productId=:productId) and (t.productDescription=:productDescription) and (t.productVersion is null) ORDER BY t.name"),
32 @NamedQuery(name = "signatureDeviceSpecificationQuery", query = "FROM DeviceSpecificationImpl t WHERE (t.bus=:bus) and (t.productId=:productId) and (t.productDescription=:productDescription) and (t.productVersion=:productVersion) and (t.serialNumber=:serialNumber) ORDER BY t.name"),
33 @NamedQuery(name = "signatureDeviceSpecificationQueryWithNullVersion", query = "FROM DeviceSpecificationImpl t WHERE (t.bus=:bus) and (t.productId=:productId) and (t.productDescription=:productDescription) and (t.productVersion is null) and (t.serialNumber=:serialNumber) ORDER BY t.name"),
34 @NamedQuery(name = "signatureDeviceSpecificationQueryWithNullSerialNumber", query = "FROM DeviceSpecificationImpl t WHERE (t.bus=:bus) and (t.productId=:productId) and (t.productDescription=:productDescription) and (t.productVersion=:productVersion) and (t.serialNumber is null) ORDER BY t.name"),
35 @NamedQuery(name = "signatureDeviceSpecificationQueryWithNullVersionAndSerialNumber", query = "FROM DeviceSpecificationImpl t WHERE (t.bus=:bus) and (t.productId=:productId) and (t.productDescription=:productDescription) and (t.productVersion is null) and (t.serialNumber is null) ORDER BY t.name") })
36 @Entity
37 public final class DeviceSpecificationImpl
38 implements DeviceSpecification, Serializable {
39
40
41
42
43 private static final long serialVersionUID = -7709095111542974139L;
44
45
46
47
48 protected final class DeviceSignatureImpl
49 extends BaseDeviceSignature {
50
51
52
53
54 protected DeviceSignatureImpl () {
55 super();
56 }
57
58
59
60
61
62 public String getBus () {
63 return DeviceSpecificationImpl.this.bus;
64 }
65
66
67
68
69
70 public String getProductId () {
71 return DeviceSpecificationImpl.this.productId;
72 }
73
74
75
76
77
78 public String getProductDescription () {
79 return DeviceSpecificationImpl.this.productDescription;
80 }
81
82
83
84
85
86 public String getProductVersion () {
87 return DeviceSpecificationImpl.this.productVersion;
88 }
89
90
91
92
93
94 public String getSerialNumber () {
95 return DeviceSpecificationImpl.this.serialNumber;
96 }
97
98
99
100
101
102 public Map<String, Object> getProperties () {
103 return DeviceSpecificationImpl.this.properties;
104 }
105
106 }
107
108
109
110
111 @Id
112 @GeneratedValue
113 @Column(name = "ID", nullable = false)
114 private Long id = null;
115
116
117
118
119 @Column(name = "NAME", length = 40, nullable = false, unique = true)
120 private String name = null;
121
122
123
124
125 @Column(name = "PLUGIN", nullable = false)
126 @Index(name = "K_DEVICE_PLUGIN")
127 private String pluginClassName = null;
128
129
130
131
132 @Column(name = "BUS", length = 15, nullable = false)
133 protected String bus = null;
134
135
136
137
138 @Column(name = "PRODUCT_ID", length = 15, nullable = false)
139 protected String productId = null;
140
141
142
143
144 @Column(name = "PRODUCT_DESCRIPTION", length = 255, nullable = false)
145 protected String productDescription = null;
146
147
148
149
150 @Column(name = "PRODUCT_VERSION", length = 8)
151 protected String productVersion = null;
152
153
154
155
156
157 @Column(name = "SERIAL_NUMBER", length = 255)
158 protected String serialNumber = null;
159
160
161
162
163 @Column(name = "PROPERTIES", nullable = false)
164 @Lob
165 protected HashMap<String, Object> properties = null;
166
167
168
169
170 @Transient
171 private final DeviceSignature signature = new DeviceSignatureImpl();
172
173
174
175
176 public DeviceSpecificationImpl () {
177 super();
178 }
179
180
181
182
183
184 public DeviceSpecificationImpl (final DeviceSpecification deviceSpecification) {
185 super();
186 this.name = deviceSpecification.getName();
187 this.pluginClassName = deviceSpecification.getPluginClassName();
188 this.bus = deviceSpecification.getSignature().getBus();
189 this.productId = deviceSpecification.getSignature().getProductId();
190 this.productDescription = deviceSpecification.getSignature().getProductDescription();
191 this.productVersion = deviceSpecification.getSignature().getProductVersion();
192 this.serialNumber = deviceSpecification.getSignature().getSerialNumber();
193 this.properties = new HashMap<String, Object>(deviceSpecification.getSignature().getProperties());
194 }
195
196
197
198
199
200 public final Long getId () {
201 return this.id;
202 }
203
204
205
206
207
208 public final String getName () {
209 return this.name;
210 }
211
212
213
214
215
216 public final void setName (final String name) {
217 this.name = name;
218 }
219
220
221
222
223
224 public final String getPluginClassName () {
225 return this.pluginClassName;
226 }
227
228
229
230
231
232
233
234 public final void setPluginClassName (final String pluginClassName) {
235 this.pluginClassName = pluginClassName;
236 }
237
238
239
240
241
242 public final DeviceSignature getSignature () {
243 return this.signature;
244 }
245
246
247
248
249
250 @Override
251 public final int hashCode () {
252 return (this.name != null ? this.name.hashCode() : 0);
253 }
254
255
256
257
258
259 @Override
260 public final boolean equals (final Object obj) {
261 boolean result = false;
262 if (obj == this) {
263 result = true;
264 }
265 else if ((obj instanceof DeviceSpecification) && (this.name != null)) {
266 result = this.name.equals(((DeviceSpecification) obj).getName());
267 }
268 return result;
269 }
270
271
272
273
274
275 @Override
276 public final String toString () {
277 return this.name + " - " + this.signature;
278 }
279
280 }