From 5eec44ee5d9160e654b340be61c477236b019675 Mon Sep 17 00:00:00 2001 From: Stephen Darlington Date: Thu, 5 Mar 2026 11:14:07 +0000 Subject: [PATCH] Update to use Spring Data 4 --- README.md | 17 ++--- config/world.sql | 4 +- docker-compose.yml | 2 +- pom.xml | 4 +- .../gridgain/training/spring/model/City.java | 73 +------------------ .../training/spring/model/CityKey.java | 6 ++ 6 files changed, 18 insertions(+), 88 deletions(-) create mode 100644 src/main/java/com/gridgain/training/spring/model/CityKey.java diff --git a/README.md b/README.md index 500df6b..e9d9208 100644 --- a/README.md +++ b/README.md @@ -22,13 +22,9 @@ All the sessions are delivered by seasoned Ignite experts and committers. * [httpie](https://httpie.io) * A web browser -### Note 1 +### Note -This project has been tested most thoroughly using Java 17 and GridGain 9.1.8. (GridGain 9 supports Java 11, but the minimum version for Spring Boot is Java 17.) Later versions _may_ work; earlier versions will not. We test most frequently on Macs, but it should also work on Windows and Linux machines. Please create an Issue (or a PR!) if you find any issues. - -### Note 2 - -This project currently uses Spring Boot and Data 3.x. GridGain 9.1.19 and higher supports Spring 4.x. +This project has been tested most thoroughly using Java 17 and GridGain 9.1.19. (GridGain 9 supports Java 11, but the minimum version for Spring Boot is Java 17.) Later versions _may_ work; earlier versions will not. We test most frequently on Macs, but it should also work on Windows and Linux machines. Please create an Issue (or a PR!) if you find any issues. ## Hands-on part 1 @@ -53,7 +49,7 @@ git clone https://github.com/GridGain-Demos/spring-data-training.git a. Start the Command Line Interface (CLI): ```bash - docker run -v ./gridgain-license.json:/opt/gridgain/downloads/gridgain-license.json -v ./config/world.sql:/opt/gridgain/downloads/world.sql --rm --network spring-boot-data-training_default -it gridgain/gridgain9:9.1.8 cli + docker run -v ./gridgain-license.json:/opt/gridgain/downloads/gridgain-license.json -v ./config/world.sql:/opt/gridgain/downloads/world.sql --rm --network spring-boot-data-training_default -it gridgain/gridgain9:9.1.19 cli ``` (Ensure your license file is in your current directory.) @@ -181,7 +177,6 @@ Leave the CLI connected to the cluster. @Test void countryRepositoryWorks() { var results = countryRepository.findByPopulationGreaterThanOrderByPopulationDesc(100_000_000); - System.out.println("count=" + results.size()); Assertions.assertTrue(results.size() > 0); } ``` @@ -202,7 +197,7 @@ Leave the CLI connected to the cluster. ```java @Repository - public interface CityRepository extends CrudRepository { + public interface CityRepository extends CrudRepository { } ``` @@ -223,9 +218,9 @@ Leave the CLI connected to the cluster. ```java @Test void cityRepositoryWorks() { - var city = cityRepository.findById(34); + var city = cityRepository.findById(new CityKey(34, "ALB")); Assertions.assertTrue(city.isPresent()); - Assertions.assertEquals("Tirana", city.get().getName()); + Assertions.assertEquals("Tirana", city.get().name()); var populatedCities = cityRepository.findTopXMostPopulatedCities(5); Assertions.assertEquals(5, populatedCities.size()); diff --git a/config/world.sql b/config/world.sql index f5631fd..720b037 100644 --- a/config/world.sql +++ b/config/world.sql @@ -26,8 +26,8 @@ CREATE TABLE City ( CountryCode VARCHAR(3), District VARCHAR, Population INT, - PRIMARY KEY (ID) -); + PRIMARY KEY (ID, CountryCode) +) COLOCATE BY (CountryCode); CREATE INDEX idx_country_code ON city (CountryCode); diff --git a/docker-compose.yml b/docker-compose.yml index 00ece26..766bf3e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,7 @@ name: spring-boot-data-training x-gridgain-def: &gridgain-def - image: gridgain/gridgain9:9.1.8 + image: gridgain/gridgain9:9.1.19-openjdk21 environment: JVM_MAX_MEM: "4g" JVM_MIN_MEM: "4g" diff --git a/pom.xml b/pom.xml index 1c9c140..e5fbfa0 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.springframework.boot spring-boot-starter-parent - 3.5.11 + 4.0.3 com.gridgain.training @@ -15,7 +15,7 @@ 17 org.gridgain - 9.1.8 + 9.1.19 diff --git a/src/main/java/com/gridgain/training/spring/model/City.java b/src/main/java/com/gridgain/training/spring/model/City.java index c98025f..f7af0db 100644 --- a/src/main/java/com/gridgain/training/spring/model/City.java +++ b/src/main/java/com/gridgain/training/spring/model/City.java @@ -1,77 +1,6 @@ package com.gridgain.training.spring.model; import org.springframework.data.annotation.Id; -import org.springframework.data.relational.core.mapping.Column; -public class City { - @Id - private Integer id; - - @Column(value = "COUNTRYCODE") - private String countryCode; - - private String name; - - private String district; - - private Integer population; - - public City() { - } - - public City(Integer id, String countryCode, String name, String district, Integer population) { - this.id = id; - this.countryCode = countryCode; - this.name = name; - this.district = district; - this.population = population; - } - - public Integer getId() { - return id; - } - - public void setId(Integer id) { - this.id = id; - } - - public String getCountryCode() { - return countryCode; - } - - public void setCountryCode(String countryCode) { - this.countryCode = countryCode; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDistrict() { - return district; - } - - public void setDistrict(String district) { - this.district = district; - } - - public Integer getPopulation() { - return population; - } - - public void setPopulation(Integer population) { - this.population = population; - } - - @Override public String toString() { - return "City{" + - "name='" + name + '\'' + - ", district='" + district + '\'' + - ", population=" + population + - '}'; - } +public record City (@Id CityKey id, String name, String district, Integer population) { } diff --git a/src/main/java/com/gridgain/training/spring/model/CityKey.java b/src/main/java/com/gridgain/training/spring/model/CityKey.java new file mode 100644 index 0000000..eb50ac2 --- /dev/null +++ b/src/main/java/com/gridgain/training/spring/model/CityKey.java @@ -0,0 +1,6 @@ +package com.gridgain.training.spring.model; + +import org.springframework.data.relational.core.mapping.Column; + +public record CityKey (Integer id, @Column(value = "COUNTRYCODE") String countryCode) { +}