Search in sources :

Example 1 with EntityIterableHandleBase

use of jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase 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 isConsistent() {
            return iterable1.getHandle().isConsistent() && iterable2.getHandle().isConsistent();
        }

        @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)

Example 2 with EntityIterableHandleBase

use of jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase in project xodus by JetBrains.

the class EntityIterableHandleTests method testTrivial.

public void testTrivial() {
    final EntityIterableHandleBase h = new ConstantEntityIterableHandle(getEntityStore(), EntityIterableType.EMPTY) {

        @Override
        public void toString(@NotNull final StringBuilder builder) {
            super.toString(builder);
            for (int i = 0; i < 31; ++i) {
                builder.append('0');
            }
        }

        @Override
        public void hashCode(@NotNull final EntityIterableHandleHash hash) {
            for (int i = 0; i < 31; ++i) {
                hash.apply("0");
            }
        }
    };
    Assert.assertEquals("00000000000000000000000000000000", h.toString());
}
Also used : ConstantEntityIterableHandle(jetbrains.exodus.entitystore.iterate.ConstantEntityIterableHandle) NotNull(org.jetbrains.annotations.NotNull) EntityIterableHandleBase(jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase)

Example 3 with EntityIterableHandleBase

use of jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase in project xodus by JetBrains.

the class EntityIterableHandleTests method test_XD_438.

public void test_XD_438() {
    final EntityIterableHandleBase h = new ConstantEntityIterableHandle(getEntityStore(), EntityIterableType.REVERSE) {

        @Override
        public void toString(@NotNull final StringBuilder builder) {
            super.toString(builder);
            builder.append(EntityIterableType.SINGLE_ENTITY.getType());
            builder.append('-');
            new PersistentEntityId(1000000000, 10000000000000000L).toString(builder);
        }

        @Override
        public void hashCode(@NotNull final EntityIterableHandleHash hash) {
            hash.apply(EntityIterableType.SINGLE_ENTITY.getType());
            hash.applyDelimiter();
            new PersistentEntityId(1000000000, 10000000000000000L).toHash(hash);
        }
    };
    Assert.assertEquals("Reversed iterable\n" + "|   Single entity 1000000000 10000000000000000", EntityIterableBase.getHumanReadablePresentation(h));
}
Also used : ConstantEntityIterableHandle(jetbrains.exodus.entitystore.iterate.ConstantEntityIterableHandle) NotNull(org.jetbrains.annotations.NotNull) EntityIterableHandleBase(jetbrains.exodus.entitystore.iterate.EntityIterableHandleBase)

Aggregations

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