results = select.executeQuery();
while(results.next()) {
VectorClock version = new VectorClock(results.getBytes("version_"));
Occurred occurred = value.getVersion().compare(version);
if(occurred == Occurred.BEFORE)
throw new ObsoleteVersionException("Attempt to put version "
+ value.getVersion()
+ " which is superceeded by " + version
+ ".");
else if(occurred == Occurred.AFTER)
delete(conn, key.get(), version.toBytes());
}
// Okay, cool, now put the value
insert = conn.prepareStatement(insertSql);
insert.setBytes(1, key.get());
VectorClock clock = (VectorClock) value.getVersion();
insert.setBytes(2, clock.toBytes());
insert.setBytes(3, value.getValue());
insert.executeUpdate();
doCommit = true;
} catch(SQLException e) {
if(e.getErrorCode() == MYSQL_ERR_DUP_KEY || e.getErrorCode() == MYSQL_ERR_DUP_ENTRY) {
throw new ObsoleteVersionException("Key or value already used.");
} else {
throw new PersistenceFailureException("Fix me!", e);
}
} finally {
if(conn != null) {