) parameters.get(PARAMETER_CUSTOM_DATA_OBJECT_BINDING);
+ binding.setObjectType(arrayType.getComponentType());
+ return new ArrayWrapper(binding);
+ } else {
return new ArrayWrapper(DataObjectBinding.getDataObjectBinding(
arrayType.getComponentType(), bindingType));
}
+ }
}
}
diff -r 718bb89ca52e -r 18df2bf882ee src/net/lemnik/eodsql/spi/util/CollectionWrapperFactory.java
--- a/src/net/lemnik/eodsql/spi/util/CollectionWrapperFactory.java Sat Sep 18 23:25:53 2010 +0200
+++ b/src/net/lemnik/eodsql/spi/util/CollectionWrapperFactory.java Sat Sep 18 23:31:37 2010 +0200
@@ -27,6 +27,7 @@
import net.lemnik.eodsql.spi.util.DataObjectBinding.BindingType;
import static net.lemnik.eodsql.spi.util.ResultSetWrapper.PARAMETER_BINDING_TYPE;
+import static net.lemnik.eodsql.spi.util.ResultSetWrapper.PARAMETER_CUSTOM_DATA_OBJECT_BINDING;
/**
*
@@ -174,9 +175,15 @@
final Class> dataObject = (Class>)ptype.getActualTypeArguments()[0];
- final DataObjectBinding binding = DataObjectBinding.getDataObjectBinding(
- dataObject,
- bindingType);
+ final DataObjectBinding binding;
+ if (parameters.containsKey(PARAMETER_CUSTOM_DATA_OBJECT_BINDING)) {
+ final DataObjectBinding
+ customBinding = (DataObjectBinding) parameters.get(PARAMETER_CUSTOM_DATA_OBJECT_BINDING);
+ customBinding.setObjectType((Class) dataObject);
+ binding = customBinding;
+ } else {
+ binding = DataObjectBinding.getDataObjectBinding(dataObject, bindingType);
+ }
if(clazz.equals(Collection.class) || clazz.equals(List.class)) {
return new ListWrapper(binding);
diff -r 718bb89ca52e -r 18df2bf882ee src/net/lemnik/eodsql/spi/util/DataIteratorWrapper.java
--- a/src/net/lemnik/eodsql/spi/util/DataIteratorWrapper.java Sat Sep 18 23:25:53 2010 +0200
+++ b/src/net/lemnik/eodsql/spi/util/DataIteratorWrapper.java Sat Sep 18 23:31:37 2010 +0200
@@ -115,6 +115,7 @@
return true;
}
+ @SuppressWarnings("unchecked")
public ResultSetWrapper create(
final Type genericType,
final Map parameters) {
@@ -122,10 +123,17 @@
final ParameterizedType parameterType = (ParameterizedType)genericType;
final Class> clazz = (Class>)parameterType.getActualTypeArguments()[0];
- final DataObjectBinding> binding = DataObjectBinding.
- getDataObjectBinding(
+ final DataObjectBinding> binding;
+ if (parameters.containsKey(PARAMETER_CUSTOM_DATA_OBJECT_BINDING)) {
+ final DataObjectBinding
+ customBinding = (DataObjectBinding) parameters.get(PARAMETER_CUSTOM_DATA_OBJECT_BINDING);
+ customBinding.setObjectType((Class) clazz);
+ binding = customBinding;
+ } else {
+ binding = DataObjectBinding.getDataObjectBinding(
clazz,
AbstractResultSetWrapper.getBindingType(parameters));
+ }
return new DataIteratorWrapper(binding, parameters);
}
diff -r 718bb89ca52e -r 18df2bf882ee src/net/lemnik/eodsql/spi/util/DataObjectBinding.java
--- a/src/net/lemnik/eodsql/spi/util/DataObjectBinding.java Sat Sep 18 23:25:53 2010 +0200
+++ b/src/net/lemnik/eodsql/spi/util/DataObjectBinding.java Sat Sep 18 23:31:37 2010 +0200
@@ -407,6 +407,9 @@
@SuppressWarnings(value = "unchecked")
final DataObjectBinding binding =
(DataObjectBinding)bindingClass.newInstance();
+ if (binding.getObjectType() == null) {
+ binding.setObjectType(dataObject);
+ }
return trySetBindingType(binding, bindingType);
} catch(final InstantiationException instantiationException) {
throw new EoDException(instantiationException);
diff -r 718bb89ca52e -r 18df2bf882ee src/net/lemnik/eodsql/spi/util/DataSetWrapper.java
--- a/src/net/lemnik/eodsql/spi/util/DataSetWrapper.java Sat Sep 18 23:25:53 2010 +0200
+++ b/src/net/lemnik/eodsql/spi/util/DataSetWrapper.java Sat Sep 18 23:31:37 2010 +0200
@@ -89,8 +89,15 @@
final Class dataObjectType,
final Map parameters) {
+ if (parameters.containsKey(PARAMETER_CUSTOM_DATA_OBJECT_BINDING)) {
+ final DataObjectBinding
+ customBinding = (DataObjectBinding) parameters.get(PARAMETER_CUSTOM_DATA_OBJECT_BINDING);
+ customBinding.setObjectType(dataObjectType);
+ binding = customBinding;
+ } else {
binding = DataObjectBinding.getDataObjectBinding(dataObjectType,
AbstractResultSetWrapper.getBindingType(parameters));
+ }
disconnected = isDisconnected(parameters);
updatable = isUpdatable(parameters);
diff -r 718bb89ca52e -r 18df2bf882ee src/net/lemnik/eodsql/spi/util/NoDataObjectBinding.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/net/lemnik/eodsql/spi/util/NoDataObjectBinding.java Sat Sep 18 23:31:37 2010 +0200
@@ -0,0 +1,23 @@
+package net.lemnik.eodsql.spi.util;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import net.lemnik.eodsql.EoDException;
+
+/**
+ * A tag class indicating that no custom data object binding is to be used.
+ *
+ * @author Bernd Rinn
+ */
+public final class NoDataObjectBinding extends DataObjectBinding {
+ @Override
+ public void marshall(T from, ResultSet results) throws SQLException, EoDException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void unmarshall(ResultSet row, T into) throws SQLException, EoDException {
+ throw new UnsupportedOperationException();
+ }
+}
diff -r 718bb89ca52e -r 18df2bf882ee src/net/lemnik/eodsql/spi/util/ResultSetWrapper.java
--- a/src/net/lemnik/eodsql/spi/util/ResultSetWrapper.java Sat Sep 18 23:25:53 2010 +0200
+++ b/src/net/lemnik/eodsql/spi/util/ResultSetWrapper.java Sat Sep 18 23:31:37 2010 +0200
@@ -62,6 +62,14 @@
public static final String PARAMETER_BINDING_TYPE =
"net.lemnik.eodsql.spi.util.ResultSetWrapper#bindingType";
+ /**
+ *
+ * This parameter allows to set a custom class for data object binding for this query. The
+ * default value {@link NoDataObjectBinding} means: no custom binding is requested.
+ *
+ */
+ public static final String PARAMETER_CUSTOM_DATA_OBJECT_BINDING = "net.lemnik.eodsql.spi.util.ResultSetWrapper#binding";
+
private static final Set FACTORIES = new LinkedHashSet(4);
private static final Map NO_PARAMETERS =
@@ -111,17 +119,20 @@
@SuppressWarnings("unchecked")
private static ResultSetWrapper getResultSetWrapperForSimpleClass(
final Class> type,
- final Type genericReturnType,
- final BindingType bindingType) {
+ final BindingType bindingType,
+ final DataObjectBinding customBinding) {
+ if (customBinding != null) {
+ customBinding.setObjectType(type);
+ return new SingleRowResultSetWrapper(customBinding);
+ }
+
final TypeMapper> mapper = QueryTool.getTypeMap().get(type);
if(mapper != null) {
return getTypeMapperResultSetWrapper(mapper, (Class)type);
} else {
- return getDataObjectResultSetWrapper(
- (Class>)genericReturnType,
- bindingType);
+ return getDataObjectResultSetWrapper(type, bindingType);
}
}
@@ -185,6 +196,23 @@
}
/**
+ * Returns the custom binding, or null
, if no custom binding is specified in the
+ * parameter {@code Map}.
+ *
+ * @param parameters the parameters as specified in {@link #get(java.lang.reflect.Type, java.util.Map)}
+ * @return the {@code DataObjectBinding} that should be used according to the parameter {@code Map}
+ */
+ protected static DataObjectBinding> getCustomBinding(
+ final Map parameters) {
+
+ if(parameters.containsKey(DataSetWrapper.PARAMETER_CUSTOM_DATA_OBJECT_BINDING)) {
+ return (DataObjectBinding>)parameters.get(DataSetWrapper.PARAMETER_CUSTOM_DATA_OBJECT_BINDING);
+ }
+
+ return null;
+ }
+
+ /**
* Wrap the given {@code Context} in whatever type this {@code ResultSetWrapper} should
* return. This method by default makes a call to {@link #wrap(java.sql.ResultSet)}, but can
* be overriden if required (for example to switch of {@link Context#setAutoclose(boolean)
@@ -353,8 +381,8 @@
return getResultSetWrapperForSimpleClass(
type,
- genericReturnType,
- getBindingType(parameters));
+ getBindingType(parameters),
+ getCustomBinding(parameters));
} else {
for(final Factory f : FACTORIES) {
if(f.isTypeConstructable(genericReturnType, parameters)) {