Skip to content

Commit e208e0d

Browse files
authored
Merge pull request eugenp#7980 from SmartyAnsh/master
BAEL-1871 - Spring Data Geode
2 parents 1a76d19 + c27a4c1 commit e208e0d

File tree

9 files changed

+261
-0
lines changed

9 files changed

+261
-0
lines changed

persistence-modules/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<module>spring-data-eclipselink</module>
4949
<module>spring-data-elasticsearch</module>
5050
<module>spring-data-gemfire</module>
51+
<module>spring-data-geode</module>
5152
<module>spring-data-jpa</module>
5253
<module>spring-data-jpa-3</module>
5354
<module>spring-data-keyvalue</module>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<artifactId>spring-data-geode</artifactId>
6+
<name>spring-data-geode</name>
7+
<packaging>jar</packaging>
8+
<description>Intro to Spring Data Geode</description>
9+
10+
<parent>
11+
<groupId>com.baeldung</groupId>
12+
<artifactId>parent-modules</artifactId>
13+
<version>1.0.0-SNAPSHOT</version>
14+
<relativePath>../../</relativePath>
15+
</parent>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>org.springframework.boot</groupId>
20+
<artifactId>spring-boot-starter</artifactId>
21+
<version>2.1.9.RELEASE</version>
22+
<exclusions>
23+
<exclusion>
24+
<groupId>org.springframework.boot</groupId>
25+
<artifactId>spring-boot-starter-logging</artifactId>
26+
</exclusion>
27+
</exclusions>
28+
</dependency>
29+
<dependency>
30+
<groupId>org.springframework.boot</groupId>
31+
<artifactId>spring-boot-starter-web</artifactId>
32+
<version>${spring-boot-version}</version>
33+
<exclusions>
34+
<exclusion>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-logging</artifactId>
37+
</exclusion>
38+
</exclusions>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.springframework.geode</groupId>
42+
<artifactId>spring-geode-starter</artifactId>
43+
<version>${spring-geode-starter-version}</version>
44+
</dependency>
45+
46+
<dependency>
47+
<groupId>org.springframework.boot</groupId>
48+
<artifactId>spring-boot-autoconfigure</artifactId>
49+
<version>${spring-boot-version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.springframework.boot</groupId>
53+
<artifactId>spring-boot-starter-test</artifactId>
54+
<version>${spring-boot-version}</version>
55+
<scope>test</scope>
56+
</dependency>
57+
</dependencies>
58+
59+
<build>
60+
<finalName>${project.artifactId}</finalName>
61+
<plugins>
62+
<plugin>
63+
<groupId>com.mysema.maven</groupId>
64+
<artifactId>maven-apt-plugin</artifactId>
65+
<version>1.0</version>
66+
<executions>
67+
<execution>
68+
<phase>generate-sources</phase>
69+
<goals>
70+
<goal>process</goal>
71+
</goals>
72+
<configuration>
73+
<outputDirectory>target/generated-sources</outputDirectory>
74+
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
75+
</configuration>
76+
</execution>
77+
</executions>
78+
</plugin>
79+
<plugin>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-maven-plugin</artifactId>
82+
<version>${spring-boot-version}</version>
83+
</plugin>
84+
</plugins>
85+
</build>
86+
87+
<properties>
88+
<spring-boot-version>2.1.9.RELEASE</spring-boot-version>
89+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
90+
<start-class>com.baeldung.springdatageode.app.ClientCacheApp</start-class>
91+
<spring-geode-starter-version>1.1.1.RELEASE</spring-geode-starter-version>
92+
</properties>
93+
94+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.baeldung.springdatageode.app;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
import org.springframework.context.annotation.ComponentScan;
6+
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
7+
import org.springframework.data.gemfire.config.annotation.EnableClusterConfiguration;
8+
import org.springframework.data.gemfire.config.annotation.EnableContinuousQueries;
9+
import org.springframework.data.gemfire.config.annotation.EnableEntityDefinedRegions;
10+
import org.springframework.data.gemfire.config.annotation.EnableIndexing;
11+
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;
12+
13+
import com.baeldung.springdatageode.controller.AppController;
14+
import com.baeldung.springdatageode.___domain.Author;
15+
import com.baeldung.springdatageode.repo.AuthorRepository;
16+
import com.baeldung.springdatageode.service.AuthorService;
17+
18+
@SpringBootApplication
19+
@ClientCacheApplication(subscriptionEnabled = true)
20+
@EnableEntityDefinedRegions(basePackageClasses = Author.class)
21+
@EnableIndexing
22+
@EnableGemfireRepositories(basePackageClasses = AuthorRepository.class)
23+
@ComponentScan(basePackageClasses = {AppController.class, AuthorService.class})
24+
@EnableClusterConfiguration(useHttp = true, requireHttps=false)
25+
@EnableContinuousQueries
26+
public class ClientCacheApp {
27+
28+
public static void main(String[] args) {
29+
SpringApplication.run(ClientCacheApp.class, args);
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.baeldung.springdatageode.controller;
2+
3+
import java.util.Optional;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.http.HttpStatus;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.CrossOrigin;
9+
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.PostMapping;
11+
import org.springframework.web.bind.annotation.RequestBody;
12+
import org.springframework.web.bind.annotation.RequestParam;
13+
import org.springframework.web.bind.annotation.RestController;
14+
15+
import com.baeldung.springdatageode.___domain.Author;
16+
import com.baeldung.springdatageode.repo.AuthorRepository;
17+
18+
@RestController
19+
@CrossOrigin
20+
public class AppController {
21+
22+
@Autowired
23+
private AuthorRepository authorRepositoryImpl;
24+
25+
@PostMapping(path = "/author" )
26+
public ResponseEntity<String> addAuthor(@RequestBody Author author) throws Exception {
27+
authorRepositoryImpl.save(author);
28+
return new ResponseEntity<>("OK", HttpStatus.OK);
29+
}
30+
31+
@GetMapping(path = "/author" )
32+
public ResponseEntity<Author> getAuthor(@RequestParam("id") String id) throws Exception {
33+
Optional<Author> author = authorRepositoryImpl.findById(Long.parseLong(id));
34+
return new ResponseEntity<>(author.isPresent() ? author.get() : null, HttpStatus.OK);
35+
}
36+
37+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package com.baeldung.springdatageode.___domain;
2+
3+
import org.springframework.data.annotation.Id;
4+
import org.springframework.data.gemfire.mapping.annotation.Indexed;
5+
import org.springframework.data.gemfire.mapping.annotation.Region;
6+
7+
@Region(name = "Authors")
8+
public class Author {
9+
10+
@Id
11+
private Long id;
12+
13+
private String firstName;
14+
15+
private String lastName;
16+
17+
@Indexed
18+
private int age;
19+
20+
public Long getId() {
21+
return id;
22+
}
23+
24+
public void setId(Long id) {
25+
this.id = id;
26+
}
27+
28+
public String getFirstName() {
29+
return firstName;
30+
}
31+
32+
public void setFirstName(String firstName) {
33+
this.firstName = firstName;
34+
}
35+
36+
public String getLastName() {
37+
return lastName;
38+
}
39+
40+
public void setLastName(String lastName) {
41+
this.lastName = lastName;
42+
}
43+
44+
public int getAge() {
45+
return age;
46+
}
47+
48+
public void setAge(int age) {
49+
this.age = age;
50+
}
51+
52+
@Override
53+
public String toString() {
54+
return this.firstName + " " + this.lastName + ", " + this.age + " years old";
55+
}
56+
57+
}
58+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.baeldung.springdatageode.repo;
2+
3+
import com.baeldung.springdatageode.___domain.Author;
4+
5+
import java.util.Optional;
6+
7+
import org.springframework.data.repository.CrudRepository;
8+
9+
public interface AuthorRepository extends CrudRepository<Author, Long> {
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.baeldung.springdatageode.service;
2+
3+
import org.apache.geode.cache.query.CqEvent;
4+
import org.springframework.data.gemfire.listener.annotation.ContinuousQuery;
5+
import org.springframework.stereotype.Service;
6+
7+
@Service
8+
public class AuthorService {
9+
10+
@ContinuousQuery(query = "SELECT * FROM /Authors a WHERE a.id = 1")
11+
public void process(CqEvent event) {
12+
System.out.println("Author #" + event.getKey() + " updated to " + event.getNewValue());
13+
}
14+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
server.port=9091
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
6+
</pattern>
7+
</encoder>
8+
</appender>
9+
10+
<root level="INFO">
11+
<appender-ref ref="STDOUT" />
12+
</root>
13+
</configuration>

0 commit comments

Comments
 (0)