Search in sources :

Example 16 with EntityIterable

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

the class ProjectDatabaseHelper method saveChecksumMap.

public static boolean saveChecksumMap(String projectRoot, Map<String, String> map) {
    ProjectDatabase database = ProjectDatabase.getInstance();
    return database.execute(txn -> {
        EntityIterable entities = txn.find(Project.ENTITY_TYPE, ProjectDatabase.ID, projectRoot);
        Entity entity = entities.getFirst();
        if (isNull(entity)) {
            return false;
        }
        try {
            ProjectDatabase.setSerializeBlobData(entity, BLOB_PROP_CHECKSUM, map);
        } catch (IOException e) {
            log.catching(e);
            txn.abort();
            return false;
        }
        // txn.saveEntity(entity);
        return true;
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) IOException(java.io.IOException)

Example 17 with EntityIterable

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

the class ProjectDatabaseHelper method getAllSources.

public static List<Source> getAllSources() {
    ProjectDatabase database = ProjectDatabase.getInstance();
    return database.computeInReadonly(txn -> {
        EntityIterable iterable = txn.getAll(Source.ENTITY_TYPE);
        List<Source> result = new ArrayList<>(8);
        for (Entity entity : iterable) {
            try (InputStream in = entity.getBlob(ProjectDatabase.SERIALIZE_KEY)) {
                Source s = Serializer.readObject(in, Source.class);
                if (nonNull(s)) {
                    result.add(s);
                }
            } catch (Exception e) {
                log.warn(e.getMessage());
            }
        }
        return result;
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Source(meghanada.analyze.Source) IOException(java.io.IOException)

Example 18 with EntityIterable

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

the class ProjectDatabaseHelper method getChecksumMap.

@Nonnull
@SuppressWarnings("unchecked")
public static Map<String, String> getChecksumMap(String projectRoot) {
    ProjectDatabase database = ProjectDatabase.getInstance();
    Optional<Map<String, String>> result = database.computeInReadonly(txn -> {
        EntityIterable entities = txn.find(Project.ENTITY_TYPE, ProjectDatabase.ID, projectRoot).intersect(txn.findWithBlob(Project.ENTITY_TYPE, BLOB_PROP_CHECKSUM));
        Entity entity = entities.getFirst();
        if (isNull(entity)) {
            return Optional.empty();
        }
        try (InputStream in = entity.getBlob(BLOB_PROP_CHECKSUM)) {
            return Optional.ofNullable(Serializer.readObject(in, ConcurrentHashMap.class));
        } catch (Exception e) {
            log.catching(e);
            return Optional.empty();
        }
    });
    return result.orElse(new ConcurrentHashMap<>(32));
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) InputStream(java.io.InputStream) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) Nonnull(javax.annotation.Nonnull)

Example 19 with EntityIterable

use of jetbrains.exodus.entitystore.EntityIterable 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 20 with EntityIterable

use of jetbrains.exodus.entitystore.EntityIterable 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)

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