-
Notifications
You must be signed in to change notification settings - Fork 143
IGNITE-28426 Fix bug preventing SqlDdlGenerator from converting value classes with nested pojos annotated with SqlQueryField #7912
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| * 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.migrationtools.tests.models; | ||
|
|
||
| import java.util.Objects; | ||
| import org.apache.ignite.cache.query.annotations.QuerySqlField; | ||
|
|
||
| /** NestedPojoWithAnnotations. */ | ||
| public class NestedPojoWithAnnotations { | ||
| @QuerySqlField | ||
| private long id; | ||
|
|
||
| @QuerySqlField | ||
| private SimplePojo nestedPojo; | ||
|
|
||
| public NestedPojoWithAnnotations() { | ||
| // Intentionally left blank. | ||
| } | ||
|
|
||
| public NestedPojoWithAnnotations(long id, SimplePojo nestedObj) { | ||
| this.id = id; | ||
| this.nestedPojo = nestedObj; | ||
| } | ||
|
|
||
| public long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public SimplePojo getNestedPojo() { | ||
| return nestedPojo; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (!(o instanceof NestedPojoWithAnnotations)) { | ||
| return false; | ||
| } | ||
| NestedPojoWithAnnotations that = (NestedPojoWithAnnotations) o; | ||
| return id == that.id && Objects.equals(nestedPojo, that.nestedPojo); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(id, nestedPojo); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -388,6 +388,9 @@ private QueryEntityEvaluation populateQueryEntity(QueryEntity qe, boolean allowE | |
| } | ||
| } | ||
|
|
||
| // Tracks whether this QE maps a POJO on either Key/Value. | ||
| boolean mapsPojo = false; | ||
|
|
||
| // Go over existing fields in the QE to they are correct and there are not silly nulls. | ||
| { | ||
| // AI2 may define primitive field types, however, they still mark them as nullable somehow. | ||
|
|
@@ -430,6 +433,28 @@ private QueryEntityEvaluation populateQueryEntity(QueryEntity qe, boolean allowE | |
|
|
||
| // Mark keyFields as not nullable. | ||
| qe.getNotNullFields().addAll(qe.getKeyFields()); | ||
|
|
||
| // We also want to remove fields non-compliant with AI3 so that they are handled in the extra fields. | ||
| for (var e : qe.getFields().entrySet()) { | ||
| String fieldType = ClassnameUtils.ensureWrapper(e.getValue()); | ||
|
|
||
| boolean isNativelySupportedType; | ||
| try { | ||
| Class<?> type = ClassUtils.getClass(this.clientClassLoader, fieldType); | ||
| isNativelySupportedType = TypeInspector.isPrimitiveType(type); | ||
| } catch (ClassNotFoundException ignored) { | ||
| // All natively supported types should be in the classpath. | ||
| // Some enums might still slip throught. | ||
| isNativelySupportedType = false; | ||
| } | ||
|
|
||
| // Remove from the field list, we will need to map it in the extra fields. | ||
| if (!isNativelySupportedType) { | ||
| mapsPojo = true; | ||
| qe.getFields().remove(e.getKey()); | ||
| qe.getKeyFields().remove(e.getKey()); | ||
| } | ||
|
Comment on lines
+437
to
+456
|
||
| } | ||
| } | ||
|
|
||
| @Nullable Map<InspectedField, String> keyFieldToColumnMap; | ||
|
|
@@ -558,7 +583,7 @@ private Entry( | |
| } | ||
|
|
||
| // Empty field lists means that the class for the type is not available on the classpath so it must be a pojo. | ||
| boolean mapsPojo = keyFields.isEmpty() || valFields.isEmpty(); | ||
| mapsPojo = mapsPojo || keyFields.isEmpty() || valFields.isEmpty(); | ||
|
|
||
| // Process key fields | ||
| { | ||
|
|
@@ -583,7 +608,7 @@ private Entry( | |
|
|
||
| // Process value fields | ||
| { | ||
| if (valFields.size() == 1) { | ||
| if (valFields.size() == 1 && !mapsPojo) { | ||
| InspectedField inspectedField = valFields.get(0); | ||
| String columnName = valFieldToColumnMap.get(inspectedField); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,7 +133,13 @@ public static List<InspectedField> inspectType(Class<?> type) { | |
| } | ||
| } | ||
|
|
||
| private static boolean isPrimitiveType(Class<?> type) { | ||
| /** | ||
| * Whether the provided class, or it's derivatives, is natively supported. | ||
| * | ||
| * @param type Type. | ||
| * @return True or false. | ||
| */ | ||
|
Comment on lines
+136
to
+141
|
||
| public static boolean isPrimitiveType(Class<?> type) { | ||
| return type.isEnum() || Mapper.nativelySupported(type) || COL_TYPE_REF.containsKey(type); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "slip throught" should be "slip through".