Skip to content

Commit f68b3d6

Browse files
authored
Merge pull request eugenp#4041 from MherBaghinyan/BAEL_1610
BAEL-1610
2 parents a529a53 + 6a03f1a commit f68b3d6

5 files changed

Lines changed: 150 additions & 2 deletions

File tree

‎libraries-data/pom.xml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
</dependency>
7373
<dependency>
7474
<groupId>org.apache.ignite</groupId>
75-
<artifactId>ignite-spring</artifactId>
75+
<artifactId>ignite-spring-data</artifactId>
7676
<version>${ignite.version}</version>
7777
</dependency>
7878
<dependency>
@@ -192,7 +192,7 @@
192192
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
193193
<ormlite.version>5.0</ormlite.version>
194194
<kafka.version>1.0.0</kafka.version>
195-
<ignite.version>2.3.0</ignite.version>
195+
<ignite.version>2.4.0</ignite.version>
196196
<gson.version>2.8.2</gson.version>
197197
</properties>
198198
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.baeldung.ignite.spring.config;
2+
3+
import com.baeldung.ignite.spring.dto.EmployeeDTO;
4+
import com.baeldung.ignite.spring.repository.EmployeeRepository;
5+
import org.apache.ignite.Ignite;
6+
import org.apache.ignite.Ignition;
7+
import org.apache.ignite.configuration.CacheConfiguration;
8+
import org.apache.ignite.configuration.IgniteConfiguration;
9+
import org.apache.ignite.springdata.repository.config.EnableIgniteRepositories;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.ComponentScan;
12+
import org.springframework.context.annotation.Configuration;
13+
14+
@Configuration
15+
@EnableIgniteRepositories(basePackageClasses = EmployeeRepository.class)
16+
@ComponentScan(basePackages = "com.baeldung.ignite.spring.repository")
17+
public class SpringDataConfig {
18+
19+
@Bean
20+
public Ignite igniteInstance() {
21+
IgniteConfiguration config = new IgniteConfiguration();
22+
// Setting some custom name for the node.
23+
//config.setIgniteInstanceName("springDataNode");
24+
// Enabling peer-class loading feature.
25+
//config.setPeerClassLoadingEnabled(true);
26+
// Defining and creating a new cache to be used by Ignite Spring Data
27+
// repository.
28+
CacheConfiguration cache = new CacheConfiguration("baeldungCache");
29+
// Setting SQL schema for the cache.
30+
cache.setIndexedTypes(Integer.class, EmployeeDTO.class);
31+
config.setCacheConfiguration(cache);
32+
return Ignition.start(config);
33+
}
34+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.baeldung.ignite.spring.dto;
2+
3+
import org.apache.ignite.cache.query.annotations.QuerySqlField;
4+
5+
import java.io.Serializable;
6+
7+
public class EmployeeDTO implements Serializable {
8+
9+
@QuerySqlField(index = true)
10+
private Integer id;
11+
@QuerySqlField(index = true)
12+
private String name;
13+
@QuerySqlField(index = true)
14+
private boolean isEmployed;
15+
16+
public Integer getId() {
17+
return id;
18+
}
19+
20+
public void setId(Integer id) {
21+
this.id = id;
22+
}
23+
24+
public String getName() {
25+
return name;
26+
}
27+
28+
public void setName(String name) {
29+
this.name = name;
30+
}
31+
32+
public boolean isEmployed() {
33+
return isEmployed;
34+
}
35+
36+
public void setEmployed(boolean employed) {
37+
isEmployed = employed;
38+
}
39+
40+
@Override
41+
public String toString() {
42+
return "EmployeeDTO{" +
43+
"id=" + id +
44+
", name='" + name + '\'' +
45+
", isEmployed=" + isEmployed +
46+
'}';
47+
}
48+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.baeldung.ignite.spring.repository;
2+
3+
import com.baeldung.ignite.spring.dto.EmployeeDTO;
4+
import org.apache.ignite.springdata.repository.IgniteRepository;
5+
import org.apache.ignite.springdata.repository.config.RepositoryConfig;
6+
import org.springframework.stereotype.Repository;
7+
8+
@Repository
9+
@RepositoryConfig(cacheName = "baeldungCache")
10+
public interface EmployeeRepository extends IgniteRepository<EmployeeDTO, Integer> {
11+
12+
EmployeeDTO getEmployeeDTOById(Integer id);
13+
}

0 commit comments

Comments
 (0)