Search in sources :

Example 1 with Employee

use of org.apache.ignite.examples.model.Employee in project ignite by apache.

the class CacheClientBinaryQueryExample method createEmployeeQueryEntity.

/**
     * Create cache type metadata for {@link Employee}.
     *
     * @return Cache type metadata.
     */
private static QueryEntity createEmployeeQueryEntity() {
    QueryEntity employeeEntity = new QueryEntity();
    employeeEntity.setValueType(Employee.class.getName());
    employeeEntity.setKeyType(EmployeeKey.class.getName());
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("name", String.class.getName());
    fields.put("salary", Long.class.getName());
    fields.put("addr.zip", Integer.class.getName());
    fields.put("organizationId", Integer.class.getName());
    fields.put("addr.street", Integer.class.getName());
    employeeEntity.setFields(fields);
    employeeEntity.setIndexes(Arrays.asList(new QueryIndex("name"), new QueryIndex("salary"), new QueryIndex("addr.zip"), new QueryIndex("organizationId"), new QueryIndex("addr.street", QueryIndexType.FULLTEXT)));
    return employeeEntity;
}
Also used : Employee(org.apache.ignite.examples.model.Employee) EmployeeKey(org.apache.ignite.examples.model.EmployeeKey) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with Employee

use of org.apache.ignite.examples.model.Employee in project ignite by apache.

the class ComputeClientBinaryTaskExecutionExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     */
public static void main(String[] args) {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Binary objects task execution example started.");
        if (ignite.cluster().forRemotes().nodes().isEmpty()) {
            System.out.println();
            System.out.println(">>> This example requires remote nodes to be started.");
            System.out.println(">>> Please start at least 1 remote node.");
            System.out.println(">>> Refer to example's javadoc for details on configuration.");
            System.out.println();
            return;
        }
        // Generate employees to calculate average salary for.
        Collection<Employee> employees = employees();
        System.out.println();
        System.out.println(">>> Calculating average salary for employees:");
        for (Employee employee : employees) System.out.println(">>>     " + employee);
        // Convert collection of employees to collection of binary objects.
        // This allows to send objects across nodes without requiring to have
        // Employee class on classpath of these nodes.
        Collection<BinaryObject> binaries = ignite.binary().toBinary(employees);
        // Execute task and get average salary.
        Long avgSalary = ignite.compute(ignite.cluster().forRemotes()).execute(new ComputeClientTask(), binaries);
        System.out.println();
        System.out.println(">>> Average salary for all employees: " + avgSalary);
        System.out.println();
    }
}
Also used : Employee(org.apache.ignite.examples.model.Employee) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite)

Example 3 with Employee

use of org.apache.ignite.examples.model.Employee in project ignite by apache.

the class ComputeClientBinaryTaskExecutionExample method employees.

/**
     * Creates collection of employees.
     *
     * @return Collection of employees.
     */
private static Collection<Employee> employees() {
    Collection<Employee> employees = new ArrayList<>();
    employees.add(new Employee("James Wilson", 12500, new Address("1096 Eddy Street, San Francisco, CA", 94109), Arrays.asList("Human Resources", "Customer Service")));
    employees.add(new Employee("Daniel Adams", 11000, new Address("184 Fidler Drive, San Antonio, TX", 78205), Arrays.asList("Development", "QA")));
    employees.add(new Employee("Cristian Moss", 12500, new Address("667 Jerry Dove Drive, Florence, SC", 29501), Arrays.asList("Logistics")));
    employees.add(new Employee("Allison Mathis", 25300, new Address("2702 Freedom Lane, Hornitos, CA", 95325), Arrays.asList("Development")));
    employees.add(new Employee("Breana Robbin", 6500, new Address("3960 Sundown Lane, Austin, TX", 78758), Arrays.asList("Sales")));
    employees.add(new Employee("Philip Horsley", 19800, new Address("2803 Elsie Drive, Sioux Falls, SD", 57104), Arrays.asList("Sales")));
    employees.add(new Employee("Brian Peters", 10600, new Address("1407 Pearlman Avenue, Boston, MA", 12110), Arrays.asList("Development", "QA")));
    employees.add(new Employee("Jack Yang", 12900, new Address("4425 Parrish Avenue Smithsons Valley, TX", 78130), Arrays.asList("Sales")));
    return employees;
}
Also used : Employee(org.apache.ignite.examples.model.Employee) Address(org.apache.ignite.examples.model.Address) ArrayList(java.util.ArrayList)

Example 4 with Employee

use of org.apache.ignite.examples.model.Employee in project ignite by apache.

the class CacheClientBinaryQueryExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     */
public static void main(String[] args) {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Binary objects cache query example started.");
        CacheConfiguration<Integer, Organization> orgCacheCfg = new CacheConfiguration<>();
        orgCacheCfg.setCacheMode(CacheMode.PARTITIONED);
        orgCacheCfg.setName(ORGANIZATION_CACHE_NAME);
        orgCacheCfg.setQueryEntities(Arrays.asList(createOrganizationQueryEntity()));
        CacheConfiguration<EmployeeKey, Employee> employeeCacheCfg = new CacheConfiguration<>();
        employeeCacheCfg.setCacheMode(CacheMode.PARTITIONED);
        employeeCacheCfg.setName(EMPLOYEE_CACHE_NAME);
        employeeCacheCfg.setQueryEntities(Arrays.asList(createEmployeeQueryEntity()));
        try (IgniteCache<Integer, Organization> orgCache = ignite.getOrCreateCache(orgCacheCfg);
            IgniteCache<EmployeeKey, Employee> employeeCache = ignite.getOrCreateCache(employeeCacheCfg)) {
            if (ignite.cluster().forDataNodes(orgCache.getName()).nodes().isEmpty()) {
                System.out.println();
                System.out.println(">>> This example requires remote cache nodes to be started.");
                System.out.println(">>> Please start at least 1 remote cache node.");
                System.out.println(">>> Refer to example's javadoc for details on configuration.");
                System.out.println();
                return;
            }
            // Populate cache with sample data entries.
            populateCache(orgCache, employeeCache);
            // Get cache that will work with binary objects.
            IgniteCache<BinaryObject, BinaryObject> binaryCache = employeeCache.withKeepBinary();
            // Run SQL query example.
            sqlQuery(binaryCache);
            // Run SQL query with join example.
            sqlJoinQuery(binaryCache);
            // Run SQL fields query example.
            sqlFieldsQuery(binaryCache);
            // Run full text query example.
            textQuery(binaryCache);
            System.out.println();
        } finally {
            // Delete caches with their content completely.
            ignite.destroyCache(ORGANIZATION_CACHE_NAME);
            ignite.destroyCache(EMPLOYEE_CACHE_NAME);
        }
    }
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Employee(org.apache.ignite.examples.model.Employee) EmployeeKey(org.apache.ignite.examples.model.EmployeeKey) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Example 5 with Employee

use of org.apache.ignite.examples.model.Employee in project ignite by apache.

the class CacheClientBinaryQueryExample method populateCache.

/**
     * Populates cache with data.
     *
     * @param orgCache Organization cache.
     * @param employeeCache Employee cache.
     */
@SuppressWarnings("TypeMayBeWeakened")
private static void populateCache(IgniteCache<Integer, Organization> orgCache, IgniteCache<EmployeeKey, Employee> employeeCache) {
    orgCache.put(1, new Organization("GridGain", new Address("1065 East Hillsdale Blvd, Foster City, CA", 94404), OrganizationType.PRIVATE, new Timestamp(System.currentTimeMillis())));
    orgCache.put(2, new Organization("Microsoft", new Address("1096 Eddy Street, San Francisco, CA", 94109), OrganizationType.PRIVATE, new Timestamp(System.currentTimeMillis())));
    employeeCache.put(new EmployeeKey(1, 1), new Employee("James Wilson", 12500, new Address("1096 Eddy Street, San Francisco, CA", 94109), Arrays.asList("Human Resources", "Customer Service")));
    employeeCache.put(new EmployeeKey(2, 1), new Employee("Daniel Adams", 11000, new Address("184 Fidler Drive, San Antonio, TX", 78130), Arrays.asList("Development", "QA")));
    employeeCache.put(new EmployeeKey(3, 1), new Employee("Cristian Moss", 12500, new Address("667 Jerry Dove Drive, Florence, SC", 29501), Arrays.asList("Logistics")));
    employeeCache.put(new EmployeeKey(4, 2), new Employee("Allison Mathis", 25300, new Address("2702 Freedom Lane, San Francisco, CA", 94109), Arrays.asList("Development")));
    employeeCache.put(new EmployeeKey(5, 2), new Employee("Breana Robbin", 6500, new Address("3960 Sundown Lane, Austin, TX", 78130), Arrays.asList("Sales")));
    employeeCache.put(new EmployeeKey(6, 2), new Employee("Philip Horsley", 19800, new Address("2803 Elsie Drive, Sioux Falls, SD", 57104), Arrays.asList("Sales")));
    employeeCache.put(new EmployeeKey(7, 2), new Employee("Brian Peters", 10600, new Address("1407 Pearlman Avenue, Boston, MA", 12110), Arrays.asList("Development", "QA")));
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Employee(org.apache.ignite.examples.model.Employee) Address(org.apache.ignite.examples.model.Address) EmployeeKey(org.apache.ignite.examples.model.EmployeeKey) Timestamp(java.sql.Timestamp)

Aggregations

Employee (org.apache.ignite.examples.model.Employee)5 EmployeeKey (org.apache.ignite.examples.model.EmployeeKey)3 Ignite (org.apache.ignite.Ignite)2 BinaryObject (org.apache.ignite.binary.BinaryObject)2 Address (org.apache.ignite.examples.model.Address)2 Organization (org.apache.ignite.examples.model.Organization)2 Timestamp (java.sql.Timestamp)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1 QueryIndex (org.apache.ignite.cache.QueryIndex)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1