|
| 1 | +package com.baeldung.ignite.spring; |
| 2 | + |
| 3 | +import com.baeldung.ignite.spring.config.SpringDataConfig; |
| 4 | +import com.baeldung.ignite.spring.dto.EmployeeDTO; |
| 5 | +import com.baeldung.ignite.spring.repository.EmployeeRepository; |
| 6 | +import org.apache.ignite.Ignite; |
| 7 | +import org.apache.ignite.IgniteCache; |
| 8 | +import org.apache.ignite.Ignition; |
| 9 | +import org.apache.ignite.cache.query.QueryCursor; |
| 10 | +import org.apache.ignite.cache.query.SqlFieldsQuery; |
| 11 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
| 12 | + |
| 13 | +import java.util.List; |
| 14 | + |
| 15 | +/** |
| 16 | + * Created by Gebruiker on 4/12/2018. |
| 17 | + */ |
| 18 | +public class IgniteApp { |
| 19 | + |
| 20 | + public static void main (String[] args) { |
| 21 | + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); |
| 22 | + context.register(SpringDataConfig.class); |
| 23 | + context.refresh(); |
| 24 | + |
| 25 | + EmployeeRepository repository = context.getBean(EmployeeRepository.class); |
| 26 | + |
| 27 | + EmployeeDTO employeeDTO = new EmployeeDTO(); |
| 28 | + employeeDTO.setId(1); |
| 29 | + employeeDTO.setName("John"); |
| 30 | + employeeDTO.setEmployed(true); |
| 31 | + |
| 32 | + repository.save(employeeDTO.getId(), employeeDTO); |
| 33 | + |
| 34 | + EmployeeDTO employee = repository.getEmployeeDTOById(employeeDTO.getId()); |
| 35 | + System.out.println(employee); |
| 36 | + } |
| 37 | + |
| 38 | + private void getUsingTheCache(Integer employeeId) { |
| 39 | + |
| 40 | + Ignite ignite = Ignition.ignite(); |
| 41 | + |
| 42 | + IgniteCache<Integer, EmployeeDTO> cache = ignite.cache("baeldungCache"); |
| 43 | + |
| 44 | + EmployeeDTO employeeDTO = cache.get(employeeId); |
| 45 | + |
| 46 | + System.out.println(employeeDTO); |
| 47 | + |
| 48 | + SqlFieldsQuery sql = new SqlFieldsQuery( |
| 49 | + "select * from EmployeeDTO where isEmployed = 'true'"); |
| 50 | + |
| 51 | + QueryCursor<List<?>> cursor = cache.query(sql); |
| 52 | + } |
| 53 | +} |
0 commit comments