19 package com.mysql.clusterj.bindings;
21 import com.mysql.cluster.ndbj.NdbApiException;
22 import com.mysql.cluster.ndbj.NdbResultSet;
23 import com.mysql.clusterj.ClusterJDatastoreException;
24 import com.mysql.clusterj.core.store.Blob;
25 import com.mysql.clusterj.core.store.Column;
26 import com.mysql.clusterj.core.store.ResultData;
27 import com.mysql.clusterj.core.util.I18NHelper;
28 import com.mysql.clusterj.core.util.Logger;
29 import com.mysql.clusterj.core.util.LoggerFactoryService;
30 import java.math.BigDecimal;
32 import java.sql.SQLException;
34 import java.sql.Timestamp;
39 class ResultDataImpl
implements ResultData {
42 static final I18NHelper local = I18NHelper
43 .getInstance(ClusterTransactionImpl.class);
46 static final Logger logger = LoggerFactoryService.getFactory()
47 .getInstance(ClusterTransactionImpl.class);
52 this.resultData = resultData;
55 public Blob getBlob(Column storeColumn) {
57 return new BlobImpl(resultData.getBlob(storeColumn.getName()));
58 }
catch (NdbApiException ndbApiException) {
59 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
64 public Date getDate(Column storeColumn) {
66 Date result = resultData.getDate(storeColumn.getName());
67 if ((result != null) && wasNull(storeColumn.getName())) {
68 logger.info(
"Column was null but non-null was returned.");
72 }
catch (NdbApiException ndbApiException) {
73 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
75 }
catch (SQLException sqlException) {
76 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
81 public BigDecimal getDecimal(Column storeColumn) {
83 BigDecimal result = resultData.getDecimal(storeColumn.getName());
84 if ((result != null) && wasNull(storeColumn.getName())) {
85 logger.info(
"Column was null but non-null was returned.");
89 }
catch (NdbApiException ndbApiException) {
90 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
95 public boolean getBoolean(Column storeColumn) {
96 throw new UnsupportedOperationException(local.message(
"ERR_NotImplemented"));
99 public boolean[] getBooleans(Column storeColumn) {
100 throw new UnsupportedOperationException(local.message(
"ERR_NotImplemented"));
103 public byte getByte(Column storeColumn) {
106 return (byte)resultData.getInt(storeColumn.getName());
107 }
catch (NdbApiException ndbApiException) {
108 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
113 public double getDouble(Column storeColumn) {
115 return resultData.getDouble(storeColumn.getName());
116 }
catch (NdbApiException ndbApiException) {
117 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
122 public float getFloat(Column storeColumn) {
124 return resultData.getFloat(storeColumn.getName());
125 }
catch (NdbApiException ndbApiException) {
126 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
131 public int getInt(Column storeColumn) {
133 return resultData.getInt(storeColumn.getName());
134 }
catch (NdbApiException ndbApiException) {
135 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
140 public long getLong(Column storeColumn) {
142 return resultData.getLong(storeColumn.getName());
143 }
catch (NdbApiException ndbApiException) {
144 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
149 public short getShort(Column storeColumn) {
151 return resultData.getShort(storeColumn.getName());
152 }
catch (NdbApiException ndbApiException) {
153 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
158 public String getString(Column storeColumn) {
160 String result = resultData.getString(storeColumn.getName());
161 if (wasNull(storeColumn.getName())) {
162 if (result != null) {
163 logger.info(
"Column " + storeColumn.getName() +
" was null but non-null was returned.");
168 }
catch (NdbApiException ndbApiException) {
169 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
174 public Time getTime(Column storeColumn) {
176 Time result = resultData.getTime(storeColumn.getName());
177 if ((result != null) && wasNull(storeColumn.getName())) {
178 logger.info(
"Column was null but non-null was returned.");
182 }
catch (NdbApiException ndbApiException) {
183 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
185 }
catch (SQLException sqlException) {
186 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
191 public Timestamp getTimestamp(Column storeColumn) {
193 Timestamp result = resultData.getTimestamp(storeColumn.getName());
194 if ((result != null) && wasNull(storeColumn.getName())) {
195 logger.info(
"Column was null but non-null was returned.");
199 }
catch (NdbApiException ndbApiException) {
200 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
205 public Timestamp getDatetime(Column storeColumn) {
206 return getTimestamp(storeColumn);
209 public boolean next() {
211 return resultData.next();
212 }
catch (NdbApiException ndbApiException) {
213 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
218 public byte[] getBytes(Column storeColumn) {
219 if (logger.isDetailEnabled()) logger.detail(
"Column name: " + storeColumn.getName());
221 byte[] result = resultData.getBytes(storeColumn.getName());
222 if ((result != null) && wasNull(storeColumn.getName())) {
223 logger.info(
"Column was null but non-null was returned.");
227 }
catch (NdbApiException ndbApiException) {
228 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
233 public byte[] getStringBytes(Column storeColumn) {
234 if (logger.isDetailEnabled()) logger.detail(
"Column name: " + storeColumn.getName());
236 byte[] result = resultData.getStringBytes(storeColumn.getName());
237 if ((result != null) && wasNull(storeColumn.getName())) {
238 logger.info(
"Column was null but non-null was returned.");
242 }
catch (NdbApiException ndbApiException) {
243 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
249 public Object getObject(Column storeColumn) {
251 return resultData.getObject(storeColumn.getName());
252 }
catch (NdbApiException ndbApiException) {
253 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
255 }
catch (SQLException sqlException) {
256 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
261 public boolean wasNull(
String columnName) {
263 return resultData.wasNull();
264 }
catch (NdbApiException ndbApiException) {
265 throw new ClusterJDatastoreException(local.message(
"ERR_Datastore"),
270 public Boolean getObjectBoolean(Column storeColumn) {
271 throw new UnsupportedOperationException(local.message(
"ERR_NotImplemented"));
274 public Byte getObjectByte(Column storeColumn) {
275 Byte result = getByte(storeColumn);
276 return (wasNull(storeColumn.getName())?null:result);
279 public Double getObjectDouble(Column storeColumn) {
280 Double result = getDouble(storeColumn);
281 return (wasNull(storeColumn.getName())?null:result);
284 public Float getObjectFloat(Column storeColumn) {
285 Float result = getFloat(storeColumn);
286 return (wasNull(storeColumn.getName())?null:result);
289 public Integer getObjectInteger(Column storeColumn) {
290 Integer result = getInt(storeColumn);
291 return (wasNull(storeColumn.getName())?null:result);
294 public Long getObjectLong(Column storeColumn) {
295 Long result = getLong(storeColumn);
296 return (wasNull(storeColumn.getName())?null:result);
299 public Short getObjectShort(Column storeColumn) {
300 Short result = getShort(storeColumn);
301 return (wasNull(storeColumn.getName())?null:result);