Skip to content

Commit 4a08e2d

Browse files
committed
GG-21442: Improve QueryEntity field conflict message. This closes apache#310.
1 parent 8b693fe commit 4a08e2d

File tree

3 files changed

+24
-29
lines changed

3 files changed

+24
-29
lines changed

modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import org.apache.ignite.internal.util.typedef.internal.A;
4848
import org.apache.ignite.internal.util.typedef.internal.S;
4949
import org.apache.ignite.internal.util.typedef.internal.U;
50+
import org.jetbrains.annotations.NotNull;
5051

5152
/**
5253
* Query entity is a description of {@link org.apache.ignite.IgniteCache cache} entry (composed of key and value)
@@ -754,13 +755,10 @@ private static QueryEntity convert(QueryEntityTypeDescriptor desc) {
754755
* @return Type descriptor.
755756
*/
756757
private static QueryEntityTypeDescriptor processKeyAndValueClasses(
757-
Class<?> keyCls,
758-
Class<?> valCls
758+
@NotNull Class<?> keyCls,
759+
@NotNull Class<?> valCls
759760
) {
760-
QueryEntityTypeDescriptor d = new QueryEntityTypeDescriptor();
761-
762-
d.keyClass(keyCls);
763-
d.valueClass(valCls);
761+
QueryEntityTypeDescriptor d = new QueryEntityTypeDescriptor(keyCls, valCls);
764762

765763
processAnnotationsInClass(true, d.keyClass(), d, null);
766764
processAnnotationsInClass(false, d.valueClass(), d, null);

modules/core/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryEntityTypeDescriptor.java

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
3030
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
3131
import org.apache.ignite.internal.util.typedef.internal.S;
32+
import org.jetbrains.annotations.NotNull;
3233

3334
/**
3435
* Descriptor of type.
@@ -63,14 +64,25 @@ public class QueryEntityTypeDescriptor {
6364
private QueryEntityIndexDescriptor fullTextIdx;
6465

6566
/** */
66-
private Class<?> keyCls;
67+
private final Class<?> keyCls;
6768

6869
/** */
69-
private Class<?> valCls;
70+
private final Class<?> valCls;
7071

7172
/** */
7273
private boolean valTextIdx;
7374

75+
/**
76+
* Constructor.
77+
*
78+
* @param keyCls QueryEntity key class.
79+
* @param valCls QueryEntity value class.
80+
*/
81+
public QueryEntityTypeDescriptor(@NotNull Class<?> keyCls, @NotNull Class<?> valCls) {
82+
this.keyCls = keyCls;
83+
this.valCls = valCls;
84+
}
85+
7486
/**
7587
* @return Indexes.
7688
*/
@@ -138,31 +150,13 @@ public Class<?> valueClass() {
138150
return valCls;
139151
}
140152

141-
/**
142-
* Sets value class.
143-
*
144-
* @param valCls Value class.
145-
*/
146-
public void valueClass(Class<?> valCls) {
147-
this.valCls = valCls;
148-
}
149-
150153
/**
151154
* @return Key class.
152155
*/
153156
public Class<?> keyClass() {
154157
return keyCls;
155158
}
156159

157-
/**
158-
* Set key class.
159-
*
160-
* @param keyCls Key class.
161-
*/
162-
public void keyClass(Class<?> keyCls) {
163-
this.keyCls = keyCls;
164-
}
165-
166160
/**
167161
* Adds property to the type descriptor.
168162
*
@@ -171,8 +165,11 @@ public void keyClass(Class<?> keyCls) {
171165
* @param failOnDuplicate Fail on duplicate flag.
172166
*/
173167
public void addProperty(QueryEntityClassProperty prop, boolean key, boolean failOnDuplicate) {
174-
if (props.put(prop.name(), prop) != null && failOnDuplicate)
175-
throw new CacheException("Property with name '" + prop.name() + "' already exists.");
168+
if (props.put(prop.name(), prop) != null && failOnDuplicate) {
169+
throw new CacheException("Property with name '" + prop.name() + "' already exists for " +
170+
(key ? "key" : "value") + ": " +
171+
"QueryEntity [key=" + keyCls.getName() + ", value=" + valCls.getName() + ']');
172+
}
176173

177174
fields.put(prop.fullName(), prop.type());
178175

modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/AffinityKeyNameAndValueFieldNameConflictTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public void testAnnotationConfigCollision() throws Exception {
142142

143143
return null;
144144
}
145-
}, CacheException.class, "Property with name 'name' already exists.");
145+
}, CacheException.class, "Property with name 'name' already exists for value");
146146
}
147147

148148
/**

0 commit comments

Comments
 (0)