This is an automated email from the ASF dual-hosted git repository.

zstan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new c262836425e IGNITE-28773 CacheOperationContext refactoring (#13242)
c262836425e is described below

commit c262836425e6b9ec621d4ef99163d621e3945071
Author: Evgeniy Stanilovskiy <[email protected]>
AuthorDate: Tue Jun 23 08:08:03 2026 +0300

    IGNITE-28773 CacheOperationContext refactoring (#13242)
---
 .../processors/cache/CacheOperationContext.java    | 543 +++++++++++----------
 .../cache/GatewayProtectedCacheProxy.java          |  14 +-
 .../processors/cache/GridCacheAdapter.java         | 124 +----
 .../processors/cache/GridCacheProxyImpl.java       | 143 ++----
 .../processors/cache/IgniteCacheProxyImpl.java     |   4 +-
 .../processors/cache/IgniteInternalCache.java      |   3 +-
 .../dht/GridDhtTransactionalCacheAdapter.java      |   2 +-
 .../distributed/dht/atomic/GridDhtAtomicCache.java |  17 +-
 .../atomic/GridNearAtomicAbstractUpdateFuture.java |   2 +-
 .../dht/colocated/GridDhtColocatedCache.java       |   6 +-
 .../near/GridNearTransactionalCache.java           |   4 +-
 .../cache/distributed/near/GridNearTxLocal.java    |  10 +-
 .../datastructures/GridCacheQueueAdapter.java      |  16 +-
 .../handlers/cache/GridCacheCommandHandler.java    |  12 +-
 .../cache/GridCacheCommandHandlerSelfTest.java     |  10 -
 .../internal/processors/query/h2/dml/DmlUtils.java |   4 +-
 16 files changed, 400 insertions(+), 514 deletions(-)

diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
index eab8e8472fa..d4aba5d39f7 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheOperationContext.java
@@ -17,13 +17,12 @@
 
 package org.apache.ignite.internal.processors.cache;
 
+import java.io.Serial;
 import java.io.Serializable;
-import java.util.Collections;
-import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import javax.cache.expiry.ExpiryPolicy;
 import org.apache.ignite.cache.ReadRepairStrategy;
-import org.apache.ignite.internal.util.tostring.GridToStringInclude;
 import org.apache.ignite.internal.util.typedef.internal.S;
 import org.jetbrains.annotations.Nullable;
 
@@ -32,68 +31,52 @@ import org.jetbrains.annotations.Nullable;
  */
 public class CacheOperationContext implements Serializable {
     /** */
-    private static final long serialVersionUID = 0L;
+    @Serial private static final long serialVersionUID = 0L;
 
-    /** Skip store. */
-    @GridToStringInclude
+    /** */
+    private static final CacheOperationContext INSTANCE = new 
Builder().build();
+
+    /** Skip store flag. */
     private final boolean skipStore;
 
-    /** Skip store. */
-    @GridToStringInclude
+    /** Skip read through flag. */
     private final boolean skipReadThrough;
 
     /** No retries flag. */
-    @GridToStringInclude
     private final boolean noRetries;
 
-    /** */
+    /** Recovery flag. */
     private final boolean recovery;
 
     /** Read-repair strategy. */
-    private final ReadRepairStrategy readRepairStrategy;
+    private final @Nullable ReadRepairStrategy readRepairStrategy;
 
     /** Keep binary flag. */
     private final boolean keepBinary;
 
     /** Expiry policy. */
-    private final ExpiryPolicy expiryPlc;
+    private final @Nullable ExpiryPolicy expiryPlc;
 
     /** Data center Id. */
-    private final Byte dataCenterId;
+    private final @Nullable Byte dataCenterId;
 
     /** Application attributes. */
-    private final Map<String, String> appAttrs;
+    private final @Nullable Map<String, String> appAttrs;
 
     /** Handle binary in interceptor operation flag. */
     private final boolean keepBinaryInInterceptor;
 
     /**
-     * Constructor with default values.
-     */
-    public CacheOperationContext() {
-        skipStore = false;
-        skipReadThrough = false;
-        keepBinary = false;
-        expiryPlc = null;
-        noRetries = false;
-        recovery = false;
-        readRepairStrategy = null;
-        dataCenterId = null;
-        appAttrs = null;
-        keepBinaryInInterceptor = false;
-    }
-
-    /**
-     * @param skipStore Skip store flag.
-     * @param skipReadThrough Skip read-through cache store flag.
-     * @param keepBinary Keep binary flag.
-     * @param expiryPlc Expiry policy.
-     * @param dataCenterId Data center id.
-     * @param readRepairStrategy Read-repair strategy.
-     * @param appAttrs Application attributes.
-     * @param keepBinaryInInterceptor Handle binary in interceptor operation 
flag.
+     * @param skipStore                  Skip store flag.
+     * @param skipReadThrough            Skip read-through cache store flag.
+     * @param keepBinary                 Keep binary flag.
+     * @param expiryPlc                  Expiry policy.
+     * @param dataCenterId               Data center id.
+     * @param readRepairStrategy         Read-repair strategy.
+     * @param appAttrs                   Application attributes.
+     * @param keepBinaryInInterceptor  Handle binary in interceptor operation 
flag.
      */
-    public CacheOperationContext(
+    private CacheOperationContext(
         boolean skipStore,
         boolean skipReadThrough,
         boolean keepBinary,
@@ -118,60 +101,30 @@ public class CacheOperationContext implements 
Serializable {
     }
 
     /**
-     * @return Keep binary flag.
+     * Helper.
      */
-    public boolean isKeepBinary() {
-        return keepBinary;
+    public static CacheOperationContext instance() {
+        return INSTANCE;
     }
 
-    /** Return handle binary in interceptor operation flag. */
-    public boolean isKeepBinaryInInterceptor() {
-        return keepBinaryInInterceptor;
+    /** Helper. */
+    public static CacheOperationContext of(CacheOperationContext opCtx) {
+        return opCtx == null ? INSTANCE : opCtx;
     }
 
     /**
-     * @return {@code True} if data center id is set otherwise {@code false}.
+     * @return keepBinary flag.
      */
-    public boolean hasDataCenterId() {
-        return dataCenterId != null;
+    public boolean isKeepBinary() {
+        return keepBinary;
     }
 
-    /**
-     * See {@link IgniteInternalCache#keepBinary()}.
-     *
-     * @return New instance of CacheOperationContext with keep binary flag.
-     */
-    public CacheOperationContext keepBinary() {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            true,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            true);
-    }
+    /** Context with keepBinary flag. */
+    public CacheOperationContext withKeepBinary() {
+        if (isKeepBinary())
+            return this;
 
-    /**
-     * See {@link IgniteInternalCache#withKeepBinaryInInterceptor()}.
-     *
-     * @return New instance of CacheOperationContext with handle binary in 
interceptor flag.
-     */
-    public CacheOperationContext withKeepBinaryInInterceptor() {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            true);
+        return builder(this).keepBinary(true).build();
     }
 
     /**
@@ -183,223 +136,311 @@ public class CacheOperationContext implements 
Serializable {
         return dataCenterId;
     }
 
-    /**
-     * @return Skip store.
-     */
-    public boolean skipStore() {
-        return skipStore;
+    /** Context with dataCenterId. */
+    public CacheOperationContext withDataCenterId(Byte dataCenterId) {
+        if (Objects.equals(this.dataCenterId, dataCenterId))
+            return this;
+
+        return builder(this).dataCenterId(dataCenterId).build();
     }
 
     /**
-     * See {@link IgniteInternalCache#setSkipStore(boolean)}.
-     *
-     * @param skipStore Skip store flag.
-     * @return New instance of CacheOperationContext with skip store flag.
+     * @return Partition recover flag.
      */
-    public CacheOperationContext setSkipStore(boolean skipStore) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            keepBinaryInInterceptor);
+    public boolean recovery() {
+        return recovery;
     }
 
-    /** @return Skip read-through cache store. */
-    public boolean skipReadThrough() {
-        return skipReadThrough;
+    /** Context with recovery flag. */
+    public CacheOperationContext withRecovery() {
+        if (recovery())
+            return this;
+
+        return builder(this).recovery(true).build();
     }
 
     /**
-     * See {@link IgniteInternalCache#withApplicationAttributes(Map)}.
-     *
-     * @return New instance of CacheOperationContext with new application 
attributes.
+     * @return Read Repair strategy.
      */
-    public CacheOperationContext withApplicationAttributes(Map<String, String> 
attrs) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            Collections.unmodifiableMap(attrs),
-            keepBinaryInInterceptor);
+    @Nullable public ReadRepairStrategy readRepairStrategy() {
+        return readRepairStrategy;
     }
 
-    /**
-     * See {@link IgniteInternalCache#withSkipReadThrough()}.
-     *
-     * @return New instance of CacheOperationContext with skip store flag.
-     */
-    public CacheOperationContext withSkipReadThrough() {
-        return new CacheOperationContext(
-            skipStore,
-            true,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            keepBinaryInInterceptor);
+    /** Context with read repair strategy. */
+    public CacheOperationContext withReadRepairStrategy(ReadRepairStrategy 
strategy) {
+        if (readRepairStrategy() == strategy)
+            return this;
+
+        return builder(this).readRepairStrategy(strategy).build();
     }
 
     /**
-     * @return {@link ExpiryPolicy} associated with this projection.
+     * @return No retries flag.
      */
-    @Nullable public ExpiryPolicy expiry() {
-        return expiryPlc;
+    public boolean noRetries() {
+        return noRetries;
     }
 
-    /**
-     * See {@link IgniteInternalCache#withExpiryPolicy(ExpiryPolicy)}.
-     *
-     * @param plc {@link ExpiryPolicy} to associate with this projection.
-     * @return New instance of CacheOperationContext with skip store flag.
-     */
-    public CacheOperationContext withExpiryPolicy(ExpiryPolicy plc) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            plc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            keepBinaryInInterceptor);
+    /** Context with noRetries flag. */
+    public CacheOperationContext withNoRetries() {
+        if (noRetries())
+            return this;
+
+        return builder(this).noRetries(true).build();
     }
 
     /**
-     * @param noRetries No retries flag.
-     * @return Operation context.
+     * @return Application attributes.
      */
-    public CacheOperationContext setNoRetries(boolean noRetries) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            keepBinaryInInterceptor);
+    @Nullable public Map<String, String> applicationAttributes() {
+        return appAttrs;
     }
 
-    /**
-     * @param dataCenterId Data center id.
-     * @return Operation context.
-     */
-    public CacheOperationContext setDataCenterId(byte dataCenterId) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            keepBinaryInInterceptor);
+    /** Context with application attributes. */
+    public CacheOperationContext withApplicationAttributes(Map<String, String> 
attrs) {
+        return builder(this).applicationAttributes(attrs).build();
     }
 
     /**
-     * @param recovery Recovery flag.
-     * @return New instance of CacheOperationContext with recovery flag.
+     * @return Skip store.
      */
-    public CacheOperationContext setRecovery(boolean recovery) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            keepBinaryInInterceptor);
+    public boolean skipStore() {
+        return skipStore;
     }
 
-    /**
-     * @param readRepairStrategy Read Repair strategy.
-     * @return New instance of CacheOperationContext with Read Repair flag.
-     */
-    public CacheOperationContext setReadRepairStrategy(ReadRepairStrategy 
readRepairStrategy) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            appAttrs,
-            keepBinaryInInterceptor);
+    /** Context with skipStore flag. */
+    public CacheOperationContext withSkipStore() {
+        if (skipStore())
+            return this;
+
+        return builder(this).skipStore(true).build();
     }
 
     /**
-     * @param appAttrs Application attributes.
-     * @return New instance of CacheOperationContext with application 
attributes.
+     * @return Skip read-through cache store.
      */
-    public CacheOperationContext setApplicationAttributes(Map<String, String> 
appAttrs) {
-        return new CacheOperationContext(
-            skipStore,
-            skipReadThrough,
-            keepBinary,
-            expiryPlc,
-            noRetries,
-            dataCenterId,
-            recovery,
-            readRepairStrategy,
-            new HashMap<>(appAttrs),
-            keepBinaryInInterceptor);
+    public boolean skipReadThrough() {
+        return skipReadThrough;
     }
 
-    /**
-     * @return Partition recover flag.
-     */
-    public boolean recovery() {
-        return recovery;
+    /** Context with {@link CacheOperationContext#skipReadThrough} flag. */
+    public CacheOperationContext withSkipReadThrough() {
+        if (skipReadThrough())
+            return this;
+
+        return builder(this).skipReadThrough(true).build();
+    }
+
+    /** @return Whether to handle binary in interceptor. */
+    public boolean keepBinaryInInterceptor() {
+        return keepBinaryInInterceptor;
+    }
+
+    /** Context with {@link CacheOperationContext#keepBinaryInInterceptor} 
flag. */
+    public CacheOperationContext withKeepBinaryInInterceptor() {
+        if (keepBinaryInInterceptor())
+            return this;
+
+        return builder(this).keepBinaryInInterceptor(true).build();
     }
 
     /**
-     * @return Read Repair strategy.
+     * @return {@link ExpiryPolicy} associated with this projection.
      */
-    public ReadRepairStrategy readRepairStrategy() {
-        return readRepairStrategy;
+    @Nullable public ExpiryPolicy expiry() {
+        return expiryPlc;
+    }
+
+    /** Context with {@link CacheOperationContext#expiryPlc}. */
+    public CacheOperationContext withExpiryPolicy(ExpiryPolicy plc) {
+        return builder(this).expiryPolicy(plc).build();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(CacheOperationContext.class, this);
     }
 
     /**
-     * @return No retries flag.
+     * Creates the builder from existing context.
+     *
+     * @return Builder for cache operations context.
      */
-    public boolean noRetries() {
-        return noRetries;
+    public static Builder builder(CacheOperationContext ctx) {
+        return new Builder(ctx);
     }
 
     /**
-     * @return Application attributes.
+     * Creates the builder for cache operations context.
+     *
+     * @return Builder for cache operations context.
      */
-    public Map<String, String> applicationAttributes() {
-        return appAttrs;
+    public static Builder builder() {
+        return new Builder();
     }
 
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(CacheOperationContext.class, this);
+    /** Cache operations context builder. */
+    public static class Builder {
+        /** Skip store. */
+        private boolean skipStore;
+
+        /** Skip read through. */
+        private boolean skipReadThrough;
+
+        /** No retries flag. */
+        private boolean noRetries;
+
+        /** Recovery flag. */
+        private boolean recovery;
+
+        /** Read-repair strategy. */
+        private ReadRepairStrategy readRepairStrategy;
+
+        /** Keep binary flag. */
+        private boolean keepBinary;
+
+        /** Expiry policy. */
+        private ExpiryPolicy expiryPlc;
+
+        /** Data center Id. */
+        private Byte dataCenterId;
+
+        /** Application attributes. */
+        private Map<String, String> appAttrs;
+
+        /** Flag indicating whether to handle binary in interceptor. */
+        private boolean keepBinaryInInterceptor;
+
+        /** */
+        Builder() {
+            // No context.
+        }
+
+        /** */
+        Builder(CacheOperationContext ctx) {
+            skipStore = ctx.skipStore;
+            skipReadThrough = ctx.skipReadThrough;
+            noRetries = ctx.noRetries;
+            recovery = ctx.recovery;
+            readRepairStrategy = ctx.readRepairStrategy;
+            keepBinary = ctx.keepBinary;
+            expiryPlc = ctx.expiryPlc;
+            dataCenterId = ctx.dataCenterId;
+            appAttrs = ctx.appAttrs;
+            keepBinaryInInterceptor = ctx.keepBinaryInInterceptor;
+        }
+
+        /**
+         * CacheOperationContext with keepBinary and keepBinaryInInterceptor 
flags.
+         *
+         * @see IgniteInternalCache#keepBinary()
+         * @see IgniteInternalCache#withKeepBinaryInInterceptor()
+         */
+        public Builder keepBinary(boolean keepBinary) {
+            this.keepBinary = keepBinary;
+            keepBinaryInInterceptor = keepBinary;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with skipStore flag.
+         *
+         * @see IgniteInternalCache#withSkipStore()
+         */
+        public Builder skipStore(boolean skipStore) {
+            this.skipStore = skipStore;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with attributes.
+         *
+         * @see IgniteInternalCache#withApplicationAttributes(Map)
+         */
+        public Builder applicationAttributes(Map<String, String> attrs) {
+            appAttrs = Map.copyOf(attrs);
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with skip read through flag.
+         *
+         * @see IgniteInternalCache#withSkipReadThrough()
+         */
+        public Builder skipReadThrough(boolean skipReadThrough) {
+            this.skipReadThrough = skipReadThrough;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with handle binary in interceptor execution 
flag.
+         *
+         * @see IgniteInternalCache#withKeepBinaryInInterceptor()
+         */
+        public Builder keepBinaryInInterceptor(boolean 
keepBinaryInInterceptor) {
+            this.keepBinaryInInterceptor = keepBinaryInInterceptor;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with expiry policy.
+         *
+         * @see IgniteInternalCache#withExpiryPolicy(ExpiryPolicy)
+         */
+        public Builder expiryPolicy(ExpiryPolicy expiryPlc) {
+            this.expiryPlc = expiryPlc;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with no retries flag.
+         */
+        public Builder noRetries(boolean noRetries) {
+            this.noRetries = noRetries;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with Data center id.
+         */
+        public Builder dataCenterId(Byte dataCenterId) {
+            this.dataCenterId = dataCenterId;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with recovery flag.
+         */
+        public Builder recovery(boolean recovery) {
+            this.recovery = recovery;
+            return this;
+        }
+
+        /**
+         * CacheOperationContext with read repair strategy.
+         */
+        public Builder readRepairStrategy(ReadRepairStrategy 
readRepairStrategy) {
+            this.readRepairStrategy = readRepairStrategy;
+            return this;
+        }
+
+        /**
+         * Builds cache operations context.
+         *
+         * @return Cache operations context.
+         */
+        public CacheOperationContext build() {
+            return new CacheOperationContext(
+                skipStore,
+                skipReadThrough,
+                keepBinary,
+                expiryPlc,
+                noRetries,
+                dataCenterId,
+                recovery,
+                readRepairStrategy,
+                appAttrs,
+                keepBinaryInInterceptor);
+        }
     }
 }
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
index fba0e990c5e..205af51e47f 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GatewayProtectedCacheProxy.java
@@ -166,7 +166,7 @@ public class GatewayProtectedCacheProxy<K, V> extends 
AsyncSupportAdapter<Ignite
             if (skip)
                 return this;
 
-            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.setSkipStore(true), lock);
+            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.withSkipStore(), lock);
         }
         finally {
             onLeave(opGate);
@@ -180,7 +180,7 @@ public class GatewayProtectedCacheProxy<K, V> extends 
AsyncSupportAdapter<Ignite
         CacheOperationGate opGate = onEnter();
 
         try {
-            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.setApplicationAttributes(appAttrs), lock);
+            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.withApplicationAttributes(appAttrs), lock);
         }
         finally {
             onLeave(opGate);
@@ -197,7 +197,7 @@ public class GatewayProtectedCacheProxy<K, V> extends 
AsyncSupportAdapter<Ignite
             if (noRetries)
                 return this;
 
-            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.setNoRetries(true), lock);
+            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.withNoRetries(), lock);
         }
         finally {
             onLeave(opGate);
@@ -214,7 +214,7 @@ public class GatewayProtectedCacheProxy<K, V> extends 
AsyncSupportAdapter<Ignite
             if (recovery)
                 return this;
 
-            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.setRecovery(true), lock);
+            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.withRecovery(), lock);
         }
         finally {
             onLeave(opGate);
@@ -244,7 +244,7 @@ public class GatewayProtectedCacheProxy<K, V> extends 
AsyncSupportAdapter<Ignite
             if (opCtx.readRepairStrategy() == strategy)
                 return this;
 
-            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.setReadRepairStrategy(strategy), lock);
+            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.withReadRepairStrategy(strategy), lock);
         }
         finally {
             onLeave(opGate);
@@ -261,7 +261,7 @@ public class GatewayProtectedCacheProxy<K, V> extends 
AsyncSupportAdapter<Ignite
         CacheOperationGate opGate = onEnter();
 
         try {
-            return new GatewayProtectedCacheProxy<>((IgniteCacheProxy<K1, 
V1>)delegate, opCtx.keepBinary(), lock);
+            return new GatewayProtectedCacheProxy<>((IgniteCacheProxy<K1, 
V1>)delegate, opCtx.withKeepBinary(), lock);
         }
         finally {
             onLeave(opGate);
@@ -278,7 +278,7 @@ public class GatewayProtectedCacheProxy<K, V> extends 
AsyncSupportAdapter<Ignite
             if (prevDataCenterId != null && dataCenterId == prevDataCenterId)
                 return this;
 
-            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.setDataCenterId(dataCenterId), lock);
+            return new GatewayProtectedCacheProxy<>(delegate, 
opCtx.withDataCenterId(dataCenterId), lock);
         }
         finally {
             onLeave(opGate);
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index d494e5df0df..f1e23417728 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -466,108 +466,48 @@ public abstract class GridCacheAdapter<K, V> implements 
IgniteInternalCache<K, V
     }
 
     /** {@inheritDoc} */
-    @Override public final GridCacheProxyImpl<K, V> setSkipStore(boolean 
skipStore) {
-        CacheOperationContext opCtx = new CacheOperationContext(
-            true,
-            false,
-            false,
-            null,
-            false,
-            null,
-            false,
-            null,
-            null,
-            false);
+    @Override public IgniteInternalCache<K, V> withSkipStore() {
+        CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+        opCtx = CacheOperationContext.of(opCtx).withSkipStore();
 
         return new GridCacheProxyImpl<>(ctx, this, opCtx);
     }
 
     /** {@inheritDoc} */
     @Override public IgniteInternalCache<K, V> withSkipReadThrough() {
-        CacheOperationContext opCtx = this.ctx.operationContextPerCall();
+        CacheOperationContext opCtx = ctx.operationContextPerCall();
 
-        if (opCtx == null) {
-            opCtx = new CacheOperationContext(
-                false,
-                true,
-                false,
-                null,
-                false,
-                null,
-                false,
-                null,
-                null,
-                false);
-        }
-        else
-            opCtx = opCtx.withSkipReadThrough();
+        opCtx = CacheOperationContext.of(opCtx).withSkipReadThrough();
+
+        return new GridCacheProxyImpl<>(ctx, this, opCtx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache<K, V> withKeepBinaryInInterceptor() {
+        CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+        opCtx = CacheOperationContext.of(opCtx).withKeepBinaryInInterceptor();
 
-        return new GridCacheProxyImpl<>(this.ctx, this, opCtx);
+        return new GridCacheProxyImpl<>(ctx, this, opCtx);
     }
 
     /** @return New internal cache instance based on this one, but with 
application attributes. */
     @Override public GridCacheProxyImpl<K, V> 
withApplicationAttributes(Map<String, String> attrs) {
         CacheOperationContext opCtx = ctx.operationContextPerCall();
 
-        if (opCtx == null) {
-            opCtx = new CacheOperationContext(
-                false,
-                false,
-                false,
-                null,
-                false,
-                null,
-                false,
-                null,
-                new HashMap<>(attrs),
-                false);
-        }
-        else
-            opCtx = opCtx.withApplicationAttributes(attrs);
+        opCtx = 
CacheOperationContext.of(opCtx).withApplicationAttributes(attrs);
 
         return new GridCacheProxyImpl<>(ctx, this, opCtx);
     }
 
     /** {@inheritDoc} */
     @Override public final <K1, V1> GridCacheProxyImpl<K1, V1> keepBinary() {
-        CacheOperationContext opCtx = new CacheOperationContext(
-            false,
-            false,
-            true,
-            null,
-            false,
-            null,
-            false,
-            null,
-            null,
-            false);
+        CacheOperationContext opCtx = 
CacheOperationContext.builder().keepBinary(true).keepBinaryInInterceptor(false).build();
 
         return new GridCacheProxyImpl<>((GridCacheContext<K1, V1>)ctx, 
(GridCacheAdapter<K1, V1>)this, opCtx);
     }
 
-    /** {@inheritDoc} */
-    @Override public GridCacheProxyImpl<K, V> withKeepBinaryInInterceptor() {
-        CacheOperationContext opCtx = this.ctx.operationContextPerCall();
-
-        if (opCtx == null) {
-            opCtx = new CacheOperationContext(
-                false,
-                false,
-                false,
-                null,
-                false,
-                null,
-                false,
-                null,
-                null,
-                true);
-        }
-        else
-            opCtx = opCtx.withKeepBinaryInInterceptor();
-
-        return new GridCacheProxyImpl<>(this.ctx, this, opCtx);
-    }
-
     /** {@inheritDoc} */
     @Nullable @Override public final ExpiryPolicy expiry() {
         return null;
@@ -577,34 +517,16 @@ public abstract class GridCacheAdapter<K, V> implements 
IgniteInternalCache<K, V
     @Override public final GridCacheProxyImpl<K, V> 
withExpiryPolicy(ExpiryPolicy plc) {
         assert !CU.isUtilityCache(ctx.name());
 
-        CacheOperationContext opCtx = new CacheOperationContext(
-            false,
-            false,
-            false,
-            plc,
-            false,
-            null,
-            false,
-            null,
-            null,
-            false);
+        CacheOperationContext opCtx = 
CacheOperationContext.builder().expiryPolicy(plc).build();
 
         return new GridCacheProxyImpl<>(ctx, this, opCtx);
     }
 
     /** {@inheritDoc} */
     @Override public final IgniteInternalCache<K, V> withNoRetries() {
-        CacheOperationContext opCtx = new CacheOperationContext(
-            false,
-            false,
-            false,
-            null,
-            true,
-            null,
-            false,
-            null,
-            null,
-            false);
+        CacheOperationContext opCtx = ctx.operationContextPerCall();
+
+        opCtx = CacheOperationContext.of(opCtx).withNoRetries();
 
         return new GridCacheProxyImpl<>(ctx, this, opCtx);
     }
@@ -4507,7 +4429,7 @@ public abstract class GridCacheAdapter<K, V> implements 
IgniteInternalCache<K, V
             @Override public Boolean call() throws IgniteCheckedException {
                 CacheOperationContext prevOpCtx = 
ctx.operationContextPerCall();
 
-                ctx.operationContextPerCall(opCtx.keepBinary());
+                ctx.operationContextPerCall(opCtx.withKeepBinary());
 
                 try {
                     return invoke((K)key, new 
AtomicReadRepairEntryProcessor<>(correctedVal, primVer)).get();
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
index 82ac5cf606e..0e335e063f5 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProxyImpl.java
@@ -31,7 +31,6 @@ import javax.cache.processor.EntryProcessor;
 import javax.cache.processor.EntryProcessorResult;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.CacheEntry;
-import org.apache.ignite.cache.CacheInterceptor;
 import org.apache.ignite.cache.CacheMetrics;
 import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.cache.affinity.Affinity;
@@ -252,26 +251,13 @@ public class GridCacheProxyImpl<K, V> implements 
IgniteInternalCache<K, V>, Exte
     }
 
     /** {@inheritDoc} */
-    @Override public GridCacheProxyImpl<K, V> setSkipStore(boolean skipStore) {
+    @Override public GridCacheProxyImpl<K, V> withSkipStore() {
         CacheOperationContext prev = gate.enter(opCtx);
 
         try {
-            if (opCtx != null && opCtx.skipStore() == skipStore)
-                return this;
+            CacheOperationContext newOpCtx = 
CacheOperationContext.of(opCtx).withSkipStore();
 
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                opCtx != null ? opCtx.setSkipStore(skipStore) :
-                    new CacheOperationContext(
-                        skipStore,
-                        false,
-                        false,
-                        null,
-                        false,
-                        null,
-                        false,
-                        null,
-                        null,
-                        false));
+            return newOpCtx == opCtx ? this : new GridCacheProxyImpl<>(ctx, 
delegate, newOpCtx);
         }
         finally {
             gate.leave(prev);
@@ -283,22 +269,9 @@ public class GridCacheProxyImpl<K, V> implements 
IgniteInternalCache<K, V>, Exte
         CacheOperationContext prev = gate.enter(opCtx);
 
         try {
-            if (opCtx != null && opCtx.skipReadThrough())
-                return this;
+            CacheOperationContext newOpCtx = 
CacheOperationContext.of(opCtx).withSkipReadThrough();
 
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                opCtx != null ? opCtx.withSkipReadThrough() :
-                    new CacheOperationContext(
-                        false,
-                        true,
-                        false,
-                        null,
-                        false,
-                        null,
-                        false,
-                        null,
-                        null,
-                        false));
+            return newOpCtx == opCtx ? this : new GridCacheProxyImpl<>(ctx, 
delegate, newOpCtx);
         }
         finally {
             gate.leave(prev);
@@ -309,20 +282,15 @@ public class GridCacheProxyImpl<K, V> implements 
IgniteInternalCache<K, V>, Exte
     @Override public GridCacheProxyImpl<K, V> 
withApplicationAttributes(Map<String, String> attrs) {
         CacheOperationContext prev = gate.enter(opCtx);
 
+        CacheOperationContext newOpCtx;
+
         try {
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                opCtx != null ? opCtx.setApplicationAttributes(attrs) :
-                    new CacheOperationContext(
-                        false,
-                        false,
-                        false,
-                        null,
-                        false,
-                        null,
-                        false,
-                        null,
-                        attrs,
-                        false));
+            if (opCtx != null)
+                newOpCtx = opCtx.withApplicationAttributes(attrs);
+            else
+                newOpCtx = 
CacheOperationContext.builder().applicationAttributes(attrs).build();
+
+            return new GridCacheProxyImpl<>(ctx, delegate, newOpCtx);
         }
         finally {
             gate.leave(prev);
@@ -331,22 +299,17 @@ public class GridCacheProxyImpl<K, V> implements 
IgniteInternalCache<K, V>, Exte
 
     /** {@inheritDoc} */
     @Override public <K1, V1> GridCacheProxyImpl<K1, V1> keepBinary() {
-        if (opCtx != null && opCtx.isKeepBinary())
-            return (GridCacheProxyImpl<K1, V1>)this;
+        CacheOperationContext prev = gate.enter(opCtx);
+
+        try {
+            CacheOperationContext newOpCtx = 
CacheOperationContext.of(opCtx).withKeepBinary();
 
-        return new GridCacheProxyImpl<>((GridCacheContext<K1, V1>)ctx,
-            (GridCacheAdapter<K1, V1>)delegate,
-            opCtx != null ? opCtx.keepBinary() :
-                new CacheOperationContext(false,
-                    false,
-                    true,
-                    null,
-                    false,
-                    null,
-                    false,
-                    null,
-                    null,
-                    false));
+            return newOpCtx == opCtx ? (GridCacheProxyImpl<K1, V1>)this : new 
GridCacheProxyImpl<>((GridCacheContext<K1, V1>)ctx,
+                (GridCacheAdapter<K1, V1>)delegate, newOpCtx);
+        }
+        finally {
+            gate.leave(prev);
+        }
     }
 
     /** {@inheritDoc} */
@@ -1585,46 +1548,29 @@ public class GridCacheProxyImpl<K, V> implements 
IgniteInternalCache<K, V>, Exte
     @Override public GridCacheProxyImpl<K, V> withExpiryPolicy(ExpiryPolicy 
plc) {
         CacheOperationContext prev = gate.enter(opCtx);
 
+        CacheOperationContext newOpCtx;
+
         try {
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                opCtx != null ? opCtx.withExpiryPolicy(plc) :
-                    new CacheOperationContext(
-                        false,
-                        false,
-                        false,
-                        plc,
-                        false,
-                        null,
-                        false,
-                        null,
-                        null,
-                        false));
+            if (opCtx != null)
+                newOpCtx = opCtx.withExpiryPolicy(plc);
+            else
+                newOpCtx = 
CacheOperationContext.builder().expiryPolicy(plc).build();
+
+            return new GridCacheProxyImpl<>(ctx, delegate, newOpCtx);
         }
         finally {
             gate.leave(prev);
         }
     }
 
-    /**
-     * @return Cache with handle binary values during {@link CacheInterceptor} 
execution flag.
-     */
-    @Override public IgniteInternalCache<K, V> withKeepBinaryInInterceptor() {
+    /** {@inheritDoc} */
+    @Override public IgniteInternalCache<K, V> withNoRetries() {
         CacheOperationContext prev = gate.enter(opCtx);
 
         try {
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                opCtx != null ? opCtx.withKeepBinaryInInterceptor() :
-                    new CacheOperationContext(
-                        false,
-                        false,
-                        false,
-                        null,
-                        false,
-                        null,
-                        false,
-                        null,
-                        null,
-                        true));
+            CacheOperationContext newOpCtx = 
CacheOperationContext.of(opCtx).withNoRetries();
+
+            return newOpCtx == opCtx ? this : new GridCacheProxyImpl<>(ctx, 
delegate, newOpCtx);
         }
         finally {
             gate.leave(prev);
@@ -1632,22 +1578,13 @@ public class GridCacheProxyImpl<K, V> implements 
IgniteInternalCache<K, V>, Exte
     }
 
     /** {@inheritDoc} */
-    @Override public IgniteInternalCache<K, V> withNoRetries() {
+    @Override public IgniteInternalCache<K, V> withKeepBinaryInInterceptor() {
         CacheOperationContext prev = gate.enter(opCtx);
 
         try {
-            return new GridCacheProxyImpl<>(ctx, delegate,
-                new CacheOperationContext(
-                    false,
-                    false,
-                    false,
-                    null,
-                    true,
-                    null,
-                    false,
-                    null,
-                    null,
-                    false));
+            CacheOperationContext newOpCtx = 
CacheOperationContext.of(opCtx).withKeepBinaryInInterceptor();
+
+            return newOpCtx == opCtx ? this : new GridCacheProxyImpl<>(ctx, 
delegate, newOpCtx);
         }
         finally {
             gate.leave(prev);
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
index 629bb9433cb..2ab4e3d990a 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxyImpl.java
@@ -272,7 +272,7 @@ public class IgniteCacheProxyImpl<K, V> extends 
AsyncSupportAdapter<IgniteCache<
 
     /** {@inheritDoc} */
     @Override public IgniteCacheProxy<K, V> cacheNoGate() {
-        return new GatewayProtectedCacheProxy<>(this, new 
CacheOperationContext(), false);
+        return new GatewayProtectedCacheProxy<>(this, 
CacheOperationContext.instance(), false);
     }
 
     /**
@@ -282,7 +282,7 @@ public class IgniteCacheProxyImpl<K, V> extends 
AsyncSupportAdapter<IgniteCache<
         if (cachedProxy != null)
             return cachedProxy;
 
-        cachedProxy = new GatewayProtectedCacheProxy<>(this, new 
CacheOperationContext(), true);
+        cachedProxy = new GatewayProtectedCacheProxy<>(this, 
CacheOperationContext.instance(), true);
 
         return cachedProxy;
     }
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
index 678a8227f41..0dd481067fe 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteInternalCache.java
@@ -223,10 +223,9 @@ public interface IgniteInternalCache<K, V> extends 
Iterable<Cache.Entry<K, V>> {
     public boolean skipStore();
 
     /**
-     * @param skipStore Skip store flag.
      * @return New internal cache instance based on this one, but with skip 
store flag enabled.
      */
-    public IgniteInternalCache<K, V> setSkipStore(boolean skipStore);
+    public IgniteInternalCache<K, V> withSkipStore();
 
     /** @return New internal cache instance based on this one, but with skip 
read-through cache store flag enabled. */
     public IgniteInternalCache<K, V> withSkipReadThrough();
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
index 08da8d8af2d..56cc6e1e0bb 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
@@ -742,7 +742,7 @@ public abstract class GridDhtTransactionalCacheAdapter<K, 
V> extends GridDhtCach
             accessTtl,
             opCtx != null && opCtx.skipStore(),
             opCtx != null && opCtx.skipReadThrough(),
-            opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+            opCtx != null && opCtx.keepBinaryInInterceptor(),
             opCtx != null && opCtx.isKeepBinary());
     }
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 0bc90070925..a214cba09be 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -288,7 +288,8 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
                     AtomicApplicationAttributesAwareRequest req
                 ) {
                     if (req.applicationAttributes() != null)
-                        ctx.operationContextPerCall(new 
CacheOperationContext().setApplicationAttributes(req.applicationAttributes()));
+                        
ctx.operationContextPerCall(CacheOperationContext.builder().applicationAttributes(req.applicationAttributes())
+                            .build());
 
                     try {
                         processNearAtomicUpdateRequest(nodeId, req.payload());
@@ -1062,7 +1063,7 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
 
         final CacheOperationContext opCtx = ctx.operationContextPerCall();
 
-        if (opCtx != null && opCtx.hasDataCenterId()) {
+        if (opCtx != null && opCtx.dataCenterId() != null) {
             assert conflictPutVals == null : conflictPutVals;
             assert conflictRmvVals == null : conflictRmvVals;
 
@@ -1112,7 +1113,7 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
             opCtx != null && opCtx.recovery(),
             opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
             opCtx != null ? opCtx.applicationAttributes() : null,
-            opCtx != null && opCtx.isKeepBinaryInInterceptor());
+            opCtx != null && opCtx.keepBinaryInInterceptor());
 
         if (async) {
             return asyncOp(new CO<IgniteInternalFuture<Object>>() {
@@ -1255,7 +1256,7 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
         GridCacheDrInfo conflictPutVal = null;
         GridCacheVersion conflictRmvVer = null;
 
-        if (opCtx != null && opCtx.hasDataCenterId()) {
+        if (opCtx != null && opCtx.dataCenterId() != null) {
             Byte dcId = opCtx.dataCenterId();
 
             assert dcId != null;
@@ -1301,7 +1302,7 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
                 opCtx != null && opCtx.recovery(),
                 opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
                 opCtx != null ? opCtx.applicationAttributes() : null,
-                opCtx != null && opCtx.isKeepBinaryInInterceptor()
+                opCtx != null && opCtx.keepBinaryInInterceptor()
             );
         }
         else {
@@ -1325,7 +1326,7 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
                 opCtx != null && opCtx.recovery(),
                 opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
                 opCtx != null ? opCtx.applicationAttributes() : null,
-                opCtx != null && opCtx.isKeepBinaryInInterceptor());
+                opCtx != null && opCtx.keepBinaryInInterceptor());
         }
     }
 
@@ -1355,7 +1356,7 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
 
         Collection<GridCacheVersion> drVers = null;
 
-        if (opCtx != null && keys != null && opCtx.hasDataCenterId()) {
+        if (opCtx != null && keys != null && opCtx.dataCenterId() != null) {
             assert conflictMap == null : conflictMap;
 
             drVers = F.transform(keys, new C1<K, GridCacheVersion>() {
@@ -1385,7 +1386,7 @@ public class GridDhtAtomicCache<K, V> extends 
GridDhtCacheAdapter<K, V> {
             opCtx != null && opCtx.recovery(),
             opCtx != null && opCtx.noRetries() ? 1 : MAX_RETRIES,
             opCtx != null ? opCtx.applicationAttributes() : null,
-            opCtx != null && opCtx.isKeepBinaryInInterceptor());
+            opCtx != null && opCtx.keepBinaryInInterceptor());
 
         if (async) {
             return asyncOp(new CO<IgniteInternalFuture<Object>>() {
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
index 47fa5e70a41..21aa24e1608 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridNearAtomicAbstractUpdateFuture.java
@@ -917,7 +917,7 @@ public abstract class GridNearAtomicAbstractUpdateFuture 
extends GridCacheFuture
             CacheOperationContext prevOpCtx = cctx.operationContextPerCall();
 
             if (appAttrs != null)
-                cctx.operationContextPerCall(new 
CacheOperationContext().setApplicationAttributes(appAttrs));
+                
cctx.operationContextPerCall(CacheOperationContext.builder().applicationAttributes(appAttrs).build());
 
             try {
                 apply0(req, res);
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
index af7f997899e..68b89011bbc 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/colocated/GridDhtColocatedCache.java
@@ -205,7 +205,7 @@ public class GridDhtColocatedCache<K, V> extends 
GridDhtTransactionalCacheAdapte
                         false,
                         opCtx != null && opCtx.skipStore(),
                         opCtx != null && opCtx.skipReadThrough(),
-                        opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+                        opCtx != null && opCtx.keepBinaryInInterceptor(),
                         recovery,
                         readRepairStrategy,
                         needVer);
@@ -309,7 +309,7 @@ public class GridDhtColocatedCache<K, V> extends 
GridDhtTransactionalCacheAdapte
                         false,
                         opCtx != null && opCtx.skipStore(),
                         opCtx != null && opCtx.skipReadThrough(),
-                        opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+                        opCtx != null && opCtx.keepBinaryInInterceptor(),
                         recovery,
                         readRepairStrategy,
                         needVer);
@@ -663,7 +663,7 @@ public class GridDhtColocatedCache<K, V> extends 
GridDhtTransactionalCacheAdapte
             accessTtl,
             opCtx != null && opCtx.skipStore(),
             opCtx != null && opCtx.skipReadThrough(),
-            opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+            opCtx != null && opCtx.keepBinaryInInterceptor(),
             opCtx != null && opCtx.isKeepBinary(),
             opCtx != null && opCtx.recovery());
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
index 7a631f090e3..d79cf19d9ce 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTransactionalCache.java
@@ -133,7 +133,7 @@ public class GridNearTransactionalCache<K, V> extends 
GridNearCacheAdapter<K, V>
 
         final boolean skipStore = opCtx != null && opCtx.skipStore();
         final boolean skipReadThrough = opCtx != null && 
opCtx.skipReadThrough();
-        boolean keepBinaryInInterceptor = opCtx != null && 
opCtx.isKeepBinaryInInterceptor();
+        boolean keepBinaryInInterceptor = opCtx != null && 
opCtx.keepBinaryInInterceptor();
 
         if (tx != null && !tx.implicit() && !skipTx) {
             return asyncOp(tx, new AsyncOp<Map<K, V>>(keys) {
@@ -309,7 +309,7 @@ public class GridNearTransactionalCache<K, V> extends 
GridNearCacheAdapter<K, V>
             accessTtl,
             opCtx != null && opCtx.skipStore(),
             opCtx != null && opCtx.skipReadThrough(),
-            opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+            opCtx != null && opCtx.keepBinaryInInterceptor(),
             opCtx != null && opCtx.isKeepBinary(),
             opCtx != null && opCtx.recovery());
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
index acd858e10f6..dffbf776c51 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearTxLocal.java
@@ -623,7 +623,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter 
implements GridTimeou
                 ret,
                 opCtx != null && opCtx.skipStore(),
                 opCtx != null && opCtx.skipReadThrough(),
-                opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+                opCtx != null && opCtx.keepBinaryInInterceptor(),
                 keepBinary,
                 opCtx != null && opCtx.recovery(),
                 dataCenterId);
@@ -751,7 +751,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter 
implements GridTimeou
 
         final Byte dataCenterId;
 
-        if (opCtx != null && opCtx.hasDataCenterId()) {
+        if (opCtx != null && opCtx.dataCenterId() != null) {
             assert drMap == null : drMap;
 
             dataCenterId = opCtx.dataCenterId();
@@ -800,7 +800,7 @@ public class GridNearTxLocal extends GridDhtTxLocalAdapter 
implements GridTimeou
                 null,
                 opCtx != null && opCtx.skipStore(),
                 opCtx != null && opCtx.skipReadThrough(),
-                opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+                opCtx != null && opCtx.keepBinaryInInterceptor(),
                 false,
                 keepBinary,
                 opCtx != null && opCtx.recovery(),
@@ -1633,7 +1633,7 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
 
         final Byte dataCenterId;
 
-        if (opCtx != null && opCtx.hasDataCenterId()) {
+        if (opCtx != null && opCtx.dataCenterId() != null) {
             assert drMap == null : drMap;
 
             dataCenterId = opCtx.dataCenterId();
@@ -1703,7 +1703,7 @@ public class GridNearTxLocal extends 
GridDhtTxLocalAdapter implements GridTimeou
             drMap,
             opCtx != null && opCtx.skipStore(),
             opCtx != null && opCtx.skipReadThrough(),
-            opCtx != null && opCtx.isKeepBinaryInInterceptor(),
+            opCtx != null && opCtx.keepBinaryInInterceptor(),
             singleRmv,
             keepBinary,
             opCtx != null && opCtx.recovery(),
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
index 0ca9467fbdb..3f1456e2155 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheQueueAdapter.java
@@ -433,18 +433,10 @@ public abstract class GridCacheQueueAdapter<T> extends 
AbstractCollection<T> imp
         if (opCtx != null && opCtx.isKeepBinary())
             return (GridCacheQueueAdapter<V1>)this;
 
-        opCtx = opCtx == null ? new CacheOperationContext(
-            false,
-            false,
-            true,
-            null,
-            false,
-            null,
-            false,
-            null,
-            null,
-            false)
-            : opCtx.keepBinary();
+        if (opCtx == null)
+            opCtx = CacheOperationContext.builder().keepBinary(true).build();
+        else
+            opCtx = opCtx.withKeepBinary();
 
         cctx.operationContextPerCall(opCtx);
 
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
index 669aa52dda5..8a50386849e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandler.java
@@ -751,8 +751,10 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
             destId == null || destId.equals(ctx.localNodeId()) || 
replicatedCacheAvailable(cacheName);
 
         if (locExec) {
-            IgniteInternalCache<?, ?> prj = localCache(cacheName)
-                .setSkipStore(cacheFlags.contains(SKIP_STORE));
+            IgniteInternalCache<?, ?> prj = localCache(cacheName);
+
+            if (cacheFlags.contains(SKIP_STORE))
+                prj = prj.withSkipStore();
 
             if (cacheFlags.contains(KEEP_BINARIES))
                 prj = prj.keepBinary();
@@ -919,8 +921,10 @@ public class GridCacheCommandHandler extends 
GridRestCommandHandlerAdapter {
 
         /** {@inheritDoc} */
         @Override public GridRestResponse call() throws Exception {
-            IgniteInternalCache<?, ?> prj = cache(g, cacheName)
-                .setSkipStore(cacheFlags.contains(SKIP_STORE));
+            IgniteInternalCache<?, ?> prj = cache(g, cacheName);
+
+            if (cacheFlags.contains(SKIP_STORE))
+                prj = prj.withSkipStore();
 
             if (cacheFlags.contains(KEEP_BINARIES))
                 prj = prj.keepBinary();
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
index f4e290d86c0..bb818a8e49f 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/processors/rest/handlers/cache/GridCacheCommandHandlerSelfTest.java
@@ -282,16 +282,6 @@ public class GridCacheCommandHandlerSelfTest extends 
GridCommonAbstractTest {
                             return fut;
                         }
 
-                        // Rewriting flagOn result to keep intercepting 
invocations after it.
-                        if ("setSkipStore".equals(mtd.getName()))
-                            return proxy;
-
-                        if ("forSubjectId".equals(mtd.getName()))
-                            return proxy;
-
-                        if ("keepBinary".equals(mtd.getName()))
-                            return proxy;
-
                         return mtd.invoke(cache, args);
                     }
                 });
diff --git 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java
 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java
index 3790c05f4af..08b7caf3887 100644
--- 
a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java
+++ 
b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/dml/DmlUtils.java
@@ -555,9 +555,9 @@ public class DmlUtils {
 
         if (opCtx == null)
             // Mimics behavior of GridCacheAdapter#keepBinary and 
GridCacheProxyImpl#keepBinary
-            newOpCtx = new CacheOperationContext(false, false, true, null, 
false, null, false, null, null, false);
+            newOpCtx = 
CacheOperationContext.builder().keepBinary(true).build();
         else if (!opCtx.isKeepBinary())
-            newOpCtx = opCtx.keepBinary();
+            newOpCtx = opCtx.withKeepBinary();
 
         if (newOpCtx != null)
             cctx.operationContextPerCall(newOpCtx);

Reply via email to