Search in sources :

Example 11 with Organization

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

the class CacheContinuousQueryWithTransformerExample method populateCache.

/**
 * Populates cache with data.
 *
 * @param cache Organization cache.
 */
private static void populateCache(IgniteCache<Integer, Organization> cache) {
    Map<Integer, Organization> data = new HashMap<>();
    data.put(1, new Organization(// Name.
    "Microsoft", // Address.
    new Address("1096 Eddy Street, San Francisco, CA", 94109), // Type.
    OrganizationType.PRIVATE, // Last update time.
    new Timestamp(System.currentTimeMillis())));
    data.put(2, new Organization(// Name.
    "Red Cross", // Address.
    new Address("184 Fidler Drive, San Antonio, TX", 78205), // Type.
    OrganizationType.NON_PROFIT, // Last update time.
    new Timestamp(System.currentTimeMillis())));
    data.put(3, new Organization(// Name.
    "Apple", // Address.
    new Address("1 Infinite Loop, Cupertino, CA", 95014), // Type.
    OrganizationType.PRIVATE, // Last update time.
    new Timestamp(System.currentTimeMillis())));
    data.put(4, new Organization(// Name.
    "IBM", // Address.
    new Address("1 New Orchard Road Armonk, New York", 10504), // Type.
    OrganizationType.PRIVATE, // Last update time.
    new Timestamp(System.currentTimeMillis())));
    data.put(5, new Organization(// Name.
    "NASA Armstrong Flight Research Center", // Address.
    new Address("4800 Lilly Ave, Edwards, CA", 793523), // Type.
    OrganizationType.NON_PROFIT, // Last update time.
    new Timestamp(System.currentTimeMillis())));
    cache.putAll(data);
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Address(org.apache.ignite.examples.model.Address) HashMap(java.util.HashMap) Timestamp(java.sql.Timestamp)

Example 12 with Organization

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

the class CacheContinuousQueryWithTransformerExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws Exception If example execution failed.
 */
public static void main(String[] args) throws Exception {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        System.out.println();
        System.out.println(">>> Cache continuous query with transformer example started.");
        // Auto-close cache at the end of the example.
        try (IgniteCache<Integer, Organization> cache = ignite.getOrCreateCache(CACHE_NAME).withKeepBinary()) {
            // Create new continuous query with transformer.
            ContinuousQueryWithTransformer<Integer, Organization, String> qry = new ContinuousQueryWithTransformer<>();
            // Factory to create transformers.
            qry.setRemoteTransformerFactory(() -> {
                // Only this field will be sent over to a local node over the network.
                return event -> ((BinaryObject) event.getValue()).field("name");
            });
            // Listener that will receive transformed data.
            qry.setLocalListener(names -> {
                for (String name : names) System.out.println("New organization name: " + name);
            });
            // Execute query.
            try (QueryCursor<Cache.Entry<Integer, Organization>> cur = cache.query(qry)) {
                populateCache(cache);
                // Wait for a while while callback is notified about remaining puts.
                Thread.sleep(2000);
            }
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) Timestamp(java.sql.Timestamp) HashMap(java.util.HashMap) Ignite(org.apache.ignite.Ignite) ExampleNodeStartup(org.apache.ignite.examples.ExampleNodeStartup) Address(org.apache.ignite.examples.model.Address) IgniteCache(org.apache.ignite.IgniteCache) OrganizationType(org.apache.ignite.examples.model.OrganizationType) Ignition(org.apache.ignite.Ignition) Organization(org.apache.ignite.examples.model.Organization) Map(java.util.Map) QueryCursor(org.apache.ignite.cache.query.QueryCursor) Cache(javax.cache.Cache) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) ContinuousQueryWithTransformer(org.apache.ignite.cache.query.ContinuousQueryWithTransformer) Organization(org.apache.ignite.examples.model.Organization) BinaryObject(org.apache.ignite.binary.BinaryObject) Ignite(org.apache.ignite.Ignite)

Example 13 with Organization

use of org.apache.ignite.examples.model.Organization 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()));
        employeeCacheCfg.setKeyConfiguration(new CacheKeyConfiguration(EmployeeKey.class));
        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 fields query example.
            sqlFieldsQuery(binaryCache);
            // Run SQL query with join example.
            sqlJoinQuery(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) CacheKeyConfiguration(org.apache.ignite.cache.CacheKeyConfiguration) 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 14 with Organization

use of org.apache.ignite.examples.model.Organization 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)

Example 15 with Organization

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

the class SqlDmlExample method main.

/**
 * Executes example.
 *
 * @param args Command line arguments, none required.
 * @throws Exception If example execution failed.
 */
@SuppressWarnings({ "unused", "ThrowFromFinallyBlock" })
public static void main(String[] args) throws Exception {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        print("Cache query DML example started.");
        CacheConfiguration<Long, Organization> orgCacheCfg = new CacheConfiguration<>(ORG_CACHE);
        orgCacheCfg.setIndexedTypes(Long.class, Organization.class);
        CacheConfiguration<Long, Person> personCacheCfg = new CacheConfiguration<>(PERSON_CACHE);
        personCacheCfg.setIndexedTypes(Long.class, Person.class);
        // Auto-close cache at the end of the example.
        try (IgniteCache<Long, Organization> orgCache = ignite.getOrCreateCache(orgCacheCfg);
            IgniteCache<Long, Person> personCache = ignite.getOrCreateCache(personCacheCfg)) {
            insert(orgCache, personCache);
            select(personCache, "Insert data");
            update(personCache);
            select(personCache, "Update salary for Master degrees");
            delete(personCache);
            select(personCache, "Delete non-Apache employees");
        } finally {
            // Distributed cache could be removed from cluster only by #destroyCache() call.
            ignite.destroyCache(PERSON_CACHE);
            ignite.destroyCache(ORG_CACHE);
        }
        print("Cache query DML example finished.");
    }
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Ignite(org.apache.ignite.Ignite) Person(org.apache.ignite.examples.model.Person) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

Organization (org.apache.ignite.examples.model.Organization)17 Ignite (org.apache.ignite.Ignite)8 Timestamp (java.sql.Timestamp)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)7 Address (org.apache.ignite.examples.model.Address)7 Person (org.apache.ignite.examples.model.Person)6 HashMap (java.util.HashMap)4 BinaryObject (org.apache.ignite.binary.BinaryObject)4 AffinityKey (org.apache.ignite.cache.affinity.AffinityKey)4 Employee (org.apache.ignite.examples.model.Employee)2 EmployeeKey (org.apache.ignite.examples.model.EmployeeKey)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Cache (javax.cache.Cache)1 IgniteCache (org.apache.ignite.IgniteCache)1 Ignition (org.apache.ignite.Ignition)1 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)1 QueryEntity (org.apache.ignite.cache.QueryEntity)1