Package com.hazelcast.query.SampleObjects

Examples of com.hazelcast.query.SampleObjects.Employee


            assertTrue(c.isActive());
        }
    }

    public static void doFunctionalQueryTest(IMap imap) {
        imap.put("1", new Employee("joe", 33, false, 14.56));
        imap.put("2", new Employee("ali", 23, true, 15.00));
        for (int i = 3; i < 103; i++) {
            imap.put(String.valueOf(i), new Employee("name" + i, i % 60, ((i & 1) == 1), Double.valueOf(i)));
        }
        Set<Map.Entry> entries = imap.entrySet();
        assertEquals(102, entries.size());
        int itCount = 0;
        for (Map.Entry entry : entries) {
            Employee c = (Employee) entry.getValue();
            itCount++;
        }
        assertEquals(102, itCount);
        EntryObject e = new PredicateBuilder().getEntryObject();
        Predicate predicate = e.is("active").and(e.get("age").equal(23));
        entries = imap.entrySet(predicate);
//        assertEquals(3, entries.size());
        for (Map.Entry entry : entries) {
            Employee c = (Employee) entry.getValue();
            assertEquals(c.getAge(), 23);
            assertTrue(c.isActive());
        }
        imap.remove("2");
        entries = imap.entrySet(predicate);
        assertEquals(2, entries.size());
        for (Map.Entry entry : entries) {
            Employee c = (Employee) entry.getValue();
            assertEquals(c.getAge(), 23);
            assertTrue(c.isActive());
        }
        entries = imap.entrySet(new SqlPredicate(" (age >= " + 30 + ") AND (age <= " + 40 + ")"));
        assertEquals(23, entries.size());
        for (Map.Entry entry : entries) {
            Employee c = (Employee) entry.getValue();
            assertTrue(c.getAge() >= 30);
            assertTrue(c.getAge() <= 40);
        }
    }
View Full Code Here


    public void testInvalidSqlPredicate() {
        Config cfg = new Config();
        TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(1);
        HazelcastInstance instance = nodeFactory.newHazelcastInstance(cfg);
        IMap map = instance.getMap("employee");
        map.put(1, new Employee("e", 1, false, 0));
        map.put(2, new Employee("e2", 1, false, 0));
        try {
            map.values(new SqlPredicate("invalid_sql"));
            fail("Should fail because of invalid SQL!");
        } catch (RuntimeException e) {
            assertTrue(e.getMessage().contains("There is no suitable accessor for 'invalid_sql'"));
View Full Code Here

        testMultipleOrPredicates(map);
    }

    private void testMultipleOrPredicates(IMap<Integer, SampleObjects.Employee> map) {
        for (int i = 0; i < 10; i++) {
            map.put(i, new Employee(i, "name" + i, "city" + i, i, true, i));
        }

        Collection<SampleObjects.Employee> values;

        values = map.values(new SqlPredicate("name = 'name1' OR name = 'name2' OR name LIKE 'name3'"));
View Full Code Here

        final HazelcastInstance instance = createHazelcastInstance();
        final IMap<Integer, SampleObjects.Employee> map = instance.getMap("default");

        map.addIndex("date", ordered);
        for (int i = 10; i >= 1; i--) {
            Employee employee = new Employee(i, "name-" + i, i, true, i * 100);
            if (i % 2 == 0) {
                employee.setDate(new Timestamp(i * 1000000));
            } else {
                employee.setDate(null);
            }
            map.put(i, employee);
        }

        final List<Long> dates = new ArrayList<Long>();
        for (SampleObjects.Employee employee : map.values(pred)) {
            dates.add(employee.getDate().getTime());
        }

        return dates;
    }
View Full Code Here

    public void testMapQuery() throws IOException {
        Set testSet = new HashSet();
        testSet.add("serra");
        testSet.add("met");
        final IMap map = getMap();
        map.put(1, new Employee("enes", 29, true, 100d));
        map.put(2, new Employee("serra", 3, true, 100d));
        map.put(3, new Employee("met", 7, true, 100d));
        MapQueryRequest request = new MapQueryRequest(mapName, new SqlPredicate("age < 10"), IterationType.VALUE);
        final SimpleClient client = getClient();
        client.send(request);
        Object receive = client.receive();
        QueryResultSet result = (QueryResultSet) receive;
        for (Object aResult : result) {
            Employee x = (Employee) TestUtil.toObject((Data) aResult);
            testSet.remove(x.getName());
        }
        assertEquals(0, testSet.size());
    }
View Full Code Here

                latch.countDown();
            }
        }, false);

        for (int i = 0; i < activeEmployees; i++) {
            Employee employee = new Employee("activeEmployee" + i, 60, true, Double.valueOf(i));
            imap.put("activeEmployee" + i, employee);
        }

        for (int i = 0; i < passiveEmployees; i++) {
            Employee employee = new Employee("passiveEmployee" + i, 60, false, Double.valueOf(i));
            imap.put("passiveEmployee" + i, employee);
        }

        //check the query result before eviction
        Collection values = imap.values(new SqlPredicate("active"));
View Full Code Here

        TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(4);
        HazelcastInstance h1 = nodeFactory.newHazelcastInstance();
        int count = 500;
        IMap imap = h1.getMap("employees");
        for (int i = 0; i < count; i++) {
            imap.put(String.valueOf(i), new Employee("joe" + i, i % 60, ((i & 1) == 1), (double) i));
        }

        HazelcastInstance h2 = nodeFactory.newHazelcastInstance();
        HazelcastInstance h3 = nodeFactory.newHazelcastInstance();
        HazelcastInstance h4 = nodeFactory.newHazelcastInstance();
View Full Code Here

        imap.addIndex("name", false);
        imap.addIndex("age", true);
        imap.addIndex("active", false);
        int size = 500;
        for (int i = 0; i < size; i++) {
            imap.put(String.valueOf(i), new Employee("joe" + i, i % 60, ((i & 1) == 1), (double) i));
        }

        HazelcastInstance h2 = nodeFactory.newHazelcastInstance(cfg);
        HazelcastInstance h3 = nodeFactory.newHazelcastInstance(cfg);
        HazelcastInstance h4 = nodeFactory.newHazelcastInstance(cfg);
View Full Code Here

        imap.addIndex("active", false);
        for (int i = 0; i < 50; i++) {
            Map temp = new HashMap(10);
            for (int j = 0; j < 10; j++) {
                String key = String.valueOf((i * 100000) + j);
                temp.put(key, new Employee("name" + key, i % 60, ((i & 1) == 1), (double) i));
            }
            imap.putAll(temp);
        }
        assertEquals(500, imap.size());
        Set<Map.Entry> entries = imap.entrySet(new SqlPredicate("active=true and age>44"));
View Full Code Here

        IMap imap = h1.getMap("employees");
        imap.addIndex("name", false);
        imap.addIndex("age", true);
        imap.addIndex("active", false);
        for (int i = 0; i < 500; i++) {
            Employee employee = new Employee(i, "name" + i % 100, "city" + (i % 100), i % 60, ((i & 1) == 1), (double) i);
            imap.put(String.valueOf(i), employee);
        }
        assertEquals(2, h1.getCluster().getMembers().size());
        assertEquals(2, h2.getCluster().getMembers().size());
        imap = h2.getMap("employees");
View Full Code Here

TOP

Related Classes of com.hazelcast.query.SampleObjects.Employee

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.