Merge branch 'eugenp:master' into master
This commit is contained in:
@@ -9,9 +9,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -34,37 +34,41 @@
|
||||
<!-- Core dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-core-api</artifactId>
|
||||
<artifactId>blaze-persistence-core-api-jakarta</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-core-impl</artifactId>
|
||||
<artifactId>blaze-persistence-core-impl-jakarta</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-integration-hibernate-5.6</artifactId>
|
||||
<artifactId>blaze-persistence-integration-hibernate-6.2</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<!-- Entity View dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-entity-view-api</artifactId>
|
||||
<artifactId>blaze-persistence-entity-view-api-jakarta</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-entity-view-impl</artifactId>
|
||||
<artifactId>blaze-persistence-entity-view-impl-jakarta</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-entity-view-processor</artifactId>
|
||||
<artifactId>blaze-persistence-entity-view-processor-jakarta</artifactId>
|
||||
</dependency>
|
||||
<!-- Spring integration dependencies -->
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-integration-entity-view-spring</artifactId>
|
||||
<artifactId>blaze-persistence-integration-entity-view-spring-6.0</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blazebit</groupId>
|
||||
<artifactId>blaze-persistence-integration-spring-data-2.7</artifactId>
|
||||
<artifactId>blaze-persistence-integration-spring-data-3.1</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- Spring dependencies -->
|
||||
<dependency>
|
||||
@@ -108,9 +112,9 @@
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<blaze-persistence.version>1.6.8</blaze-persistence.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<blaze-persistence.version>1.6.11</blaze-persistence.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+1
-1
@@ -11,7 +11,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.persistence.EntityManagerFactory;
|
||||
import jakarta.persistence.EntityManagerFactory;
|
||||
|
||||
@Configuration
|
||||
@EnableEntityViews(basePackages = {"com.baeldung.view"})
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.baeldung.model;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.baeldung.model;
|
||||
|
||||
import javax.persistence.*;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@Entity
|
||||
public class Post {
|
||||
|
||||
+2
-2
@@ -6,8 +6,8 @@ import com.blazebit.persistence.CriteriaBuilder;
|
||||
import com.blazebit.persistence.CriteriaBuilderFactory;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
@Repository
|
||||
@Transactional
|
||||
|
||||
+2
-2
@@ -8,8 +8,8 @@ import com.blazebit.persistence.view.EntityViewManager;
|
||||
import com.blazebit.persistence.view.EntityViewSetting;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.transaction.Transactional;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.transaction.Transactional;
|
||||
|
||||
@Repository
|
||||
@Transactional
|
||||
|
||||
@@ -4,3 +4,4 @@
|
||||
- [N+1 Problem in Hibernate and Spring Data JPA](https://www.baeldung.com/spring-hibernate-n1-problem)
|
||||
- [Get All Results at Once in a Spring Boot Paged Query Method](https://www.baeldung.com/spring-boot-paged-query-all-results)
|
||||
- [Calling Custom Database Functions With JPA and Spring Boot](https://www.baeldung.com/spring-data-jpa-custom-database-functions)
|
||||
- [Spring Data JPA Repository for Database View](https://www.baeldung.com/spring-data-jpa-repository-view)
|
||||
|
||||
@@ -7,25 +7,13 @@
|
||||
<artifactId>spring-boot-persistence-4</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>spring-boot-persistence-4</name>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit</groupId>
|
||||
<artifactId>junit-bom</artifactId>
|
||||
<version>${junit-jupiter.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring.boot.dependencies}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -79,13 +67,16 @@
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<mainClass>com.baeldung.customfunc.CustomFunctionApplication</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring.boot.dependencies>3.2.2</spring.boot.dependencies>
|
||||
<junit-jupiter.version>5.9.3</junit-jupiter.version>
|
||||
<junit-jupiter.version>5.10.2</junit-jupiter.version>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<db.util.version>1.0.7</db.util.version>
|
||||
|
||||
+6
@@ -2,6 +2,7 @@ package com.baeldung.customfunc;
|
||||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -54,5 +55,10 @@ public class ProductRepositoryIntegrationTest {
|
||||
var hashList = productRepository.getProductNameListInSha256Hex();
|
||||
assertThat(hashList.get(0)).isEqualTo(EXPECTED_HASH_HEX);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void afterEach() {
|
||||
productRepository.deleteAll();
|
||||
}
|
||||
|
||||
}
|
||||
+2
@@ -1,5 +1,6 @@
|
||||
package com.baeldung.dbview;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -15,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.jpa.defer-datasource-initialization=true",
|
||||
"spring.sql.init.data-locations=classpath:shop-sale-data.sql"
|
||||
})
|
||||
@Disabled
|
||||
class ShopSaleRepositoryIntegrationTest {
|
||||
|
||||
private static final ShopSaleCompositeId id = ShopSaleCompositeId.builder()
|
||||
|
||||
+2
@@ -1,5 +1,6 @@
|
||||
package com.baeldung.dbview;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
@@ -15,6 +16,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
"spring.jpa.defer-datasource-initialization=true",
|
||||
"spring.sql.init.data-locations=classpath:shop-sale-data.sql"
|
||||
})
|
||||
@Disabled
|
||||
class ShopSaleVidRepositoryIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest(classes = {Application.class, TestConfig.class})
|
||||
class JsonUtilTest {
|
||||
class JsonUtilUnitTest {
|
||||
|
||||
@Autowired
|
||||
private JsonUtils jsonUtils;
|
||||
+3
@@ -15,6 +15,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
@@ -57,6 +59,7 @@ class NPlusOneEagerModerateDomainIntegrationTest extends BaseNPlusOneIntegration
|
||||
assertSelectCount(1);
|
||||
}
|
||||
|
||||
@Disabled
|
||||
@ParameterizedTest
|
||||
@ValueSource(longs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
|
||||
void givenEagerListBasedGroup_whenRemoveUser_thenIssueOnlyOneDelete(Long groupId) {
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -63,7 +63,7 @@
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>java-driver-mapper-runtime</artifactId>
|
||||
<version>4.15.0</version>
|
||||
<version>4.17.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
@@ -99,10 +99,11 @@
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<org.springframework.data.version>3.4.15</org.springframework.data.version>
|
||||
<testcontainers.version>1.19.0</testcontainers.version>
|
||||
<system.stubs.version>1.1.0</system.stubs.version>
|
||||
<org.springframework.data.version>4.1.9</org.springframework.data.version>
|
||||
<testcontainers.version>1.19.5</testcontainers.version>
|
||||
<system.stubs.version>2.1.5</system.stubs.version>
|
||||
<junit.jupiter.version>5.9.3</junit.jupiter.version>
|
||||
<start-class>org.baeldung.springcassandra.SpringCassandraApplication</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
spring.data.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
|
||||
spring.data.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
|
||||
spring.data.cassandra.port=${CASSANDRA_PORT}
|
||||
spring.data.cassandra.local-datacenter=datacenter1
|
||||
spring.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
|
||||
spring.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
|
||||
spring.cassandra.port=${CASSANDRA_PORT}
|
||||
spring.cassandra.local-datacenter=datacenter1
|
||||
+13
-10
@@ -14,6 +14,8 @@ import org.testcontainers.containers.CassandraContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -30,14 +32,14 @@ class ProductRepositoryNestedLiveTest {
|
||||
private static final String KEYSPACE_NAME = "mynamespace";
|
||||
|
||||
@Container
|
||||
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2")
|
||||
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2")
|
||||
.withExposedPorts(9042);
|
||||
|
||||
@BeforeAll
|
||||
static void setupCassandraConnectionProperties() {
|
||||
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.data.cassandra.contact-points", cassandra.getHost());
|
||||
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.cassandra.contact-points", cassandra.getHost());
|
||||
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
createKeyspace(cassandra.getCluster());
|
||||
}
|
||||
|
||||
@@ -72,9 +74,9 @@ class ProductRepositoryNestedLiveTest {
|
||||
Product product3 = new Product(productId3, "Banana", "Banana v1", 5.5);
|
||||
Product product4 = new Product(productId3, "Banana v2", "Banana v2", 15.5);
|
||||
|
||||
productRepository.saveAll(List.of(product1, product2, product3, product4));
|
||||
productRepository.saveAll(Arrays.asList(product1, product2, product3, product4));
|
||||
|
||||
List<Product> existingProducts = productRepository.findByProductIds(List.of(productId1, productId2));
|
||||
List<Product> existingProducts = productRepository.findByProductIds(Arrays.asList(productId1, productId2));
|
||||
assertEquals(2, existingProducts.size());
|
||||
assertTrue(existingProducts.contains(product1));
|
||||
assertTrue(existingProducts.contains(product2));
|
||||
@@ -89,10 +91,10 @@ class ProductRepositoryNestedLiveTest {
|
||||
Product product3 = new Product(productId2, "Banana", "Banana v1", 5.5);
|
||||
Product product4 = new Product(productId2, "Banana v2", "Banana v2", 15.5);
|
||||
|
||||
productRepository.saveAll(List.of(product1, product2, product3, product4));
|
||||
productRepository.saveAll(Arrays.asList(product1, product2, product3, product4));
|
||||
|
||||
List<Product> existingProducts = productRepository.findByProductIdAndNames(productId1,
|
||||
List.of(product1.getProductName(), product2.getProductName()));
|
||||
Arrays.asList(product1.getProductName(), product2.getProductName()));
|
||||
assertEquals(2, existingProducts.size());
|
||||
assertTrue(existingProducts.contains(product1));
|
||||
assertTrue(existingProducts.contains(product2));
|
||||
@@ -107,10 +109,11 @@ class ProductRepositoryNestedLiveTest {
|
||||
Product product3 = new Product(productId2, "Banana", "Banana v1", 5.5);
|
||||
Product product4 = new Product(productId2, "Banana v2", "Banana v2", 15.5);
|
||||
|
||||
productRepository.saveAll(List.of(product1, product2, product4));
|
||||
productRepository.saveAll(Arrays.asList(product1, product2, product4));
|
||||
|
||||
List<Product> existingProducts = productRepository.findByProductIdAndNames(productId1,
|
||||
List.of(product3.getProductName()));
|
||||
Collections.singletonList(product3.getProductName())
|
||||
);
|
||||
assertEquals(0, existingProducts.size());
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -25,13 +25,13 @@ public class MapperLiveTest {
|
||||
private static final String KEYSPACE_NAME = "baeldung";
|
||||
|
||||
@Container
|
||||
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2").withExposedPorts(9042);
|
||||
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2").withExposedPorts(9042);
|
||||
|
||||
@BeforeAll
|
||||
static void setupCassandraConnectionProperties() {
|
||||
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.data.cassandra.contact-points", cassandra.getHost());
|
||||
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.cassandra.contact-points", cassandra.getHost());
|
||||
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
setupCassandra(new InetSocketAddress(cassandra.getHost(), cassandra.getMappedPort(9042)), cassandra.getLocalDatacenter());
|
||||
}
|
||||
|
||||
@@ -92,5 +92,4 @@ public class MapperLiveTest {
|
||||
.all();
|
||||
Assertions.assertEquals(1, retrievedUsers.size());
|
||||
}
|
||||
|
||||
}
|
||||
+9
-10
@@ -14,6 +14,7 @@ import org.testcontainers.containers.CassandraContainer;
|
||||
import org.testcontainers.junit.jupiter.Container;
|
||||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -28,14 +29,14 @@ class CassandraNestedLiveTest {
|
||||
private static final String KEYSPACE_NAME = "test";
|
||||
|
||||
@Container
|
||||
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2")
|
||||
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2")
|
||||
.withExposedPorts(9042);
|
||||
|
||||
@BeforeAll
|
||||
static void setupCassandraConnectionProperties() {
|
||||
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.data.cassandra.contact-points", cassandra.getContainerIpAddress());
|
||||
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.cassandra.contact-points", cassandra.getContainerIpAddress());
|
||||
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
|
||||
createKeyspace(cassandra.getCluster());
|
||||
}
|
||||
@@ -70,7 +71,7 @@ class CassandraNestedLiveTest {
|
||||
|
||||
carRepository.save(newCar);
|
||||
|
||||
List<Car> savedCars = carRepository.findAllById(List.of(carId));
|
||||
List<Car> savedCars = carRepository.findAllById(Collections.singletonList(carId));
|
||||
assertThat(savedCars.get(0)).isEqualTo(newCar);
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ class CassandraNestedLiveTest {
|
||||
existingCar.setModel("X-Trail");
|
||||
carRepository.save(existingCar);
|
||||
|
||||
List<Car> savedCars = carRepository.findAllById(List.of(carId));
|
||||
List<Car> savedCars = carRepository.findAllById(Collections.singletonList(carId));
|
||||
assertThat(savedCars.get(0).getModel()).isEqualTo("X-Trail");
|
||||
}
|
||||
|
||||
@@ -93,10 +94,8 @@ class CassandraNestedLiveTest {
|
||||
|
||||
carRepository.delete(existingCar);
|
||||
|
||||
List<Car> savedCars = carRepository.findAllById(List.of(carId));
|
||||
assertThat(savedCars.isEmpty()).isTrue();
|
||||
List<Car> savedCars = carRepository.findAllById(Collections.singletonList(carId));
|
||||
assertThat(savedCars).isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-5
@@ -20,14 +20,14 @@ class CassandraSimpleLiveTest {
|
||||
private static final String KEYSPACE_NAME = "test";
|
||||
|
||||
@Container
|
||||
private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2")
|
||||
private static final CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2")
|
||||
.withExposedPorts(9042);
|
||||
|
||||
@BeforeAll
|
||||
static void setupCassandraConnectionProperties() {
|
||||
System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.data.cassandra.contact-points", cassandra.getContainerIpAddress());
|
||||
System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
System.setProperty("spring.cassandra.keyspace-name", KEYSPACE_NAME);
|
||||
System.setProperty("spring.cassandra.contact-points", cassandra.getContainerIpAddress());
|
||||
System.setProperty("spring.cassandra.port", String.valueOf(cassandra.getMappedPort(9042)));
|
||||
|
||||
createKeyspace(cassandra.getCluster());
|
||||
}
|
||||
@@ -43,5 +43,4 @@ class CassandraSimpleLiveTest {
|
||||
void givenCassandraContainer_whenSpringContextIsBootstrapped_thenContainerIsRunningWithNoExceptions() {
|
||||
assertThat(cassandra.isRunning()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
spring.data.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
|
||||
spring.data.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
|
||||
spring.data.cassandra.port=${CASSANDRA_PORT}
|
||||
spring.data.cassandra.local-datacenter=datacenter1
|
||||
spring.data.cassandra.schema-action=create_if_not_exists
|
||||
spring.cassandra.keyspace-name=${CASSANDRA_KEYSPACE_NAME}
|
||||
spring.cassandra.contact-points=${CASSANDRA_CONTACT_POINTS}
|
||||
spring.cassandra.port=${CASSANDRA_PORT}
|
||||
spring.cassandra.local-datacenter=datacenter1
|
||||
spring.cassandra.schema-action=create_if_not_exists
|
||||
@@ -1,2 +1,3 @@
|
||||
### Relevant Articles:
|
||||
- [@DataJpaTest and Repository Class in JUnit](https://www.baeldung.com/junit-datajpatest-repository)
|
||||
- [Query Hints in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-query-hints)
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -26,6 +26,11 @@
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.postgresql</groupId>
|
||||
<artifactId>postgresql</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
@@ -33,4 +38,8 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<start-class>com.baeldung.Application</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+5
-5
@@ -3,11 +3,11 @@ package com.baeldung.elementcollection.model;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import jakarta.persistence.CollectionTable;
|
||||
import jakarta.persistence.ElementCollection;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
|
||||
@Entity
|
||||
public class Employee {
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package com.baeldung.elementcollection.model;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.persistence.Embeddable;
|
||||
import jakarta.persistence.Embeddable;
|
||||
|
||||
@Embeddable
|
||||
public class Phone {
|
||||
|
||||
+4
-4
@@ -3,15 +3,15 @@ package com.baeldung.elementcollection.repository;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.persistence.EntityGraph;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.baeldung.elementcollection.model.Employee;
|
||||
|
||||
import jakarta.persistence.EntityGraph;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
|
||||
@Repository
|
||||
public class EmployeeRepository {
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package com.baeldung.namingstrategy;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class Person {
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.baeldung.namingstrategy;
|
||||
|
||||
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.Identifier;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
|
||||
|
||||
public class QuotedLowerCaseNamingStrategy extends SpringPhysicalNamingStrategy {
|
||||
public class QuotedLowerCaseNamingStrategy extends CamelCaseToUnderscoresNamingStrategy {
|
||||
@Override
|
||||
protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) {
|
||||
return new Identifier(name.toLowerCase(), true);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.baeldung.namingstrategy;
|
||||
|
||||
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.Identifier;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
|
||||
|
||||
public class QuotedUpperCaseNamingStrategy extends SpringPhysicalNamingStrategy {
|
||||
public class QuotedUpperCaseNamingStrategy extends CamelCaseToUnderscoresNamingStrategy {
|
||||
@Override
|
||||
protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) {
|
||||
return new Identifier(name.toUpperCase(), true);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.baeldung.namingstrategy;
|
||||
|
||||
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.Identifier;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
|
||||
|
||||
public class UnquotedLowerCaseNamingStrategy extends SpringPhysicalNamingStrategy {
|
||||
public class UnquotedLowerCaseNamingStrategy extends CamelCaseToUnderscoresNamingStrategy {
|
||||
@Override
|
||||
protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) {
|
||||
return new Identifier(name.toLowerCase(), false);
|
||||
|
||||
+2
-2
@@ -1,10 +1,10 @@
|
||||
package com.baeldung.namingstrategy;
|
||||
|
||||
import org.hibernate.boot.model.naming.CamelCaseToUnderscoresNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.Identifier;
|
||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
||||
import org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy;
|
||||
|
||||
public class UnquotedUpperCaseNamingStrategy extends SpringPhysicalNamingStrategy {
|
||||
public class UnquotedUpperCaseNamingStrategy extends CamelCaseToUnderscoresNamingStrategy {
|
||||
@Override
|
||||
protected Identifier getIdentifier(String name, boolean quoted, JdbcEnvironment jdbcEnvironment) {
|
||||
return new Identifier(name.toUpperCase(), false);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -73,8 +73,7 @@ class QuotedLowerCaseNamingStrategyH2IntegrationTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -77,8 +77,7 @@ class QuotedLowerCaseNamingStrategyPostgresLiveTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -77,8 +77,7 @@ class QuotedUpperCaseNamingStrategyH2IntegrationTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+5
-7
@@ -3,15 +3,10 @@ package com.baeldung.namingstrategy;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -22,6 +17,10 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class)
|
||||
@TestPropertySource("quoted-upper-case-naming-strategy-on-postgres.properties")
|
||||
class QuotedUpperCaseNamingStrategyPostgresLiveTest {
|
||||
@@ -73,8 +72,7 @@ class QuotedUpperCaseNamingStrategyPostgresLiveTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -77,8 +77,7 @@ class SpringPhysicalNamingStrategyH2IntegrationTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -77,8 +77,7 @@ class SpringPhysicalNamingStrategyPostgresLiveTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -77,8 +77,7 @@ class UnquotedLowerCaseNamingStrategyH2IntegrationTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+5
-6
@@ -8,10 +8,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -22,6 +18,10 @@ import org.springframework.boot.test.autoconfigure.jdbc.TestDatabaseAutoConfigur
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
@DataJpaTest(excludeAutoConfiguration = TestDatabaseAutoConfiguration.class)
|
||||
@TestPropertySource("unquoted-lower-case-naming-strategy-on-postgres.properties")
|
||||
class UnquotedLowerCaseNamingStrategyPostgresLiveTest {
|
||||
@@ -77,8 +77,7 @@ class UnquotedLowerCaseNamingStrategyPostgresLiveTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -77,8 +77,7 @@ class UnquotedUpperCaseNamingStrategyH2IntegrationTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+4
-5
@@ -8,9 +8,9 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.PersistenceContext;
|
||||
import jakarta.persistence.Query;
|
||||
|
||||
import org.hibernate.exception.SQLGrammarException;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -77,8 +77,7 @@ class UnquotedUpperCaseNamingStrategyPostgresLiveTest {
|
||||
public Person fromDatabase(Object databaseRow) {
|
||||
Object[] typedDatabaseRow = (Object[]) databaseRow;
|
||||
|
||||
return new Person(
|
||||
((BigInteger) typedDatabaseRow[0]).longValue(),
|
||||
return new Person((Long) typedDatabaseRow[0],
|
||||
(String) typedDatabaseRow[1],
|
||||
(String) typedDatabaseRow[2]
|
||||
);
|
||||
|
||||
+1
-5
@@ -2,8 +2,4 @@ spring.datasource.url=jdbc:postgresql://localhost:5432/spring-strategy
|
||||
spring.datasource.username=postgres
|
||||
spring.datasource.password=root
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
|
||||
#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
|
||||
#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
|
||||
#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=default-naming-strategy-ddl.sql
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
+1
-5
@@ -2,8 +2,4 @@ spring.datasource.url=jdbc:h2:mem:spring-strategy
|
||||
spring.datasource.username=sa
|
||||
spring.datasource.password=
|
||||
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
spring.jpa.hibernate.naming.physical-strategy=org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
|
||||
#spring.jpa.properties.javax.persistence.schema-generation.create-source=metadata
|
||||
#spring.jpa.properties.javax.persistence.schema-generation.scripts.action=create
|
||||
#spring.jpa.properties.javax.persistence.schema-generation.scripts.create-target=default-naming-strategy-ddl.sql
|
||||
spring.jpa.hibernate.ddl-auto=create-drop
|
||||
@@ -34,11 +34,13 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-oxm</artifactId>
|
||||
<version>${spring-oxm.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<datasource-proxy.version>1.4.1</datasource-proxy.version>
|
||||
<spring-oxm.version>6.1.4</spring-oxm.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -41,6 +41,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-oxm</artifactId>
|
||||
<version>${spring-oxm.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
@@ -74,4 +75,8 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<spring-oxm.version>6.1.4</spring-oxm.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<artifactId>parent-boot-3</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
<relativePath>../../parent-boot-3</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
@@ -78,6 +78,7 @@
|
||||
<mysema.maven.version>1.1.3</mysema.maven.version>
|
||||
<projectreactor.version>3.5.4</projectreactor.version>
|
||||
<embed.mongo.version>4.6.3</embed.mongo.version>
|
||||
<start-class>com.baeldung.Main</start-class>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
+8
@@ -1,11 +1,14 @@
|
||||
package com.baeldung.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration;
|
||||
import org.springframework.data.mongodb.repository.config.EnableReactiveMongoRepositories;
|
||||
|
||||
import com.mongodb.reactivestreams.client.MongoClient;
|
||||
import com.mongodb.reactivestreams.client.MongoClients;
|
||||
import org.springframework.transaction.ReactiveTransactionManager;
|
||||
import org.springframework.transaction.reactive.TransactionalOperator;
|
||||
|
||||
@Configuration
|
||||
@EnableReactiveMongoRepositories(basePackages = "com.baeldung.reactive.repository")
|
||||
@@ -20,4 +23,9 @@ public class MongoReactiveConfig extends AbstractReactiveMongoConfiguration {
|
||||
protected String getDatabaseName() {
|
||||
return "reactive";
|
||||
}
|
||||
|
||||
@Bean
|
||||
public TransactionalOperator transactionalOperator(ReactiveTransactionManager reactiveTransactionManager) {
|
||||
return TransactionalOperator.create(reactiveTransactionManager);
|
||||
}
|
||||
}
|
||||
|
||||
+14
-3
@@ -6,11 +6,14 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoOperations;
|
||||
import org.springframework.data.mongodb.core.ReactiveMongoTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.baeldung.config.MongoReactiveConfig;
|
||||
import com.baeldung.model.User;
|
||||
import org.springframework.transaction.reactive.TransactionalOperator;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -25,6 +28,12 @@ public class MongoTransactionReactiveLiveTest {
|
||||
@Autowired
|
||||
private ReactiveMongoOperations reactiveOps;
|
||||
|
||||
@Autowired
|
||||
private TransactionalOperator transactionalOperator;
|
||||
|
||||
@Autowired
|
||||
private ReactiveMongoTemplate mongoTemplate;
|
||||
|
||||
@Before
|
||||
public void testSetup() {
|
||||
if (!reactiveOps.collectionExists(User.class)
|
||||
@@ -45,9 +54,11 @@ public class MongoTransactionReactiveLiveTest {
|
||||
public void whenPerformTransaction_thenSuccess() {
|
||||
User user1 = new User("Jane", 23);
|
||||
User user2 = new User("John", 34);
|
||||
reactiveOps.inTransaction()
|
||||
.execute(action -> action.insert(user1)
|
||||
.then(action.insert(user2)));
|
||||
|
||||
Mono<User> saveEntity1 = mongoTemplate.save(user1);
|
||||
Mono<User> saveEntity2 = mongoTemplate.save(user2);
|
||||
|
||||
saveEntity1.then(saveEntity2).then().as(transactionalOperator::transactional);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user