public void fromStream() {
// READ CURRENT SCHEMA VERSION
int schemaVersion = (Integer) document.field("schemaVersion");
if (schemaVersion != CURRENT_VERSION_NUMBER) {
// HANDLE SCHEMA UPGRADE
throw new OConfigurationException(
"Database schema is different. Please export your old database with the previous verison of OrientDB and reimport it using the current one.");
}
// REGISTER ALL THE CLASSES
classes.clear();
OClass cls;
Collection<ODocument> storedClasses = document.field("classes");
for (ODocument c : storedClasses) {
c.setDatabase(document.getDatabase());
cls = new OClass(this, c);
cls.fromStream();
classes.put(cls.getName().toLowerCase(), cls);
}
// REBUILD THE INHERITANCE TREE
String superClassName;
OClass superClass;
for (ODocument c : storedClasses) {
superClassName = c.field("superClass");
if (superClassName != null) {
// HAS A SUPER CLASS
cls = classes.get(((String) c.field("name")).toLowerCase());
superClass = classes.get(superClassName.toLowerCase());
if (superClass == null)
throw new OConfigurationException("Super class '" + superClassName + "' was declared in class '" + cls.getName()
+ "' but was not found in schema. Remove the dependency or create the class to continue.");
cls.setSuperClass(superClass);
}
}