// Make sure only changed fields are updated
if (!dco.isChanged(field.getIndex()))
continue;
if (field.getValueType() == DcRepository.ValueTypes._PICTURE) {
Picture picture = (Picture) dco.getValue(field.getIndex());
if (picture != null && (picture.isNew() || picture.isEdited() || picture.isDeleted())) {
picture.setValue(Picture._A_OBJECTID, dco.getID());
picture.setValue(Picture._B_FIELD, field.getDatabaseFieldName());
picture.setValue(Picture._C_FILENAME, dco.getID() + "_" + field.getDatabaseFieldName() + ".jpg");
ImageIcon icon = (ImageIcon) picture.getValue(Picture._D_IMAGE);
if (icon != null) {
picture.setValue(Picture._E_HEIGHT, Long.valueOf(icon.getIconHeight()));
picture.setValue(Picture._F_WIDTH, Long.valueOf(icon.getIconWidth()));
pictures.add(picture);
}
}
} else if (field.getValueType() == DcRepository.ValueTypes._DCOBJECTCOLLECTION) {
Collection<DcMapping> c = (Collection<DcMapping>) dco.getValue(field.getIndex());
if (c != null) references.add(c);
if (dco.isChanged(field.getIndex())) {
DcModule mappingMod = DcModules.get(DcModules.getMappingModIdx(field.getModule(), field.getReferenceIdx(), field.getIndex()));
String sql = "DELETE FROM " + mappingMod.getTableName() + " WHERE " +
mappingMod.getField(DcMapping._A_PARENT_ID).getDatabaseFieldName() + " = '" + dco.getID() + "'";
stmt.execute(sql);
}
} else if (dco.isChanged(field.getIndex()) && !field.isUiOnly()) {
if (sbValues.length() > 0)
sbValues.append(", ");
sbValues.append(field.getDatabaseFieldName());
sbValues.append(" = ?");
values.add(getQueryValue(dco, field.getIndex()));
}
}
String s = sbValues.toString();
if (dco.getModule().getIndex() != DcModules._PICTURE && !Utilities.isEmpty(values)) {
ps = conn.prepareStatement("UPDATE " + dco.getTableName() + " SET " + s + "\r\n WHERE ID = '" + dco.getID() + "'");
setValues(ps, values);
ps.execute();
ps.close();
} else if (!Utilities.isEmpty(values)) {
ps = conn.prepareStatement("UPDATE " + dco.getTableName() + " SET " + s + "\r\n WHERE " +
dco.getDatabaseFieldName(Picture._A_OBJECTID) + " = '" + dco.getValue(Picture._A_OBJECTID) + "' AND " +
dco.getDatabaseFieldName(Picture._B_FIELD) + " = '" + dco.getValue(Picture._B_FIELD) + "'");
setValues(ps, values);
ps.execute();
ps.close();
}
int counter = 0;
for (Collection<DcMapping> c : references) {
counter = 0;
for (DcMapping mapping : c) {
stmt.execute("INSERT INTO " + mapping.getTableName() +
" (" + mapping.getDatabaseFieldName(DcMapping._A_PARENT_ID) + ", " +
mapping.getDatabaseFieldName(DcMapping._B_REFERENCED_ID) +
") \r\n VALUES ('" + dco.getID() + "', '" + mapping.getReferencedID() + "');");
counter++;
}
}
for (Picture picture : pictures) {
if (picture.isNew()) {
new InsertQuery(picture).run();
saveImage(picture);
} else if (picture.isEdited()) {
new UpdateQuery(picture).run();
saveImage(picture);
} else if (picture.isDeleted()) {
stmt.execute("DELETE FROM " + picture.getTableName() + " WHERE " +
picture.getField(Picture._A_OBJECTID).getDatabaseFieldName() + " = '" + dco.getID() + "' AND " +
picture.getField(Picture._B_FIELD).getDatabaseFieldName() + " = '" + picture.getValue(Picture._B_FIELD) + "'");
deleteImage(picture);
}
}
for (DcObject child : dco.getCurrentChildren()) {