mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2199 - ScalarTypeWrapper doesn't handle "nullValue" correctly
Handles the case for ScalarTypeConverter with custom null value and binding the custom null value (via query parameter, CallableSql parameter etc)
This commit is contained in:
@@ -177,9 +177,6 @@ public class ScalarTypeWrapper<B, S> implements ScalarType<B> {
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object toJdbcType(Object value) {
|
||||
Object sv = converter.unwrapValue((B) value);
|
||||
if (sv == null) {
|
||||
return nullValue;
|
||||
}
|
||||
return scalarType.toJdbcType(sv);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.ebeaninternal.server.type;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.tests.model.ivo.Oid;
|
||||
import org.tests.model.ivo.converter.OidTypeConverter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
public class ScalarTypeWrapperOidTest {
|
||||
|
||||
private final OidTypeConverter oidTypeConverter = new OidTypeConverter();
|
||||
private final ScalarTypeLong longType = new ScalarTypeLong();
|
||||
private final ScalarTypeWrapper<Oid<?>,Long> wrapper = new ScalarTypeWrapper(Oid.class, longType, oidTypeConverter);
|
||||
|
||||
@Test
|
||||
public void toJdbcType() {
|
||||
|
||||
assertThat(wrapper.toJdbcType(new Oid<String>(42))).isEqualTo(42L);
|
||||
assertThat(wrapper.toJdbcType(new Oid<String>(98))).isEqualTo(98L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toJdbcType_when_nullValue() {
|
||||
assertThat(wrapper.toJdbcType(OidTypeConverter.NULL_VALUE)).isNull();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,22 +5,21 @@ import org.tests.model.ivo.Oid;
|
||||
|
||||
public class OidTypeConverter implements ScalarTypeConverter<Oid<?>,Long> {
|
||||
|
||||
public static final Oid<?> NULL_VALUE = new Oid<>(0);
|
||||
|
||||
@Override
|
||||
public Oid<?> getNullValue() {
|
||||
return null;
|
||||
return NULL_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Oid<?> wrapValue(Long scalarType) {
|
||||
if (scalarType == null) {
|
||||
return null;
|
||||
}
|
||||
return new Oid<>(scalarType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long unwrapValue(Oid<?> beanType) {
|
||||
if (beanType == null) {
|
||||
if (NULL_VALUE.equals(beanType)) {
|
||||
return null;
|
||||
}
|
||||
return beanType.getValue();
|
||||
|
||||
Reference in New Issue
Block a user