Search in sources :

Example 26 with Entity

use of jetbrains.exodus.entitystore.Entity in project meghanada-server by mopemope.

the class ProjectDatabase method findRange.

@SuppressWarnings("rawtypes")
public <U> List<U> findRange(String entityType, String propName, Comparable min, Comparable max, Function<? super Entity, ? extends U> mapper) {
    return this.entityStore.computeInReadonlyTransaction(txn -> {
        EntityIterable iterable = txn.find(entityType, propName, min, max);
        List<U> result = new ArrayList<>(8);
        for (Entity entity : iterable) {
            result.add(mapper.apply(entity));
        }
        return result;
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) ArrayList(java.util.ArrayList)

Example 27 with Entity

use of jetbrains.exodus.entitystore.Entity in project meghanada-server by mopemope.

the class ProjectDatabase method putObject.

@SuppressWarnings("rawtypes")
private static long putObject(Storable s, boolean allowUpdate, StoreTransaction txn) {
    String entityType = s.getEntityType();
    EntityId entityId = s.getEntityId();
    String id = s.getStoreId();
    Entity entity = null;
    if (nonNull(entityId)) {
        try {
            entity = txn.getEntity(entityId);
        } catch (EntityStoreException e) {
        // re-create
        }
    } else {
        EntityIterable it = txn.find(entityType, ID, id);
        entity = it.getFirst();
    }
    if (!allowUpdate && nonNull(entity)) {
        // find update entry
        s.onSuccess(entity);
        return entity.getId().getLocalId();
    }
    if (isNull(entity)) {
        entity = txn.newEntity(entityType);
        entity.setProperty(ID, id);
    }
    s.store(txn, entity);
    if (s instanceof Serializable) {
        try {
            setSerializeBlobData(entity, SERIALIZE_KEY, s);
        } catch (IOException e) {
            log.catching(e);
            txn.abort();
            return -1;
        }
    }
    // txn.saveEntity(entity);
    s.onSuccess(entity);
    return entity.getId().getLocalId();
}
Also used : EntityId(jetbrains.exodus.entitystore.EntityId) Entity(jetbrains.exodus.entitystore.Entity) Serializable(java.io.Serializable) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) EntityStoreException(jetbrains.exodus.entitystore.EntityStoreException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 28 with Entity

use of jetbrains.exodus.entitystore.Entity 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 29 with Entity

use of jetbrains.exodus.entitystore.Entity in project meghanada-server by mopemope.

the class Source method addClassReference.

private static void addClassReference(StoreTransaction txn, Entity mainEntity, Map<String, ClassIndex> classIndex, Entity entity, String fqcn) {
    if (isNull(fqcn)) {
        return;
    }
    classIndex.computeIfPresent(fqcn, (key, index) -> {
        try {
            EntityId entityId = index.getEntityId();
            if (nonNull(entityId)) {
                Entity classEntity = txn.getEntity(entityId);
                classEntity.addLink(LINK_CLASS_REFERENCES, entity);
                entity.addLink(LINK_CLASS, classEntity);
                mainEntity.addLink(LINK_REV_CLASS_REFERENCES, entity);
            }
        } catch (Exception e) {
            log.warn(e.getMessage());
        }
        return index;
    });
}
Also used : EntityId(jetbrains.exodus.entitystore.EntityId) Entity(jetbrains.exodus.entitystore.Entity) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 30 with Entity

use of jetbrains.exodus.entitystore.Entity 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 Iterable<Entity>() {

        @Override
        public Iterator<Entity> iterator() {
            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();
                }
            };
        }
    };
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) ExcludeNullIterableDecorator(jetbrains.exodus.entitystore.iterate.ExcludeNullIterableDecorator) EntityIterableBase(jetbrains.exodus.entitystore.iterate.EntityIterableBase) Iterator(java.util.Iterator) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Entity (jetbrains.exodus.entitystore.Entity)44 EntityIterable (jetbrains.exodus.entitystore.EntityIterable)23 IOException (java.io.IOException)13 EntityIterableBase (jetbrains.exodus.entitystore.iterate.EntityIterableBase)7 InputStream (java.io.InputStream)6 UncheckedIOException (java.io.UncheckedIOException)5 ArrayList (java.util.ArrayList)5 ComparableGetter (jetbrains.exodus.entitystore.ComparableGetter)4 EntityStoreException (jetbrains.exodus.entitystore.EntityStoreException)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 EntityId (jetbrains.exodus.entitystore.EntityId)3 File (java.io.File)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 NoSuchElementException (java.util.NoSuchElementException)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Nonnull (javax.annotation.Nonnull)2 ExodusException (jetbrains.exodus.ExodusException)2 EntityMetaData (jetbrains.exodus.query.metadata.EntityMetaData)2 Serializable (java.io.Serializable)1