Search in sources :

Example 6 with Organization

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

the class CacheClientBinaryQueryExample method createOrganizationQueryEntity.

/**
 * Create cache type metadata for {@link Organization}.
 *
 * @return Cache type metadata.
 */
private static QueryEntity createOrganizationQueryEntity() {
    QueryEntity organizationEntity = new QueryEntity();
    organizationEntity.setValueType(Organization.class.getName());
    organizationEntity.setKeyType(Integer.class.getName());
    LinkedHashMap<String, String> fields = new LinkedHashMap<>();
    fields.put("name", String.class.getName());
    fields.put("address.street", String.class.getName());
    organizationEntity.setFields(fields);
    organizationEntity.setIndexes(Arrays.asList(new QueryIndex("name")));
    return organizationEntity;
}
Also used : Organization(org.apache.ignite.examples.model.Organization) QueryIndex(org.apache.ignite.cache.QueryIndex) QueryEntity(org.apache.ignite.cache.QueryEntity) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with Organization

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

the class CacheClientBinaryPutGetExample method putGetAll.

/**
 * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations.
 *
 * @param cache Cache.
 */
private static void putGetAll(IgniteCache<Integer, Organization> cache) {
    // Create new Organization binary objects to store in cache.
    Organization org1 = new Organization(// Name.
    "Microsoft", // Address.
    new Address("1096 Eddy Street, San Francisco, CA", 94109), // Type.
    OrganizationType.PRIVATE, // Last update time.
    new Timestamp(System.currentTimeMillis()));
    Organization org2 = 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()));
    Map<Integer, Organization> map = new HashMap<>();
    map.put(1, org1);
    map.put(2, org2);
    // Put created data entries to cache.
    cache.putAll(map);
    // Get recently created organizations as a strongly-typed fully de-serialized instances.
    Map<Integer, Organization> mapFromCache = cache.getAll(map.keySet());
    System.out.println();
    System.out.println(">>> Retrieved organization instances from cache:");
    for (Organization org : mapFromCache.values()) System.out.println(">>>     " + org);
}
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 8 with Organization

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

the class CacheClientBinaryPutGetExample method putGet.

/**
 * Execute individual put and get.
 *
 * @param cache Cache.
 */
private static void putGet(IgniteCache<Integer, Organization> cache) {
    // Create new Organization binary object to store in cache.
    Organization org = new Organization(// Name.
    "Microsoft", // Address.
    new Address("1096 Eddy Street, San Francisco, CA", 94109), // Type.
    OrganizationType.PRIVATE, // Last update time.
    new Timestamp(System.currentTimeMillis()));
    // Put created data entry to cache.
    cache.put(1, org);
    // Get recently created organization as a strongly-typed fully de-serialized instance.
    Organization orgFromCache = cache.get(1);
    System.out.println();
    System.out.println(">>> Retrieved organization instance from cache: " + orgFromCache);
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Address(org.apache.ignite.examples.model.Address) Timestamp(java.sql.Timestamp)

Example 9 with Organization

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

the class CacheClientBinaryPutGetExample method putGetAllBinary.

/**
 * Execute bulk {@code putAll(...)} and {@code getAll(...)} operations,
 * getting values in binary format, without de-serializing it.
 *
 * @param cache Cache.
 */
private static void putGetAllBinary(IgniteCache<Integer, Organization> cache) {
    // Create new Organization binary objects to store in cache.
    Organization org1 = new Organization(// Name.
    "Microsoft", // Address.
    new Address("1096 Eddy Street, San Francisco, CA", 94109), // Type.
    OrganizationType.PRIVATE, // Last update time.
    new Timestamp(System.currentTimeMillis()));
    Organization org2 = 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()));
    Map<Integer, Organization> map = new HashMap<>();
    map.put(1, org1);
    map.put(2, org2);
    // Put created data entries to cache.
    cache.putAll(map);
    // Get cache that will get values as binary objects.
    IgniteCache<Integer, BinaryObject> binaryCache = cache.withKeepBinary();
    // Get recently created organizations as binary objects.
    Map<Integer, BinaryObject> poMap = binaryCache.getAll(map.keySet());
    Collection<String> names = new ArrayList<>();
    // objects don't need to be fully deserialized).
    for (BinaryObject po : poMap.values()) names.add(po.<String>field("name"));
    System.out.println();
    System.out.println(">>> Retrieved organization names from binary objects: " + names);
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Address(org.apache.ignite.examples.model.Address) BinaryObject(org.apache.ignite.binary.BinaryObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Timestamp(java.sql.Timestamp)

Example 10 with Organization

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

the class CacheClientBinaryPutGetExample 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 put-get example started.");
        CacheConfiguration<Integer, Organization> cfg = new CacheConfiguration<>();
        cfg.setCacheMode(CacheMode.PARTITIONED);
        cfg.setName(CACHE_NAME);
        cfg.setAtomicityMode(CacheAtomicityMode.ATOMIC);
        try (IgniteCache<Integer, Organization> cache = ignite.getOrCreateCache(cfg)) {
            if (ignite.cluster().forDataNodes(cache.getName()).nodes().isEmpty()) {
                System.out.println();
                System.out.println(">>> This example requires remote cache node 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;
            }
            putGet(cache);
            putGetBinary(cache);
            putGetAll(cache);
            putGetAllBinary(cache);
            System.out.println();
        } finally {
            // Delete cache with its content completely.
            ignite.destroyCache(CACHE_NAME);
        }
    }
}
Also used : Organization(org.apache.ignite.examples.model.Organization) Ignite(org.apache.ignite.Ignite) 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