Skip to content

Commit

Permalink
fix #591
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaudroger committed Dec 5, 2018
1 parent 49d6425 commit ab081db
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 5 deletions.
@@ -1,7 +1,5 @@
package org.simpleflatmapper.jdbc.spring;

import org.simpleflatmapper.converter.ContextFactory;

import java.util.Arrays;

public final class ArrayPlaceHolderValueGetterSource<T> implements PlaceHolderValueGetterSource<T> {
Expand All @@ -15,7 +13,7 @@ public ArrayPlaceHolderValueGetterSource(PlaceHolderValueGetter<T>[] parameters)
@Override
public PlaceHolderValueGetter<T> getPlaceHolderValueGetter(String column) {
for(PlaceHolderValueGetter<T> parameter : parameters) {
if (parameter.isColumn(column)) {
if (parameter != null && parameter.isColumn(column)) {
return parameter;
}
}
Expand Down
Expand Up @@ -11,7 +11,9 @@ public MapPlaceHolderValueGetterSource(PlaceHolderValueGetter<T>[] parameters) {
this.parameters = new HashMap<String, PlaceHolderValueGetter<T>>();

for(PlaceHolderValueGetter<T> getter : parameters) {
this.parameters.put(getter.getColumn(), getter);
if (getter != null) {
this.parameters.put(getter.getColumn(), getter);
}
}
}

Expand Down
Expand Up @@ -118,7 +118,7 @@ public void handle(PropertyMapping<T, ?, JdbcColumnKey> pm) {
}
});

return parameters.length > 10
return parameters.length < 10
? new ArrayPlaceHolderValueGetterSource<T>(parameters)
: new MapPlaceHolderValueGetterSource<T>(parameters)
;
Expand Down
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

public class SqlParameterSourceTest {

Expand Down Expand Up @@ -196,4 +197,53 @@ public void testConstantValue() {
assertEquals(-3l, parameterSource.getValue("id"));

}


@Test
public void test591_MapStrategy() {
String sql = "INSERT INTO table VALUES(:id, :1, :2, :3, :4, :5, :6, :7, :8, :9, :unknown)";

SqlParameterSourceFactory<DbObject> sqlParameters =
JdbcTemplateMapperFactory
.newInstance()
.ignorePropertyNotFound()
.newSqlParameterSourceFactory(DbObject.class, sql);


DbObject dbObject = DbObject.newInstance();

SqlParameterSource parameterSource = sqlParameters.newSqlParameterSource(dbObject);

assertEquals(dbObject.getId(), parameterSource.getValue("id"));
assertFalse(parameterSource.hasValue("unknown"));

}

@Test
public void test591_ArrayStrategy() {
String sql = "INSERT INTO table VALUES(:id, :unknown)";

SqlParameterSourceFactory<DbObject> sqlParameters =
JdbcTemplateMapperFactory
.newInstance()
.ignorePropertyNotFound()
.newSqlParameterSourceFactory(DbObject.class, sql);


DbObject dbObject = DbObject.newInstance();

SqlParameterSource parameterSource = sqlParameters.newSqlParameterSource(dbObject);

assertEquals(dbObject.getId(), parameterSource.getValue("id"));
assertFalse(parameterSource.hasValue("unknown"));

}

public static class I591 {
private final long id;

public I591(long id) {
this.id = id;
}
}
}

0 comments on commit ab081db

Please sign in to comment.