Search in sources :

Example 21 with Entity

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

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

Example 23 with Entity

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

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

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

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