}
public UpdateCommandImpl getUpdateCommand(MappingWrapper mapping, DataObject changedObject, Table table) {
ArrayList parameters = new ArrayList();
Type type = changedObject.getType();
TableWrapper t = new TableWrapper(table);
StringBuffer statement = new StringBuffer("update ");
statement.append(table.getName());
statement.append(" set ");
ChangeSummary summary = changedObject.getDataGraph().getChangeSummary();
Iterator i = getChangedFields(mapping, summary, changedObject).iterator();
while (i.hasNext()) {
Property attr = (Property) i.next();
Column c = t.getColumnByPropertyName(attr.getName());
if ((c != null) && (c.isCollision() || c.isPrimaryKey())) {
// get rid of comma if OCC or PK is last field
if (!i.hasNext()) {
statement
.delete(statement.length() - 2, statement.length());
}
} else {
parameters.add(attr);
statement.append(c == null ? attr.getName() : c.getName());
statement.append(" = ?");
if (i.hasNext())
statement.append(", ");
}
}
statement.append(" where ");
Iterator names = t.getPrimaryKeyNames().iterator();
Iterator properties = t.getPrimaryKeyProperties().iterator();
while (names.hasNext() && properties.hasNext()) {
String name = (String) names.next();
String property = (String) properties.next();
statement.append(name);
statement.append(" = ?");
if (names.hasNext() && properties.hasNext())
statement.append(" and ");
parameters.add(type.getProperty(property));
}
if (t.getCollisionColumn() != null) {
statement.append(" and ");
statement.append(t.getCollisionColumn().getName());
statement.append(" = ?");
parameters.add(type.getProperty(t.getCollisionColumnPropertyName()));
}
UpdateCommandImpl updateCommand;
if ( t.getCollisionColumn() != null )
updateCommand = new OptimisticWriteCommandImpl(statement.toString());
else
updateCommand = new UpdateCommandImpl(statement.toString());
Iterator params = parameters.iterator();