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;
}
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);
}
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);
}
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);
}
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);
}
}
}
Aggregations