]> review.fuel-infra Code Review - packages/trusty/mysql-wsrep-5.6.git/blob
11eef8f24dd2294b5485d5b21a1cf0cecc71a001
[packages/trusty/mysql-wsrep-5.6.git] /
1 /*
2    Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
3
4    This program is free software; you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation; version 2 of the License.
7
8    This program is distributed in the hope that it will be useful,
9    but WITHOUT ANY WARRANTY; without even the implied warranty of
10    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11    GNU General Public License for more details.
12
13    You should have received a copy of the GNU General Public License
14    along with this program; if not, write to the Free Software
15    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301  USA
16 */
17
18 package com.mysql.clusterj.core.metadata;
19
20 import com.mysql.clusterj.ClusterJFatalInternalException;
21 import com.mysql.clusterj.ColumnMetadata;
22 import com.mysql.clusterj.core.spi.ValueHandler;
23 import com.mysql.clusterj.core.spi.DomainTypeHandler;
24 import com.mysql.clusterj.core.util.I18NHelper;
25 import com.mysql.clusterj.core.util.Logger;
26 import com.mysql.clusterj.core.util.LoggerFactoryService;
27 import java.math.BigDecimal;
28 import java.math.BigInteger;
29 import java.sql.Date;
30 import java.sql.Time;
31 import java.sql.Timestamp;
32
33 /** KeyValueHandlerImpl implements the ValueHandler interface for an array
34  * of objects that represent key values. 
35  *
36  */
37 public class KeyValueHandlerImpl implements ValueHandler {
38     static final I18NHelper local = I18NHelper.getInstance(KeyValueHandlerImpl.class);
39     static final Logger logger = LoggerFactoryService.getFactory().getInstance(KeyValueHandlerImpl.class);
40
41     private Object[] values;
42
43     /** The number of fields */
44     private int numberOfFields;
45     
46     public KeyValueHandlerImpl(Object[] keyValues) {
47         this.values = keyValues;
48         this.numberOfFields = keyValues.length;
49         if (logger.isDetailEnabled()) {
50             StringBuffer buffer = new StringBuffer();
51             for (int i = 0; i < values.length; ++i) {
52                 if (values[i] != null) {
53                     buffer.append(" values[" + i +"]: \"" + values[i] + "\"");
54                 }
55             }
56             logger.detail("KeyValueHandler<init> values.length: " + values.length + buffer.toString());
57         }
58     }
59
60     public boolean isNull(int fieldNumber) {
61         return values[fieldNumber] == null;
62     }
63
64     public int getInt(int fieldNumber) {
65         if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getInt(" + fieldNumber + ") returns: " + values[fieldNumber]);
66         return (Integer) values[fieldNumber];
67     }
68
69     public long getLong(int fieldNumber) {
70         if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getLong(" + fieldNumber + ") returns: " + values[fieldNumber]);
71         return (Long) values[fieldNumber];
72     }
73
74     public Integer getObjectInt(int fieldNumber) {
75         if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getObjectInt(" + fieldNumber + ") returns: " + values[fieldNumber]);
76         return (Integer) values[fieldNumber];
77     }
78
79     public Long getObjectLong(int fieldNumber) {
80         if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getObjectLong(" + fieldNumber + ") returns: " + values[fieldNumber]);
81         return (Long) values[fieldNumber];
82     }
83
84     public String getString(int fieldNumber) {
85         if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getString(" + fieldNumber + ") returns: " + values[fieldNumber]);
86         return (String) values[fieldNumber];
87     }
88
89     public boolean isModified(int fieldNumber) {
90         throw new UnsupportedOperationException(
91                 local.message("ERR_Operation_Not_Supported",
92                 "isModified", "KeyValueHandlerImpl"));
93     }
94
95     public BigInteger getBigInteger(int fieldNumber) {
96         throw new ClusterJFatalInternalException(
97                 local.message("ERR_Operation_Not_Supported",
98                 "getBigInteger", "KeyValueHandlerImpl"));
99     }
100
101     public boolean getBoolean(int fieldNumber) {
102         throw new ClusterJFatalInternalException(
103                 local.message("ERR_Operation_Not_Supported",
104                 "getBoolean", "KeyValueHandlerImpl"));
105     }
106
107     public boolean[] getBooleans(int fieldNumber) {
108         throw new ClusterJFatalInternalException(
109                 local.message("ERR_Operation_Not_Supported",
110                 "getBooleans", "KeyValueHandlerImpl"));
111     }
112
113     public byte getByte(int fieldNumber) {
114         throw new ClusterJFatalInternalException(
115                 local.message("ERR_Operation_Not_Supported",
116                 "getByte", "KeyValueHandlerImpl"));
117     }
118
119     public byte[] getBytes(int fieldNumber) {
120         if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getBytes(" + fieldNumber + ") returns: " + values[fieldNumber]);
121         return (byte[]) values[fieldNumber];
122     }
123
124     public short getShort(int fieldNumber) {
125         throw new ClusterJFatalInternalException(
126                 local.message("ERR_Operation_Not_Supported",
127                 "getShort", "KeyValueHandlerImpl"));
128     }
129
130     public float getFloat(int fieldNumber) {
131         throw new ClusterJFatalInternalException(
132                 local.message("ERR_Operation_Not_Supported",
133                 "getFloat", "KeyValueHandlerImpl"));
134     }
135
136     public double getDouble(int fieldNumber) {
137         throw new ClusterJFatalInternalException(
138                 local.message("ERR_Operation_Not_Supported",
139                 "getDouble", "KeyValueHandlerImpl"));
140     }
141
142     public Boolean getObjectBoolean(int fieldNumber) {
143         throw new ClusterJFatalInternalException(
144                 local.message("ERR_Operation_Not_Supported",
145                 "getObjectBoolean", "KeyValueHandlerImpl"));
146     }
147
148     public Byte getObjectByte(int fieldNumber) {
149         throw new ClusterJFatalInternalException(
150                 local.message("ERR_Operation_Not_Supported",
151                 "getObjectByte", "KeyValueHandlerImpl"));
152     }
153
154     public Short getObjectShort(int fieldNumber) {
155         throw new ClusterJFatalInternalException(
156                 local.message("ERR_Operation_Not_Supported",
157                 "getObjectShort", "KeyValueHandlerImpl"));
158     }
159
160     public Float getObjectFloat(int fieldNumber) {
161         throw new ClusterJFatalInternalException(
162                 local.message("ERR_Operation_Not_Supported",
163                 "getObjectFloat", "KeyValueHandlerImpl"));
164     }
165
166     public Double getObjectDouble(int fieldNumber) {
167         throw new ClusterJFatalInternalException(
168                 local.message("ERR_Operation_Not_Supported",
169                 "getObjectDouble", "KeyValueHandlerImpl"));
170     }
171
172     public BigDecimal getBigDecimal(int fieldNumber) {
173         throw new ClusterJFatalInternalException(
174                 local.message("ERR_Operation_Not_Supported",
175                 "getBigDecimal", "KeyValueHandlerImpl"));
176     }
177
178     public Date getJavaSqlDate(int fieldNumber) {
179         throw new ClusterJFatalInternalException(
180                 local.message("ERR_Operation_Not_Supported",
181                 "getJavaSqlDate", "KeyValueHandlerImpl"));
182     }
183
184     public java.util.Date getJavaUtilDate(int fieldNumber) {
185         throw new ClusterJFatalInternalException(
186                 local.message("ERR_Operation_Not_Supported",
187                 "getJavaUtilDate", "KeyValueHandlerImpl"));
188     }
189
190     public Time getJavaSqlTime(int fieldNumber) {
191         throw new ClusterJFatalInternalException(
192                 local.message("ERR_Operation_Not_Supported",
193                 "getJavaSqlTime", "KeyValueHandlerImpl"));
194     }
195
196     public Timestamp getJavaSqlTimestamp(int fieldNumber) {
197         throw new ClusterJFatalInternalException(
198                 local.message("ERR_Operation_Not_Supported",
199                 "getJavaSqlTimestamp", "KeyValueHandlerImpl"));
200     }
201
202     public void setBoolean(int fieldNumber, boolean b) {
203         throw new ClusterJFatalInternalException(
204                 local.message("ERR_Operation_Not_Supported",
205                 "setBoolean", "KeyValueHandlerImpl"));
206     }
207
208     public void setBooleans(int fieldNumber, boolean[] b) {
209         throw new ClusterJFatalInternalException(
210                 local.message("ERR_Operation_Not_Supported",
211                 "setBooleans", "KeyValueHandlerImpl"));
212     }
213
214     public void setBigInteger(int fieldNumber, BigInteger value) {
215         throw new ClusterJFatalInternalException(
216                 local.message("ERR_Operation_Not_Supported",
217                 "setBigInteger", "KeyValueHandlerImpl"));
218     }
219
220     public void setByte(int fieldNumber, byte value) {
221         throw new ClusterJFatalInternalException(
222                 local.message("ERR_Operation_Not_Supported",
223                 "setByte", "KeyValueHandlerImpl"));
224     }
225
226     public void setBytes(int fieldNumber, byte[] value) {
227         throw new ClusterJFatalInternalException(
228                 local.message("ERR_Operation_Not_Supported",
229                 "setBytes", "KeyValueHandlerImpl"));
230     }
231
232     public void setShort(int fieldNumber, short value) {
233         throw new ClusterJFatalInternalException(
234                 local.message("ERR_Operation_Not_Supported",
235                 "setShort", "KeyValueHandlerImpl"));
236     }
237
238     public void setInt(int fieldNumber, int value) {
239         throw new ClusterJFatalInternalException(
240                 local.message("ERR_Operation_Not_Supported",
241                 "setInt", "KeyValueHandlerImpl"));
242     }
243
244     public void setLong(int fieldNumber, long value) {
245         throw new ClusterJFatalInternalException(
246                 local.message("ERR_Operation_Not_Supported",
247                 "setLong", "KeyValueHandlerImpl"));
248     }
249
250     public void setFloat(int fieldNumber, float value) {
251         throw new ClusterJFatalInternalException(
252                 local.message("ERR_Operation_Not_Supported",
253                 "setFloat", "KeyValueHandlerImpl"));
254     }
255
256     public void setDouble(int fieldNumber, double value) {
257         throw new ClusterJFatalInternalException(
258                 local.message("ERR_Operation_Not_Supported",
259                 "setDouble", "KeyValueHandlerImpl"));
260     }
261
262     public void setObjectBoolean(int fieldNumber, Boolean value) {
263         throw new ClusterJFatalInternalException(
264                 local.message("ERR_Operation_Not_Supported",
265                 "setObjectBoolean", "KeyValueHandlerImpl"));
266     }
267
268     public void setObjectByte(int fieldNumber, Byte value) {
269         throw new ClusterJFatalInternalException(
270                 local.message("ERR_Operation_Not_Supported",
271                 "setObjectByte", "KeyValueHandlerImpl"));
272     }
273
274     public void setObjectShort(int fieldNumber, Short value) {
275         throw new ClusterJFatalInternalException(
276                 local.message("ERR_Operation_Not_Supported",
277                 "setObjectShort", "KeyValueHandlerImpl"));
278     }
279
280     public void setObjectInt(int fieldNumber, Integer value) {
281         throw new ClusterJFatalInternalException(
282                 local.message("ERR_Operation_Not_Supported",
283                 "setObjectInt", "KeyValueHandlerImpl"));
284     }
285
286     public void setObjectLong(int fieldNumber, Long value) {
287         throw new ClusterJFatalInternalException(
288                 local.message("ERR_Operation_Not_Supported",
289                 "setObjectLong", "KeyValueHandlerImpl"));
290     }
291
292     public void setObjectFloat(int fieldNumber, Float value) {
293         throw new ClusterJFatalInternalException(
294                 local.message("ERR_Operation_Not_Supported",
295                 "setObjectFloat", "KeyValueHandlerImpl"));
296     }
297
298     public void setObjectDouble(int fieldNumber, Double value) {
299         throw new ClusterJFatalInternalException(
300                 local.message("ERR_Operation_Not_Supported",
301                 "setObjectDouble", "KeyValueHandlerImpl"));
302     }
303
304     public void setBigDecimal(int fieldNumber, BigDecimal value) {
305         throw new ClusterJFatalInternalException(
306                 local.message("ERR_Operation_Not_Supported",
307                 "setBigDecimal", "KeyValueHandlerImpl"));
308     }
309
310     public void setString(int fieldNumber, String value) {
311         throw new ClusterJFatalInternalException(
312                 local.message("ERR_Operation_Not_Supported",
313                 "setString", "KeyValueHandlerImpl"));
314     }
315
316     public void setObject(int fieldNumber, Object value) {
317         throw new ClusterJFatalInternalException(
318                 local.message("ERR_Operation_Not_Supported",
319                 "setObject", "KeyValueHandlerImpl"));
320     }
321
322     public void setJavaSqlDate(int fieldNumber, Date value) {
323         throw new ClusterJFatalInternalException(
324                 local.message("ERR_Operation_Not_Supported",
325                 "setJavaSqlDate", "KeyValueHandlerImpl"));
326     }
327
328     public void setJavaUtilDate(int fieldNumber, java.util.Date value) {
329         throw new ClusterJFatalInternalException(
330                 local.message("ERR_Operation_Not_Supported",
331                 "setJavaUtilDate", "KeyValueHandlerImpl"));
332     }
333
334     public void setJavaSqlTime(int fieldNumber, Time value) {
335         throw new ClusterJFatalInternalException(
336                 local.message("ERR_Operation_Not_Supported",
337                 "setJavaSqlTime", "KeyValueHandlerImpl"));
338     }
339
340     public void setJavaSqlTimestamp(int fieldNumber, Timestamp value) {
341         throw new ClusterJFatalInternalException(
342                 local.message("ERR_Operation_Not_Supported",
343                 "setJavaSqlTimestamp", "KeyValueHandlerImpl"));
344     }
345
346     public void markModified(int fieldNumber) {
347         throw new UnsupportedOperationException("Not supported yet.");
348     }
349
350     public void resetModified() {
351         throw new UnsupportedOperationException("Not supported yet.");
352     }
353
354     public String pkToString(DomainTypeHandler<?> domainTypeHandler) {
355         StringBuffer sb = new StringBuffer(" key: [");
356         int[] keys = domainTypeHandler.getKeyFieldNumbers();
357         String separator = "";
358         for (int i: keys) {
359             sb.append(separator);
360             sb.append(values[i]);
361             separator = ";";
362         }
363         sb.append("]");
364         return sb.toString();
365     }
366
367     public void found(Boolean found) {
368         throw new ClusterJFatalInternalException(
369                 local.message("ERR_Operation_Not_Supported",
370                 "found(Boolean)", "KeyValueHandlerImpl"));
371     }
372
373     public ColumnMetadata[] columnMetadata() {
374         throw new ClusterJFatalInternalException(
375                 local.message("ERR_Operation_Not_Supported",
376                 "columnMetadata", "KeyValueHandlerImpl"));
377     }
378
379     public Boolean found() {
380         throw new ClusterJFatalInternalException(
381                 local.message("ERR_Operation_Not_Supported",
382                 "found", "KeyValueHandlerImpl"));
383     }
384
385     public Object get(int columnNumber) {
386         throw new ClusterJFatalInternalException(
387                 local.message("ERR_Operation_Not_Supported",
388                 "get(int)", "KeyValueHandlerImpl"));
389     }
390
391     public void set(int columnNumber, Object value) {
392         throw new ClusterJFatalInternalException(
393                 local.message("ERR_Operation_Not_Supported",
394                 "set(int, Object)", "KeyValueHandlerImpl"));
395     }
396
397 }