use of org.apache.ignite.examples.model.Organization in project ignite by apache.
the class CacheQueryDmlExample 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.");
}
}
use of org.apache.ignite.examples.model.Organization in project ignite by apache.
the class CacheClientBinaryPutGetExample method putGetBinary.
/**
* Execute individual put and get, getting value in binary format, without de-serializing it.
*
* @param cache Cache.
*/
private static void putGetBinary(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 cache that will get values as binary objects.
IgniteCache<Integer, BinaryObject> binaryCache = cache.withKeepBinary();
// Get recently created organization as a binary object.
BinaryObject po = binaryCache.get(1);
// Get organization's name from binary object (note that
// object doesn't need to be fully deserialized).
String name = po.field("name");
System.out.println();
System.out.println(">>> Retrieved organization name from binary object: " + name);
}
use of org.apache.ignite.examples.model.Organization in project ignite by apache.
the class PersistentStoreExample method main.
/**
* @param args Program arguments, ignored.
* @throws Exception If failed.
*/
public static void main(String[] args) throws Exception {
Ignition.setClientMode(true);
try (Ignite ignite = Ignition.start("examples/config/persistentstore/example-persistent-store.xml")) {
// Activate the cluster. Required to do if the persistent store is enabled because you might need
// to wait while all the nodes, that store a subset of data on disk, join the cluster.
ignite.active(true);
CacheConfiguration<Long, Organization> cacheCfg = new CacheConfiguration<>(ORG_CACHE);
cacheCfg.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
cacheCfg.setBackups(1);
cacheCfg.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
cacheCfg.setIndexedTypes(Long.class, Organization.class);
IgniteCache<Long, Organization> cache = ignite.getOrCreateCache(cacheCfg);
if (UPDATE) {
System.out.println("Populating the cache...");
try (IgniteDataStreamer<Long, Organization> streamer = ignite.dataStreamer(ORG_CACHE)) {
streamer.allowOverwrite(true);
for (long i = 0; i < 100_000; i++) {
streamer.addData(i, new Organization(i, "organization-" + i));
if (i > 0 && i % 10_000 == 0)
System.out.println("Done: " + i);
}
}
}
// Run SQL without explicitly calling to loadCache().
QueryCursor<List<?>> cur = cache.query(new SqlFieldsQuery("select id, name from Organization where name like ?").setArgs("organization-54321"));
System.out.println("SQL Result: " + cur.getAll());
// Run get() without explicitly calling to loadCache().
Organization org = cache.get(54321l);
System.out.println("GET Result: " + org);
}
}
use of org.apache.ignite.examples.model.Organization in project ignite by apache.
the class SqlQueriesExample 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(">>> SQL queries example started.");
CacheConfiguration<Long, Organization> orgCacheCfg = new CacheConfiguration<>(ORG_CACHE);
// Default.
orgCacheCfg.setCacheMode(CacheMode.PARTITIONED);
orgCacheCfg.setIndexedTypes(Long.class, Organization.class);
CacheConfiguration<AffinityKey<Long>, Person> colPersonCacheCfg = new CacheConfiguration<>(COLLOCATED_PERSON_CACHE);
// Default.
colPersonCacheCfg.setCacheMode(CacheMode.PARTITIONED);
colPersonCacheCfg.setIndexedTypes(AffinityKey.class, Person.class);
CacheConfiguration<Long, Person> personCacheCfg = new CacheConfiguration<>(PERSON_CACHE);
// Default.
personCacheCfg.setCacheMode(CacheMode.PARTITIONED);
personCacheCfg.setIndexedTypes(Long.class, Person.class);
try {
// Create caches.
ignite.getOrCreateCache(orgCacheCfg);
ignite.getOrCreateCache(colPersonCacheCfg);
ignite.getOrCreateCache(personCacheCfg);
// Populate caches.
initialize();
// Example for SQL-based querying employees based on salary ranges.
sqlQuery();
// Example for SQL-based querying employees for a given organization
// (includes SQL join for collocated objects).
sqlQueryWithJoin();
// Example for SQL-based querying employees for a given organization
// (includes distributed SQL join).
sqlQueryWithDistributedJoin();
// Example for SQL-based querying to calculate average salary
// among all employees within a company.
sqlQueryWithAggregation();
// Example for SQL-based fields queries that return only required
// fields instead of whole key-value pairs.
sqlFieldsQuery();
// Example for SQL-based fields queries that uses joins.
sqlFieldsQueryWithJoin();
} finally {
// Distributed cache could be removed from cluster only by Ignite.destroyCache() call.
ignite.destroyCache(COLLOCATED_PERSON_CACHE);
ignite.destroyCache(PERSON_CACHE);
ignite.destroyCache(ORG_CACHE);
}
print("SQL queries example finished.");
}
}
use of org.apache.ignite.examples.model.Organization in project ignite by apache.
the class SqlQueriesExample method initialize.
/**
* Populate cache with test data.
*/
private static void initialize() {
IgniteCache<Long, Organization> orgCache = Ignition.ignite().cache(ORG_CACHE);
// Clear cache before running the example.
orgCache.clear();
// Organizations.
Organization org1 = new Organization("ApacheIgnite");
Organization org2 = new Organization("Other");
orgCache.put(org1.id(), org1);
orgCache.put(org2.id(), org2);
IgniteCache<AffinityKey<Long>, Person> colPersonCache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
IgniteCache<Long, Person> personCache = Ignition.ignite().cache(PERSON_CACHE);
// Clear caches before running the example.
colPersonCache.clear();
personCache.clear();
// People.
Person p1 = new Person(org1, "John", "Doe", 2000, "John Doe has Master Degree.");
Person p2 = new Person(org1, "Jane", "Doe", 1000, "Jane Doe has Bachelor Degree.");
Person p3 = new Person(org2, "John", "Smith", 1000, "John Smith has Bachelor Degree.");
Person p4 = new Person(org2, "Jane", "Smith", 2000, "Jane Smith has Master Degree.");
// Note that in this example we use custom affinity key for Person objects
// to ensure that all persons are collocated with their organizations.
colPersonCache.put(p1.key(), p1);
colPersonCache.put(p2.key(), p2);
colPersonCache.put(p3.key(), p3);
colPersonCache.put(p4.key(), p4);
// These Person objects are not collocated with their organizations.
personCache.put(p1.id, p1);
personCache.put(p2.id, p2);
personCache.put(p3.id, p3);
personCache.put(p4.id, p4);
}
Aggregations