Search in sources :

Example 1 with SimpleConditionInfo

use of org.apache.ignite.internal.metastorage.common.command.SimpleConditionInfo in project ignite-3 by apache.

the class MetaStorageListener method toCondition.

private static Condition toCondition(ConditionInfo info) {
    if (info instanceof SimpleConditionInfo) {
        SimpleConditionInfo inf = (SimpleConditionInfo) info;
        byte[] key = inf.key();
        ConditionType type = inf.type();
        if (type == ConditionType.KEY_EXISTS) {
            return new ExistenceCondition(ExistenceCondition.Type.EXISTS, key);
        } else if (type == ConditionType.KEY_NOT_EXISTS) {
            return new ExistenceCondition(ExistenceCondition.Type.NOT_EXISTS, key);
        } else if (type == ConditionType.TOMBSTONE) {
            return new TombstoneCondition(key);
        } else if (type == ConditionType.VAL_EQUAL) {
            return new ValueCondition(ValueCondition.Type.EQUAL, key, inf.value());
        } else if (type == ConditionType.VAL_NOT_EQUAL) {
            return new ValueCondition(ValueCondition.Type.NOT_EQUAL, key, inf.value());
        } else if (type == ConditionType.VAL_GREATER) {
            return new ValueCondition(ValueCondition.Type.GREATER, key, inf.value());
        } else if (type == ConditionType.VAL_GREATER_OR_EQUAL) {
            return new ValueCondition(ValueCondition.Type.GREATER_OR_EQUAL, key, inf.value());
        } else if (type == ConditionType.VAL_LESS) {
            return new ValueCondition(ValueCondition.Type.LESS, key, inf.value());
        } else if (type == ConditionType.VAL_LESS_OR_EQUAL) {
            return new ValueCondition(ValueCondition.Type.LESS_OR_EQUAL, key, inf.value());
        } else if (type == ConditionType.REV_EQUAL) {
            return new RevisionCondition(RevisionCondition.Type.EQUAL, key, inf.revision());
        } else if (type == ConditionType.REV_NOT_EQUAL) {
            return new RevisionCondition(RevisionCondition.Type.NOT_EQUAL, key, inf.revision());
        } else if (type == ConditionType.REV_GREATER) {
            return new RevisionCondition(RevisionCondition.Type.GREATER, key, inf.revision());
        } else if (type == ConditionType.REV_GREATER_OR_EQUAL) {
            return new RevisionCondition(RevisionCondition.Type.GREATER_OR_EQUAL, key, inf.revision());
        } else if (type == ConditionType.REV_LESS) {
            return new RevisionCondition(RevisionCondition.Type.LESS, key, inf.revision());
        } else if (type == ConditionType.REV_LESS_OR_EQUAL) {
            return new RevisionCondition(RevisionCondition.Type.LESS_OR_EQUAL, key, inf.revision());
        } else {
            throw new IllegalArgumentException("Unknown condition type: " + type);
        }
    } else if (info instanceof CompoundConditionInfo) {
        CompoundConditionInfo inf = (CompoundConditionInfo) info;
        if (inf.type() == CompoundConditionType.AND) {
            return new AndCondition(toCondition(inf.leftConditionInfo()), toCondition(inf.rightConditionInfo()));
        } else if (inf.type() == CompoundConditionType.OR) {
            return new OrCondition(toCondition(inf.leftConditionInfo()), toCondition(inf.rightConditionInfo()));
        } else {
            throw new IllegalArgumentException("Unknown compound condition " + inf.type());
        }
    } else {
        throw new IllegalArgumentException("Unknown condition info type " + info);
    }
}
Also used : SimpleConditionInfo(org.apache.ignite.internal.metastorage.common.command.SimpleConditionInfo) TombstoneCondition(org.apache.ignite.internal.metastorage.server.TombstoneCondition) CompoundConditionInfo(org.apache.ignite.internal.metastorage.common.command.CompoundConditionInfo) ValueCondition(org.apache.ignite.internal.metastorage.server.ValueCondition) ExistenceCondition(org.apache.ignite.internal.metastorage.server.ExistenceCondition) CompoundConditionType(org.apache.ignite.internal.metastorage.common.command.CompoundConditionType) ConditionType(org.apache.ignite.internal.metastorage.common.ConditionType) OrCondition(org.apache.ignite.internal.metastorage.server.OrCondition) RevisionCondition(org.apache.ignite.internal.metastorage.server.RevisionCondition) AndCondition(org.apache.ignite.internal.metastorage.server.AndCondition)

Example 2 with SimpleConditionInfo

use of org.apache.ignite.internal.metastorage.common.command.SimpleConditionInfo in project ignite-3 by apache.

the class MetaStorageServiceImpl method toConditionInfo.

private static ConditionInfo toConditionInfo(@NotNull Condition condition) {
    ConditionInfo cnd = null;
    if (condition instanceof SimpleCondition) {
        Object obj = ((SimpleCondition) condition).inner();
        if (obj instanceof SimpleCondition.ExistenceCondition) {
            SimpleCondition.ExistenceCondition inner = (SimpleCondition.ExistenceCondition) obj;
            cnd = new SimpleConditionInfo(inner.key(), inner.type(), null, 0);
        } else if (obj instanceof SimpleCondition.TombstoneCondition) {
            SimpleCondition.TombstoneCondition inner = (SimpleCondition.TombstoneCondition) obj;
            cnd = new SimpleConditionInfo(inner.key(), inner.type(), null, 0);
        } else if (obj instanceof SimpleCondition.RevisionCondition) {
            SimpleCondition.RevisionCondition inner = (SimpleCondition.RevisionCondition) obj;
            cnd = new SimpleConditionInfo(inner.key(), inner.type(), null, inner.revision());
        } else if (obj instanceof SimpleCondition.ValueCondition) {
            SimpleCondition.ValueCondition inner = (SimpleCondition.ValueCondition) obj;
            cnd = new SimpleConditionInfo(inner.key(), inner.type(), inner.value(), 0);
        } else {
            assert false : "Unknown condition type: " + obj.getClass().getSimpleName();
        }
    } else if (condition instanceof CompoundCondition) {
        CompoundCondition cond = (CompoundCondition) condition;
        cnd = new CompoundConditionInfo(toConditionInfo(cond.leftCondition()), toConditionInfo(cond.rightCondition()), cond.compoundConditionType());
    } else {
        assert false : "Unknown condition type: " + condition.getClass().getSimpleName();
    }
    return cnd;
}
Also used : ConditionInfo(org.apache.ignite.internal.metastorage.common.command.ConditionInfo) SimpleConditionInfo(org.apache.ignite.internal.metastorage.common.command.SimpleConditionInfo) CompoundConditionInfo(org.apache.ignite.internal.metastorage.common.command.CompoundConditionInfo) SimpleConditionInfo(org.apache.ignite.internal.metastorage.common.command.SimpleConditionInfo) CompoundConditionInfo(org.apache.ignite.internal.metastorage.common.command.CompoundConditionInfo)

Aggregations

CompoundConditionInfo (org.apache.ignite.internal.metastorage.common.command.CompoundConditionInfo)2 SimpleConditionInfo (org.apache.ignite.internal.metastorage.common.command.SimpleConditionInfo)2 ConditionType (org.apache.ignite.internal.metastorage.common.ConditionType)1 CompoundConditionType (org.apache.ignite.internal.metastorage.common.command.CompoundConditionType)1 ConditionInfo (org.apache.ignite.internal.metastorage.common.command.ConditionInfo)1 AndCondition (org.apache.ignite.internal.metastorage.server.AndCondition)1 ExistenceCondition (org.apache.ignite.internal.metastorage.server.ExistenceCondition)1 OrCondition (org.apache.ignite.internal.metastorage.server.OrCondition)1 RevisionCondition (org.apache.ignite.internal.metastorage.server.RevisionCondition)1 TombstoneCondition (org.apache.ignite.internal.metastorage.server.TombstoneCondition)1 ValueCondition (org.apache.ignite.internal.metastorage.server.ValueCondition)1