Search in sources :

Example 1 with EntityIterableHandle

use of jetbrains.exodus.entitystore.EntityIterableHandle 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();
        }
    };
}
Also used : EntityId(jetbrains.exodus.entitystore.EntityId) EntityIterableHandle(jetbrains.exodus.entitystore.EntityIterableHandle) NotNull(org.jetbrains.annotations.NotNull) EntityIterableHandleBase(jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase) Nullable(org.jetbrains.annotations.Nullable) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

EntityId (jetbrains.exodus.entitystore.EntityId)1 EntityIterableHandle (jetbrains.exodus.entitystore.EntityIterableHandle)1 EntityIterableHandleBase (jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1