use of jetbrains.exodus.entitystore.Entity 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.Entity 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();
}
use of jetbrains.exodus.entitystore.Entity in project meghanada-server by mopemope.
the class ProjectDatabase method loadObject.
public <T> T loadObject(String entityType, String id, Class<T> clazz) throws Exception {
return this.entityStore.computeInReadonlyTransaction(txn -> {
EntityIterable it = txn.find(entityType, ID, id);
Entity entity = it.getFirst();
if (nonNull(entity)) {
try (InputStream in = entity.getBlob(SERIALIZE_KEY)) {
return Serializer.readObject(in, clazz);
} catch (Exception e) {
log.warn(e.getMessage());
return null;
}
}
return null;
});
}
use of jetbrains.exodus.entitystore.Entity in project meghanada-server by mopemope.
the class Source method addClassReference.
private static void addClassReference(StoreTransaction txn, Entity mainEntity, Map<String, ClassIndex> classIndex, Entity entity, String fqcn) {
if (isNull(fqcn)) {
return;
}
classIndex.computeIfPresent(fqcn, (key, index) -> {
try {
EntityId entityId = index.getEntityId();
if (nonNull(entityId)) {
Entity classEntity = txn.getEntity(entityId);
classEntity.addLink(LINK_CLASS_REFERENCES, entity);
entity.addLink(LINK_CLASS, classEntity);
mainEntity.addLink(LINK_REV_CLASS_REFERENCES, entity);
}
} catch (Exception e) {
log.warn(e.getMessage());
}
return index;
});
}
use of jetbrains.exodus.entitystore.Entity in project xodus by JetBrains.
the class ExcludeNullStaticTypedEntityIterable method instantiate.
@Override
public Iterable<Entity> instantiate() {
Iterable<Entity> instantiatedDecorated = decorated.instantiate();
if (queryEngine.isPersistentIterable(instantiatedDecorated)) {
EntityIterableBase entityIterableBaseDecorated = ((EntityIterableBase) instantiatedDecorated).getSource();
if (entityIterableBaseDecorated == EntityIterableBase.EMPTY) {
return EntityIterableBase.EMPTY;
}
return queryEngine.wrap(new ExcludeNullIterableDecorator(entityIterableBaseDecorated.getTransaction(), entityIterableBaseDecorated));
}
return new Iterable<Entity>() {
@Override
public Iterator<Entity> iterator() {
return new Iterator<Entity>() {
private Iterator<Entity> iterator = null;
private Entity next = null;
@Override
public boolean hasNext() {
if (next != null) {
return true;
}
if (iterator == null) {
iterator = decorated.iterator();
}
while (iterator.hasNext() && next == null) {
next = iterator.next();
}
return next != null;
}
@Override
public Entity next() {
if (hasNext()) {
Entity result = next;
next = null;
return result;
}
throw new NoSuchElementException();
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
};
}
Aggregations