ignite-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Artem Shutak <ashu...@gridgain.com>
Subject Re: Indexing/Querying of child element fields.
Date Wed, 28 Oct 2015 11:00:52 GMT
Hi,

You need just use @QuerySqlField (name = "unique_name").

See my example below.

    public static void main(String[] args) {
        try (Ignite ignite = Ignition.start(new IgniteConfiguration())) {
            CacheConfiguration<Integer, ProductSpecification> cc = new
CacheConfiguration<>("productSpecifications");

            cc.setIndexedTypes(
                Integer.class, ProductSpecification.class
            );

            IgniteCache<Integer, ProductSpecification> c =
ignite.getOrCreateCache(cc);

            CatalogValue v1 = new CatalogValue(13, "Catalog 13");
            CatalogValue v2 = new CatalogValue(-317, "Catalog -317");

            c.put(1, new ProductSpecification("spec1", v1));
            c.put(2, new ProductSpecification("spec2", v2));
            c.put(3, new ProductSpecification("spec3", v1));

            QueryCursor<List&lt;?>> q = c.query(
                new SqlFieldsQuery("select ps_id from ProductSpecification
ps where cv_id > 0"));

            for (List<?> objects : q)
                System.out.println(objects);
        }
    }

    public static class ProductSpecification implements Serializable {
        private static final long serialVersionUID = 0;

        @QuerySqlField (name = "ps_id")
        private String id;

        @QuerySqlField
        private CatalogValue characteristic;

        public ProductSpecification(String id, CatalogValue characteristic)
{
            this.id = id;
            this.characteristic = characteristic;
        }
    }

    public static class CatalogValue implements Serializable {
        private static final long serialVersionUID = 0;

        @QuerySqlField(index = true, name = "cv_id")
        private int id;

        private String name;

        public CatalogValue(int catalogId, String name) {
            this.id = catalogId;
            this.name = name;
        }
    }



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/Indexing-Querying-of-child-element-fields-tp1704p1738.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Mime
View raw message