use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class TruncateClassTest method testTruncateVertexClassSubclasses.
@Test
public void testTruncateVertexClassSubclasses() {
database.command(new OCommandSQL("create class TestTruncateVertexClassSuperclass")).execute();
database.command(new OCommandSQL("create class TestTruncateVertexClassSubclass extends TestTruncateVertexClassSuperclass")).execute();
database.command(new OCommandSQL("insert into TestTruncateVertexClassSuperclass set name = 'foo'")).execute();
database.command(new OCommandSQL("insert into TestTruncateVertexClassSubclass set name = 'bar'")).execute();
List<?> result = database.query(new OSQLSynchQuery("select from TestTruncateVertexClassSuperclass"));
Assert.assertEquals(result.size(), 2);
database.command(new OCommandSQL("truncate class TestTruncateVertexClassSuperclass ")).execute();
result = database.query(new OSQLSynchQuery("select from TestTruncateVertexClassSubclass"));
Assert.assertEquals(result.size(), 1);
database.command(new OCommandSQL("truncate class TestTruncateVertexClassSuperclass polymorphic")).execute();
result = database.query(new OSQLSynchQuery("select from TestTruncateVertexClassSubclass"));
Assert.assertEquals(result.size(), 0);
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class SchemaTest method testRenameClass.
@Test
public void testRenameClass() {
OClass oClass = database.getMetadata().getSchema().createClass("RenameClassTest");
ODocument document = new ODocument("RenameClassTest");
document.save();
document.reset();
document.setClassName("RenameClassTest");
document.save();
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from RenameClassTest"));
Assert.assertEquals(result.size(), 2);
oClass.set(OClass.ATTRIBUTES.NAME, "RenameClassTest2");
database.getLocalCache().clear();
result = database.query(new OSQLSynchQuery<ODocument>("select from RenameClassTest2"));
Assert.assertEquals(result.size(), 2);
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class SQLUpdateTest method testUpdateEdgeContent.
public void testUpdateEdgeContent() {
final OSchema schema = database.getMetadata().getSchema();
OClass vertex = schema.getClass("V");
OClass edge = schema.getClass("E");
schema.createClass("UpdateEdgeContentV", vertex);
schema.createClass("UpdateEdgeContentE", edge);
final ORID vOneId = ((ODocument) database.command(new OCommandSQL("create vertex UpdateEdgeContentV")).execute()).getIdentity();
final ORID vTwoId = ((ODocument) database.command(new OCommandSQL("create vertex UpdateEdgeContentV")).execute()).getIdentity();
database.command(new OCommandSQL("create edge UpdateEdgeContentE from " + vOneId + " to " + vTwoId)).execute();
database.command(new OCommandSQL("create edge UpdateEdgeContentE from " + vOneId + " to " + vTwoId)).execute();
database.command(new OCommandSQL("create edge UpdateEdgeContentE from " + vOneId + " to " + vTwoId)).execute();
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select outV(), inV() from UpdateEdgeContentE"));
Assert.assertEquals(result.size(), 3);
for (ODocument doc : result) {
Assert.assertEquals(doc.field("outV"), vOneId);
Assert.assertEquals(doc.field("inV"), vTwoId);
}
database.command(new OCommandSQL("update UpdateEdgeContentE content {value : 'val'}")).execute();
result = database.query(new OSQLSynchQuery<ODocument>("select outV(), inV() from UpdateEdgeContentE"));
Assert.assertEquals(result.size(), 3);
for (ODocument doc : result) {
Assert.assertEquals(doc.field("outV"), vOneId);
Assert.assertEquals(doc.field("inV"), vTwoId);
}
result = database.query(new OSQLSynchQuery<ODocument>("select from UpdateEdgeContentE"));
Assert.assertEquals(result.size(), 3);
for (ODocument doc : result) {
Assert.assertEquals(doc.field("value"), "val");
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class SchemaIndexTest method testPolymorphicIdsPropagationAfterClusterAddRemove.
public void testPolymorphicIdsPropagationAfterClusterAddRemove() {
final OSchema schema = database.getMetadata().getSchema();
OClass polymorpicIdsPropagationSuperSuper = schema.getClass("polymorpicIdsPropagationSuperSuper");
if (polymorpicIdsPropagationSuperSuper == null)
polymorpicIdsPropagationSuperSuper = schema.createClass("polymorpicIdsPropagationSuperSuper");
OClass polymorpicIdsPropagationSuper = schema.getClass("polymorpicIdsPropagationSuper");
if (polymorpicIdsPropagationSuper == null)
polymorpicIdsPropagationSuper = schema.createClass("polymorpicIdsPropagationSuper");
OClass polymorpicIdsPropagation = schema.getClass("polymorpicIdsPropagation");
if (polymorpicIdsPropagation == null)
polymorpicIdsPropagation = schema.createClass("polymorpicIdsPropagation");
polymorpicIdsPropagation.setSuperClass(polymorpicIdsPropagationSuper);
polymorpicIdsPropagationSuper.setSuperClass(polymorpicIdsPropagationSuperSuper);
polymorpicIdsPropagationSuperSuper.createProperty("value", OType.STRING);
polymorpicIdsPropagationSuperSuper.createIndex("PolymorpicIdsPropagationSuperSuperIndex", OClass.INDEX_TYPE.UNIQUE, "value");
int counter = 0;
for (int i = 0; i < 10; i++) {
ODocument document = new ODocument("polymorpicIdsPropagation");
document.field("value", "val" + counter);
document.save();
counter++;
}
final int clusterId2 = database.addCluster("polymorpicIdsPropagationSuperSuper2");
for (int i = 0; i < 10; i++) {
ODocument document = new ODocument();
document.field("value", "val" + counter);
document.save("polymorpicIdsPropagationSuperSuper2");
counter++;
}
polymorpicIdsPropagation.addCluster("polymorpicIdsPropagationSuperSuper2");
assertContains(polymorpicIdsPropagationSuperSuper.getPolymorphicClusterIds(), clusterId2);
assertContains(polymorpicIdsPropagationSuper.getPolymorphicClusterIds(), clusterId2);
List<ODocument> result = database.query(new OSQLSynchQuery<ODocument>("select from polymorpicIdsPropagationSuperSuper where value = 'val12'"));
Assert.assertEquals(result.size(), 1);
ODocument doc = result.get(0);
Assert.assertEquals(doc.getSchemaClass().getName(), "polymorpicIdsPropagation");
polymorpicIdsPropagation.removeClusterId(clusterId2);
assertDoesNotContain(polymorpicIdsPropagationSuperSuper.getPolymorphicClusterIds(), clusterId2);
assertDoesNotContain(polymorpicIdsPropagationSuper.getPolymorphicClusterIds(), clusterId2);
result = database.query(new OSQLSynchQuery<ODocument>("select from polymorpicIdsPropagationSuperSuper where value = 'val12'"));
Assert.assertTrue(result.isEmpty());
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OCommandExecutorSQLResultsetAbstract method parse.
/**
* Compile the filter conditions only the first time.
*/
public OCommandExecutorSQLResultsetAbstract parse(final OCommandRequest iRequest) {
final OCommandRequestText textRequest = (OCommandRequestText) iRequest;
init(textRequest);
if (iRequest instanceof OSQLSynchQuery) {
request = (OSQLSynchQuery<ODocument>) iRequest;
} else if (iRequest instanceof OSQLAsynchQuery)
request = (OSQLAsynchQuery<ODocument>) iRequest;
else {
// BUILD A QUERY OBJECT FROM THE COMMAND REQUEST
request = new OSQLSynchQuery<ODocument>(textRequest.getText());
if (textRequest.getResultListener() != null)
request.setResultListener(textRequest.getResultListener());
}
return this;
}
Aggregations