use of jetbrains.exodus.entitystore.EntityId in project meghanada-server by mopemope.
the class ProjectDatabaseHelper method getClassIndexLinks.
public static void getClassIndexLinks(String fqcn, String linkName, Consumer<EntityIterable> fn) throws Exception {
Map<String, ClassIndex> globalClassIndex = CachedASMReflector.getInstance().getGlobalClassIndex();
if (!globalClassIndex.containsKey(fqcn)) {
return;
}
ClassIndex index = globalClassIndex.get(fqcn);
EntityId entityId = index.getEntityId();
ProjectDatabase database = ProjectDatabase.getInstance();
boolean result = database.execute(txn -> {
Entity classEntity = txn.getEntity(entityId);
EntityIterable iterable = classEntity.getLinks(linkName);
fn.accept(iterable);
return true;
});
}
use of jetbrains.exodus.entitystore.EntityId 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.EntityId 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.EntityId in project xodus by JetBrains.
the class OrderedEntityIdCollectionIterator method nextIdImpl.
@Override
@Nullable
public EntityId nextIdImpl() {
EntityId result = sourceIterator.next();
index++;
return result;
}
use of jetbrains.exodus.entitystore.EntityId in project xodus by JetBrains.
the class BinaryOperatorEntityIterable method getHandleImpl.
@Override
@NotNull
protected EntityIterableHandleBase getHandleImpl() {
return new EntityIterableHandleBase(getStore(), getIterableType()) {
private int entityTypeId = -1;
@NotNull
private final int[] linkIds = mergeFieldIds(iterable1.getHandle().getLinkIds(), iterable2.getHandle().getLinkIds());
@NotNull
private final int[] propertyIds = mergeFieldIds(iterable1.getHandle().getPropertyIds(), iterable2.getHandle().getPropertyIds());
@NotNull
private final int[] typeIdsAffectingCreation = mergeFieldIds(iterable1.getHandle().getTypeIdsAffectingCreation(), iterable2.getHandle().getTypeIdsAffectingCreation());
@NotNull
@Override
public int[] getLinkIds() {
return linkIds;
}
@Override
@NotNull
public int[] getPropertyIds() {
return propertyIds;
}
@NotNull
@Override
public int[] getTypeIdsAffectingCreation() {
return typeIdsAffectingCreation;
}
@Override
public void toString(@NotNull final StringBuilder builder) {
super.toString(builder);
((EntityIterableHandleBase) iterable1.getHandle()).toString(builder);
builder.append('-');
((EntityIterableHandleBase) iterable2.getHandle()).toString(builder);
}
@Override
public void hashCode(@NotNull final EntityIterableHandleHash hash) {
final EntityIterableHandle handle1 = iterable1.getHandle();
final EntityIterableHandle handle2 = iterable2.getHandle();
if (!isCommutative() || isOrderOk(handle1, handle2)) {
hash.apply(handle1);
hash.applyDelimiter();
hash.apply(handle2);
} else {
hash.apply(handle2);
hash.applyDelimiter();
hash.apply(handle1);
}
}
@Override
public int getEntityTypeId() {
if (entityTypeId == -1) {
final int entityTypeId1 = iterable1.getHandle().getEntityTypeId();
if (entityTypeId1 < 0) {
entityTypeId = NULL_TYPE_ID;
} else {
final int entityTypeId2 = iterable2.getHandle().getEntityTypeId();
entityTypeId = entityTypeId1 == entityTypeId2 ? entityTypeId1 : NULL_TYPE_ID;
}
}
return entityTypeId;
}
@Override
public boolean isMatchedEntityAdded(@NotNull final EntityId added) {
return iterable1.getHandle().isMatchedEntityAdded(added) || iterable2.getHandle().isMatchedEntityAdded(added);
}
@Override
public boolean isMatchedEntityDeleted(@NotNull final EntityId deleted) {
return iterable1.getHandle().isMatchedEntityDeleted(deleted) || iterable2.getHandle().isMatchedEntityDeleted(deleted);
}
@Override
public boolean isMatchedLinkAdded(@NotNull final EntityId source, @NotNull final EntityId target, final int linkId) {
final EntityIterableHandle handle1 = iterable1.getHandle();
final EntityIterableHandle handle2;
if (handle1.hasLinkId(linkId)) {
if (handle1.isMatchedLinkAdded(source, target, linkId)) {
return true;
}
handle2 = iterable2.getHandle();
if (!handle2.hasLinkId(linkId)) {
return false;
}
} else {
handle2 = iterable2.getHandle();
}
return handle2.isMatchedLinkAdded(source, target, linkId);
}
@Override
public boolean isMatchedLinkDeleted(@NotNull EntityId source, @NotNull EntityId target, int linkId) {
final EntityIterableHandle handle1 = iterable1.getHandle();
final EntityIterableHandle handle2;
if (handle1.hasLinkId(linkId)) {
if (handle1.isMatchedLinkDeleted(source, target, linkId)) {
return true;
}
handle2 = iterable2.getHandle();
if (!handle2.hasLinkId(linkId)) {
return false;
}
} else {
handle2 = iterable2.getHandle();
}
return handle2.isMatchedLinkDeleted(source, target, linkId);
}
@Override
public boolean isMatchedPropertyChanged(@NotNull EntityId id, final int propertyId, @Nullable final Comparable oldValue, @Nullable final Comparable newValue) {
final int entityTypeId = getEntityTypeId();
return (entityTypeId < 0 || entityTypeId == id.getTypeId()) && (iterable1.getHandle().isMatchedPropertyChanged(id, propertyId, oldValue, newValue) || iterable2.getHandle().isMatchedPropertyChanged(id, propertyId, oldValue, newValue));
}
@Override
public boolean isExpired() {
return iterable1.getHandle().isExpired() || iterable2.getHandle().isExpired();
}
};
}
Aggregations