FIX: Reuse of io.ebean.Update with collection parameters did not work correctly

This commit is contained in:
Jonas Pöhler committed 2021-10-06 11:57:09 +02:00
1 parent e2c6125501
commit db6f93e383
5 files changed
+92 -12

No files matched your search

@@ -285,12 +285,17 @@ public final class BindParams implements Serializable {
*/
public boolean isSameBindHash() {
if (bindHash == null) {
bindHash = calcQueryPlanHash();
return false;
}
String oldPlan = bindHash;
String newHash = calcQueryPlanHash();
return bindHash.equals(newHash);
}
/**
* Updates the hash.
*/
public void updateHash() {
bindHash = calcQueryPlanHash();
return bindHash.equals(oldPlan);
}
/**
@@ -118,7 +118,11 @@ public final class Binder {
bindLog.append(value);
}
}
if (value == null) {
if (value instanceof Collection) {
for (Object entry: (Collection<?>) value) {
bindObject(dataBind, entry);
}
} else if (value == null) {
// this doesn't work for query predicates
bindObject(dataBind, null, param.getType());
} else {
@@ -79,6 +79,7 @@ public final class BindParamsParser {
preparedSql = sql;
}
params.setPreparedSql(preparedSql);
params.updateHash();
return preparedSql;
}
@@ -151,18 +152,15 @@ public final class BindParamsParser {
Object inValue = param.getInValue();
if (inValue instanceof Collection<?>) {
// Chop up Collection parameter into a number
// of individual parameters and add each one individually
// of individual parameters
Collection<?> collection = (Collection<?>) inValue;
int c = 0;
for (Object elVal : collection) {
if (++c > 1) {
for (int c = 0; c < collection.size(); c++) {
if (c > 0) {
orderedList.appendSql(",");
}
orderedList.appendSql("?");
BindParams.Param elParam = new BindParams.Param();
elParam.setInValue(elVal);
orderedList.add(elParam);
}
orderedList.add(param);
} else {
// its a normal scalar value parameter...