Skip to content

Commit

Permalink
fixed bug on graph read only validation, issue #7144
Browse files Browse the repository at this point in the history
  • Loading branch information
tglman committed Feb 13, 2017
1 parent 2d5bcdf commit 48db6e5
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2410,9 +2410,8 @@ public <RET extends ORecord> RET save(ORecord iRecord, String iClusterName, fina

ODocument doc = (ODocument) iRecord;
ODocumentInternal.checkClass(doc, this);
if (!getTransaction().isActive() && !getStorage().isRemote())
// EXECUTE VALIDATION ONLY IF NOT IN TX
doc.validate();
// IN TX THE VALIDATION MAY BE RUN TWICE BUT IS CORRECT BECAUSE OF DIFFERENT RECORD STATUS
doc.validate();
ODocumentInternal.convertAllMultiValuesToTrackedVersions(doc);

if (iForceCreate || !doc.getIdentity().isValid()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package com.orientechnologies.orient.graph.blueprints;

import com.orientechnologies.orient.core.metadata.schema.OProperty;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -182,4 +183,29 @@ private void setupSchema() {
graphNoTx.shutdown();
}
}

@Test(expected = OValidationException.class)
public void testPropertyReadOnly() {
OrientGraphNoTx graphNoTx = new OrientGraphNoTx(URL);
OrientVertexType testType = graphNoTx.createVertexType("Test");
OProperty prop;
prop = testType.createProperty("name", OType.STRING).setReadonly(true);
graphNoTx.shutdown();

Assert.assertTrue(prop.isReadonly()); //this one passes

OrientGraph graph = new OrientGraph(URL);
try {
OrientVertex vert1 = graph.addVertex("class:Test", "name", "Sam");
graph.commit();

vert1.setProperty("name", "Ben"); //should throw an exception
graph.commit();

Assert.assertEquals(vert1.getProperty("name"), "Sam"); //fails
} finally {
graph.drop();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,15 @@ public void validationDisabledAdDatabaseLevel() throws ParseException {
}

database.command(new OCommandSQL("ALTER DATABASE " + ODatabase.ATTRIBUTES.VALIDATION.name() + " FALSE")).execute();
database.setValidationEnabled(false);
try {

ODocument doc = new ODocument("MyTestClass");
doc.save();

doc.delete();
} finally {
database.setValidationEnabled(true);
database.command(new OCommandSQL("ALTER DATABASE " + ODatabase.ATTRIBUTES.VALIDATION.name() + " TRUE")).execute();
}
}
Expand Down

0 comments on commit 48db6e5

Please sign in to comment.