18 package com.mysql.clusterj.openjpa;
20 import com.mysql.clusterj.core.spi.DomainTypeHandler;
21 import com.mysql.clusterj.core.store.ResultData;
22 import com.mysql.clusterj.core.util.I18NHelper;
23 import com.mysql.clusterj.core.util.Logger;
24 import com.mysql.clusterj.core.util.LoggerFactoryService;
28 import java.sql.SQLException;
29 import java.sql.Types;
30 import java.util.BitSet;
31 import java.util.HashMap;
34 import org.apache.openjpa.jdbc.kernel.JDBCStore;
35 import org.apache.openjpa.jdbc.meta.JavaSQLTypes;
36 import org.apache.openjpa.jdbc.schema.Column;
37 import org.apache.openjpa.jdbc.sql.AbstractResult;
38 import org.apache.openjpa.jdbc.sql.Joins;
39 import org.apache.openjpa.jdbc.sql.Result;
40 import org.apache.openjpa.meta.JavaTypes;
69 private Map<
String, com.mysql.clusterj.core.store.Column> columnMap =
70 new HashMap<
String, com.mysql.clusterj.core.store.Column>();
83 Set<com.mysql.clusterj.core.store.Column> storeColumns = domainTypeHandler.getStoreColumns(fields);
84 for (com.mysql.clusterj.core.store.Column storeColumn: storeColumns) {
85 columnMap.put(storeColumn.getName(), storeColumn);
90 protected boolean nextInternal() throws SQLException {
92 if (logger.isDetailEnabled()) {
93 logger.detail(
"returning: " + result);
99 protected boolean containsInternal(Object obj, Joins joins)
throws SQLException {
101 com.mysql.clusterj.core.store.Column storeColumn = resolve(obj);
102 return storeColumn != null;
106 protected Object getObjectInternal(Object obj,
int metaType, Object arg, Joins joins)
throws SQLException {
109 Object result = null;
110 com.mysql.clusterj.core.store.Column columnName = resolve(obj);
112 case JavaTypes.INT_OBJ:
118 case JavaTypes.DOUBLE_OBJ:
121 case JavaTypes.DOUBLE:
124 case JavaTypes.FLOAT_OBJ:
127 case JavaTypes.FLOAT:
130 case JavaTypes.STRING:
133 case JavaTypes.LONG_OBJ:
139 case JavaTypes.BIGDECIMAL:
142 case JavaTypes.BIGINTEGER:
143 result =
resultData.getBigInteger(columnName);
146 result =
new java.util.Date(
resultData.getLong(columnName));
148 case JavaSQLTypes.TIME:
149 result =
new java.sql.Time(
resultData.getLong(columnName));
151 case JavaSQLTypes.SQL_DATE:
152 result =
new java.sql.Date(
resultData.getLong(columnName));
154 case JavaSQLTypes.TIMESTAMP:
155 result =
new java.sql.Timestamp(
resultData.getLong(columnName));
157 case JavaSQLTypes.BYTES:
160 case JavaTypes.BOOLEAN:
161 case JavaTypes.BOOLEAN_OBJ:
162 result =
resultData.getObjectBoolean(columnName);
165 if (obj instanceof Column) {
166 Column col = (Column) obj;
167 if (col.getType() == Types.BLOB
168 || col.getType() == Types.VARBINARY) {
174 if (logger.isDetailEnabled()) {
175 logger.detail(
"obj: " + obj +
" arg: " + arg +
" joins: " + joins +
" metaType: " + metaType +
" result: " + result);
181 protected Object getStreamInternal(JDBCStore store, Object obj,
int metaType, Object arg, Joins joins)
throws SQLException {
182 throw new UnsupportedOperationException(
"Not supported yet.");
185 public int size() throws SQLException {
186 throw new UnsupportedOperationException(
"Not supported yet.");
198 throws SQLException {
200 JavaTypes.LONG, null, joins));
201 return (val == null) ? 0 : val.longValue();
204 protected com.mysql.clusterj.core.store.Column resolve(Object obj) {
206 com.mysql.clusterj.core.store.Column result = null;
207 if (logger.isDetailEnabled()) {
208 logger.detail(
"resolving object of type: " + obj.getClass().getName());
210 if (obj instanceof
String) {
212 result = columnMap.get(key);
213 }
else if (obj instanceof Column) {
214 key = ((Column)obj).getName();
215 result = columnMap.get(key);
217 throw new UnsupportedOperationException(
218 local.
message(
"ERR_Unsupported_Object_Type_For_Resolve", obj.getClass().getName()));
220 if (logger.isDetailEnabled()) logger.detail(
"key: " + key +
" column: " + ((result==null)?
"<null>":result.getName()));
225 return columnMap.keySet();