Search in sources :

Example 91 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OChainIndexFetchTest method testFetchChaninedIndex.

@Test
public void testFetchChaninedIndex() {
    OClass baseClass = db.getMetadata().getSchema().createClass("BaseClass");
    OProperty propr = baseClass.createProperty("ref", OType.LINK);
    OClass linkedClass = db.getMetadata().getSchema().createClass("LinkedClass");
    OProperty id = linkedClass.createProperty("id", OType.STRING);
    id.createIndex(INDEX_TYPE.UNIQUE);
    propr.setLinkedClass(linkedClass);
    propr.createIndex(INDEX_TYPE.NOTUNIQUE);
    ODocument doc = new ODocument(linkedClass);
    doc.field("id", "referred");
    db.save(doc);
    ODocument doc1 = new ODocument(baseClass);
    doc1.field("ref", doc);
    db.save(doc1);
    List<ODocument> res = db.query(new OSQLSynchQuery(" select from BaseClass where ref.id ='wrong_referred' "));
    assertEquals(0, res.size());
}
Also used : OProperty(com.orientechnologies.orient.core.metadata.schema.OProperty) 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 92 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class FaultDuringWritingWithOperationRedirectScenarioTest method executeTest.

@Override
public void executeTest() throws Exception {
    //  TO-CHANGE
    List<ODocument> result = null;
    ODatabaseDocumentTx dbServer3 = new ODatabaseDocumentTx(getRemoteDatabaseURL(serverInstance.get(2))).open("admin", "admin");
    String dbServerUrl1 = getRemoteDatabaseURL(serverInstance.get(0));
    try {
        /*
       * Test with quorum = 2
       */
        banner("Test with quorum = 2");
        // writes on server3 (remote access) while a task is monitoring the inserted records amount and shutdown server
        // after 1/3 of total number of records to insert, and restarting it when 2/3 of records were inserted.
        ODatabaseRecordThreadLocal.INSTANCE.set(null);
        Callable shutdownAndRestartTask = new ShutdownAndRestartServer(serverInstance.get(2), dbServerUrl1, "net-fault");
        final ExecutorService executor = Executors.newSingleThreadExecutor();
        Future f = executor.submit(shutdownAndRestartTask);
        executeMultipleWrites(this.executeTestsOnServers, "remote");
        // waiting for task ending
        f.get();
        // waiting for changes propagation
        waitForMultipleInsertsInClassPropagation(500L, "Person", 5000L);
        // preliminar check
        ODatabaseRecordThreadLocal.INSTANCE.set(dbServer3);
        result = dbServer3.query(new OSQLSynchQuery<OIdentifiable>("select from Person"));
        assertEquals(500, result.size());
        // check consistency on all the server:
        // all the records destined to server3 were redirected to an other server, so we must inspect consistency for all 500 records
        checkWritesAboveCluster(serverInstance, executeTestsOnServers);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    } finally {
        if (!dbServer3.isClosed()) {
            ODatabaseRecordThreadLocal.INSTANCE.set(dbServer3);
            dbServer3.close();
            ODatabaseRecordThreadLocal.INSTANCE.set(null);
        }
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ExecutorService(java.util.concurrent.ExecutorService) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) Future(java.util.concurrent.Future) Callable(java.util.concurrent.Callable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 93 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class TestDistributeConfigSerialization method executeTest.

@Override
protected void executeTest() throws Exception {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:target/server0/databases/" + getDatabaseName());
    try {
        db.setSerializer(new ORecordSerializerSchemaAware2CSV());
        db.create();
        db.getMetadata().getSchema().createClass("TestMessaging");
        db.activateOnCurrentThread();
        db.save(new ODocument("TestMessaging").field("test", "test"));
        db.query(new OSQLSynchQuery("select from TestMessaging "));
        db.close();
    } catch (OException e) {
        e.printStackTrace();
        Assert.fail("error on creating a csv database in distributed environment");
    }
    try {
        db = new ODatabaseDocumentTx("remote:localhost/" + getDatabaseName());
        db.open("admin", "admin");
        db.query(new OSQLSynchQuery("select from TestMessaging "));
        db.close();
    } catch (OException e) {
        e.printStackTrace();
        Assert.fail("error on creating a csv database in distributed environment");
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OException(com.orientechnologies.common.exception.OException) ORecordSerializerSchemaAware2CSV(com.orientechnologies.orient.core.serialization.serializer.record.string.ORecordSerializerSchemaAware2CSV) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 94 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OrientGraphQuery method vertices.

/**
   * Returns the result set of the query as iterable vertices.
   */
@Override
public Iterable<Vertex> vertices() {
    if (limit == 0)
        return Collections.emptyList();
    OTransaction transaction = ((OrientBaseGraph) graph).getRawGraph().getTransaction();
    if (transaction.isActive() && transaction.getEntryCount() > 0 || hasCustomPredicate()) {
        // INSIDE TRANSACTION QUERY DOESN'T SEE IN MEMORY CHANGES, UNTIL
        // SUPPORTED USED THE BASIC IMPL
        String[] classes = allSubClassesLabels();
        return new OrientGraphQueryIterable<Vertex>(true, classes);
    }
    final StringBuilder text = new StringBuilder(512);
    // GO DIRECTLY AGAINST E CLASS AND SUB-CLASSES
    text.append(QUERY_SELECT_FROM);
    if (((OrientBaseGraph) graph).isUseClassForVertexLabel() && labels != null && labels.length > 0) {
        // FILTER PER CLASS SAVING CHECKING OF LABEL PROPERTY
        if (labels.length == 1)
            // USE THE CLASS NAME
            text.append(OrientBaseGraph.encodeClassName(labels[0]));
        else {
            // MULTIPLE CLASSES NOT SUPPORTED DIRECTLY: CREATE A SUB-QUERY
            String[] classes = allSubClassesLabels();
            return new OrientGraphQueryIterable<Vertex>(true, classes);
        }
    } else
        text.append(OrientVertexType.CLASS_NAME);
    final boolean usedWhere = manageFilters(text);
    if (!((OrientBaseGraph) graph).isUseClassForVertexLabel())
        manageLabels(usedWhere, text);
    if (orderBy.length() > 1) {
        text.append(ORDERBY);
        text.append(orderBy);
        text.append(" ").append(orderByDir).append(" ");
    }
    if (skip > 0 && skip < Integer.MAX_VALUE) {
        text.append(SKIP);
        text.append(skip);
    }
    if (limit > 0 && limit < Integer.MAX_VALUE) {
        text.append(LIMIT);
        text.append(limit);
    }
    final OSQLSynchQuery<OIdentifiable> query = new OSQLSynchQuery<OIdentifiable>(text.toString());
    if (fetchPlan != null)
        query.setFetchPlan(fetchPlan);
    return new OrientElementIterable<Vertex>(((OrientBaseGraph) graph), ((OrientBaseGraph) graph).getRawGraph().query(query));
}
Also used : OTransaction(com.orientechnologies.orient.core.tx.OTransaction) OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 95 with OSQLSynchQuery

use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.

the class OrientIndex method removeElement.

protected void removeElement(final T element) {
    graph.setCurrentGraphInThreadLocal();
    graph.autoStartTransaction();
    final OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select from index:" + recordKeyValueIndex.getName() + " where key between [" + element.getIdentity() + "] and [" + element.getIdentity() + "]");
    final Collection<ODocument> entries = (Collection<ODocument>) graph.getRawGraph().query(query);
    for (ODocument entry : entries) {
        final OCompositeKey key = entry.field("key");
        final List<Object> keys = key.getKeys();
        underlying.remove(keys.get(1).toString(), element.getIdentity());
        recordKeyValueIndex.remove(key, element.getIdentity());
    }
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) Collection(java.util.Collection) OCompositeKey(com.orientechnologies.orient.core.index.OCompositeKey) 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