|
| 1 | +package com.baeldung.ignite.cache; |
| 2 | + |
| 3 | +import com.baeldung.ignite.model.Employee; |
| 4 | +import org.apache.ignite.Ignite; |
| 5 | +import org.apache.ignite.IgniteCache; |
| 6 | +import org.apache.ignite.Ignition; |
| 7 | +import org.apache.ignite.cache.query.QueryCursor; |
| 8 | +import org.apache.ignite.cache.query.SqlFieldsQuery; |
| 9 | +import org.apache.ignite.configuration.IgniteConfiguration; |
| 10 | + |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | +public class IgniteCacheExample { |
| 14 | + |
| 15 | + public static void main(String[] args) { |
| 16 | + |
| 17 | + Ignite ignite = Ignition.ignite(); |
| 18 | + |
| 19 | + IgniteCache<Integer, String> cache = ignite.cache("baeldungCache"); |
| 20 | + |
| 21 | + cache.put(1, "baeldung cache value"); |
| 22 | + |
| 23 | + String message = cache.get(1); |
| 24 | + } |
| 25 | + |
| 26 | + private static void getObjectFromCache(Ignite ignite) { |
| 27 | + |
| 28 | + IgniteCache<Integer, Employee> cache = ignite.getOrCreateCache("baeldungCache"); |
| 29 | + |
| 30 | + cache.put(1, new Employee(1, "John", true)); |
| 31 | + cache.put(2, new Employee(2, "Anna", false)); |
| 32 | + cache.put(3, new Employee(3, "George", true)); |
| 33 | + |
| 34 | + Employee employee = cache.get(1); |
| 35 | + } |
| 36 | + |
| 37 | + private static void getFromCacheWithSQl(Ignite ignite) { |
| 38 | + |
| 39 | + IgniteCache<Integer, Employee> cache = ignite.cache("baeldungCache"); |
| 40 | + |
| 41 | + SqlFieldsQuery sql = new SqlFieldsQuery( |
| 42 | + "select name from Employee where isEmployed = 'true'"); |
| 43 | + |
| 44 | + QueryCursor<List<?>> cursor = cache.query(sql); |
| 45 | + |
| 46 | + for (List<?> row : cursor) { |
| 47 | + System.out.println(row.get(0)); |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + private static void customInitialization() { |
| 52 | + |
| 53 | + IgniteConfiguration configuration = new IgniteConfiguration(); |
| 54 | + configuration.setLifecycleBeans(new CustomLifecycleBean()); |
| 55 | + Ignite ignite = Ignition.start(configuration); |
| 56 | + } |
| 57 | + |
| 58 | +} |
0 commit comments