Search in sources :

Example 11 with EntityIterable

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

the class ProjectDatabaseHelper method saveMemberDescriptors.

public static boolean saveMemberDescriptors(final String fqcn, final List<MemberDescriptor> members) {
    ProjectDatabase database = ProjectDatabase.getInstance();
    return database.execute(txn -> {
        EntityIterable it = txn.find(ClassIndex.ENTITY_TYPE, ProjectDatabase.ID, fqcn);
        Entity entity = it.getFirst();
        if (isNull(entity)) {
            return false;
        }
        try {
            ProjectDatabase.setSerializeBlobData(entity, BLOB_PROP_MEMBERS, members);
        } 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 12 with EntityIterable

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

the class ProjectDatabaseHelper method deleteMemberDescriptors.

public static boolean deleteMemberDescriptors(String fqcn) {
    ProjectDatabase database = ProjectDatabase.getInstance();
    return database.execute(txn -> {
        EntityIterable it = txn.find(ClassIndex.ENTITY_TYPE, ProjectDatabase.ID, fqcn);
        Entity entity = it.getFirst();
        if (isNull(entity)) {
            return false;
        }
        boolean result = entity.deleteBlob(BLOB_PROP_MEMBERS);
        // txn.saveEntity(entity);
        return result;
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable)

Example 13 with EntityIterable

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

the class ProjectDatabaseHelper method getClassIndexLinks.

public static void getClassIndexLinks(String fqcn, String linkName, Consumer<EntityIterable> fn) throws Exception {
    Map<String, ClassIndex> globalClassIndex = CachedASMReflector.getInstance().getGlobalClassIndex();
    if (!globalClassIndex.containsKey(fqcn)) {
        return;
    }
    ClassIndex index = globalClassIndex.get(fqcn);
    EntityId entityId = index.getEntityId();
    ProjectDatabase database = ProjectDatabase.getInstance();
    boolean result = database.execute(txn -> {
        Entity classEntity = txn.getEntity(entityId);
        EntityIterable iterable = classEntity.getLinks(linkName);
        fn.accept(iterable);
        return true;
    });
}
Also used : EntityId(jetbrains.exodus.entitystore.EntityId) ClassIndex(meghanada.reflect.ClassIndex) Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable)

Example 14 with EntityIterable

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

the class ProjectDatabaseHelper method deleteUnunsedSource.

public static boolean deleteUnunsedSource(Project p) {
    ProjectDatabase database = ProjectDatabase.getInstance();
    return database.execute(txn -> {
        EntityIterable all = txn.getAll(Source.ENTITY_TYPE);
        boolean result = false;
        for (Entity entity : all) {
            String path = (String) entity.getProperty("filePath");
            if (!Files.exists(Paths.get(path))) {
                entity.delete();
                try {
                    FileUtils.getClassFile(path, p.getSources(), p.getOutput()).ifPresent(File::delete);
                    FileUtils.getClassFile(path, p.getTestSources(), p.getTestOutput()).ifPresent(File::delete);
                } catch (IOException e) {
                    log.catching(e);
                }
                result = true;
            }
        }
        return result;
    });
}
Also used : Entity(jetbrains.exodus.entitystore.Entity) EntityIterable(jetbrains.exodus.entitystore.EntityIterable) IOException(java.io.IOException) File(java.io.File)

Example 15 with EntityIterable

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

the class ProjectDatabaseHelper method getCallerMap.

@Nonnull
@SuppressWarnings("unchecked")
public static Map<String, Set<String>> getCallerMap(String projectRoot) {
    ProjectDatabase database = ProjectDatabase.getInstance();
    Optional<Map<String, Set<String>>> result = database.computeInReadonly(txn -> {
        EntityIterable entities = txn.find(Project.ENTITY_TYPE, ProjectDatabase.ID, projectRoot).intersect(txn.findWithBlob(Project.ENTITY_TYPE, BLOB_PROP_CALLER));
        Entity entity = entities.getFirst();
        if (isNull(entity)) {
            return Optional.empty();
        }
        try (InputStream in = entity.getBlob(BLOB_PROP_CALLER)) {
            return Optional.ofNullable(Serializer.readObject(in, ConcurrentHashMap.class));
        } catch (Exception e) {
            log.warn(e.getMessage());
            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)

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