use of jetbrains.exodus.entitystore.EntityIterable in project xodus by JetBrains.
the class SortEngine method sort.
public Iterable<Entity> sort(String entityType, final String propertyName, Iterable<Entity> source, final boolean ascending) {
ComparableGetter valueGetter = propertyGetter(propertyName);
final ModelMetaData mmd = queryEngine.getModelMetaData();
if (mmd != null) {
final EntityMetaData emd = mmd.getEntityMetaData(entityType);
if (emd != null) {
if (source == null) {
return mergeSorted(emd, new IterableGetter() {
@Override
public EntityIterableBase getIterable(String type) {
queryEngine.assertOperational();
return (EntityIterableBase) queryEngine.getPersistentStore().getAndCheckCurrentTransaction().sort(type, propertyName, ascending);
}
}, valueGetter, caseInsensitiveComparator(ascending));
}
final Iterable<Entity> i = queryEngine.toEntityIterable(source);
if (queryEngine.isPersistentIterable(i)) {
final EntityIterable it = ((EntityIterableBase) i).getSource();
if (it == EntityIterableBase.EMPTY) {
return queryEngine.wrap(EntityIterableBase.EMPTY);
}
if (it.getRoughCount() == 0 && it.count() == 0) {
return queryEngine.wrap(EntityIterableBase.EMPTY.asSortResult());
}
return mergeSorted(emd, new IterableGetter() {
@Override
public EntityIterableBase getIterable(String type) {
queryEngine.assertOperational();
return (EntityIterableBase) queryEngine.getPersistentStore().getAndCheckCurrentTransaction().sort(type, propertyName, it, ascending);
}
}, valueGetter, caseInsensitiveComparator(ascending));
}
}
}
if (source == null) {
source = getAllEntities(entityType, mmd);
}
return sortInMemory(source, valueGetter, ascending);
}
use of jetbrains.exodus.entitystore.EntityIterable in project xodus by JetBrains.
the class SortEngine method mergeSorted.
private EntityIterableBase mergeSorted(EntityMetaData emd, IterableGetter sorted, final ComparableGetter valueGetter, final Comparator<Comparable<Object>> comparator) {
EntityIterableBase result;
if (!(emd.hasSubTypes())) {
result = sorted.getIterable(emd.getType());
} else {
final List<EntityIterable> iterables = new ArrayList<>(4);
EntityIterableBase source = sorted.getIterable(emd.getType()).getSource();
if (source != EntityIterableBase.EMPTY) {
iterables.add(source);
}
for (final String type : emd.getAllSubTypes()) {
source = sorted.getIterable(type).getSource();
if (source != EntityIterableBase.EMPTY) {
iterables.add(source);
}
}
int iterablesCount = iterables.size();
if (iterablesCount == 0) {
result = EntityIterableBase.EMPTY;
} else if (iterablesCount == 1) {
result = (EntityIterableBase) iterables.get(0);
} else {
queryEngine.assertOperational();
result = (EntityIterableBase) queryEngine.getPersistentStore().getAndCheckCurrentTransaction().mergeSorted(iterables, new ComparableGetter() {
@Override
public Comparable select(Entity entity) {
return valueGetter.select(attach(entity));
}
}, comparator);
}
}
return (EntityIterableBase) queryEngine.wrap(result.getSource().asSortResult());
}
use of jetbrains.exodus.entitystore.EntityIterable in project xodus by JetBrains.
the class SortEngine method getAllEntities.
private Iterable<Entity> getAllEntities(final String entityType, final ModelMetaData mmd) {
queryEngine.assertOperational();
EntityIterable it = queryEngine.instantiateGetAll(entityType);
final EntityMetaData emd = mmd.getEntityMetaData(entityType);
if (emd != null) {
for (String subType : emd.getSubTypes()) {
if (Utils.getUnionSubtypes()) {
it = ((EntityIterable) getAllEntities(subType, mmd)).union(it);
} else {
it = ((EntityIterable) getAllEntities(subType, mmd)).concat(it);
}
}
}
return queryEngine.wrap(it);
}
use of jetbrains.exodus.entitystore.EntityIterable in project meghanada-server by mopemope.
the class ProjectDatabase method deleteObject.
public boolean deleteObject(String entityType, String id) throws Exception {
return this.entityStore.computeInTransaction(txn -> {
EntityIterable it = txn.find(entityType, ID, id);
Entity entity = it.getFirst();
if (isNull(entity)) {
return false;
}
return entity.delete();
});
}
use of jetbrains.exodus.entitystore.EntityIterable in project meghanada-server by mopemope.
the class ProjectDatabase method findAllObject.
public <T> void findAllObject(String entityType, Class<T> clazz, Consumer<T> consumer) throws Exception {
this.entityStore.executeInReadonlyTransaction(txn -> {
EntityIterable all = txn.getAll(entityType);
for (Entity entity : all) {
try (InputStream in = entity.getBlob(SERIALIZE_KEY)) {
T t = Serializer.readObject(in, clazz);
consumer.accept(t);
} catch (Exception e) {
log.warn(e.getMessage());
}
}
});
}
Aggregations