use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class ExcludeNullStaticTypedEntityIterable method instantiate.
@Override
public Iterable<Entity> instantiate() {
Iterable<Entity> instantiatedDecorated = decorated.instantiate();
if (queryEngine.isPersistentIterable(instantiatedDecorated)) {
EntityIterableBase entityIterableBaseDecorated = ((EntityIterableBase) instantiatedDecorated).getSource();
if (entityIterableBaseDecorated == EntityIterableBase.EMPTY) {
return EntityIterableBase.EMPTY;
}
return queryEngine.wrap(new ExcludeNullIterableDecorator(entityIterableBaseDecorated.getTransaction(), entityIterableBaseDecorated));
}
return () -> new Iterator<Entity>() {
private Iterator<Entity> iterator = null;
private Entity next = null;
@Override
public boolean hasNext() {
if (next != null) {
return true;
}
if (iterator == null) {
iterator = decorated.iterator();
}
while (iterator.hasNext() && next == null) {
next = iterator.next();
}
return next != null;
}
@Override
public Entity next() {
if (hasNext()) {
Entity result = next;
next = null;
return result;
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class AddNullStaticTypedEntityIterable method instantiate.
@Override
public Iterable<Entity> instantiate() {
Iterable<Entity> instantiatedDecorated = decorated.instantiate();
Iterable<Entity> instantiatedNullContainer = nullContainer.instantiate();
if (queryEngine.isPersistentIterable(instantiatedDecorated) && queryEngine.isPersistentIterable(instantiatedNullContainer)) {
EntityIterableBase entityIterableBaseDecorated = ((EntityIterableBase) instantiatedDecorated).getSource();
EntityIterableBase entityIterableBaseNullContainer = ((EntityIterableBase) instantiatedNullContainer).getSource();
return queryEngine.wrap(new AddNullDecoratorIterable(queryEngine.getPersistentStore().getAndCheckCurrentTransaction(), entityIterableBaseDecorated, entityIterableBaseNullContainer));
}
return () -> new Iterator<Entity>() {
private Iterator<Entity> iterator = null;
private Boolean hasNull = null;
@Override
public boolean hasNext() {
if (iterator == null) {
iterator = decorated.iterator();
}
if (iterator.hasNext()) {
return true;
}
if (hasNull == null) {
hasNull = false;
for (Entity entity : nullContainer) {
if (entity == null) {
hasNull = true;
break;
}
}
}
return hasNull;
}
@Override
public Entity next() {
if (hasNext()) {
if (hasNull == null) {
Entity result = iterator.next();
if (result == null) {
hasNull = false;
}
return result;
} else {
hasNull = false;
return null;
}
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class TreeKeepingEntityIterable method instantiate.
@SuppressWarnings("UnusedDeclaration")
@Override
public Iterable<Entity> instantiate() {
optimize();
Iterable<Entity> result;
if (instance == null) {
result = instantiateForWholeHierarchy();
} else if (optimizedTree instanceof GetAll) {
result = instance;
} else {
// clone
TreeKeepingEntityIterable tkei = new TreeKeepingEntityIterable(null, entityType, optimizedTree.getClone(), queryEngine);
tkei.optimizedTree = optimizedTree;
result = queryEngine.toEntityIterable(queryEngine.intersect(instance, tkei));
}
if (sorts != null) {
result = sorts.apply(entityType, result, queryEngine);
}
if (result == null) {
result = instantiateForWholeHierarchy();
}
if (isExplainOn) {
Iterable<Entity> explained = result;
while (explained instanceof SortEngine.InMemorySortIterable) {
explained = ((SortEngine.InMemorySortIterable) explained).getSrc();
}
if (explained instanceof EntityIterableBase) {
final EntityIterableBase entityIterable = ((EntityIterableBase) explained).getSource();
if (entityIterable != EntityIterableBase.EMPTY) {
final PersistentEntityStoreImpl store = queryEngine.getPersistentStore();
final Explainer explainer = store.getExplainer();
final boolean explainForcedForThread = Explainer.isExplainForcedForThread();
if (!explainForcedForThread) {
explainer.start(origin);
}
entityIterable.setOrigin(origin);
explainer.explain(origin, Explainer.INITIAL_TREE, annotatedTree);
explainer.explain(origin, Explainer.OPTIMIZED_TREE, optimizedTree);
if (!explainForcedForThread) {
for (Entity entity : result) {
explainer.explain(origin, Explainer.ITERABLE_ADVANCES);
}
explainer.log(origin);
}
}
}
}
return result;
}
use of jetbrains.exodus.entitystore.iterate.EntityIterableBase in project xodus by JetBrains.
the class ReplayTest method testPerformance.
public void testPerformance() {
final PersistentStoreTransaction txn = getStoreTransaction();
assertNotNull(txn);
for (int i = 0; i < CACHE_SIZE; ++i) {
final Entity entity = txn.newEntity("Issue");
// entity.setProperty("description", "Test issue #" + i);
entity.setProperty("size", i);
}
txn.flush();
for (int i = 0; i < CACHE_SIZE; ++i) {
final EntityIterableBase issues = findSome(txn, i);
// fill cache
issues.getOrCreateCachedInstance(txn);
}
final Entity[] change = new Entity[CHANGES_SIZE];
for (int i = 0; i < CHANGES_SIZE; i++) {
Entity issue = findSome(txn, 239 + i).getFirst();
assertNotNull(issue);
change[i] = issue;
}
System.out.println(System.currentTimeMillis());
changeStuff(change);
System.out.println(System.currentTimeMillis());
System.out.println("----------");
System.out.println(System.currentTimeMillis());
replay(txn, change);
System.out.println(System.currentTimeMillis());
}
Aggregations