From 8dd12b631bde3ed9ba476770f1a2f52270d6b7d4 Mon Sep 17 00:00:00 2001 From: bernd Date: Wed, 14 Nov 2012 21:24:31 +0100 Subject: [PATCH 13/25] Do not try to set auto key columns when marshalling into a ResultSet as some databases (notabley Derby aka JavaDB) do not fancy that and throws an exception on update. --- .../net/lemnik/eodsql/spi/util/DefaultDataObjectBinding.java | 10 ++++++---- eodsql/src/net/lemnik/eodsql/spi/util/MutableColumn.java | 2 ++ eodsql/src/net/lemnik/eodsql/spi/util/MutableField.java | 5 +++++ eodsql/src/net/lemnik/eodsql/spi/util/MutableProperty.java | 6 ++++++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/eodsql/src/net/lemnik/eodsql/spi/util/DefaultDataObjectBinding.java b/eodsql/src/net/lemnik/eodsql/spi/util/DefaultDataObjectBinding.java index 86ee656..c0b1ccb 100644 --- a/eodsql/src/net/lemnik/eodsql/spi/util/DefaultDataObjectBinding.java +++ b/eodsql/src/net/lemnik/eodsql/spi/util/DefaultDataObjectBinding.java @@ -281,10 +281,12 @@ class DefaultDataObjectBinding extends DataObjectBinding { if(columns[i] != null) { final Object value = columns[i].get(from); - if(value == null) { - results.updateNull(i + 1); - } else { - ((TypeMapper)mappers[i]).set(results, i + 1, value); + if (false == columns[i].isAutoKey()) { + if(value == null) { + results.updateNull(i + 1); + } else { + ((TypeMapper)mappers[i]).set(results, i + 1, value); + } } } } diff --git a/eodsql/src/net/lemnik/eodsql/spi/util/MutableColumn.java b/eodsql/src/net/lemnik/eodsql/spi/util/MutableColumn.java index ef46a53..a1379ef 100644 --- a/eodsql/src/net/lemnik/eodsql/spi/util/MutableColumn.java +++ b/eodsql/src/net/lemnik/eodsql/spi/util/MutableColumn.java @@ -17,5 +17,7 @@ interface MutableColumn { Object get(Object object) throws EoDException; Class getType(); + + boolean isAutoKey(); } diff --git a/eodsql/src/net/lemnik/eodsql/spi/util/MutableField.java b/eodsql/src/net/lemnik/eodsql/spi/util/MutableField.java index 972f68d..fc1af5c 100644 --- a/eodsql/src/net/lemnik/eodsql/spi/util/MutableField.java +++ b/eodsql/src/net/lemnik/eodsql/spi/util/MutableField.java @@ -3,6 +3,7 @@ package net.lemnik.eodsql.spi.util; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import net.lemnik.eodsql.AutoGeneratedKeys; import net.lemnik.eodsql.EoDException; /** @@ -68,4 +69,8 @@ class MutableField implements MutableColumn { return field.getDeclaringClass().getName() + "." + field.getName(); } + public boolean isAutoKey() { + return field.isAnnotationPresent(AutoGeneratedKeys.class); + } + } diff --git a/eodsql/src/net/lemnik/eodsql/spi/util/MutableProperty.java b/eodsql/src/net/lemnik/eodsql/spi/util/MutableProperty.java index 63f79b1..b481353 100644 --- a/eodsql/src/net/lemnik/eodsql/spi/util/MutableProperty.java +++ b/eodsql/src/net/lemnik/eodsql/spi/util/MutableProperty.java @@ -3,6 +3,8 @@ package net.lemnik.eodsql.spi.util; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; + +import net.lemnik.eodsql.AutoGeneratedKeys; import net.lemnik.eodsql.EoDException; /** @@ -77,4 +79,8 @@ class MutableProperty implements MutableColumn { return type; } + public boolean isAutoKey() { + return setter.isAnnotationPresent(AutoGeneratedKeys.class); + } + } -- 1.8.0