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;
});
}
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));
}
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;
});
}
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;
});
}
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));
}
Aggregations