use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class CacheQueryExample method sqlFieldsQuery.
/**
* Example for SQL-based fields queries that return only required
* fields instead of whole key-value pairs.
*/
private static void sqlFieldsQuery() {
IgniteCache<Long, Person> cache = Ignition.ignite().cache(PERSON_CACHE);
// Execute query to get names of all employees.
QueryCursor<List<?>> cursor = cache.query(new SqlFieldsQuery("select concat(firstName, ' ', lastName) from Person"));
// In this particular case each row will have one element with full name of an employees.
List<List<?>> res = cursor.getAll();
// Print names.
print("Names of all employees:", res);
}
use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class CacheBinaryAutoStoreExample 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 {
// To start ignite with desired configuration uncomment the appropriate line.
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println(">>> Populate database with data...");
DbH2ServerStartup.populateDatabase();
System.out.println();
System.out.println(">>> Cache auto store example started...");
try (IgniteCache<Long, Person> cache = ignite.getOrCreateCache(cacheConfiguration())) {
try (Transaction tx = ignite.transactions().txStart()) {
Person val = cache.get(id);
System.out.println(">>> Read value: " + val);
val = cache.getAndPut(id, new Person(id, 1L, "Isaac", "Newton", 100.10, "English physicist and mathematician"));
System.out.println(">>> Overwrote old value: " + val);
val = cache.get(id);
System.out.println(">>> Read value: " + val);
System.out.println(">>> Update salary in transaction...");
val.salary *= 2;
cache.put(id, val);
tx.commit();
}
System.out.println(">>> Read value after commit: " + cache.get(id));
cache.clear();
System.out.println(">>> ------------------------------------------");
System.out.println(">>> Load data to cache from DB with custom SQL...");
// Load cache on all data nodes with custom SQL statement.
cache.loadCache(null, "java.lang.Long", "select * from PERSON where id <= 3");
System.out.println(">>> Loaded cache entries: " + cache.size());
cache.clear();
// Load cache on all data nodes with default SQL statement.
System.out.println(">>> Load ALL data to cache from DB...");
cache.loadCache(null);
System.out.println(">>> Loaded cache entries: " + cache.size());
} 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 SpringDataExample method queryRepository.
/**
* Execute advanced queries over the repository.
*/
private static void queryRepository() {
System.out.println("\n>>> Persons with name 'John':");
List<Person> persons = repo.findByFirstName("John");
for (Person person : persons) System.out.println(" >>> " + person);
Cache.Entry<Long, Person> topPerson = repo.findTopByLastNameLike("Smith");
System.out.println("\n>>> Top Person with surname 'Smith': " + topPerson.getValue());
List<Long> ids = repo.selectId(1000L, new PageRequest(0, 4));
System.out.println("\n>>> Persons working for organization with ID > 1000: ");
for (Long id : ids) System.out.println(" >>> [id=" + id + "]");
}
use of org.apache.ignite.examples.model.Person in project ignite by apache.
the class SqlDmlExample 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.Person in project ignite by apache.
the class CacheJdbcStoreExample method executeTransaction.
/**
* Executes transaction with read/write-through to persistent store.
*
* @param cache Cache to execute transaction on.
*/
private static void executeTransaction(IgniteCache<Long, Person> cache) {
try (Transaction tx = Ignition.ignite().transactions().txStart()) {
Person val = cache.get(id);
System.out.println("Read value: " + val);
val = cache.getAndPut(id, new Person(id, "Isaac", "Newton"));
System.out.println("Overwrote old value: " + val);
val = cache.get(id);
System.out.println("Read value: " + val);
tx.commit();
}
System.out.println("Read value after commit: " + cache.get(id));
// Clear entry from memory, but keep it in store.
cache.clear(id);
// Operations on this cache will not affect store.
IgniteCache<Long, Person> cacheSkipStore = cache.withSkipStore();
System.out.println("Read value skipping store (expecting null): " + cacheSkipStore.get(id));
System.out.println("Read value with store lookup (expecting NOT null): " + cache.get(id));
// Expecting not null, since entry should be in memory since last call.
System.out.println("Read value skipping store (expecting NOT null): " + cacheSkipStore.get(id));
}
Aggregations