2 Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
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.
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.
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
18 package com.mysql.clusterj.core.metadata;
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;
31 import java.sql.Timestamp;
33 /** KeyValueHandlerImpl implements the ValueHandler interface for an array
34 * of objects that represent key values.
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);
41 private Object[] values;
43 /** The number of fields */
44 private int numberOfFields;
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] + "\"");
56 logger.detail("KeyValueHandler<init> values.length: " + values.length + buffer.toString());
60 public boolean isNull(int fieldNumber) {
61 return values[fieldNumber] == null;
64 public int getInt(int fieldNumber) {
65 if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getInt(" + fieldNumber + ") returns: " + values[fieldNumber]);
66 return (Integer) values[fieldNumber];
69 public long getLong(int fieldNumber) {
70 if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getLong(" + fieldNumber + ") returns: " + values[fieldNumber]);
71 return (Long) values[fieldNumber];
74 public Integer getObjectInt(int fieldNumber) {
75 if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getObjectInt(" + fieldNumber + ") returns: " + values[fieldNumber]);
76 return (Integer) values[fieldNumber];
79 public Long getObjectLong(int fieldNumber) {
80 if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getObjectLong(" + fieldNumber + ") returns: " + values[fieldNumber]);
81 return (Long) values[fieldNumber];
84 public String getString(int fieldNumber) {
85 if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getString(" + fieldNumber + ") returns: " + values[fieldNumber]);
86 return (String) values[fieldNumber];
89 public boolean isModified(int fieldNumber) {
90 throw new UnsupportedOperationException(
91 local.message("ERR_Operation_Not_Supported",
92 "isModified", "KeyValueHandlerImpl"));
95 public BigInteger getBigInteger(int fieldNumber) {
96 throw new ClusterJFatalInternalException(
97 local.message("ERR_Operation_Not_Supported",
98 "getBigInteger", "KeyValueHandlerImpl"));
101 public boolean getBoolean(int fieldNumber) {
102 throw new ClusterJFatalInternalException(
103 local.message("ERR_Operation_Not_Supported",
104 "getBoolean", "KeyValueHandlerImpl"));
107 public boolean[] getBooleans(int fieldNumber) {
108 throw new ClusterJFatalInternalException(
109 local.message("ERR_Operation_Not_Supported",
110 "getBooleans", "KeyValueHandlerImpl"));
113 public byte getByte(int fieldNumber) {
114 throw new ClusterJFatalInternalException(
115 local.message("ERR_Operation_Not_Supported",
116 "getByte", "KeyValueHandlerImpl"));
119 public byte[] getBytes(int fieldNumber) {
120 if (logger.isDetailEnabled()) logger.detail("KeyValueHandler.getBytes(" + fieldNumber + ") returns: " + values[fieldNumber]);
121 return (byte[]) values[fieldNumber];
124 public short getShort(int fieldNumber) {
125 throw new ClusterJFatalInternalException(
126 local.message("ERR_Operation_Not_Supported",
127 "getShort", "KeyValueHandlerImpl"));
130 public float getFloat(int fieldNumber) {
131 throw new ClusterJFatalInternalException(
132 local.message("ERR_Operation_Not_Supported",
133 "getFloat", "KeyValueHandlerImpl"));
136 public double getDouble(int fieldNumber) {
137 throw new ClusterJFatalInternalException(
138 local.message("ERR_Operation_Not_Supported",
139 "getDouble", "KeyValueHandlerImpl"));
142 public Boolean getObjectBoolean(int fieldNumber) {
143 throw new ClusterJFatalInternalException(
144 local.message("ERR_Operation_Not_Supported",
145 "getObjectBoolean", "KeyValueHandlerImpl"));
148 public Byte getObjectByte(int fieldNumber) {
149 throw new ClusterJFatalInternalException(
150 local.message("ERR_Operation_Not_Supported",
151 "getObjectByte", "KeyValueHandlerImpl"));
154 public Short getObjectShort(int fieldNumber) {
155 throw new ClusterJFatalInternalException(
156 local.message("ERR_Operation_Not_Supported",
157 "getObjectShort", "KeyValueHandlerImpl"));
160 public Float getObjectFloat(int fieldNumber) {
161 throw new ClusterJFatalInternalException(
162 local.message("ERR_Operation_Not_Supported",
163 "getObjectFloat", "KeyValueHandlerImpl"));
166 public Double getObjectDouble(int fieldNumber) {
167 throw new ClusterJFatalInternalException(
168 local.message("ERR_Operation_Not_Supported",
169 "getObjectDouble", "KeyValueHandlerImpl"));
172 public BigDecimal getBigDecimal(int fieldNumber) {
173 throw new ClusterJFatalInternalException(
174 local.message("ERR_Operation_Not_Supported",
175 "getBigDecimal", "KeyValueHandlerImpl"));
178 public Date getJavaSqlDate(int fieldNumber) {
179 throw new ClusterJFatalInternalException(
180 local.message("ERR_Operation_Not_Supported",
181 "getJavaSqlDate", "KeyValueHandlerImpl"));
184 public java.util.Date getJavaUtilDate(int fieldNumber) {
185 throw new ClusterJFatalInternalException(
186 local.message("ERR_Operation_Not_Supported",
187 "getJavaUtilDate", "KeyValueHandlerImpl"));
190 public Time getJavaSqlTime(int fieldNumber) {
191 throw new ClusterJFatalInternalException(
192 local.message("ERR_Operation_Not_Supported",
193 "getJavaSqlTime", "KeyValueHandlerImpl"));
196 public Timestamp getJavaSqlTimestamp(int fieldNumber) {
197 throw new ClusterJFatalInternalException(
198 local.message("ERR_Operation_Not_Supported",
199 "getJavaSqlTimestamp", "KeyValueHandlerImpl"));
202 public void setBoolean(int fieldNumber, boolean b) {
203 throw new ClusterJFatalInternalException(
204 local.message("ERR_Operation_Not_Supported",
205 "setBoolean", "KeyValueHandlerImpl"));
208 public void setBooleans(int fieldNumber, boolean[] b) {
209 throw new ClusterJFatalInternalException(
210 local.message("ERR_Operation_Not_Supported",
211 "setBooleans", "KeyValueHandlerImpl"));
214 public void setBigInteger(int fieldNumber, BigInteger value) {
215 throw new ClusterJFatalInternalException(
216 local.message("ERR_Operation_Not_Supported",
217 "setBigInteger", "KeyValueHandlerImpl"));
220 public void setByte(int fieldNumber, byte value) {
221 throw new ClusterJFatalInternalException(
222 local.message("ERR_Operation_Not_Supported",
223 "setByte", "KeyValueHandlerImpl"));
226 public void setBytes(int fieldNumber, byte[] value) {
227 throw new ClusterJFatalInternalException(
228 local.message("ERR_Operation_Not_Supported",
229 "setBytes", "KeyValueHandlerImpl"));
232 public void setShort(int fieldNumber, short value) {
233 throw new ClusterJFatalInternalException(
234 local.message("ERR_Operation_Not_Supported",
235 "setShort", "KeyValueHandlerImpl"));
238 public void setInt(int fieldNumber, int value) {
239 throw new ClusterJFatalInternalException(
240 local.message("ERR_Operation_Not_Supported",
241 "setInt", "KeyValueHandlerImpl"));
244 public void setLong(int fieldNumber, long value) {
245 throw new ClusterJFatalInternalException(
246 local.message("ERR_Operation_Not_Supported",
247 "setLong", "KeyValueHandlerImpl"));
250 public void setFloat(int fieldNumber, float value) {
251 throw new ClusterJFatalInternalException(
252 local.message("ERR_Operation_Not_Supported",
253 "setFloat", "KeyValueHandlerImpl"));
256 public void setDouble(int fieldNumber, double value) {
257 throw new ClusterJFatalInternalException(
258 local.message("ERR_Operation_Not_Supported",
259 "setDouble", "KeyValueHandlerImpl"));
262 public void setObjectBoolean(int fieldNumber, Boolean value) {
263 throw new ClusterJFatalInternalException(
264 local.message("ERR_Operation_Not_Supported",
265 "setObjectBoolean", "KeyValueHandlerImpl"));
268 public void setObjectByte(int fieldNumber, Byte value) {
269 throw new ClusterJFatalInternalException(
270 local.message("ERR_Operation_Not_Supported",
271 "setObjectByte", "KeyValueHandlerImpl"));
274 public void setObjectShort(int fieldNumber, Short value) {
275 throw new ClusterJFatalInternalException(
276 local.message("ERR_Operation_Not_Supported",
277 "setObjectShort", "KeyValueHandlerImpl"));
280 public void setObjectInt(int fieldNumber, Integer value) {
281 throw new ClusterJFatalInternalException(
282 local.message("ERR_Operation_Not_Supported",
283 "setObjectInt", "KeyValueHandlerImpl"));
286 public void setObjectLong(int fieldNumber, Long value) {
287 throw new ClusterJFatalInternalException(
288 local.message("ERR_Operation_Not_Supported",
289 "setObjectLong", "KeyValueHandlerImpl"));
292 public void setObjectFloat(int fieldNumber, Float value) {
293 throw new ClusterJFatalInternalException(
294 local.message("ERR_Operation_Not_Supported",
295 "setObjectFloat", "KeyValueHandlerImpl"));
298 public void setObjectDouble(int fieldNumber, Double value) {
299 throw new ClusterJFatalInternalException(
300 local.message("ERR_Operation_Not_Supported",
301 "setObjectDouble", "KeyValueHandlerImpl"));
304 public void setBigDecimal(int fieldNumber, BigDecimal value) {
305 throw new ClusterJFatalInternalException(
306 local.message("ERR_Operation_Not_Supported",
307 "setBigDecimal", "KeyValueHandlerImpl"));
310 public void setString(int fieldNumber, String value) {
311 throw new ClusterJFatalInternalException(
312 local.message("ERR_Operation_Not_Supported",
313 "setString", "KeyValueHandlerImpl"));
316 public void setObject(int fieldNumber, Object value) {
317 throw new ClusterJFatalInternalException(
318 local.message("ERR_Operation_Not_Supported",
319 "setObject", "KeyValueHandlerImpl"));
322 public void setJavaSqlDate(int fieldNumber, Date value) {
323 throw new ClusterJFatalInternalException(
324 local.message("ERR_Operation_Not_Supported",
325 "setJavaSqlDate", "KeyValueHandlerImpl"));
328 public void setJavaUtilDate(int fieldNumber, java.util.Date value) {
329 throw new ClusterJFatalInternalException(
330 local.message("ERR_Operation_Not_Supported",
331 "setJavaUtilDate", "KeyValueHandlerImpl"));
334 public void setJavaSqlTime(int fieldNumber, Time value) {
335 throw new ClusterJFatalInternalException(
336 local.message("ERR_Operation_Not_Supported",
337 "setJavaSqlTime", "KeyValueHandlerImpl"));
340 public void setJavaSqlTimestamp(int fieldNumber, Timestamp value) {
341 throw new ClusterJFatalInternalException(
342 local.message("ERR_Operation_Not_Supported",
343 "setJavaSqlTimestamp", "KeyValueHandlerImpl"));
346 public void markModified(int fieldNumber) {
347 throw new UnsupportedOperationException("Not supported yet.");
350 public void resetModified() {
351 throw new UnsupportedOperationException("Not supported yet.");
354 public String pkToString(DomainTypeHandler<?> domainTypeHandler) {
355 StringBuffer sb = new StringBuffer(" key: [");
356 int[] keys = domainTypeHandler.getKeyFieldNumbers();
357 String separator = "";
359 sb.append(separator);
360 sb.append(values[i]);
364 return sb.toString();
367 public void found(Boolean found) {
368 throw new ClusterJFatalInternalException(
369 local.message("ERR_Operation_Not_Supported",
370 "found(Boolean)", "KeyValueHandlerImpl"));
373 public ColumnMetadata[] columnMetadata() {
374 throw new ClusterJFatalInternalException(
375 local.message("ERR_Operation_Not_Supported",
376 "columnMetadata", "KeyValueHandlerImpl"));
379 public Boolean found() {
380 throw new ClusterJFatalInternalException(
381 local.message("ERR_Operation_Not_Supported",
382 "found", "KeyValueHandlerImpl"));
385 public Object get(int columnNumber) {
386 throw new ClusterJFatalInternalException(
387 local.message("ERR_Operation_Not_Supported",
388 "get(int)", "KeyValueHandlerImpl"));
391 public void set(int columnNumber, Object value) {
392 throw new ClusterJFatalInternalException(
393 local.message("ERR_Operation_Not_Supported",
394 "set(int, Object)", "KeyValueHandlerImpl"));