Merge branch 'master' of https://github.com/eugenp/tutorials into BAEL_3301_testing_@ConfigurationProperties

This commit is contained in:
m.raheem 2020-02-20 07:26:05 +02:00
commit b09f1d7fa9
224 changed files with 2363 additions and 627 deletions

View File

@ -106,7 +106,7 @@
<arguments>
<argument>java</argument>
<argument>-jar</argument>
<argument>sample-blade-app.jar</argument>
<argument>blade.jar</argument>
</arguments>
</configuration>
</execution>

View File

@ -0,0 +1,5 @@
## Core Java Arrays (Part 3)
This module contains articles about Java arrays
## Relevant Articles

View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>core-java-arrays-3</artifactId>
<version>0.1.0-SNAPSHOT</version>
<name>core-java-arrays-3</name>
<packaging>jar</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-java</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<assertj.version>3.14.0</assertj.version>
</properties>
</project>

View File

@ -0,0 +1,96 @@
package com.baeldung.arrays.deepequals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.Objects;
import org.junit.jupiter.api.Test;
public class ArraysDeepEqualsUnitTest {
class Person {
private int id;
private String name;
private int age;
Person(int id, String name, int age) {
this.id = id;
this.name = name;
this.age = age;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof Person))
return false;
Person person = (Person) obj;
return id == person.id && name.equals(person.name) && age == person.age;
}
@Override
public int hashCode() {
return Objects.hash(id, name, age);
}
}
@Test
void givenTwoUnidimensionalObjectTypeArrays_whenUsingEqualsAndDeepEquals_thenBothShouldReturnTrue() {
Object[] anArray = new Object[] { "string1", "string2", "string3" };
Object[] anotherArray = new Object[] { "string1", "string2", "string3" };
assertTrue(Arrays.equals(anArray, anotherArray));
assertTrue(Arrays.deepEquals(anArray, anotherArray));
}
@Test
void givenTwoUnidimensionalObjectTypeArraysWithNullElements_whenUsingEqualsAndDeepEquals_thenBothShouldReturnTrue() {
Object[] anArray = new Object[] { "string1", null, "string3" };
Object[] anotherArray = new Object[] { "string1", null, "string3" };
assertTrue(Arrays.equals(anArray, anotherArray));
assertTrue(Arrays.deepEquals(anArray, anotherArray));
}
@Test
void givenTwoUnidimensionalObjectTypeArraysWithNestedElements_whenUsingEqualsAndDeepEquals_thenShouldReturnDifferently() {
Object[] anArray = new Object[] { "string1", null, new String[] { "nestedString1", "nestedString2" } };
Object[] anotherArray = new Object[] { "string1", null, new String[] { "nestedString1", "nestedString2" } };
assertFalse(Arrays.equals(anArray, anotherArray));
assertTrue(Arrays.deepEquals(anArray, anotherArray));
}
@Test
void givenTwoMultidimensionalPrimitiveTypeArrays_whenUsingEqualsAndDeepEquals_thenBothShouldReturnDifferently() {
int[][] anArray = { { 1, 2, 3 }, { 4, 5, 6, 9 }, { 7 } };
int[][] anotherArray = { { 1, 2, 3 }, { 4, 5, 6, 9 }, { 7 } };
assertFalse(Arrays.equals(anArray, anotherArray));
assertTrue(Arrays.deepEquals(anArray, anotherArray));
}
@Test
void givenTwoMultidimensionalObjectTypeArrays_whenUsingEqualsAndDeepEquals_thenBothShouldReturnDifferently() {
Person personArray1[][] = { { new Person(1, "John", 22), new Person(2, "Mike", 23) }, { new Person(3, "Steve", 27), new Person(4, "Gary", 28) } };
Person personArray2[][] = { { new Person(1, "John", 22), new Person(2, "Mike", 23) }, { new Person(3, "Steve", 27), new Person(4, "Gary", 28) } };
assertFalse(Arrays.equals(personArray1, personArray2));
assertTrue(Arrays.deepEquals(personArray1, personArray2));
}
@Test
void givenTwoMultidimensionalObjectTypeArrays_whenUsingDeepEqualsFromObjectsAndArraysClasses_thenBothShouldReturnTrue() {
Person personArray1[][] = { { new Person(1, "John", 22), new Person(2, "Mike", 23) }, { new Person(3, "Steve", 27), new Person(4, "Gary", 28) } };
Person personArray2[][] = { { new Person(1, "John", 22), new Person(2, "Mike", 23) }, { new Person(3, "Steve", 27), new Person(4, "Gary", 28) } };
assertTrue(Objects.deepEquals(personArray1, personArray2));
assertTrue(Arrays.deepEquals(personArray1, personArray2));
}
}

View File

@ -1,134 +0,0 @@
package com.baeldung.readfile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
public class FileOperationsManualTest {
@Test
public void givenFileName_whenUsingClassloader_thenFileData() throws IOException {
String expectedData = "Hello World from fileTest.txt!!!";
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("fileTest.txt").getFile());
InputStream inputStream = new FileInputStream(file);
String data = readFromInputStream(inputStream);
assertEquals(expectedData, data.trim());
}
@Test
public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws IOException {
String expectedData = "Hello World from fileTest.txt!!!";
Class clazz = FileOperationsManualTest.class;
InputStream inputStream = clazz.getResourceAsStream("/fileTest.txt");
String data = readFromInputStream(inputStream);
assertEquals(expectedData, data.trim());
}
@Test
public void givenFileName_whenUsingJarFile_thenFileData() throws IOException {
String expectedData = "MIT License";
Class clazz = Matchers.class;
InputStream inputStream = clazz.getResourceAsStream("/LICENSE.txt");
String data = readFromInputStream(inputStream);
assertThat(data.trim(), CoreMatchers.containsString(expectedData));
}
@Test
public void givenURLName_whenUsingURL_thenFileData() throws IOException {
String expectedData = "Example Domain";
URL urlObject = new URL("http://www.example.com/");
URLConnection urlConnection = urlObject.openConnection();
InputStream inputStream = urlConnection.getInputStream();
String data = readFromInputStream(inputStream);
assertThat(data.trim(), CoreMatchers.containsString(expectedData));
}
@Test
public void givenFileName_whenUsingFileUtils_thenFileData() throws IOException {
String expectedData = "Hello World from fileTest.txt!!!";
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("fileTest.txt").getFile());
String data = FileUtils.readFileToString(file, "UTF-8");
assertEquals(expectedData, data.trim());
}
@Test
public void givenFilePath_whenUsingFilesReadAllBytes_thenFileData() throws IOException, URISyntaxException {
String expectedData = "Hello World from fileTest.txt!!!";
Path path = Paths.get(getClass().getClassLoader().getResource("fileTest.txt").toURI());
byte[] fileBytes = Files.readAllBytes(path);
String data = new String(fileBytes);
assertEquals(expectedData, data.trim());
}
@Test
public void givenFilePath_whenUsingFilesLines_thenFileData() throws IOException, URISyntaxException {
String expectedData = "Hello World from fileTest.txt!!!";
Path path = Paths.get(getClass().getClassLoader().getResource("fileTest.txt").toURI());
Stream<String> lines = Files.lines(path);
String data = lines.collect(Collectors.joining("\n"));
lines.close();
assertEquals(expectedData, data.trim());
}
private String readFromInputStream(InputStream inputStream) throws IOException {
StringBuilder resultStringBuilder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
resultStringBuilder.append(line).append("\n");
}
}
return resultStringBuilder.toString();
}
@Test
public void givenFileName_whenUsingIOUtils_thenFileData() throws IOException {
String expectedData = "This is a content of the file";
FileInputStream fis = new FileInputStream("src/test/resources/fileToRead.txt");
String data = IOUtils.toString(fis, "UTF-8");
assertEquals(expectedData, data.trim());
}
}

View File

@ -1,11 +1,15 @@
package com.baeldung.readfile;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.Ignore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.*;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.Charset;
@ -13,55 +17,148 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class JavaReadFromFileUnitTest {
private static final Logger LOG = LoggerFactory.getLogger(JavaReadFromFileUnitTest.class);
@Test
public void whenReadWithBufferedReader_thenCorrect() throws IOException {
final String expected_value = "Hello world";
final String expected_value = "Hello, world!";
final BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/test_read.in"));
final BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/fileTest.txt"));
final String currentLine = reader.readLine();
reader.close();
assertEquals(expected_value, currentLine);
}
@Test
public void givenFileName_whenUsingClassloader_thenFileData() throws IOException {
String expectedData = "Hello, world!";
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("fileTest.txt").getFile());
InputStream inputStream = new FileInputStream(file);
String data = readFromInputStream(inputStream);
assertEquals(expectedData, data.trim());
}
@Test
public void givenFileNameAsAbsolutePath_whenUsingClasspath_thenFileData() throws IOException {
String expectedData = "Hello, world!";
Class clazz = JavaReadFromFileUnitTest.class;
InputStream inputStream = clazz.getResourceAsStream("/fileTest.txt");
String data = readFromInputStream(inputStream);
assertEquals(expectedData, data.trim());
}
@Test
public void givenFileName_whenUsingJarFile_thenFileData() throws IOException {
String expectedData = "BSD License";
Class clazz = Matchers.class;
InputStream inputStream = clazz.getResourceAsStream("/LICENSE.txt");
String data = readFromInputStream(inputStream);
assertThat(data.trim(), CoreMatchers.containsString(expectedData));
}
@Test
public void givenURLName_whenUsingURL_thenFileData() throws IOException {
String expectedData = "Example Domain";
URL urlObject = new URL("http://www.example.com/");
URLConnection urlConnection = urlObject.openConnection();
InputStream inputStream = urlConnection.getInputStream();
String data = readFromInputStream(inputStream);
assertThat(data.trim(), CoreMatchers.containsString(expectedData));
}
@Test
public void givenFileName_whenUsingFileUtils_thenFileData() throws IOException {
String expectedData = "Hello, world!";
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(classLoader.getResource("fileTest.txt").getFile());
String data = FileUtils.readFileToString(file, "UTF-8");
assertEquals(expectedData, data.trim());
}
@Test
public void givenFilePath_whenUsingFilesReadAllBytes_thenFileData() throws IOException, URISyntaxException {
String expectedData = "Hello, world!";
Path path = Paths.get(getClass().getClassLoader().getResource("fileTest.txt").toURI());
byte[] fileBytes = Files.readAllBytes(path);
String data = new String(fileBytes);
assertEquals(expectedData, data.trim());
}
@Test
public void givenFilePath_whenUsingFilesLines_thenFileData() throws IOException, URISyntaxException {
String expectedData = "Hello, world!";
Path path = Paths.get(getClass().getClassLoader().getResource("fileTest.txt").toURI());
Stream<String> lines = Files.lines(path);
String data = lines.collect(Collectors.joining("\n"));
lines.close();
assertEquals(expectedData, data.trim());
}
@Test
public void givenFileName_whenUsingIOUtils_thenFileData() throws IOException {
String expectedData = "Hello, world!";
FileInputStream fis = new FileInputStream("src/test/resources/fileTest.txt");
String data = IOUtils.toString(fis, "UTF-8");
assertEquals(expectedData, data.trim());
}
@Test
public void whenReadWithScanner_thenCorrect() throws IOException {
final Scanner scanner = new Scanner(new File("src/test/resources/test_read1.in"));
final Scanner scanner = new Scanner(new File("src/test/resources/fileTest.txt"));
scanner.useDelimiter(" ");
assertTrue(scanner.hasNext());
assertEquals("Hello", scanner.next());
assertEquals("world", scanner.next());
assertEquals(1, scanner.nextInt());
assertEquals("Hello,", scanner.next());
assertEquals("world!", scanner.next());
scanner.close();
}
@Test
public void whenReadWithScannerTwoDelimiters_thenCorrect() throws IOException {
final Scanner scanner = new Scanner(new File("src/test/resources/test_read2.in"));
scanner.useDelimiter(",| ");
final Scanner scanner = new Scanner(new File("src/test/resources/fileTest.txt"));
scanner.useDelimiter("\\s|,");
assertTrue(scanner.hasNextInt());
assertEquals(2, scanner.nextInt());
assertEquals(3, scanner.nextInt());
assertEquals(4, scanner.nextInt());
assertTrue(scanner.hasNext());
assertEquals("Hello", scanner.next());
assertEquals("", scanner.next());
assertEquals("world!", scanner.next());
scanner.close();
}
@Test
public void whenReadWithStreamTokenizer_thenCorrectTokens() throws IOException {
final FileReader reader = new FileReader("src/test/resources/test_read3.in");
final FileReader reader = new FileReader("src/test/resources/fileTestTokenizer.txt");
final StreamTokenizer tokenizer = new StreamTokenizer(reader);
tokenizer.nextToken();
@ -78,49 +175,36 @@ public class JavaReadFromFileUnitTest {
@Test
public void whenReadWithDataInputStream_thenCorrect() throws IOException {
final String expected_value = "Hello";
String expectedValue = "Hello, world!";
String file ="src/test/resources/fileTest.txt";
String result;
final DataInputStream reader = new DataInputStream(new FileInputStream("src/test/resources/test_read4.in"));
result = reader.readUTF();
reader.close();
String result = null;
assertEquals(expected_value, result);
DataInputStream reader = new DataInputStream(new FileInputStream(file));
int nBytesToRead = reader.available();
if(nBytesToRead > 0) {
byte[] bytes = new byte[nBytesToRead];
reader.read(bytes);
result = new String(bytes);
}
public void whenReadTwoFilesWithSequenceInputStream_thenCorrect() throws IOException {
final int expected_value1 = 2000;
final int expected_value2 = 5000;
final FileInputStream stream1 = new FileInputStream("src/test/resources/test_read5.in");
final FileInputStream stream2 = new FileInputStream("src/test/resources/test_read6.in");
final SequenceInputStream sequence = new SequenceInputStream(stream1, stream2);
final DataInputStream reader = new DataInputStream(sequence);
assertEquals(expected_value1, reader.readInt());
assertEquals(expected_value2, reader.readInt());
reader.close();
stream2.close();
assertEquals(expectedValue, result);
}
@Test
@Ignore // TODO
public void whenReadUTFEncodedFile_thenCorrect() throws IOException {
final String expected_value = "青空";
final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/test_read7.in"), "UTF-8"));
final BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("src/test/resources/fileTestUtf8.txt"), "UTF-8"));
final String currentLine = reader.readLine();
reader.close();
LOG.debug(currentLine);
assertEquals(expected_value, currentLine);
}
@Test
public void whenReadFileContentsIntoString_thenCorrect() throws IOException {
final String expected_value = "Hello world \n Test line \n";
final BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/test_read8.in"));
final String expected_value = "Hello, world!\n";
final BufferedReader reader = new BufferedReader(new FileReader("src/test/resources/fileTest.txt"));
final StringBuilder builder = new StringBuilder();
String currentLine = reader.readLine();
while (currentLine != null) {
@ -136,8 +220,8 @@ public class JavaReadFromFileUnitTest {
@Test
public void whenReadWithFileChannel_thenCorrect() throws IOException {
final String expected_value = "Hello world";
final RandomAccessFile reader = new RandomAccessFile("src/test/resources/test_read.in", "r");
final String expected_value = "Hello, world!";
final RandomAccessFile reader = new RandomAccessFile("src/test/resources/fileTest.txt", "r");
final FileChannel channel = reader.getChannel();
int bufferSize = 1024;
@ -154,8 +238,8 @@ public class JavaReadFromFileUnitTest {
@Test
public void whenReadSmallFileJava7_thenCorrect() throws IOException {
final String expected_value = "Hello world";
final Path path = Paths.get("src/test/resources/test_read.in");
final String expected_value = "Hello, world!";
final Path path = Paths.get("src/test/resources/fileTest.txt");
final String read = Files.readAllLines(path, Charset.defaultCharset()).get(0);
assertEquals(expected_value, read);
@ -163,12 +247,24 @@ public class JavaReadFromFileUnitTest {
@Test
public void whenReadLargeFileJava7_thenCorrect() throws IOException {
final String expected_value = "Hello world";
final String expected_value = "Hello, world!";
final Path path = Paths.get("src/test/resources/test_read.in");
final Path path = Paths.get("src/test/resources/fileTest.txt");
final BufferedReader reader = Files.newBufferedReader(path, Charset.defaultCharset());
final String line = reader.readLine();
assertEquals(expected_value, line);
}
private String readFromInputStream(InputStream inputStream) throws IOException {
StringBuilder resultStringBuilder = new StringBuilder();
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
String line;
while ((line = bufferedReader.readLine()) != null) {
resultStringBuilder.append(line).append("\n");
}
}
return resultStringBuilder.toString();
}
}

View File

@ -1 +1 @@
Hello World from fileTest.txt!!!
Hello, world!

View File

@ -1 +0,0 @@
Hello world 1

View File

@ -1,2 +0,0 @@
Hello world
Test line

View File

@ -31,6 +31,7 @@
<module>core-java-annotations</module>
<module>core-java-arrays</module>
<module>core-java-arrays-2</module>
<module>core-java-arrays-3</module>
<module>core-java-collections</module>
<module>core-java-collections-2</module>

View File

@ -20,6 +20,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>

View File

@ -1,13 +1,37 @@
package com.baeldung.dddhexagonalspring;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.PropertySource;
import com.baeldung.dddhexagonalspring.application.cli.CliOrderController;
@SpringBootApplication
@PropertySource(value = { "classpath:ddd-layers.properties" })
public class DomainLayerApplication {
public class DomainLayerApplication implements CommandLineRunner {
public static void main(final String[] args) {
SpringApplication.run(DomainLayerApplication.class, args);
SpringApplication application = new SpringApplication(DomainLayerApplication.class);
// uncomment to run just the console application
// application.setWebApplicationType(WebApplicationType.NONE);
application.run(args);
}
@Autowired
public CliOrderController orderController;
@Autowired
public ConfigurableApplicationContext context;
@Override
public void run(String... args) throws Exception {
orderController.createCompleteOrder();
orderController.createIncompleteOrder();
// uncomment to stop the context when execution is done
// context.close();
}
}

View File

@ -0,0 +1,47 @@
package com.baeldung.dddhexagonalspring.application.cli;
import java.math.BigDecimal;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.domain.service.OrderService;
@Component
public class CliOrderController {
private static final Logger LOG = LoggerFactory.getLogger(CliOrderController.class);
private final OrderService orderService;
@Autowired
public CliOrderController(OrderService orderService) {
this.orderService = orderService;
}
public void createCompleteOrder() {
LOG.info("<<Create complete order>>");
UUID orderId = createOrder();
orderService.completeOrder(orderId);
}
public void createIncompleteOrder() {
LOG.info("<<Create incomplete order>>");
UUID orderId = createOrder();
}
private UUID createOrder() {
LOG.info("Placing a new order with two products");
Product mobilePhone = new Product(UUID.randomUUID(), BigDecimal.valueOf(200), "mobile");
Product razor = new Product(UUID.randomUUID(), BigDecimal.valueOf(50), "razor");
LOG.info("Creating order with mobile phone");
UUID orderId = orderService.createOrder(mobilePhone);
LOG.info("Adding a razor to the order");
orderService.addProduct(orderId, razor);
return orderId;
}
}

View File

@ -1,4 +1,4 @@
package com.baeldung.dddhexagonalspring.application.controller;
package com.baeldung.dddhexagonalspring.application.rest;
import com.baeldung.dddhexagonalspring.application.request.AddProductRequest;
import com.baeldung.dddhexagonalspring.application.request.CreateOrderRequest;

View File

@ -4,6 +4,7 @@ import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
public class Order {
@ -40,10 +41,8 @@ public class Order {
}
private OrderItem getOrderItem(final UUID id) {
return orderItems
.stream()
.filter(orderItem -> orderItem
.getProductId()
return orderItems.stream()
.filter(orderItem -> orderItem.getProductId()
.equals(id))
.findFirst()
.orElseThrow(() -> new DomainException("Product with " + id + " doesn't exist."));
@ -77,6 +76,21 @@ public class Order {
return Collections.unmodifiableList(orderItems);
}
@Override
public int hashCode() {
return Objects.hash(id, orderItems, price, status);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!(obj instanceof Order))
return false;
Order other = (Order) obj;
return Objects.equals(id, other.id) && Objects.equals(orderItems, other.orderItems) && Objects.equals(price, other.price) && status == other.status;
}
private Order() {
}
}

View File

@ -0,0 +1,10 @@
package com.baeldung.dddhexagonalspring.infrastracture.configuration;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
import com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra.SpringDataCassandraOrderRepository;
@EnableCassandraRepositories(basePackageClasses = SpringDataCassandraOrderRepository.class)
public class CassandraConfiguration {
}

View File

@ -1,8 +1,9 @@
package com.baeldung.dddhexagonalspring.infrastracture.configuration;
import com.baeldung.dddhexagonalspring.infrastracture.repository.SpringDataOrderRepository;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
@EnableMongoRepositories(basePackageClasses = SpringDataOrderRepository.class)
import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository;
@EnableMongoRepositories(basePackageClasses = SpringDataMongoOrderRepository.class)
public class MongoDBConfiguration {
}

View File

@ -0,0 +1,38 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra;
import java.util.Optional;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.baeldung.dddhexagonalspring.domain.Order;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
@Component
public class CassandraDbOrderRepository implements OrderRepository {
private final SpringDataCassandraOrderRepository orderRepository;
@Autowired
public CassandraDbOrderRepository(SpringDataCassandraOrderRepository orderRepository) {
this.orderRepository = orderRepository;
}
@Override
public Optional<Order> findById(UUID id) {
Optional<OrderEntity> orderEntity = orderRepository.findById(id);
if (orderEntity.isPresent()) {
return Optional.of(orderEntity.get()
.toOrder());
} else {
return Optional.empty();
}
}
@Override
public void save(Order order) {
orderRepository.save(new OrderEntity(order));
}
}

View File

@ -0,0 +1,75 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
import com.baeldung.dddhexagonalspring.domain.Order;
import com.baeldung.dddhexagonalspring.domain.OrderItem;
import com.baeldung.dddhexagonalspring.domain.OrderStatus;
import com.baeldung.dddhexagonalspring.domain.Product;
public class OrderEntity {
@PrimaryKey
private UUID id;
private OrderStatus status;
private List<OrderItemEntity> orderItemEntities;
private BigDecimal price;
public OrderEntity(UUID id, OrderStatus status, List<OrderItemEntity> orderItemEntities, BigDecimal price) {
this.id = id;
this.status = status;
this.orderItemEntities = orderItemEntities;
this.price = price;
}
public OrderEntity() {
}
public OrderEntity(Order order) {
this.id = order.getId();
this.price = order.getPrice();
this.status = order.getStatus();
this.orderItemEntities = order.getOrderItems()
.stream()
.map(OrderItemEntity::new)
.collect(Collectors.toList());
}
public Order toOrder() {
List<OrderItem> orderItems = orderItemEntities.stream()
.map(OrderItemEntity::toOrderItem)
.collect(Collectors.toList());
List<Product> namelessProducts = orderItems.stream()
.map(orderItem -> new Product(orderItem.getProductId(), orderItem.getPrice(), ""))
.collect(Collectors.toList());
Order order = new Order(id, namelessProducts.remove(0));
namelessProducts.forEach(product -> order.addOrder(product));
if (status == OrderStatus.COMPLETED) {
order.complete();
}
return order;
}
public UUID getId() {
return id;
}
public OrderStatus getStatus() {
return status;
}
public List<OrderItemEntity> getOrderItems() {
return orderItemEntities;
}
public BigDecimal getPrice() {
return price;
}
}

View File

@ -0,0 +1,44 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra;
import java.math.BigDecimal;
import java.util.UUID;
import org.springframework.data.cassandra.core.mapping.UserDefinedType;
import com.baeldung.dddhexagonalspring.domain.OrderItem;
import com.baeldung.dddhexagonalspring.domain.Product;
@UserDefinedType
public class OrderItemEntity {
private UUID productId;
private BigDecimal price;
public OrderItemEntity() {
}
public OrderItemEntity(final OrderItem orderItem) {
this.productId = orderItem.getProductId();
this.price = orderItem.getPrice();
}
public OrderItem toOrderItem() {
return new OrderItem(new Product(productId, price, ""));
}
public UUID getProductId() {
return productId;
}
public void setProductId(UUID productId) {
this.productId = productId;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
}

View File

@ -0,0 +1,10 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra;
import java.util.UUID;
import org.springframework.data.cassandra.repository.CassandraRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface SpringDataCassandraOrderRepository extends CassandraRepository<OrderEntity, UUID> {
}

View File

@ -1,20 +1,23 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository;
import com.baeldung.dddhexagonalspring.domain.Order;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
package com.baeldung.dddhexagonalspring.infrastracture.repository.mongo;
import java.util.Optional;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import com.baeldung.dddhexagonalspring.domain.Order;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
@Component
@Primary
public class MongoDbOrderRepository implements OrderRepository {
private final SpringDataOrderRepository orderRepository;
private final SpringDataMongoOrderRepository orderRepository;
@Autowired
public MongoDbOrderRepository(final SpringDataOrderRepository orderRepository) {
public MongoDbOrderRepository(final SpringDataMongoOrderRepository orderRepository) {
this.orderRepository = orderRepository;
}

View File

@ -1,4 +1,4 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository;
package com.baeldung.dddhexagonalspring.infrastracture.repository.mongo;
import com.baeldung.dddhexagonalspring.domain.Order;
import org.springframework.data.mongodb.repository.MongoRepository;
@ -7,5 +7,5 @@ import org.springframework.stereotype.Repository;
import java.util.UUID;
@Repository
public interface SpringDataOrderRepository extends MongoRepository<Order, UUID> {
public interface SpringDataMongoOrderRepository extends MongoRepository<Order, UUID> {
}

View File

@ -1,5 +1,12 @@
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=order-database
spring.data.mongodb.username=order
spring.data.mongodb.password=order
spring.data.cassandra.keyspaceName=order_database
spring.data.cassandra.username=cassandra
spring.data.cassandra.password=cassandra
spring.data.cassandra.contactPoints=localhost
spring.data.cassandra.port=9042

View File

@ -0,0 +1,57 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.UUID;
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;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.baeldung.dddhexagonalspring.domain.Order;
import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
import com.baeldung.dddhexagonalspring.infrastracture.repository.cassandra.SpringDataCassandraOrderRepository;
@SpringJUnitConfig
@SpringBootTest
@TestPropertySource("classpath:ddd-layers-test.properties")
class CassandraDbOrderRepositoryIntegrationTest {
@Autowired
private SpringDataCassandraOrderRepository cassandraOrderRepository;
@Autowired
private OrderRepository orderRepository;
@AfterEach
void cleanUp() {
cassandraOrderRepository.deleteAll();
}
@Test
void shouldFindById_thenReturnOrder() {
// given
final UUID id = UUID.randomUUID();
final Order order = createOrder(id);
order.addOrder(new Product(UUID.randomUUID(), BigDecimal.TEN, "second"));
order.complete();
// when
orderRepository.save(order);
final Optional<Order> result = orderRepository.findById(id);
assertEquals(order, result.get());
}
private Order createOrder(UUID id) {
return new Order(id, new Product(UUID.randomUUID(), BigDecimal.TEN, "product"));
}
}

View File

@ -0,0 +1,55 @@
package com.baeldung.dddhexagonalspring.infrastracture.repository;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.math.BigDecimal;
import java.util.Optional;
import java.util.UUID;
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;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import com.baeldung.dddhexagonalspring.domain.Order;
import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.domain.repository.OrderRepository;
import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository;
@SpringJUnitConfig
@SpringBootTest
@TestPropertySource("classpath:ddd-layers-test.properties")
class MongoDbOrderRepositoryIntegrationTest {
@Autowired
private SpringDataMongoOrderRepository mongoOrderRepository;
@Autowired
private OrderRepository orderRepository;
@AfterEach
void cleanUp() {
mongoOrderRepository.deleteAll();
}
@Test
void shouldFindById_thenReturnOrder() {
// given
final UUID id = UUID.randomUUID();
final Order order = createOrder(id);
// when
orderRepository.save(order);
final Optional<Order> result = orderRepository.findById(id);
assertEquals(order, result.get());
}
private Order createOrder(UUID id) {
return new Order(id, new Product(UUID.randomUUID(), BigDecimal.TEN, "product"));
}
}

View File

@ -2,6 +2,9 @@ package com.baeldung.dddhexagonalspring.infrastracture.repository;
import com.baeldung.dddhexagonalspring.domain.Order;
import com.baeldung.dddhexagonalspring.domain.Product;
import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.MongoDbOrderRepository;
import com.baeldung.dddhexagonalspring.infrastracture.repository.mongo.SpringDataMongoOrderRepository;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@ -14,12 +17,12 @@ import static org.mockito.Mockito.*;
class MongoDbOrderRepositoryUnitTest {
private SpringDataOrderRepository springDataOrderRepository;
private SpringDataMongoOrderRepository springDataOrderRepository;
private MongoDbOrderRepository tested;
@BeforeEach
void setUp() {
springDataOrderRepository = mock(SpringDataOrderRepository.class);
springDataOrderRepository = mock(SpringDataMongoOrderRepository.class);
tested = new MongoDbOrderRepository(springDataOrderRepository);
}

View File

@ -4,4 +4,6 @@ To run this project, follow these steps:
* Run the application database by executing `docker-compose up` in this directory.
* Launch the Spring Boot Application (DomainLayerApplication).
* By default, application will connect to this database (configuration in *ddd-layers.properties*)
* By default, the application will connect to the one of the two databases (configuration in *ddd-layers.properties*)
* check `CassandraDbOrderRepository.java` and `MongoDbOrderRepository.java`
* switch between the databases by making one of the above beans primary using the `@Primary` annotation

View File

@ -0,0 +1,12 @@
CREATE KEYSPACE IF NOT exists order_database
WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};
CREATE TYPE IF NOT EXISTS order_database.orderitementity (productid uuid, price decimal);
CREATE TABLE IF NOT EXISTS order_database.orderentity(
id uuid,
status text,
orderitementities list<frozen<orderitementity>>,
price decimal,
primary key(id)
);

View File

@ -3,6 +3,7 @@ version: '3'
services:
order-mongo-database:
image: mongo:3.4.13
container_name: order-mongo-db
restart: always
ports:
- 27017:27017
@ -12,3 +13,18 @@ services:
MONGO_INITDB_DATABASE: order-database
volumes:
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
order-cassandra-database:
image: cassandra:3.11.5
container_name: order-cassandra-db
restart: always
ports:
- 9042:9042
order-cassandra-init:
image: cassandra:3.11.5
container_name: order-cassandra-db-init
depends_on:
- order-cassandra-database
volumes:
- ./cassandra-init.cql:/cassandra-init.cql:ro
command: bin/bash -c "echo Initializing cassandra schema... && sleep 30 && cqlsh -u cassandra -p cassandra -f cassandra-init.cql order-cassandra-db"

View File

@ -0,0 +1,12 @@
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.data.mongodb.host=127.0.0.1
spring.data.mongodb.port=27017
spring.data.mongodb.database=order-database
spring.data.mongodb.username=order
spring.data.mongodb.password=order
spring.data.cassandra.keyspaceName=order_database
spring.data.cassandra.username=cassandra
spring.data.cassandra.password=cassandra
spring.data.cassandra.contactPoints=127.0.0.1
spring.data.cassandra.port=9042

18
gradle-6/.gitignore vendored Normal file
View File

@ -0,0 +1,18 @@
# Gradle
.gradle
build
# Ignore Gradle GUI config
gradle-app.setting
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar
# Cache of project
.gradletasknamecache
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

View File

@ -0,0 +1,5 @@
subprojects {
repositories {
mavenCentral()
}
}

View File

@ -0,0 +1,37 @@
plugins {
base
}
description = """
Demonstrates Gradle Configuraiton Avoidance API. Creates a new configuration "extralibs" to
which we add dependencies. The custom task "copyExtraLibs" copies those dependencies to a new
build directory "extra-libs". This build uses the Task Configuraion Avoidance APIs which have
been marked stable in Gradle 6.0
""".trimIndent()
// extraLibs is a NamedDomainObjectProvider<Configuration!> - the Configuration object will not be
// realized until it is needed. In the meantime, the build may reference it by name
val extralibs by configurations.registering
dependencies {
// we can call extralibs.name without causing the extralibs to be realized
add(extralibs.name, "junit:junit:4.12")
}
// extraLibsDir is a Provider<Directory!> - the Directory object will not be realized until it is
// needed
val extraLibsDir = project.layout.buildDirectory.dir("extra-libs")
// copyExtraLibs is a TaskProvider<Copy!> - the task will not be realized until it is needed
val copyExtraLibs by tasks.registering(Copy::class) {
// the copy task's "from" and "into" APIs accept Provider types to support configuration
// avoidance
from(extralibs)
into(extraLibsDir)
}
// configures the "build" task only if it needs to be
tasks.build {
// dependsOn accepts a TaskProvider to avoid realizing the copyExtraLibs needlessly
dependsOn(copyExtraLibs)
}

View File

@ -0,0 +1,29 @@
plugins {
`java-library`
}
group = "com.baeldung"
version = "1.0.0"
dependencies {
api("io.reactivex.rxjava2:rxjava:2.2.16")
implementation("com.google.guava:guava") {
version {
require("10.0")
prefer("28.1-jre")
because("Only uses ImmutableList type, so any version since 2.0 will do, but tested with 28.1-jre")
}
}
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
}
tasks.compileJava {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
tasks.test {
useJUnitPlatform()
}

View File

@ -0,0 +1,24 @@
package com.baeldung.gradle;
import com.google.common.collect.ImmutableList;
import io.reactivex.Observable;
import java.util.List;
/**
* Demonstrates a library type that returns an RxJava type.
*/
public class RxHelloWorld {
/**
* @return an {@link Observable} that emits events "hello" and "world" before completing.
*/
public static Observable<String> hello() {
// Guava ImmutableList class is an implementation detail.
List<String> values = ImmutableList.of("hello", "world");
return Observable.fromIterable(values);
}
private RxHelloWorld() {
}
}

View File

@ -0,0 +1,14 @@
package com.baeldung.gradle;
import org.junit.jupiter.api.Test;
import static com.baeldung.gradle.RxHelloWorld.hello;
/**
* Unit test for {@link RxHelloWorld}.
*/
final class RxHelloWorldUnitTest {
@Test void it_emits_hello_world_values() {
hello().test().assertValues("hello", "world").assertComplete();
}
}

View File

@ -0,0 +1,17 @@
plugins {
`java-library`
}
dependencies {
api(project(":fibonacci-spi"))
compileOnly("com.google.auto.service:auto-service-annotations:1.0-rc6")
annotationProcessor("com.google.auto.service:auto-service:1.0-rc6")
testImplementation(testFixtures(project(":fibonacci-spi")))
testImplementation("org.junit.jupiter:junit-jupiter-api:5.5.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.5.2")
}
tasks.test {
useJUnitPlatform()
}

View File

@ -0,0 +1,20 @@
package com.baeldung.fibonacci.impl;
import com.baeldung.fibonacci.FibonacciSequenceGenerator;
import com.google.auto.service.AutoService;
/**
* Recursive implementation of the {@link FibonacciSequenceGenerator}.
*/
@AutoService(FibonacciSequenceGenerator.class) public final class RecursiveFibonacci implements FibonacciSequenceGenerator {
@Override public int generate(int nth) {
if (nth < 0) {
throw new IllegalArgumentException("sequence number must be 0 or greater");
}
if (nth <= 1) {
return nth;
}
return generate(nth - 1) + generate(nth - 2);
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.fibonacci.impl;
import com.baeldung.fibonacci.FibonacciSequenceGenerator;
import com.baeldung.fibonacci.FibonacciSequenceGeneratorFixture;
/**
* Unit test which reuses the {@link FibonacciSequenceGeneratorFixture} test mix-in exported from the fibonacci-spi project.
*/
final class RecursiveFibonacciUnitTest implements FibonacciSequenceGeneratorFixture {
@Override public FibonacciSequenceGenerator provide() {
return new RecursiveFibonacci();
}
}

View File

@ -0,0 +1,13 @@
plugins {
`java-library`
`java-test-fixtures`
}
dependencies {
testFixturesApi("org.junit.jupiter:junit-jupiter-api:5.5.2")
testFixturesImplementation("org.junit.jupiter:junit-jupiter-engine:5.5.2")
}
tasks.test {
useJUnitPlatform()
}

View File

@ -0,0 +1,13 @@
package com.baeldung.fibonacci;
/**
* Describes an SPI for a Fibonacci sequence generator function.
*/
public interface FibonacciSequenceGenerator {
/**
* @param nth the index of the number in the fibonacci sequence
* @return the nth number in the fibonacci sequence
*/
int generate(int nth);
}

View File

@ -0,0 +1,30 @@
package com.baeldung.fibonacci;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Reusable test fixture for {@link FibonacciSequenceGenerator} implementations. Tests will be skipped if no such implementation exists.
*/
public interface FibonacciSequenceGeneratorFixture {
/**
* @return the implementation of {@link FibonacciSequenceGenerator} to test. Must not be null
*/
FibonacciSequenceGenerator provide();
@Test default void when_sequence_index_is_negative_then_throws() {
final FibonacciSequenceGenerator generator = provide();
assertThrows(IllegalArgumentException.class, () -> generator.generate(-1));
}
@Test default void when_given_index_then_generates_fibonacci_number() {
final FibonacciSequenceGenerator generator = provide();
final int[] sequence = { 0, 1, 1, 2, 3, 5, 8 };
for (int i = 0; i < sequence.length; i++) {
assertEquals(sequence[i], generator.generate(i));
}
}
}

View File

@ -0,0 +1,2 @@
org.gradle.parallel=true
org.gradle.configureondemand=true

Binary file not shown.

View File

@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.0.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

183
gradle-6/gradlew vendored Executable file
View File

@ -0,0 +1,183 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

100
gradle-6/gradlew.bat vendored Normal file
View File

@ -0,0 +1,100 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

View File

@ -0,0 +1,11 @@
plugins {
`java-platform`
}
dependencies {
constraints {
api("org.apache.httpcomponents:fluent-hc:4.5.10")
api("org.apache.httpcomponents:httpclient:4.5.10")
runtime("commons-logging:commons-logging:1.2")
}
}

View File

@ -0,0 +1,12 @@
plugins {
java
`maven-publish`
}
publishing {
publications {
register<MavenPublication>("mavenJava") {
from(components["java"])
}
}
}

View File

@ -0,0 +1,8 @@
plugins {
`java-library`
}
dependencies {
api(platform(project(":httpclient-platform")))
implementation("org.apache.httpcomponents:fluent-hc")
}

View File

@ -0,0 +1,10 @@
rootProject.name = "gradle-6"
include("configuration-avoidance")
include("dependency-constraints")
include("fibonacci-spi")
include("fibonacci-recursive")
include("httpclient-platform")
include("module-metadata-publishing")
include("person-rest-client")
include("widget-rest-client")

View File

@ -0,0 +1,8 @@
plugins {
`java-library`
}
dependencies {
api(platform(project(":httpclient-platform")))
implementation("org.apache.httpcomponents:httpclient")
}

View File

@ -4,8 +4,8 @@ This module contains articles about Spring with Hibernate 3
### Relevant Articles:
- [Hibernate 3 with Spring](http://www.baeldung.com/hibernate3-spring)
- [HibernateException: No Hibernate Session Bound to Thread in Hibernate 3](http://www.baeldung.com/no-hibernate-session-bound-to-thread-exception)
- [Hibernate 3 with Spring](https://www.baeldung.com/hibernate3-spring)
- [HibernateException: No Hibernate Session Bound to Thread in Hibernate 3](https://www.baeldung.com/no-hibernate-session-bound-to-thread-exception)
### Quick Start

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import java.io.Serializable;
import java.util.List;

View File

@ -1,7 +1,7 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import org.baeldung.persistence.model.Event;
import com.baeldung.persistence.model.Event;
import org.springframework.stereotype.Repository;
@Repository

View File

@ -1,6 +1,6 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.model.Foo;
import org.springframework.stereotype.Repository;
@Repository

View File

@ -0,0 +1,8 @@
package com.baeldung.persistence.dao;
import com.baeldung.persistence.model.Event;
public interface IEventDao extends IOperations<Event> {
//
}

View File

@ -0,0 +1,7 @@
package com.baeldung.persistence.dao;
import com.baeldung.persistence.model.Foo;
public interface IFooDao extends IOperations<Foo> {
//
}

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.dao;
package com.baeldung.persistence.dao;
import java.io.Serializable;
import java.util.List;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.model;
package com.baeldung.persistence.model;
import java.io.Serializable;

View File

@ -1,4 +1,4 @@
package org.baeldung.persistence.model;
package com.baeldung.persistence.model;
import java.io.Serializable;

View File

@ -1,8 +1,8 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import org.baeldung.persistence.dao.IEventDao;
import org.baeldung.persistence.model.Event;
import com.baeldung.persistence.model.Event;
import com.baeldung.persistence.dao.IEventDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

View File

@ -1,7 +1,7 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import org.baeldung.persistence.dao.IFooDao;
import org.baeldung.persistence.model.Foo;
import com.baeldung.persistence.dao.IFooDao;
import com.baeldung.persistence.model.Foo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring;
package com.baeldung.spring;
import java.util.Properties;
@ -22,7 +22,7 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "org.baeldung.persistence.dao", "org.baeldung.persistence.service" })
@ComponentScan({ "com.baeldung.persistence.dao", "com.baeldung.persistence.service" })
public class PersistenceConfig {
@Autowired
@ -36,7 +36,7 @@ public class PersistenceConfig {
public AnnotationSessionFactoryBean sessionFactory() {
final AnnotationSessionFactoryBean sessionFactory = new AnnotationSessionFactoryBean();
sessionFactory.setDataSource(dataSource());
sessionFactory.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
sessionFactory.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
sessionFactory.setHibernateProperties(hibernateProperties());
return sessionFactory;

View File

@ -1,4 +1,4 @@
package org.baeldung.spring;
package com.baeldung.spring;
import java.util.Properties;
@ -24,7 +24,7 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "org.baeldung.persistence.dao", "org.baeldung.persistence.service" })
@ComponentScan({ "com.baeldung.persistence.dao", "com.baeldung.persistence.service" })
public class PersistenceConfigHibernate3 {
@Autowired

View File

@ -1,4 +1,4 @@
package org.baeldung.spring;
package com.baeldung.spring;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
@ -6,7 +6,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
// @Configuration
@EnableTransactionManagement
@ComponentScan({ "org.baeldung.persistence.dao", "org.baeldung.persistence.service" })
@ComponentScan({ "com.baeldung.persistence.dao", "com.baeldung.persistence.service" })
@ImportResource({ "classpath:persistenceConfig.xml" })
public class PersistenceXmlConfig {

View File

@ -1,9 +0,0 @@
package org.baeldung.persistence.dao;
import org.baeldung.persistence.model.Event;
public interface IEventDao extends IOperations<Event> {
//
}

View File

@ -1,7 +0,0 @@
package org.baeldung.persistence.dao;
import org.baeldung.persistence.model.Foo;
public interface IFooDao extends IOperations<Foo> {
//
}

View File

@ -4,6 +4,6 @@
"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<mapping class="org.baeldung.persistence.model.Event" />
<mapping class="com.baeldung.persistence.model.Event" />
</session-factory>
</hibernate-configuration>

View File

@ -16,7 +16,7 @@
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<context:annotation-config />
<context:component-scan base-package="org.baeldung.persistence" />
<context:component-scan base-package="com.baeldung.persistence" />
<context:property-placeholder location="classpath:persistence-h2.properties"/>

View File

@ -9,7 +9,7 @@
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="packagesToScan" value="org.baeldung.persistence.model"/>
<property name="packagesToScan" value="com.baeldung.persistence.model"/>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>

View File

@ -11,7 +11,7 @@
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>org.baeldung.spring</param-value>
<param-value>com.baeldung.spring</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

View File

@ -1,6 +1,6 @@
package org.baeldung;
package com.baeldung;
import org.baeldung.spring.PersistenceConfig;
import com.baeldung.spring.PersistenceConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;

View File

@ -1,10 +1,9 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import org.baeldung.persistence.model.Foo;
import org.baeldung.persistence.service.FooService;
import org.baeldung.spring.PersistenceConfig;
import com.baeldung.spring.PersistenceConfig;
import com.baeldung.persistence.model.Foo;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;

View File

@ -1,7 +1,7 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import org.baeldung.persistence.model.Event;
import org.baeldung.spring.PersistenceConfigHibernate3;
import com.baeldung.persistence.model.Event;
import com.baeldung.spring.PersistenceConfigHibernate3;
import org.hamcrest.core.IsInstanceOf;
import org.hibernate.HibernateException;
import org.junit.Ignore;

View File

@ -1,7 +1,7 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import org.baeldung.persistence.model.Event;
import org.baeldung.spring.PersistenceConfig;
import com.baeldung.persistence.model.Event;
import com.baeldung.spring.PersistenceConfig;
import org.hamcrest.core.IsInstanceOf;
import org.hibernate.HibernateException;
import org.junit.Ignore;

View File

@ -1,7 +1,7 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import org.baeldung.persistence.model.Event;
import org.baeldung.spring.PersistenceXmlConfig;
import com.baeldung.persistence.model.Event;
import com.baeldung.spring.PersistenceXmlConfig;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

View File

@ -1,6 +1,6 @@
package org.baeldung.persistence.service;
package com.baeldung.persistence.service;
import org.baeldung.persistence.model.Event;
import com.baeldung.persistence.model.Event;
import org.hibernate.HibernateException;
import org.junit.Ignore;
import org.junit.Rule;
@ -8,7 +8,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateSystemException;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@ -4,11 +4,11 @@ This module contains articles about Hibernate 5 with Spring.
### Relevant articles
- [Hibernate Many to Many Annotation Tutorial](http://www.baeldung.com/hibernate-many-to-many)
- [Programmatic Transactions in the Spring TestContext Framework](http://www.baeldung.com/spring-test-programmatic-transactions)
- [JPA Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries)
- [Introduction to Hibernate Search](http://www.baeldung.com/hibernate-search)
- [Hibernate Many to Many Annotation Tutorial](https://www.baeldung.com/hibernate-many-to-many)
- [Programmatic Transactions in the Spring TestContext Framework](https://www.baeldung.com/spring-test-programmatic-transactions)
- [JPA Criteria Queries](https://www.baeldung.com/hibernate-criteria-queries)
- [Introduction to Hibernate Search](https://www.baeldung.com/hibernate-search)
- [@DynamicUpdate with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-dynamicupdate)
- [Hibernate Second-Level Cache](http://www.baeldung.com/hibernate-second-level-cache)
- [Deleting Objects with Hibernate](http://www.baeldung.com/delete-with-hibernate)
- [Spring, Hibernate and a JNDI Datasource](http://www.baeldung.com/spring-persistence-jpa-jndi-datasource)
- [Hibernate Second-Level Cache](https://www.baeldung.com/hibernate-second-level-cache)
- [Deleting Objects with Hibernate](https://www.baeldung.com/delete-with-hibernate)
- [Spring, Hibernate and a JNDI Datasource](https://www.baeldung.com/spring-persistence-jpa-jndi-datasource)

View File

@ -1,4 +1,4 @@
package org.baeldung;
package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -3,13 +3,13 @@
This module contains articles about Spring with Hibernate 4
### Relevant Articles:
- [Guide to Hibernate 4 with Spring](http://www.baeldung.com/hibernate-4-spring)
- [Hibernate Pagination](http://www.baeldung.com/hibernate-pagination)
- [Sorting with Hibernate](http://www.baeldung.com/hibernate-sort)
- [Stored Procedures with Hibernate](http://www.baeldung.com/stored-procedures-with-hibernate-tutorial)
- [Hibernate: save, persist, update, merge, saveOrUpdate](http://www.baeldung.com/hibernate-save-persist-update-merge-saveorupdate)
- [Eager/Lazy Loading In Hibernate](http://www.baeldung.com/hibernate-lazy-eager-loading)
- [The DAO with Spring and Hibernate](http://www.baeldung.com/persistence-layer-with-spring-and-hibernate)
- [Guide to Hibernate 4 with Spring](https://www.baeldung.com/hibernate-4-spring)
- [Hibernate Pagination](https://www.baeldung.com/hibernate-pagination)
- [Sorting with Hibernate](https://www.baeldung.com/hibernate-sort)
- [Stored Procedures with Hibernate](https://www.baeldung.com/stored-procedures-with-hibernate-tutorial)
- [Hibernate: save, persist, update, merge, saveOrUpdate](https://www.baeldung.com/hibernate-save-persist-update-merge-saveorupdate)
- [Eager/Lazy Loading In Hibernate](https://www.baeldung.com/hibernate-lazy-eager-loading)
- [The DAO with Spring and Hibernate](https://www.baeldung.com/persistence-layer-with-spring-and-hibernate)
- [Auditing with JPA, Hibernate, and Spring Data JPA](https://www.baeldung.com/database-auditing-jpa)
### Quick Start

View File

@ -1,4 +1,4 @@
package org.baeldung;
package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;

View File

@ -4,13 +4,13 @@
### Relevant Articles:
- [The DAO with JPA and Spring](http://www.baeldung.com/spring-dao-jpa)
- [JPA Pagination](http://www.baeldung.com/jpa-pagination)
- [Sorting with JPA](http://www.baeldung.com/jpa-sort)
- [Self-Contained Testing Using an In-Memory Database](http://www.baeldung.com/spring-jpa-test-in-memory-database)
- [A Guide to Spring AbstractRoutingDatasource](http://www.baeldung.com/spring-abstract-routing-data-source)
- [Obtaining Auto-generated Keys in Spring JDBC](http://www.baeldung.com/spring-jdbc-autogenerated-keys)
- [Transactions with Spring 4 and JPA](http://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
- [The DAO with JPA and Spring](https://www.baeldung.com/spring-dao-jpa)
- [JPA Pagination](https://www.baeldung.com/jpa-pagination)
- [Sorting with JPA](https://www.baeldung.com/jpa-sort)
- [Self-Contained Testing Using an In-Memory Database](https://www.baeldung.com/spring-jpa-test-in-memory-database)
- [A Guide to Spring AbstractRoutingDatasource](https://www.baeldung.com/spring-abstract-routing-data-source)
- [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys)
- [Transactions with Spring 4 and JPA](https://www.baeldung.com/transaction-configuration-with-jpa-and-spring)
- [Use Criteria Queries in a Spring Data Application](https://www.baeldung.com/spring-data-criteria-queries)
- [Many-To-Many Relationship in JPA](https://www.baeldung.com/jpa-many-to-many)
- [Spring Persistence (Hibernate and JPA) with a JNDI datasource](https://www.baeldung.com/spring-persistence-hibernate-and-jpa-with-a-jndi-datasource/)

View File

@ -1,4 +1,4 @@
package org.baeldung.annotations;
package com.baeldung.annotations;
import java.io.Serializable;
import java.util.Optional;

View File

@ -1,4 +1,4 @@
package org.baeldung.annotations;
package com.baeldung.annotations;
import java.util.Date;
@ -8,7 +8,7 @@ import javax.persistence.NamedStoredProcedureQuery;
import javax.persistence.ParameterMode;
import javax.persistence.StoredProcedureParameter;
import org.baeldung.persistence.multiple.model.user.User;
import com.baeldung.persistence.multiple.model.user.User;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;

View File

@ -1,4 +1,4 @@
package org.baeldung.annotations;
package com.baeldung.annotations;
import javax.persistence.LockModeType;

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import java.util.Properties;
@ -25,8 +25,8 @@ import com.google.common.base.Preconditions;
@Configuration
@EnableTransactionManagement
@PropertySource({ "classpath:persistence-h2.properties" })
@ComponentScan({ "org.baeldung.persistence" })
@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
@ComponentScan({ "com.baeldung.persistence" })
@EnableJpaRepositories(basePackages = "com.baeldung.persistence.dao")
public class PersistenceJPAConfig {
@Autowired
@ -42,7 +42,7 @@ public class PersistenceJPAConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
em.setPackagesToScan(new String[] { "com.baeldung.persistence.model" });
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ImportResource;
@ -6,7 +6,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
// @Configuration
@EnableTransactionManagement
@ComponentScan({ "org.baeldung.persistence" })
@ComponentScan({ "com.baeldung.persistence" })
@ImportResource({ "classpath:jpaConfig.xml" })
public class PersistenceJPAConfigXml {

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -10,7 +10,7 @@ import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc
@Configuration
@ComponentScan({ "org.baeldung.web" })
@ComponentScan({ "com.baeldung.web" })
public class SpringWebConfig extends WebMvcConfigurerAdapter {
@Bean

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import java.util.Properties;
@ -18,7 +18,7 @@ import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableJpaRepositories(basePackages = "org.baeldung.inmemory.persistence.dao")
@EnableJpaRepositories(basePackages = "com.baeldung.inmemory.persistence.dao")
@PropertySource("persistence-student.properties")
@EnableTransactionManagement
public class StudentJpaConfig {
@ -41,7 +41,7 @@ public class StudentJpaConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan(new String[] { "org.baeldung.inmemory.persistence.model" });
em.setPackagesToScan(new String[] { "com.baeldung.inmemory.persistence.model" });
em.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
em.setJpaProperties(additionalProperties());
return em;

View File

@ -1,4 +1,4 @@
package org.baeldung.config;
package com.baeldung.config;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

View File

@ -1,4 +1,4 @@
package org.baeldung.dsrouting;
package com.baeldung.dsrouting;
import javax.sql.DataSource;

View File

@ -1,4 +1,4 @@
package org.baeldung.dsrouting;
package com.baeldung.dsrouting;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

View File

@ -1,4 +1,4 @@
package org.baeldung.dsrouting;
package com.baeldung.dsrouting;
public enum ClientDatabase {

Some files were not shown because too many files have changed in this diff Show More