You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ni...@apache.org on 2022/11/11 13:39:04 UTC
[ignite] 05/10: IGN-2745 .NET: RegisterSameJavaType mode for Scan Query
This is an automated email from the ASF dual-hosted git repository.
nizhikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git
commit 326b05ae533785e3e036a74c263b251d35896f5f
Author: Ижиков Николай Владимирович <NV...@sberbank.ru>
AuthorDate: Thu Feb 25 18:09:18 2021 +0300
IGN-2745 .NET: RegisterSameJavaType mode for Scan Query
(cherry picked from commit 5579994c4b542f2790c133a3c5dbc342b71b7cdf)
---
.../ignite/platform/PlatformDeployServiceTask.java | 29 ++++++++++
.../java/org/apache/ignite/platform/model/V13.java | 34 ++++++++++++
.../java/org/apache/ignite/platform/model/V14.java | 34 ++++++++++++
.../java/org/apache/ignite/platform/model/V15.java | 34 ++++++++++++
.../java/org/apache/ignite/platform/model/V16.java | 34 ++++++++++++
.../Apache.Ignite.Core.Tests/Services/Model.cs | 20 +++++++
.../Services/ServicesTypeAutoResolveTest.cs | 61 ++++++++++++++++++++++
.../Impl/Cache/Query/QueryCursorBase.cs | 38 ++++++++++++++
8 files changed, 284 insertions(+)
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java
index d76928b5964..eceb16d95ab 100644
--- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformDeployServiceTask.java
@@ -44,6 +44,7 @@ import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskAdapter;
import org.apache.ignite.compute.ComputeTaskSplitAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.IgniteEx;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.binary.BinaryArray;
@@ -63,6 +64,10 @@ import org.apache.ignite.platform.model.User;
import org.apache.ignite.platform.model.V10;
import org.apache.ignite.platform.model.V11;
import org.apache.ignite.platform.model.V12;
+import org.apache.ignite.platform.model.V13;
+import org.apache.ignite.platform.model.V14;
+import org.apache.ignite.platform.model.V15;
+import org.apache.ignite.platform.model.V16;
import org.apache.ignite.platform.model.V5;
import org.apache.ignite.platform.model.V6;
import org.apache.ignite.platform.model.V7;
@@ -691,6 +696,30 @@ public class PlatformDeployServiceTask extends ComputeTaskAdapter<String, Object
v12.put(1, new V12("1"));
v12.put(2, new V12("2"));
+
+ IgniteCache<Integer, V13> v13 = ignite.getOrCreateCache("V13");
+
+ v13.put(1, new V13("1"));
+ v13.put(2, new V13("2"));
+
+ IgniteCache<Integer, V14> v14 = ignite.getOrCreateCache("V14");
+
+ v14.put(1, new V14("1"));
+ v14.put(2, new V14("2"));
+
+ IgniteCache<Integer, V15> v15 = ignite.getOrCreateCache("V15");
+
+ v15.put(1, new V15("1"));
+ v15.put(2, new V15("2"));
+
+ CacheConfiguration<Integer, V16> ccfg = new CacheConfiguration<>("V16");
+
+ ccfg.setIndexedTypes(Integer.class, V16.class);
+
+ IgniteCache<Integer, V16> v16 = ignite.getOrCreateCache(ccfg);
+
+ v16.put(1, new V16("1"));
+ v16.put(2, new V16("2"));
}
/** */
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/model/V13.java b/modules/core/src/test/java/org/apache/ignite/platform/model/V13.java
new file mode 100644
index 00000000000..a82cd573dbf
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/model/V13.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.platform.model;
+
+/** Test V13 object. */
+public class V13 {
+ /** */
+ private final String name;
+
+ /** */
+ public V13(String name) {
+ this.name = name;
+ }
+
+ /** */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/model/V14.java b/modules/core/src/test/java/org/apache/ignite/platform/model/V14.java
new file mode 100644
index 00000000000..075c2430cd9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/model/V14.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.platform.model;
+
+/** Test V14 object. */
+public class V14 {
+ /** */
+ private final String name;
+
+ /** */
+ public V14(String name) {
+ this.name = name;
+ }
+
+ /** */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/model/V15.java b/modules/core/src/test/java/org/apache/ignite/platform/model/V15.java
new file mode 100644
index 00000000000..b9a29f16a4f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/model/V15.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.platform.model;
+
+/** Test V15 object. */
+public class V15 {
+ /** */
+ private final String name;
+
+ /** */
+ public V15(String name) {
+ this.name = name;
+ }
+
+ /** */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/model/V16.java b/modules/core/src/test/java/org/apache/ignite/platform/model/V16.java
new file mode 100644
index 00000000000..bf70834d99e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/platform/model/V16.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.platform.model;
+
+/** Test V15 object. */
+public class V16 {
+ /** */
+ private final String name;
+
+ /** */
+ public V16(String name) {
+ this.name = name;
+ }
+
+ /** */
+ public String getName() {
+ return name;
+ }
+}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs
index 58bb4a37fd5..81debdbd92d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/Model.cs
@@ -241,4 +241,24 @@ namespace Apache.Ignite.Platform.Model
/// A class is a clone of Java class V12 with the same namespace.
/// </summary>
public class V12 { public String Name { get; set; } }
+
+ /// <summary>
+ /// A class is a clone of Java class V13 with the same namespace.
+ /// </summary>
+ public class V13 { public String Name { get; set; } }
+
+ /// <summary>
+ /// A class is a clone of Java class V14 with the same namespace.
+ /// </summary>
+ public class V14 { public String Name { get; set; } }
+
+ /// <summary>
+ /// A class is a clone of Java class V15 with the same namespace.
+ /// </summary>
+ public class V15 { public String Name { get; set; } }
+
+ /// <summary>
+ /// A class is a clone of Java class V16 with the same namespace.
+ /// </summary>
+ public class V16 { public String Name { get; set; } }
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs
index f2803c4bc42..bb6ffef2e6d 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Services/ServicesTypeAutoResolveTest.cs
@@ -25,6 +25,8 @@ namespace Apache.Ignite.Core.Tests.Services
using System.Net;
using System.Reflection;
using Apache.Ignite.Core.Binary;
+ using Apache.Ignite.Core.Cache;
+ using Apache.Ignite.Core.Cache.Query;
using Apache.Ignite.Core.Client;
using Apache.Ignite.Core.Log;
using Apache.Ignite.Core.Tests.Client.Cache;
@@ -317,6 +319,53 @@ namespace Apache.Ignite.Core.Tests.Services
else
Assert.AreEqual("2", entry.Value.Name);
}
+
+ var v13 = _grid1.GetCache<int, V13>("V13").Query(new ScanQuery<int, V13>()).GetAll();
+
+ Assert.AreEqual(2, v13.Count);
+
+ foreach (var entry in v13)
+ {
+ if (entry.Key == 1)
+ Assert.AreEqual("1", entry.Value.Name);
+ else
+ Assert.AreEqual("2", entry.Value.Name);
+ }
+
+ var v14 = _grid1.GetCache<int, V14>("V14").Query(new ScanQuery<int, V14>());
+
+ foreach (var entry in v14)
+ {
+ if (entry.Key == 1)
+ Assert.AreEqual("1", entry.Value.Name);
+ else
+ Assert.AreEqual("2", entry.Value.Name);
+ }
+
+ var v15 = _grid1.GetCache<int, V15>("V15")
+ .Query(new ScanQuery<int, V15>(new CacheEntryFilter())).GetAll();
+
+ Assert.AreEqual(1, v15.Count);
+
+ foreach (var entry in v15)
+ {
+ Assert.AreEqual("1", entry.Value.Name);
+ }
+
+ var v16 = _grid1.GetCache<int, V16>("V16").Query(new SqlFieldsQuery("SELECT _KEY, _VAL FROM V16"));
+
+ var cnt = 0;
+
+ foreach (var entry in v16)
+ {
+ cnt++;
+ if ((int) entry[0] == 1)
+ Assert.AreEqual("1", ((V16) entry[1]).Name);
+ else
+ Assert.AreEqual("2", ((V16) entry[1]).Name);
+ }
+
+ Assert.AreEqual(2, cnt);
}
/// <summary>
@@ -464,4 +513,16 @@ namespace Apache.Ignite.Core.Tests.Services
// No-op.
}
}
+
+ /// <summary>
+ /// Cache entry filter.
+ /// </summary>
+ class CacheEntryFilter : ICacheEntryFilter<int, V15>
+ {
+ /** <inheritDoc /> */
+ public bool Invoke(ICacheEntry<int, V15> entry)
+ {
+ return entry.Value.Name.Equals("1");
+ }
+ }
}
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/QueryCursorBase.cs b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/QueryCursorBase.cs
index 058027c1bf7..3e6244a2980 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/QueryCursorBase.cs
+++ b/modules/platforms/dotnet/Apache.Ignite.Core/Impl/Cache/Query/QueryCursorBase.cs
@@ -87,6 +87,11 @@ namespace Apache.Ignite.Core.Impl.Cache.Query
/** <inheritdoc /> */
public IList<T> GetAll()
+ {
+ return WithReg(() => GetAll0(), _keepBinary);
+ }
+
+ private IList<T> GetAll0()
{
if (_getAllCalled)
throw new InvalidOperationException("Failed to get all entries because GetAll() " +
@@ -257,6 +262,14 @@ namespace Apache.Ignite.Core.Impl.Cache.Query
/// <param name="stream">Stream.</param>
/// <returns>Result.</returns>
protected T[] ConvertGetBatch(IBinaryStream stream)
+ {
+ return WithReg(() => ConvertGetBatch0(stream), _keepBinary);
+ }
+
+ /// <summary>
+ /// Converter for GET_BATCH operation.
+ /// </summary>
+ private T[] ConvertGetBatch0(IBinaryStream stream)
{
var reader = _marsh.StartUnmarshal(stream, _keepBinary);
@@ -326,5 +339,30 @@ namespace Apache.Ignite.Core.Impl.Cache.Query
throw new ObjectDisposedException(GetType().Name, "Object has been disposed.");
}
}
+
+ /// <summary>
+ /// Enables Register Same Java Type mode is keepBinary = false.
+ /// </summary>
+ /// <param name="action">Action.</param>
+ /// <param name="keepBinary">Keep binary flag.</param>
+ /// <returns></returns>
+ private static TK WithReg<TK>(Func<TK> action, bool keepBinary)
+ {
+ if (keepBinary)
+ return action.Invoke();
+
+ bool locRegisterSameJavaType = Marshaller.RegisterSameJavaTypeTl.Value;
+
+ Marshaller.RegisterSameJavaTypeTl.Value = true;
+
+ try
+ {
+ return action.Invoke();
+ }
+ finally
+ {
+ Marshaller.RegisterSameJavaTypeTl.Value = locRegisterSameJavaType;
+ }
+ }
}
}