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);
}
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);
}
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());
}
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()));
}
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();
}
Aggregations