public void setUseAutoPrimaryKeyUpdate(boolean useAutoPrimaryKeyUpdate) {
this.useAutoPrimaryKeyUpdate = useAutoPrimaryKeyUpdate;
}
public String getUpdateSQL(ORMappingSupport data) {
SQLParser parser = new SQLParser();
StringBuffer values = new StringBuffer();
String tableName = null;
blobIndex = 0;
for (RdbColumnMetaData col : updateColumns.toArray(new RdbColumnMetaData[updateColumns.size()])) {
if (tableName == null) tableName = col.getRdbTableMetaData().getTableName();
if (col.isPrimaryKey()) {
if (useAutoPrimaryKeyUpdate) {
addWhere("and", parser.value(col, Condition.EQUAL, data.getValue(col)));
}
continue;
}
if (col.isAutoGenerateId()) continue;
if (data.isUpdate(col)) {
if (values.length() > 0) {
values.append(",");
}
values.append(parser.value(col, Condition.EQUAL, data.getValue(col))
.replaceFirst(tableName+".", ""));
} else if (col.isAutoTimestamp()) {
if (values.length() > 0) {
values.append(",");
}
values.append(parser.value(col, Condition.EQUAL, getTimestampString())
.replaceFirst(tableName+".", ""));
} else if (col.getType() == RdbDataType.OBJECT) {
if (values.length() > 0) {
values.append(",");
}
values.append(parser.value(col, Condition.EQUAL, "?"));
blobIndex++;
}
}
String query = UPDATE.replace("${TABLE}", tableName)
.replace("${VALUES}", values.toString());