Skip to content

Commit

Permalink
IGN-2745 .NET: RegisterSameJavaType mode for Scan Query
Browse files Browse the repository at this point in the history
Merge in OSPT/ignite from IGN-2745 to master

Squashed commit of the following:

commit b0634120190db4f0c20dbbb92d7a047b8738bca8
Author: Nikolay Izhikov <nizhikov@apache.org>
Date:   Thu Feb 25 16:53:22 2021 +0300

    IGN-2745: RegisterSameJavaType mode for SQLFields Query.

commit af43837ec19bd5032284a625a469e707d893b124
Author: Nikolay Izhikov <nizhikov@apache.org>
Date:   Thu Feb 25 15:45:15 2021 +0300

    IGN-2745: RegisterSameJavaType mode for Scan Query.

commit 57289aabdb64b4d0306b84ebb47a48a88d525183
Author: Nikolay Izhikov <nizhikov@apache.org>
Date:   Thu Feb 25 15:40:14 2021 +0300

    IGN-2745: WIP.

IGN-2783 .NET: Compilation fix

Merge in OSPT/ignite from IGN-2783 to master

Squashed commit of the following:

commit 9ef10fb21dd887d23fbda1ae87b77d77d36aea93
Author: Nikolay Izhikov <nizhikov@apache.org>
Date:   Mon Mar 1 12:09:42 2021 +0300

    IGN-2783: Compilation fix.
  • Loading branch information
nizhikov committed Feb 22, 2022
1 parent 330ef81 commit 5579994
Show file tree
Hide file tree
Showing 8 changed files with 284 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.apache.ignite.compute.ComputeJobAdapter;
import org.apache.ignite.compute.ComputeJobResult;
import org.apache.ignite.compute.ComputeTaskAdapter;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.internal.IgniteInterruptedCheckedException;
import org.apache.ignite.internal.binary.BinaryArray;
import org.apache.ignite.internal.util.typedef.F;
Expand All @@ -57,6 +58,10 @@
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;
Expand Down Expand Up @@ -670,6 +675,30 @@ public void putValsForCache() {

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"));
}

/** */
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,24 @@ public class V11 { public String Name { get; set; } }
/// 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; } }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -317,6 +319,53 @@ private void DoTestService(IJavaService svc, bool isPlatform = false)
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>
Expand Down Expand Up @@ -464,4 +513,16 @@ public ServicesTypeAutoResolveTestBinaryArrays() : base(true)
// 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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ internal abstract class QueryCursorBase<T> : IQueryCursor<T>, IEnumerator<T>

/** <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() " +
Expand Down Expand Up @@ -257,6 +262,14 @@ protected IList<T> ConvertGetAll(IBinaryStream stream)
/// <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);

Expand Down Expand Up @@ -326,5 +339,30 @@ private void ThrowIfDisposed()
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;
}
}
}
}

0 comments on commit 5579994

Please sign in to comment.