* @throws T2DBException
*/
public boolean updateSchema(UpdatableSchema schema, SchemaUpdatePolicy policy) throws T2DBException {
boolean done = false;
Throwable cause = null;
Surrogate s = schema.getSurrogate();
MongoDatabase database = (MongoDatabase) s.getDatabase();
try {
check(Permission.MODIFY, schema);
UpdatableSchema original = database.getReadMethodsForSchema().getSchema(s);
Schema base = schema.getBase();
if (base != null && !base.equals(original.getBase()))
check(Permission.READ, base);
DBCollection coll = getMongoDB(s).getSchemas();
// full replace (no need to set _id in full update)
com.mongodb.DBObject operation = mongoObject(
MongoDatabase.FLD_SCHEMA_NAME, schema.getName(),
MongoDatabase.FLD_SCHEMA_BASE, getIdOrZero(schema.getBase()),
MongoDatabase.FLD_SCHEMA_ATTRIBS,
attributeDefinitions(schema.getAttributeDefinitions()),
MongoDatabase.FLD_SCHEMA_SERIES,
seriesDefinitions(schema.getSeriesDefinitions()));
coll.update(asQuery(s.getId()), operation, false, false, WriteConcern.SAFE);
database.sleep();
try {
policy.willUpdate(schema);
} catch (T2DBException e) {
// Oops! referential integrity broken!
operation = mongoObject(
MongoDatabase.FLD_SCHEMA_NAME, original.getName(),
MongoDatabase.FLD_SCHEMA_BASE, getId(original.getBase()),
MongoDatabase.FLD_SCHEMA_ATTRIBS, original.getAttributeDefinitions(),
MongoDatabase.FLD_SCHEMA_SERIES, original.getSeriesDefinitions());
coll.update(asQuery(s.getId()), operation);
throw e;
}
done = true;
} catch (Exception e) {
cause = e;