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