sashapolo commented on code in PR #1518:
URL: https://github.com/apache/ignite-3/pull/1518#discussion_r1069126579
##########
modules/metastorage-api/src/main/java/org/apache/ignite/internal/metastorage/dsl/Operation.java:
##########
@@ -17,158 +17,90 @@
package org.apache.ignite.internal.metastorage.dsl;
-import org.jetbrains.annotations.NotNull;
+import org.apache.ignite.internal.util.IgniteUtils;
import org.jetbrains.annotations.Nullable;
/**
* Defines operation for meta storage conditional update (invoke).
*/
public final class Operation {
- /** Actual operation implementation. */
- private final InnerOp upd;
-
/**
- * Constructs an operation which wraps the actual operation implementation.
- *
- * @param upd The actual operation implementation.
+ * Key identifies an entry which operation will be applied to. Key is
{@code null} for {@link OperationType#NO_OP} operation.
*/
- Operation(InnerOp upd) {
- this.upd = upd;
- }
+ private final byte @Nullable [] key;
/**
- * Returns actual operation implementation.
+ * Value which will be associated with the {@link #key}. Value is not
{@code null} only for {@link OperationType#PUT} operation.
*/
- public InnerOp inner() {
- return upd;
- }
+ private final byte @Nullable [] val;
/**
- * Returns operation type.
+ * Operation type.
*
- * @return Operation type.
+ * @see OperationType
*/
- public OperationType type() {
- return upd.type();
- }
+ private final OperationType type;
/**
- * Represents operation of type <i>remove</i>.
+ * Constructs operation which will be applied to an entry identified by
the given key.
+ *
+ * @param type Operation type. Can't be {@code null}.
+ * @param key Key identifies an entry which operation will be applied to.
+ * @param val Value will be associated with an entry identified by the
{@code key}.
*/
- public static final class RemoveOp extends AbstractOp {
- /**
- * Default no-op constructor.
- *
- * @param key Identifies an entry which operation will be applied to.
- */
- RemoveOp(byte[] key) {
- super(key, OperationType.REMOVE);
- }
+ public Operation(OperationType type, byte @Nullable [] key, byte @Nullable
[] val) {
+ assert (type == OperationType.NO_OP && key == null && val == null)
+ || (type == OperationType.PUT && key != null && val != null)
+ || (type == OperationType.REMOVE && key != null && val == null)
+ : "Invalid operation parameters: [type=" + type
+ + ", key=" + (key == null ? "null" :
IgniteUtils.toHexString(key, 256))
+ + ", val=" + (val == null ? "null" :
IgniteUtils.toHexString(val, 256)) + ']';
+
+ this.key = key;
+ this.val = val;
+ this.type = type;
}
/**
- * Represents operation of type <i>put</i>.
+ * Returns a key which identifies an entry which operation will be applied
to.
+ *
+ * @return A key which identifies an entry which operation will be applied
to.
*/
- public static final class PutOp extends AbstractOp {
- /** Value. */
- private final byte[] val;
-
- /**
- * Constructs operation of type <i>put</i>.
- *
- * @param key Identifies an entry which operation will be applied to.
- * @param val The value to which the entry should be updated.
- */
- PutOp(byte[] key, byte[] val) {
- super(key, OperationType.PUT);
-
- this.val = val;
- }
-
- /**
- * Returns value.
- *
- * @return Value.
- */
- public byte[] value() {
- return val;
- }
+ public byte @Nullable [] key() {
+ return key;
}
/**
- * Represents operation of type <i>no-op</i>.
+ * Returns a value which will be associated with an entry identified by
the {@code key}.
+ *
+ * @return A value which will be associated with an entry identified by
the {@code key}.
*/
- public static final class NoOp extends AbstractOp {
- /**
- * Default no-op constructor.
- */
- NoOp() {
- super(null, OperationType.NO_OP);
- }
+
+ public byte @Nullable [] value() {
+ return val;
}
/**
- * Defines operation interface.
+ * Returns an operation type.
+ *
+ * @return An operation type.
*/
- public interface InnerOp {
- /**
- * Returns key.
- *
- * @return Key.
- */
- @Nullable byte[] key();
-
- /**
- * Returns operation type.
- *
- * @return Operation type.
- */
- @NotNull OperationType type();
+ public OperationType type() {
+ return type;
}
/**
- * Extension of {@link InnerOp}.
+ * Represents operation of type <i>remove</i>.
*/
- private static class AbstractOp implements InnerOp {
- /** Key. */
- @Nullable
- private final byte[] key;
-
- /** Operation type. */
- @NotNull
- private final OperationType type;
-
- /**
- * Ctor.
- *
- * @param key Key.
- * @param type Operation type.
- */
- private AbstractOp(@Nullable byte[] key, OperationType type) {
- this.key = key;
- this.type = type;
- }
+ public static Operation remove(byte[] key) {
+ return new Operation(OperationType.REMOVE, key, null);
+ }
- /**
- * Returns key.
- *
- * @return Key.
- */
- @Nullable
- @Override
- public byte[] key() {
- return key;
- }
+ public static Operation put(byte[] key, byte[] val) {
Review Comment:
I forgot about them, sorry
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]