use of jetbrains.exodus.entitystore.EntityIterable in project meghanada-server by mopemope.
the class ProjectDatabase method loadObject.
public <T> T loadObject(String entityType, String id, Class<T> clazz) throws Exception {
return this.entityStore.computeInReadonlyTransaction(txn -> {
EntityIterable it = txn.find(entityType, ID, id);
Entity entity = it.getFirst();
if (nonNull(entity)) {
try (InputStream in = entity.getBlob(SERIALIZE_KEY)) {
return Serializer.readObject(in, clazz);
} catch (Exception e) {
log.warn(e.getMessage());
return null;
}
}
return null;
});
}
use of jetbrains.exodus.entitystore.EntityIterable in project xodus by JetBrains.
the class And method instantiateCustom.
private static Iterable<Entity> instantiateCustom(@NotNull final String entityType, @NotNull final QueryEngine queryEngine, @NotNull final ModelMetaData metaData, @NotNull final NodeBase self, @NotNull final LinksEqualDecorator decorator, @NotNull final Instantiatable directClosure) {
final Iterable<Entity> selfInstance = self.instantiate(entityType, queryEngine, metaData);
if (selfInstance instanceof EntityIterableBase) {
final EntityIterable result = ((EntityIterableBase) selfInstance).findLinks(((EntityIterableBase) decorator.instantiateDecorated(decorator.getLinkEntityType(), queryEngine, metaData)).getSource(), decorator.getLinkName());
if (traceFindLinks) {
final Iterator<Entity> directIt = directClosure.instantiate().iterator();
final EntityIterator it = result.iterator();
while (true) {
final boolean directHasNext = directIt.hasNext();
final boolean hasNext = it.hasNext();
if (directHasNext != hasNext) {
throw new EntityStoreException("Invalid custom findLinks() result: different sizes");
}
if (!hasNext) {
break;
}
if (!directIt.next().getId().equals(it.nextId())) {
throw new EntityStoreException("Invalid custom findLinks() result");
}
}
}
return result;
}
return directClosure.instantiate();
}
use of jetbrains.exodus.entitystore.EntityIterable in project xodus by JetBrains.
the class LongProcessRunner method oneMoreStep.
@Override
protected void oneMoreStep() throws Exception {
logger.info("One more step...");
EntityIterable iterable = txn.find("Person", "name", "Vadim");
Entity entity = iterable.iterator().next();
logger.info("Starting separate thread...");
new Thread() {
@Override
public void run() {
try {
Thread.sleep(5 * 1000);
logger.info("Requesting euthanasia");
getStreamer().writeString(store.getLocation());
} catch (Exception e) {
logger.error("Something went terribly wrong: ", e);
}
}
}.start();
logger.info("...separate thread started");
logger.info("Getting ready for a rush...");
long l = 0;
while (true) {
entity.setProperty("password", "dummypassword" + l++);
Thread.sleep(0);
}
}
use of jetbrains.exodus.entitystore.EntityIterable 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).source;
}
if (explained instanceof EntityIterableBase) {
EntityIterable entityIterable = ((EntityIterableBase) explained).getSource();
if (entityIterable instanceof EntityIterableBase && entityIterable != EntityIterableBase.EMPTY) {
EntityIterableBase entityIterableBase = ((EntityIterableBase) entityIterable);
final PersistentEntityStoreImpl store = queryEngine.getPersistentStore();
Explainer explainer = store.getExplainer();
if (!Explainer.isExplainForcedForThread()) {
explainer.start(origin);
}
entityIterableBase.setOrigin(origin);
explainer.explain(origin, Explainer.INITIAL_TREE, annotatedTree);
explainer.explain(origin, Explainer.OPTIMIZED_TREE, optimizedTree);
if (!Explainer.isExplainForcedForThread()) {
for (Entity entity : result) {
explainer.explain(origin, Explainer.ITERABLE_ADVANCES);
}
explainer.log(origin);
}
}
}
}
return result;
}
Aggregations