This is an automated email from the ASF dual-hosted git repository.
mpetrov 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 51e22861ee5 IGNITE-27791 Added char arrays support for IDTO code
generator (#12717)
51e22861ee5 is described below
commit 51e22861ee51d8ead534a0583d0dbcb28c808d71
Author: Mikhail Petrov <[email protected]>
AuthorDate: Tue Feb 10 18:42:59 2026 +0300
IGNITE-27791 Added char arrays support for IDTO code generator (#12717)
---
.../internal/idto/IDTOSerializerGenerator.java | 1 +
.../services/javax.annotation.processing.Processor | 1 +
.../apache/ignite/internal/util/IgniteUtils.java | 35 +++++++++++++++++
.../IgniteDataTransferObjectProcessorTest.java | 44 ++++++++++++++++++++++
.../internal/codegen/MessageProcessorTest.java | 16 ++++++--
.../ignite/testsuites/IgniteBasicTestSuite.java | 4 +-
.../codegen/idto/TestIgniteDataTransferObject.java | 31 +++++++++++++++
.../TestIgniteDataTransferObjectSerializer.java | 41 ++++++++++++++++++++
8 files changed, 168 insertions(+), 5 deletions(-)
diff --git
a/modules/codegen/src/main/java/org/apache/ignite/internal/idto/IDTOSerializerGenerator.java
b/modules/codegen/src/main/java/org/apache/ignite/internal/idto/IDTOSerializerGenerator.java
index ccb836b3b31..743e159cee5 100644
---
a/modules/codegen/src/main/java/org/apache/ignite/internal/idto/IDTOSerializerGenerator.java
+++
b/modules/codegen/src/main/java/org/apache/ignite/internal/idto/IDTOSerializerGenerator.java
@@ -145,6 +145,7 @@ public class IDTOSerializerGenerator {
{
ARRAY_TYPE_SERDES.put(byte.class.getName(), F.t("U.writeByteArray(out,
obj.${f});", "U.readByteArray(in)"));
+ ARRAY_TYPE_SERDES.put(char.class.getName(), F.t("U.writeCharArray(out,
obj.${f});", "U.readCharArray(in)"));
ARRAY_TYPE_SERDES.put(int.class.getName(), F.t("U.writeIntArray(out,
obj.${f});", "U.readIntArray(in)"));
ARRAY_TYPE_SERDES.put(long.class.getName(), F.t("U.writeLongArray(out,
obj.${f});", "U.readLongArray(in)"));
ARRAY_TYPE_SERDES.put(String.class.getName(), OBJ_ARRAY_SERDES);
diff --git
a/modules/codegen/src/main/resources/META-INF/services/javax.annotation.processing.Processor
b/modules/codegen/src/main/resources/META-INF/services/javax.annotation.processing.Processor
index ba066bcc8be..8c28704c8a1 100644
---
a/modules/codegen/src/main/resources/META-INF/services/javax.annotation.processing.Processor
+++
b/modules/codegen/src/main/resources/META-INF/services/javax.annotation.processing.Processor
@@ -1,2 +1,3 @@
org.apache.ignite.internal.MessageProcessor
org.apache.ignite.internal.systemview.SystemViewRowAttributeWalkerProcessor
+org.apache.ignite.internal.idto.IgniteDataTransferObjectProcessor
diff --git
a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 978698cb21e..c1ad82b1c63 100755
---
a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++
b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -3625,6 +3625,41 @@ public abstract class IgniteUtils extends CommonUtils {
return res;
}
+ /**
+ * @param out Output stream to write to.
+ * @param arr Array to write, possibly <tt>null</tt>.
+ * @throws IOException If write failed.
+ */
+ public static void writeCharArray(DataOutput out, char[] arr) throws
IOException {
+ if (arr == null)
+ out.writeInt(-1);
+ else {
+ out.writeInt(arr.length);
+
+ for (int c : arr)
+ out.writeChar(c);
+ }
+ }
+
+ /**
+ * @param in Stream to read from.
+ * @return Read char array, possibly <tt>null</tt>.
+ * @throws IOException If read failed.
+ */
+ public static char[] readCharArray(DataInput in) throws IOException {
+ int len = in.readInt();
+
+ if (len == -1)
+ return null; // Value "-1" indicates null.
+
+ char[] res = new char[len];
+
+ for (int i = 0; i < len; i++)
+ res[i] = in.readChar();
+
+ return res;
+ }
+
/**
* @param out Output.
* @param map Map to write.
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/codegen/IgniteDataTransferObjectProcessorTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/codegen/IgniteDataTransferObjectProcessorTest.java
new file mode 100644
index 00000000000..308b32ae131
--- /dev/null
+++
b/modules/core/src/test/java/org/apache/ignite/internal/codegen/IgniteDataTransferObjectProcessorTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.internal.codegen;
+
+import com.google.testing.compile.Compilation;
+import org.apache.ignite.internal.idto.IgniteDataTransferObjectProcessor;
+import org.junit.Test;
+
+import static com.google.testing.compile.CompilationSubject.assertThat;
+import static org.apache.ignite.internal.codegen.MessageProcessorTest.compile;
+import static org.apache.ignite.internal.codegen.MessageProcessorTest.javaFile;
+import static org.junit.Assert.assertEquals;
+
+/** */
+public class IgniteDataTransferObjectProcessorTest {
+ /** */
+ @Test
+ public void testProcessorGeneratesSerializer() {
+ Compilation compilation = compile(new
IgniteDataTransferObjectProcessor(), "idto/TestIgniteDataTransferObject.java");
+
+ assertThat(compilation).succeeded();
+
+ assertEquals(2, compilation.generatedSourceFiles().size());
+
+ assertThat(compilation)
+
.generatedSourceFile("org.apache.ignite.internal.TestIgniteDataTransferObjectSerializer")
+
.hasSourceEquivalentTo(javaFile("idto/TestIgniteDataTransferObjectSerializer.java"));
+ }
+}
diff --git
a/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java
b/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java
index f2611ca9e3c..e18ee07ffba 100644
---
a/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java
+++
b/modules/core/src/test/java/org/apache/ignite/internal/codegen/MessageProcessorTest.java
@@ -21,12 +21,14 @@ import java.io.File;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.processing.Processor;
import javax.tools.JavaFileObject;
import com.google.testing.compile.Compilation;
import com.google.testing.compile.Compiler;
import com.google.testing.compile.JavaFileObjects;
import org.apache.ignite.internal.MessageProcessor;
import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.util.CommonUtils;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.plugin.extensions.communication.Message;
@@ -270,6 +272,11 @@ public class MessageProcessorTest {
/** */
private Compilation compile(String... srcFiles) {
+ return compile(new MessageProcessor());
+ }
+
+ /** */
+ static Compilation compile(Processor proc, String... srcFiles) {
List<JavaFileObject> input = new ArrayList<>();
for (String srcFile: srcFiles)
@@ -278,20 +285,21 @@ public class MessageProcessorTest {
File igniteCoreJar = jarForClass(Message.class);
File igniteCodegenJar = jarForClass(Order.class);
File igniteBinaryApiJar = jarForClass(IgniteUuid.class);
+ File igniteCommonsJar = jarForClass(CommonUtils.class);
return Compiler.javac()
- .withClasspath(F.asList(igniteCoreJar, igniteCodegenJar,
igniteBinaryApiJar))
- .withProcessors(new MessageProcessor())
+ .withClasspath(F.asList(igniteCoreJar, igniteCodegenJar,
igniteBinaryApiJar, igniteCommonsJar))
+ .withProcessors(proc)
.compile(input);
}
/** */
- private JavaFileObject javaFile(String srcName) {
+ static JavaFileObject javaFile(String srcName) {
return JavaFileObjects.forResource("codegen/" + srcName);
}
/** */
- private File jarForClass(Class<?> clazz) {
+ private static File jarForClass(Class<?> clazz) {
try {
URI jar = clazz
.getProtectionDomain()
diff --git
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
index fbd490fb6b1..4bb13394dcf 100644
---
a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
+++
b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBasicTestSuite.java
@@ -36,6 +36,7 @@ import
org.apache.ignite.internal.GridStopWithCollisionSpiTest;
import org.apache.ignite.internal.IgniteLocalNodeMapBeforeStartTest;
import org.apache.ignite.internal.IgniteSlowClientDetectionSelfTest;
import org.apache.ignite.internal.TransactionsMXBeanImplTest;
+import
org.apache.ignite.internal.codegen.IgniteDataTransferObjectProcessorTest;
import org.apache.ignite.internal.codegen.MessageProcessorTest;
import
org.apache.ignite.internal.managers.communication.CacheEntryPredicateAdapterMessageTest;
import org.apache.ignite.internal.managers.communication.DefaultEnumMapperTest;
@@ -151,7 +152,8 @@ import org.junit.runners.Suite;
ErrorMessageSelfTest.class,
CacheEntryPredicateAdapterMessageTest.class,
DefaultEnumMapperTest.class,
- IndexKeyTypeMessageTest.class
+ IndexKeyTypeMessageTest.class,
+ IgniteDataTransferObjectProcessorTest.class,
})
public class IgniteBasicTestSuite {
}
diff --git
a/modules/core/src/test/resources/codegen/idto/TestIgniteDataTransferObject.java
b/modules/core/src/test/resources/codegen/idto/TestIgniteDataTransferObject.java
new file mode 100644
index 00000000000..afa32f42a3b
--- /dev/null
+++
b/modules/core/src/test/resources/codegen/idto/TestIgniteDataTransferObject.java
@@ -0,0 +1,31 @@
+/*
+ * 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.internal;
+
+import java.util.Arrays;
+import org.apache.ignite.internal.Order;
+import org.apache.ignite.internal.dto.IgniteDataTransferObject;
+import org.apache.ignite.internal.management.api.Argument;
+
+/** */
+public class TestIgniteDataTransferObject extends IgniteDataTransferObject {
+ /** */
+ @Order(0)
+ @Argument
+ char[] charArray;
+}
diff --git
a/modules/core/src/test/resources/codegen/idto/TestIgniteDataTransferObjectSerializer.java
b/modules/core/src/test/resources/codegen/idto/TestIgniteDataTransferObjectSerializer.java
new file mode 100644
index 00000000000..cd6eceabd89
--- /dev/null
+++
b/modules/core/src/test/resources/codegen/idto/TestIgniteDataTransferObjectSerializer.java
@@ -0,0 +1,41 @@
+ /*
+ * 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.internal;
+
+ import java.io.ObjectOutput;
+ import org.apache.ignite.internal.util.typedef.internal.U;
+ import java.io.ObjectInput;
+ import java.io.IOException;
+ import org.apache.ignite.internal.dto.IgniteDataTransferObjectSerializer;
+
+ /**
+ * This class is generated automatically.
+ *
+ * @see org.apache.ignite.internal.dto.IgniteDataTransferObject
+ */
+ public class TestIgniteDataTransferObjectSerializer implements
IgniteDataTransferObjectSerializer<TestIgniteDataTransferObject> {
+ /** {@inheritDoc} */
+ @Override public void writeExternal(TestIgniteDataTransferObject obj,
ObjectOutput out) throws IOException {
+ U.writeCharArray(out, obj.charArray);
+ }
+
+ /** {@inheritDoc} */
+ @Override public void readExternal(TestIgniteDataTransferObject obj,
ObjectInput in) throws IOException, ClassNotFoundException {
+ obj.charArray = U.readCharArray(in);
+ }
+ }