Search in sources :

Example 21 with EntityIterable

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;
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ExodusException(jetbrains.exodus.ExodusException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) EntityStoreException(jetbrains.exodus.entitystore.EntityStoreException)

Example 22 with EntityIterable

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();
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) EntityIterator(jetbrains.exodus.entitystore.EntityIterator) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) EntityStoreException(jetbrains.exodus.entitystore.EntityStoreException)

Example 23 with EntityIterable

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);
    }
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable)

Example 24 with EntityIterable

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;
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) PersistentEntityStoreImpl(jetbrains.exodus.entitystore.PersistentEntityStoreImpl) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) Explainer(jetbrains.exodus.entitystore.Explainer)

Aggregations

EntityIterable (jetbrains.exodus.entitystore.EntityIterable)24 Entity (jetbrains.exodus.entitystore.Entity)23 IOException (java.io.IOException)11 InputStream (java.io.InputStream)6 ArrayList (java.util.ArrayList)5 EntityStoreException (jetbrains.exodus.entitystore.EntityStoreException)4 EntityIterableBase (jetbrains.exodus.entitystore.iterate.EntityIterableBase)4 UncheckedIOException (java.io.UncheckedIOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Map (java.util.Map)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Nonnull (javax.annotation.Nonnull)2 ExodusException (jetbrains.exodus.ExodusException)2 ComparableGetter (jetbrains.exodus.entitystore.ComparableGetter)2 EntityId (jetbrains.exodus.entitystore.EntityId)2 File (java.io.File)1 Serializable (java.io.Serializable)1 EntityIterator (jetbrains.exodus.entitystore.EntityIterator)1 Explainer (jetbrains.exodus.entitystore.Explainer)1 PersistentEntityStoreImpl (jetbrains.exodus.entitystore.PersistentEntityStoreImpl)1