You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by kromulan <re...@tetryon.net> on 2015/11/10 09:40:18 UTC
Re: Indexing/Querying of child element fields.
Hi,
I've got another issue while using annotations. As seen in this example
below,
I have two embeddable types inside Person class. The problem seems that
names
are flattened out back to the main class. Even if I were to change names in
Embedded class, it would still clash as I have two of them in the main
class.
I wonder if there is an existing solution to this, because I failed to find
it.
*If not, is it going to be addressed any time soon* ? This is quite a
blocker for us.
Also would the following small patch I did be sufficient to fix the problem
(the diff is against
1.5 github branch). The patch simply prefixes properties with it's parent's
name.
==========================================================
Patch:
--- old/GridQueryProcessor.java 2015-11-10 09:37:28.328732300 +0100
+++ new/GridQueryProcessor.java 2015-11-10 09:44:01.637024700 +0100
@@ -1150,6 +1150,9 @@
if (!sqlAnn.name().isEmpty())
prop.name(sqlAnn.name());
+ if (null != prop.parent)
+ prop.name (prop.parent.name () + '.' + prop.name ());
+
if (sqlAnn.index()) {
String idxName = prop.name() + "_idx";
==========================================================
Test:
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.query.annotations.QuerySqlField;
import org.apache.ignite.configuration.CacheConfiguration;
import org.junit.BeforeClass;
import org.junit.Test;
public class IndexedTest
{
public static class Embedded
{
@QuerySqlField (name = "id")
private final long id;
@QuerySqlField (name = "name")
private final String name;
public Embedded (long id, String name)
{
this.id = id;
this.name = name;
}
}
public static class Person
{
@QuerySqlField (name = "id")
private final long id;
@QuerySqlField (name = "firstname")
private final String firstname;
@QuerySqlField (name = "lastname")
private final String lastname;
@QuerySqlField
private final Embedded embedded1;
@QuerySqlField
private final Embedded embedded2;
public long getId ()
{
return id;
}
public Person (long id, String firstname, String lastname, Embedded
embedded1, Embedded embedded2)
{
this.id = id;
this.firstname = firstname;
this.lastname = lastname;
this.embedded1 = embedded1;
this.embedded2 = embedded2;
}
}
@BeforeClass
public static void beforeClass ()
{
System.getProperties ().setProperty ("IGNITE_H2_DEBUG_CONSOLE", "true");
}
@Test
public void test1 ()
{
CacheConfiguration<Long, Person> cc;
Person person;
try (Ignite ignite = Ignition.start ())
{
cc = new CacheConfiguration<> ();
cc.setCacheMode (CacheMode.REPLICATED);
cc.setName (Person.class.getName ());
cc.setIndexedTypes (Long.class, Person.class);
IgniteCache<Long, Person> cache = ignite.getOrCreateCache (cc);
// We never get here.
person = new Person (1, "Name 1", "Lastname 1", new Embedded (10,
"Embedded 10"),
new Embedded (100, "Embedded 100"));
cache.put (person.getId (), person);
person = new Person (2, "Name 2", "Lastname 2", new Embedded (20,
"Embedded 20"),
new Embedded (200, "Embedded 200"));
cache.put (person.getId (), person);
person = new Person (3, "Name 3", "Lastname 3", new Embedded (20,
"Embedded 30"),
new Embedded (300, "Embedded 300"));
cache.put (person.getId (), person);
}
}
}
==========================================================
--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Indexing-Querying-of-child-element-fields-tp1704p1905.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.