DB2: Do not try to update deferred null values (Discovered by TestPrinterStateIssue)

This commit is contained in:
Roland Praml
2022-01-07 15:25:11 +01:00
parent d4280bc033
commit 5f707053d3
4 changed files with 11 additions and 0 deletions
@@ -167,6 +167,7 @@ public final class BindParams implements Serializable {
*/
@SuppressWarnings("rawtypes")
public void setParameter(int position, Object value) {
assert value != null : "use setNullParameter";
Param p = getParam(position);
if (value instanceof Collection) {
// use of postgres ANY with positioned parameter
@@ -218,6 +219,7 @@ public final class BindParams implements Serializable {
* Set a named In parameter that is not null.
*/
public Param setParameter(String name, Object value) {
assert value != null : "use setNullParameter";
Param p = getParam(name);
p.setInValue(value);
return p;
@@ -40,6 +40,9 @@ public final class PersistDeferredRelationship {
// bind the set clause for the importedId
int pos = importedId.bind(1, sqlUpdate, assocBean);
if (pos == -1) {
return; // could not bind: TODO: should we log/throw an error?
}
// bind the where clause for the bean
Object[] idValues = beanDescriptor.idBinder().getIdValues(bean);
for (int j = 0; j < idValues.length; j++) {
@@ -85,6 +85,9 @@ public final class ImportedIdEmbedded implements ImportedId {
for (ImportedIdSimple anImported : imported) {
if (anImported.owner.isUpdateable()) {
Object scalarValue = anImported.foreignProperty.getValue(embedded);
if (scalarValue == null) {
return -1; // could not bind
}
update.setParameter(pos++, scalarValue);
}
}
@@ -151,6 +151,9 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
@Override
public int bind(int position, SqlUpdate update, EntityBean bean) {
Object value = getIdValue(bean);
if (value == null) {
return -1; // could not bind
}
update.setParameter(position, value);
return ++position;
}