use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class ODatabaseCompare method compareSchema.
private void compareSchema() {
OSchema schema1 = databaseOne.getMetadata().getImmutableSchemaSnapshot();
OSchema schema2 = databaseTwo.getMetadata().getImmutableSchemaSnapshot();
boolean ok = true;
for (OClass clazz : schema1.getClasses()) {
OClass clazz2 = schema2.getClass(clazz.getName());
if (clazz2 == null) {
listener.onMessage("\n- ERR: Class definition " + clazz.getName() + " for DB2 is null.");
continue;
}
final List<String> sc1 = clazz.getSuperClassesNames();
final List<String> sc2 = clazz2.getSuperClassesNames();
if (!sc1.isEmpty() || !sc2.isEmpty()) {
if (!sc1.containsAll(sc2) || !sc2.containsAll(sc1)) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " in DB1 is not equals in superclasses in DB2.");
ok = false;
}
}
if (!clazz.getClassIndexes().equals(clazz2.getClassIndexes())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " in DB1 is not equals in indexes in DB2.");
ok = false;
}
if (!Arrays.equals(clazz.getClusterIds(), clazz2.getClusterIds())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " in DB1 is not equals in clusters in DB2.");
ok = false;
}
if (!clazz.getCustomKeys().equals(clazz2.getCustomKeys())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " in DB1 is not equals in custom keys in DB2.");
ok = false;
}
if (clazz.getOverSize() != clazz2.getOverSize()) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " in DB1 is not equals in overSize in DB2.");
ok = false;
}
if (clazz.getDefaultClusterId() != clazz2.getDefaultClusterId()) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " in DB1 is not equals in default cluser id in DB2.");
ok = false;
}
for (OProperty prop : clazz.declaredProperties()) {
OProperty prop2 = clazz2.getProperty(prop.getName());
if (prop2 == null) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as missed property " + prop.getName() + "in DB2.");
ok = false;
continue;
}
if (prop.getType() != prop2.getType()) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same type for property " + prop.getName() + "in DB2. ");
ok = false;
}
if (prop.getLinkedType() != prop2.getLinkedType()) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same linkedtype for property " + prop.getName() + "in DB2.");
ok = false;
}
if (prop.getMin() != null) {
if (!prop.getMin().equals(prop2.getMin())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same min for property " + prop.getName() + "in DB2.");
ok = false;
}
}
if (prop.getMax() != null) {
if (!prop.getMax().equals(prop2.getMax())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same max for property " + prop.getName() + "in DB2.");
ok = false;
}
}
if (prop.getMax() != null) {
if (!prop.getMax().equals(prop2.getMax())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same regexp for property " + prop.getName() + "in DB2.");
ok = false;
}
}
if (prop.getLinkedClass() != null) {
if (!prop.getLinkedClass().equals(prop2.getLinkedClass())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same linked class for property " + prop.getName() + "in DB2.");
ok = false;
}
}
if (prop.getLinkedClass() != null) {
if (!prop.getCustomKeys().equals(prop2.getCustomKeys())) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same custom keys for property " + prop.getName() + "in DB2.");
ok = false;
}
}
if (prop.isMandatory() != prop2.isMandatory()) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same mandatory flag for property " + prop.getName() + "in DB2.");
ok = false;
}
if (prop.isNotNull() != prop2.isNotNull()) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same nut null flag for property " + prop.getName() + "in DB2.");
ok = false;
}
if (prop.isReadonly() != prop2.isReadonly()) {
listener.onMessage("\n- ERR: Class definition for " + clazz.getName() + " as not same readonly flag setting for property " + prop.getName() + "in DB2.");
ok = false;
}
}
if (!ok) {
++differences;
ok = true;
}
}
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class OQueryOperatorInstanceof method evaluateExpression.
@Override
protected boolean evaluateExpression(final OIdentifiable iRecord, final OSQLFilterCondition iCondition, final Object iLeft, final Object iRight, OCommandContext iContext) {
final OSchema schema = ((OMetadataInternal) ODatabaseRecordThreadLocal.INSTANCE.get().getMetadata()).getImmutableSchemaSnapshot();
final String baseClassName = iRight.toString();
final OClass baseClass = schema.getClass(baseClassName);
if (baseClass == null)
throw new OCommandExecutionException("Class '" + baseClassName + "' is not defined in database schema");
OClass cls = null;
if (iLeft instanceof OIdentifiable) {
// GET THE RECORD'S CLASS
final ORecord record = ((OIdentifiable) iLeft).getRecord();
if (record instanceof ODocument) {
cls = ODocumentInternal.getImmutableSchemaClass(((ODocument) record));
}
} else if (iLeft instanceof String)
// GET THE CLASS BY NAME
cls = schema.getClass((String) iLeft);
return cls != null ? cls.isSubClassOf(baseClass) : false;
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class OMatchStatement method getLowerSubclass.
private String getLowerSubclass(String className1, String className2) {
OSchema schema = getDatabase().getMetadata().getSchema();
OClass class1 = schema.getClass(className1);
OClass class2 = schema.getClass(className2);
if (class1 == null) {
throw new OCommandExecutionException("Class " + className1 + " not found in the schema");
}
if (class2 == null) {
throw new OCommandExecutionException("Class " + className2 + " not found in the schema");
}
if (class1.isSubClassOf(class2)) {
return class1.getName();
}
if (class2.isSubClassOf(class1)) {
return class2.getName();
}
return null;
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class HookChangeValidationTest method testHookUpdateChange.
@Test
public void testHookUpdateChange() {
ODatabaseDocument db = new ODatabaseDocumentTx("memory:" + HookChangeValidationTest.class.getName());
db.create();
try {
OSchema schema = db.getMetadata().getSchema();
OClass classA = schema.createClass("TestClass");
classA.createProperty("property1", OType.STRING).setNotNull(true);
classA.createProperty("property2", OType.STRING).setReadonly(true);
classA.createProperty("property3", OType.STRING).setMandatory(true);
db.registerHook(new ODocumentHookAbstract() {
@Override
public RESULT onRecordBeforeCreate(ODocument doc) {
return RESULT.RECORD_NOT_CHANGED;
}
@Override
public RESULT onRecordBeforeUpdate(ODocument doc) {
doc.removeField("property1");
doc.removeField("property2");
doc.removeField("property3");
return RESULT.RECORD_CHANGED;
}
@Override
public DISTRIBUTED_EXECUTION_MODE getDistributedExecutionMode() {
return DISTRIBUTED_EXECUTION_MODE.SOURCE_NODE;
}
});
ODocument doc = new ODocument(classA);
doc.field("property1", "value1-create");
doc.field("property2", "value2-create");
doc.field("property3", "value3-create");
doc.save();
assertEquals("value1-create", doc.field("property1"));
assertEquals("value2-create", doc.field("property2"));
assertEquals("value3-create", doc.field("property3"));
doc.field("property1", "value1-update");
doc.field("property2", "value2-update");
try {
doc.save();
Assert.fail("The document save should fail for validation exception");
} catch (OValidationException ex) {
}
} finally {
db.drop();
}
}
use of com.orientechnologies.orient.core.metadata.schema.OSchema in project orientdb by orientechnologies.
the class UniqueIndexTest method testUniqueOnUpdate.
@Test()
public void testUniqueOnUpdate() {
final OSchema schema = db.getMetadata().getSchema();
OClass userClass = schema.createClass("User");
userClass.createProperty("MailAddress", OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE);
ODocument john = new ODocument("User");
john.field("MailAddress", "john@doe.com");
db.save(john);
ODocument jane = new ODocument("User");
jane.field("MailAddress", "jane@doe.com");
ODocument id = jane.save();
db.save(jane);
try {
ODocument toUp = db.load(id.getIdentity());
toUp.field("MailAddress", "john@doe.com");
db.save(toUp);
Assert.fail("Expected record duplicate exception");
} catch (ORecordDuplicatedException ex) {
}
ODocument fromDb = db.load(id.getIdentity());
Assert.assertEquals(fromDb.field("MailAddress"), "jane@doe.com");
}
Aggregations