Search in sources :

Example 51 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OMatchPathItem method traversePatternEdge.

protected Iterable<OIdentifiable> traversePatternEdge(OMatchStatement.MatchContext matchContext, OIdentifiable startingPoint, OCommandContext iCommandContext) {
    Iterable possibleResults = null;
    if (filter != null) {
        OIdentifiable matchedNode = matchContext.matched.get(filter.getAlias());
        if (matchedNode != null) {
            possibleResults = Collections.singleton(matchedNode);
        } else if (matchContext.matched.containsKey(filter.getAlias())) {
            //optional node, the matched element is a null value
            possibleResults = Collections.emptySet();
        } else {
            possibleResults = matchContext.candidates == null ? null : matchContext.candidates.get(filter.getAlias());
        }
    }
    Object qR = this.method.execute(startingPoint, possibleResults, iCommandContext);
    return (qR instanceof Iterable) ? (Iterable) qR : Collections.singleton(qR);
}
Also used : OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 52 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OMatchPathItemIterator method loadNextInternal.

protected void loadNextInternal() {
    if (stack == null || stack.size() == 0) {
        nextElement = null;
        return;
    }
    int depth = stack.size() - 1;
    Object oldDepth = ctx.getVariable("$depth", depth);
    ctx.setVariable("$depth", depth);
    final OWhereClause filter = this.item.filter == null ? null : this.item.filter.getFilter();
    final OWhereClause whileCondition = this.item.filter == null ? null : this.item.filter.getWhileCondition();
    final Integer maxDepth = maxDepth(this.item.filter);
    final OClass oClass = this.item.filter == null ? null : item.getDatabase().getMetadata().getSchema().getClass(this.item.filter.getClassName(ctx));
    boolean notDeep = this.item.filter == null || (whileCondition == null && this.item.filter.getMaxDepth() == null);
    OIdentifiable startingPoint = (OIdentifiable) stack.get(0).next();
    nextElement = null;
    if (this.item.filter == null || (whileCondition == null && this.item.filter.getMaxDepth() == null)) {
        //basic case, no traversal, discard level zero
        if (depth == 1) {
            Object prevMatch = ctx.getVariable("$currentMatch");
            ctx.setVariable("$currentMatch", startingPoint);
            if (filter == null || filter.matchesFilters(startingPoint, ctx)) {
                nextElement = startingPoint;
            }
            ctx.setVariable("$currentMatch", prevMatch);
        }
    } else {
        Object prevMatch = ctx.getVariable("$currentMatch");
        ctx.setVariable("$currentMatch", startingPoint);
        if (filter == null || filter.matchesFilters(startingPoint, ctx)) {
            nextElement = startingPoint;
        }
        ctx.setVariable("$currentMatch", prevMatch);
    }
    if ((notDeep && depth == 0) || ((maxDepth == null || depth < maxDepth) && (whileCondition == null || whileCondition.matchesFilters(startingPoint, ctx)) && (oClass == null || matchesClass(oClass, startingPoint)))) {
        stack.add(0, item.traversePatternEdge(matchContext, startingPoint, ctx).iterator());
    }
    ctx.setVariable("$depth", oldDepth);
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 53 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testAddOneSavedDocumentsAndDeleteOneWithoutTx.

/**
   * This test is no longer useful
   */
@Test(enabled = false)
public void testAddOneSavedDocumentsAndDeleteOneWithoutTx() {
    ODocument docOne = new ODocument();
    docOne.save();
    ODocument docTwo = new ODocument();
    docTwo.save();
    ODocument docThree = new ODocument();
    docThree.save();
    ODocument rootDoc = new ODocument();
    ORidBag ridBag = new ORidBag();
    rootDoc.field("ridBag", ridBag);
    ridBag.add(docOne);
    ridBag.add(docTwo);
    rootDoc.save();
    ODocument staleRooDoc = database.load(rootDoc.getIdentity());
    ORidBag staleRidBag = staleRooDoc.field("ridBag");
    Iterator<OIdentifiable> iterator = staleRidBag.iterator();
    iterator.next();
    iterator.remove();
    staleRidBag.add(docThree);
    rootDoc.setDirty();
    rootDoc.save();
    try {
        staleRooDoc.save();
        Assert.fail();
    } catch (OConcurrentModificationException e) {
    }
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    Assert.assertEquals(ridBag.size(), 2);
    iterator = ridBag.iterator();
    Assert.assertEquals(iterator.next(), docOne);
    Assert.assertEquals(iterator.next(), docTwo);
    Assert.assertTrue(!iterator.hasNext());
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) OConcurrentModificationException(com.orientechnologies.orient.core.exception.OConcurrentModificationException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument) Test(org.testng.annotations.Test) DatabaseAbstractTest(com.orientechnologies.DatabaseAbstractTest)

Example 54 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class ORidBagAtomicUpdateTest method testAddInternalDocumentsAndSubDocuments.

public void testAddInternalDocumentsAndSubDocuments() {
    database.begin();
    ODocument rootDoc = new ODocument();
    ORidBag ridBag = new ORidBag();
    rootDoc.field("ridBag", ridBag);
    ODocument docOne = new ODocument();
    docOne.save();
    ODocument docTwo = new ODocument();
    docTwo.save();
    ridBag.add(docOne);
    ridBag.add(docTwo);
    rootDoc.save();
    database.commit();
    long recordsCount = database.countClusterElements(database.getDefaultClusterId());
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    database.begin();
    ODocument docThree = new ODocument();
    docThree.save();
    ODocument docFour = new ODocument();
    docFour.save();
    ridBag.add(docThree);
    ridBag.add(docFour);
    rootDoc.save();
    ODocument docThreeOne = new ODocument();
    docThreeOne.save();
    ODocument docThreeTwo = new ODocument();
    docThreeTwo.save();
    ORidBag ridBagThree = new ORidBag();
    ridBagThree.add(docThreeOne);
    ridBagThree.add(docThreeTwo);
    docThree.field("ridBag", ridBagThree);
    docThree.save();
    ODocument docFourOne = new ODocument();
    docFourOne.save();
    ODocument docFourTwo = new ODocument();
    docFourTwo.save();
    ORidBag ridBagFour = new ORidBag();
    ridBagFour.add(docFourOne);
    ridBagFour.add(docFourTwo);
    docFour.field("ridBag", ridBagFour);
    docFour.save();
    database.rollback();
    Assert.assertEquals(database.countClusterElements(database.getDefaultClusterId()), recordsCount);
    List<OIdentifiable> addedDocs = new ArrayList<OIdentifiable>(Arrays.asList(docOne, docTwo));
    rootDoc = database.load(rootDoc.getIdentity());
    ridBag = rootDoc.field("ridBag");
    Iterator<OIdentifiable> iterator = ridBag.iterator();
    Assert.assertTrue(addedDocs.remove(iterator.next()));
    Assert.assertTrue(addedDocs.remove(iterator.next()));
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 55 with OIdentifiable

use of com.orientechnologies.orient.core.db.record.OIdentifiable in project orientdb by orientechnologies.

the class OSBTreeRidBagConcurrencyMultiRidBag method testConcurrency.

public void testConcurrency() throws Exception {
    ODatabaseDocumentTx db = new ODatabaseDocumentTx(URL);
    if (db.exists()) {
        db.open("admin", "admin");
        db.drop();
    }
    db.create();
    for (int i = 0; i < 100; i++) {
        ODocument document = new ODocument();
        ORidBag ridBag = new ORidBag();
        document.field("ridBag", ridBag);
        document.save();
        ridTreePerDocument.put(document.getIdentity(), new ConcurrentSkipListSet<ORID>());
        lastClusterPosition.set(document.getIdentity().getClusterPosition());
    }
    final List<Future<?>> futures = new ArrayList<Future<?>>();
    Random random = new Random();
    for (int i = 0; i < 5; i++) addDocExecutor.scheduleAtFixedRate(new DocumentAdder(), random.nextInt(250), 250, TimeUnit.MILLISECONDS);
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidAdder(i)));
    for (int i = 0; i < 5; i++) futures.add(threadExecutor.submit(new RidDeleter(i)));
    latch.countDown();
    Thread.sleep(30 * 60000);
    addDocExecutor.shutdown();
    addDocExecutor.awaitTermination(30, TimeUnit.SECONDS);
    Thread.sleep(30 * 60000);
    cont = false;
    for (Future<?> future : futures) future.get();
    long amountOfRids = 0;
    for (ORID rid : ridTreePerDocument.keySet()) {
        ODocument document = db.load(rid);
        document.setLazyLoad(false);
        final ConcurrentSkipListSet<ORID> ridTree = ridTreePerDocument.get(rid);
        final ORidBag ridBag = document.field("ridBag");
        for (OIdentifiable identifiable : ridBag) Assert.assertTrue(ridTree.remove(identifiable.getIdentity()));
        Assert.assertTrue(ridTree.isEmpty());
        amountOfRids += ridBag.size();
    }
    System.out.println("Total  records added :  " + db.countClusterElements(db.getDefaultClusterId()));
    System.out.println("Total rids added : " + amountOfRids);
    db.drop();
}
Also used : ORidBag(com.orientechnologies.orient.core.db.record.ridbag.ORidBag) ArrayList(java.util.ArrayList) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) Random(java.util.Random) Future(java.util.concurrent.Future) ORID(com.orientechnologies.orient.core.id.ORID) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)536 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)278 ORecordId (com.orientechnologies.orient.core.id.ORecordId)120 Test (org.testng.annotations.Test)104 HashSet (java.util.HashSet)89 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)79 ORidBag (com.orientechnologies.orient.core.db.record.ridbag.ORidBag)70 ORID (com.orientechnologies.orient.core.id.ORID)56 OIndexCursor (com.orientechnologies.orient.core.index.OIndexCursor)47 Test (org.junit.Test)43 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)42 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)41 ArrayList (java.util.ArrayList)39 ORecord (com.orientechnologies.orient.core.record.ORecord)35 Map (java.util.Map)31 ByteBuffer (java.nio.ByteBuffer)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)26 OIndexTxAwareOneValue (com.orientechnologies.orient.core.index.OIndexTxAwareOneValue)22 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)22 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)21