public static void main()

in content/Apache/Ignite/src/main/java/example/SqlExample.java [72:120]


    public static void main(String[] args) {
        IgniteConfiguration cfg = new IgniteConfiguration();
        try (Ignite ignite = Ignition.start(cfg)) {

            // tag::entity[]
            CacheConfiguration<Long, Customer> ccfg = new CacheConfiguration<>("customer");
            ccfg.setQueryEntities(Collections.singletonList(new QueryEntity(Long.class, Customer.class)));
            // end::entity[]
            IgniteCache<Long, Customer> cache = ignite.getOrCreateCache(ccfg);
            Customer client = new Customer(777200, "Jennifer Stain", "jenny@test.com", "+1-541-754-3010");
            System.out.println("Saving client " + client);
            cache.put(client.id, client);

            // tag::scan[]
            IgniteBiPredicate<Long, Customer> filter
                = (Long k, Customer v) -> v.email != null && v.email.contains("@test.com");

            try (QueryCursor<Cache.Entry<Long, Customer>> cursor
                     = cache.query(new ScanQuery<Long, Customer>().setFilter(filter))) {
                for (Cache.Entry<Long, Customer> entry : cursor.getAll())
                    System.out.println(entry.getValue().name + " " + entry.getValue().phoneNumber);
            }
            // end::scan[]

            // tag::query[]
            String phoneNum = "+1-541-754-3010";
            try (QueryCursor<Cache.Entry<Long, Customer>> qry
                     = cache.query(new SqlQuery<Long, Customer>(Customer.class, "where phoneNumber = ?")
                .setArgs(phoneNum))) {

                for (Cache.Entry<Long, Customer> entry : qry) {
                    Customer val = entry.getValue();
                    System.out.println("Customer found " + val);
                }
            }
            // end::query[]

            // tag::fields[]
            SqlFieldsQuery qry = new SqlFieldsQuery("select concat(name, ' <', email, '>') from Customer");

            // Execute query to get collection of rows. In this particular
            // case each row will have one element with full name formatted in Git-style
            Collection<List<?>> res = cache.query(qry).getAll();

            // Print names.
            System.out.println("Names of all customers:" + res);
            // end::fields[]
        }
    }