* @throws T2DBException
*/
public <T>void updateValueType(ValueType<T> vt, SchemaUpdatePolicy policy) throws T2DBException {
boolean done = false;
Throwable cause = null;
Surrogate s = vt.getSurrogate();
MongoDatabase database = (MongoDatabase) s.getDatabase();
try {
check(Permission.MODIFY, vt);
DBCollection coll = getMongoDB(s).getValueTypes();
if (vt.isRestricted() && vt.getValues().size() > 0) {
ValueType<T> original = database.getReadMethodsForValueType().getValueType(s);
Set<T> deleted = deletedValues(original, vt);
com.mongodb.DBObject operation = operation(Operator.SET,
MongoDatabase.FLD_VT_NAME, vt.getName(),
MongoDatabase.FLD_VT_VALUES, valueDescriptionsAsMap(vt));
if (deleted.size() > 0) {
// dangerous update! see comment in MongoDatabase.sleep
Iterator<T> it = deleted.iterator();
while (it.hasNext()) {
policy.willDelete(vt, it.next());
}
coll.update(asQuery(s.getId()), operation, false, false, WriteConcern.SAFE);
database.sleep();
try {
it = deleted.iterator();
while (it.hasNext()) {
policy.willDelete(vt, it.next());
}
} catch (T2DBException e) {
// restore state and throw exception
operation = operation(Operator.SET,
MongoDatabase.FLD_VT_NAME, original.getName(),
MongoDatabase.FLD_VT_VALUES, valueDescriptionsAsMap(original));
coll.update(asQuery(s.getId()), operation);
throw e;
}
} else {
coll.update(asQuery(s.getId()), operation);
}
} else
coll.update(asQuery(s.getId()), operation(Operator.SET, MongoDatabase.FLD_VT_NAME, vt.getName()));
done = true;
} catch (Exception e) {
cause = e;
} finally {
}