use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class SpringDataExample method findPersons.
/**
* Gets a list of Persons using standard read operations.
*/
private static void findPersons() {
// Getting Person with specific ID.
Person person = repo.findOne(2L);
System.out.println("\n>>> Found Person [id=" + 2L + ", val=" + person + "]");
// Getting a list of Persons.
ArrayList<Long> ids = new ArrayList<>();
for (long i = 0; i < 5; i++) ids.add(i);
Iterator<Person> persons = repo.findAll(ids).iterator();
System.out.println("\n>>> Persons list for specific ids: ");
while (persons.hasNext()) System.out.println(" >>> " + persons.next());
}
use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class SpringDataExample method populateRepository.
/**
* Fills the repository in with sample data.
*/
private static void populateRepository() {
TreeMap<Long, Person> persons = new TreeMap<>();
persons.put(1L, new Person(1L, 2000L, "John", "Smith", 15000, "Worked for Apple"));
persons.put(2L, new Person(2L, 2000L, "Brad", "Pitt", 16000, "Worked for Oracle"));
persons.put(3L, new Person(3L, 1000L, "Mark", "Tomson", 10000, "Worked for Sun"));
persons.put(4L, new Person(4L, 2000L, "Erick", "Smith", 13000, "Worked for Apple"));
persons.put(5L, new Person(5L, 1000L, "John", "Rozenberg", 25000, "Worked for RedHat"));
persons.put(6L, new Person(6L, 2000L, "Denis", "Won", 35000, "Worked for CBS"));
persons.put(7L, new Person(7L, 1000L, "Abdula", "Adis", 45000, "Worked for NBC"));
persons.put(8L, new Person(8L, 2000L, "Roman", "Ive", 15000, "Worked for Sun"));
// Adding data into the repository.
repo.save(persons);
System.out.println("\n>>> Added " + repo.count() + " Persons into the repository.");
}
use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class CacheLoadOnlyStoreExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> CacheLoadOnlyStoreExample started.");
ProductLoader productLoader = new ProductLoader("examples/src/main/resources/person.csv");
productLoader.setThreadsCount(2);
productLoader.setBatchSize(10);
productLoader.setBatchQueueSize(1);
try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheConfiguration(productLoader))) {
// load data.
cache.loadCache(null);
System.out.println(">>> Loaded number of items: " + cache.size(CachePeekMode.PRIMARY));
System.out.println(">>> Data for the person by id1: " + cache.get(1L));
} finally {
// Distributed cache could be removed from cluster only by #destroyCache() call.
ignite.destroyCache(CACHE_NAME);
}
}
}
use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class CacheQueryExample method sqlFieldsQueryWithJoin.
/**
* Example for SQL-based fields queries that return only required
* fields instead of whole key-value pairs.
*/
private static void sqlFieldsQueryWithJoin() {
IgniteCache<AffinityKey<Long>, Person> cache = Ignition.ignite().cache(COLLOCATED_PERSON_CACHE);
// Execute query to get names of all employees.
String sql = "select concat(firstName, ' ', lastName), org.name " + "from Person, \"" + ORG_CACHE + "\".Organization as org " + "where Person.orgId = org.id";
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery(sql));
// In this particular case each row will have one element with full name of an employees.
List<List<?>> res = cursor.getAll();
// Print persons' names and organizations' names.
print("Names of all employees and organizations they belong to: ", res);
}
use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class CacheQueryExample method sqlQueryWithDistributedJoin.
/**
* Example for SQL queries based on all employees working
* for a specific organization (query uses distributed join).
*/
private static void sqlQueryWithDistributedJoin() {
IgniteCache<Long, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// SQL clause query which joins on 2 types to select people for a specific organization.
String joinSql = "from Person, \"" + ORG_CACHE + "\".Organization as org " + "where Person.orgId = org.id " + "and lower(org.name) = lower(?)";
SqlQuery qry = new SqlQuery<Long, Person>(Person.class, joinSql).setArgs("ApacheIgnite");
// Enable distributed joins for query.
qry.setDistributedJoins(true);
// Execute queries for find employees for different organizations.
print("Following people are 'ApacheIgnite' employees (distributed join): ", cache.query(qry).getAll());
qry.setArgs("Other");
print("Following people are 'Other' employees (distributed join): ", cache.query(qry).getAll());
}
Aggregations