private UpdatableSchema unpack(Database db, BasicDBObject obj, Set<ObjectId> cycleDetector) throws T2DBException {
if (cycleDetector == null)
cycleDetector = new HashSet<ObjectId>();
try {
ObjectId id = obj.getObjectId(MongoDatabase.FLD_ID);
Surrogate s = makeSurrogate(db, DBObjectType.SCHEMA, new MongoDBObjectId(id));
boolean cycleDetected = !cycleDetector.add(id);
String name = obj.getString(MongoDatabase.FLD_SCHEMA_NAME);
UpdatableSchema base = null;
ObjectId baseId = obj.getObjectId(MongoDatabase.FLD_SCHEMA_BASE);
if (baseId != null && !cycleDetected) {
Surrogate baseSurr = makeSurrogate(db, DBObjectType.SCHEMA, new MongoDBObjectId(baseId));
base = getSchema(baseSurr, cycleDetector);
}
Collection<AttributeDefinition<?>> attribs = attributeDefinitions(s, 0, db, (BasicDBList)obj.get(MongoDatabase.FLD_SCHEMA_ATTRIBS));
Collection<SeriesDefinition> series = seriesDefinitions(s, db, (BasicDBList)obj.get(MongoDatabase.FLD_SCHEMA_SERIES));
return new UpdatableSchemaImpl(name, base, attribs, series, s);