use of org.apache.ignite.examples.model.Organization in project ignite by apache.
the class CacheQueryExample 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 query 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> personCacheCfg = new CacheConfiguration<>(PERSON_CACHE);
// Default.
personCacheCfg.setCacheMode(CacheMode.PARTITIONED);
personCacheCfg.setIndexedTypes(AffinityKey.class, Person.class);
try {
// Create caches.
ignite.getOrCreateCache(orgCacheCfg);
ignite.getOrCreateCache(personCacheCfg);
// Populate caches.
initialize();
// Example for SCAN-based query based on a predicate.
scanQuery();
// Example for TEXT-based querying for a given string in peoples resumes.
textQuery();
// Example for INDEX-based query with index criteria.
indexQuery();
} finally {
// Distributed cache could be removed from cluster only by Ignite.destroyCache() call.
ignite.destroyCache(PERSON_CACHE);
ignite.destroyCache(ORG_CACHE);
}
print("Cache query example finished.");
}
}
use of org.apache.ignite.examples.model.Organization in project ignite by apache.
the class CacheQueryExample 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(PERSON_CACHE);
// Clear caches before running the example.
colPersonCache.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);
}
Aggregations