Always update then insert in case for whatever reason the zeroth schema version

is not one (like for ItemRecord).
This commit is contained in:
Michael Bayne
2006-09-29 01:28:53 +00:00
parent 18491c5565
commit e903948eb1
@@ -540,14 +540,16 @@ public class DepotMarshaller<T>
protected void updateVersion (Connection conn, int version)
throws SQLException
{
String query = (version == 1) ?
"insert into " + SCHEMA_VERSION_TABLE +
" values('" + getTableName() + "', " + version + ")" :
"update " + SCHEMA_VERSION_TABLE + " set version = " + version +
String update = "update " + SCHEMA_VERSION_TABLE +
" set version = " + version +
" where persistentClass = '" + getTableName() + "'";
String insert = "insert into " + SCHEMA_VERSION_TABLE +
" values('" + getTableName() + "', " + version + ")";
Statement stmt = conn.createStatement();
try {
stmt.executeUpdate(query);
if (stmt.executeUpdate(update) == 0) {
stmt.executeUpdate(insert);
}
} finally {
stmt.close();
}