Search in sources :

Example 56 with OSQLSynchQuery

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);
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Test(org.testng.annotations.Test)

Example 57 with OSQLSynchQuery

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);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test)

Example 58 with OSQLSynchQuery

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");
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 59 with OSQLSynchQuery

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());
}
Also used : OSchema(com.orientechnologies.orient.core.metadata.schema.OSchema) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OClass(com.orientechnologies.orient.core.metadata.schema.OClass) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 60 with OSQLSynchQuery

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;
}
Also used : OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OSQLAsynchQuery(com.orientechnologies.orient.core.sql.query.OSQLAsynchQuery) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)506 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)426 Test (org.testng.annotations.Test)282 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)78 Test (org.junit.Test)60 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)57 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)47 ORID (com.orientechnologies.orient.core.id.ORID)34 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)31 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)22 List (java.util.List)21 HashMap (java.util.HashMap)20 ORecordId (com.orientechnologies.orient.core.id.ORecordId)19 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)19 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)16 Collection (java.util.Collection)15 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)13 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)13 Set (java.util.Set)12 OCommandScript (com.orientechnologies.orient.core.command.script.OCommandScript)11