From 2e4de12d4f77a3e3ede527ca2c1d1f3e9e4e6f67 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 5 Dec 2019 11:32:58 +0100 Subject: [PATCH 001/278] Hexagonal architecture: a quick and practical example --- hexagonal-architecture-poc/pom.xml | 44 +++++++++++++++++++ .../HexagonalArchitecturePocApplication.java | 13 ++++++ .../boundary/input/OrderService.java | 11 +++++ .../boundary/output/OrderRepository.java | 11 +++++ .../hexagonal/core/entities/Order.java | 27 ++++++++++++ .../core/services/OrderServiceImpl.java | 35 +++++++++++++++ .../hexagonal/outside/OrderController.java | 32 ++++++++++++++ .../src/main/resources/application.properties | 5 +++ 8 files changed, 178 insertions(+) create mode 100644 hexagonal-architecture-poc/pom.xml create mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java create mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java create mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java create mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java create mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java create mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java create mode 100644 hexagonal-architecture-poc/src/main/resources/application.properties diff --git a/hexagonal-architecture-poc/pom.xml b/hexagonal-architecture-poc/pom.xml new file mode 100644 index 0000000000..b31a6dec90 --- /dev/null +++ b/hexagonal-architecture-poc/pom.xml @@ -0,0 +1,44 @@ + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + com.baeldung + hexagonal-architecture-poc + 0.0.1-SNAPSHOT + hexagonal-architecture-poc + Demo project for Hexagonal Architecture POC + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + com.h2database + h2 + runtime + + + org.springframework.boot + spring-boot-starter-web + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java new file mode 100644 index 0000000000..1690fbbeb5 --- /dev/null +++ b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.hexagonal; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class HexagonalArchitecturePocApplication { + + public static void main(String[] args) { + SpringApplication.run(HexagonalArchitecturePocApplication.class, args); + } + +} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java new file mode 100644 index 0000000000..07793f75ab --- /dev/null +++ b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java @@ -0,0 +1,11 @@ +package com.baeldung.hexagonal.boundary.input; + +import org.springframework.stereotype.Service; + +import com.baeldung.hexagonal.core.entities.Order; + +@Service public interface OrderService { + Iterable getOrders(); + Order createOrder(Double total); + boolean registerOrder(Order order); +} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java new file mode 100644 index 0000000000..ea1d38d296 --- /dev/null +++ b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java @@ -0,0 +1,11 @@ +package com.baeldung.hexagonal.boundary.output; + +import java.util.List; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +import com.baeldung.hexagonal.core.entities.Order; + +@Repository public interface OrderRepository extends CrudRepository{ +} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java new file mode 100644 index 0000000000..db0c4efd54 --- /dev/null +++ b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java @@ -0,0 +1,27 @@ +package com.baeldung.hexagonal.core.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity @Table(name="Orders") public class Order { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; + Double total; + + public Order() { + super(); + } + public Double getTotal() { + return total; + } + public void setTotal(Double total) { + this.total = total; + } + public Long getId() { + return id; + } + + +} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java new file mode 100644 index 0000000000..d3d8f1ba6a --- /dev/null +++ b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java @@ -0,0 +1,35 @@ +package com.baeldung.hexagonal.core.services; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import com.baeldung.hexagonal.boundary.input.OrderService; +import com.baeldung.hexagonal.boundary.output.OrderRepository; +import com.baeldung.hexagonal.core.entities.Order; + +@Service public class OrderServiceImpl implements OrderService { + + @Autowired OrderRepository orderRepository; + + @Override + public Iterable getOrders() { + return orderRepository.findAll(); + } + + @Override + public boolean registerOrder(Order order) { + if (order.getTotal() > 0) + orderRepository.save(order); + else + return false; + + return true; + } + + @Override + public Order createOrder(Double total) { + Order order = new Order(); + order.setTotal(total); + return order; + } +} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java new file mode 100644 index 0000000000..85c2e42368 --- /dev/null +++ b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java @@ -0,0 +1,32 @@ +package com.baeldung.hexagonal.outside; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.hexagonal.boundary.input.OrderService; +import com.baeldung.hexagonal.core.entities.Order; + +@RestController public class OrderController { + + @Autowired OrderService orderService; + + @GetMapping(path = "/orders/list") + public Iterable getOrders(){ + return orderService.getOrders(); + } + + @GetMapping(path = "/orders/add") + public String placeOrder(@RequestParam Double total) { + boolean isPlaced = orderService.registerOrder(orderService.createOrder(total)); + return isPlaced ? "Ok" : "Nok"; + } + + @GetMapping(path = "/orders/add-commission") + public String placeCommissionOrder(@RequestParam Double total) { + boolean isPlaced = orderService.registerOrder(orderService.createOrder(total*1.05)); + return isPlaced ? "Ok" : "Nok"; + } + +} diff --git a/hexagonal-architecture-poc/src/main/resources/application.properties b/hexagonal-architecture-poc/src/main/resources/application.properties new file mode 100644 index 0000000000..bc2fdde8c1 --- /dev/null +++ b/hexagonal-architecture-poc/src/main/resources/application.properties @@ -0,0 +1,5 @@ +spring.datasource.url=jdbc:h2:mem:testdb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password=password +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect From b48f01d324bf1d3439eaa4b7337f541f842da0d0 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 23 Dec 2019 09:28:02 +0100 Subject: [PATCH 002/278] BAEL 3486 --- .../baeldung/algorithms/greedy/Follower.java | 20 ++++++ .../algorithms/greedy/FollowersPath.java | 44 +++++++++++++ .../algorithms/greedy/GreedyAlgorithm.java | 47 +++++++++++++ .../algorithms/greedy/NonGreedyAlgorithm.java | 44 +++++++++++++ .../algorithms/greedy/SocialConnector.java | 36 ++++++++++ .../algorithms/greedy/SocialUser.java | 38 +++++++++++ .../greedy/GreedyAlgorithmUnitTest.java | 66 +++++++++++++++++++ 7 files changed, 295 insertions(+) create mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java create mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java create mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java create mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java create mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java create mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java create mode 100644 algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java new file mode 100644 index 0000000000..e24b29f5cb --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java @@ -0,0 +1,20 @@ +package com.baeldung.algorithms.greedy; + +import lombok.Getter; + +public class Follower { + + @Getter String username; + @Getter long count; + + public Follower(String username, long count) { + super(); + this.username = username; + this.count = count; + } + + @Override + public String toString() { + return "User: " + username + ", Followers: " + count + "\n\r" ; + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java new file mode 100644 index 0000000000..932037edb1 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java @@ -0,0 +1,44 @@ +package com.baeldung.algorithms.greedy; + +import java.util.ArrayList; +import java.util.List; + +public class FollowersPath { + + private List accounts; + private long count; + + public FollowersPath() { + super(); + this.accounts = new ArrayList<>(); + } + + public List getAccounts() { + return accounts; + } + public long getCount() { + return count; + } + + public void addFollower(String username, long count) { + accounts.add(new Follower(username, count)); + } + + public void addCount(long count) { + this.count += count; + } + + @Override + public String toString() { + String details = ""; + for(Follower a : accounts) { + details+=a.toString() + ", "; + } + + return "Total: " + count + ", \n\r" + + " Details: { " + "\n\r" + + details + "\n\r" + + " }"; + } + +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java new file mode 100644 index 0000000000..891695e5dc --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java @@ -0,0 +1,47 @@ +package com.baeldung.algorithms.greedy; + +import java.util.List; + +public class GreedyAlgorithm { + + int currentLevel = 0; + final int maxLevel = 3; + SocialConnector sc; + FollowersPath fp; + + public GreedyAlgorithm(SocialConnector sc) { + super(); + this.sc = sc; + this.fp = new FollowersPath(); + } + + public long findMostFollowersPath(String account) throws Exception { + long max = 0; + SocialUser toFollow = null; + + List followers = sc.getFollowers(account); + for (SocialUser el : followers) { + long followersCount = el.getFollowersCount(); + if (followersCount > max) { + toFollow = el; + max = followersCount; + } + } + + if (currentLevel < maxLevel - 1) { + currentLevel++; + max += findMostFollowersPath(toFollow.getUsername()); + //fp.addFollower(toFollow.getUsername(), max); + //fp.addCount(max); + return max; + } else { + //fp.addFollower(toFollow.getUsername(), max); + //fp.addCount(max); + return max; + } + } + + public FollowersPath getFollowers() { + return fp; + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java new file mode 100644 index 0000000000..db8a47be11 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java @@ -0,0 +1,44 @@ +package com.baeldung.algorithms.greedy; + +import java.util.List; + +public class NonGreedyAlgorithm { + + int currentLevel = 0; + final int maxLevel = 3; + SocialConnector tc; + + public NonGreedyAlgorithm(SocialConnector tc, int level) { + super(); + this.tc = tc; + this.currentLevel = level; + } + + + public long findMostFollowersPath(String account) throws Exception { + List followers = tc.getFollowers(account); + long total = currentLevel > 0 ? followers.size() : 0; + + if (currentLevel < maxLevel ) { + currentLevel++; + + long[] count = new long[followers.size()]; + int i = 0; + for (SocialUser el : followers) { + NonGreedyAlgorithm sub = new NonGreedyAlgorithm(tc, currentLevel); + count[i] = sub.findMostFollowersPath(el.getUsername()); + i++; + } + + long max = 0; + for (; i > 0; i--) { + if (count[i-1] > max ) + max = count[i-1]; + } + + return total + max; + } + + return total; + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java new file mode 100644 index 0000000000..cdcf0df395 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java @@ -0,0 +1,36 @@ +package com.baeldung.algorithms.greedy; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; +import lombok.Setter; + +public class SocialConnector { + private boolean isCounterEnabled = true; + private int counter = 4; + @Getter @Setter List users; + + public SocialConnector() { + users = new ArrayList<>(); + } + + public boolean switchCounter() { + this.isCounterEnabled = !this.isCounterEnabled; + return this.isCounterEnabled; + } + + public List getFollowers(String account) throws Exception { + if (counter < 0) + throw new Exception ("API limit reached"); + else { + if(this.isCounterEnabled) counter--; + for(SocialUser user : users) { + if (user.getUsername().equals(account)) { + return user.getFollowers(); + } + } + } + return new ArrayList<>(); + } +} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java new file mode 100644 index 0000000000..33eab9e799 --- /dev/null +++ b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java @@ -0,0 +1,38 @@ +package com.baeldung.algorithms.greedy; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Getter; + +public class SocialUser { + + @Getter private String username; + @Getter private List followers; + + public SocialUser(String username) { + super(); + this.username = username; + this.followers = new ArrayList<>(); + } + + public SocialUser(String username, List followers) { + super(); + this.username = username; + this.followers = followers; + } + + public long getFollowersCount() { + return followers.size(); + } + + public void addFollowers(List followers) { + this.followers.addAll(followers); + } + + @Override + public boolean equals(Object obj) { + return ((SocialUser) obj).getUsername().equals(username); + } + +} diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java new file mode 100644 index 0000000000..3560657ace --- /dev/null +++ b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java @@ -0,0 +1,66 @@ +package com.baeldung.algorithms.greedy; + +import static org.junit.Assert.assertEquals; + +import java.util.Arrays; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class GreedyAlgorithmUnitTest { + + private SocialConnector prepareNetwork() { + SocialConnector sc = new SocialConnector(); + + SocialUser root = new SocialUser("root"); + SocialUser child1 = new SocialUser("child1"); + SocialUser child2 = new SocialUser("child2"); + SocialUser child3 = new SocialUser("child3"); + SocialUser child21 = new SocialUser("child21"); + SocialUser child211 = new SocialUser("child211"); + SocialUser child2111 = new SocialUser("child2111"); + SocialUser child31 = new SocialUser("child31"); + SocialUser child311 = new SocialUser("child311"); + SocialUser child3111 = new SocialUser("child3111"); + + + child211.addFollowers(Arrays.asList(new SocialUser[]{child2111})); + child311.addFollowers(Arrays.asList(new SocialUser[]{child3111})); + + child21.addFollowers(Arrays.asList(new SocialUser[]{child211})); + child31.addFollowers(Arrays.asList(new SocialUser[]{child311, + new SocialUser("child312"), new SocialUser("child313"), new SocialUser("child314")})); + + child1.addFollowers(Arrays.asList(new SocialUser[]{new SocialUser("child11"), new SocialUser("child12")})); + child2.addFollowers(Arrays.asList(new SocialUser[]{child21, new SocialUser("child22"), new SocialUser("child23")})); + child3.addFollowers(Arrays.asList(new SocialUser[]{child31})); + + root.addFollowers(Arrays.asList(new SocialUser[]{child1, child2, child3})); + + sc.setUsers(Arrays.asList(new SocialUser[]{root, child1, child2, child3, child21, child31, child311, child211})); + return sc; + } + + @Test + public void greedyAlgorithmTest() throws Exception { + GreedyAlgorithm ga = new GreedyAlgorithm(prepareNetwork()); + assertEquals(ga.findMostFollowersPath("root"), 5); + } + + @Test + public void nongreedyAlgorithmTest() throws Exception { + NonGreedyAlgorithm nga = new NonGreedyAlgorithm(prepareNetwork(), 0); + Assertions.assertThrows(Exception.class, () -> { + nga.findMostFollowersPath("root"); + }); + } + + @Test + public void nongreedyAlgorithmUnboundedTest() throws Exception { + SocialConnector sc = prepareNetwork(); + sc.switchCounter(); + NonGreedyAlgorithm nga = new NonGreedyAlgorithm(sc, 0); + assertEquals(nga.findMostFollowersPath("root"), 6); + } + +} \ No newline at end of file From 36350012225d15264bfd5165d0a5f3fd2a052668 Mon Sep 17 00:00:00 2001 From: Max <56247279+the-magic-max@users.noreply.github.com> Date: Wed, 15 Jan 2020 15:43:57 +0100 Subject: [PATCH 003/278] Redundant Variable 'config' Instead of initializing a local variable first and then return it, you could directly return a new Builder instance. -> return new Builder().uri(URL).build(); --- .../data/neo4j/config/MovieDatabaseNeo4jConfiguration.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java index 9bbc571aee..4e87c24614 100644 --- a/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java +++ b/persistence-modules/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jConfiguration.java @@ -16,8 +16,7 @@ public class MovieDatabaseNeo4jConfiguration { @Bean public org.neo4j.ogm.config.Configuration getConfiguration() { - org.neo4j.ogm.config.Configuration config = new Builder().uri(URL).build(); - return config; + return new Builder().uri(URL).build(); } @Bean From 03da414d7a7df52cb8d732c98e62b67d1998f0ff Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sat, 25 Jan 2020 23:15:17 +0530 Subject: [PATCH 004/278] updated spring 4 minor version --- parent-spring-4/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent-spring-4/pom.xml b/parent-spring-4/pom.xml index 671ca7db6b..3749c5016e 100644 --- a/parent-spring-4/pom.xml +++ b/parent-spring-4/pom.xml @@ -51,7 +51,7 @@ - 4.3.25.RELEASE + 4.3.26.RELEASE 1.6.1 From fe1642be6f13d0f3c886cd8c023df4fccabade51 Mon Sep 17 00:00:00 2001 From: chirag d Date: Tue, 4 Feb 2020 22:19:12 +0530 Subject: [PATCH 005/278] BAEL3771: Cache Headers in Spring MVC --- .../baeldung/spring/web/config/WebConfig.java | 25 +++++- .../controller/CacheControlController.java | 55 ++++++++++++ .../src/main/webapp/resources/hello.css | 0 ...CacheControlControllerIntegrationTest.java | 84 +++++++++++++++++++ 4 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 spring-mvc-java/src/main/java/com/baeldung/web/controller/CacheControlController.java create mode 100644 spring-mvc-java/src/main/webapp/resources/hello.css create mode 100644 spring-mvc-java/src/test/java/com/baeldung/web/controller/CacheControlControllerIntegrationTest.java diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java index 96e300464b..5cc165680f 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -2,6 +2,7 @@ package com.baeldung.spring.web.config; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.TimeUnit; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; @@ -9,15 +10,19 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Description; import org.springframework.context.support.ResourceBundleMessageSource; +import org.springframework.http.CacheControl; import org.springframework.http.MediaType; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; +import org.springframework.web.servlet.mvc.WebContentInterceptor; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.util.UrlPathHelper; @@ -30,14 +35,14 @@ import com.baeldung.excel.ExcelPOIHelper; @EnableWebMvc @Configuration -@ComponentScan(basePackages = { "com.baeldung.web.controller" }) +@ComponentScan(basePackages = {"com.baeldung.web.controller"}) public class WebConfig implements WebMvcConfigurer { - + @Override public void addViewControllers(final ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); } - + @Bean public ViewResolver thymeleafViewResolver() { final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); @@ -84,7 +89,10 @@ public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(final ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/") + .setCacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS) + .noTransform() + .mustRevalidate()); } @Override @@ -121,4 +129,13 @@ public class WebConfig implements WebMvcConfigurer { public ExcelPOIHelper excelPOIHelper() { return new ExcelPOIHelper(); } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + WebContentInterceptor interceptor = new WebContentInterceptor(); + interceptor.addCacheMapping(CacheControl.maxAge(60, TimeUnit.SECONDS) + .noTransform() + .mustRevalidate(), "/cache/*"); + registry.addInterceptor(interceptor); + } } \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/CacheControlController.java b/spring-mvc-java/src/main/java/com/baeldung/web/controller/CacheControlController.java new file mode 100644 index 0000000000..f1614ab448 --- /dev/null +++ b/spring-mvc-java/src/main/java/com/baeldung/web/controller/CacheControlController.java @@ -0,0 +1,55 @@ +package com.baeldung.web.controller; + +import org.springframework.http.CacheControl; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.context.request.WebRequest; + +import javax.servlet.http.HttpServletResponse; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.concurrent.TimeUnit; + +@Controller +public class CacheControlController { + + @RequestMapping(value = "/hello/{name}", method = RequestMethod.GET) + public ResponseEntity helloWorld(@PathVariable String name) { + CacheControl cacheControl = CacheControl.maxAge(60, TimeUnit.SECONDS) + .noTransform() + .mustRevalidate(); + return ResponseEntity.ok() + .cacheControl(cacheControl) + .body("Hello " + name); + } + + @RequestMapping(value = "/home/{name}", method = RequestMethod.GET) + public String home(@PathVariable String name, final HttpServletResponse response) { + response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform"); + return "home"; + } + + @RequestMapping(value = "/cache/{name}", method = RequestMethod.GET) + public ResponseEntity intercept(@PathVariable String name) { + return ResponseEntity.ok().body("Hello " + name); + } + + @RequestMapping(value = "/validate/{name}", method = RequestMethod.GET) + public ResponseEntity validate(@PathVariable String name, WebRequest request) { + + ZoneId zoneId = ZoneId.of("GMT"); + long lastModifiedTimestamp = LocalDateTime.of(2020, 02, 4, 19, 57, 45) + .atZone(zoneId).toInstant().toEpochMilli(); + + if (request.checkNotModified(lastModifiedTimestamp)) { + return ResponseEntity.status(304).build(); + } + + return ResponseEntity.ok().body("Hello " + name); + } + + +} diff --git a/spring-mvc-java/src/main/webapp/resources/hello.css b/spring-mvc-java/src/main/webapp/resources/hello.css new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/CacheControlControllerIntegrationTest.java b/spring-mvc-java/src/test/java/com/baeldung/web/controller/CacheControlControllerIntegrationTest.java new file mode 100644 index 0000000000..b03f628b20 --- /dev/null +++ b/spring-mvc-java/src/test/java/com/baeldung/web/controller/CacheControlControllerIntegrationTest.java @@ -0,0 +1,84 @@ +package com.baeldung.web.controller; + +import com.baeldung.spring.web.config.WebConfig; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpHeaders; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; + +import java.time.LocalDate; +import java.time.LocalDateTime; + +import static org.springframework.http.HttpHeaders.IF_UNMODIFIED_SINCE; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +@ContextConfiguration(classes = {WebConfig.class, WebConfig.class}) +public class CacheControlControllerIntegrationTest { + + @Autowired + private WebApplicationContext wac; + + private MockMvc mockMvc; + + @BeforeEach + void setup() throws Exception { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build(); + } + + @Test + void whenResponseBody_thenReturnCacheHeader() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/hello/baeldung")) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform")); + } + + @Test + void whenViewName_thenReturnCacheHeader() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/home/baeldung")) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform")) + .andExpect(MockMvcResultMatchers.view().name("home")); + } + + @Test + void whenStaticResources_thenReturnCacheHeader() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/resources/hello.css")) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform")); + } + + @Test + void whenInterceptor_thenReturnCacheHeader() throws Exception { + this.mockMvc.perform(MockMvcRequestBuilders.get("/cache/baeldung")) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform")); + } + + @Test + void whenValidate_thenReturnCacheHeader() throws Exception { + HttpHeaders headers = new HttpHeaders(); + headers.add(IF_UNMODIFIED_SINCE, "Tue, 04 Feb 2020 19:57:25 GMT"); + this.mockMvc.perform(MockMvcRequestBuilders.get("/validate/baeldung").headers(headers)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().is(304)); + } + + + + +} From 92b7e549a14f82dcef37d29e793a19c8ea853f98 Mon Sep 17 00:00:00 2001 From: chirag d Date: Sat, 8 Feb 2020 16:34:45 +0530 Subject: [PATCH 006/278] BEAL3771: Cache Headers in Spring MVC --- pom.xml | 1 + spring-mvc-java-2/.gitignore | 13 ++++++ spring-mvc-java-2/pom.xml | 39 ++++++++++++++++++ .../cache}/CacheControlController.java | 2 +- .../java/com/baeldung/cache/WebConfig.java | 41 +++++++++++++++++++ .../src/main/webapp/resources/hello.css | 0 ...CacheControlControllerIntegrationTest.java | 6 +-- .../baeldung/spring/web/config/WebConfig.java | 25 ++--------- 8 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 spring-mvc-java-2/.gitignore create mode 100644 spring-mvc-java-2/pom.xml rename {spring-mvc-java/src/main/java/com/baeldung/web/controller => spring-mvc-java-2/src/main/java/com/baeldung/cache}/CacheControlController.java (98%) create mode 100644 spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java rename {spring-mvc-java => spring-mvc-java-2}/src/main/webapp/resources/hello.css (100%) rename {spring-mvc-java/src/test/java/com/baeldung/web/controller => spring-mvc-java-2/src/test/java/com/baeldung/cache}/CacheControlControllerIntegrationTest.java (95%) diff --git a/pom.xml b/pom.xml index 6e6316edd6..1972350c75 100644 --- a/pom.xml +++ b/pom.xml @@ -692,6 +692,7 @@ spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java + spring-mvc-java-2 spring-mvc-kotlin spring-mvc-velocity diff --git a/spring-mvc-java-2/.gitignore b/spring-mvc-java-2/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-mvc-java-2/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/spring-mvc-java-2/pom.xml b/spring-mvc-java-2/pom.xml new file mode 100644 index 0000000000..d5b7d087ab --- /dev/null +++ b/spring-mvc-java-2/pom.xml @@ -0,0 +1,39 @@ + + + 4.0.0 + spring-mvc-java-2 + 0.1-SNAPSHOT + spring-mvc-java-2 + war + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + javax.servlet + javax.servlet-api + ${javax.version} + + + org.springframework + spring-webmvc + ${spring.mvc.version} + + + + + + 4.0.1 + 5.2.2.RELEASE + + + + + \ No newline at end of file diff --git a/spring-mvc-java/src/main/java/com/baeldung/web/controller/CacheControlController.java b/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java similarity index 98% rename from spring-mvc-java/src/main/java/com/baeldung/web/controller/CacheControlController.java rename to spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java index f1614ab448..5bf095888e 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/web/controller/CacheControlController.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java @@ -1,4 +1,4 @@ -package com.baeldung.web.controller; +package com.baeldung.cache; import org.springframework.http.CacheControl; import org.springframework.http.ResponseEntity; diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java b/spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java new file mode 100644 index 0000000000..728479979c --- /dev/null +++ b/spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java @@ -0,0 +1,41 @@ +package com.baeldung.cache; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.CacheControl; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.mvc.WebContentInterceptor; + +import java.util.concurrent.TimeUnit; + +@EnableWebMvc +@Configuration +@ComponentScan(basePackages = {"com.baeldung.cache"}) +public class WebConfig implements WebMvcConfigurer { + + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("index"); + } + + @Override + public void addResourceHandlers(final ResourceHandlerRegistry registry) { + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/") + .setCacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS) + .noTransform() + .mustRevalidate()); + } + + @Override + public void addInterceptors(InterceptorRegistry registry) { + WebContentInterceptor interceptor = new WebContentInterceptor(); + interceptor.addCacheMapping(CacheControl.maxAge(60, TimeUnit.SECONDS) + .noTransform() + .mustRevalidate(), "/cache/*"); + registry.addInterceptor(interceptor); + } +} \ No newline at end of file diff --git a/spring-mvc-java/src/main/webapp/resources/hello.css b/spring-mvc-java-2/src/main/webapp/resources/hello.css similarity index 100% rename from spring-mvc-java/src/main/webapp/resources/hello.css rename to spring-mvc-java-2/src/main/webapp/resources/hello.css diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/CacheControlControllerIntegrationTest.java b/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java similarity index 95% rename from spring-mvc-java/src/test/java/com/baeldung/web/controller/CacheControlControllerIntegrationTest.java rename to spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java index b03f628b20..ef408038ae 100644 --- a/spring-mvc-java/src/test/java/com/baeldung/web/controller/CacheControlControllerIntegrationTest.java +++ b/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java @@ -1,6 +1,5 @@ -package com.baeldung.web.controller; +package com.baeldung.cache; -import com.baeldung.spring.web.config.WebConfig; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -16,9 +15,6 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; -import java.time.LocalDate; -import java.time.LocalDateTime; - import static org.springframework.http.HttpHeaders.IF_UNMODIFIED_SINCE; @ExtendWith(SpringExtension.class) diff --git a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java index 5cc165680f..96e300464b 100644 --- a/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java +++ b/spring-mvc-java/src/main/java/com/baeldung/spring/web/config/WebConfig.java @@ -2,7 +2,6 @@ package com.baeldung.spring.web.config; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.TimeUnit; import org.springframework.context.MessageSource; import org.springframework.context.annotation.Bean; @@ -10,19 +9,15 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Description; import org.springframework.context.support.ResourceBundleMessageSource; -import org.springframework.http.CacheControl; import org.springframework.http.MediaType; import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.PathMatchConfigurer; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping; -import org.springframework.web.servlet.mvc.WebContentInterceptor; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.web.util.UrlPathHelper; @@ -35,14 +30,14 @@ import com.baeldung.excel.ExcelPOIHelper; @EnableWebMvc @Configuration -@ComponentScan(basePackages = {"com.baeldung.web.controller"}) +@ComponentScan(basePackages = { "com.baeldung.web.controller" }) public class WebConfig implements WebMvcConfigurer { - + @Override public void addViewControllers(final ViewControllerRegistry registry) { registry.addViewController("/").setViewName("index"); } - + @Bean public ViewResolver thymeleafViewResolver() { final ThymeleafViewResolver viewResolver = new ThymeleafViewResolver(); @@ -89,10 +84,7 @@ public class WebConfig implements WebMvcConfigurer { @Override public void addResourceHandlers(final ResourceHandlerRegistry registry) { - registry.addResourceHandler("/resources/**").addResourceLocations("/resources/") - .setCacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS) - .noTransform() - .mustRevalidate()); + registry.addResourceHandler("/resources/**").addResourceLocations("/resources/"); } @Override @@ -129,13 +121,4 @@ public class WebConfig implements WebMvcConfigurer { public ExcelPOIHelper excelPOIHelper() { return new ExcelPOIHelper(); } - - @Override - public void addInterceptors(InterceptorRegistry registry) { - WebContentInterceptor interceptor = new WebContentInterceptor(); - interceptor.addCacheMapping(CacheControl.maxAge(60, TimeUnit.SECONDS) - .noTransform() - .mustRevalidate(), "/cache/*"); - registry.addInterceptor(interceptor); - } } \ No newline at end of file From e6b1faa8c2ae0edfbc292c98a22f5eee0964a120 Mon Sep 17 00:00:00 2001 From: chirag d Date: Sat, 8 Feb 2020 18:17:34 +0530 Subject: [PATCH 007/278] BEAL3771: Cache Headers in Spring MVC --- pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/pom.xml b/pom.xml index 1972350c75..6bc56a8ab6 100644 --- a/pom.xml +++ b/pom.xml @@ -1194,6 +1194,7 @@ spring-mvc-forms-jsp spring-mvc-forms-thymeleaf spring-mvc-java + spring-mvc-java-2 spring-mvc-kotlin spring-mvc-velocity From af596b23381616097aa132ef2eacfcd3eeaad02e Mon Sep 17 00:00:00 2001 From: chirag d Date: Sat, 15 Feb 2020 21:57:54 +0530 Subject: [PATCH 008/278] BAEL:3771 Few review comments --- .../cache/CacheControlController.java | 21 +++++++++---------- .../java/com/baeldung/cache/WebConfig.java | 2 +- ...CacheControlControllerIntegrationTest.java | 7 ++++--- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java b/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java index 5bf095888e..7305f836cf 100644 --- a/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/cache/CacheControlController.java @@ -3,9 +3,8 @@ package com.baeldung.cache; import org.springframework.http.CacheControl; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.context.request.WebRequest; import javax.servlet.http.HttpServletResponse; @@ -16,28 +15,28 @@ import java.util.concurrent.TimeUnit; @Controller public class CacheControlController { - @RequestMapping(value = "/hello/{name}", method = RequestMethod.GET) - public ResponseEntity helloWorld(@PathVariable String name) { + @GetMapping(value = "/hello/{name}") + public ResponseEntity hello(@PathVariable String name) { CacheControl cacheControl = CacheControl.maxAge(60, TimeUnit.SECONDS) - .noTransform() - .mustRevalidate(); + .noTransform() + .mustRevalidate(); return ResponseEntity.ok() - .cacheControl(cacheControl) - .body("Hello " + name); + .cacheControl(cacheControl) + .body("Hello " + name); } - @RequestMapping(value = "/home/{name}", method = RequestMethod.GET) + @GetMapping(value = "/home/{name}") public String home(@PathVariable String name, final HttpServletResponse response) { response.addHeader("Cache-Control", "max-age=60, must-revalidate, no-transform"); return "home"; } - @RequestMapping(value = "/cache/{name}", method = RequestMethod.GET) + @GetMapping(value = "/login/{name}") public ResponseEntity intercept(@PathVariable String name) { return ResponseEntity.ok().body("Hello " + name); } - @RequestMapping(value = "/validate/{name}", method = RequestMethod.GET) + @GetMapping(value = "/productInfo/{name}") public ResponseEntity validate(@PathVariable String name, WebRequest request) { ZoneId zoneId = ZoneId.of("GMT"); diff --git a/spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java b/spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java index 728479979c..2f07912e80 100644 --- a/spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java +++ b/spring-mvc-java-2/src/main/java/com/baeldung/cache/WebConfig.java @@ -35,7 +35,7 @@ public class WebConfig implements WebMvcConfigurer { WebContentInterceptor interceptor = new WebContentInterceptor(); interceptor.addCacheMapping(CacheControl.maxAge(60, TimeUnit.SECONDS) .noTransform() - .mustRevalidate(), "/cache/*"); + .mustRevalidate(), "/login/*"); registry.addInterceptor(interceptor); } } \ No newline at end of file diff --git a/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java b/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java index ef408038ae..7acfe5e480 100644 --- a/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java +++ b/spring-mvc-java-2/src/test/java/com/baeldung/cache/CacheControlControllerIntegrationTest.java @@ -37,7 +37,8 @@ public class CacheControlControllerIntegrationTest { this.mockMvc.perform(MockMvcRequestBuilders.get("/hello/baeldung")) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) - .andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform")); + .andExpect(MockMvcResultMatchers.header() + .string("Cache-Control","max-age=60, must-revalidate, no-transform")); } @Test @@ -59,7 +60,7 @@ public class CacheControlControllerIntegrationTest { @Test void whenInterceptor_thenReturnCacheHeader() throws Exception { - this.mockMvc.perform(MockMvcRequestBuilders.get("/cache/baeldung")) + this.mockMvc.perform(MockMvcRequestBuilders.get("/login/baeldung")) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().isOk()) .andExpect(MockMvcResultMatchers.header().string("Cache-Control","max-age=60, must-revalidate, no-transform")); @@ -69,7 +70,7 @@ public class CacheControlControllerIntegrationTest { void whenValidate_thenReturnCacheHeader() throws Exception { HttpHeaders headers = new HttpHeaders(); headers.add(IF_UNMODIFIED_SINCE, "Tue, 04 Feb 2020 19:57:25 GMT"); - this.mockMvc.perform(MockMvcRequestBuilders.get("/validate/baeldung").headers(headers)) + this.mockMvc.perform(MockMvcRequestBuilders.get("/productInfo/baeldung").headers(headers)) .andDo(MockMvcResultHandlers.print()) .andExpect(MockMvcResultMatchers.status().is(304)); } From 34d04156fc8033181c42c956ff3ef148e8c9bc09 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 19 Feb 2020 23:14:00 +0100 Subject: [PATCH 009/278] BAEL-3855 Lock Striping --- lock-striping/pom.xml | 43 ++++++++++++ .../baeldung/concurrent/lock/BenchMark.java | 66 +++++++++++++++++++ .../concurrent/lock/CoarseGrained.java | 39 +++++++++++ .../concurrent/lock/ConcurrentAccessMap.java | 33 ++++++++++ .../baeldung/concurrent/lock/LockStriped.java | 47 +++++++++++++ .../com/baeldung/concurrent/lock/NoLock.java | 34 ++++++++++ 6 files changed, 262 insertions(+) create mode 100644 lock-striping/pom.xml create mode 100644 lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java create mode 100644 lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java create mode 100644 lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java create mode 100644 lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java create mode 100644 lock-striping/src/com/baeldung/concurrent/lock/NoLock.java diff --git a/lock-striping/pom.xml b/lock-striping/pom.xml new file mode 100644 index 0000000000..79469593cf --- /dev/null +++ b/lock-striping/pom.xml @@ -0,0 +1,43 @@ + + 4.0.0 + com.baeldung.concurrent.lock + lock-striping + 0.0.1-SNAPSHOT + + + 1.21 + 28.2-jre + + + + + com.google.guava + guava + ${guava.version} + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + + + + + src + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + + \ No newline at end of file diff --git a/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java b/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java new file mode 100644 index 0000000000..5aae5145d2 --- /dev/null +++ b/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java @@ -0,0 +1,66 @@ +package com.baeldung.concurrent.lock; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +@State(Scope.Thread) +@Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.MILLISECONDS) +@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.MILLISECONDS) +public class BenchMark { + ConcurrentAccessMap accessMyMap; + + @Param({"HashMap", "HashMap with Lock", "HashMap with Striped Lock", + "ConcurrentHashMap", "ConcurrentHashMap with Lock", "ConcurrentHashMap with Striped Lock"}) + private String type; + + @Setup + public void setup() { + switch (type) { + case "HashMap": + accessMyMap = new NoLock(getHashMap()); + break; + case "ConcurrentHashMap": + accessMyMap = new NoLock(getConcurrentHashMap()); + break; + case "HashMap with Lock": + accessMyMap = new CoarseGrained(getHashMap()); + break; + case "ConcurrentHashMap with Lock": + accessMyMap = new CoarseGrained(getConcurrentHashMap()); + break; + case "HashMap with Striped Lock": + accessMyMap = new LockStriped(getHashMap()); + break; + case "ConcurrentHashMap with Striped Lock": + accessMyMap = new LockStriped(getConcurrentHashMap()); + break; + } + } + + private Map getHashMap() { + return new HashMap(); + } + + private Map getConcurrentHashMap() { + return new ConcurrentHashMap(); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public void test() throws InterruptedException { + accessMyMap.doWork(type); + } +} diff --git a/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java b/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java new file mode 100644 index 0000000000..adc70fc3ab --- /dev/null +++ b/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java @@ -0,0 +1,39 @@ +package com.baeldung.concurrent.lock; + +import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; + +import com.google.common.base.Supplier; + +public class CoarseGrained extends ConcurrentAccessMap { + ReentrantLock lock; + + public CoarseGrained(Map map) { + super(map); + lock = new ReentrantLock(); + } + + protected Supplier putSupplier(int x) { + return (()-> { + boolean done = false; + while(!done) { + done = lock.tryLock(); + } + map.put("key" + x, "value" + x); + lock.unlock(); + return null; + }); + } + + protected Supplier getSupplier(int x) { + return (()-> { + boolean done = false; + while(!done) { + done = lock.tryLock(); + } + map.get("key" + x); + lock.unlock(); + return null; + }); + } +} diff --git a/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java b/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java new file mode 100644 index 0000000000..87c305b8aa --- /dev/null +++ b/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java @@ -0,0 +1,33 @@ +package com.baeldung.concurrent.lock; + +import java.util.Map; +import java.util.concurrent.CompletableFuture; + +import com.google.common.base.Supplier; + +public abstract class ConcurrentAccessMap { + static final int SLOTS = 4; + static final int THREADS = 10000; + static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; + private CompletableFuture[] requests; + Map map; + + public ConcurrentAccessMap(Map map) { + this.map = map; + } + + public final void doWork(String type) { + requests = new CompletableFuture[THREADS * SLOTS]; + + for (int i = 0; i < THREADS; i++) { + requests[SLOTS * i + 0] = CompletableFuture.supplyAsync(putSupplier(i)); + requests[SLOTS * i + 1] = CompletableFuture.supplyAsync(getSupplier(i)); + requests[SLOTS * i + 2] = CompletableFuture.supplyAsync(getSupplier(i)); + requests[SLOTS * i + 3] = CompletableFuture.supplyAsync(getSupplier(i)); + } + CompletableFuture.allOf(requests).join(); + } + + protected abstract Supplier putSupplier(int x); + protected abstract Supplier getSupplier(int x); +} diff --git a/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java b/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java new file mode 100644 index 0000000000..91d72eb362 --- /dev/null +++ b/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java @@ -0,0 +1,47 @@ +package com.baeldung.concurrent.lock; + +import java.util.Map; +import java.util.concurrent.locks.Lock; + +import com.google.common.base.Supplier; +import com.google.common.util.concurrent.Striped; + +public class LockStriped extends ConcurrentAccessMap { + Striped lock; + + public LockStriped(Map map) { + super(map); + lock = getStripedLock(); + } + + private Striped getStripedLock() { + Striped map = Striped.lock(BUCKETS); + return map; + } + + protected Supplier putSupplier(int x) { + return (()-> { + Lock currentLock = lock.get("key" + x); + boolean done = false; + while(!done) { + done = currentLock.tryLock(); + } + map.put("key" + x, "value" + x); + currentLock.unlock(); + return null; + }); + } + + protected Supplier getSupplier(int x) { + return (()-> { + Lock currentLock = lock.get("key" + x); + boolean done = false; + while(!done) { + done = currentLock.tryLock(); + } + map.get("key" + x); + currentLock.unlock(); + return null; + }); + } +} diff --git a/lock-striping/src/com/baeldung/concurrent/lock/NoLock.java b/lock-striping/src/com/baeldung/concurrent/lock/NoLock.java new file mode 100644 index 0000000000..f2d5b445d7 --- /dev/null +++ b/lock-striping/src/com/baeldung/concurrent/lock/NoLock.java @@ -0,0 +1,34 @@ +package com.baeldung.concurrent.lock; + +import java.util.Map; + +import com.google.common.base.Supplier; + +public class NoLock extends ConcurrentAccessMap { + + public NoLock(Map map) { + super(map); + } + + protected Supplier putSupplier(int x) { + return (()-> { + boolean done = false; + while(!done) { + map.put("key" + x, "value" + x); + done = true; + } + return null; + }); + } + + protected Supplier getSupplier(int x) { + return (()-> { + boolean done = false; + while(!done) { + map.get("key" + x); + done = true; + } + return null; + }); + } +} \ No newline at end of file From 72ea7a14e6bf9e00ca20e592c5d49bc7376bc82b Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 19 Feb 2020 23:26:24 +0100 Subject: [PATCH 010/278] BAEL-3855 --- .../baeldung/algorithms/greedy/Follower.java | 20 -------- .../algorithms/greedy/FollowersPath.java | 44 ----------------- .../algorithms/greedy/GreedyAlgorithm.java | 47 ------------------- .../algorithms/greedy/NonGreedyAlgorithm.java | 44 ----------------- .../algorithms/greedy/SocialConnector.java | 36 -------------- .../algorithms/greedy/SocialUser.java | 38 --------------- 6 files changed, 229 deletions(-) delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java deleted file mode 100644 index e24b29f5cb..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/Follower.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.algorithms.greedy; - -import lombok.Getter; - -public class Follower { - - @Getter String username; - @Getter long count; - - public Follower(String username, long count) { - super(); - this.username = username; - this.count = count; - } - - @Override - public String toString() { - return "User: " + username + ", Followers: " + count + "\n\r" ; - } -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java deleted file mode 100644 index 932037edb1..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/FollowersPath.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.algorithms.greedy; - -import java.util.ArrayList; -import java.util.List; - -public class FollowersPath { - - private List accounts; - private long count; - - public FollowersPath() { - super(); - this.accounts = new ArrayList<>(); - } - - public List getAccounts() { - return accounts; - } - public long getCount() { - return count; - } - - public void addFollower(String username, long count) { - accounts.add(new Follower(username, count)); - } - - public void addCount(long count) { - this.count += count; - } - - @Override - public String toString() { - String details = ""; - for(Follower a : accounts) { - details+=a.toString() + ", "; - } - - return "Total: " + count + ", \n\r" + - " Details: { " + "\n\r" + - details + "\n\r" + - " }"; - } - -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java deleted file mode 100644 index 891695e5dc..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/GreedyAlgorithm.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.algorithms.greedy; - -import java.util.List; - -public class GreedyAlgorithm { - - int currentLevel = 0; - final int maxLevel = 3; - SocialConnector sc; - FollowersPath fp; - - public GreedyAlgorithm(SocialConnector sc) { - super(); - this.sc = sc; - this.fp = new FollowersPath(); - } - - public long findMostFollowersPath(String account) throws Exception { - long max = 0; - SocialUser toFollow = null; - - List followers = sc.getFollowers(account); - for (SocialUser el : followers) { - long followersCount = el.getFollowersCount(); - if (followersCount > max) { - toFollow = el; - max = followersCount; - } - } - - if (currentLevel < maxLevel - 1) { - currentLevel++; - max += findMostFollowersPath(toFollow.getUsername()); - //fp.addFollower(toFollow.getUsername(), max); - //fp.addCount(max); - return max; - } else { - //fp.addFollower(toFollow.getUsername(), max); - //fp.addCount(max); - return max; - } - } - - public FollowersPath getFollowers() { - return fp; - } -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java deleted file mode 100644 index db8a47be11..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/NonGreedyAlgorithm.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.algorithms.greedy; - -import java.util.List; - -public class NonGreedyAlgorithm { - - int currentLevel = 0; - final int maxLevel = 3; - SocialConnector tc; - - public NonGreedyAlgorithm(SocialConnector tc, int level) { - super(); - this.tc = tc; - this.currentLevel = level; - } - - - public long findMostFollowersPath(String account) throws Exception { - List followers = tc.getFollowers(account); - long total = currentLevel > 0 ? followers.size() : 0; - - if (currentLevel < maxLevel ) { - currentLevel++; - - long[] count = new long[followers.size()]; - int i = 0; - for (SocialUser el : followers) { - NonGreedyAlgorithm sub = new NonGreedyAlgorithm(tc, currentLevel); - count[i] = sub.findMostFollowersPath(el.getUsername()); - i++; - } - - long max = 0; - for (; i > 0; i--) { - if (count[i-1] > max ) - max = count[i-1]; - } - - return total + max; - } - - return total; - } -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java deleted file mode 100644 index cdcf0df395..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialConnector.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.algorithms.greedy; - -import java.util.ArrayList; -import java.util.List; - -import lombok.Getter; -import lombok.Setter; - -public class SocialConnector { - private boolean isCounterEnabled = true; - private int counter = 4; - @Getter @Setter List users; - - public SocialConnector() { - users = new ArrayList<>(); - } - - public boolean switchCounter() { - this.isCounterEnabled = !this.isCounterEnabled; - return this.isCounterEnabled; - } - - public List getFollowers(String account) throws Exception { - if (counter < 0) - throw new Exception ("API limit reached"); - else { - if(this.isCounterEnabled) counter--; - for(SocialUser user : users) { - if (user.getUsername().equals(account)) { - return user.getFollowers(); - } - } - } - return new ArrayList<>(); - } -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java deleted file mode 100644 index 33eab9e799..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/greedy/SocialUser.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.algorithms.greedy; - -import java.util.ArrayList; -import java.util.List; - -import lombok.Getter; - -public class SocialUser { - - @Getter private String username; - @Getter private List followers; - - public SocialUser(String username) { - super(); - this.username = username; - this.followers = new ArrayList<>(); - } - - public SocialUser(String username, List followers) { - super(); - this.username = username; - this.followers = followers; - } - - public long getFollowersCount() { - return followers.size(); - } - - public void addFollowers(List followers) { - this.followers.addAll(followers); - } - - @Override - public boolean equals(Object obj) { - return ((SocialUser) obj).getUsername().equals(username); - } - -} From 510c474ef568f59bdb3c0832385d971b41dd9747 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 19 Feb 2020 23:27:45 +0100 Subject: [PATCH 011/278] BAEL-3855 --- .../greedy/GreedyAlgorithmUnitTest.java | 66 ------------------- 1 file changed, 66 deletions(-) delete mode 100644 algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java deleted file mode 100644 index 3560657ace..0000000000 --- a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/greedy/GreedyAlgorithmUnitTest.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.baeldung.algorithms.greedy; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class GreedyAlgorithmUnitTest { - - private SocialConnector prepareNetwork() { - SocialConnector sc = new SocialConnector(); - - SocialUser root = new SocialUser("root"); - SocialUser child1 = new SocialUser("child1"); - SocialUser child2 = new SocialUser("child2"); - SocialUser child3 = new SocialUser("child3"); - SocialUser child21 = new SocialUser("child21"); - SocialUser child211 = new SocialUser("child211"); - SocialUser child2111 = new SocialUser("child2111"); - SocialUser child31 = new SocialUser("child31"); - SocialUser child311 = new SocialUser("child311"); - SocialUser child3111 = new SocialUser("child3111"); - - - child211.addFollowers(Arrays.asList(new SocialUser[]{child2111})); - child311.addFollowers(Arrays.asList(new SocialUser[]{child3111})); - - child21.addFollowers(Arrays.asList(new SocialUser[]{child211})); - child31.addFollowers(Arrays.asList(new SocialUser[]{child311, - new SocialUser("child312"), new SocialUser("child313"), new SocialUser("child314")})); - - child1.addFollowers(Arrays.asList(new SocialUser[]{new SocialUser("child11"), new SocialUser("child12")})); - child2.addFollowers(Arrays.asList(new SocialUser[]{child21, new SocialUser("child22"), new SocialUser("child23")})); - child3.addFollowers(Arrays.asList(new SocialUser[]{child31})); - - root.addFollowers(Arrays.asList(new SocialUser[]{child1, child2, child3})); - - sc.setUsers(Arrays.asList(new SocialUser[]{root, child1, child2, child3, child21, child31, child311, child211})); - return sc; - } - - @Test - public void greedyAlgorithmTest() throws Exception { - GreedyAlgorithm ga = new GreedyAlgorithm(prepareNetwork()); - assertEquals(ga.findMostFollowersPath("root"), 5); - } - - @Test - public void nongreedyAlgorithmTest() throws Exception { - NonGreedyAlgorithm nga = new NonGreedyAlgorithm(prepareNetwork(), 0); - Assertions.assertThrows(Exception.class, () -> { - nga.findMostFollowersPath("root"); - }); - } - - @Test - public void nongreedyAlgorithmUnboundedTest() throws Exception { - SocialConnector sc = prepareNetwork(); - sc.switchCounter(); - NonGreedyAlgorithm nga = new NonGreedyAlgorithm(sc, 0); - assertEquals(nga.findMostFollowersPath("root"), 6); - } - -} \ No newline at end of file From d144322c45d0a5f6940bfa9939307450c0de9291 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 19 Feb 2020 23:28:54 +0100 Subject: [PATCH 012/278] BAEL-3855 --- hexagonal-architecture-poc/pom.xml | 44 ------------------- .../HexagonalArchitecturePocApplication.java | 13 ------ .../boundary/input/OrderService.java | 11 ----- .../boundary/output/OrderRepository.java | 11 ----- .../hexagonal/core/entities/Order.java | 27 ------------ .../core/services/OrderServiceImpl.java | 35 --------------- .../hexagonal/outside/OrderController.java | 32 -------------- .../src/main/resources/application.properties | 5 --- 8 files changed, 178 deletions(-) delete mode 100644 hexagonal-architecture-poc/pom.xml delete mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java delete mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java delete mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java delete mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java delete mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java delete mode 100644 hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java delete mode 100644 hexagonal-architecture-poc/src/main/resources/application.properties diff --git a/hexagonal-architecture-poc/pom.xml b/hexagonal-architecture-poc/pom.xml deleted file mode 100644 index b31a6dec90..0000000000 --- a/hexagonal-architecture-poc/pom.xml +++ /dev/null @@ -1,44 +0,0 @@ - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.0.5.RELEASE - - - com.baeldung - hexagonal-architecture-poc - 0.0.1-SNAPSHOT - hexagonal-architecture-poc - Demo project for Hexagonal Architecture POC - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-starter-web - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java deleted file mode 100644 index 1690fbbeb5..0000000000 --- a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/HexagonalArchitecturePocApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.hexagonal; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class HexagonalArchitecturePocApplication { - - public static void main(String[] args) { - SpringApplication.run(HexagonalArchitecturePocApplication.class, args); - } - -} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java deleted file mode 100644 index 07793f75ab..0000000000 --- a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/input/OrderService.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.hexagonal.boundary.input; - -import org.springframework.stereotype.Service; - -import com.baeldung.hexagonal.core.entities.Order; - -@Service public interface OrderService { - Iterable getOrders(); - Order createOrder(Double total); - boolean registerOrder(Order order); -} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java deleted file mode 100644 index ea1d38d296..0000000000 --- a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/boundary/output/OrderRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.baeldung.hexagonal.boundary.output; - -import java.util.List; - -import org.springframework.data.repository.CrudRepository; -import org.springframework.stereotype.Repository; - -import com.baeldung.hexagonal.core.entities.Order; - -@Repository public interface OrderRepository extends CrudRepository{ -} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java deleted file mode 100644 index db0c4efd54..0000000000 --- a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/entities/Order.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.hexagonal.core.entities; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity @Table(name="Orders") public class Order { - @Id @GeneratedValue(strategy = GenerationType.IDENTITY) Long id; - Double total; - - public Order() { - super(); - } - public Double getTotal() { - return total; - } - public void setTotal(Double total) { - this.total = total; - } - public Long getId() { - return id; - } - - -} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java deleted file mode 100644 index d3d8f1ba6a..0000000000 --- a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/core/services/OrderServiceImpl.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.hexagonal.core.services; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import com.baeldung.hexagonal.boundary.input.OrderService; -import com.baeldung.hexagonal.boundary.output.OrderRepository; -import com.baeldung.hexagonal.core.entities.Order; - -@Service public class OrderServiceImpl implements OrderService { - - @Autowired OrderRepository orderRepository; - - @Override - public Iterable getOrders() { - return orderRepository.findAll(); - } - - @Override - public boolean registerOrder(Order order) { - if (order.getTotal() > 0) - orderRepository.save(order); - else - return false; - - return true; - } - - @Override - public Order createOrder(Double total) { - Order order = new Order(); - order.setTotal(total); - return order; - } -} diff --git a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java b/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java deleted file mode 100644 index 85c2e42368..0000000000 --- a/hexagonal-architecture-poc/src/main/java/com/baeldung/hexagonal/outside/OrderController.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.hexagonal.outside; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.hexagonal.boundary.input.OrderService; -import com.baeldung.hexagonal.core.entities.Order; - -@RestController public class OrderController { - - @Autowired OrderService orderService; - - @GetMapping(path = "/orders/list") - public Iterable getOrders(){ - return orderService.getOrders(); - } - - @GetMapping(path = "/orders/add") - public String placeOrder(@RequestParam Double total) { - boolean isPlaced = orderService.registerOrder(orderService.createOrder(total)); - return isPlaced ? "Ok" : "Nok"; - } - - @GetMapping(path = "/orders/add-commission") - public String placeCommissionOrder(@RequestParam Double total) { - boolean isPlaced = orderService.registerOrder(orderService.createOrder(total*1.05)); - return isPlaced ? "Ok" : "Nok"; - } - -} diff --git a/hexagonal-architecture-poc/src/main/resources/application.properties b/hexagonal-architecture-poc/src/main/resources/application.properties deleted file mode 100644 index bc2fdde8c1..0000000000 --- a/hexagonal-architecture-poc/src/main/resources/application.properties +++ /dev/null @@ -1,5 +0,0 @@ -spring.datasource.url=jdbc:h2:mem:testdb -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.username=sa -spring.datasource.password=password -spring.jpa.database-platform=org.hibernate.dialect.H2Dialect From d01b7be0b6476aad67aa9fad3ccdacd6d474d68e Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 21 Feb 2020 14:17:46 +0100 Subject: [PATCH 013/278] BAEL-3855 identation, moved to new module, removed needless classes, better benchmark --- lock-striping/pom.xml | 38 +++++----- .../baeldung/concurrent/lock/BenchMark.java | 49 ++++++------- .../concurrent/lock/CoarseGrained.java | 56 +++++++-------- .../concurrent/lock/ConcurrentAccessMap.java | 46 ++++++------ .../baeldung/concurrent/lock/LockStriped.java | 70 +++++++++---------- .../com/baeldung/concurrent/lock/NoLock.java | 34 --------- 6 files changed, 127 insertions(+), 166 deletions(-) delete mode 100644 lock-striping/src/com/baeldung/concurrent/lock/NoLock.java diff --git a/lock-striping/pom.xml b/lock-striping/pom.xml index 79469593cf..0e5310b9da 100644 --- a/lock-striping/pom.xml +++ b/lock-striping/pom.xml @@ -1,31 +1,31 @@ 4.0.0 com.baeldung.concurrent.lock - lock-striping + core-java-concurrency-collections-2 0.0.1-SNAPSHOT - + 1.21 28.2-jre - + - - com.google.guava - guava - ${guava.version} - - - org.openjdk.jmh - jmh-core - ${jmh.version} - - - org.openjdk.jmh - jmh-generator-annprocess - ${jmh.version} - - + + com.google.guava + guava + ${guava.version} + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + + src diff --git a/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java b/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java index 5aae5145d2..438bcb2f4b 100644 --- a/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java +++ b/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java @@ -6,6 +6,7 @@ import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; @@ -16,24 +17,18 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; @State(Scope.Thread) -@Warmup(iterations = 2, time = 1, timeUnit = TimeUnit.MILLISECONDS) -@Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.MILLISECONDS) +@Fork(value = 2) +@Warmup(iterations = 3) public class BenchMark { ConcurrentAccessMap accessMyMap; - - @Param({"HashMap", "HashMap with Lock", "HashMap with Striped Lock", - "ConcurrentHashMap", "ConcurrentHashMap with Lock", "ConcurrentHashMap with Striped Lock"}) + + @Param({"HashMap with Lock", "HashMap with Striped Lock", + "ConcurrentHashMap with Lock", "ConcurrentHashMap with Striped Lock"}) private String type; - - @Setup + + @Setup public void setup() { switch (type) { - case "HashMap": - accessMyMap = new NoLock(getHashMap()); - break; - case "ConcurrentHashMap": - accessMyMap = new NoLock(getConcurrentHashMap()); - break; case "HashMap with Lock": accessMyMap = new CoarseGrained(getHashMap()); break; @@ -48,19 +43,19 @@ public class BenchMark { break; } } - - private Map getHashMap() { - return new HashMap(); - } - - private Map getConcurrentHashMap() { - return new ConcurrentHashMap(); - } - - @Benchmark - @BenchmarkMode(Mode.Throughput) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void test() throws InterruptedException { + + private Map getHashMap() { + return new HashMap(); + } + + private Map getConcurrentHashMap() { + return new ConcurrentHashMap(); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public void test() throws InterruptedException { accessMyMap.doWork(type); - } + } } diff --git a/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java b/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java index adc70fc3ab..a9af3e1bba 100644 --- a/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java +++ b/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java @@ -6,34 +6,34 @@ import java.util.concurrent.locks.ReentrantLock; import com.google.common.base.Supplier; public class CoarseGrained extends ConcurrentAccessMap { - ReentrantLock lock; + ReentrantLock lock; - public CoarseGrained(Map map) { - super(map); - lock = new ReentrantLock(); - } + public CoarseGrained(Map map) { + super(map); + lock = new ReentrantLock(); + } - protected Supplier putSupplier(int x) { - return (()-> { - boolean done = false; - while(!done) { - done = lock.tryLock(); - } - map.put("key" + x, "value" + x); - lock.unlock(); - return null; - }); - } - - protected Supplier getSupplier(int x) { - return (()-> { - boolean done = false; - while(!done) { - done = lock.tryLock(); - } - map.get("key" + x); - lock.unlock(); - return null; - }); - } + protected Supplier putSupplier(int x) { + return (()-> { + boolean done = false; + while(!done) { + done = lock.tryLock(); + } + map.put("key" + x, "value" + x); + lock.unlock(); + return null; + }); + } + + protected Supplier getSupplier(int x) { + return (()-> { + boolean done = false; + while(!done) { + done = lock.tryLock(); + } + map.get("key" + x); + lock.unlock(); + return null; + }); + } } diff --git a/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java b/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java index 87c305b8aa..00b61cdc09 100644 --- a/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java +++ b/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java @@ -6,28 +6,28 @@ import java.util.concurrent.CompletableFuture; import com.google.common.base.Supplier; public abstract class ConcurrentAccessMap { - static final int SLOTS = 4; - static final int THREADS = 10000; - static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; - private CompletableFuture[] requests; - Map map; - - public ConcurrentAccessMap(Map map) { - this.map = map; - } - - public final void doWork(String type) { - requests = new CompletableFuture[THREADS * SLOTS]; + static final int SLOTS = 4; + static final int THREADS = 10000; + static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; + private CompletableFuture[] requests; + protected Map map; + + public ConcurrentAccessMap(Map map) { + this.map = map; + } - for (int i = 0; i < THREADS; i++) { - requests[SLOTS * i + 0] = CompletableFuture.supplyAsync(putSupplier(i)); - requests[SLOTS * i + 1] = CompletableFuture.supplyAsync(getSupplier(i)); - requests[SLOTS * i + 2] = CompletableFuture.supplyAsync(getSupplier(i)); - requests[SLOTS * i + 3] = CompletableFuture.supplyAsync(getSupplier(i)); + public final void doWork(String type) { + requests = new CompletableFuture[THREADS * SLOTS]; + + for (int i = 0; i < THREADS; i++) { + requests[SLOTS * i + 0] = CompletableFuture.supplyAsync(putSupplier(i)); + requests[SLOTS * i + 1] = CompletableFuture.supplyAsync(getSupplier(i)); + requests[SLOTS * i + 2] = CompletableFuture.supplyAsync(getSupplier(i)); + requests[SLOTS * i + 3] = CompletableFuture.supplyAsync(getSupplier(i)); } - CompletableFuture.allOf(requests).join(); - } - - protected abstract Supplier putSupplier(int x); - protected abstract Supplier getSupplier(int x); -} + CompletableFuture.allOf(requests).join(); + } + + protected abstract Supplier putSupplier(int x); + protected abstract Supplier getSupplier(int x); +} \ No newline at end of file diff --git a/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java b/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java index 91d72eb362..f162c06f89 100644 --- a/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java +++ b/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java @@ -7,41 +7,41 @@ import com.google.common.base.Supplier; import com.google.common.util.concurrent.Striped; public class LockStriped extends ConcurrentAccessMap { - Striped lock; + Striped lock; - public LockStriped(Map map) { - super(map); - lock = getStripedLock(); - } + public LockStriped(Map map) { + super(map); + lock = getStripedLock(); + } - private Striped getStripedLock() { - Striped map = Striped.lock(BUCKETS); - return map; - } - - protected Supplier putSupplier(int x) { - return (()-> { - Lock currentLock = lock.get("key" + x); - boolean done = false; - while(!done) { - done = currentLock.tryLock(); - } - map.put("key" + x, "value" + x); - currentLock.unlock(); - return null; - }); - } - - protected Supplier getSupplier(int x) { - return (()-> { - Lock currentLock = lock.get("key" + x); - boolean done = false; - while(!done) { - done = currentLock.tryLock(); - } - map.get("key" + x); - currentLock.unlock(); - return null; - }); - } + private Striped getStripedLock() { + Striped map = Striped.lock(BUCKETS); + return map; + } + + protected Supplier putSupplier(int x) { + return (()-> { + Lock currentLock = lock.get("key" + x); + boolean done = false; + while(!done) { + done = currentLock.tryLock(); + } + map.put("key" + x, "value" + x); + currentLock.unlock(); + return null; + }); + } + + protected Supplier getSupplier(int x) { + return (()-> { + Lock currentLock = lock.get("key" + x); + boolean done = false; + while(!done) { + done = currentLock.tryLock(); + } + map.get("key" + x); + currentLock.unlock(); + return null; + }); + } } diff --git a/lock-striping/src/com/baeldung/concurrent/lock/NoLock.java b/lock-striping/src/com/baeldung/concurrent/lock/NoLock.java deleted file mode 100644 index f2d5b445d7..0000000000 --- a/lock-striping/src/com/baeldung/concurrent/lock/NoLock.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.concurrent.lock; - -import java.util.Map; - -import com.google.common.base.Supplier; - -public class NoLock extends ConcurrentAccessMap { - - public NoLock(Map map) { - super(map); - } - - protected Supplier putSupplier(int x) { - return (()-> { - boolean done = false; - while(!done) { - map.put("key" + x, "value" + x); - done = true; - } - return null; - }); - } - - protected Supplier getSupplier(int x) { - return (()-> { - boolean done = false; - while(!done) { - map.get("key" + x); - done = true; - } - return null; - }); - } -} \ No newline at end of file From 41d82b78f5de6d0f247d4e39e8cd8c916427d788 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 22 Feb 2020 12:34:10 +0100 Subject: [PATCH 014/278] BAEL-3855 Tree update --- {lock-striping => core-java-concurrency-collections-2}/pom.xml | 0 .../src/com/baeldung/concurrent/lock/BenchMark.java | 0 .../src/com/baeldung/concurrent/lock/CoarseGrained.java | 0 .../src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java | 0 .../src/com/baeldung/concurrent/lock/LockStriped.java | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {lock-striping => core-java-concurrency-collections-2}/pom.xml (100%) rename {lock-striping => core-java-concurrency-collections-2}/src/com/baeldung/concurrent/lock/BenchMark.java (100%) rename {lock-striping => core-java-concurrency-collections-2}/src/com/baeldung/concurrent/lock/CoarseGrained.java (100%) rename {lock-striping => core-java-concurrency-collections-2}/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java (100%) rename {lock-striping => core-java-concurrency-collections-2}/src/com/baeldung/concurrent/lock/LockStriped.java (100%) diff --git a/lock-striping/pom.xml b/core-java-concurrency-collections-2/pom.xml similarity index 100% rename from lock-striping/pom.xml rename to core-java-concurrency-collections-2/pom.xml diff --git a/lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java b/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/BenchMark.java similarity index 100% rename from lock-striping/src/com/baeldung/concurrent/lock/BenchMark.java rename to core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/BenchMark.java diff --git a/lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java b/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/CoarseGrained.java similarity index 100% rename from lock-striping/src/com/baeldung/concurrent/lock/CoarseGrained.java rename to core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/CoarseGrained.java diff --git a/lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java b/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java similarity index 100% rename from lock-striping/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java rename to core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java diff --git a/lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java b/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/LockStriped.java similarity index 100% rename from lock-striping/src/com/baeldung/concurrent/lock/LockStriped.java rename to core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/LockStriped.java From 0fc23d01e519741b417620f517041aef7747eadf Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 24 Feb 2020 10:10:02 +0100 Subject: [PATCH 015/278] BAEL-3855 tree fix --- .../{ => main/java}/com/baeldung/concurrent/lock/BenchMark.java | 0 .../java}/com/baeldung/concurrent/lock/CoarseGrained.java | 0 .../java}/com/baeldung/concurrent/lock/ConcurrentAccessMap.java | 0 .../{ => main/java}/com/baeldung/concurrent/lock/LockStriped.java | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename core-java-concurrency-collections-2/src/{ => main/java}/com/baeldung/concurrent/lock/BenchMark.java (100%) rename core-java-concurrency-collections-2/src/{ => main/java}/com/baeldung/concurrent/lock/CoarseGrained.java (100%) rename core-java-concurrency-collections-2/src/{ => main/java}/com/baeldung/concurrent/lock/ConcurrentAccessMap.java (100%) rename core-java-concurrency-collections-2/src/{ => main/java}/com/baeldung/concurrent/lock/LockStriped.java (100%) diff --git a/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/BenchMark.java b/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java similarity index 100% rename from core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/BenchMark.java rename to core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java diff --git a/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/CoarseGrained.java b/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java similarity index 100% rename from core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/CoarseGrained.java rename to core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java diff --git a/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java b/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java similarity index 100% rename from core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/ConcurrentAccessMap.java rename to core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java diff --git a/core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/LockStriped.java b/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java similarity index 100% rename from core-java-concurrency-collections-2/src/com/baeldung/concurrent/lock/LockStriped.java rename to core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java From 79be75cd74e17ae9000abbc025c81bb69cb80560 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 25 Feb 2020 10:31:59 +0100 Subject: [PATCH 016/278] BAEL-3855 Moved to java-core-modules folder --- .../core-java-concurrency-collections-2}/pom.xml | 0 .../src/main/java/com/baeldung/concurrent/lock/BenchMark.java | 0 .../src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java | 0 .../java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java | 0 .../src/main/java/com/baeldung/concurrent/lock/LockStriped.java | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename {core-java-concurrency-collections-2 => core-java-modules/core-java-concurrency-collections-2}/pom.xml (100%) rename {core-java-concurrency-collections-2 => core-java-modules/core-java-concurrency-collections-2}/src/main/java/com/baeldung/concurrent/lock/BenchMark.java (100%) rename {core-java-concurrency-collections-2 => core-java-modules/core-java-concurrency-collections-2}/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java (100%) rename {core-java-concurrency-collections-2 => core-java-modules/core-java-concurrency-collections-2}/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java (100%) rename {core-java-concurrency-collections-2 => core-java-modules/core-java-concurrency-collections-2}/src/main/java/com/baeldung/concurrent/lock/LockStriped.java (100%) diff --git a/core-java-concurrency-collections-2/pom.xml b/core-java-modules/core-java-concurrency-collections-2/pom.xml similarity index 100% rename from core-java-concurrency-collections-2/pom.xml rename to core-java-modules/core-java-concurrency-collections-2/pom.xml diff --git a/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java similarity index 100% rename from core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java rename to core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java diff --git a/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java similarity index 100% rename from core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java rename to core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java diff --git a/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java similarity index 100% rename from core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java rename to core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java diff --git a/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java similarity index 100% rename from core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java rename to core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java From ab784af235a2dc2ec9a8409ff9cc09c111c4ef6b Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 29 Feb 2020 16:12:08 +0100 Subject: [PATCH 017/278] JAVA-841 Standardize package in spring-security-modules-mvc-boot-2 module --- .../spring-security-mvc-boot-2/pom.xml | 11 +++++------ .../h2/H2JdbcAuthenticationApplication.java | 2 +- .../h2/config/SecurityConfiguration.java | 2 +- .../jdbcauthentication/h2/web/UserController.java | 2 +- .../mysql/MySqlJdbcAuthenticationApplication.java | 2 +- .../mysql/config/SecurityConfiguration.java | 2 +- .../jdbcauthentication/mysql/web/UserController.java | 2 +- .../postgre/PostgreJdbcAuthenticationApplication.java | 2 +- .../postgre/config/SecurityConfiguration.java | 2 +- .../postgre/web/UserController.java | 2 +- .../CustomAuthenticationProvider.java | 2 +- .../multipleauthproviders/MultipleAuthController.java | 2 +- .../MultipleAuthProvidersApplication.java | 2 +- .../MultipleAuthProvidersSecurityConfig.java | 2 +- .../MultipleEntryPointsApplication.java | 2 +- .../MultipleEntryPointsSecurityConfig.java | 2 +- .../baeldung/multipleentrypoints/PagesController.java | 2 +- .../multiplelogin/MultipleLoginApplication.java | 3 +-- .../multiplelogin/MultipleLoginMvcConfig.java | 4 +--- .../multiplelogin/MultipleLoginSecurityConfig.java | 2 +- .../baeldung/multiplelogin/UsersController.java | 2 +- .../baeldung/ssl/HttpsEnabledApplication.java | 2 +- .../{org => com}/baeldung/ssl/SecurityConfig.java | 2 +- .../{org => com}/baeldung/ssl/WelcomeController.java | 3 +-- .../jdbcauthentication/h2/SpringContextTest.java | 3 +-- .../h2/web/UserControllerLiveTest.java | 2 +- .../mysql/web/UserControllerLiveTest.java | 2 +- .../postgre/web/UserControllerLiveTest.java | 2 +- .../baeldung/web/HttpsApplicationIntegrationTest.java | 4 ++-- ...ltipleAuthProvidersApplicationIntegrationTest.java | 4 ++-- .../web/MultipleEntryPointsIntegrationTest.java | 4 ++-- 31 files changed, 38 insertions(+), 44 deletions(-) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java (92%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java (97%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/h2/web/UserController.java (89%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java (90%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java (95%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/mysql/web/UserController.java (88%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java (90%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java (93%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/jdbcauthentication/postgre/web/UserController.java (88%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multipleauthproviders/CustomAuthenticationProvider.java (96%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multipleauthproviders/MultipleAuthController.java (85%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java (92%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java (97%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java (92%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java (99%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multipleentrypoints/PagesController.java (96%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multiplelogin/MultipleLoginApplication.java (85%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multiplelogin/MultipleLoginMvcConfig.java (89%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multiplelogin/MultipleLoginSecurityConfig.java (99%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/multiplelogin/UsersController.java (95%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/ssl/HttpsEnabledApplication.java (95%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/ssl/SecurityConfig.java (95%) rename spring-security-modules/spring-security-mvc-boot-2/src/main/java/{org => com}/baeldung/ssl/WelcomeController.java (74%) rename spring-security-modules/spring-security-mvc-boot-2/src/test/java/{org => com}/baeldung/jdbcauthentication/h2/SpringContextTest.java (76%) rename spring-security-modules/spring-security-mvc-boot-2/src/test/java/{org => com}/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java (95%) rename spring-security-modules/spring-security-mvc-boot-2/src/test/java/{org => com}/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java (95%) rename spring-security-modules/spring-security-mvc-boot-2/src/test/java/{org => com}/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java (95%) rename spring-security-modules/spring-security-mvc-boot-2/src/test/java/{org => com}/baeldung/web/HttpsApplicationIntegrationTest.java (96%) rename spring-security-modules/spring-security-mvc-boot-2/src/test/java/{org => com}/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java (96%) rename spring-security-modules/spring-security-mvc-boot-2/src/test/java/{org => com}/baeldung/web/MultipleEntryPointsIntegrationTest.java (96%) diff --git a/spring-security-modules/spring-security-mvc-boot-2/pom.xml b/spring-security-modules/spring-security-mvc-boot-2/pom.xml index fca38b9714..799b3acd96 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/pom.xml +++ b/spring-security-modules/spring-security-mvc-boot-2/pom.xml @@ -227,16 +227,15 @@ - org.baeldung.custom.Application - - + + + com.baeldung.multiplelogin.MultipleLoginApplication - + - + 1.1.2 1.6.1 diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java similarity index 92% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java index 6936cdc560..d71885d73c 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/H2JdbcAuthenticationApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.h2; +package com.baeldung.jdbcauthentication.h2; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java index 8b8696f0b2..50dc5b6958 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/config/SecurityConfiguration.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.h2.config; +package com.baeldung.jdbcauthentication.h2.config; import javax.sql.DataSource; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/web/UserController.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java similarity index 89% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/web/UserController.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java index 0955061614..03271677a4 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/h2/web/UserController.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/h2/web/UserController.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.h2.web; +package com.baeldung.jdbcauthentication.h2.web; import java.security.Principal; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java similarity index 90% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java index 52934e0096..1f4c54e512 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/MySqlJdbcAuthenticationApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.mysql; +package com.baeldung.jdbcauthentication.mysql; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java index 157c0be748..a0584818cd 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/config/SecurityConfiguration.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.mysql.config; +package com.baeldung.jdbcauthentication.mysql.config; import javax.sql.DataSource; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/web/UserController.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java similarity index 88% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/web/UserController.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java index f1060b5f78..ed15f8bfe6 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/mysql/web/UserController.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/mysql/web/UserController.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.mysql.web; +package com.baeldung.jdbcauthentication.mysql.web; import java.security.Principal; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java similarity index 90% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java index 2c4d1a5255..4b074ef51d 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/PostgreJdbcAuthenticationApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.postgre; +package com.baeldung.jdbcauthentication.postgre; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java similarity index 93% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java index ba79635852..85dc9d364c 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/config/SecurityConfiguration.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.postgre.config; +package com.baeldung.jdbcauthentication.postgre.config; import javax.sql.DataSource; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/web/UserController.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java similarity index 88% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/web/UserController.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java index c8fd3812b1..da85a46562 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/jdbcauthentication/postgre/web/UserController.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/jdbcauthentication/postgre/web/UserController.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.postgre.web; +package com.baeldung.jdbcauthentication.postgre.web; import java.security.Principal; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/CustomAuthenticationProvider.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/CustomAuthenticationProvider.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java index 1a89c362cd..97a8d8ac2a 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/CustomAuthenticationProvider.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/CustomAuthenticationProvider.java @@ -1,4 +1,4 @@ -package org.baeldung.multipleauthproviders; +package com.baeldung.multipleauthproviders; import java.util.Collections; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthController.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java similarity index 85% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthController.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java index b63169bb00..0079c84c6c 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthController.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthController.java @@ -1,4 +1,4 @@ -package org.baeldung.multipleauthproviders; +package com.baeldung.multipleauthproviders; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java similarity index 92% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java index 1f641298c3..e1a437e9a9 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.multipleauthproviders; +package com.baeldung.multipleauthproviders; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java index 3819e981a2..aa2ffc9046 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleauthproviders/MultipleAuthProvidersSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.multipleauthproviders; +package com.baeldung.multipleauthproviders; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java similarity index 92% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java index 847dab073e..4ed36f770f 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.multipleentrypoints; +package com.baeldung.multipleentrypoints; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java similarity index 99% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java index dc89c83cde..b6155fc100 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/MultipleEntryPointsSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.multipleentrypoints; +package com.baeldung.multipleentrypoints; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/PagesController.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/PagesController.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/PagesController.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/PagesController.java index b3462d4061..ba5028aea7 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multipleentrypoints/PagesController.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multipleentrypoints/PagesController.java @@ -1,4 +1,4 @@ -package org.baeldung.multipleentrypoints; +package com.baeldung.multipleentrypoints; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginApplication.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java similarity index 85% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginApplication.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java index 90bb5e4260..abba2ba339 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.multiplelogin; +package com.baeldung.multiplelogin; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -7,7 +7,6 @@ import org.springframework.context.annotation.PropertySource; @SpringBootApplication @PropertySource("classpath:application-defaults.properties") -@ComponentScan("org.baeldung.multiplelogin") public class MultipleLoginApplication { public static void main(String[] args) { SpringApplication.run(MultipleLoginApplication.class, args); diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginMvcConfig.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java similarity index 89% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginMvcConfig.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java index 204b186411..86b3314c7c 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginMvcConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginMvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.multiplelogin; +package com.baeldung.multiplelogin; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -6,14 +6,12 @@ import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; import org.springframework.context.annotation.ComponentScan; @EnableWebMvc @Configuration -@ComponentScan("org.baeldung.controller") public class MultipleLoginMvcConfig implements WebMvcConfigurer { public MultipleLoginMvcConfig() { diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginSecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java similarity index 99% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginSecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java index 9962bf41a9..3d12951f39 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/MultipleLoginSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/MultipleLoginSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.multiplelogin; +package com.baeldung.multiplelogin; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/UsersController.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/UsersController.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/UsersController.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/UsersController.java index 61d7da127c..03be0fd6b2 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/multiplelogin/UsersController.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/multiplelogin/UsersController.java @@ -1,4 +1,4 @@ -package org.baeldung.multiplelogin; +package com.baeldung.multiplelogin; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/HttpsEnabledApplication.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/HttpsEnabledApplication.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java index 17c249067c..f6a550ae54 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/HttpsEnabledApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/HttpsEnabledApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.ssl; +package com.baeldung.ssl; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/SecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/SecurityConfig.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/SecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/SecurityConfig.java index 92f92d8fc7..4bddf0592a 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/SecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/SecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.ssl; +package com.baeldung.ssl; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/WelcomeController.java b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/WelcomeController.java similarity index 74% rename from spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/WelcomeController.java rename to spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/WelcomeController.java index 72ad8abb85..2bd8c8cfde 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/main/java/org/baeldung/ssl/WelcomeController.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/main/java/com/baeldung/ssl/WelcomeController.java @@ -1,8 +1,7 @@ -package org.baeldung.ssl; +package com.baeldung.ssl; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; @Controller public class WelcomeController { diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/h2/SpringContextTest.java b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java similarity index 76% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/h2/SpringContextTest.java rename to spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java index 659dad9155..5bd2a0ce27 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/h2/SpringContextTest.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/SpringContextTest.java @@ -1,6 +1,5 @@ -package org.baeldung.jdbcauthentication.h2; +package com.baeldung.jdbcauthentication.h2; -import org.baeldung.jdbcauthentication.h2.H2JdbcAuthenticationApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java rename to spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java index 638e9d7919..12b5ca5867 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/h2/web/UserControllerLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.h2.web; +package com.baeldung.jdbcauthentication.h2.web; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java rename to spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java index 261063cbb6..79bc84ea69 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/mysql/web/UserControllerLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.mysql.web; +package com.baeldung.jdbcauthentication.mysql.web; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java rename to spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java index 82bf6df8db..e6426a843e 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/jdbcauthentication/postgre/web/UserControllerLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.jdbcauthentication.postgre.web; +package com.baeldung.jdbcauthentication.postgre.web; import static io.restassured.RestAssured.given; import static org.hamcrest.CoreMatchers.is; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/HttpsApplicationIntegrationTest.java b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/HttpsApplicationIntegrationTest.java rename to spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java index fe7883ec94..63d47e6a46 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/HttpsApplicationIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/HttpsApplicationIntegrationTest.java @@ -1,10 +1,10 @@ -package org.baeldung.web; +package com.baeldung.web; import org.apache.http.client.HttpClient; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; -import org.baeldung.ssl.HttpsEnabledApplication; +import com.baeldung.ssl.HttpsEnabledApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Value; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java rename to spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java index 9ef09f1f67..c5ef469fe8 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleAuthProvidersApplicationIntegrationTest.java @@ -1,10 +1,10 @@ -package org.baeldung.web; +package com.baeldung.web; import static org.assertj.core.api.Assertions.assertThat; import java.util.Collections; -import org.baeldung.multipleauthproviders.MultipleAuthProvidersApplication; +import com.baeldung.multipleauthproviders.MultipleAuthProvidersApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/MultipleEntryPointsIntegrationTest.java b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/MultipleEntryPointsIntegrationTest.java rename to spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java index 422be2ac88..352b4af244 100644 --- a/spring-security-modules/spring-security-mvc-boot-2/src/test/java/org/baeldung/web/MultipleEntryPointsIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-boot-2/src/test/java/com/baeldung/web/MultipleEntryPointsIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung.web; +package com.baeldung.web; import org.junit.Before; import org.junit.Test; @@ -15,7 +15,7 @@ import org.springframework.web.context.WebApplicationContext; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import org.baeldung.multipleentrypoints.MultipleEntryPointsApplication; +import com.baeldung.multipleentrypoints.MultipleEntryPointsApplication; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*; From 636e76ade03ef610f4ceee65886b97c32f7d0ea2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 9 Mar 2020 16:43:35 +0100 Subject: [PATCH 018/278] BAEL-3855 Updated --- .../baeldung/concurrent/lock/BenchMark.java | 47 +++++++---------- .../concurrent/lock/ConcurrentAccessMap.java | 51 ++++++++++++------- .../baeldung/concurrent/lock/SingleLock.java | 38 ++++++++++++++ .../baeldung/concurrent/lock/StripedLock.java | 46 +++++++++++++++++ 4 files changed, 134 insertions(+), 48 deletions(-) create mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java create mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java index 438bcb2f4b..5d9e382351 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java @@ -1,13 +1,9 @@ -package com.baeldung.concurrent.lock; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; +package main.java.com.baeldung.concurrent.lock; import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; import org.openjdk.jmh.annotations.Param; @@ -17,45 +13,36 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; @State(Scope.Thread) -@Fork(value = 2) -@Warmup(iterations = 3) +@Fork(value = 1) +@Warmup(iterations = 0) public class BenchMark { ConcurrentAccessMap accessMyMap; + static final int SLOTS = 4; + static final int THREADS = 1000; + static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; - @Param({"HashMap with Lock", "HashMap with Striped Lock", - "ConcurrentHashMap with Lock", "ConcurrentHashMap with Striped Lock"}) - private String type; + @Param({"Single Lock", "Striped Lock"}) + private String lockType; + @Param({"HashMap", "ConcurrentHashMap"}) + private String mapType; + @Setup public void setup() { - switch (type) { - case "HashMap with Lock": - accessMyMap = new CoarseGrained(getHashMap()); + switch (lockType) { + case "Single Lock": + accessMyMap = new SingleLock(); break; - case "ConcurrentHashMap with Lock": - accessMyMap = new CoarseGrained(getConcurrentHashMap()); - break; - case "HashMap with Striped Lock": - accessMyMap = new LockStriped(getHashMap()); - break; - case "ConcurrentHashMap with Striped Lock": - accessMyMap = new LockStriped(getConcurrentHashMap()); + case "Striped Lock": + accessMyMap = new StripedLock(BUCKETS); break; } } - private Map getHashMap() { - return new HashMap(); - } - - private Map getConcurrentHashMap() { - return new ConcurrentHashMap(); - } - @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public void test() throws InterruptedException { - accessMyMap.doWork(type); + accessMyMap.doWork(mapType, THREADS, SLOTS); } } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java index 00b61cdc09..e5fcd6d406 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java @@ -1,33 +1,48 @@ -package com.baeldung.concurrent.lock; +package main.java.com.baeldung.concurrent.lock; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; import com.google.common.base.Supplier; public abstract class ConcurrentAccessMap { - static final int SLOTS = 4; - static final int THREADS = 10000; - static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; - private CompletableFuture[] requests; - protected Map map; - public ConcurrentAccessMap(Map map) { - this.map = map; + public ConcurrentAccessMap() { + } + + private Map getHashMap() { + return new HashMap(); } - public final void doWork(String type) { - requests = new CompletableFuture[THREADS * SLOTS]; + private Map getConcurrentHashMap() { + return new ConcurrentHashMap(); + } + + private Map setup(String type) { + switch (type) { + case "HashMap": + return getHashMap(); + case "ConcurrentHashMap": + return getConcurrentHashMap(); + } + return null; + } - for (int i = 0; i < THREADS; i++) { - requests[SLOTS * i + 0] = CompletableFuture.supplyAsync(putSupplier(i)); - requests[SLOTS * i + 1] = CompletableFuture.supplyAsync(getSupplier(i)); - requests[SLOTS * i + 2] = CompletableFuture.supplyAsync(getSupplier(i)); - requests[SLOTS * i + 3] = CompletableFuture.supplyAsync(getSupplier(i)); - } + public final void doWork(String type, int threads, int slots) { + CompletableFuture[] requests = new CompletableFuture[threads * slots]; + Map map = setup(type); + + for (int i = 0; i < threads; i++) { + requests[slots * i + 0] = CompletableFuture.supplyAsync(putSupplier(map, i)); + requests[slots * i + 1] = CompletableFuture.supplyAsync(getSupplier(map, i)); + requests[slots * i + 2] = CompletableFuture.supplyAsync(getSupplier(map, i)); + requests[slots * i + 3] = CompletableFuture.supplyAsync(getSupplier(map, i)); + } CompletableFuture.allOf(requests).join(); } - protected abstract Supplier putSupplier(int x); - protected abstract Supplier getSupplier(int x); + protected abstract Supplier putSupplier(Map map, int key); + protected abstract Supplier getSupplier(Map map, int key); } \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java new file mode 100644 index 0000000000..4f0fe0222a --- /dev/null +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -0,0 +1,38 @@ +package main.java.com.baeldung.concurrent.lock; + +import java.util.Map; +import java.util.concurrent.locks.ReentrantLock; + +import com.google.common.base.Supplier; + +public class SingleLock extends ConcurrentAccessMap { + ReentrantLock lock; + + public SingleLock() { + lock = new ReentrantLock(); + } + + protected synchronized Supplier putSupplier(Map map, int key) { + return (()-> { + boolean done = false; + while(!done) { + done = lock.tryLock(); + } + map.put("key" + key, "value" + key); + lock.unlock(); + return null; + }); + } + + protected synchronized Supplier getSupplier(Map map, int key) { + return (()-> { + boolean done = false; + while(!done) { + done = lock.tryLock(); + } + map.get("key" + key); + lock.unlock(); + return null; + }); + } +} diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java new file mode 100644 index 0000000000..fe98dd82be --- /dev/null +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -0,0 +1,46 @@ +package main.java.com.baeldung.concurrent.lock; + +import java.util.Map; +import java.util.concurrent.locks.Lock; + +import com.google.common.base.Supplier; +import com.google.common.util.concurrent.Striped; + +public class StripedLock extends ConcurrentAccessMap { + Striped lock; + + public StripedLock(int buckets) { + lock = getStripedLock(buckets); + } + + private Striped getStripedLock(int buckets) { + Striped map = Striped.lock(buckets); + return map; + } + + protected synchronized Supplier putSupplier(Map map, int key) { + return (()-> { + Lock currentLock = lock.get("key" + key); + boolean done = false; + while(!done) { + done = currentLock.tryLock(); + } + map.put("key" + key, "value" + key); + currentLock.unlock(); + return null; + }); + } + + protected synchronized Supplier getSupplier(Map map, int key) { + return (()-> { + Lock currentLock = lock.get("key" + key); + boolean done = false; + while(!done) { + done = currentLock.tryLock(); + } + map.get("key" + key); + currentLock.unlock(); + return null; + }); + } +} From ae6aaf40f057741fec9429fa5ba1e6576fe6310f Mon Sep 17 00:00:00 2001 From: Florin Hriscu Date: Tue, 10 Mar 2020 00:50:53 +0200 Subject: [PATCH 019/278] BAEL-3859 - Add implementation for AtomicMarkableReference article. --- .../AtomicMarkableReferenceUnitTest.java | 193 ++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java new file mode 100644 index 0000000000..b864c78559 --- /dev/null +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java @@ -0,0 +1,193 @@ +package com.baeldung.concurrent.atomic; + +import java.util.Objects; +import java.util.concurrent.atomic.AtomicMarkableReference; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class AtomicMarkableReferenceUnitTest { + + private AtomicMarkableReference employeeNode; + + class Employee { + private int id; + private String name; + + Employee(int id, String name) { + this.id = id; + this.name = name; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof Employee)) + return false; + Employee employee = (Employee) obj; + return id == employee.id && name.equals(employee.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + } + + @Test + void givenMarkValueAsTrue_whenUsingIsMarkedMethod_thenMarkValueShouldBeTrue() { + employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), true); + + Assertions.assertTrue(employeeNode.isMarked()); + } + + @Test + void givenMarkValueAsFalse_whenUsingIsMarkedMethod_thenMarkValueShouldBeFalse() { + employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), false); + + Assertions.assertFalse(employeeNode.isMarked()); + } + + @Test + void whenUsingGetReferenceMethod_thenCurrentReferenceShouldBeReturned() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, false); + + Assertions.assertEquals(employeeNode.getReference(), employee); + } + + @Test + void whenUsingGetMethod_thenCurrentReferenceAndMarkShouldBeReturned() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + + boolean[] markHolder = new boolean[1]; + Employee currentEmployee = employeeNode.get(markHolder); + + Assertions.assertEquals(currentEmployee, employee); + Assertions.assertTrue(markHolder[0]); + } + + @Test + void givenNewReferenceAndMark_whenUsingSetMethod_thenCurrentReferenceAndMarkShouldBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + + Employee newEmployee = new Employee(124, "John"); + employeeNode.set(newEmployee, false); + + Assertions.assertEquals(employeeNode.getReference(), newEmployee); + Assertions.assertFalse(employeeNode.isMarked()); + } + + @Test + void givenTheSameObjectReference_whenUsingAttemptMarkMethod_thenMarkShouldBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + + Assertions.assertTrue(employeeNode.attemptMark(employee, false)); + Assertions.assertFalse(employeeNode.isMarked()); + } + + @Test + void givenDifferentObjectReference_whenUsingAttemptMarkMethod_thenMarkShouldNotBeUpdated() { + Employee employee = new Employee(123, "Mike"); + Employee expectedEmployee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + + Assertions.assertFalse(employeeNode.attemptMark(expectedEmployee, false)); + Assertions.assertTrue(employeeNode.isMarked()); + } + + @Test + void givenCurrentReferenceAndCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertTrue(employeeNode.compareAndSet(employee, newEmployee, true, false)); + Assertions.assertEquals(employeeNode.getReference(), newEmployee); + Assertions.assertFalse(employeeNode.isMarked()); + } + + @Test + void givenNotCurrentReferenceAndCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertFalse(employeeNode.compareAndSet(new Employee(1234, "Steve"), newEmployee, true, false)); + Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertTrue(employeeNode.isMarked()); + } + + @Test + void givenCurrentReferenceAndNotCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertFalse(employeeNode.compareAndSet(employee, newEmployee, false, true)); + Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertTrue(employeeNode.isMarked()); + } + + @Test + void givenNotCurrentReferenceAndNotCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertFalse(employeeNode.compareAndSet(new Employee(1234, "Steve"), newEmployee, false, true)); + Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertTrue(employeeNode.isMarked()); + } + + @Test + void givenCurrentReferenceAndCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertTrue(employeeNode.weakCompareAndSet(employee, newEmployee, true, false)); + Assertions.assertEquals(employeeNode.getReference(), newEmployee); + Assertions.assertFalse(employeeNode.isMarked()); + } + + @Test + void givenNotCurrentReferenceAndCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { + Employee expectedEmployee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(expectedEmployee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertFalse(employeeNode.weakCompareAndSet(new Employee(1234, "Steve"), newEmployee, true, false)); + Assertions.assertEquals(employeeNode.getReference(), expectedEmployee); + Assertions.assertTrue(employeeNode.isMarked()); + } + + @Test + void givenCurrentReferenceAndNotCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { + Employee expectedEmployee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(expectedEmployee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertFalse(employeeNode.weakCompareAndSet(expectedEmployee, newEmployee, false, true)); + Assertions.assertEquals(employeeNode.getReference(), expectedEmployee); + Assertions.assertTrue(employeeNode.isMarked()); + } + + @Test + void givenNotCurrentReferenceAndNotCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { + Employee employee = new Employee(123, "Mike"); + employeeNode = new AtomicMarkableReference(employee, true); + Employee newEmployee = new Employee(124, "John"); + + Assertions.assertFalse(employeeNode.weakCompareAndSet(new Employee(1234, "Steve"), newEmployee, false, true)); + Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertTrue(employeeNode.isMarked()); + } +} From 8efe817cd38e160faafa9fb113b73fcee773ba90 Mon Sep 17 00:00:00 2001 From: Roger Yates <587230+rojyates@users.noreply.github.com> Date: Tue, 10 Mar 2020 09:19:13 +1000 Subject: [PATCH 020/278] BAEL-3603 Add test examples for Java IO versus NIO article --- core-java-modules/core-java-io-2/pom.xml | 8 ++ .../BlockingClientUnitTest.java | 51 ++++++++++ .../NonBlockingClientUnitTest.java | 94 +++++++++++++++++++ 3 files changed, 153 insertions(+) create mode 100644 core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java create mode 100644 core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java diff --git a/core-java-modules/core-java-io-2/pom.xml b/core-java-modules/core-java-io-2/pom.xml index 0c271737d9..960cc51bbd 100644 --- a/core-java-modules/core-java-io-2/pom.xml +++ b/core-java-modules/core-java-io-2/pom.xml @@ -45,6 +45,14 @@ ${assertj.version} test + + + com.github.tomakehurst + wiremock + 2.26.3 + test + + diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java new file mode 100644 index 0000000000..eca2a2638f --- /dev/null +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java @@ -0,0 +1,51 @@ +package com.baeldung.blockingnonblocking; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.*; +import java.net.Socket; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertTrue; + +public class BlockingClientUnitTest { + private static final String REQUESTED_RESOURCE = "/test.json"; + + @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Before + public void setup() { + stubFor(get(urlEqualTo(REQUESTED_RESOURCE)).willReturn(aResponse() + .withStatus(200) + .withBody("{ \"response\" : \"It worked!\" }\r\n\r\n"))); + } + + @Test + public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenReadSuccessfully() throws IOException { + // given an IO socket and somewhere to store our result + Socket socket = new Socket("localhost", wireMockRule.port()); + StringBuilder ourStore = new StringBuilder(); + + // when we write and read (using try-with-resources so our resources are auto-closed) + try (InputStream serverInput = socket.getInputStream(); + BufferedReader reader = new BufferedReader(new InputStreamReader(serverInput)); + OutputStream clientOutput = socket.getOutputStream(); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(clientOutput))) { + writer.print("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"); + writer.flush(); // important - without this the request is never sent, and the test will hang on readLine() + + for (String line; (line = reader.readLine()) != null; ) { + ourStore.append(line); + } + } + + // then we read and saved our data + assertTrue(ourStore + .toString() + .contains("It worked!")); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java new file mode 100644 index 0000000000..47115887ab --- /dev/null +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java @@ -0,0 +1,94 @@ +package com.baeldung.blockingnonblocking; + +import com.github.tomakehurst.wiremock.junit.WireMockRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.StandardCharsets; + +import static com.github.tomakehurst.wiremock.client.WireMock.*; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; +import static org.junit.Assert.assertTrue; + +public class NonBlockingClientUnitTest { + private String REQUESTED_RESOURCE = "/test.json"; + + @Rule public WireMockRule wireMockRule = new WireMockRule(wireMockConfig().dynamicPort()); + + @Before + public void setup() { + stubFor(get(urlEqualTo(REQUESTED_RESOURCE)).willReturn(aResponse() + .withStatus(200) + .withBody("{ \"response\" : \"It worked!\" }"))); + } + + @Test + public void givenJavaNIOSocketChannel_whenReadingAndWriting_thenUseBuffers() throws IOException { + // given a NIO SocketChannel and a charset + InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); + SocketChannel socketChannel = SocketChannel.open(address); + Charset charset = StandardCharsets.UTF_8; + + // when we write and read using buffers + socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); + + ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access + CharBuffer charBuffer = CharBuffer.allocate(8192); + CharsetDecoder decoder = charset.newDecoder(); + StringBuilder ourStore = new StringBuilder(); + while (socketChannel.read(buffer) != -1 || buffer.position() > 0) { + buffer.flip(); + storeBufferContents(buffer, charBuffer, decoder, ourStore); + buffer.compact(); + } + socketChannel.close(); + + // then we read and saved our data + assertTrue(ourStore + .toString() + .contains("It worked!")); + } + + @Test + public void givenJavaNIO_whenReadingAndWriting_thenSmallBuffers() throws IOException { + // given a NIO SocketChannel and a charset + InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); + SocketChannel socket = SocketChannel.open(address); + Charset charset = StandardCharsets.UTF_8; + + // when we write and read using buffers that are too small for our message + socket.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); + + ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access + CharBuffer charBuffer = CharBuffer.allocate(8); + CharsetDecoder decoder = charset.newDecoder(); + StringBuilder ourStore = new StringBuilder(); + while (socket.read(buffer) != -1 || buffer.position() > 0) { + buffer.flip(); + storeBufferContents(buffer, charBuffer, decoder, ourStore); + buffer.compact(); + } + socket.close(); + + // then we read and saved our data + assertTrue(ourStore + .toString() + .contains("It worked!")); + } + + void storeBufferContents(ByteBuffer buffer, CharBuffer charBuffer, CharsetDecoder decoder, StringBuilder ourStore) { + decoder.decode(buffer, charBuffer, true); + charBuffer.flip(); + ourStore.append(charBuffer); + charBuffer.clear(); + } + +} \ No newline at end of file From 1470deb1878580e3e46a8ebcbb1538c4d94df0da Mon Sep 17 00:00:00 2001 From: mguarnaccia Date: Wed, 11 Mar 2020 11:20:37 +0100 Subject: [PATCH 021/278] Delete CoarseGrained.java --- .../concurrent/lock/CoarseGrained.java | 39 ------------------- 1 file changed, 39 deletions(-) delete mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java deleted file mode 100644 index a9af3e1bba..0000000000 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/CoarseGrained.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.concurrent.lock; - -import java.util.Map; -import java.util.concurrent.locks.ReentrantLock; - -import com.google.common.base.Supplier; - -public class CoarseGrained extends ConcurrentAccessMap { - ReentrantLock lock; - - public CoarseGrained(Map map) { - super(map); - lock = new ReentrantLock(); - } - - protected Supplier putSupplier(int x) { - return (()-> { - boolean done = false; - while(!done) { - done = lock.tryLock(); - } - map.put("key" + x, "value" + x); - lock.unlock(); - return null; - }); - } - - protected Supplier getSupplier(int x) { - return (()-> { - boolean done = false; - while(!done) { - done = lock.tryLock(); - } - map.get("key" + x); - lock.unlock(); - return null; - }); - } -} From 52608c32cbee8cb73f261a78106ae9417cbfe615 Mon Sep 17 00:00:00 2001 From: mguarnaccia Date: Wed, 11 Mar 2020 11:21:01 +0100 Subject: [PATCH 022/278] Delete LockStriped.java --- .../baeldung/concurrent/lock/LockStriped.java | 47 ------------------- 1 file changed, 47 deletions(-) delete mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java deleted file mode 100644 index f162c06f89..0000000000 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/LockStriped.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.concurrent.lock; - -import java.util.Map; -import java.util.concurrent.locks.Lock; - -import com.google.common.base.Supplier; -import com.google.common.util.concurrent.Striped; - -public class LockStriped extends ConcurrentAccessMap { - Striped lock; - - public LockStriped(Map map) { - super(map); - lock = getStripedLock(); - } - - private Striped getStripedLock() { - Striped map = Striped.lock(BUCKETS); - return map; - } - - protected Supplier putSupplier(int x) { - return (()-> { - Lock currentLock = lock.get("key" + x); - boolean done = false; - while(!done) { - done = currentLock.tryLock(); - } - map.put("key" + x, "value" + x); - currentLock.unlock(); - return null; - }); - } - - protected Supplier getSupplier(int x) { - return (()-> { - Lock currentLock = lock.get("key" + x); - boolean done = false; - while(!done) { - done = currentLock.tryLock(); - } - map.get("key" + x); - currentLock.unlock(); - return null; - }); - } -} From ff4ac10bb2b8f3f0ba74e0ff084f56dff634dee6 Mon Sep 17 00:00:00 2001 From: Michele Date: Wed, 11 Mar 2020 13:19:25 +0100 Subject: [PATCH 023/278] BAEL-3855 --- .../baeldung/concurrent/lock/BenchMark.java | 48 ------------------- .../concurrent/lock/ConcurrentAccessMap.java | 48 ------------------- .../baeldung/concurrent/lock/SingleLock.java | 26 ++++++---- .../baeldung/concurrent/lock/StripedLock.java | 26 ++++++---- 4 files changed, 32 insertions(+), 116 deletions(-) delete mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java delete mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java deleted file mode 100644 index 5d9e382351..0000000000 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/BenchMark.java +++ /dev/null @@ -1,48 +0,0 @@ -package main.java.com.baeldung.concurrent.lock; -import java.util.concurrent.TimeUnit; - -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.Warmup; - -@State(Scope.Thread) -@Fork(value = 1) -@Warmup(iterations = 0) -public class BenchMark { - ConcurrentAccessMap accessMyMap; - static final int SLOTS = 4; - static final int THREADS = 1000; - static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; - - @Param({"Single Lock", "Striped Lock"}) - private String lockType; - - @Param({"HashMap", "ConcurrentHashMap"}) - private String mapType; - - @Setup - public void setup() { - switch (lockType) { - case "Single Lock": - accessMyMap = new SingleLock(); - break; - case "Striped Lock": - accessMyMap = new StripedLock(BUCKETS); - break; - } - } - - @Benchmark - @BenchmarkMode(Mode.Throughput) - @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void test() throws InterruptedException { - accessMyMap.doWork(mapType, THREADS, SLOTS); - } -} diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java deleted file mode 100644 index e5fcd6d406..0000000000 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessMap.java +++ /dev/null @@ -1,48 +0,0 @@ -package main.java.com.baeldung.concurrent.lock; - -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; - -import com.google.common.base.Supplier; - -public abstract class ConcurrentAccessMap { - - public ConcurrentAccessMap() { - } - - private Map getHashMap() { - return new HashMap(); - } - - private Map getConcurrentHashMap() { - return new ConcurrentHashMap(); - } - - private Map setup(String type) { - switch (type) { - case "HashMap": - return getHashMap(); - case "ConcurrentHashMap": - return getConcurrentHashMap(); - } - return null; - } - - public final void doWork(String type, int threads, int slots) { - CompletableFuture[] requests = new CompletableFuture[threads * slots]; - Map map = setup(type); - - for (int i = 0; i < threads; i++) { - requests[slots * i + 0] = CompletableFuture.supplyAsync(putSupplier(map, i)); - requests[slots * i + 1] = CompletableFuture.supplyAsync(getSupplier(map, i)); - requests[slots * i + 2] = CompletableFuture.supplyAsync(getSupplier(map, i)); - requests[slots * i + 3] = CompletableFuture.supplyAsync(getSupplier(map, i)); - } - CompletableFuture.allOf(requests).join(); - } - - protected abstract Supplier putSupplier(Map map, int key); - protected abstract Supplier getSupplier(Map map, int key); -} \ No newline at end of file diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java index 4f0fe0222a..8a3106f650 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -1,11 +1,11 @@ -package main.java.com.baeldung.concurrent.lock; +package com.baeldung.concurrent.lock; import java.util.Map; import java.util.concurrent.locks.ReentrantLock; import com.google.common.base.Supplier; -public class SingleLock extends ConcurrentAccessMap { +public class SingleLock extends ConcurrentAccessExperiment { ReentrantLock lock; public SingleLock() { @@ -15,11 +15,14 @@ public class SingleLock extends ConcurrentAccessMap { protected synchronized Supplier putSupplier(Map map, int key) { return (()-> { boolean done = false; - while(!done) { - done = lock.tryLock(); + try { + while(!done) { + done = lock.tryLock(); + } + map.put("key" + key, "value" + key); + } finally { + lock.unlock(); } - map.put("key" + key, "value" + key); - lock.unlock(); return null; }); } @@ -27,11 +30,14 @@ public class SingleLock extends ConcurrentAccessMap { protected synchronized Supplier getSupplier(Map map, int key) { return (()-> { boolean done = false; - while(!done) { - done = lock.tryLock(); + try { + while(!done) { + done = lock.tryLock(); + } + map.get("key" + key); + } finally { + lock.unlock(); } - map.get("key" + key); - lock.unlock(); return null; }); } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index fe98dd82be..fad7243bf4 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -1,4 +1,4 @@ -package main.java.com.baeldung.concurrent.lock; +package com.baeldung.concurrent.lock; import java.util.Map; import java.util.concurrent.locks.Lock; @@ -6,7 +6,7 @@ import java.util.concurrent.locks.Lock; import com.google.common.base.Supplier; import com.google.common.util.concurrent.Striped; -public class StripedLock extends ConcurrentAccessMap { +public class StripedLock extends ConcurrentAccessExperiment { Striped lock; public StripedLock(int buckets) { @@ -22,11 +22,14 @@ public class StripedLock extends ConcurrentAccessMap { return (()-> { Lock currentLock = lock.get("key" + key); boolean done = false; - while(!done) { - done = currentLock.tryLock(); + try { + while(!done) { + done = currentLock.tryLock(); + } + map.put("key" + key, "value" + key); + } finally { + currentLock.unlock(); } - map.put("key" + key, "value" + key); - currentLock.unlock(); return null; }); } @@ -35,11 +38,14 @@ public class StripedLock extends ConcurrentAccessMap { return (()-> { Lock currentLock = lock.get("key" + key); boolean done = false; - while(!done) { - done = currentLock.tryLock(); + try { + while(!done) { + done = currentLock.tryLock(); + } + map.get("key" + key); + } finally { + currentLock.unlock(); } - map.get("key" + key); - currentLock.unlock(); return null; }); } From 7cbc45c95aa939462b93db5cc2e987c2259600fe Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:15:02 +0530 Subject: [PATCH 024/278] JAVA-4 : Module pom update --- persistence-modules/pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 15b62d5d77..2e9b033b79 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -21,9 +21,13 @@ flyway hbase hibernate5 - hibernate5-2 hibernate-mapping hibernate-ogm + hibernate5-mapping + hibernate5-annotations + hibernate5-jpa + hibernate5-queries + hibernate5-enterprise influxdb java-cassandra java-cockroachdb From 25d015b3dfb6f62a1c6493c66225a3dc9e14c3fb Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:17:43 +0530 Subject: [PATCH 025/278] JAVA-4 : Removed hibernate5-2 module, moved its artifacts to other modules - hibernate-jpa and hibernate-enterprise --- persistence-modules/hibernate5-2/README.md | 11 --- persistence-modules/hibernate5-2/pom.xml | 74 --------------- .../baeldung/hibernate/logging/Employee.java | 59 ------------ .../baeldung/hibernateparameters/Event.java | 30 ------- .../PersistenceContextDemoApplication.java | 13 --- .../persistencecontext/entity/User.java | 36 -------- ...ExtendedPersistenceContextUserService.java | 33 ------- ...ansctionPersistenceContextUserService.java | 32 ------- .../hibernateparameters/Event.hbm.xml | 15 ---- .../main/resources/hibernate-logging.cfg.xml | 27 ------ .../src/main/resources/hibernate.cfg.xml | 28 ------ .../HibernateLoggingIntegrationTest.java | 50 ----------- .../NamedParameterUnitTest.java | 73 --------------- .../PersistenceContextIntegrationTest.java | 90 ------------------- .../hibernate5-2/src/test/resources/log4j.xml | 25 ------ .../src/test/resources/log4j2.xml | 18 ---- .../src/test/resources/logback.xml | 18 ---- 17 files changed, 632 deletions(-) delete mode 100644 persistence-modules/hibernate5-2/README.md delete mode 100644 persistence-modules/hibernate5-2/pom.xml delete mode 100644 persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernate/logging/Employee.java delete mode 100644 persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernateparameters/Event.java delete mode 100644 persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java delete mode 100644 persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/entity/User.java delete mode 100644 persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java delete mode 100644 persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java delete mode 100644 persistence-modules/hibernate5-2/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml delete mode 100644 persistence-modules/hibernate5-2/src/main/resources/hibernate-logging.cfg.xml delete mode 100644 persistence-modules/hibernate5-2/src/main/resources/hibernate.cfg.xml delete mode 100644 persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java delete mode 100644 persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java delete mode 100644 persistence-modules/hibernate5-2/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java delete mode 100644 persistence-modules/hibernate5-2/src/test/resources/log4j.xml delete mode 100644 persistence-modules/hibernate5-2/src/test/resources/log4j2.xml delete mode 100644 persistence-modules/hibernate5-2/src/test/resources/logback.xml diff --git a/persistence-modules/hibernate5-2/README.md b/persistence-modules/hibernate5-2/README.md deleted file mode 100644 index 330708f6d3..0000000000 --- a/persistence-modules/hibernate5-2/README.md +++ /dev/null @@ -1,11 +0,0 @@ -## Hibernate 5 - -This module contains articles about Hibernate 5. - -### Relevant Articles: -- [Hibernate Error “Not all named parameters have been set”](https://www.baeldung.com/hibernate-error-named-parameters-not-set) -- [FetchMode in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-fetchmode) -- [JPA/Hibernate Persistence Context](https://www.baeldung.com/jpa-hibernate-persistence-context) -- [FetchMode in Hibernate](https://www.baeldung.com/hibernate-fetchmode) -- [Various Logging Levels in Hibernate](https://www.baeldung.com/hibernate-logging-levels) -- [[<-- Prev]](/hibernate5) diff --git a/persistence-modules/hibernate5-2/pom.xml b/persistence-modules/hibernate5-2/pom.xml deleted file mode 100644 index 15d42b3244..0000000000 --- a/persistence-modules/hibernate5-2/pom.xml +++ /dev/null @@ -1,74 +0,0 @@ - - - 4.0.0 - hibernate5-2 - 0.1-SNAPSHOT - hibernate5-2 - jar - Hibernate tutorial illustrating the use of named parameters - - - com.baeldung - persistence-modules - 1.0.0-SNAPSHOT - - - - - org.hibernate - hibernate-core - ${hibernate-core.version} - - - org.springframework.boot - spring-boot-starter-web - ${spring-boot.version} - - - org.springframework.boot - spring-boot-starter-thymeleaf - ${spring-boot.version} - - - org.springframework.boot - spring-boot-starter-data-jpa - ${spring-boot.version} - - - com.zaxxer - HikariCP - - - - - org.springframework.boot - spring-boot-starter-test - ${spring-boot.version} - - - - com.h2database - h2 - ${h2.version} - - - - org.apache.commons - commons-lang3 - ${commons.lang3.version} - - - - - 5.4.7.Final - 1.4.200 - 3.8.1 - true - 2.1.7.RELEASE - 5.4.7.Final - 1.4.200 - 3.8.1 - - - diff --git a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernate/logging/Employee.java b/persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernate/logging/Employee.java deleted file mode 100644 index 9dcf4058a7..0000000000 --- a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernate/logging/Employee.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.baeldung.hibernate.logging; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class Employee { - @Id - @GeneratedValue(strategy = GenerationType.SEQUENCE) - private long id; - - private String employeeNumber; - - private String title; - - private String name; - - public Employee() { - } - - public Employee(String name, String employeeNumber) { - this.name = name; - this.employeeNumber = employeeNumber; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getEmployeeNumber() { - return employeeNumber; - } - - public void setEmployeeNumber(String employeeNumber) { - this.employeeNumber = employeeNumber; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } -} diff --git a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernateparameters/Event.java b/persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernateparameters/Event.java deleted file mode 100644 index 7912659a09..0000000000 --- a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/hibernateparameters/Event.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.hibernateparameters; - -public class Event { - private Long id; - - private String title; - - public Event() { - } - - public Event(String title) { - this.title = title; - } - - public Long getId() { - return id; - } - - private void setId(Long id) { - this.id = id; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java b/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java deleted file mode 100644 index 17fa582e10..0000000000 --- a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.persistencecontext; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - -@SpringBootApplication -@ComponentScan(basePackages="com.baeldung.persistencecontext") -public class PersistenceContextDemoApplication { - public static void main(String[] args) { - SpringApplication.run(PersistenceContextDemoApplication.class, args); - } -} diff --git a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/entity/User.java b/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/entity/User.java deleted file mode 100644 index 7252ac46f5..0000000000 --- a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/entity/User.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.persistencecontext.entity; - -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class User { - - @Id - private Long id; - private String name; - private String role; - - public User() { - - } - - public User(Long id, String name, String role) { - this.id = id; - this.name = name; - this.role = role; - } - - public Long getId() { - return id; - } - - public String getName() { - return name; - } - - public String getRole() { - return role; - } - -} diff --git a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java b/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java deleted file mode 100644 index ef25aac69f..0000000000 --- a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.persistencecontext.service; - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.persistence.PersistenceContextType; -import javax.transaction.Transactional; - -import org.springframework.stereotype.Component; - -import com.baeldung.persistencecontext.entity.User; - -@Component -public class ExtendedPersistenceContextUserService { - - @PersistenceContext(type = PersistenceContextType.EXTENDED) - private EntityManager entityManager; - - @Transactional - public User insertWithTransaction(User user) { - entityManager.persist(user); - return user; - } - - public User insertWithoutTransaction(User user) { - entityManager.persist(user); - return user; - } - - public User find(long id) { - User user = entityManager.find(User.class, id); - return user; - } -} diff --git a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java b/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java deleted file mode 100644 index 481defcf08..0000000000 --- a/persistence-modules/hibernate5-2/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.persistencecontext.service; - - -import javax.persistence.EntityManager; -import javax.persistence.PersistenceContext; -import javax.transaction.Transactional; - -import org.springframework.stereotype.Component; - -import com.baeldung.persistencecontext.entity.User; - -@Component -public class TransctionPersistenceContextUserService { - - @PersistenceContext - private EntityManager entityManager; - - @Transactional - public User insertWithTransaction(User user) { - entityManager.persist(user); - return user; - } - - public User insertWithoutTransaction(User user) { - entityManager.persist(user); - return user; - } - - public User find(long id) { - return entityManager.find(User.class, id); - } -} diff --git a/persistence-modules/hibernate5-2/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml b/persistence-modules/hibernate5-2/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml deleted file mode 100644 index c485080879..0000000000 --- a/persistence-modules/hibernate5-2/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - diff --git a/persistence-modules/hibernate5-2/src/main/resources/hibernate-logging.cfg.xml b/persistence-modules/hibernate5-2/src/main/resources/hibernate-logging.cfg.xml deleted file mode 100644 index 52ef1ee685..0000000000 --- a/persistence-modules/hibernate5-2/src/main/resources/hibernate-logging.cfg.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - org.h2.Driver - jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 - sa - - - 1 - - org.hibernate.dialect.H2Dialect - - org.hibernate.cache.internal.NoCacheProvider - - true - - create - - - - - \ No newline at end of file diff --git a/persistence-modules/hibernate5-2/src/main/resources/hibernate.cfg.xml b/persistence-modules/hibernate5-2/src/main/resources/hibernate.cfg.xml deleted file mode 100644 index be564aaf5a..0000000000 --- a/persistence-modules/hibernate5-2/src/main/resources/hibernate.cfg.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - - - - org.h2.Driver - jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 - sa - - - 1 - - org.hibernate.dialect.H2Dialect - - org.hibernate.cache.internal.NoCacheProvider - - true - - create - - - - - - \ No newline at end of file diff --git a/persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java b/persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java deleted file mode 100644 index f609c75834..0000000000 --- a/persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.baeldung.hibernate.logging; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -import java.io.IOException; -import java.util.List; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.query.Query; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.logging.Employee; - -public class HibernateLoggingIntegrationTest { - - private SessionFactory sessionFactory; - - @Before - public void setUp() throws IOException { - final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure("hibernate-logging.cfg.xml") - .build(); - try { - sessionFactory = new MetadataSources(registry).buildMetadata() - .buildSessionFactory(); - Session session = sessionFactory.openSession(); - session.beginTransaction(); - session.save(new Employee("John Smith", "001")); - session.getTransaction() - .commit(); - session.close(); - } catch (Exception e) { - fail(e); - StandardServiceRegistryBuilder.destroy(registry); - } - } - - @Test - public void whenAllEmployeesAreSelected_ThenSuccess() { - Query query = sessionFactory.openSession().createQuery("from com.baeldung.hibernate.logging.Employee", Employee.class); - List deptEmployees = query.list(); - Employee deptEmployee = deptEmployees.get(0); - assertEquals("John Smith", deptEmployee.getName()); - } -} diff --git a/persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java b/persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java deleted file mode 100644 index 4efa1e1f68..0000000000 --- a/persistence-modules/hibernate5-2/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.baeldung.hibernateparameters; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistry; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.query.Query; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.jupiter.api.Assertions.fail; - -public class NamedParameterUnitTest { - private SessionFactory sessionFactory; - - @Before - public void setUp() throws Exception { - final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() - .configure() - .build(); - try { - sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); - Session session = sessionFactory.openSession(); - session.beginTransaction(); - session.save(new Event("Event 1")); - session.save(new Event("Event 2")); - session.getTransaction().commit(); - session.close(); - } catch (Exception e) { - fail(e); - StandardServiceRegistryBuilder.destroy(registry); - } - } - - @After - public void tearDown() throws Exception { - if (sessionFactory != null) { - sessionFactory.close(); - } - } - - @Test - public void whenNamedParameterProvided_thenCorrect() { - Session session = sessionFactory.openSession(); - session.beginTransaction(); - Query query = session.createQuery("from Event E WHERE E.title = :eventTitle", Event.class); - - // This binds the value "Event1" to the parameter :eventTitle - query.setParameter("eventTitle", "Event 1"); - - assertEquals(1, query.list().size()); - session.getTransaction().commit(); - session.close(); - } - - @Test(expected = org.hibernate.QueryException.class) - public void whenNamedParameterMissing_thenThrowsQueryException() { - Session session = sessionFactory.openSession(); - session.beginTransaction(); - Query query = session.createQuery("from Event E WHERE E.title = :eventTitle", Event.class); - - try { - query.list(); - fail("We are expecting an exception!"); - } finally { - session.getTransaction().commit(); - session.close(); - } - } -} diff --git a/persistence-modules/hibernate5-2/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java b/persistence-modules/hibernate5-2/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java deleted file mode 100644 index b299dd5834..0000000000 --- a/persistence-modules/hibernate5-2/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.baeldung.persistencecontext; - -import com.baeldung.persistencecontext.entity.User; -import com.baeldung.persistencecontext.service.ExtendedPersistenceContextUserService; -import com.baeldung.persistencecontext.service.TransctionPersistenceContextUserService; - -import javax.persistence.EntityExistsException; -import javax.persistence.TransactionRequiredException; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = com.baeldung.persistencecontext.PersistenceContextDemoApplication.class) -public class PersistenceContextIntegrationTest { - - @Autowired - private TransctionPersistenceContextUserService transctionPersistenceContext; - @Autowired - private ExtendedPersistenceContextUserService extendedPersistenceContext; - - @Test - public void testThatWhenUserSavedWithTransctionPersistenceContextThenUserShouldGetSavedInDB() { - User user = new User(121L, "Devender", "admin"); - transctionPersistenceContext.insertWithTransaction(user); - - User userFromTransctionPersistenceContext = transctionPersistenceContext.find(user.getId()); - assertNotNull(userFromTransctionPersistenceContext); - - User userFromExtendedPersistenceContext = extendedPersistenceContext.find(user.getId()); - assertNotNull(userFromExtendedPersistenceContext); - } - - @Test(expected = TransactionRequiredException.class) - public void testThatUserSaveWithoutTransactionThrowException() { - User user = new User(122L, "Devender", "admin"); - transctionPersistenceContext.insertWithoutTransaction(user); - } - - @Test - public void testThatWhenUserSavedWithExtendedPersistenceContextWithoutTransactionThenUserShouldGetCached() { - User user = new User(123L, "Devender", "admin"); - extendedPersistenceContext.insertWithoutTransaction(user); - - User userFromExtendedPersistenceContext = extendedPersistenceContext.find(user.getId()); - assertNotNull(userFromExtendedPersistenceContext); - - User userFromTransctionPersistenceContext = transctionPersistenceContext.find(user.getId()); - assertNull(userFromTransctionPersistenceContext); - } - - @Test(expected = EntityExistsException.class) - public void testThatPersistUserWithSameIdentifierThrowException() { - User user1 = new User(126L, "Devender", "admin"); - User user2 = new User(126L, "Devender", "admin"); - extendedPersistenceContext.insertWithoutTransaction(user1); - extendedPersistenceContext.insertWithoutTransaction(user2); - } - - @Test - public void testThatWhenUserSavedWithExtendedPersistenceContextWithTransactionThenUserShouldSaveEntityIntoDB() { - User user = new User(127L, "Devender", "admin"); - extendedPersistenceContext.insertWithTransaction(user); - - User userFromDB = transctionPersistenceContext.find(user.getId()); - assertNotNull(userFromDB); - } - - @Test - public void testThatWhenUserSavedWithExtendedPersistenceContextWithTransactionThenUserShouldFlushCachedEntityIntoDB() { - User user1 = new User(124L, "Devender", "admin"); - extendedPersistenceContext.insertWithoutTransaction(user1); - - User user2 = new User(125L, "Devender", "admin"); - extendedPersistenceContext.insertWithTransaction(user2); - - User user1FromTransctionPersistenceContext = transctionPersistenceContext.find(user1.getId()); - assertNotNull(user1FromTransctionPersistenceContext); - - User user2FromTransctionPersistenceContext = transctionPersistenceContext.find(user2.getId()); - assertNotNull(user2FromTransctionPersistenceContext); - } - -} diff --git a/persistence-modules/hibernate5-2/src/test/resources/log4j.xml b/persistence-modules/hibernate5-2/src/test/resources/log4j.xml deleted file mode 100644 index 2d153af124..0000000000 --- a/persistence-modules/hibernate5-2/src/test/resources/log4j.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/persistence-modules/hibernate5-2/src/test/resources/log4j2.xml b/persistence-modules/hibernate5-2/src/test/resources/log4j2.xml deleted file mode 100644 index c5d0f12462..0000000000 --- a/persistence-modules/hibernate5-2/src/test/resources/log4j2.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/persistence-modules/hibernate5-2/src/test/resources/logback.xml b/persistence-modules/hibernate5-2/src/test/resources/logback.xml deleted file mode 100644 index 9e591977d7..0000000000 --- a/persistence-modules/hibernate5-2/src/test/resources/logback.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - %d{yyyy-MM-dd HH:mm:ss} | %-5p | [%thread] %logger{5}:%L - %msg%n - - - - - - - - - - - - \ No newline at end of file From a5ae83d28aef770b7ef5722a56d086244369a549 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:18:27 +0530 Subject: [PATCH 026/278] JAVA-4 : Split hibernate5 module to smaller parts --- persistence-modules/hibernate5/README.md | 25 -- .../com/baeldung/hibernate/HibernateUtil.java | 28 -- .../converters/PersonNameConverter.java | 61 --- .../criteriaquery/HibernateUtil.java | 60 --- .../hibernate/criteriaquery/Student.java | 58 --- .../hibernate/customtypes/Address.java | 69 --- .../hibernate/customtypes/AddressType.java | 169 ------- .../LocalDateStringJavaDescriptor.java | 51 --- .../customtypes/LocalDateStringType.java | 34 -- .../hibernate/customtypes/OfficeEmployee.java | 88 ---- .../hibernate/customtypes/PhoneNumber.java | 43 -- .../customtypes/PhoneNumberType.java | 98 ---- .../hibernate/customtypes/Salary.java | 39 -- .../customtypes/SalaryCurrencyConvertor.java | 15 - .../hibernate/customtypes/SalaryType.java | 161 ------- .../hibernate/exception/EntityWithNoId.java | 16 - .../hibernate/exception/HibernateUtil.java | 63 --- .../baeldung/hibernate/exception/Product.java | 40 -- .../baeldung/hibernate/findall/FindAll.java | 35 -- .../baeldung/hibernate/joincolumn/Email.java | 47 -- .../baeldung/hibernate/joincolumn/Office.java | 41 -- .../hibernate/joincolumn/OfficeAddress.java | 34 -- .../joincolumn/OfficialEmployee.java | 36 -- .../jpabootstrap/application/Application.java | 34 -- .../config/HibernatePersistenceUnitInfo.java | 131 ------ .../config/JpaEntityManagerFactory.java | 69 --- .../hibernate/jpabootstrap/entities/User.java | 45 -- .../service/EmployeeSearchService.java | 15 - .../service/EmployeeSearchServiceImpl.java | 77 ---- .../hibernate/lob/HibernateSessionUtil.java | 61 --- .../baeldung/hibernate/lob/model/User.java | 46 -- .../hibernate/onetoone/HibernateUtil.java | 63 --- .../baeldung/hibernate/onetoone/Strategy.java | 25 -- .../onetoone/foreignkeybased/Address.java | 60 --- .../onetoone/foreignkeybased/User.java | 51 --- .../onetoone/jointablebased/Employee.java | 53 --- .../onetoone/jointablebased/WorkStation.java | 61 --- .../onetoone/sharedkeybased/Address.java | 60 --- .../onetoone/sharedkeybased/User.java | 50 --- .../OptimisticLockingCourse.java | 48 -- .../OptimisticLockingStudent.java | 70 --- .../hibernate/pessimisticlocking/Address.java | 34 -- .../pessimisticlocking/Customer.java | 58 --- .../pessimisticlocking/Individual.java | 49 -- .../PessimisticLockingCourse.java | 47 -- .../PessimisticLockingEmployee.java | 27 -- .../PessimisticLockingStudent.java | 46 -- .../com/baeldung/hibernate/pojo/Person.java | 32 -- .../hibernate/transaction/PostService.java | 29 -- .../hibernate/CustomClassIntegrationTest.java | 78 ---- .../DynamicMappingIntegrationTest.java | 160 ------- .../HibernateSpatialIntegrationTest.java | 161 ------- .../InheritanceMappingIntegrationTest.java | 89 ---- .../hibernate/NamedQueryIntegrationTest.java | 98 ---- .../hibernate/TemporalValuesUnitTest.java | 128 ------ .../AggregateFunctionsIntegrationTest.java | 87 ---- .../PersonNameConverterUnitTest.java | 200 --------- .../TypeSafeCriteriaIntegrationTest.java | 89 ---- .../HibernateCustomTypesManualTest.java | 90 ---- .../exception/HibernateExceptionUnitTest.java | 425 ------------------ .../hibernate/findall/FindAllUnitTest.java | 63 --- .../joincolumn/JoinColumnIntegrationTest.java | 57 --- .../EmployeeSearchServiceIntegrationTest.java | 121 ----- .../baeldung/hibernate/lob/LobUnitTest.java | 61 --- .../baeldung/hibernate/multitenancy/Car.java | 26 -- .../MultitenancyIntegrationTest.java | 104 ----- ...seApproachMultitenancyIntegrationTest.java | 25 -- .../MapMultiTenantConnectionProvider.java | 42 -- .../multitenancy/database/TenantIdNames.java | 6 - ...maApproachMultitenancyIntegrationTest.java | 26 -- .../SchemaMultiTenantConnectionProvider.java | 48 -- .../multitenancy/schema/TenantIdNames.java | 6 - ...ToOneAnnotationFKBasedIntegrationTest.java | 80 ---- ...ToOneAnnotationJTBasedIntegrationTest.java | 80 ---- ...oOneAnnotationSPKBasedIntegrationTest.java | 79 ---- .../OptimisticLockingIntegrationTest.java | 146 ------ ...asicPessimisticLockingIntegrationTest.java | 162 ------- .../PessimisticLockScopesIntegrationTest.java | 125 ------ .../QueryPlanCacheBenchmark.java | 106 ----- .../TransactionIntegrationTest.java | 57 --- .../hibernate-customtypes.properties | 14 - ...hibernate-database-multitenancy.properties | 2 - .../hibernate-database-mydb1.properties | 4 - .../hibernate-database-mydb2.properties | 4 - .../resources/hibernate-exception.properties | 16 - .../resources/hibernate-namedquery.properties | 9 - .../hibernate-pessimistic-locking.properties | 8 - .../hibernate-schema-multitenancy.properties | 7 - .../resources/hibernate-spatial.properties | 14 - 89 files changed, 5755 deletions(-) delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Address.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Salary.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/Product.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/model/User.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Person.java delete mode 100644 persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/transaction/PostService.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/Car.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java delete mode 100644 persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-database-multitenancy.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb1.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb2.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-exception.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-namedquery.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-schema-multitenancy.properties delete mode 100644 persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index d1bfe897f6..7b5e3bb189 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -4,38 +4,13 @@ This module contains articles about Hibernate 5. ### Relevant articles: -- [Dynamic Mapping with Hibernate](http://www.baeldung.com/hibernate-dynamic-mapping) - [An Overview of Identifiers in Hibernate](http://www.baeldung.com/hibernate-identifiers) -- [Hibernate – Mapping Date and Time](http://www.baeldung.com/hibernate-date-time) -- [Hibernate Inheritance Mapping](http://www.baeldung.com/hibernate-inheritance) -- [A Guide to Multitenancy in Hibernate 5](http://www.baeldung.com/hibernate-5-multitenancy) -- [Introduction to Hibernate Spatial](http://www.baeldung.com/hibernate-spatial) - [Hibernate Interceptors](http://www.baeldung.com/hibernate-interceptor) -- [JPA Attribute Converters](http://www.baeldung.com/jpa-attribute-converters) -- [Mapping LOB Data in Hibernate](http://www.baeldung.com/hibernate-lob) -- [@Immutable in Hibernate](http://www.baeldung.com/hibernate-immutable) -- [Pessimistic Locking in JPA](http://www.baeldung.com/jpa-pessimistic-locking) -- [Bootstrapping JPA Programmatically in Java](http://www.baeldung.com/java-bootstrap-jpa) -- [Optimistic Locking in JPA](http://www.baeldung.com/jpa-optimistic-locking) - [Hibernate Entity Lifecycle](https://www.baeldung.com/hibernate-entity-lifecycle) -- [Mapping A Hibernate Query to a Custom Class](https://www.baeldung.com/hibernate-query-to-custom-class) -- [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column) - [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy) - [Proxy in Hibernate load() Method](https://www.baeldung.com/hibernate-proxy-load-method) -- [Custom Types in Hibernate and the @Type Annotation](https://www.baeldung.com/hibernate-custom-types) -- [Criteria API – An Example of IN Expressions](https://www.baeldung.com/jpa-criteria-api-in-expressions) -- [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby) - [Hibernate 5 Bootstrapping API](https://www.baeldung.com/hibernate-5-bootstrapping-api) -- [Criteria Queries Using JPA Metamodel](https://www.baeldung.com/hibernate-criteria-queries-metamodel) - [Guide to the Hibernate EntityManager](https://www.baeldung.com/hibernate-entitymanager) -- [Get All Data from a Table with Hibernate](https://www.baeldung.com/hibernate-select-all) -- [One-to-One Relationship in JPA](https://www.baeldung.com/jpa-one-to-one) -- [Hibernate Named Query](https://www.baeldung.com/hibernate-named-query) - [Using c3p0 with Hibernate](https://www.baeldung.com/hibernate-c3p0) - [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) -- [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions) -- [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions) -- [Hibernate Query Plan Cache](https://www.baeldung.com/hibernate-query-plan-cache) -- [TransactionRequiredException Error](https://www.baeldung.com/jpa-transaction-required-exception) -- [Enabling Transaction Locks in Spring Data JPA](https://www.baeldung.com/java-jpa-transaction-locks) - [[Next -->]](/hibernate5-2) \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java index 137fc4f0bd..11a59c9cf0 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -12,25 +12,13 @@ import org.hibernate.boot.MetadataSources; import org.hibernate.boot.registry.StandardServiceRegistryBuilder; import org.hibernate.service.ServiceRegistry; -import com.baeldung.hibernate.customtypes.LocalDateStringType; -import com.baeldung.hibernate.customtypes.OfficeEmployee; import com.baeldung.hibernate.entities.DeptEmployee; -import com.baeldung.hibernate.joincolumn.Email; -import com.baeldung.hibernate.joincolumn.Office; -import com.baeldung.hibernate.joincolumn.OfficeAddress; -import com.baeldung.hibernate.optimisticlocking.OptimisticLockingCourse; -import com.baeldung.hibernate.optimisticlocking.OptimisticLockingStudent; -import com.baeldung.hibernate.pessimisticlocking.Individual; -import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingCourse; -import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingEmployee; -import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingStudent; import com.baeldung.hibernate.pojo.Course; import com.baeldung.hibernate.pojo.Employee; import com.baeldung.hibernate.pojo.EntityDescription; import com.baeldung.hibernate.pojo.OrderEntry; import com.baeldung.hibernate.pojo.OrderEntryIdClass; import com.baeldung.hibernate.pojo.OrderEntryPK; -import com.baeldung.hibernate.pojo.Person; import com.baeldung.hibernate.pojo.Phone; import com.baeldung.hibernate.pojo.PointEntity; import com.baeldung.hibernate.pojo.PolygonEntity; @@ -88,7 +76,6 @@ public class HibernateUtil { metadataSources.addAnnotatedClass(MyEmployee.class); metadataSources.addAnnotatedClass(MyProduct.class); metadataSources.addAnnotatedClass(Pen.class); - metadataSources.addAnnotatedClass(Person.class); metadataSources.addAnnotatedClass(Animal.class); metadataSources.addAnnotatedClass(Pet.class); metadataSources.addAnnotatedClass(Vehicle.class); @@ -96,26 +83,11 @@ public class HibernateUtil { metadataSources.addAnnotatedClass(Bag.class); metadataSources.addAnnotatedClass(PointEntity.class); metadataSources.addAnnotatedClass(PolygonEntity.class); - metadataSources.addAnnotatedClass(com.baeldung.hibernate.pojo.Person.class); - metadataSources.addAnnotatedClass(Individual.class); - metadataSources.addAnnotatedClass(PessimisticLockingEmployee.class); - metadataSources.addAnnotatedClass(PessimisticLockingStudent.class); - metadataSources.addAnnotatedClass(PessimisticLockingCourse.class); - metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Customer.class); - metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Address.class); metadataSources.addAnnotatedClass(DeptEmployee.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); - metadataSources.addAnnotatedClass(OptimisticLockingCourse.class); - metadataSources.addAnnotatedClass(OptimisticLockingStudent.class); - metadataSources.addAnnotatedClass(OfficeEmployee.class); metadataSources.addAnnotatedClass(Post.class); - metadataSources.addAnnotatedClass(com.baeldung.hibernate.joincolumn.OfficialEmployee.class); - metadataSources.addAnnotatedClass(Email.class); - metadataSources.addAnnotatedClass(Office.class); - metadataSources.addAnnotatedClass(OfficeAddress.class); Metadata metadata = metadataSources.getMetadataBuilder() - .applyBasicType(LocalDateStringType.INSTANCE) .build(); return metadata.getSessionFactoryBuilder() diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java deleted file mode 100644 index 506e674984..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.hibernate.converters; - -import javax.persistence.AttributeConverter; -import javax.persistence.Converter; - -import com.baeldung.hibernate.pojo.PersonName; - -@Converter -public class PersonNameConverter implements AttributeConverter { - - private static final String SEPARATOR = ", "; - - @Override - public String convertToDatabaseColumn(PersonName personName) { - if (personName == null) { - return null; - } - - StringBuilder sb = new StringBuilder(); - if (personName.getSurname() != null && !personName.getSurname() - .isEmpty()) { - sb.append(personName.getSurname()); - sb.append(SEPARATOR); - } - - if (personName.getName() != null && !personName.getName() - .isEmpty()) { - sb.append(personName.getName()); - } - - return sb.toString(); - } - - @Override - public PersonName convertToEntityAttribute(String dbPersonName) { - if (dbPersonName == null || dbPersonName.isEmpty()) { - return null; - } - - String[] pieces = dbPersonName.split(SEPARATOR); - - if (pieces == null || pieces.length == 0) { - return null; - } - - PersonName personName = new PersonName(); - String firstPiece = !pieces[0].isEmpty() ? pieces[0] : null; - if (dbPersonName.contains(SEPARATOR)) { - personName.setSurname(firstPiece); - - if (pieces.length >= 2 && pieces[1] != null && !pieces[1].isEmpty()) { - personName.setName(pieces[1]); - } - } else { - personName.setName(firstPiece); - } - - return personName; - } - -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java deleted file mode 100644 index 35cfe55ba6..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.hibernate.criteriaquery; - -import com.baeldung.hibernate.customtypes.LocalDateStringType; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.service.ServiceRegistry; - -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Properties; - -public class HibernateUtil { - private static SessionFactory sessionFactory; - - private HibernateUtil() { - } - - public static SessionFactory getSessionFactory() { - if (sessionFactory == null) { - sessionFactory = buildSessionFactory(); - } - return sessionFactory; - } - - private static SessionFactory buildSessionFactory() { - try { - ServiceRegistry serviceRegistry = configureServiceRegistry(); - - MetadataSources metadataSources = new MetadataSources(serviceRegistry); - - metadataSources.addAnnotatedClass(Student.class); - Metadata metadata = metadataSources.getMetadataBuilder() - .applyBasicType(LocalDateStringType.INSTANCE) - .build(); - return metadata.getSessionFactoryBuilder().build(); - } catch (IOException ex) { - throw new ExceptionInInitializerError(ex); - } - } - - - private static ServiceRegistry configureServiceRegistry() throws IOException { - Properties properties = getProperties(); - return new StandardServiceRegistryBuilder().applySettings(properties).build(); - } - - private static Properties getProperties() throws IOException { - Properties properties = new Properties(); - URL propertiesURL = Thread.currentThread() - .getContextClassLoader() - .getResource("hibernate.properties"); - try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { - properties.load(inputStream); - } - return properties; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java deleted file mode 100644 index 314e7ca557..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.hibernate.criteriaquery; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "students") -public class Student { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private int id; - - @Column(name = "first_name") - private String firstName; - - @Column(name = "last_name") - private String lastName; - - @Column(name = "grad_year") - private int gradYear; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public int getGradYear() { - return gradYear; - } - - public void setGradYear(int gradYear) { - this.gradYear = gradYear; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Address.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Address.java deleted file mode 100644 index d559e5a6c2..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Address.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import java.util.Objects; - -public class Address { - - private String addressLine1; - private String addressLine2; - private String city; - private String country; - private int zipCode; - - public String getAddressLine1() { - return addressLine1; - } - - public String getAddressLine2() { - return addressLine2; - } - - public String getCity() { - return city; - } - - public String getCountry() { - return country; - } - - public int getZipCode() { - return zipCode; - } - - public void setAddressLine1(String addressLine1) { - this.addressLine1 = addressLine1; - } - - public void setAddressLine2(String addressLine2) { - this.addressLine2 = addressLine2; - } - - public void setCity(String city) { - this.city = city; - } - - public void setCountry(String country) { - this.country = country; - } - - public void setZipCode(int zipCode) { - this.zipCode = zipCode; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Address address = (Address) o; - return zipCode == address.zipCode && - Objects.equals(addressLine1, address.addressLine1) && - Objects.equals(addressLine2, address.addressLine2) && - Objects.equals(city, address.city) && - Objects.equals(country, address.country); - } - - @Override - public int hashCode() { - return Objects.hash(addressLine1, addressLine2, city, country, zipCode); - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java deleted file mode 100644 index c10c67df9a..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java +++ /dev/null @@ -1,169 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.type.IntegerType; -import org.hibernate.type.StringType; -import org.hibernate.type.Type; -import org.hibernate.usertype.CompositeUserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Objects; - -public class AddressType implements CompositeUserType { - - @Override - public String[] getPropertyNames() { - return new String[]{"addressLine1", "addressLine2", - "city", "country", "zipcode"}; - } - - @Override - public Type[] getPropertyTypes() { - return new Type[]{StringType.INSTANCE, StringType.INSTANCE, - StringType.INSTANCE, StringType.INSTANCE, IntegerType.INSTANCE}; - } - - @Override - public Object getPropertyValue(Object component, int property) throws HibernateException { - - Address empAdd = (Address) component; - - switch (property) { - case 0: - return empAdd.getAddressLine1(); - case 1: - return empAdd.getAddressLine2(); - case 2: - return empAdd.getCity(); - case 3: - return empAdd.getCountry(); - case 4: - return Integer.valueOf(empAdd.getZipCode()); - } - - throw new IllegalArgumentException(property + - " is an invalid property index for class type " + - component.getClass().getName()); - } - - @Override - public void setPropertyValue(Object component, int property, Object value) throws HibernateException { - - Address empAdd = (Address) component; - - switch (property) { - case 0: - empAdd.setAddressLine1((String) value); - case 1: - empAdd.setAddressLine2((String) value); - case 2: - empAdd.setCity((String) value); - case 3: - empAdd.setCountry((String) value); - case 4: - empAdd.setZipCode((Integer) value); - } - - throw new IllegalArgumentException(property + - " is an invalid property index for class type " + - component.getClass().getName()); - - } - - @Override - public Class returnedClass() { - return Address.class; - } - - @Override - public boolean equals(Object x, Object y) throws HibernateException { - if (x == y) - return true; - - if (Objects.isNull(x) || Objects.isNull(y)) - return false; - - return x.equals(y); - } - - @Override - public int hashCode(Object x) throws HibernateException { - return x.hashCode(); - } - - @Override - public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { - - Address empAdd = new Address(); - empAdd.setAddressLine1(rs.getString(names[0])); - - if (rs.wasNull()) - return null; - - empAdd.setAddressLine2(rs.getString(names[1])); - empAdd.setCity(rs.getString(names[2])); - empAdd.setCountry(rs.getString(names[3])); - empAdd.setZipCode(rs.getInt(names[4])); - - return empAdd; - } - - @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { - - if (Objects.isNull(value)) - st.setNull(index, Types.VARCHAR); - else { - - Address empAdd = (Address) value; - st.setString(index, empAdd.getAddressLine1()); - st.setString(index + 1, empAdd.getAddressLine2()); - st.setString(index + 2, empAdd.getCity()); - st.setString(index + 3, empAdd.getCountry()); - st.setInt(index + 4, empAdd.getZipCode()); - } - } - - @Override - public Object deepCopy(Object value) throws HibernateException { - - if (Objects.isNull(value)) - return null; - - Address oldEmpAdd = (Address) value; - Address newEmpAdd = new Address(); - - newEmpAdd.setAddressLine1(oldEmpAdd.getAddressLine1()); - newEmpAdd.setAddressLine2(oldEmpAdd.getAddressLine2()); - newEmpAdd.setCity(oldEmpAdd.getCity()); - newEmpAdd.setCountry(oldEmpAdd.getCountry()); - newEmpAdd.setZipCode(oldEmpAdd.getZipCode()); - - return newEmpAdd; - } - - @Override - public boolean isMutable() { - return true; - } - - @Override - public Serializable disassemble(Object value, SharedSessionContractImplementor session) throws HibernateException { - return (Serializable) deepCopy(value); - } - - @Override - public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) throws HibernateException { - return deepCopy(cached); - } - - @Override - public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner) throws HibernateException { - return original; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java deleted file mode 100644 index 56be9e693f..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import org.hibernate.type.LocalDateType; -import org.hibernate.type.descriptor.WrapperOptions; -import org.hibernate.type.descriptor.java.AbstractTypeDescriptor; -import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan; -import org.hibernate.type.descriptor.java.MutabilityPlan; - -import java.time.LocalDate; - -public class LocalDateStringJavaDescriptor extends AbstractTypeDescriptor { - - public static final LocalDateStringJavaDescriptor INSTANCE = new LocalDateStringJavaDescriptor(); - - public LocalDateStringJavaDescriptor() { - super(LocalDate.class, ImmutableMutabilityPlan.INSTANCE); - } - - @Override - public String toString(LocalDate value) { - return LocalDateType.FORMATTER.format(value); - } - - @Override - public LocalDate fromString(String string) { - return LocalDate.from(LocalDateType.FORMATTER.parse(string)); - } - - @Override - public X unwrap(LocalDate value, Class type, WrapperOptions options) { - - if (value == null) - return null; - - if (String.class.isAssignableFrom(type)) - return (X) LocalDateType.FORMATTER.format(value); - - throw unknownUnwrap(type); - } - - @Override - public LocalDate wrap(X value, WrapperOptions options) { - if (value == null) - return null; - - if(String.class.isInstance(value)) - return LocalDate.from(LocalDateType.FORMATTER.parse((CharSequence) value)); - - throw unknownWrap(value.getClass()); - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java deleted file mode 100644 index c8d37073e8..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import org.hibernate.dialect.Dialect; -import org.hibernate.type.AbstractSingleColumnStandardBasicType; -import org.hibernate.type.DiscriminatorType; -import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor; -import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; - -import java.time.LocalDate; - -public class LocalDateStringType extends AbstractSingleColumnStandardBasicType implements DiscriminatorType { - - public static final LocalDateStringType INSTANCE = new LocalDateStringType(); - - public LocalDateStringType() { - super(VarcharTypeDescriptor.INSTANCE, LocalDateStringJavaDescriptor.INSTANCE); - } - - @Override - public String getName() { - return "LocalDateString"; - } - - @Override - public LocalDate stringToObject(String xml) throws Exception { - return fromString(xml); - } - - @Override - public String objectToSQLString(LocalDate value, Dialect dialect) throws Exception { - return '\'' + toString(value) + '\''; - } - -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java deleted file mode 100644 index 3ca06e4316..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import com.baeldung.hibernate.pojo.Phone; -import org.hibernate.annotations.Columns; -import org.hibernate.annotations.Parameter; -import org.hibernate.annotations.Type; -import org.hibernate.annotations.TypeDef; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.Table; -import java.time.LocalDate; - -@TypeDef(name = "PhoneNumber", - typeClass = PhoneNumberType.class, - defaultForType = PhoneNumber.class) -@Entity -@Table(name = "OfficeEmployee") -public class OfficeEmployee { - - @Id - @GeneratedValue - private long id; - - @Column - @Type(type = "LocalDateString") - private LocalDate dateOfJoining; - - @Columns(columns = {@Column(name = "country_code"), - @Column(name = "city_code"), - @Column(name = "number")}) - private PhoneNumber employeeNumber; - - @Columns(columns = {@Column(name = "address_line_1"), - @Column(name = "address_line_2"), - @Column(name = "city"), @Column(name = "country"), - @Column(name = "zip_code")}) - @Type(type = "com.baeldung.hibernate.customtypes.AddressType") - private Address empAddress; - - @Type(type = "com.baeldung.hibernate.customtypes.SalaryType", - parameters = {@Parameter(name = "currency", value = "USD")}) - @Columns(columns = {@Column(name = "amount"), - @Column(name = "currency")}) - private Salary salary; - - public Salary getSalary() { - return salary; - } - - public void setSalary(Salary salary) { - this.salary = salary; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public LocalDate getDateOfJoining() { - return dateOfJoining; - } - - public void setDateOfJoining(LocalDate dateOfJoining) { - this.dateOfJoining = dateOfJoining; - } - - public PhoneNumber getEmployeeNumber() { - return employeeNumber; - } - - public void setEmployeeNumber(PhoneNumber employeeNumber) { - this.employeeNumber = employeeNumber; - } - - public Address getEmpAddress() { - return empAddress; - } - - public void setEmpAddress(Address empAddress) { - this.empAddress = empAddress; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java deleted file mode 100644 index 0be6cbc910..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import java.util.Objects; - -public final class PhoneNumber { - - private final int countryCode; - private final int cityCode; - private final int number; - - public PhoneNumber(int countryCode, int cityCode, int number) { - this.countryCode = countryCode; - this.cityCode = cityCode; - this.number = number; - } - - public int getCountryCode() { - return countryCode; - } - - public int getCityCode() { - return cityCode; - } - - public int getNumber() { - return number; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - PhoneNumber that = (PhoneNumber) o; - return countryCode == that.countryCode && - cityCode == that.cityCode && - number == that.number; - } - - @Override - public int hashCode() { - return Objects.hash(countryCode, cityCode, number); - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java deleted file mode 100644 index 9f09352bec..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.usertype.UserType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Objects; - - -public class PhoneNumberType implements UserType { - @Override - public int[] sqlTypes() { - return new int[]{Types.INTEGER, Types.INTEGER, Types.INTEGER}; - } - - @Override - public Class returnedClass() { - return PhoneNumber.class; - } - - @Override - public boolean equals(Object x, Object y) throws HibernateException { - if (x == y) - return true; - if (Objects.isNull(x) || Objects.isNull(y)) - return false; - - return x.equals(y); - } - - @Override - public int hashCode(Object x) throws HibernateException { - return x.hashCode(); - } - - @Override - public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { - int countryCode = rs.getInt(names[0]); - - if (rs.wasNull()) - return null; - - int cityCode = rs.getInt(names[1]); - int number = rs.getInt(names[2]); - PhoneNumber employeeNumber = new PhoneNumber(countryCode, cityCode, number); - - return employeeNumber; - } - - @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { - - if (Objects.isNull(value)) { - st.setNull(index, Types.INTEGER); - } else { - PhoneNumber employeeNumber = (PhoneNumber) value; - st.setInt(index,employeeNumber.getCountryCode()); - st.setInt(index+1,employeeNumber.getCityCode()); - st.setInt(index+2,employeeNumber.getNumber()); - } - } - - @Override - public Object deepCopy(Object value) throws HibernateException { - if (Objects.isNull(value)) - return null; - - PhoneNumber empNumber = (PhoneNumber) value; - PhoneNumber newEmpNumber = new PhoneNumber(empNumber.getCountryCode(),empNumber.getCityCode(),empNumber.getNumber()); - - return newEmpNumber; - } - - @Override - public boolean isMutable() { - return false; - } - - @Override - public Serializable disassemble(Object value) throws HibernateException { - return (Serializable) value; - } - - @Override - public Object assemble(Serializable cached, Object owner) throws HibernateException { - return cached; - } - - @Override - public Object replace(Object original, Object target, Object owner) throws HibernateException { - return original; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Salary.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Salary.java deleted file mode 100644 index f9a7ac5902..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/Salary.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import java.util.Objects; - -public class Salary { - - private Long amount; - private String currency; - - public Long getAmount() { - return amount; - } - - public void setAmount(Long amount) { - this.amount = amount; - } - - public String getCurrency() { - return currency; - } - - public void setCurrency(String currency) { - this.currency = currency; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - Salary salary = (Salary) o; - return Objects.equals(amount, salary.amount) && - Objects.equals(currency, salary.currency); - } - - @Override - public int hashCode() { - return Objects.hash(amount, currency); - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java deleted file mode 100644 index 340c697c11..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -public class SalaryCurrencyConvertor { - - public static Long convert(Long amount, String oldCurr, String newCurr){ - if (newCurr.equalsIgnoreCase(oldCurr)) - return amount; - - return convertTo(); - } - - private static Long convertTo() { - return 10L; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java deleted file mode 100644 index 266b85140b..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import org.hibernate.HibernateException; -import org.hibernate.engine.spi.SharedSessionContractImplementor; -import org.hibernate.type.LongType; -import org.hibernate.type.StringType; -import org.hibernate.type.Type; -import org.hibernate.usertype.CompositeUserType; -import org.hibernate.usertype.DynamicParameterizedType; - -import java.io.Serializable; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Types; -import java.util.Objects; -import java.util.Properties; - -public class SalaryType implements CompositeUserType, DynamicParameterizedType { - - private String localCurrency; - - @Override - public String[] getPropertyNames() { - return new String[]{"amount", "currency"}; - } - - @Override - public Type[] getPropertyTypes() { - return new Type[]{LongType.INSTANCE, StringType.INSTANCE}; - } - - @Override - public Object getPropertyValue(Object component, int property) throws HibernateException { - - Salary salary = (Salary) component; - - switch (property) { - case 0: - return salary.getAmount(); - case 1: - return salary.getCurrency(); - } - - throw new IllegalArgumentException(property + - " is an invalid property index for class type " + - component.getClass().getName()); - - } - - - @Override - public void setPropertyValue(Object component, int property, Object value) throws HibernateException { - - Salary salary = (Salary) component; - - switch (property) { - case 0: - salary.setAmount((Long) value); - case 1: - salary.setCurrency((String) value); - } - - throw new IllegalArgumentException(property + - " is an invalid property index for class type " + - component.getClass().getName()); - - } - - @Override - public Class returnedClass() { - return Salary.class; - } - - @Override - public boolean equals(Object x, Object y) throws HibernateException { - - if (x == y) - return true; - - if (Objects.isNull(x) || Objects.isNull(y)) - return false; - - return x.equals(y); - - } - - @Override - public int hashCode(Object x) throws HibernateException { - return x.hashCode(); - } - - @Override - public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { - - Salary salary = new Salary(); - salary.setAmount(rs.getLong(names[0])); - - if (rs.wasNull()) - return null; - - salary.setCurrency(rs.getString(names[1])); - - return salary; - } - - @Override - public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { - - - if (Objects.isNull(value)) - st.setNull(index, Types.BIGINT); - else { - - Salary salary = (Salary) value; - st.setLong(index, SalaryCurrencyConvertor.convert(salary.getAmount(), - salary.getCurrency(), localCurrency)); - st.setString(index + 1, salary.getCurrency()); - } - } - - @Override - public Object deepCopy(Object value) throws HibernateException { - - if (Objects.isNull(value)) - return null; - - Salary oldSal = (Salary) value; - Salary newSal = new Salary(); - - newSal.setAmount(oldSal.getAmount()); - newSal.setCurrency(oldSal.getCurrency()); - - return newSal; - } - - @Override - public boolean isMutable() { - return true; - } - - @Override - public Serializable disassemble(Object value, SharedSessionContractImplementor session) throws HibernateException { - return (Serializable) deepCopy(value); - } - - @Override - public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) throws HibernateException { - return deepCopy(cached); - } - - @Override - public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner) throws HibernateException { - return original; - } - - @Override - public void setParameterValues(Properties parameters) { - this.localCurrency = parameters.getProperty("currency"); - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java deleted file mode 100644 index 989fa1281a..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.hibernate.exception; - -import javax.persistence.Entity; - -@Entity -public class EntityWithNoId { - private int id; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java deleted file mode 100644 index ae5174ac9c..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.hibernate.exception; - -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.service.ServiceRegistry; - -public class HibernateUtil { - private static SessionFactory sessionFactory; - private static String PROPERTY_FILE_NAME; - - public static SessionFactory getSessionFactory() throws IOException { - return getSessionFactory(null); - } - - public static SessionFactory getSessionFactory(String propertyFileName) - throws IOException { - PROPERTY_FILE_NAME = propertyFileName; - if (sessionFactory == null) { - ServiceRegistry serviceRegistry = configureServiceRegistry(); - sessionFactory = makeSessionFactory(serviceRegistry); - } - return sessionFactory; - } - - private static SessionFactory makeSessionFactory( - ServiceRegistry serviceRegistry) { - MetadataSources metadataSources = new MetadataSources(serviceRegistry); - metadataSources.addAnnotatedClass(Product.class); - Metadata metadata = metadataSources.getMetadataBuilder() - .build(); - return metadata.getSessionFactoryBuilder() - .build(); - - } - - private static ServiceRegistry configureServiceRegistry() - throws IOException { - Properties properties = getProperties(); - return new StandardServiceRegistryBuilder().applySettings(properties) - .build(); - } - - private static Properties getProperties() throws IOException { - Properties properties = new Properties(); - URL propertiesURL = Thread.currentThread() - .getContextClassLoader() - .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, - "hibernate-exception.properties")); - try (FileInputStream inputStream = new FileInputStream( - propertiesURL.getFile())) { - properties.load(inputStream); - } - return properties; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/Product.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/Product.java deleted file mode 100644 index 031fa38de0..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/exception/Product.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.hibernate.exception; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; - -@Entity -public class Product { - - private int id; - - private String name; - private String description; - - @Id - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - @Column(nullable=false) - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java deleted file mode 100644 index cc0c234df0..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/findall/FindAll.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.hibernate.findall; - -import java.util.List; - -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; - -import org.hibernate.Session; - -import com.baeldung.hibernate.pojo.Student; - -public class FindAll { - - private Session session; - - public FindAll(Session session) { - super(); - this.session = session; - } - - public List findAllWithJpql() { - return session.createQuery("SELECT a FROM Student a", Student.class).getResultList(); - } - - public List findAllWithCriteriaQuery() { - CriteriaBuilder cb = session.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(Student.class); - Root rootEntry = cq.from(Student.class); - CriteriaQuery all = cq.select(rootEntry); - TypedQuery allQuery = session.createQuery(all); - return allQuery.getResultList(); - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java deleted file mode 100644 index df07c3cf69..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Email.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.hibernate.joincolumn; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; - -@Entity -public class Email { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - - private String address; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "employee_id") - private OfficialEmployee employee; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - - public OfficialEmployee getEmployee() { - return employee; - } - - public void setEmployee(OfficialEmployee employee) { - this.employee = employee; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java deleted file mode 100644 index 9940577761..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/Office.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.hibernate.joincolumn; - -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinColumns; -import javax.persistence.ManyToOne; - -@Entity -public class Office { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumns({ - @JoinColumn(name="ADDR_ID", referencedColumnName="ID"), - @JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP") - }) - private OfficeAddress address; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public OfficeAddress getAddress() { - return address; - } - - public void setAddress(OfficeAddress address) { - this.address = address; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java deleted file mode 100644 index cc723db6a2..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.hibernate.joincolumn; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; - -@Entity -public class OfficeAddress { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - - @Column(name = "ZIP") - private String zipCode; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getZipCode() { - return zipCode; - } - - public void setZipCode(String zipCode) { - this.zipCode = zipCode; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java deleted file mode 100644 index 49c63c7578..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.baeldung.hibernate.joincolumn; - -import java.util.List; -import javax.persistence.Entity; -import javax.persistence.FetchType; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; - -@Entity -public class OfficialEmployee { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private Long id; - - @OneToMany(fetch = FetchType.LAZY, mappedBy = "employee") - private List emails; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public List getEmails() { - return emails; - } - - public void setEmails(List emails) { - this.emails = emails; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java deleted file mode 100644 index f7b8e6bf6d..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.hibernate.jpabootstrap.application; - -import com.baeldung.hibernate.jpabootstrap.config.JpaEntityManagerFactory; -import com.baeldung.hibernate.jpabootstrap.entities.User; -import javax.persistence.EntityManager; - -public class Application { - - public static void main(String[] args) { - EntityManager entityManager = getJpaEntityManager(); - User user = entityManager.find(User.class, 1); - System.out.println(user); - entityManager.getTransaction().begin(); - user.setName("John"); - user.setEmail("john@domain.com"); - entityManager.merge(user); - entityManager.getTransaction().commit(); - entityManager.getTransaction().begin(); - entityManager.persist(new User("Monica", "monica@domain.com")); - entityManager.getTransaction().commit(); - - // additional CRUD operations - - } - - private static class EntityManagerHolder { - private static final EntityManager ENTITY_MANAGER = new JpaEntityManagerFactory( - new Class[]{User.class}).getEntityManager(); - } - - public static EntityManager getJpaEntityManager() { - return EntityManagerHolder.ENTITY_MANAGER; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java deleted file mode 100644 index 3852b44b64..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java +++ /dev/null @@ -1,131 +0,0 @@ -package com.baeldung.hibernate.jpabootstrap.config; - -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Properties; -import javax.sql.DataSource; -import javax.persistence.SharedCacheMode; -import javax.persistence.ValidationMode; -import javax.persistence.spi.ClassTransformer; -import javax.persistence.spi.PersistenceUnitInfo; -import javax.persistence.spi.PersistenceUnitTransactionType; -import org.hibernate.jpa.HibernatePersistenceProvider; - -public class HibernatePersistenceUnitInfo implements PersistenceUnitInfo { - - public static final String JPA_VERSION = "2.1"; - private final String persistenceUnitName; - private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; - private final List managedClassNames; - private final List mappingFileNames = new ArrayList<>(); - private final Properties properties; - private DataSource jtaDataSource; - private DataSource nonjtaDataSource; - private final List transformers = new ArrayList<>(); - - public HibernatePersistenceUnitInfo(String persistenceUnitName, List managedClassNames, Properties properties) { - this.persistenceUnitName = persistenceUnitName; - this.managedClassNames = managedClassNames; - this.properties = properties; - } - - @Override - public String getPersistenceUnitName() { - return persistenceUnitName; - } - - @Override - public String getPersistenceProviderClassName() { - return HibernatePersistenceProvider.class.getName(); - } - - @Override - public PersistenceUnitTransactionType getTransactionType() { - return transactionType; - } - - public HibernatePersistenceUnitInfo setJtaDataSource(DataSource jtaDataSource) { - this.jtaDataSource = jtaDataSource; - this.nonjtaDataSource = null; - transactionType = PersistenceUnitTransactionType.JTA; - return this; - } - - @Override - public DataSource getJtaDataSource() { - return jtaDataSource; - } - - public HibernatePersistenceUnitInfo setNonJtaDataSource(DataSource nonJtaDataSource) { - this.nonjtaDataSource = nonJtaDataSource; - this.jtaDataSource = null; - transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; - return this; - } - - @Override - public DataSource getNonJtaDataSource() { - return nonjtaDataSource; - } - - @Override - public List getMappingFileNames() { - return mappingFileNames; - } - - @Override - public List getJarFileUrls() { - return Collections.emptyList(); - } - - @Override - public URL getPersistenceUnitRootUrl() { - return null; - } - - @Override - public List getManagedClassNames() { - return managedClassNames; - } - - @Override - public boolean excludeUnlistedClasses() { - return false; - } - - @Override - public SharedCacheMode getSharedCacheMode() { - return SharedCacheMode.UNSPECIFIED; - } - - @Override - public ValidationMode getValidationMode() { - return ValidationMode.AUTO; - } - - public Properties getProperties() { - return properties; - } - - @Override - public String getPersistenceXMLSchemaVersion() { - return JPA_VERSION; - } - - @Override - public ClassLoader getClassLoader() { - return Thread.currentThread().getContextClassLoader(); - } - - @Override - public void addTransformer(ClassTransformer transformer) { - transformers.add(transformer); - } - - @Override - public ClassLoader getNewTempClassLoader() { - return null; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java deleted file mode 100644 index bc1932af6f..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.baeldung.hibernate.jpabootstrap.config; - -import com.mysql.cj.jdbc.MysqlDataSource; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.stream.Collectors; -import javax.persistence.EntityManager; -import javax.sql.DataSource; -import javax.persistence.EntityManagerFactory; -import javax.persistence.spi.PersistenceUnitInfo; -import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; -import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor; - -public class JpaEntityManagerFactory { - - private final String DB_URL = "jdbc:mysql://databaseurl"; - private final String DB_USER_NAME = "username"; - private final String DB_PASSWORD = "password"; - private final Class[] entityClasses; - - public JpaEntityManagerFactory(Class[] entityClasses) { - this.entityClasses = entityClasses; - } - - public EntityManager getEntityManager() { - return getEntityManagerFactory().createEntityManager(); - } - - protected EntityManagerFactory getEntityManagerFactory() { - PersistenceUnitInfo persistenceUnitInfo = getPersistenceUnitInfo(getClass().getSimpleName()); - Map configuration = new HashMap<>(); - return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration) - .build(); - } - - protected HibernatePersistenceUnitInfo getPersistenceUnitInfo(String name) { - return new HibernatePersistenceUnitInfo(name, getEntityClassNames(), getProperties()); - } - - protected List getEntityClassNames() { - return Arrays.asList(getEntities()) - .stream() - .map(Class::getName) - .collect(Collectors.toList()); - } - - protected Properties getProperties() { - Properties properties = new Properties(); - properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); - properties.put("hibernate.id.new_generator_mappings", false); - properties.put("hibernate.connection.datasource", getMysqlDataSource()); - return properties; - } - - protected Class[] getEntities() { - return entityClasses; - } - - protected DataSource getMysqlDataSource() { - MysqlDataSource mysqlDataSource = new MysqlDataSource(); - mysqlDataSource.setURL(DB_URL); - mysqlDataSource.setUser(DB_USER_NAME); - mysqlDataSource.setPassword(DB_PASSWORD); - return mysqlDataSource; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java deleted file mode 100644 index 86ca1dfa19..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.hibernate.jpabootstrap.entities; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity -@Table(name = "users") -public class User { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - private long id; - private String name; - private String email; - - public User(){} - - public User(String name, String email) { - this.name = name; - this.email = email; - } - - public void setName(String name) { - this.name = name; - } - - public void setEmail(String email) { - this.email = email; - } - - public long getId() { - return id; - } - - public String getName() { - return name; - } - - public String getEmail() { - return email; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java deleted file mode 100644 index b7d1a537f0..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.hibernate.jpacriteriabuilder.service; - -import java.util.List; - -import com.baeldung.hibernate.entities.DeptEmployee; - -public interface EmployeeSearchService { - - List filterbyTitleUsingCriteriaBuilder(List titles); - - List filterbyTitleUsingExpression(List titles); - - List searchByDepartmentQuery(String query); - -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java deleted file mode 100644 index e79168a451..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.baeldung.hibernate.jpacriteriabuilder.service; - -import java.util.List; - -import javax.persistence.EntityManager; -import javax.persistence.TypedQuery; -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaBuilder.In; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import javax.persistence.criteria.Subquery; - -import com.baeldung.hibernate.entities.Department; -import com.baeldung.hibernate.entities.DeptEmployee; - -public class EmployeeSearchServiceImpl implements EmployeeSearchService { - - private EntityManager entityManager; - private CriteriaBuilder criteriaBuilder; - - public EmployeeSearchServiceImpl(EntityManager entityManager) { - this.entityManager = entityManager; - this.criteriaBuilder = entityManager.getCriteriaBuilder(); - - } - - @Override - public List filterbyTitleUsingCriteriaBuilder(List titles) { - CriteriaQuery criteriaQuery = createCriteriaQuery(DeptEmployee.class); - Root root = criteriaQuery.from(DeptEmployee.class); - In inClause = criteriaBuilder.in(root.get("title")); - for (String title : titles) { - inClause.value(title); - } - criteriaQuery.select(root) - .where(inClause); - TypedQuery query = entityManager.createQuery(criteriaQuery); - return query.getResultList(); - } - - @Override - public List filterbyTitleUsingExpression(List titles) { - CriteriaQuery criteriaQuery = createCriteriaQuery(DeptEmployee.class); - Root root = criteriaQuery.from(DeptEmployee.class); - criteriaQuery.select(root) - .where(root.get("title") - .in(titles)); - TypedQuery query = entityManager.createQuery(criteriaQuery); - return query.getResultList(); - } - - @Override - public List searchByDepartmentQuery(String searchKey) { - CriteriaQuery criteriaQuery = createCriteriaQuery(DeptEmployee.class); - Root emp = criteriaQuery.from(DeptEmployee.class); - - Subquery subquery = criteriaQuery.subquery(Department.class); - Root dept = subquery.from(Department.class); - subquery.select(dept) - .distinct(true) - .where(criteriaBuilder.like(dept.get("name"), new StringBuffer("%").append(searchKey) - .append("%") - .toString())); - - criteriaQuery.select(emp) - .where(criteriaBuilder.in(emp.get("department")) - .value(subquery)); - - TypedQuery query = entityManager.createQuery(criteriaQuery); - return query.getResultList(); - } - - private CriteriaQuery createCriteriaQuery(Class klass) { - return criteriaBuilder.createQuery(klass); - } - -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java deleted file mode 100644 index dc5242ee7c..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.hibernate.lob; - -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.service.ServiceRegistry; - -import com.baeldung.hibernate.lob.model.User; - -public class HibernateSessionUtil { - - private static SessionFactory sessionFactory; - private static String PROPERTY_FILE_NAME; - - public static SessionFactory getSessionFactory() throws IOException { - return getSessionFactory(null); - } - - public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { - PROPERTY_FILE_NAME = propertyFileName; - if (sessionFactory == null) { - ServiceRegistry serviceRegistry = configureServiceRegistry(); - sessionFactory = makeSessionFactory(serviceRegistry); - } - return sessionFactory; - } - - private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { - MetadataSources metadataSources = new MetadataSources(serviceRegistry); - metadataSources.addAnnotatedClass(User.class); - - Metadata metadata = metadataSources.buildMetadata(); - return metadata.getSessionFactoryBuilder() - .build(); - - } - - private static ServiceRegistry configureServiceRegistry() throws IOException { - Properties properties = getProperties(); - return new StandardServiceRegistryBuilder().applySettings(properties) - .build(); - } - - private static Properties getProperties() throws IOException { - Properties properties = new Properties(); - URL propertiesURL = Thread.currentThread() - .getContextClassLoader() - .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); - try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { - properties.load(inputStream); - } - return properties; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/model/User.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/model/User.java deleted file mode 100644 index 21f725b388..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/lob/model/User.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.hibernate.lob.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Lob; -import javax.persistence.Table; - -@Entity -@Table(name="user") -public class User { - - @Id - private String id; - - @Column(name = "name", columnDefinition="VARCHAR(128)") - private String name; - - @Lob - @Column(name = "photo", columnDefinition="BLOB") - private byte[] photo; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public byte[] getPhoto() { - return photo; - } - - public void setPhoto(byte[] photo) { - this.photo = photo; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java deleted file mode 100644 index c2f276472e..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.hibernate.onetoone; - -import com.baeldung.hibernate.customtypes.LocalDateStringType; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.service.ServiceRegistry; - -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Properties; - -public class HibernateUtil { - private static SessionFactory sessionFactory; - - private HibernateUtil() { - } - - public static SessionFactory getSessionFactory(Strategy strategy) { - return buildSessionFactory(strategy); - } - - private static SessionFactory buildSessionFactory(Strategy strategy) { - try { - ServiceRegistry serviceRegistry = configureServiceRegistry(); - - MetadataSources metadataSources = new MetadataSources(serviceRegistry); - - for (Class entityClass : strategy.getEntityClasses()) { - metadataSources.addAnnotatedClass(entityClass); - } - - Metadata metadata = metadataSources.getMetadataBuilder() - .applyBasicType(LocalDateStringType.INSTANCE) - .build(); - - return metadata.getSessionFactoryBuilder() - .build(); - } catch (IOException ex) { - throw new ExceptionInInitializerError(ex); - } - } - - - private static ServiceRegistry configureServiceRegistry() throws IOException { - Properties properties = getProperties(); - return new StandardServiceRegistryBuilder().applySettings(properties) - .build(); - } - - private static Properties getProperties() throws IOException { - Properties properties = new Properties(); - URL propertiesURL = Thread.currentThread() - .getContextClassLoader() - .getResource("hibernate.properties"); - try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { - properties.load(inputStream); - } - return properties; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java deleted file mode 100644 index 3180566ca5..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.hibernate.onetoone; - - -import java.util.Arrays; -import java.util.List; - -public enum Strategy { - //See that the classes belongs to different packages - FOREIGN_KEY(Arrays.asList(com.baeldung.hibernate.onetoone.foreignkeybased.User.class, - com.baeldung.hibernate.onetoone.foreignkeybased.Address.class)), - SHARED_PRIMARY_KEY(Arrays.asList(com.baeldung.hibernate.onetoone.sharedkeybased.User.class, - com.baeldung.hibernate.onetoone.sharedkeybased.Address.class)), - JOIN_TABLE_BASED(Arrays.asList(com.baeldung.hibernate.onetoone.jointablebased.Employee.class, - com.baeldung.hibernate.onetoone.jointablebased.WorkStation.class)); - - private List> entityClasses; - - Strategy(List> entityClasses) { - this.entityClasses = entityClasses; - } - - public List> getEntityClasses() { - return entityClasses; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java deleted file mode 100644 index e05eb46030..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.hibernate.onetoone.foreignkeybased; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "address") -public class Address { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private Long id; - - @Column(name = "street") - private String street; - - @Column(name = "city") - private String city; - - @OneToOne(mappedBy = "address") - private User user; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getStreet() { - return street; - } - - public void setStreet(String street) { - this.street = street; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java deleted file mode 100644 index dda972f29c..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.baeldung.hibernate.onetoone.foreignkeybased; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "users") -public class User { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private Long id; - - @Column(name = "username") - private String userName; - - @OneToOne(cascade = CascadeType.ALL) - @JoinColumn(name = "address_id", referencedColumnName = "id") - private Address address; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public Address getAddress() { - return address; - } - - public void setAddress(Address address) { - this.address = address; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java deleted file mode 100644 index a0bc101b9f..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.hibernate.onetoone.jointablebased; - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.OneToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "employee") -public class Employee { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private Long id; - - @Column(name = "ename") - private String name; - - @OneToOne(cascade = CascadeType.ALL) - @JoinTable(name = "emp_workstation", joinColumns = {@JoinColumn(name = "employee_id", referencedColumnName = "id")}, - inverseJoinColumns = {@JoinColumn(name = "workstation_id", referencedColumnName = "id")}) - private WorkStation workStation; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public WorkStation getWorkStation() { - return workStation; - } - - public void setWorkStation(WorkStation workStation) { - this.workStation = workStation; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java deleted file mode 100644 index f530611f6e..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.hibernate.onetoone.jointablebased; - - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "workstation") -public class WorkStation { - - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private Long id; - - @Column(name = "workstation_number") - private Integer workstationNumber; - - @Column(name = "floor") - private String floor; - - @OneToOne(mappedBy = "workStation") - private Employee employee; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Integer getWorkstationNumber() { - return workstationNumber; - } - - public void setWorkstationNumber(Integer workstationNumber) { - this.workstationNumber = workstationNumber; - } - - public String getFloor() { - return floor; - } - - public void setFloor(String floor) { - this.floor = floor; - } - - public Employee getEmployee() { - return employee; - } - - public void setEmployee(Employee employee) { - this.employee = employee; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java deleted file mode 100644 index 927516f6bb..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.hibernate.onetoone.sharedkeybased; - - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.MapsId; -import javax.persistence.OneToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "address") -public class Address { - - @Id - @Column(name = "id") - private Long id; - - @Column(name = "street") - private String street; - - @Column(name = "city") - private String city; - - @OneToOne - @MapsId - private User user; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getStreet() { - return street; - } - - public void setStreet(String street) { - this.street = street; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java deleted file mode 100644 index fa00db1271..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.baeldung.hibernate.onetoone.sharedkeybased; - - -import javax.persistence.CascadeType; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "users") -public class User { - @Id - @GeneratedValue(strategy = GenerationType.AUTO) - @Column(name = "id") - private Long id; - - @Column(name = "username") - private String userName; - - @OneToOne(mappedBy = "user", cascade = CascadeType.ALL) - private Address address; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public Address getAddress() { - return address; - } - - public void setAddress(Address address) { - this.address = address; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java deleted file mode 100644 index 1af3e3e21b..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.hibernate.optimisticlocking; - -import javax.persistence.*; - -@Entity -public class OptimisticLockingCourse { - - @Id - private Long id; - - private String name; - - @ManyToOne - @JoinTable(name = "optimistic_student_course") - private OptimisticLockingStudent student; - - public OptimisticLockingCourse(Long id, String name) { - this.id = id; - this.name = name; - } - - public OptimisticLockingCourse() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public OptimisticLockingStudent getStudent() { - return student; - } - - public void setStudent(OptimisticLockingStudent student) { - this.student = student; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java deleted file mode 100644 index b79212ae8d..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.baeldung.hibernate.optimisticlocking; - -import javax.persistence.*; -import java.util.List; - -@Entity -public class OptimisticLockingStudent { - - @Id - private Long id; - - private String name; - - private String lastName; - @Version - private Integer version; - - @OneToMany(mappedBy = "student") - private List courses; - - public OptimisticLockingStudent(Long id, String name, String lastName, List courses) { - this.id = id; - this.name = name; - this.lastName = lastName; - this.courses = courses; - } - - public OptimisticLockingStudent() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Integer getVersion() { - return version; - } - - public void setVersion(Integer version) { - this.version = version; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public List getCourses() { - return courses; - } - - public void setCourses(List courses) { - this.courses = courses; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java deleted file mode 100644 index c889cb6127..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import javax.persistence.Embeddable; - -@Embeddable -public class Address { - - private String country; - private String city; - - public Address(String country, String city) { - this.country = country; - this.city = city; - } - - public Address() { - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country; - } - - public String getCity() { - return city; - } - - public void setCity(String city) { - this.city = city; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java deleted file mode 100644 index cb73cbc958..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import javax.persistence.*; -import java.util.List; - -@Entity -public class Customer { - - @Id - private Long customerId; - private String name; - private String lastName; - @ElementCollection - @CollectionTable(name = "customer_address") - private List
addressList; - - public Customer() { - } - - public Customer(Long customerId, String name, String lastName, List
addressList) { - this.customerId = customerId; - this.name = name; - this.lastName = lastName; - this.addressList = addressList; - } - - public Long getCustomerId() { - return customerId; - } - - public void setCustomerId(Long customerId) { - this.customerId = customerId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public List
getAddressList() { - return addressList; - } - - public void setAddressList(List
addressList) { - this.addressList = addressList; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java deleted file mode 100644 index e491c09eb5..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Inheritance; -import javax.persistence.InheritanceType; - -@Entity -@Inheritance(strategy = InheritanceType.JOINED) -public class Individual { - - @Id - private Long id; - private String name; - private String lastName; - - public Individual(Long id, String name, String lastName) { - this.id = id; - this.name = name; - this.lastName = lastName; - } - - public Individual() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java deleted file mode 100644 index aea7d5fc87..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import javax.persistence.*; - -@Entity -public class PessimisticLockingCourse { - - @Id - private Long courseId; - private String name; - @ManyToOne - @JoinTable(name = "student_course") - private PessimisticLockingStudent student; - - public PessimisticLockingCourse(Long courseId, String name, PessimisticLockingStudent student) { - this.courseId = courseId; - this.name = name; - this.student = student; - } - - public PessimisticLockingCourse() { - } - - public Long getCourseId() { - return courseId; - } - - public void setCourseId(Long courseId) { - this.courseId = courseId; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public PessimisticLockingStudent getStudent() { - return student; - } - - public void setStudent(PessimisticLockingStudent students) { - this.student = students; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java deleted file mode 100644 index a1328cbdad..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import javax.persistence.Entity; -import java.math.BigDecimal; - -@Entity -public class PessimisticLockingEmployee extends Individual { - - private BigDecimal salary; - - public PessimisticLockingEmployee(Long id, String name, String lastName, BigDecimal salary) { - super(id, name, lastName); - this.salary = salary; - } - - public PessimisticLockingEmployee() { - super(); - } - - public BigDecimal getSalary() { - return salary; - } - - public void setSalary(BigDecimal average) { - this.salary = average; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java deleted file mode 100644 index e6c5f476b4..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import javax.persistence.*; -import java.util.List; - -@Entity -public class PessimisticLockingStudent { - - @Id - private Long id; - private String name; - @OneToMany(mappedBy = "student") - private List courses; - - public PessimisticLockingStudent(Long id, String name) { - this.id = id; - this.name = name; - } - - public PessimisticLockingStudent() { - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getCourses() { - return courses; - } - - public void setCourses(List courses) { - this.courses = courses; - } -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Person.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Person.java deleted file mode 100644 index 390a5954ed..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Person.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.hibernate.pojo; - -import javax.persistence.Convert; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; - -import com.baeldung.hibernate.converters.PersonNameConverter; - -@Entity(name = "PersonTable") -public class Person { - - @Id - @GeneratedValue - private Long id; - - @Convert(converter = PersonNameConverter.class) - private PersonName personName; - - public PersonName getPersonName() { - return personName; - } - - public void setPersonName(PersonName personName) { - this.personName = personName; - } - - public Long getId() { - return id; - } - -} diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/transaction/PostService.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/transaction/PostService.java deleted file mode 100644 index 5a4eb20079..0000000000 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/transaction/PostService.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.hibernate.transaction; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.query.Query; - -public class PostService { - - - private Session session; - - public PostService(Session session) { - this.session = session; - } - - - public void updatePost(String title, String body, int id) { - Transaction txn = session.beginTransaction(); - Query updateQuery = session.createQuery("UPDATE Post p SET p.title = ?1, p.body = ?2 WHERE p.id = ?3"); - updateQuery.setParameter(1, title); - updateQuery.setParameter(2, body); - updateQuery.setParameter(3, id); - updateQuery.executeUpdate(); - txn.commit(); - } - - - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java deleted file mode 100644 index 699890c457..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.baeldung.hibernate; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.IOException; -import java.util.List; - -import com.baeldung.hibernate.entities.DeptEmployee; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.query.Query; -import org.hibernate.transform.Transformers; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import com.baeldung.hibernate.entities.Department; -import com.baeldung.hibernate.pojo.Result; - -public class CustomClassIntegrationTest { - - private Session session; - - private Transaction transaction; - - @BeforeEach - public void setUp() throws IOException { - session = HibernateUtil.getSessionFactory().openSession(); - transaction = session.beginTransaction(); - session.createNativeQuery("delete from department").executeUpdate(); - Department department = new Department("Sales"); - DeptEmployee employee = new DeptEmployee("John Smith", "001", department); - session.persist(department); - session.persist(employee); - transaction.commit(); - transaction = session.beginTransaction(); - } - - @Test - public void whenAllManagersAreSelected_ThenObjectGraphIsReturned() { - Query query = session.createQuery("from com.baeldung.hibernate.entities.DeptEmployee"); - List deptEmployees = query.list(); - DeptEmployee deptEmployee = deptEmployees.get(0); - assertEquals("John Smith", deptEmployee.getName()); - assertEquals("Sales", deptEmployee.getDepartment().getName()); - } - - @Test - public void whenIndividualPropertiesAreSelected_ThenObjectArrayIsReturned() { - Query query = session.createQuery("select m.name, m.department.name from com.baeldung.hibernate.entities.DeptEmployee m"); - List managers = query.list(); - Object[] manager = (Object[]) managers.get(0); - assertEquals("John Smith", manager[0]); - assertEquals("Sales", manager[1]); - } - - @Test - public void whenResultConstructorInSelect_ThenListOfResultIsReturned() { - Query query = session.createQuery("select new com.baeldung.hibernate.pojo.Result(m.name, m.department.name) " - + "from DeptEmployee m"); - List results = query.list(); - Result result = results.get(0); - assertEquals("John Smith", result.getEmployeeName()); - assertEquals("Sales", result.getDepartmentName()); - } - - @Test - public void whenResultTransformerOnQuery_ThenListOfResultIsReturned() { - Query query = session.createQuery("select m.name as employeeName, m.department.name as departmentName " - + "from com.baeldung.hibernate.entities.DeptEmployee m"); - query.setResultTransformer(Transformers.aliasToBean(Result.class)); - List results = query.list(); - Result result = results.get(0); - assertEquals("John Smith", result.getEmployeeName()); - assertEquals("Sales", result.getDepartmentName()); - } - - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java deleted file mode 100644 index 7a112200b5..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java +++ /dev/null @@ -1,160 +0,0 @@ -package com.baeldung.hibernate; - -import com.baeldung.hibernate.pojo.Employee; -import com.baeldung.hibernate.pojo.EntityDescription; -import com.baeldung.hibernate.pojo.Phone; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.util.List; - -import static org.assertj.core.api.Assertions.assertThat; - -public class DynamicMappingIntegrationTest { - - private Session session; - - private Transaction transaction; - - @Before - public void setUp() throws IOException { - session = HibernateUtil.getSessionFactory().openSession(); - transaction = session.beginTransaction(); - - session.createNativeQuery("delete from phone").executeUpdate(); - session.createNativeQuery("delete from employee").executeUpdate(); - - transaction.commit(); - transaction = session.beginTransaction(); - } - - @After - public void tearDown() { - transaction.rollback(); - session.close(); - } - - @Test - public void givenEntity_whenFieldMappedWithFormula_thenFieldIsCalculated() { - Employee employee = new Employee(10_000L, 25); - assertThat(employee.getTaxJavaWay()).isEqualTo(2_500L); - - session.save(employee); - session.flush(); - session.clear(); - - employee = session.get(Employee.class, employee.getId()); - assertThat(employee.getTax()).isEqualTo(2_500L); - } - - @Test - public void givenEntityMappedWithWhere_whenDeletedIsTrue_thenEntityNotFetched() { - Employee employee = new Employee(); - - session.save(employee); - session.clear(); - - employee = session.find(Employee.class, employee.getId()); - assertThat(employee).isNotNull(); - - employee.setDeleted(true); - session.flush(); - - employee = session.find(Employee.class, employee.getId()); - assertThat(employee).isNotNull(); - - session.clear(); - - employee = session.find(Employee.class, employee.getId()); - assertThat(employee).isNull(); - - } - - @Test - public void givenCollectionMappedWithWhere_whenDeletedIsTrue_thenEntityNotFetched() { - Employee employee = new Employee(); - Phone phone1 = new Phone("555-45-67"); - Phone phone2 = new Phone("555-89-01"); - employee.getPhones().add(phone1); - employee.getPhones().add(phone2); - - session.save(phone1); - session.save(phone2); - session.save(employee); - session.flush(); - session.clear(); - - employee = session.find(Employee.class, employee.getId()); - assertThat(employee.getPhones()).hasSize(2); - - employee.getPhones().iterator().next().setDeleted(true); - session.flush(); - session.clear(); - - employee = session.find(Employee.class, employee.getId()); - assertThat(employee.getPhones()).hasSize(1); - - List fullPhoneList = session.createQuery("from Phone").getResultList(); - assertThat(fullPhoneList).hasSize(2); - - } - - @Test - public void givenFilterByIncome_whenIncomeLimitSet_thenFilterIsApplied() throws IOException { - session.save(new Employee(10_000, 25)); - session.save(new Employee(12_000, 25)); - session.save(new Employee(15_000, 25)); - - session.flush(); - session.clear(); - - session.enableFilter("incomeLevelFilter") - .setParameter("incomeLimit", 11_000); - - List employees = session.createQuery("from Employee").getResultList(); - - assertThat(employees).hasSize(2); - - Employee employee = session.get(Employee.class, 1); - assertThat(employee.getGrossIncome()).isEqualTo(10_000); - - session.disableFilter("incomeLevelFilter"); - employees = session.createQuery("from Employee").getResultList(); - - assertThat(employees).hasSize(3); - - } - - @Test - public void givenMappingWithAny_whenDescriptionAddedToEntity_thenDescriptionCanReferAnyEntity() { - Employee employee = new Employee(); - Phone phone1 = new Phone("555-45-67"); - Phone phone2 = new Phone("555-89-01"); - employee.getPhones().add(phone1); - employee.getPhones().add(phone2); - - EntityDescription employeeDescription = new EntityDescription("Send to conference next year", employee); - EntityDescription phone1Description = new EntityDescription("Home phone (do not call after 10PM)", phone1); - EntityDescription phone2Description = new EntityDescription("Work phone", phone1); - - session.save(phone1); - session.save(phone2); - session.save(employee); - session.save(employeeDescription); - session.save(phone1Description); - session.save(phone2Description); - session.flush(); - session.clear(); - - List descriptions = session.createQuery("from EntityDescription").getResultList(); - - assertThat(Employee.class.isAssignableFrom(descriptions.get(0).getEntity().getClass())).isTrue(); - assertThat(Phone.class.isAssignableFrom(descriptions.get(1).getEntity().getClass())).isTrue(); - assertThat(Phone.class.isAssignableFrom(descriptions.get(2).getEntity().getClass())).isTrue(); - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java deleted file mode 100644 index 74f752ab8c..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java +++ /dev/null @@ -1,161 +0,0 @@ -package com.baeldung.hibernate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Properties; - -import javax.persistence.Query; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.pojo.PointEntity; -import com.baeldung.hibernate.pojo.PolygonEntity; -import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; -import com.vividsolutions.jts.geom.Point; -import com.vividsolutions.jts.geom.Polygon; -import com.vividsolutions.jts.io.ParseException; -import com.vividsolutions.jts.io.WKTReader; -import com.vividsolutions.jts.util.GeometricShapeFactory; - -import geodb.GeoDB; - -public class HibernateSpatialIntegrationTest { - - private Session session; - private Transaction transaction; - - @Before - public void setUp() throws IOException { - session = HibernateUtil.getSessionFactory("hibernate-spatial.properties") - .openSession(); - transaction = session.beginTransaction(); - session.doWork(conn -> { GeoDB.InitGeoDB(conn); }); - } - - @After - public void tearDown() { - transaction.rollback(); - session.close(); - } - - @Test - public void shouldConvertWktToGeometry() throws ParseException { - Geometry geometry = wktToGeometry("POINT (2 5)"); - assertEquals("Point", geometry.getGeometryType()); - assertTrue(geometry instanceof Point); - } - - @Test - public void shouldInsertAndSelectPoints() throws ParseException { - PointEntity entity = new PointEntity(); - entity.setPoint((Point) wktToGeometry("POINT (1 1)")); - - session.persist(entity); - PointEntity fromDb = session.find(PointEntity.class, entity.getId()); - assertEquals("POINT (1 1)", fromDb.getPoint().toString()); - } - - @Test - public void shouldSelectDisjointPoints() throws ParseException { - insertPoint("POINT (1 2)"); - insertPoint("POINT (3 4)"); - insertPoint("POINT (5 6)"); - - Point point = (Point) wktToGeometry("POINT (3 4)"); - Query query = session.createQuery("select p from PointEntity p " - + "where disjoint(p.point, :point) = true", PointEntity.class); - query.setParameter("point", point); - assertEquals("POINT (1 2)", ((PointEntity) query.getResultList().get(0)).getPoint().toString()); - assertEquals("POINT (5 6)", ((PointEntity) query.getResultList().get(1)).getPoint().toString()); - } - - @Test - public void shouldSelectAllPointsWithinPolygon() throws ParseException { - insertPoint("POINT (1 1)"); - insertPoint("POINT (1 2)"); - insertPoint("POINT (3 4)"); - insertPoint("POINT (5 6)"); - - Query query = session.createQuery("select p from PointEntity p where within(p.point, :area) = true", - PointEntity.class); - query.setParameter("area", wktToGeometry("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))")); - assertThat(query.getResultList().stream().map(p -> ((PointEntity) p).getPoint().toString())) - .containsOnly("POINT (1 1)", "POINT (1 2)", "POINT (3 4)"); - } - - @Test - public void shouldSelectAllPointsWithinRadius() throws ParseException { - insertPoint("POINT (1 1)"); - insertPoint("POINT (1 2)"); - insertPoint("POINT (3 4)"); - insertPoint("POINT (5 6)"); - - Query query = session.createQuery("select p from PointEntity p where within(p.point, :circle) = true", - PointEntity.class); - query.setParameter("circle", createCircle(0.0, 0.0, 5)); - - assertThat(query.getResultList().stream().map(p -> ((PointEntity) p).getPoint().toString())) - .containsOnly("POINT (1 1)", "POINT (1 2)"); - } - - @Test - public void shouldSelectAdjacentPolygons() throws ParseException { - insertPolygon("POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))"); - insertPolygon("POLYGON ((3 0, 3 5, 8 5, 8 0, 3 0))"); - insertPolygon("POLYGON ((2 2, 3 1, 2 5, 4 3, 3 3, 2 2))"); - - Query query = session.createQuery("select p from PolygonEntity p where touches(p.polygon, :polygon) = true", - PolygonEntity.class); - query.setParameter("polygon", wktToGeometry("POLYGON ((5 5, 5 10, 10 10, 10 5, 5 5))")); - assertThat(query.getResultList().stream().map(p -> ((PolygonEntity) p).getPolygon().toString())) - .containsOnly("POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))", "POLYGON ((3 0, 3 5, 8 5, 8 0, 3 0))"); - } - - private void insertPoint(String point) throws ParseException { - PointEntity entity = new PointEntity(); - entity.setPoint((Point) wktToGeometry(point)); - session.persist(entity); - } - - private void insertPolygon(String polygon) throws ParseException { - PolygonEntity entity = new PolygonEntity(); - entity.setPolygon((Polygon) wktToGeometry(polygon)); - session.persist(entity); - } - - private Geometry wktToGeometry(String wellKnownText) throws ParseException { - WKTReader fromText = new WKTReader(); - Geometry geom = null; - geom = fromText.read(wellKnownText); - return geom; - } - - private static Geometry createCircle(double x, double y, double radius) { - GeometricShapeFactory shapeFactory = new GeometricShapeFactory(); - shapeFactory.setNumPoints(32); - shapeFactory.setCentre(new Coordinate(x, y)); - shapeFactory.setSize(radius * 2); - return shapeFactory.createCircle(); - } - - public static Properties getProperties(String propertyFile) throws IOException { - Properties properties = new Properties(); - URL propertiesURL = Thread.currentThread() - .getContextClassLoader() - .getResource(propertyFile); - try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { - properties.load(inputStream); - } - return properties; - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java deleted file mode 100644 index 0f35dbb8af..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.baeldung.hibernate; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.pojo.inheritance.Bag; -import com.baeldung.hibernate.pojo.inheritance.Book; -import com.baeldung.hibernate.pojo.inheritance.Car; -import com.baeldung.hibernate.pojo.inheritance.MyEmployee; -import com.baeldung.hibernate.pojo.inheritance.Pen; -import com.baeldung.hibernate.pojo.inheritance.Pet; - -public class InheritanceMappingIntegrationTest { - private Session session; - - private Transaction transaction; - - @Before - public void setUp() throws IOException { - session = HibernateUtil.getSessionFactory() - .openSession(); - transaction = session.beginTransaction(); - } - - @After - public void tearDown() { - transaction.rollback(); - session.close(); - } - - @Test - public void givenSubclasses_whenQuerySingleTableSuperclass_thenOk() { - Book book = new Book(1, "1984", "George Orwell"); - session.save(book); - Pen pen = new Pen(2, "my pen", "blue"); - session.save(pen); - - assertThat(session.createQuery("from MyProduct") - .getResultList() - .size()).isEqualTo(2); - } - - @Test - public void givenSubclasses_whenQueryMappedSuperclass_thenOk() { - MyEmployee emp = new MyEmployee(1, "john", "baeldung"); - session.save(emp); - - assertThat(session.createQuery("from com.baeldung.hibernate.pojo.inheritance.Person") - .getResultList() - .size()).isEqualTo(1); - } - - @Test - public void givenSubclasses_whenQueryJoinedTableSuperclass_thenOk() { - Pet pet = new Pet(1, "dog", "lassie"); - session.save(pet); - - assertThat(session.createQuery("from Animal") - .getResultList() - .size()).isEqualTo(1); - } - - @Test - public void givenSubclasses_whenQueryTablePerClassSuperclass_thenOk() { - Car car = new Car(1, "audi", "xyz"); - session.save(car); - - assertThat(session.createQuery("from Vehicle") - .getResultList() - .size()).isEqualTo(1); - } - - @Test - public void givenSubclasses_whenQueryNonMappedInterface_thenOk() { - Bag bag = new Bag(1, "large"); - session.save(bag); - - assertThat(session.createQuery("from com.baeldung.hibernate.pojo.inheritance.Item") - .getResultList() - .size()).isEqualTo(0); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java deleted file mode 100644 index cb73fe348c..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java +++ /dev/null @@ -1,98 +0,0 @@ -package com.baeldung.hibernate; - -import com.baeldung.hibernate.entities.Department; -import com.baeldung.hibernate.entities.DeptEmployee; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.hibernate.query.NativeQuery; -import org.hibernate.query.Query; -import org.junit.*; - -import java.io.IOException; - -public class NamedQueryIntegrationTest { - private static Session session; - - private Transaction transaction; - - private Long purchaseDeptId; - - @BeforeClass - public static void setUpClass() throws IOException { - session = HibernateUtil.getSessionFactory("hibernate-namedquery.properties").openSession(); - } - - @Before - public void setUp() throws IOException { - transaction = session.beginTransaction(); - session.createNativeQuery("delete from deptemployee").executeUpdate(); - session.createNativeQuery("delete from department").executeUpdate(); - Department salesDepartment = new Department("Sales"); - Department purchaseDepartment = new Department("Purchase"); - DeptEmployee employee1 = new DeptEmployee("John Wayne", "001", salesDepartment); - DeptEmployee employee2 = new DeptEmployee("Sarah Vinton", "002", salesDepartment); - DeptEmployee employee3 = new DeptEmployee("Lisa Carter", "003", salesDepartment); - session.persist(salesDepartment); - session.persist(purchaseDepartment); - purchaseDeptId = purchaseDepartment.getId(); - session.persist(employee1); - session.persist(employee2); - session.persist(employee3); - transaction.commit(); - transaction = session.beginTransaction(); - } - - @After - public void tearDown() { - if(transaction.isActive()) { - transaction.rollback(); - } - } - - @Test - public void whenNamedQueryIsCalledUsingCreateNamedQuery_ThenOk() { - Query query = session.createNamedQuery("DeptEmployee_FindByEmployeeNumber", DeptEmployee.class); - query.setParameter("employeeNo", "001"); - DeptEmployee result = query.getSingleResult(); - Assert.assertNotNull(result); - Assert.assertEquals("John Wayne", result.getName()); - } - - @Test - public void whenNamedNativeQueryIsCalledUsingCreateNamedQuery_ThenOk() { - Query query = session.createNamedQuery("DeptEmployee_FindByEmployeeName", DeptEmployee.class); - query.setParameter("name", "John Wayne"); - DeptEmployee result = query.getSingleResult(); - Assert.assertNotNull(result); - Assert.assertEquals("001", result.getEmployeeNumber()); - } - - @Test - public void whenNamedNativeQueryIsCalledUsingGetNamedNativeQuery_ThenOk() { - @SuppressWarnings("rawtypes") - NativeQuery query = session.getNamedNativeQuery("DeptEmployee_FindByEmployeeName"); - query.setParameter("name", "John Wayne"); - DeptEmployee result = (DeptEmployee) query.getSingleResult(); - Assert.assertNotNull(result); - Assert.assertEquals("001", result.getEmployeeNumber()); - } - - @Test - public void whenUpdateQueryIsCalledWithCreateNamedQuery_ThenOk() { - Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDepartment"); - spQuery.setParameter("employeeNo", "001"); - Department newDepartment = session.find(Department.class, purchaseDeptId); - spQuery.setParameter("newDepartment", newDepartment); - spQuery.executeUpdate(); - transaction.commit(); - } - - @Test - public void whenNamedStoredProcedureIsCalledWithCreateNamedQuery_ThenOk() { - Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDesignation"); - spQuery.setParameter("employeeNumber", "002"); - spQuery.setParameter("newDesignation", "Supervisor"); - spQuery.executeUpdate(); - transaction.commit(); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java deleted file mode 100644 index 91c41af0fe..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.baeldung.hibernate; - -import com.baeldung.hibernate.pojo.TemporalValues; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.time.*; -import java.util.Calendar; -import java.util.TimeZone; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TemporalValuesUnitTest { - - private Session session; - - private Transaction transaction; - - @Before - public void setUp() throws IOException { - session = HibernateUtil.getSessionFactory().withOptions() - .jdbcTimeZone(TimeZone.getTimeZone("UTC")) - .openSession(); - transaction = session.beginTransaction(); - session.createNativeQuery("delete from temporalvalues").executeUpdate(); - } - - @After - public void tearDown() { - transaction.rollback(); - session.close(); - } - - @Test - public void givenEntity_whenMappingSqlTypes_thenTemporalIsSelectedAutomatically() { - TemporalValues temporalValues = new TemporalValues(); - temporalValues.setSqlDate(java.sql.Date.valueOf("2017-11-15")); - temporalValues.setSqlTime(java.sql.Time.valueOf("15:30:14")); - temporalValues.setSqlTimestamp(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); - - session.save(temporalValues); - session.flush(); - session.clear(); - - temporalValues = session.get(TemporalValues.class, temporalValues.getId()); - assertThat(temporalValues.getSqlDate()).isEqualTo(java.sql.Date.valueOf("2017-11-15")); - assertThat(temporalValues.getSqlTime()).isEqualTo(java.sql.Time.valueOf("15:30:14")); - assertThat(temporalValues.getSqlTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); - - } - - @Test - public void givenEntity_whenMappingUtilDateType_thenTemporalIsSpecifiedExplicitly() throws Exception { - TemporalValues temporalValues = new TemporalValues(); - temporalValues.setUtilDate(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); - temporalValues.setUtilTime(new SimpleDateFormat("HH:mm:ss").parse("15:30:14")); - temporalValues.setUtilTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.332")); - - session.save(temporalValues); - session.flush(); - session.clear(); - - temporalValues = session.get(TemporalValues.class, temporalValues.getId()); - assertThat(temporalValues.getUtilDate()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); - assertThat(temporalValues.getUtilTime()).isEqualTo(new SimpleDateFormat("HH:mm:ss").parse("15:30:14")); - assertThat(temporalValues.getUtilTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); - - } - - @Test - public void givenEntity_whenMappingCalendarType_thenTemporalIsSpecifiedExplicitly() throws Exception { - TemporalValues temporalValues = new TemporalValues(); - - Calendar calendarDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - calendarDate.set(Calendar.YEAR, 2017); - calendarDate.set(Calendar.MONTH, 10); - calendarDate.set(Calendar.DAY_OF_MONTH, 15); - temporalValues.setCalendarDate(calendarDate); - - Calendar calendarTimestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); - calendarTimestamp.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322")); - temporalValues.setCalendarTimestamp(calendarTimestamp); - - session.save(temporalValues); - session.flush(); - session.clear(); - - temporalValues = session.get(TemporalValues.class, temporalValues.getId()); - assertThat(temporalValues.getCalendarDate().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); - assertThat(temporalValues.getCalendarTimestamp().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322")); - - } - - @Test - public void givenEntity_whenMappingJavaTimeTypes_thenTemporalIsSelectedAutomatically() { - TemporalValues temporalValues = new TemporalValues(); - - temporalValues.setLocalDate(LocalDate.parse("2017-11-15")); - temporalValues.setLocalTime(LocalTime.parse("15:30:18")); - temporalValues.setOffsetTime(OffsetTime.parse("08:22:12+01:00")); - - System.out.println("********"+OffsetTime.parse("08:22:12+01:00").toString()); - temporalValues.setInstant(Instant.parse("2017-11-15T08:22:12Z")); - temporalValues.setLocalDateTime(LocalDateTime.parse("2017-11-15T08:22:12")); - temporalValues.setOffsetDateTime(OffsetDateTime.parse("2017-11-15T08:22:12+01:00")); - temporalValues.setZonedDateTime(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]")); - - session.save(temporalValues); - session.flush(); - session.clear(); - - temporalValues = session.get(TemporalValues.class, temporalValues.getId()); - assertThat(temporalValues.getLocalDate()).isEqualTo(LocalDate.parse("2017-11-15")); - assertThat(temporalValues.getLocalTime()).isEqualTo(LocalTime.parse("15:30:18")); - //assertThat(temporalValues.getOffsetTime()).isEqualTo(OffsetTime.parse("08:22:12+01:00")); - assertThat(temporalValues.getInstant()).isEqualTo(Instant.parse("2017-11-15T08:22:12Z")); - assertThat(temporalValues.getLocalDateTime()).isEqualTo(LocalDateTime.parse("2017-11-15T08:22:12")); - //assertThat(temporalValues.getOffsetDateTime()).isEqualTo(OffsetDateTime.parse("2017-11-15T08:22:12+01:00")); - assertThat(temporalValues.getZonedDateTime()).isEqualTo(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]")); - - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java deleted file mode 100644 index 0b2bdf7ead..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java +++ /dev/null @@ -1,87 +0,0 @@ -package com.baeldung.hibernate.aggregatefunctions; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; - -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.baeldung.hibernate.HibernateUtil; -import com.baeldung.hibernate.pojo.Student; - -public class AggregateFunctionsIntegrationTest { - - private static Session session; - private static Transaction transaction; - - @BeforeClass - public static final void setup() throws HibernateException, IOException { - session = HibernateUtil.getSessionFactory() - .openSession(); - transaction = session.beginTransaction(); - - Student jonas = new Student("Jonas", 22); - session.save(jonas); - - Student sally = new Student("Sally", 20); - session.save(sally); - - Student simon = new Student("Simon", 25); - session.save(simon); - - Student raven = new Student("Raven", 21); - session.save(raven); - - Student sam = new Student("Sam", 23); - session.save(sam); - - } - - @AfterClass - public static final void teardown() { - if (session != null) { - transaction.rollback(); - session.close(); - } - } - - @Test - public void whenMaxAge_ThenReturnValue() { - int maxAge = (int) session.createQuery("SELECT MAX(age) from Student") - .getSingleResult(); - assertThat(maxAge).isEqualTo(25); - } - - @Test - public void whenMinAge_ThenReturnValue() { - int minAge = (int) session.createQuery("SELECT MIN(age) from Student") - .getSingleResult(); - assertThat(minAge).isEqualTo(20); - } - - @Test - public void whenAverageAge_ThenReturnValue() { - Double avgAge = (Double) session.createQuery("SELECT AVG(age) from Student") - .getSingleResult(); - assertThat(avgAge).isEqualTo(22.2); - } - - @Test - public void whenCountAll_ThenReturnValue() { - Long totalStudents = (Long) session.createQuery("SELECT COUNT(*) from Student") - .getSingleResult(); - assertThat(totalStudents).isEqualTo(5); - } - - @Test - public void whenSumOfAllAges_ThenReturnValue() { - Long sumOfAllAges = (Long) session.createQuery("SELECT SUM(age) from Student") - .getSingleResult(); - assertThat(sumOfAllAges).isEqualTo(111); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java deleted file mode 100644 index 3cd4761a7b..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java +++ /dev/null @@ -1,200 +0,0 @@ -package com.baeldung.hibernate.converter; - -import java.io.IOException; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.HibernateUtil; -import com.baeldung.hibernate.pojo.Person; -import com.baeldung.hibernate.pojo.PersonName; - -import static org.junit.Assert.assertEquals; - -public class PersonNameConverterUnitTest { - - private Session session; - private Transaction transaction; - - @Before - public void setUp() throws IOException { - session = HibernateUtil.getSessionFactory() - .openSession(); - transaction = session.beginTransaction(); - - session.createNativeQuery("delete from personTable") - .executeUpdate(); - - transaction.commit(); - transaction = session.beginTransaction(); - } - - @After - public void tearDown() { - transaction.rollback(); - session.close(); - } - - @Test - public void givenPersonName_WhenSaving_ThenNameAndSurnameConcat() { - final String name = "name"; - final String surname = "surname"; - - PersonName personName = new PersonName(); - personName.setName(name); - personName.setSurname(surname); - - Person person = new Person(); - person.setPersonName(personName); - - Long id = (Long) session.save(person); - - session.flush(); - session.clear(); - - String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") - .setParameter("id", id) - .getSingleResult(); - - assertEquals(surname + ", " + name, dbPersonName); - - Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) - .setParameter("id", id) - .getSingleResult(); - - assertEquals(dbPerson.getPersonName() - .getName(), name); - assertEquals(dbPerson.getPersonName() - .getSurname(), surname); - } - - @Test - public void givenPersonNameNull_WhenSaving_ThenNullStored() { - final String name = null; - final String surname = null; - - PersonName personName = new PersonName(); - personName.setName(name); - personName.setSurname(surname); - - Person person = new Person(); - person.setPersonName(personName); - - Long id = (Long) session.save(person); - - session.flush(); - session.clear(); - - String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") - .setParameter("id", id) - .getSingleResult(); - - assertEquals("", dbPersonName); - - Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) - .setParameter("id", id) - .getSingleResult(); - - assertEquals(dbPerson.getPersonName(), null); - } - - @Test - public void givenPersonNameWithoutName_WhenSaving_ThenNotNameStored() { - final String name = null; - final String surname = "surname"; - - PersonName personName = new PersonName(); - personName.setName(name); - personName.setSurname(surname); - - Person person = new Person(); - person.setPersonName(personName); - - Long id = (Long) session.save(person); - - session.flush(); - session.clear(); - - String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") - .setParameter("id", id) - .getSingleResult(); - - assertEquals("surname, ", dbPersonName); - - Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) - .setParameter("id", id) - .getSingleResult(); - - assertEquals(dbPerson.getPersonName() - .getName(), name); - assertEquals(dbPerson.getPersonName() - .getSurname(), surname); - } - - @Test - public void givenPersonNameWithoutSurName_WhenSaving_ThenNotSurNameStored() { - final String name = "name"; - final String surname = null; - - PersonName personName = new PersonName(); - personName.setName(name); - personName.setSurname(surname); - - Person person = new Person(); - person.setPersonName(personName); - - Long id = (Long) session.save(person); - - session.flush(); - session.clear(); - - String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") - .setParameter("id", id) - .getSingleResult(); - - assertEquals("name", dbPersonName); - - Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) - .setParameter("id", id) - .getSingleResult(); - - assertEquals(dbPerson.getPersonName() - .getName(), name); - assertEquals(dbPerson.getPersonName() - .getSurname(), surname); - } - - @Test - public void givenPersonNameEmptyFields_WhenSaving_ThenFielsNotStored() { - final String name = ""; - final String surname = ""; - - PersonName personName = new PersonName(); - personName.setName(name); - personName.setSurname(surname); - - Person person = new Person(); - person.setPersonName(personName); - - Long id = (Long) session.save(person); - - session.flush(); - session.clear(); - - String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") - .setParameter("id", id) - .getSingleResult(); - - assertEquals("", dbPersonName); - - Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) - .setParameter("id", id) - .getSingleResult(); - - assertEquals(dbPerson.getPersonName(), null); - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java deleted file mode 100644 index cedba412d9..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.baeldung.hibernate.criteriaquery; - -import com.baeldung.hibernate.criteriaquery.HibernateUtil; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.query.Query; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.persistence.criteria.CriteriaBuilder; -import javax.persistence.criteria.CriteriaQuery; -import javax.persistence.criteria.Root; -import java.io.IOException; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - - -public class TypeSafeCriteriaIntegrationTest { - - private static SessionFactory sessionFactory; - - private Session session; - - @BeforeClass - public static void beforeTests() throws IOException { - sessionFactory = HibernateUtil.getSessionFactory(); - } - - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - } - - @Test - public void givenStudentData_whenUsingTypeSafeCriteriaQuery_thenSearchAllStudentsOfAGradYear() { - - prepareData(); - CriteriaBuilder cb = session.getCriteriaBuilder(); - CriteriaQuery criteriaQuery = cb.createQuery(Student.class); - - Root root = criteriaQuery.from(Student.class); - criteriaQuery.select(root).where(cb.equal(root.get("gradYear"), 1965)); - - Query query = session.createQuery(criteriaQuery); - List results = query.getResultList(); - - assertNotNull(results); - assertEquals(1, results.size()); - - Student student = results.get(0); - - assertEquals("Ken", student.getFirstName()); - assertEquals("Thompson", student.getLastName()); - assertEquals(1965, student.getGradYear()); - } - - private void prepareData() { - Student student1 = new Student(); - student1.setFirstName("Ken"); - student1.setLastName("Thompson"); - student1.setGradYear(1965); - - session.save(student1); - - Student student2 = new Student(); - student2.setFirstName("Dennis"); - student2.setLastName("Ritchie"); - student2.setGradYear(1963); - - session.save(student2); - session.getTransaction().commit(); - } - - @After - public void tearDown() { - session.close(); - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java deleted file mode 100644 index 63dc6330be..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.baeldung.hibernate.customtypes; - -import com.baeldung.hibernate.HibernateUtil; -import org.hibernate.SessionFactory; -import org.hibernate.query.Query; -import org.junit.Assert; -import org.junit.Test; - -import java.io.IOException; -import java.time.LocalDate; - -import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; - -public class HibernateCustomTypesManualTest { - - @Test - public void givenEmployee_whenSavedWithCustomTypes_thenEntityIsSaved() throws IOException { - - final OfficeEmployee e = new OfficeEmployee(); - e.setDateOfJoining(LocalDate.now()); - - PhoneNumber number = new PhoneNumber(1, 222, 8781902); - e.setEmployeeNumber(number); - - Address empAdd = new Address(); - empAdd.setAddressLine1("Street"); - empAdd.setAddressLine2("Area"); - empAdd.setCity("City"); - empAdd.setCountry("Country"); - empAdd.setZipCode(100); - - e.setEmpAddress(empAdd); - - Salary empSalary = new Salary(); - empSalary.setAmount(1000L); - empSalary.setCurrency("USD"); - e.setSalary(empSalary); - - doInHibernate(this::sessionFactory, session -> { - session.save(e); - boolean contains = session.contains(e); - Assert.assertTrue(contains); - }); - - } - - @Test - public void givenEmployee_whenCustomTypeInQuery_thenReturnEntity() throws IOException { - - final OfficeEmployee e = new OfficeEmployee(); - e.setDateOfJoining(LocalDate.now()); - - PhoneNumber number = new PhoneNumber(1, 222, 8781902); - e.setEmployeeNumber(number); - - Address empAdd = new Address(); - empAdd.setAddressLine1("Street"); - empAdd.setAddressLine2("Area"); - empAdd.setCity("City"); - empAdd.setCountry("Country"); - empAdd.setZipCode(100); - e.setEmpAddress(empAdd); - - Salary empSalary = new Salary(); - empSalary.setAmount(1000L); - empSalary.setCurrency("USD"); - e.setSalary(empSalary); - - doInHibernate(this::sessionFactory, session -> { - session.save(e); - - Query query = session.createQuery("FROM OfficeEmployee OE WHERE OE.empAddress.zipcode = :pinCode"); - query.setParameter("pinCode",100); - int size = query.list().size(); - - Assert.assertEquals(1, size); - }); - - } - - private SessionFactory sessionFactory() { - try { - return HibernateUtil.getSessionFactory("hibernate-customtypes.properties"); - } catch (IOException e) { - e.printStackTrace(); - } - - return null; - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java deleted file mode 100644 index 3581c81daa..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java +++ /dev/null @@ -1,425 +0,0 @@ -package com.baeldung.hibernate.exception; - -import static org.hamcrest.CoreMatchers.isA; -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.util.List; - -import javax.persistence.OptimisticLockException; -import javax.persistence.PersistenceException; - -import org.hibernate.AnnotationException; -import org.hibernate.HibernateException; -import org.hibernate.MappingException; -import org.hibernate.NonUniqueObjectException; -import org.hibernate.PropertyValueException; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.StaleObjectStateException; -import org.hibernate.StaleStateException; -import org.hibernate.Transaction; -import org.hibernate.TransactionException; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.cfg.Configuration; -import org.hibernate.exception.ConstraintViolationException; -import org.hibernate.exception.DataException; -import org.hibernate.exception.SQLGrammarException; -import org.hibernate.query.NativeQuery; -import org.hibernate.tool.schema.spi.CommandAcceptanceException; -import org.hibernate.tool.schema.spi.SchemaManagementException; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class HibernateExceptionUnitTest { - - private static final Logger logger = LoggerFactory - .getLogger(HibernateExceptionUnitTest.class); - private SessionFactory sessionFactory; - - @Before - public void setUp() throws IOException { - sessionFactory = HibernateUtil.getSessionFactory(); - } - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private Configuration getConfiguration() { - Configuration cfg = new Configuration(); - cfg.setProperty(AvailableSettings.DIALECT, - "org.hibernate.dialect.H2Dialect"); - cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "none"); - cfg.setProperty(AvailableSettings.DRIVER, "org.h2.Driver"); - cfg.setProperty(AvailableSettings.URL, - "jdbc:h2:mem:myexceptiondb2;DB_CLOSE_DELAY=-1"); - cfg.setProperty(AvailableSettings.USER, "sa"); - cfg.setProperty(AvailableSettings.PASS, ""); - return cfg; - } - - @Test - public void whenQueryExecutedWithUnmappedEntity_thenMappingException() { - thrown.expectCause(isA(MappingException.class)); - thrown.expectMessage("Unknown entity: java.lang.String"); - - Session session = sessionFactory.openSession(); - NativeQuery query = session - .createNativeQuery("select name from PRODUCT", String.class); - query.getResultList(); - } - - @Test - @SuppressWarnings("rawtypes") - public void whenQueryExecuted_thenOK() { - Session session = sessionFactory.openSession(); - NativeQuery query = session - .createNativeQuery("select name from PRODUCT"); - List results = query.getResultList(); - assertNotNull(results); - } - - @Test - public void givenEntityWithoutId_whenSessionFactoryCreated_thenAnnotationException() { - thrown.expect(AnnotationException.class); - thrown.expectMessage("No identifier specified for entity"); - - Configuration cfg = getConfiguration(); - cfg.addAnnotatedClass(EntityWithNoId.class); - cfg.buildSessionFactory(); - } - - @Test - public void givenMissingTable_whenSchemaValidated_thenSchemaManagementException() { - thrown.expect(SchemaManagementException.class); - thrown.expectMessage("Schema-validation: missing table"); - - Configuration cfg = getConfiguration(); - cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "validate"); - cfg.addAnnotatedClass(Product.class); - cfg.buildSessionFactory(); - } - - @Test - public void whenWrongDialectSpecified_thenCommandAcceptanceException() { - thrown.expect(SchemaManagementException.class); - thrown.expectCause(isA(CommandAcceptanceException.class)); - thrown.expectMessage("Halting on error : Error executing DDL"); - - Configuration cfg = getConfiguration(); - cfg.setProperty(AvailableSettings.DIALECT, - "org.hibernate.dialect.MySQLDialect"); - cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "update"); - - // This does not work due to hibernate bug - // cfg.setProperty(AvailableSettings.HBM2DDL_HALT_ON_ERROR,"true"); - cfg.getProperties() - .put(AvailableSettings.HBM2DDL_HALT_ON_ERROR, true); - - cfg.addAnnotatedClass(Product.class); - cfg.buildSessionFactory(); - } - - @Test - public void givenMissingTable_whenEntitySaved_thenSQLGrammarException() { - thrown.expect(isA(PersistenceException.class)); - thrown.expectCause(isA(SQLGrammarException.class)); - thrown - .expectMessage("SQLGrammarException: could not prepare statement"); - - Configuration cfg = getConfiguration(); - cfg.addAnnotatedClass(Product.class); - - SessionFactory sessionFactory = cfg.buildSessionFactory(); - Session session = null; - Transaction transaction = null; - try { - - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - Product product = new Product(); - product.setId(1); - product.setName("Product 1"); - session.save(product); - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - closeSessionFactoryQuietly(sessionFactory); - } - } - - @Test - public void givenMissingTable_whenQueryExecuted_thenSQLGrammarException() { - thrown.expect(isA(PersistenceException.class)); - thrown.expectCause(isA(SQLGrammarException.class)); - thrown - .expectMessage("SQLGrammarException: could not prepare statement"); - - Session session = sessionFactory.openSession(); - NativeQuery query = session.createNativeQuery( - "select * from NON_EXISTING_TABLE", Product.class); - query.getResultList(); - } - - @Test - public void whenDuplicateIdSaved_thenConstraintViolationException() { - thrown.expect(isA(PersistenceException.class)); - thrown.expectCause(isA(ConstraintViolationException.class)); - thrown.expectMessage( - "ConstraintViolationException: could not execute statement"); - - Session session = null; - Transaction transaction = null; - - for (int i = 1; i <= 2; i++) { - try { - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - Product product = new Product(); - product.setId(1); - product.setName("Product " + i); - session.save(product); - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - } - } - } - - @Test - public void givenNotNullPropertyNotSet_whenEntityIdSaved_thenPropertyValueException() { - thrown.expect(isA(PropertyValueException.class)); - thrown.expectMessage( - "not-null property references a null or transient value"); - - Session session = null; - Transaction transaction = null; - - try { - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - - Product product = new Product(); - product.setId(1); - session.save(product); - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - } - - } - - @Test - public void givenQueryWithDataTypeMismatch_WhenQueryExecuted_thenDataException() { - thrown.expectCause(isA(DataException.class)); - thrown.expectMessage( - "org.hibernate.exception.DataException: could not prepare statement"); - - Session session = sessionFactory.openSession(); - NativeQuery query = session.createNativeQuery( - "select * from PRODUCT where id='wrongTypeId'", Product.class); - query.getResultList(); - } - - @Test - public void givenSessionContainingAnId_whenIdAssociatedAgain_thenNonUniqueObjectException() { - thrown.expect(isA(NonUniqueObjectException.class)); - thrown.expectMessage( - "A different object with the same identifier value was already associated with the session"); - - Session session = null; - Transaction transaction = null; - - try { - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - - Product product1 = new Product(); - product1.setId(1); - product1.setName("Product 1"); - session.save(product1); - - Product product2 = new Product(); - product2.setId(1); - product2.setName("Product 2"); - session.save(product2); - - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - } - } - - @Test - public void whenDeletingADeletedObject_thenOptimisticLockException() { - thrown.expect(isA(OptimisticLockException.class)); - thrown.expectMessage( - "Batch update returned unexpected row count from update"); - thrown.expectCause(isA(StaleStateException.class)); - - Session session = null; - Transaction transaction = null; - - try { - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - - Product product1 = new Product(); - product1.setId(12); - product1.setName("Product 12"); - session.save(product1); - transaction.commit(); - session.close(); - - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - Product product2 = session.get(Product.class, 12); - session.createNativeQuery("delete from Product where id=12") - .executeUpdate(); - // We need to refresh to fix the error. - // session.refresh(product2); - session.delete(product2); - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - } - } - - @Test - public void whenUpdatingNonExistingObject_thenStaleStateException() { - thrown.expect(isA(OptimisticLockException.class)); - thrown - .expectMessage("Row was updated or deleted by another transaction"); - thrown.expectCause(isA(StaleObjectStateException.class)); - - Session session = null; - Transaction transaction = null; - - try { - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - - Product product1 = new Product(); - product1.setId(15); - product1.setName("Product1"); - session.update(product1); - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - } - } - - @Test - public void givenTxnMarkedRollbackOnly_whenCommitted_thenTransactionException() { - thrown.expect(isA(TransactionException.class)); - - Session session = null; - Transaction transaction = null; - try { - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - - Product product1 = new Product(); - product1.setId(15); - product1.setName("Product1"); - session.save(product1); - transaction.setRollbackOnly(); - - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - } - } - - private void rollbackTransactionQuietly(Transaction transaction) { - if (transaction != null && transaction.isActive()) { - try { - transaction.rollback(); - } catch (Exception e) { - logger.error("Exception while rolling back transaction", e); - } - } - } - - private void closeSessionQuietly(Session session) { - if (session != null) { - try { - session.close(); - } catch (Exception e) { - logger.error("Exception while closing session", e); - } - } - } - - private void closeSessionFactoryQuietly(SessionFactory sessionFactory) { - if (sessionFactory != null) { - try { - sessionFactory.close(); - } catch (Exception e) { - logger.error("Exception while closing sessionFactory", e); - } - } - } - - @Test - public void givenExistingEntity_whenIdUpdated_thenHibernateException() { - thrown.expect(isA(PersistenceException.class)); - thrown.expectCause(isA(HibernateException.class)); - thrown.expectMessage( - "identifier of an instance of com.baeldung.hibernate.exception.Product was altered"); - - Session session = null; - Transaction transaction = null; - - try { - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - - Product product1 = new Product(); - product1.setId(222); - product1.setName("Product 222"); - session.save(product1); - transaction.commit(); - closeSessionQuietly(session); - - session = sessionFactory.openSession(); - transaction = session.beginTransaction(); - - Product product2 = session.get(Product.class, 222); - product2.setId(333); - session.save(product2); - - transaction.commit(); - } catch (Exception e) { - rollbackTransactionQuietly(transaction); - throw (e); - } finally { - closeSessionQuietly(session); - } - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java deleted file mode 100644 index 8a1b9e9791..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.hibernate.findall; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.List; - -import org.hibernate.Session; -import org.hibernate.Transaction; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.HibernateUtil; -import com.baeldung.hibernate.pojo.Student; - -public class FindAllUnitTest { - - private Session session; - private Transaction transaction; - - private FindAll findAll; - - @Before - public void setUp() throws IOException { - - session = HibernateUtil.getSessionFactory().openSession(); - transaction = session.beginTransaction(); - findAll = new FindAll(session); - - session.createNativeQuery("delete from Student").executeUpdate(); - - Student student1 = new Student(); - session.persist(student1); - - Student student2 = new Student(); - session.persist(student2); - - Student student3 = new Student(); - session.persist(student3); - - transaction.commit(); - transaction = session.beginTransaction(); - } - - @After - public void tearDown() { - transaction.rollback(); - session.close(); - } - - @Test - public void givenCriteriaQuery_WhenFindAll_ThenGetAllPersons() { - List list = findAll.findAllWithCriteriaQuery(); - assertEquals(3, list.size()); - } - - @Test - public void givenJpql_WhenFindAll_ThenGetAllPersons() { - List list = findAll.findAllWithJpql(); - assertEquals(3, list.size()); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java deleted file mode 100644 index 0998ff1d90..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.baeldung.hibernate.joincolumn; - -import com.baeldung.hibernate.HibernateUtil; -import java.io.IOException; -import org.hibernate.Session; -import org.hibernate.Transaction; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - - -public class JoinColumnIntegrationTest { - - private Session session; - private Transaction transaction; - - @Before - public void setUp() throws IOException { - session = HibernateUtil.getSessionFactory("hibernate-spatial.properties") - .openSession(); - transaction = session.beginTransaction(); - } - - @After - public void tearDown() { - transaction.rollback(); - session.close(); - } - - @Test - public void givenOfficeEntity_setAddress_shouldPersist() { - Office office = new Office(); - - OfficeAddress address = new OfficeAddress(); - address.setZipCode("11-111"); - office.setAddress(address); - - session.save(office); - session.flush(); - session.clear(); - } - - @Test - public void givenEmployeeEntity_setEmails_shouldPersist() { - OfficialEmployee employee = new OfficialEmployee(); - - Email email = new Email(); - email.setAddress("example@email.com"); - email.setEmployee(employee); - - session.save(employee); - session.flush(); - session.clear(); - } - -} \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java deleted file mode 100644 index 2b12734a10..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.baeldung.hibernate.jpacriteriabuilder; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; -import static org.junit.Assert.assertEquals; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -import javax.persistence.EntityManager; - -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.HibernateUtil; -import com.baeldung.hibernate.entities.Department; -import com.baeldung.hibernate.entities.DeptEmployee; -import com.baeldung.hibernate.jpacriteriabuilder.service.EmployeeSearchService; -import com.baeldung.hibernate.jpacriteriabuilder.service.EmployeeSearchServiceImpl; - -public class EmployeeSearchServiceIntegrationTest { - - private EntityManager entityManager; - private EmployeeSearchService searchService; - private Session session; - - @Before - public final void setup() throws HibernateException, IOException { - session = HibernateUtil.getSessionFactory() - .openSession(); - entityManager = session.getEntityManagerFactory() - .createEntityManager(); - searchService = new EmployeeSearchServiceImpl(entityManager); - - entityManager.getTransaction() - .begin(); - Department department = new Department("Pre Sales"); - DeptEmployee employee = new DeptEmployee("John Smith", "001", "Manager", department); - entityManager.persist(department); - entityManager.persist(employee); - employee = new DeptEmployee("Ian Evans", "002", "Associate", department); - entityManager.persist(department); - entityManager.persist(employee); - department = new Department("Copporate Sales"); - employee = new DeptEmployee("Robert Carter", "003", "Manager", department); - entityManager.persist(department); - entityManager.persist(employee); - employee = new DeptEmployee("John Carter", "004", "Senior Manager", department); - entityManager.persist(employee); - employee = new DeptEmployee("David Guetta", "009", "Associate", department); - entityManager.persist(department); - entityManager.persist(employee); - department = new Department("Post Sales"); - employee = new DeptEmployee("Robert Jonas", "005", "Director", department); - entityManager.persist(department); - entityManager.persist(employee); - employee = new DeptEmployee("John Ferros", "006", "Junior Associate", department); - entityManager.persist(department); - entityManager.persist(employee); - department = new Department("Client Support"); - employee = new DeptEmployee("Robert Mcclements", "007", "Director", department); - entityManager.persist(department); - entityManager.persist(employee); - employee = new DeptEmployee("Peter Parker", "008", "Manager", department); - entityManager.persist(department); - entityManager.persist(employee); - - } - - @After - public final void teardown() { - entityManager.getTransaction() - .rollback(); - entityManager.close(); - } - - @Test - public final void givenCriteriaQuery_whenSearchedUsingCriteriaBuilderWithListofAuthors_thenResultIsFilteredByAuthorNames() { - List titles = new ArrayList() { - { - add("Manager"); - add("Senior Manager"); - add("Director"); - } - }; - List result = searchService.filterbyTitleUsingCriteriaBuilder(titles); - assertEquals("Number of Employees does not match with expected.", 6, result.size()); - assertThat(result.stream() - .map(DeptEmployee::getTitle) - .distinct() - .collect(Collectors.toList()), containsInAnyOrder(titles.toArray())); - } - - @Test - public final void givenCriteriaQuery_whenSearchedUsingExpressionWithListofAuthors_thenResultIsFilteredByAuthorNames() { - List titles = new ArrayList() { - { - add("Manager"); - add("Senior Manager"); - add("Director"); - } - }; - List result = searchService.filterbyTitleUsingExpression(titles); - assertEquals("Number of Employees does not match with expected.", 6, result.size()); - assertThat(result.stream() - .map(DeptEmployee::getTitle) - .distinct() - .collect(Collectors.toList()), containsInAnyOrder(titles.toArray())); - } - - @Test - public final void givenCriteriaQuery_whenSearchedDepartmentLike_thenResultIsFilteredByDepartment() { - List result = searchService.searchByDepartmentQuery("Sales"); - assertEquals("Number of Employees does not match with expected.", 7, result.size()); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java deleted file mode 100644 index 398b2290fa..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.hibernate.lob; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; - -import org.apache.commons.io.IOUtils; -import org.hibernate.HibernateException; -import org.hibernate.Session; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.lob.model.User; - -public class LobUnitTest { - - private Session session; - - @Before - public void init(){ - try { - session = HibernateSessionUtil.getSessionFactory("hibernate.properties") - .openSession(); - } catch (HibernateException | IOException e) { - fail("Failed to initiate Hibernate Session [Exception:" + e.toString() + "]"); - } - } - - @After - public void close(){ - if(session != null) session.close(); - } - - @Test - public void givenValidInsertLobObject_whenQueried_returnSameDataAsInserted(){ - User user = new User(); - try(InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("profile.png");) { - // Get Image file from the resource - if(inputStream == null) fail("Unable to get resources"); - user.setId("1"); - user.setName("User"); - user.setPhoto(IOUtils.toByteArray(inputStream)); - - session.persist(user); - } catch (IOException e) { - fail("Unable to read input stream"); - } - - User result = session.find(User.class, "1"); - - assertNotNull("Query result is null", result); - assertEquals("User's name is invalid", user.getName(), result.getName() ); - assertTrue("User's photo is corrupted", Arrays.equals(user.getPhoto(), result.getPhoto()) ); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/Car.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/Car.java deleted file mode 100644 index 1b6cee7e67..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/Car.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.hibernate.multitenancy; - -import java.io.Serializable; - -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.Table; - -@Entity(name = "Car") -@Table(name = "Car") -public class Car implements Serializable { - - private static final long serialVersionUID = 1015320564683423342L; - - private String brand; - - @Id - public String getBrand() { - return brand; - } - - public void setBrand(String brand) { - this.brand = brand; - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java deleted file mode 100644 index fdc3f9fa81..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java +++ /dev/null @@ -1,104 +0,0 @@ -package com.baeldung.hibernate.multitenancy; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.io.IOException; -import java.util.Properties; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.AvailableSettings; -import org.hibernate.context.spi.CurrentTenantIdentifierResolver; -import org.hibernate.service.ServiceRegistry; -import org.junit.Before; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; - -import com.baeldung.hibernate.multitenancy.database.TenantIdNames; - -public abstract class MultitenancyIntegrationTest { - - public abstract String getPropertyFile(); - - @Mock - private CurrentTenantIdentifierResolver currentTenantIdentifierResolver; - - private SessionFactory sessionFactory; - - @Before - public void setup() throws IOException { - MockitoAnnotations.initMocks(this); - - Mockito.when(currentTenantIdentifierResolver.validateExistingCurrentSessions()) - .thenReturn(false); - - Properties properties = getHibernateProperties(); - properties.put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver); - - sessionFactory = buildSessionFactory(properties); - - initTenant(TenantIdNames.MYDB1); - initTenant(TenantIdNames.MYDB2); - } - - protected void initTenant(String tenantId) { - whenCurrentTenantIs(tenantId); - createCarTable(); - } - - protected void whenCurrentTenantIs(String tenantId) { - Mockito.when(currentTenantIdentifierResolver.resolveCurrentTenantIdentifier()) - .thenReturn(tenantId); - } - - protected void whenAddCar(String brand) { - Session session = sessionFactory.openSession(); - Transaction tx = session.beginTransaction(); - Car car = new Car(); - car.setBrand(brand); - session.save(car); - tx.commit(); - } - - protected void thenCarFound(String brand) { - Session session = sessionFactory.openSession(); - assertNotNull(session.get(Car.class, brand)); - } - - protected void thenCarNotFound(String brand) { - Session session = sessionFactory.openSession(); - assertNull(session.get(Car.class, brand)); - } - - @SuppressWarnings("deprecation") - private void createCarTable() { - Session session = sessionFactory.openSession(); - Transaction tx = session.beginTransaction(); - session.createSQLQuery("drop table Car if exists") - .executeUpdate(); - session.createSQLQuery("create table Car (brand varchar(255) primary key)") - .executeUpdate(); - tx.commit(); - } - - private Properties getHibernateProperties() throws IOException { - Properties properties = new Properties(); - properties.load(getClass().getResourceAsStream(getPropertyFile())); - return properties; - } - - private static SessionFactory buildSessionFactory(Properties properties) { - ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(properties) - .build(); - MetadataSources metadataSources = new MetadataSources(serviceRegistry); - metadataSources.addAnnotatedClass(Car.class); - return metadataSources.buildMetadata() - .buildSessionFactory(); - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java deleted file mode 100644 index 92f477a646..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.hibernate.multitenancy.database; - -import java.io.IOException; - -import org.junit.Test; - -import com.baeldung.hibernate.multitenancy.MultitenancyIntegrationTest; - -public class DatabaseApproachMultitenancyIntegrationTest extends MultitenancyIntegrationTest { - - @Override - public String getPropertyFile() { - return "/hibernate-database-multitenancy.properties"; - } - - @Test - public void givenDatabaseApproach_whenAddingEntries_thenOnlyAddedToConcreteDatabase() throws IOException { - whenCurrentTenantIs(TenantIdNames.MYDB1); - whenAddCar("myCar"); - thenCarFound("myCar"); - whenCurrentTenantIs(TenantIdNames.MYDB2); - thenCarNotFound("myCar"); - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java deleted file mode 100644 index eb1f410622..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.hibernate.multitenancy.database; - -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; -import java.util.Properties; - -import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; -import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider; -import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; - -@SuppressWarnings("serial") -public class MapMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider { - - private final Map connectionProviderMap = new HashMap<>(); - - public MapMultiTenantConnectionProvider() throws IOException { - initConnectionProviderForTenant(TenantIdNames.MYDB1); - initConnectionProviderForTenant(TenantIdNames.MYDB2); - } - - @Override - protected ConnectionProvider getAnyConnectionProvider() { - return connectionProviderMap.values() - .iterator() - .next(); - } - - @Override - protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) { - return connectionProviderMap.get(tenantIdentifier); - } - - private void initConnectionProviderForTenant(String tenantId) throws IOException { - Properties properties = new Properties(); - properties.load(getClass().getResourceAsStream(String.format("/hibernate-database-%s.properties", tenantId))); - DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); - connectionProvider.configure(properties); - this.connectionProviderMap.put(tenantId, connectionProvider); - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java deleted file mode 100644 index 231272fa63..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.hibernate.multitenancy.database; - -public class TenantIdNames { - public static final String MYDB1 = "mydb1"; - public static final String MYDB2 = "mydb2"; -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java deleted file mode 100644 index 304af65fca..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.hibernate.multitenancy.schema; - -import java.io.IOException; - -import org.junit.Test; - -import com.baeldung.hibernate.multitenancy.MultitenancyIntegrationTest; -import com.baeldung.hibernate.multitenancy.database.TenantIdNames; - -public class SchemaApproachMultitenancyIntegrationTest extends MultitenancyIntegrationTest { - - @Override - public String getPropertyFile() { - return "/hibernate-schema-multitenancy.properties"; - } - - @Test - public void givenSchemaApproach_whenAddingEntries_thenOnlyAddedToConcreteSchema() throws IOException { - whenCurrentTenantIs(TenantIdNames.MYDB1); - whenAddCar("Ferrari"); - thenCarFound("Ferrari"); - whenCurrentTenantIs(TenantIdNames.MYDB2); - thenCarNotFound("Ferrari"); - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java deleted file mode 100644 index 601eba651c..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.hibernate.multitenancy.schema; - -import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; -import java.util.Properties; - -import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; -import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider; -import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; - -@SuppressWarnings("serial") -public class SchemaMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider { - - private final ConnectionProvider connectionProvider; - - public SchemaMultiTenantConnectionProvider() throws IOException { - connectionProvider = initConnectionProvider(); - } - - @Override - protected ConnectionProvider getAnyConnectionProvider() { - return connectionProvider; - } - - @Override - protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) { - return connectionProvider; - } - - @Override - public Connection getConnection(String tenantIdentifier) throws SQLException { - Connection connection = super.getConnection(tenantIdentifier); - connection.createStatement() - .execute(String.format("SET SCHEMA %s;", tenantIdentifier)); - return connection; - } - - private ConnectionProvider initConnectionProvider() throws IOException { - Properties properties = new Properties(); - properties.load(getClass().getResourceAsStream("/hibernate-schema-multitenancy.properties")); - - DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); - connectionProvider.configure(properties); - return connectionProvider; - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java deleted file mode 100644 index 2eba94e307..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.hibernate.multitenancy.schema; - -public class TenantIdNames { - public static final String MYDB1 = "mydb1"; - public static final String MYDB2 = "mydb2"; -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java deleted file mode 100644 index 475c93f6ff..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.baeldung.hibernate.onetoone; - -import com.baeldung.hibernate.onetoone.foreignkeybased.Address; -import com.baeldung.hibernate.onetoone.foreignkeybased.User; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class HibernateOneToOneAnnotationFKBasedIntegrationTest { - - private static SessionFactory sessionFactory; - - private Session session; - - @BeforeClass - public static void beforeTests() { - sessionFactory = HibernateUtil.getSessionFactory(Strategy.FOREIGN_KEY); - } - - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - } - - @Test - public void givenData_whenInsert_thenCreates1to1relationship() { - User user = new User(); - user.setUserName("alice@baeldung.com"); - - Address address = new Address(); - address.setStreet("FK Street"); - address.setCity("FK City"); - - address.setUser(user); - user.setAddress(address); - - //Address entry will automatically be created by hibernate, since cascade type is specified as ALL - session.persist(user); - session.getTransaction().commit(); - - assert1to1InsertedData(); - } - - private void assert1to1InsertedData() { - @SuppressWarnings("unchecked") - List userList = session.createQuery("FROM User").list(); - - assertNotNull(userList); - assertEquals(1, userList.size()); - - User user = userList.get(0); - assertEquals("alice@baeldung.com", user.getUserName()); - - Address address = user.getAddress(); - assertNotNull(address); - assertEquals("FK Street", address.getStreet()); - assertEquals("FK City", address.getCity()); - - } - - @After - public void tearDown() { - session.close(); - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java deleted file mode 100644 index df4cd4d137..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.baeldung.hibernate.onetoone; - -import com.baeldung.hibernate.onetoone.jointablebased.Employee; -import com.baeldung.hibernate.onetoone.jointablebased.WorkStation; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class HibernateOneToOneAnnotationJTBasedIntegrationTest { - - private static SessionFactory sessionFactory; - - private Session session; - - @BeforeClass - public static void beforeTests() { - sessionFactory = HibernateUtil.getSessionFactory(Strategy.JOIN_TABLE_BASED); - } - - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - } - - @Test - public void givenData_whenInsert_thenCreates1to1relationship() { - Employee employee = new Employee(); - employee.setName("bob@baeldung.com"); - - WorkStation workStation = new WorkStation(); - workStation.setWorkstationNumber(626); - workStation.setFloor("Sixth Floor"); - - - employee.setWorkStation(workStation); - workStation.setEmployee(employee); - - session.persist(employee); - session.getTransaction().commit(); - - assert1to1InsertedData(); - } - - private void assert1to1InsertedData() { - @SuppressWarnings("unchecked") - List employeeList = session.createQuery("FROM Employee").list(); - assertNotNull(employeeList); - assertEquals(1, employeeList.size()); - - Employee employee = employeeList.get(0); - assertEquals("bob@baeldung.com", employee.getName()); - - WorkStation workStation = employee.getWorkStation(); - - assertNotNull(workStation); - assertEquals((long) 626, (long) workStation.getWorkstationNumber()); - assertEquals("Sixth Floor", workStation.getFloor()); - - } - - @After - public void tearDown() { - session.close(); - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java deleted file mode 100644 index 7931a8e3fe..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.baeldung.hibernate.onetoone; - -import com.baeldung.hibernate.onetoone.sharedkeybased.Address; -import com.baeldung.hibernate.onetoone.sharedkeybased.User; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -public class HibernateOneToOneAnnotationSPKBasedIntegrationTest { - - private static SessionFactory sessionFactory; - - private Session session; - - @BeforeClass - public static void beforeTests() { - sessionFactory = HibernateUtil.getSessionFactory(Strategy.SHARED_PRIMARY_KEY); - } - - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - } - - @Test - public void givenData_whenInsert_thenCreates1to1relationship() { - User user = new User(); - user.setUserName("alice@baeldung.com"); - - Address address = new Address(); - address.setStreet("SPK Street"); - address.setCity("SPK City"); - - address.setUser(user); - user.setAddress(address); - - //Address entry will automatically be created by hibernate, since cascade type is specified as ALL - session.persist(user); - session.getTransaction().commit(); - - assert1to1InsertedData(); - } - - - private void assert1to1InsertedData() { - @SuppressWarnings("unchecked") - List userList = session.createQuery("FROM User").list(); - assertNotNull(userList); - assertEquals(1, userList.size()); - - User user = userList.get(0); - assertEquals("alice@baeldung.com", user.getUserName()); - - Address address = user.getAddress(); - assertNotNull(address); - assertEquals("SPK Street", address.getStreet()); - assertEquals("SPK City", address.getCity()); - } - - @After - public void tearDown() { - session.close(); - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java deleted file mode 100644 index 37c490f297..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package com.baeldung.hibernate.optimisticlocking; - -import java.io.IOException; -import java.util.Arrays; - -import javax.persistence.EntityManager; -import javax.persistence.LockModeType; -import javax.persistence.OptimisticLockException; - -import org.hibernate.SessionFactory; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.Test; - -import com.baeldung.hibernate.HibernateUtil; - -public class OptimisticLockingIntegrationTest { - - private static SessionFactory sessionFactory; - - @Before - public void setUp() throws IOException { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - OptimisticLockingCourse course = new OptimisticLockingCourse(1L, "MATH"); - OptimisticLockingStudent student = new OptimisticLockingStudent(1L, "John", "Doe", Arrays.asList(course)); - course.setStudent(student); - entityManager.persist(course); - entityManager.persist(student); - entityManager.getTransaction() - .commit(); - entityManager.close(); - } - - @After - public void clean() throws IOException { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - OptimisticLockingCourse course = entityManager.find(OptimisticLockingCourse.class, 1L); - OptimisticLockingStudent student = entityManager.find(OptimisticLockingStudent.class, 1L); - entityManager.remove(course); - entityManager.remove(student); - entityManager.getTransaction() - .commit(); - entityManager.close(); - } - - @Test(expected = OptimisticLockException.class) - public void givenVersionedEntities_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { - EntityManager em = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); - - EntityManager em2 = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); - student2.setName("RICHARD"); - em2.persist(student2); - em2.getTransaction() - .commit(); - em2.close(); - - student.setName("JOHN"); - em.persist(student); - em.getTransaction() - .commit(); - em.close(); - } - - @Test(expected = OptimisticLockException.class) - public void givenVersionedEntitiesWithLockByFindMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { - EntityManager em = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L, LockModeType.OPTIMISTIC); - - EntityManager em2 = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L, LockModeType.OPTIMISTIC_FORCE_INCREMENT); - student2.setName("RICHARD"); - em2.persist(student2); - em2.getTransaction() - .commit(); - em2.close(); - - student.setName("JOHN"); - em.persist(student); - em.getTransaction() - .commit(); - em.close(); - } - - @Test(expected = OptimisticLockException.class) - public void givenVersionedEntitiesWithLockByRefreshMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { - EntityManager em = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); - em.refresh(student, LockModeType.OPTIMISTIC); - - EntityManager em2 = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); - em.refresh(student, LockModeType.OPTIMISTIC_FORCE_INCREMENT); - student2.setName("RICHARD"); - em2.persist(student2); - em2.getTransaction() - .commit(); - em2.close(); - - student.setName("JOHN"); - em.persist(student); - em.getTransaction() - .commit(); - em.close(); - } - - @Test(expected = OptimisticLockException.class) - public void givenVersionedEntitiesWithLockByLockMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { - EntityManager em = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); - em.lock(student, LockModeType.OPTIMISTIC); - - EntityManager em2 = getEntityManagerWithOpenTransaction(); - OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); - em.lock(student, LockModeType.OPTIMISTIC_FORCE_INCREMENT); - student2.setName("RICHARD"); - em2.persist(student2); - em2.getTransaction() - .commit(); - em2.close(); - - student.setName("JOHN"); - em.persist(student); - em.getTransaction() - .commit(); - em.close(); - } - - protected static EntityManager getEntityManagerWithOpenTransaction() throws IOException { - String propertyFileName = "hibernate-pessimistic-locking.properties"; - if (sessionFactory == null) { - sessionFactory = HibernateUtil.getSessionFactory(propertyFileName); - } - EntityManager entityManager = sessionFactory.openSession(); - entityManager.getTransaction().begin(); - - return entityManager; - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java deleted file mode 100644 index 4b9c7720fd..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java +++ /dev/null @@ -1,162 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import com.baeldung.hibernate.HibernateUtil; -import com.vividsolutions.jts.util.Assert; - -import org.hibernate.SessionFactory; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; - -import javax.persistence.*; -import java.io.IOException; -import java.util.Arrays; - -public class BasicPessimisticLockingIntegrationTest { - - private static SessionFactory sessionFactory; - - @BeforeClass - public static void setUp() throws IOException { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent student = new PessimisticLockingStudent(1L, "JOHN"); - PessimisticLockingCourse course = new PessimisticLockingCourse(1L, "MATH", student); - student.setCourses(Arrays.asList(course)); - entityManager.persist(course); - entityManager.persist(student); - entityManager.getTransaction() - .commit(); - entityManager.close(); - } - - @Test - public void givenFoundRecordWithPessimisticRead_whenFindingNewOne_PessimisticLockExceptionThrown() { - try { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - entityManager.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_READ); - - EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); - entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_READ); - - entityManager.close(); - entityManager2.close(); - } catch (Exception e) { - Assert.isTrue(e instanceof PessimisticLockException); - } - } - - @Test - public void givenRecordWithPessimisticReadQuery_whenQueryingNewOne_PessimisticLockExceptionThrown() throws IOException { - try { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - Query query = entityManager.createQuery("from Student where studentId = :studentId"); - query.setParameter("studentId", 1L); - query.setLockMode(LockModeType.PESSIMISTIC_WRITE); - query.getResultList(); - - EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); - Query query2 = entityManager2.createQuery("from Student where studentId = :studentId"); - query2.setParameter("studentId", 1L); - query2.setLockMode(LockModeType.PESSIMISTIC_READ); - query2.getResultList(); - - entityManager.close(); - entityManager2.close(); - } catch (Exception e) { - Assert.isTrue(e instanceof PessimisticLockException); - } - } - - @Test - public void givenRecordWithPessimisticReadLock_whenFindingNewOne_PessimisticLockExceptionThrown() { - try { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); - entityManager.lock(resultStudent, LockModeType.PESSIMISTIC_READ); - - EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); - entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_FORCE_INCREMENT); - - entityManager.close(); - entityManager2.close(); - } catch (Exception e) { - Assert.isTrue(e instanceof PessimisticLockException); - } - } - - @Test - public void givenRecordAndRefreshWithPessimisticRead_whenFindingWithPessimisticWrite_PessimisticLockExceptionThrown() { - try { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); - entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_FORCE_INCREMENT); - - EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); - entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_WRITE); - - entityManager.close(); - entityManager2.close(); - } catch (Exception e) { - Assert.isTrue(e instanceof PessimisticLockException); - } - } - - @Test - public void givenRecordWithPessimisticRead_whenUpdatingRecord_PessimisticLockExceptionThrown() { - try { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); - entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_READ); - - EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent resultStudent2 = entityManager2.find(PessimisticLockingStudent.class, 1L); - resultStudent2.setName("Change"); - entityManager2.persist(resultStudent2); - entityManager2.getTransaction() - .commit(); - - entityManager.close(); - entityManager2.close(); - } catch (Exception e) { - Assert.isTrue(e instanceof PessimisticLockException); - } - } - - @Test - public void givenRecordWithPessimisticWrite_whenUpdatingRecord_PessimisticLockExceptionThrown() { - try { - EntityManager entityManager = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); - entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_WRITE); - - EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent resultStudent2 = entityManager2.find(PessimisticLockingStudent.class, 1L); - resultStudent2.setName("Change"); - entityManager2.persist(resultStudent2); - entityManager2.getTransaction() - .commit(); - - entityManager.close(); - entityManager2.close(); - } catch (Exception e) { - Assert.isTrue(e instanceof PessimisticLockException); - } - } - - protected static EntityManager getEntityManagerWithOpenTransaction() throws IOException { - String propertyFileName = "hibernate-pessimistic-locking.properties"; - if (sessionFactory == null) { - sessionFactory = HibernateUtil.getSessionFactory(propertyFileName); - } - EntityManager entityManager = sessionFactory.openSession(); - entityManager.getTransaction().begin(); - - return entityManager; - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } - -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java deleted file mode 100644 index 81cb7d95f8..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java +++ /dev/null @@ -1,125 +0,0 @@ -package com.baeldung.hibernate.pessimisticlocking; - -import com.baeldung.hibernate.HibernateUtil; - -import org.hibernate.SessionFactory; -import org.junit.AfterClass; -import org.junit.Test; - -import javax.persistence.EntityManager; -import javax.persistence.LockModeType; -import javax.persistence.PessimisticLockScope; -import java.io.IOException; -import java.math.BigDecimal; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -public class PessimisticLockScopesIntegrationTest { - - private static SessionFactory sessionFactory; - - @Test - public void givenEclipseEntityWithJoinInheritance_whenNormalLock_thenShouldChildAndParentEntity() throws IOException { - EntityManager em = getEntityManagerWithOpenTransaction(); - PessimisticLockingEmployee employee = new PessimisticLockingEmployee(1L, "JOHN", "SMITH", new BigDecimal(4.5)); - em.persist(employee); - em.getTransaction() - .commit(); - em.close(); - - // NORMAL SCOPE - EntityManager em2 = getEntityManagerWithOpenTransaction(); - PessimisticLockingEmployee foundEmployee = em2.find(PessimisticLockingEmployee.class, 1L, LockModeType.PESSIMISTIC_WRITE); - em2.getTransaction() - .rollback(); - - // EXTENDED SCOPE - Map map = new HashMap<>(); - map.put("javax.persistence.lock.scope", PessimisticLockScope.EXTENDED); - - EntityManager em3 = getEntityManagerWithOpenTransaction(); - foundEmployee = em3.find(PessimisticLockingEmployee.class, 1L, LockModeType.PESSIMISTIC_WRITE, map); - em3.getTransaction() - .rollback(); - - em2.close(); - em3.close(); - } - - @Test - public void givenEntityWithElementCollection_whenLock_thenHibernateExtendedScopeLockOnlyOwningEntity() throws IOException { - EntityManager em = getEntityManagerWithOpenTransaction(); - Address address = new Address("Poland", "Warsaw"); - Customer customer = new Customer(1L, "JOE", "DOE", Arrays.asList(address)); - em.persist(customer); - em.getTransaction() - .commit(); - em.close(); - - // NORMAL SCOPE - EntityManager em2 = getEntityManagerWithOpenTransaction(); - Customer foundCustomer = em2.find(Customer.class, 1L, LockModeType.PESSIMISTIC_WRITE); - em2.getTransaction() - .rollback(); - - // EXTENDED SCOPE - Map map = new HashMap<>(); - map.put("javax.persistence.lock.scope", PessimisticLockScope.EXTENDED); - - EntityManager em3 = getEntityManagerWithOpenTransaction(); - foundCustomer = em3.find(Customer.class, 1L, LockModeType.PESSIMISTIC_WRITE, map); - em2.getTransaction() - .rollback(); - - em2.close(); - em3.close(); - } - - @Test - public void givenEntityWithOneToMany_whenLock_thenHibernateExtendedScopeLockOnlyOwningEntity() throws IOException { - EntityManager em = getEntityManagerWithOpenTransaction(); - PessimisticLockingStudent student = new PessimisticLockingStudent(1L, "JOE"); - PessimisticLockingCourse course = new PessimisticLockingCourse(1L, "COURSE", student); - student.setCourses(Arrays.asList(course)); - em.persist(course); - em.persist(student); - em.getTransaction() - .commit(); - em.close(); - - // NORMAL SCOPE - EntityManager em2 = getEntityManagerWithOpenTransaction(); - PessimisticLockingCourse foundCourse = em2.find(PessimisticLockingCourse.class, 1L, LockModeType.PESSIMISTIC_WRITE); - em2.getTransaction() - .rollback(); - - // EXTENDED SCOPE - Map map = new HashMap<>(); - map.put("javax.persistence.lock.scope", PessimisticLockScope.EXTENDED); - - EntityManager em3 = getEntityManagerWithOpenTransaction(); - foundCourse = em3.find(PessimisticLockingCourse.class, 1L, LockModeType.PESSIMISTIC_WRITE, map); - em3.getTransaction() - .rollback(); - - em2.close(); - em3.close(); - } - - protected EntityManager getEntityManagerWithOpenTransaction() throws IOException { - String propertyFileName = "hibernate-pessimistic-locking.properties"; - if (sessionFactory == null) { - sessionFactory = HibernateUtil.getSessionFactory(propertyFileName); - } - EntityManager entityManager = sessionFactory.openSession(); - entityManager.getTransaction().begin(); - - return entityManager; - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java deleted file mode 100644 index 13eae3d877..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.baeldung.hibernate.queryplancache; - -import com.baeldung.hibernate.HibernateUtil; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.jpa.QueryHints; -import org.hibernate.query.Query; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.BenchmarkMode; -import org.openjdk.jmh.annotations.Fork; -import org.openjdk.jmh.annotations.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.annotations.TearDown; -import org.openjdk.jmh.annotations.Warmup; -import org.openjdk.jmh.infra.Blackhole; -import org.openjdk.jmh.runner.RunnerException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Properties; -import java.util.concurrent.TimeUnit; - -public class QueryPlanCacheBenchmark { - - private static final Logger LOGGER = LoggerFactory.getLogger(QueryPlanCacheBenchmark.class); - - @State(Scope.Thread) - public static class QueryPlanCacheBenchMarkState { - @Param({"1", "2", "3"}) - public int planCacheSize; - - public Session session; - - @Setup - public void stateSetup() throws IOException { - LOGGER.info("State - Setup"); - session = initSession(planCacheSize); - LOGGER.info("State - Setup Complete"); - } - - private Session initSession(int planCacheSize) throws IOException { - Properties properties = HibernateUtil.getProperties(); - properties.put("hibernate.query.plan_cache_max_size", planCacheSize); - properties.put("hibernate.query.plan_parameter_metadata_max_size", planCacheSize); - SessionFactory sessionFactory = HibernateUtil.getSessionFactoryByProperties(properties); - return sessionFactory.openSession(); - } - - @TearDown - public void tearDownState() { - LOGGER.info("State - Teardown"); - SessionFactory sessionFactory = session.getSessionFactory(); - session.close(); - sessionFactory.close(); - LOGGER.info("State - Teardown complete"); - } - } - - @Benchmark - @BenchmarkMode(Mode.AverageTime) - @OutputTimeUnit(TimeUnit.MICROSECONDS) - @Fork(1) - @Warmup(iterations = 2) - @Measurement(iterations = 5) - public void givenQueryPlanCacheSize_thenCompileQueries(QueryPlanCacheBenchMarkState state, Blackhole blackhole) { - - Query query1 = findEmployeesByDepartmentNameQuery(state.session); - Query query2 = findEmployeesByDesignationQuery(state.session); - Query query3 = findDepartmentOfAnEmployeeQuery(state.session); - - blackhole.consume(query1); - blackhole.consume(query2); - blackhole.consume(query3); - - } - - private Query findEmployeesByDepartmentNameQuery(Session session) { - return session.createQuery("SELECT e FROM DeptEmployee e " + - "JOIN e.department WHERE e.department.name = :deptName") - .setMaxResults(30) - .setHint(QueryHints.HINT_FETCH_SIZE, 30); - } - - private Query findEmployeesByDesignationQuery(Session session) { - return session.createQuery("SELECT e FROM DeptEmployee e " + - "WHERE e.title = :designation") - .setHint(QueryHints.SPEC_HINT_TIMEOUT, 1000); - } - - private Query findDepartmentOfAnEmployeeQuery(Session session) { - return session.createQuery("SELECT e.department FROM DeptEmployee e " + - "JOIN e.department WHERE e.employeeNumber = :empId"); - - } - - public static void main(String... args) throws IOException, RunnerException { - //main-class to run the benchmark - org.openjdk.jmh.Main.main(args); - } -} diff --git a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java b/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java deleted file mode 100644 index 246a7d59f9..0000000000 --- a/persistence-modules/hibernate5/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.baeldung.hibernate.transaction; - -import com.baeldung.hibernate.HibernateUtil; -import com.baeldung.hibernate.pojo.Post; -import com.baeldung.hibernate.transaction.PostService; -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.junit.BeforeClass; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.FileInputStream; -import java.io.IOException; -import java.util.Properties; - -import static org.junit.Assert.assertEquals; - -public class TransactionIntegrationTest { - - private static PostService postService; - private static Session session; - private static Logger logger = LoggerFactory.getLogger(TransactionIntegrationTest.class); - - @BeforeClass - public static void init() throws IOException { - Properties properties = new Properties(); - properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); - properties.setProperty("hibernate.connection.url", "jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1"); - properties.setProperty("hibernate.connection.username", "sa"); - properties.setProperty("hibernate.show_sql", "true"); - properties.setProperty("jdbc.password", ""); - properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); - properties.setProperty("hibernate.hbm2ddl.auto", "create-drop"); - SessionFactory sessionFactory = HibernateUtil.getSessionFactoryByProperties(properties); - session = sessionFactory.openSession(); - postService = new PostService(session); - } - - @Test - public void givenTitleAndBody_whenRepositoryUpdatePost_thenUpdatePost() { - - Post post = new Post("This is a title", "This is a sample post"); - session.persist(post); - - String title = "[UPDATE] Java HowTos"; - String body = "This is an updated posts on Java how-tos"; - postService.updatePost(title, body, post.getId()); - - session.refresh(post); - - assertEquals(post.getTitle(), title); - assertEquals(post.getBody(), body); - } - - -} diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties deleted file mode 100644 index c14782ce0f..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-customtypes.properties +++ /dev/null @@ -1,14 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 -hibernate.connection.username=sa -hibernate.connection.autocommit=true -jdbc.password= - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop - -hibernate.c3p0.min_size=5 -hibernate.c3p0.max_size=20 -hibernate.c3p0.acquire_increment=5 -hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-database-multitenancy.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-database-multitenancy.properties deleted file mode 100644 index 853fa80dfc..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-database-multitenancy.properties +++ /dev/null @@ -1,2 +0,0 @@ -hibernate.multiTenancy=DATABASE -hibernate.multi_tenant_connection_provider=com.baeldung.hibernate.multitenancy.database.MapMultiTenantConnectionProvider \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb1.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb1.properties deleted file mode 100644 index 345f1dbbea..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb1.properties +++ /dev/null @@ -1,4 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 -hibernate.connection.username=sa -hibernate.dialect=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb2.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb2.properties deleted file mode 100644 index 626b7853c6..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-database-mydb2.properties +++ /dev/null @@ -1,4 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb2;DB_CLOSE_DELAY=-1 -hibernate.connection.username=sa -hibernate.dialect=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-exception.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-exception.properties deleted file mode 100644 index e08a23166d..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-exception.properties +++ /dev/null @@ -1,16 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:myexceptiondb1;DB_CLOSE_DELAY=-1 -hibernate.connection.username=sa -hibernate.connection.autocommit=true -jdbc.password= - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop - -hibernate.c3p0.min_size=5 -hibernate.c3p0.max_size=20 -hibernate.c3p0.acquire_increment=5 -hibernate.c3p0.timeout=1800 - -hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-namedquery.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-namedquery.properties deleted file mode 100644 index 457f965347..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-namedquery.properties +++ /dev/null @@ -1,9 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'src/main/resources/init_database.sql' -hibernate.connection.username=sa -hibernate.connection.autocommit=true -jdbc.password= - -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties deleted file mode 100644 index 4f1ff5e93a..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-pessimistic-locking.properties +++ /dev/null @@ -1,8 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb3;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=100;MVCC=FALSE -hibernate.connection.username=sa -hibernate.connection.autocommit=true -hibernate.dialect=org.hibernate.dialect.H2Dialect - -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-schema-multitenancy.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-schema-multitenancy.properties deleted file mode 100644 index 4abb621355..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-schema-multitenancy.properties +++ /dev/null @@ -1,7 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS MYDB1\\;CREATE SCHEMA IF NOT EXISTS MYDB2\\; -hibernate.connection.username=sa -hibernate.connection.autocommit=true -hibernate.dialect=org.hibernate.dialect.H2Dialect -hibernate.multiTenancy=SCHEMA -hibernate.multi_tenant_connection_provider=com.baeldung.hibernate.multitenancy.schema.SchemaMultiTenantConnectionProvider \ No newline at end of file diff --git a/persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties b/persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties deleted file mode 100644 index 1657c838e3..0000000000 --- a/persistence-modules/hibernate5/src/test/resources/hibernate-spatial.properties +++ /dev/null @@ -1,14 +0,0 @@ -hibernate.connection.driver_class=org.h2.Driver -hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 -hibernate.connection.username=sa -hibernate.connection.autocommit=true -jdbc.password= - -hibernate.dialect=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect -hibernate.show_sql=true -hibernate.hbm2ddl.auto=create-drop - -hibernate.c3p0.min_size=5 -hibernate.c3p0.max_size=20 -hibernate.c3p0.acquire_increment=5 -hibernate.c3p0.timeout=1800 From 592df829e60a68045e6332f2a74f1a0141c52438 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:19:46 +0530 Subject: [PATCH 027/278] JAVA-4 : added new module hibernate-annotations --- .../hibernate5-annotations/README.md | 10 ++ .../hibernate5-annotations/pom.xml | 74 ++++++++ .../com/baeldung/hibernate/HibernateUtil.java | 73 ++++++++ .../UnsupportedTenancyException.java | 8 + .../hibernate/customtypes/Address.java | 69 +++++++ .../hibernate/customtypes/AddressType.java | 169 ++++++++++++++++++ .../LocalDateStringJavaDescriptor.java | 51 ++++++ .../customtypes/LocalDateStringType.java | 34 ++++ .../hibernate/customtypes/OfficeEmployee.java | 88 +++++++++ .../hibernate/customtypes/PhoneNumber.java | 43 +++++ .../customtypes/PhoneNumberType.java | 98 ++++++++++ .../hibernate/customtypes/Salary.java | 39 ++++ .../customtypes/SalaryCurrencyConvertor.java | 15 ++ .../hibernate/customtypes/SalaryType.java | 161 +++++++++++++++++ .../baeldung/hibernate/joincolumn/Email.java | 47 +++++ .../baeldung/hibernate/joincolumn/Office.java | 41 +++++ .../hibernate/joincolumn/OfficeAddress.java | 34 ++++ .../joincolumn/OfficialEmployee.java | 36 ++++ .../com/baeldung/hibernate/pojo/Phone.java | 50 ++++++ .../main/resources/META-INF/persistence.xml | 18 ++ .../src/main/resources/logback.xml | 13 ++ .../HibernateCustomTypesManualTest.java | 90 ++++++++++ .../joincolumn/JoinColumnIntegrationTest.java | 57 ++++++ .../resources/hibernate-spatial.properties | 14 ++ .../src/test/resources/log4j.xml | 25 +++ .../src/test/resources/log4j2.xml | 18 ++ .../src/test/resources/logback.xml | 18 ++ .../src/test/resources/profile.png | Bin 0 -> 1117 bytes 28 files changed, 1393 insertions(+) create mode 100644 persistence-modules/hibernate5-annotations/README.md create mode 100644 persistence-modules/hibernate5-annotations/pom.xml create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/resources/META-INF/persistence.xml create mode 100644 persistence-modules/hibernate5-annotations/src/main/resources/logback.xml create mode 100644 persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java create mode 100644 persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java create mode 100644 persistence-modules/hibernate5-annotations/src/test/resources/hibernate-spatial.properties create mode 100644 persistence-modules/hibernate5-annotations/src/test/resources/log4j.xml create mode 100644 persistence-modules/hibernate5-annotations/src/test/resources/log4j2.xml create mode 100644 persistence-modules/hibernate5-annotations/src/test/resources/logback.xml create mode 100644 persistence-modules/hibernate5-annotations/src/test/resources/profile.png diff --git a/persistence-modules/hibernate5-annotations/README.md b/persistence-modules/hibernate5-annotations/README.md new file mode 100644 index 0000000000..da3c5ad1fd --- /dev/null +++ b/persistence-modules/hibernate5-annotations/README.md @@ -0,0 +1,10 @@ +## Hibernate 5 + +This module contains articles about Hibernate 5. + +### Relevant Articles: +- [Custom Types in Hibernate and the @Type Annotation](https://www.baeldung.com/hibernate-custom-types) +- [@Immutable in Hibernate](http://www.baeldung.com/hibernate-immutable) +- [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column) +- [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby) + diff --git a/persistence-modules/hibernate5-annotations/pom.xml b/persistence-modules/hibernate5-annotations/pom.xml new file mode 100644 index 0000000000..ab242333fe --- /dev/null +++ b/persistence-modules/hibernate5-annotations/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + hibernate5-annotations + 0.1-SNAPSHOT + hibernate5-annotations + jar + Hibernate tutorial illustrating the use of named parameters + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + org.hibernate + hibernate-core + ${hibernate-core.version} + + + + com.h2database + h2 + ${h2.version} + + + + org.apache.commons + commons-lang3 + ${commons.lang3.version} + + + + org.hibernate + hibernate-testing + ${hibernate-core.version} + + + + org.hibernate + hibernate-spatial + ${hibernate-core.version} + + + org.opengeo + geodb + ${geodb.version} + + + + + + geodb-repo + GeoDB repository + http://repo.boundlessgeo.com/main/ + + + + + 5.4.7.Final + 1.4.200 + 3.8.1 + true + 2.1.7.RELEASE + 5.4.7.Final + 1.4.200 + 3.8.1 + 0.9 + + + diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java new file mode 100644 index 0000000000..afe2aeac89 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -0,0 +1,73 @@ +package com.baeldung.hibernate; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.joincolumn.Email; +import com.baeldung.hibernate.joincolumn.Office; +import com.baeldung.hibernate.joincolumn.OfficeAddress; + +public class HibernateUtil { + private static String PROPERTY_FILE_NAME; + + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(null); + } + + public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { + PROPERTY_FILE_NAME = propertyFileName; + ServiceRegistry serviceRegistry = configureServiceRegistry(); + return makeSessionFactory(serviceRegistry); + } + + public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException { + ServiceRegistry serviceRegistry = configureServiceRegistry(properties); + return makeSessionFactory(serviceRegistry); + } + + private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + metadataSources.addPackage("com.baeldung.hibernate.pojo"); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.joincolumn.OfficialEmployee.class); + metadataSources.addAnnotatedClass(Email.class); + metadataSources.addAnnotatedClass(Office.class); + metadataSources.addAnnotatedClass(OfficeAddress.class); + + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + + } + + private static ServiceRegistry configureServiceRegistry() throws IOException { + return configureServiceRegistry(getProperties()); + } + + private static ServiceRegistry configureServiceRegistry(Properties properties) throws IOException { + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + public static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java new file mode 100644 index 0000000000..99d9505ea3 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java @@ -0,0 +1,8 @@ +package com.baeldung.hibernate; + +public class UnsupportedTenancyException extends Exception { + public UnsupportedTenancyException (String message) { + super(message); + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java new file mode 100644 index 0000000000..d559e5a6c2 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java @@ -0,0 +1,69 @@ +package com.baeldung.hibernate.customtypes; + +import java.util.Objects; + +public class Address { + + private String addressLine1; + private String addressLine2; + private String city; + private String country; + private int zipCode; + + public String getAddressLine1() { + return addressLine1; + } + + public String getAddressLine2() { + return addressLine2; + } + + public String getCity() { + return city; + } + + public String getCountry() { + return country; + } + + public int getZipCode() { + return zipCode; + } + + public void setAddressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + } + + public void setAddressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + } + + public void setCity(String city) { + this.city = city; + } + + public void setCountry(String country) { + this.country = country; + } + + public void setZipCode(int zipCode) { + this.zipCode = zipCode; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Address address = (Address) o; + return zipCode == address.zipCode && + Objects.equals(addressLine1, address.addressLine1) && + Objects.equals(addressLine2, address.addressLine2) && + Objects.equals(city, address.city) && + Objects.equals(country, address.country); + } + + @Override + public int hashCode() { + return Objects.hash(addressLine1, addressLine2, city, country, zipCode); + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java new file mode 100644 index 0000000000..c10c67df9a --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java @@ -0,0 +1,169 @@ +package com.baeldung.hibernate.customtypes; + +import org.hibernate.HibernateException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.type.IntegerType; +import org.hibernate.type.StringType; +import org.hibernate.type.Type; +import org.hibernate.usertype.CompositeUserType; + +import java.io.Serializable; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Objects; + +public class AddressType implements CompositeUserType { + + @Override + public String[] getPropertyNames() { + return new String[]{"addressLine1", "addressLine2", + "city", "country", "zipcode"}; + } + + @Override + public Type[] getPropertyTypes() { + return new Type[]{StringType.INSTANCE, StringType.INSTANCE, + StringType.INSTANCE, StringType.INSTANCE, IntegerType.INSTANCE}; + } + + @Override + public Object getPropertyValue(Object component, int property) throws HibernateException { + + Address empAdd = (Address) component; + + switch (property) { + case 0: + return empAdd.getAddressLine1(); + case 1: + return empAdd.getAddressLine2(); + case 2: + return empAdd.getCity(); + case 3: + return empAdd.getCountry(); + case 4: + return Integer.valueOf(empAdd.getZipCode()); + } + + throw new IllegalArgumentException(property + + " is an invalid property index for class type " + + component.getClass().getName()); + } + + @Override + public void setPropertyValue(Object component, int property, Object value) throws HibernateException { + + Address empAdd = (Address) component; + + switch (property) { + case 0: + empAdd.setAddressLine1((String) value); + case 1: + empAdd.setAddressLine2((String) value); + case 2: + empAdd.setCity((String) value); + case 3: + empAdd.setCountry((String) value); + case 4: + empAdd.setZipCode((Integer) value); + } + + throw new IllegalArgumentException(property + + " is an invalid property index for class type " + + component.getClass().getName()); + + } + + @Override + public Class returnedClass() { + return Address.class; + } + + @Override + public boolean equals(Object x, Object y) throws HibernateException { + if (x == y) + return true; + + if (Objects.isNull(x) || Objects.isNull(y)) + return false; + + return x.equals(y); + } + + @Override + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); + } + + @Override + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { + + Address empAdd = new Address(); + empAdd.setAddressLine1(rs.getString(names[0])); + + if (rs.wasNull()) + return null; + + empAdd.setAddressLine2(rs.getString(names[1])); + empAdd.setCity(rs.getString(names[2])); + empAdd.setCountry(rs.getString(names[3])); + empAdd.setZipCode(rs.getInt(names[4])); + + return empAdd; + } + + @Override + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { + + if (Objects.isNull(value)) + st.setNull(index, Types.VARCHAR); + else { + + Address empAdd = (Address) value; + st.setString(index, empAdd.getAddressLine1()); + st.setString(index + 1, empAdd.getAddressLine2()); + st.setString(index + 2, empAdd.getCity()); + st.setString(index + 3, empAdd.getCountry()); + st.setInt(index + 4, empAdd.getZipCode()); + } + } + + @Override + public Object deepCopy(Object value) throws HibernateException { + + if (Objects.isNull(value)) + return null; + + Address oldEmpAdd = (Address) value; + Address newEmpAdd = new Address(); + + newEmpAdd.setAddressLine1(oldEmpAdd.getAddressLine1()); + newEmpAdd.setAddressLine2(oldEmpAdd.getAddressLine2()); + newEmpAdd.setCity(oldEmpAdd.getCity()); + newEmpAdd.setCountry(oldEmpAdd.getCountry()); + newEmpAdd.setZipCode(oldEmpAdd.getZipCode()); + + return newEmpAdd; + } + + @Override + public boolean isMutable() { + return true; + } + + @Override + public Serializable disassemble(Object value, SharedSessionContractImplementor session) throws HibernateException { + return (Serializable) deepCopy(value); + } + + @Override + public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) throws HibernateException { + return deepCopy(cached); + } + + @Override + public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner) throws HibernateException { + return original; + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java new file mode 100644 index 0000000000..56be9e693f --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.customtypes; + +import org.hibernate.type.LocalDateType; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.java.AbstractTypeDescriptor; +import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan; +import org.hibernate.type.descriptor.java.MutabilityPlan; + +import java.time.LocalDate; + +public class LocalDateStringJavaDescriptor extends AbstractTypeDescriptor { + + public static final LocalDateStringJavaDescriptor INSTANCE = new LocalDateStringJavaDescriptor(); + + public LocalDateStringJavaDescriptor() { + super(LocalDate.class, ImmutableMutabilityPlan.INSTANCE); + } + + @Override + public String toString(LocalDate value) { + return LocalDateType.FORMATTER.format(value); + } + + @Override + public LocalDate fromString(String string) { + return LocalDate.from(LocalDateType.FORMATTER.parse(string)); + } + + @Override + public X unwrap(LocalDate value, Class type, WrapperOptions options) { + + if (value == null) + return null; + + if (String.class.isAssignableFrom(type)) + return (X) LocalDateType.FORMATTER.format(value); + + throw unknownUnwrap(type); + } + + @Override + public LocalDate wrap(X value, WrapperOptions options) { + if (value == null) + return null; + + if(String.class.isInstance(value)) + return LocalDate.from(LocalDateType.FORMATTER.parse((CharSequence) value)); + + throw unknownWrap(value.getClass()); + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java new file mode 100644 index 0000000000..c8d37073e8 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.customtypes; + +import org.hibernate.dialect.Dialect; +import org.hibernate.type.AbstractSingleColumnStandardBasicType; +import org.hibernate.type.DiscriminatorType; +import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor; +import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; + +import java.time.LocalDate; + +public class LocalDateStringType extends AbstractSingleColumnStandardBasicType implements DiscriminatorType { + + public static final LocalDateStringType INSTANCE = new LocalDateStringType(); + + public LocalDateStringType() { + super(VarcharTypeDescriptor.INSTANCE, LocalDateStringJavaDescriptor.INSTANCE); + } + + @Override + public String getName() { + return "LocalDateString"; + } + + @Override + public LocalDate stringToObject(String xml) throws Exception { + return fromString(xml); + } + + @Override + public String objectToSQLString(LocalDate value, Dialect dialect) throws Exception { + return '\'' + toString(value) + '\''; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java new file mode 100644 index 0000000000..3ca06e4316 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java @@ -0,0 +1,88 @@ +package com.baeldung.hibernate.customtypes; + +import com.baeldung.hibernate.pojo.Phone; +import org.hibernate.annotations.Columns; +import org.hibernate.annotations.Parameter; +import org.hibernate.annotations.Type; +import org.hibernate.annotations.TypeDef; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; +import java.time.LocalDate; + +@TypeDef(name = "PhoneNumber", + typeClass = PhoneNumberType.class, + defaultForType = PhoneNumber.class) +@Entity +@Table(name = "OfficeEmployee") +public class OfficeEmployee { + + @Id + @GeneratedValue + private long id; + + @Column + @Type(type = "LocalDateString") + private LocalDate dateOfJoining; + + @Columns(columns = {@Column(name = "country_code"), + @Column(name = "city_code"), + @Column(name = "number")}) + private PhoneNumber employeeNumber; + + @Columns(columns = {@Column(name = "address_line_1"), + @Column(name = "address_line_2"), + @Column(name = "city"), @Column(name = "country"), + @Column(name = "zip_code")}) + @Type(type = "com.baeldung.hibernate.customtypes.AddressType") + private Address empAddress; + + @Type(type = "com.baeldung.hibernate.customtypes.SalaryType", + parameters = {@Parameter(name = "currency", value = "USD")}) + @Columns(columns = {@Column(name = "amount"), + @Column(name = "currency")}) + private Salary salary; + + public Salary getSalary() { + return salary; + } + + public void setSalary(Salary salary) { + this.salary = salary; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public LocalDate getDateOfJoining() { + return dateOfJoining; + } + + public void setDateOfJoining(LocalDate dateOfJoining) { + this.dateOfJoining = dateOfJoining; + } + + public PhoneNumber getEmployeeNumber() { + return employeeNumber; + } + + public void setEmployeeNumber(PhoneNumber employeeNumber) { + this.employeeNumber = employeeNumber; + } + + public Address getEmpAddress() { + return empAddress; + } + + public void setEmpAddress(Address empAddress) { + this.empAddress = empAddress; + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java new file mode 100644 index 0000000000..0be6cbc910 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java @@ -0,0 +1,43 @@ +package com.baeldung.hibernate.customtypes; + +import java.util.Objects; + +public final class PhoneNumber { + + private final int countryCode; + private final int cityCode; + private final int number; + + public PhoneNumber(int countryCode, int cityCode, int number) { + this.countryCode = countryCode; + this.cityCode = cityCode; + this.number = number; + } + + public int getCountryCode() { + return countryCode; + } + + public int getCityCode() { + return cityCode; + } + + public int getNumber() { + return number; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + PhoneNumber that = (PhoneNumber) o; + return countryCode == that.countryCode && + cityCode == that.cityCode && + number == that.number; + } + + @Override + public int hashCode() { + return Objects.hash(countryCode, cityCode, number); + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java new file mode 100644 index 0000000000..9f09352bec --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java @@ -0,0 +1,98 @@ +package com.baeldung.hibernate.customtypes; + +import org.hibernate.HibernateException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.usertype.UserType; + +import java.io.Serializable; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Objects; + + +public class PhoneNumberType implements UserType { + @Override + public int[] sqlTypes() { + return new int[]{Types.INTEGER, Types.INTEGER, Types.INTEGER}; + } + + @Override + public Class returnedClass() { + return PhoneNumber.class; + } + + @Override + public boolean equals(Object x, Object y) throws HibernateException { + if (x == y) + return true; + if (Objects.isNull(x) || Objects.isNull(y)) + return false; + + return x.equals(y); + } + + @Override + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); + } + + @Override + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { + int countryCode = rs.getInt(names[0]); + + if (rs.wasNull()) + return null; + + int cityCode = rs.getInt(names[1]); + int number = rs.getInt(names[2]); + PhoneNumber employeeNumber = new PhoneNumber(countryCode, cityCode, number); + + return employeeNumber; + } + + @Override + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { + + if (Objects.isNull(value)) { + st.setNull(index, Types.INTEGER); + } else { + PhoneNumber employeeNumber = (PhoneNumber) value; + st.setInt(index,employeeNumber.getCountryCode()); + st.setInt(index+1,employeeNumber.getCityCode()); + st.setInt(index+2,employeeNumber.getNumber()); + } + } + + @Override + public Object deepCopy(Object value) throws HibernateException { + if (Objects.isNull(value)) + return null; + + PhoneNumber empNumber = (PhoneNumber) value; + PhoneNumber newEmpNumber = new PhoneNumber(empNumber.getCountryCode(),empNumber.getCityCode(),empNumber.getNumber()); + + return newEmpNumber; + } + + @Override + public boolean isMutable() { + return false; + } + + @Override + public Serializable disassemble(Object value) throws HibernateException { + return (Serializable) value; + } + + @Override + public Object assemble(Serializable cached, Object owner) throws HibernateException { + return cached; + } + + @Override + public Object replace(Object original, Object target, Object owner) throws HibernateException { + return original; + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java new file mode 100644 index 0000000000..f9a7ac5902 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java @@ -0,0 +1,39 @@ +package com.baeldung.hibernate.customtypes; + +import java.util.Objects; + +public class Salary { + + private Long amount; + private String currency; + + public Long getAmount() { + return amount; + } + + public void setAmount(Long amount) { + this.amount = amount; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Salary salary = (Salary) o; + return Objects.equals(amount, salary.amount) && + Objects.equals(currency, salary.currency); + } + + @Override + public int hashCode() { + return Objects.hash(amount, currency); + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java new file mode 100644 index 0000000000..340c697c11 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java @@ -0,0 +1,15 @@ +package com.baeldung.hibernate.customtypes; + +public class SalaryCurrencyConvertor { + + public static Long convert(Long amount, String oldCurr, String newCurr){ + if (newCurr.equalsIgnoreCase(oldCurr)) + return amount; + + return convertTo(); + } + + private static Long convertTo() { + return 10L; + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java new file mode 100644 index 0000000000..266b85140b --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java @@ -0,0 +1,161 @@ +package com.baeldung.hibernate.customtypes; + +import org.hibernate.HibernateException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.type.LongType; +import org.hibernate.type.StringType; +import org.hibernate.type.Type; +import org.hibernate.usertype.CompositeUserType; +import org.hibernate.usertype.DynamicParameterizedType; + +import java.io.Serializable; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Types; +import java.util.Objects; +import java.util.Properties; + +public class SalaryType implements CompositeUserType, DynamicParameterizedType { + + private String localCurrency; + + @Override + public String[] getPropertyNames() { + return new String[]{"amount", "currency"}; + } + + @Override + public Type[] getPropertyTypes() { + return new Type[]{LongType.INSTANCE, StringType.INSTANCE}; + } + + @Override + public Object getPropertyValue(Object component, int property) throws HibernateException { + + Salary salary = (Salary) component; + + switch (property) { + case 0: + return salary.getAmount(); + case 1: + return salary.getCurrency(); + } + + throw new IllegalArgumentException(property + + " is an invalid property index for class type " + + component.getClass().getName()); + + } + + + @Override + public void setPropertyValue(Object component, int property, Object value) throws HibernateException { + + Salary salary = (Salary) component; + + switch (property) { + case 0: + salary.setAmount((Long) value); + case 1: + salary.setCurrency((String) value); + } + + throw new IllegalArgumentException(property + + " is an invalid property index for class type " + + component.getClass().getName()); + + } + + @Override + public Class returnedClass() { + return Salary.class; + } + + @Override + public boolean equals(Object x, Object y) throws HibernateException { + + if (x == y) + return true; + + if (Objects.isNull(x) || Objects.isNull(y)) + return false; + + return x.equals(y); + + } + + @Override + public int hashCode(Object x) throws HibernateException { + return x.hashCode(); + } + + @Override + public Object nullSafeGet(ResultSet rs, String[] names, SharedSessionContractImplementor session, Object owner) throws HibernateException, SQLException { + + Salary salary = new Salary(); + salary.setAmount(rs.getLong(names[0])); + + if (rs.wasNull()) + return null; + + salary.setCurrency(rs.getString(names[1])); + + return salary; + } + + @Override + public void nullSafeSet(PreparedStatement st, Object value, int index, SharedSessionContractImplementor session) throws HibernateException, SQLException { + + + if (Objects.isNull(value)) + st.setNull(index, Types.BIGINT); + else { + + Salary salary = (Salary) value; + st.setLong(index, SalaryCurrencyConvertor.convert(salary.getAmount(), + salary.getCurrency(), localCurrency)); + st.setString(index + 1, salary.getCurrency()); + } + } + + @Override + public Object deepCopy(Object value) throws HibernateException { + + if (Objects.isNull(value)) + return null; + + Salary oldSal = (Salary) value; + Salary newSal = new Salary(); + + newSal.setAmount(oldSal.getAmount()); + newSal.setCurrency(oldSal.getCurrency()); + + return newSal; + } + + @Override + public boolean isMutable() { + return true; + } + + @Override + public Serializable disassemble(Object value, SharedSessionContractImplementor session) throws HibernateException { + return (Serializable) deepCopy(value); + } + + @Override + public Object assemble(Serializable cached, SharedSessionContractImplementor session, Object owner) throws HibernateException { + return deepCopy(cached); + } + + @Override + public Object replace(Object original, Object target, SharedSessionContractImplementor session, Object owner) throws HibernateException { + return original; + } + + @Override + public void setParameterValues(Properties parameters) { + this.localCurrency = parameters.getProperty("currency"); + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java new file mode 100644 index 0000000000..df07c3cf69 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java @@ -0,0 +1,47 @@ +package com.baeldung.hibernate.joincolumn; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; + +@Entity +public class Email { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + private String address; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "employee_id") + private OfficialEmployee employee; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public OfficialEmployee getEmployee() { + return employee; + } + + public void setEmployee(OfficialEmployee employee) { + this.employee = employee; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java new file mode 100644 index 0000000000..9940577761 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java @@ -0,0 +1,41 @@ +package com.baeldung.hibernate.joincolumn; + +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinColumns; +import javax.persistence.ManyToOne; + +@Entity +public class Office { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumns({ + @JoinColumn(name="ADDR_ID", referencedColumnName="ID"), + @JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP") + }) + private OfficeAddress address; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public OfficeAddress getAddress() { + return address; + } + + public void setAddress(OfficeAddress address) { + this.address = address; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java new file mode 100644 index 0000000000..cc723db6a2 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.joincolumn; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class OfficeAddress { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @Column(name = "ZIP") + private String zipCode; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getZipCode() { + return zipCode; + } + + public void setZipCode(String zipCode) { + this.zipCode = zipCode; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java new file mode 100644 index 0000000000..49c63c7578 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java @@ -0,0 +1,36 @@ +package com.baeldung.hibernate.joincolumn; + +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.FetchType; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class OfficialEmployee { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private Long id; + + @OneToMany(fetch = FetchType.LAZY, mappedBy = "employee") + private List emails; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public List getEmails() { + return emails; + } + + public void setEmails(List emails) { + this.emails = emails; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java new file mode 100644 index 0000000000..d923bda5de --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java @@ -0,0 +1,50 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.io.Serializable; + +@Entity +public class Phone implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private boolean deleted; + + private String number; + + public Phone() { + } + + public Phone(String number) { + this.number = number; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public boolean isDeleted() { + return deleted; + } + + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate5-annotations/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..474eeb7a44 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,18 @@ + + + + Hibernate EntityManager Demo + true + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/main/resources/logback.xml b/persistence-modules/hibernate5-annotations/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java new file mode 100644 index 0000000000..63dc6330be --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java @@ -0,0 +1,90 @@ +package com.baeldung.hibernate.customtypes; + +import com.baeldung.hibernate.HibernateUtil; +import org.hibernate.SessionFactory; +import org.hibernate.query.Query; +import org.junit.Assert; +import org.junit.Test; + +import java.io.IOException; +import java.time.LocalDate; + +import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate; + +public class HibernateCustomTypesManualTest { + + @Test + public void givenEmployee_whenSavedWithCustomTypes_thenEntityIsSaved() throws IOException { + + final OfficeEmployee e = new OfficeEmployee(); + e.setDateOfJoining(LocalDate.now()); + + PhoneNumber number = new PhoneNumber(1, 222, 8781902); + e.setEmployeeNumber(number); + + Address empAdd = new Address(); + empAdd.setAddressLine1("Street"); + empAdd.setAddressLine2("Area"); + empAdd.setCity("City"); + empAdd.setCountry("Country"); + empAdd.setZipCode(100); + + e.setEmpAddress(empAdd); + + Salary empSalary = new Salary(); + empSalary.setAmount(1000L); + empSalary.setCurrency("USD"); + e.setSalary(empSalary); + + doInHibernate(this::sessionFactory, session -> { + session.save(e); + boolean contains = session.contains(e); + Assert.assertTrue(contains); + }); + + } + + @Test + public void givenEmployee_whenCustomTypeInQuery_thenReturnEntity() throws IOException { + + final OfficeEmployee e = new OfficeEmployee(); + e.setDateOfJoining(LocalDate.now()); + + PhoneNumber number = new PhoneNumber(1, 222, 8781902); + e.setEmployeeNumber(number); + + Address empAdd = new Address(); + empAdd.setAddressLine1("Street"); + empAdd.setAddressLine2("Area"); + empAdd.setCity("City"); + empAdd.setCountry("Country"); + empAdd.setZipCode(100); + e.setEmpAddress(empAdd); + + Salary empSalary = new Salary(); + empSalary.setAmount(1000L); + empSalary.setCurrency("USD"); + e.setSalary(empSalary); + + doInHibernate(this::sessionFactory, session -> { + session.save(e); + + Query query = session.createQuery("FROM OfficeEmployee OE WHERE OE.empAddress.zipcode = :pinCode"); + query.setParameter("pinCode",100); + int size = query.list().size(); + + Assert.assertEquals(1, size); + }); + + } + + private SessionFactory sessionFactory() { + try { + return HibernateUtil.getSessionFactory("hibernate-customtypes.properties"); + } catch (IOException e) { + e.printStackTrace(); + } + + return null; + } +} diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java new file mode 100644 index 0000000000..0998ff1d90 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java @@ -0,0 +1,57 @@ +package com.baeldung.hibernate.joincolumn; + +import com.baeldung.hibernate.HibernateUtil; +import java.io.IOException; +import org.hibernate.Session; +import org.hibernate.Transaction; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + + +public class JoinColumnIntegrationTest { + + private Session session; + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory("hibernate-spatial.properties") + .openSession(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenOfficeEntity_setAddress_shouldPersist() { + Office office = new Office(); + + OfficeAddress address = new OfficeAddress(); + address.setZipCode("11-111"); + office.setAddress(address); + + session.save(office); + session.flush(); + session.clear(); + } + + @Test + public void givenEmployeeEntity_setEmails_shouldPersist() { + OfficialEmployee employee = new OfficialEmployee(); + + Email email = new Email(); + email.setAddress("example@email.com"); + email.setEmployee(employee); + + session.save(employee); + session.flush(); + session.clear(); + } + +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/hibernate-spatial.properties b/persistence-modules/hibernate5-annotations/src/test/resources/hibernate-spatial.properties new file mode 100644 index 0000000000..1657c838e3 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/resources/hibernate-spatial.properties @@ -0,0 +1,14 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/log4j.xml b/persistence-modules/hibernate5-annotations/src/test/resources/log4j.xml new file mode 100644 index 0000000000..2d153af124 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/resources/log4j.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/log4j2.xml b/persistence-modules/hibernate5-annotations/src/test/resources/log4j2.xml new file mode 100644 index 0000000000..c5d0f12462 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/resources/log4j2.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/logback.xml b/persistence-modules/hibernate5-annotations/src/test/resources/logback.xml new file mode 100644 index 0000000000..9e591977d7 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/resources/logback.xml @@ -0,0 +1,18 @@ + + + + + + %d{yyyy-MM-dd HH:mm:ss} | %-5p | [%thread] %logger{5}:%L - %msg%n + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/profile.png b/persistence-modules/hibernate5-annotations/src/test/resources/profile.png new file mode 100644 index 0000000000000000000000000000000000000000..1cd4e978b96d0f59a6e48692fcb68d1c6c565a20 GIT binary patch literal 1117 zcmV-j1fu(iP)%yyh@V&OYl(_AFwE`D&8)` zPnvkdvc#Z>pRh2kBHk{=qaGfCG;?<;rVe;D+%LyZS~!K}c+|op81YK@rzPHU@Th|m z4Dk`HcojTY;+}_-W%HGqKH@C!LiH8Tp>1lC@aTqoy zBU~QK<}hs@q|M8($ee`o<9#`B3-PL4Y7d9kW#<;n>t}6VNpYCswLrJTtEa_lFwgN$52-_vxvvfJs@B6-OYs%-@M_JTx*UfozG6(Bhs)>w z!pG%vU$b%f++EGa<#Tu1FZ^c#{;G|y5=kM3Y#X^mtSrFA_-o-vX7e_$5-udx(>S4U)i|4)(UJ~zR(vwE+6VTAzoo7wIS|c zh*yt`3wK%<+yX~Z9G1z2GQgf3~qx jc9u$WjpqGof00000NkvXXu0mjfJX<<= literal 0 HcmV?d00001 From 074dd3e986f44ebc0100103b381c64ee8d8c8bed Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:20:04 +0530 Subject: [PATCH 028/278] JAVA-4 : added new module hibernate-enterprise --- .../hibernate5-enterprise/README.md | 13 + .../hibernate5-enterprise/pom.xml | 76 ++++ .../com/baeldung/hibernate/HibernateUtil.java | 72 +++ .../UnsupportedTenancyException.java | 8 + .../hibernate/exception/EntityWithNoId.java | 16 + .../hibernate/exception/HibernateUtil.java | 63 +++ .../baeldung/hibernate/exception/Product.java | 40 ++ .../baeldung/hibernate/logging/Employee.java | 59 +++ .../baeldung/hibernate/pojo/PointEntity.java | 43 ++ .../hibernate/pojo/PolygonEntity.java | 38 ++ .../com/baeldung/hibernate/pojo/Student.java | 51 +++ .../baeldung/hibernateparameters/Event.java | 30 ++ .../main/resources/META-INF/persistence.xml | 18 + .../hibernateparameters/Event.hbm.xml | 15 + .../main/resources/hibernate-logging.cfg.xml | 27 ++ .../src/main/resources/hibernate.cfg.xml | 28 ++ .../src/main/resources/init_database.sql | 10 + .../src/main/resources/logback.xml | 13 + .../HibernateSpatialIntegrationTest.java | 161 +++++++ .../AggregateFunctionsIntegrationTest.java | 87 ++++ .../exception/HibernateExceptionUnitTest.java | 425 ++++++++++++++++++ .../HibernateLoggingIntegrationTest.java | 50 +++ .../baeldung/hibernate/multitenancy/Car.java | 26 ++ .../MultitenancyIntegrationTest.java | 104 +++++ ...seApproachMultitenancyIntegrationTest.java | 25 ++ .../MapMultiTenantConnectionProvider.java | 42 ++ .../multitenancy/database/TenantIdNames.java | 6 + ...maApproachMultitenancyIntegrationTest.java | 26 ++ .../SchemaMultiTenantConnectionProvider.java | 48 ++ .../multitenancy/schema/TenantIdNames.java | 6 + .../NamedParameterUnitTest.java | 73 +++ ...hibernate-database-multitenancy.properties | 2 + .../hibernate-database-mydb1.properties | 4 + .../hibernate-database-mydb2.properties | 4 + .../resources/hibernate-exception.properties | 16 + .../hibernate-schema-multitenancy.properties | 7 + .../resources/hibernate-spatial.properties | 14 + .../src/test/resources/hibernate.properties | 14 + .../src/test/resources/lifecycle-init.sql | 25 ++ .../src/test/resources/profile.png | Bin 0 -> 1117 bytes 40 files changed, 1785 insertions(+) create mode 100644 persistence-modules/hibernate5-enterprise/README.md create mode 100644 persistence-modules/hibernate5-enterprise/pom.xml create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java create mode 100644 persistence-modules/hibernate5-enterprise/src/main/resources/META-INF/persistence.xml create mode 100644 persistence-modules/hibernate5-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml create mode 100644 persistence-modules/hibernate5-enterprise/src/main/resources/hibernate-logging.cfg.xml create mode 100644 persistence-modules/hibernate5-enterprise/src/main/resources/hibernate.cfg.xml create mode 100644 persistence-modules/hibernate5-enterprise/src/main/resources/init_database.sql create mode 100644 persistence-modules/hibernate5-enterprise/src/main/resources/logback.xml create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-multitenancy.properties create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb1.properties create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb2.properties create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-exception.properties create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-schema-multitenancy.properties create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-spatial.properties create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/hibernate.properties create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/lifecycle-init.sql create mode 100644 persistence-modules/hibernate5-enterprise/src/test/resources/profile.png diff --git a/persistence-modules/hibernate5-enterprise/README.md b/persistence-modules/hibernate5-enterprise/README.md new file mode 100644 index 0000000000..994d8f062a --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/README.md @@ -0,0 +1,13 @@ +## Hibernate 5 + +This module contains articles about Hibernate 5. + +### Relevant articles: + +- [Introduction to Hibernate Spatial](http://www.baeldung.com/hibernate-spatial) +- [A Guide to Multitenancy in Hibernate 5](http://www.baeldung.com/hibernate-5-multitenancy) +- [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions) +- [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions) +- [Hibernate Error “Not all named parameters have been set”](https://www.baeldung.com/hibernate-error-named-parameters-not-set) +- [FetchMode in Hibernate](https://www.baeldung.com/hibernate-fetchmode) +- [Various Logging Levels in Hibernate](https://www.baeldung.com/hibernate-logging-levels) \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/pom.xml b/persistence-modules/hibernate5-enterprise/pom.xml new file mode 100644 index 0000000000..f12bb7e081 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + hibernate5-enterprise + 0.0.1-SNAPSHOT + hibernate5-enterprise + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + com.h2database + h2 + ${h2.version} + + + org.hibernate + hibernate-spatial + ${hibernate.version} + + + org.opengeo + geodb + ${geodb.version} + + + mysql + mysql-connector-java + ${mysql.version} + + + ch.vorburger.mariaDB4j + mariaDB4j + ${mariaDB4j.version} + + + org.hibernate + hibernate-testing + ${hibernate.version} + + + + + + geodb-repo + GeoDB repository + http://repo.boundlessgeo.com/main/ + + + + + 5.3.7.Final + 6.0.6 + 2.2.3 + 3.8.0 + 0.9 + + + diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java new file mode 100644 index 0000000000..ddeb1c42ea --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -0,0 +1,72 @@ +package com.baeldung.hibernate; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.pojo.PointEntity; +import com.baeldung.hibernate.pojo.PolygonEntity; +import com.baeldung.hibernate.pojo.Student; + +public class HibernateUtil { + private static String PROPERTY_FILE_NAME; + + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(null); + } + + public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { + PROPERTY_FILE_NAME = propertyFileName; + ServiceRegistry serviceRegistry = configureServiceRegistry(); + return makeSessionFactory(serviceRegistry); + } + + public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException { + ServiceRegistry serviceRegistry = configureServiceRegistry(properties); + return makeSessionFactory(serviceRegistry); + } + + private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + metadataSources.addPackage("com.baeldung.hibernate.pojo"); + metadataSources.addAnnotatedClass(Student.class); + metadataSources.addAnnotatedClass(PointEntity.class); + metadataSources.addAnnotatedClass(PolygonEntity.class); + + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + + } + + private static ServiceRegistry configureServiceRegistry() throws IOException { + return configureServiceRegistry(getProperties()); + } + + private static ServiceRegistry configureServiceRegistry(Properties properties) throws IOException { + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + public static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java new file mode 100644 index 0000000000..99d9505ea3 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java @@ -0,0 +1,8 @@ +package com.baeldung.hibernate; + +public class UnsupportedTenancyException extends Exception { + public UnsupportedTenancyException (String message) { + super(message); + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java new file mode 100644 index 0000000000..989fa1281a --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java @@ -0,0 +1,16 @@ +package com.baeldung.hibernate.exception; + +import javax.persistence.Entity; + +@Entity +public class EntityWithNoId { + private int id; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java new file mode 100644 index 0000000000..ae5174ac9c --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java @@ -0,0 +1,63 @@ +package com.baeldung.hibernate.exception; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + private static String PROPERTY_FILE_NAME; + + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(null); + } + + public static SessionFactory getSessionFactory(String propertyFileName) + throws IOException { + PROPERTY_FILE_NAME = propertyFileName; + if (sessionFactory == null) { + ServiceRegistry serviceRegistry = configureServiceRegistry(); + sessionFactory = makeSessionFactory(serviceRegistry); + } + return sessionFactory; + } + + private static SessionFactory makeSessionFactory( + ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + metadataSources.addAnnotatedClass(Product.class); + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + return metadata.getSessionFactoryBuilder() + .build(); + + } + + private static ServiceRegistry configureServiceRegistry() + throws IOException { + Properties properties = getProperties(); + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + private static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, + "hibernate-exception.properties")); + try (FileInputStream inputStream = new FileInputStream( + propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java new file mode 100644 index 0000000000..031fa38de0 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java @@ -0,0 +1,40 @@ +package com.baeldung.hibernate.exception; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Product { + + private int id; + + private String name; + private String description; + + @Id + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + @Column(nullable=false) + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java new file mode 100644 index 0000000000..9dcf4058a7 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java @@ -0,0 +1,59 @@ +package com.baeldung.hibernate.logging; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Employee { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String employeeNumber; + + private String title; + + private String name; + + public Employee() { + } + + public Employee(String name, String employeeNumber) { + this.name = name; + this.employeeNumber = employeeNumber; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getEmployeeNumber() { + return employeeNumber; + } + + public void setEmployeeNumber(String employeeNumber) { + this.employeeNumber = employeeNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java new file mode 100644 index 0000000000..736abde866 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java @@ -0,0 +1,43 @@ +package com.baeldung.hibernate.pojo; + +import com.vividsolutions.jts.geom.Point; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class PointEntity { + + @Id + @GeneratedValue + private Long id; + + @Column(columnDefinition="BINARY(2048)") + private Point point; + + public PointEntity() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Point getPoint() { + return point; + } + + public void setPoint(Point point) { + this.point = point; + } + + @Override + public String toString() { + return "PointEntity{" + "id=" + id + ", point=" + point + '}'; + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java new file mode 100644 index 0000000000..69208c8cd4 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java @@ -0,0 +1,38 @@ +package com.baeldung.hibernate.pojo; + +import com.vividsolutions.jts.geom.Polygon; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +@Entity +public class PolygonEntity { + + @Id + @GeneratedValue + private Long id; + + private Polygon polygon; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Polygon getPolygon() { + return polygon; + } + + public void setPolygon(Polygon polygon) { + this.polygon = polygon; + } + + @Override + public String toString() { + return "PolygonEntity{" + "id=" + id + ", polygon=" + polygon + '}'; + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java new file mode 100644 index 0000000000..9b26c117eb --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long studentId; + + private String name; + + private int age; + + public Student() { + } + + public Student(String name, int age) { + this.name = name; + this.age = age; + } + + public long getStudentId() { + return studentId; + } + + public void setStudentId(long studentId) { + this.studentId = studentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java new file mode 100644 index 0000000000..7912659a09 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java @@ -0,0 +1,30 @@ +package com.baeldung.hibernateparameters; + +public class Event { + private Long id; + + private String title; + + public Event() { + } + + public Event(String title) { + this.title = title; + } + + public Long getId() { + return id; + } + + private void setId(Long id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate5-enterprise/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..474eeb7a44 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,18 @@ + + + + Hibernate EntityManager Demo + true + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml b/persistence-modules/hibernate5-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml new file mode 100644 index 0000000000..c485080879 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate-logging.cfg.xml b/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate-logging.cfg.xml new file mode 100644 index 0000000000..52ef1ee685 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate-logging.cfg.xml @@ -0,0 +1,27 @@ + + + + + + + org.h2.Driver + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 + sa + + + 1 + + org.hibernate.dialect.H2Dialect + + org.hibernate.cache.internal.NoCacheProvider + + true + + create + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate.cfg.xml b/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate.cfg.xml new file mode 100644 index 0000000000..be564aaf5a --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate.cfg.xml @@ -0,0 +1,28 @@ + + + + + + + org.h2.Driver + jdbc:h2:mem:db1;DB_CLOSE_DELAY=-1 + sa + + + 1 + + org.hibernate.dialect.H2Dialect + + org.hibernate.cache.internal.NoCacheProvider + + true + + create + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/init_database.sql b/persistence-modules/hibernate5-enterprise/src/main/resources/init_database.sql new file mode 100644 index 0000000000..b2848aa256 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/resources/init_database.sql @@ -0,0 +1,10 @@ +CREATE ALIAS UPDATE_EMPLOYEE_DESIGNATION AS $$ +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +@CODE +void updateEmployeeDesignation(final Connection conn, final String employeeNumber, final String title) throws SQLException { + CallableStatement updateStatement = conn.prepareCall("update deptemployee set title = '" + title + "' where employeeNumber = '" + employeeNumber + "'"); + updateStatement.execute(); +} +$$; \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/logback.xml b/persistence-modules/hibernate5-enterprise/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java new file mode 100644 index 0000000000..74f752ab8c --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java @@ -0,0 +1,161 @@ +package com.baeldung.hibernate; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import javax.persistence.Query; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.pojo.PointEntity; +import com.baeldung.hibernate.pojo.PolygonEntity; +import com.vividsolutions.jts.geom.Coordinate; +import com.vividsolutions.jts.geom.Geometry; +import com.vividsolutions.jts.geom.Point; +import com.vividsolutions.jts.geom.Polygon; +import com.vividsolutions.jts.io.ParseException; +import com.vividsolutions.jts.io.WKTReader; +import com.vividsolutions.jts.util.GeometricShapeFactory; + +import geodb.GeoDB; + +public class HibernateSpatialIntegrationTest { + + private Session session; + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory("hibernate-spatial.properties") + .openSession(); + transaction = session.beginTransaction(); + session.doWork(conn -> { GeoDB.InitGeoDB(conn); }); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void shouldConvertWktToGeometry() throws ParseException { + Geometry geometry = wktToGeometry("POINT (2 5)"); + assertEquals("Point", geometry.getGeometryType()); + assertTrue(geometry instanceof Point); + } + + @Test + public void shouldInsertAndSelectPoints() throws ParseException { + PointEntity entity = new PointEntity(); + entity.setPoint((Point) wktToGeometry("POINT (1 1)")); + + session.persist(entity); + PointEntity fromDb = session.find(PointEntity.class, entity.getId()); + assertEquals("POINT (1 1)", fromDb.getPoint().toString()); + } + + @Test + public void shouldSelectDisjointPoints() throws ParseException { + insertPoint("POINT (1 2)"); + insertPoint("POINT (3 4)"); + insertPoint("POINT (5 6)"); + + Point point = (Point) wktToGeometry("POINT (3 4)"); + Query query = session.createQuery("select p from PointEntity p " + + "where disjoint(p.point, :point) = true", PointEntity.class); + query.setParameter("point", point); + assertEquals("POINT (1 2)", ((PointEntity) query.getResultList().get(0)).getPoint().toString()); + assertEquals("POINT (5 6)", ((PointEntity) query.getResultList().get(1)).getPoint().toString()); + } + + @Test + public void shouldSelectAllPointsWithinPolygon() throws ParseException { + insertPoint("POINT (1 1)"); + insertPoint("POINT (1 2)"); + insertPoint("POINT (3 4)"); + insertPoint("POINT (5 6)"); + + Query query = session.createQuery("select p from PointEntity p where within(p.point, :area) = true", + PointEntity.class); + query.setParameter("area", wktToGeometry("POLYGON((0 0, 0 5, 5 5, 5 0, 0 0))")); + assertThat(query.getResultList().stream().map(p -> ((PointEntity) p).getPoint().toString())) + .containsOnly("POINT (1 1)", "POINT (1 2)", "POINT (3 4)"); + } + + @Test + public void shouldSelectAllPointsWithinRadius() throws ParseException { + insertPoint("POINT (1 1)"); + insertPoint("POINT (1 2)"); + insertPoint("POINT (3 4)"); + insertPoint("POINT (5 6)"); + + Query query = session.createQuery("select p from PointEntity p where within(p.point, :circle) = true", + PointEntity.class); + query.setParameter("circle", createCircle(0.0, 0.0, 5)); + + assertThat(query.getResultList().stream().map(p -> ((PointEntity) p).getPoint().toString())) + .containsOnly("POINT (1 1)", "POINT (1 2)"); + } + + @Test + public void shouldSelectAdjacentPolygons() throws ParseException { + insertPolygon("POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))"); + insertPolygon("POLYGON ((3 0, 3 5, 8 5, 8 0, 3 0))"); + insertPolygon("POLYGON ((2 2, 3 1, 2 5, 4 3, 3 3, 2 2))"); + + Query query = session.createQuery("select p from PolygonEntity p where touches(p.polygon, :polygon) = true", + PolygonEntity.class); + query.setParameter("polygon", wktToGeometry("POLYGON ((5 5, 5 10, 10 10, 10 5, 5 5))")); + assertThat(query.getResultList().stream().map(p -> ((PolygonEntity) p).getPolygon().toString())) + .containsOnly("POLYGON ((0 0, 0 5, 5 5, 5 0, 0 0))", "POLYGON ((3 0, 3 5, 8 5, 8 0, 3 0))"); + } + + private void insertPoint(String point) throws ParseException { + PointEntity entity = new PointEntity(); + entity.setPoint((Point) wktToGeometry(point)); + session.persist(entity); + } + + private void insertPolygon(String polygon) throws ParseException { + PolygonEntity entity = new PolygonEntity(); + entity.setPolygon((Polygon) wktToGeometry(polygon)); + session.persist(entity); + } + + private Geometry wktToGeometry(String wellKnownText) throws ParseException { + WKTReader fromText = new WKTReader(); + Geometry geom = null; + geom = fromText.read(wellKnownText); + return geom; + } + + private static Geometry createCircle(double x, double y, double radius) { + GeometricShapeFactory shapeFactory = new GeometricShapeFactory(); + shapeFactory.setNumPoints(32); + shapeFactory.setCentre(new Coordinate(x, y)); + shapeFactory.setSize(radius * 2); + return shapeFactory.createCircle(); + } + + public static Properties getProperties(String propertyFile) throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(propertyFile); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java new file mode 100644 index 0000000000..0b2bdf7ead --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java @@ -0,0 +1,87 @@ +package com.baeldung.hibernate.aggregatefunctions; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.pojo.Student; + +public class AggregateFunctionsIntegrationTest { + + private static Session session; + private static Transaction transaction; + + @BeforeClass + public static final void setup() throws HibernateException, IOException { + session = HibernateUtil.getSessionFactory() + .openSession(); + transaction = session.beginTransaction(); + + Student jonas = new Student("Jonas", 22); + session.save(jonas); + + Student sally = new Student("Sally", 20); + session.save(sally); + + Student simon = new Student("Simon", 25); + session.save(simon); + + Student raven = new Student("Raven", 21); + session.save(raven); + + Student sam = new Student("Sam", 23); + session.save(sam); + + } + + @AfterClass + public static final void teardown() { + if (session != null) { + transaction.rollback(); + session.close(); + } + } + + @Test + public void whenMaxAge_ThenReturnValue() { + int maxAge = (int) session.createQuery("SELECT MAX(age) from Student") + .getSingleResult(); + assertThat(maxAge).isEqualTo(25); + } + + @Test + public void whenMinAge_ThenReturnValue() { + int minAge = (int) session.createQuery("SELECT MIN(age) from Student") + .getSingleResult(); + assertThat(minAge).isEqualTo(20); + } + + @Test + public void whenAverageAge_ThenReturnValue() { + Double avgAge = (Double) session.createQuery("SELECT AVG(age) from Student") + .getSingleResult(); + assertThat(avgAge).isEqualTo(22.2); + } + + @Test + public void whenCountAll_ThenReturnValue() { + Long totalStudents = (Long) session.createQuery("SELECT COUNT(*) from Student") + .getSingleResult(); + assertThat(totalStudents).isEqualTo(5); + } + + @Test + public void whenSumOfAllAges_ThenReturnValue() { + Long sumOfAllAges = (Long) session.createQuery("SELECT SUM(age) from Student") + .getSingleResult(); + assertThat(sumOfAllAges).isEqualTo(111); + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java new file mode 100644 index 0000000000..3581c81daa --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java @@ -0,0 +1,425 @@ +package com.baeldung.hibernate.exception; + +import static org.hamcrest.CoreMatchers.isA; +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.util.List; + +import javax.persistence.OptimisticLockException; +import javax.persistence.PersistenceException; + +import org.hibernate.AnnotationException; +import org.hibernate.HibernateException; +import org.hibernate.MappingException; +import org.hibernate.NonUniqueObjectException; +import org.hibernate.PropertyValueException; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.StaleObjectStateException; +import org.hibernate.StaleStateException; +import org.hibernate.Transaction; +import org.hibernate.TransactionException; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.cfg.Configuration; +import org.hibernate.exception.ConstraintViolationException; +import org.hibernate.exception.DataException; +import org.hibernate.exception.SQLGrammarException; +import org.hibernate.query.NativeQuery; +import org.hibernate.tool.schema.spi.CommandAcceptanceException; +import org.hibernate.tool.schema.spi.SchemaManagementException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class HibernateExceptionUnitTest { + + private static final Logger logger = LoggerFactory + .getLogger(HibernateExceptionUnitTest.class); + private SessionFactory sessionFactory; + + @Before + public void setUp() throws IOException { + sessionFactory = HibernateUtil.getSessionFactory(); + } + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + private Configuration getConfiguration() { + Configuration cfg = new Configuration(); + cfg.setProperty(AvailableSettings.DIALECT, + "org.hibernate.dialect.H2Dialect"); + cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "none"); + cfg.setProperty(AvailableSettings.DRIVER, "org.h2.Driver"); + cfg.setProperty(AvailableSettings.URL, + "jdbc:h2:mem:myexceptiondb2;DB_CLOSE_DELAY=-1"); + cfg.setProperty(AvailableSettings.USER, "sa"); + cfg.setProperty(AvailableSettings.PASS, ""); + return cfg; + } + + @Test + public void whenQueryExecutedWithUnmappedEntity_thenMappingException() { + thrown.expectCause(isA(MappingException.class)); + thrown.expectMessage("Unknown entity: java.lang.String"); + + Session session = sessionFactory.openSession(); + NativeQuery query = session + .createNativeQuery("select name from PRODUCT", String.class); + query.getResultList(); + } + + @Test + @SuppressWarnings("rawtypes") + public void whenQueryExecuted_thenOK() { + Session session = sessionFactory.openSession(); + NativeQuery query = session + .createNativeQuery("select name from PRODUCT"); + List results = query.getResultList(); + assertNotNull(results); + } + + @Test + public void givenEntityWithoutId_whenSessionFactoryCreated_thenAnnotationException() { + thrown.expect(AnnotationException.class); + thrown.expectMessage("No identifier specified for entity"); + + Configuration cfg = getConfiguration(); + cfg.addAnnotatedClass(EntityWithNoId.class); + cfg.buildSessionFactory(); + } + + @Test + public void givenMissingTable_whenSchemaValidated_thenSchemaManagementException() { + thrown.expect(SchemaManagementException.class); + thrown.expectMessage("Schema-validation: missing table"); + + Configuration cfg = getConfiguration(); + cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "validate"); + cfg.addAnnotatedClass(Product.class); + cfg.buildSessionFactory(); + } + + @Test + public void whenWrongDialectSpecified_thenCommandAcceptanceException() { + thrown.expect(SchemaManagementException.class); + thrown.expectCause(isA(CommandAcceptanceException.class)); + thrown.expectMessage("Halting on error : Error executing DDL"); + + Configuration cfg = getConfiguration(); + cfg.setProperty(AvailableSettings.DIALECT, + "org.hibernate.dialect.MySQLDialect"); + cfg.setProperty(AvailableSettings.HBM2DDL_AUTO, "update"); + + // This does not work due to hibernate bug + // cfg.setProperty(AvailableSettings.HBM2DDL_HALT_ON_ERROR,"true"); + cfg.getProperties() + .put(AvailableSettings.HBM2DDL_HALT_ON_ERROR, true); + + cfg.addAnnotatedClass(Product.class); + cfg.buildSessionFactory(); + } + + @Test + public void givenMissingTable_whenEntitySaved_thenSQLGrammarException() { + thrown.expect(isA(PersistenceException.class)); + thrown.expectCause(isA(SQLGrammarException.class)); + thrown + .expectMessage("SQLGrammarException: could not prepare statement"); + + Configuration cfg = getConfiguration(); + cfg.addAnnotatedClass(Product.class); + + SessionFactory sessionFactory = cfg.buildSessionFactory(); + Session session = null; + Transaction transaction = null; + try { + + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + Product product = new Product(); + product.setId(1); + product.setName("Product 1"); + session.save(product); + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + closeSessionFactoryQuietly(sessionFactory); + } + } + + @Test + public void givenMissingTable_whenQueryExecuted_thenSQLGrammarException() { + thrown.expect(isA(PersistenceException.class)); + thrown.expectCause(isA(SQLGrammarException.class)); + thrown + .expectMessage("SQLGrammarException: could not prepare statement"); + + Session session = sessionFactory.openSession(); + NativeQuery query = session.createNativeQuery( + "select * from NON_EXISTING_TABLE", Product.class); + query.getResultList(); + } + + @Test + public void whenDuplicateIdSaved_thenConstraintViolationException() { + thrown.expect(isA(PersistenceException.class)); + thrown.expectCause(isA(ConstraintViolationException.class)); + thrown.expectMessage( + "ConstraintViolationException: could not execute statement"); + + Session session = null; + Transaction transaction = null; + + for (int i = 1; i <= 2; i++) { + try { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + Product product = new Product(); + product.setId(1); + product.setName("Product " + i); + session.save(product); + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + } + } + } + + @Test + public void givenNotNullPropertyNotSet_whenEntityIdSaved_thenPropertyValueException() { + thrown.expect(isA(PropertyValueException.class)); + thrown.expectMessage( + "not-null property references a null or transient value"); + + Session session = null; + Transaction transaction = null; + + try { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + + Product product = new Product(); + product.setId(1); + session.save(product); + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + } + + } + + @Test + public void givenQueryWithDataTypeMismatch_WhenQueryExecuted_thenDataException() { + thrown.expectCause(isA(DataException.class)); + thrown.expectMessage( + "org.hibernate.exception.DataException: could not prepare statement"); + + Session session = sessionFactory.openSession(); + NativeQuery query = session.createNativeQuery( + "select * from PRODUCT where id='wrongTypeId'", Product.class); + query.getResultList(); + } + + @Test + public void givenSessionContainingAnId_whenIdAssociatedAgain_thenNonUniqueObjectException() { + thrown.expect(isA(NonUniqueObjectException.class)); + thrown.expectMessage( + "A different object with the same identifier value was already associated with the session"); + + Session session = null; + Transaction transaction = null; + + try { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + + Product product1 = new Product(); + product1.setId(1); + product1.setName("Product 1"); + session.save(product1); + + Product product2 = new Product(); + product2.setId(1); + product2.setName("Product 2"); + session.save(product2); + + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + } + } + + @Test + public void whenDeletingADeletedObject_thenOptimisticLockException() { + thrown.expect(isA(OptimisticLockException.class)); + thrown.expectMessage( + "Batch update returned unexpected row count from update"); + thrown.expectCause(isA(StaleStateException.class)); + + Session session = null; + Transaction transaction = null; + + try { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + + Product product1 = new Product(); + product1.setId(12); + product1.setName("Product 12"); + session.save(product1); + transaction.commit(); + session.close(); + + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + Product product2 = session.get(Product.class, 12); + session.createNativeQuery("delete from Product where id=12") + .executeUpdate(); + // We need to refresh to fix the error. + // session.refresh(product2); + session.delete(product2); + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + } + } + + @Test + public void whenUpdatingNonExistingObject_thenStaleStateException() { + thrown.expect(isA(OptimisticLockException.class)); + thrown + .expectMessage("Row was updated or deleted by another transaction"); + thrown.expectCause(isA(StaleObjectStateException.class)); + + Session session = null; + Transaction transaction = null; + + try { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + + Product product1 = new Product(); + product1.setId(15); + product1.setName("Product1"); + session.update(product1); + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + } + } + + @Test + public void givenTxnMarkedRollbackOnly_whenCommitted_thenTransactionException() { + thrown.expect(isA(TransactionException.class)); + + Session session = null; + Transaction transaction = null; + try { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + + Product product1 = new Product(); + product1.setId(15); + product1.setName("Product1"); + session.save(product1); + transaction.setRollbackOnly(); + + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + } + } + + private void rollbackTransactionQuietly(Transaction transaction) { + if (transaction != null && transaction.isActive()) { + try { + transaction.rollback(); + } catch (Exception e) { + logger.error("Exception while rolling back transaction", e); + } + } + } + + private void closeSessionQuietly(Session session) { + if (session != null) { + try { + session.close(); + } catch (Exception e) { + logger.error("Exception while closing session", e); + } + } + } + + private void closeSessionFactoryQuietly(SessionFactory sessionFactory) { + if (sessionFactory != null) { + try { + sessionFactory.close(); + } catch (Exception e) { + logger.error("Exception while closing sessionFactory", e); + } + } + } + + @Test + public void givenExistingEntity_whenIdUpdated_thenHibernateException() { + thrown.expect(isA(PersistenceException.class)); + thrown.expectCause(isA(HibernateException.class)); + thrown.expectMessage( + "identifier of an instance of com.baeldung.hibernate.exception.Product was altered"); + + Session session = null; + Transaction transaction = null; + + try { + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + + Product product1 = new Product(); + product1.setId(222); + product1.setName("Product 222"); + session.save(product1); + transaction.commit(); + closeSessionQuietly(session); + + session = sessionFactory.openSession(); + transaction = session.beginTransaction(); + + Product product2 = session.get(Product.class, 222); + product2.setId(333); + session.save(product2); + + transaction.commit(); + } catch (Exception e) { + rollbackTransactionQuietly(transaction); + throw (e); + } finally { + closeSessionQuietly(session); + } + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java new file mode 100644 index 0000000000..f609c75834 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java @@ -0,0 +1,50 @@ +package com.baeldung.hibernate.logging; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +import java.io.IOException; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.query.Query; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.logging.Employee; + +public class HibernateLoggingIntegrationTest { + + private SessionFactory sessionFactory; + + @Before + public void setUp() throws IOException { + final StandardServiceRegistry registry = new StandardServiceRegistryBuilder().configure("hibernate-logging.cfg.xml") + .build(); + try { + sessionFactory = new MetadataSources(registry).buildMetadata() + .buildSessionFactory(); + Session session = sessionFactory.openSession(); + session.beginTransaction(); + session.save(new Employee("John Smith", "001")); + session.getTransaction() + .commit(); + session.close(); + } catch (Exception e) { + fail(e); + StandardServiceRegistryBuilder.destroy(registry); + } + } + + @Test + public void whenAllEmployeesAreSelected_ThenSuccess() { + Query query = sessionFactory.openSession().createQuery("from com.baeldung.hibernate.logging.Employee", Employee.class); + List deptEmployees = query.list(); + Employee deptEmployee = deptEmployees.get(0); + assertEquals("John Smith", deptEmployee.getName()); + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java new file mode 100644 index 0000000000..1b6cee7e67 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java @@ -0,0 +1,26 @@ +package com.baeldung.hibernate.multitenancy; + +import java.io.Serializable; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity(name = "Car") +@Table(name = "Car") +public class Car implements Serializable { + + private static final long serialVersionUID = 1015320564683423342L; + + private String brand; + + @Id + public String getBrand() { + return brand; + } + + public void setBrand(String brand) { + this.brand = brand; + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java new file mode 100644 index 0000000000..fdc3f9fa81 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java @@ -0,0 +1,104 @@ +package com.baeldung.hibernate.multitenancy; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.io.IOException; +import java.util.Properties; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.AvailableSettings; +import org.hibernate.context.spi.CurrentTenantIdentifierResolver; +import org.hibernate.service.ServiceRegistry; +import org.junit.Before; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import com.baeldung.hibernate.multitenancy.database.TenantIdNames; + +public abstract class MultitenancyIntegrationTest { + + public abstract String getPropertyFile(); + + @Mock + private CurrentTenantIdentifierResolver currentTenantIdentifierResolver; + + private SessionFactory sessionFactory; + + @Before + public void setup() throws IOException { + MockitoAnnotations.initMocks(this); + + Mockito.when(currentTenantIdentifierResolver.validateExistingCurrentSessions()) + .thenReturn(false); + + Properties properties = getHibernateProperties(); + properties.put(AvailableSettings.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantIdentifierResolver); + + sessionFactory = buildSessionFactory(properties); + + initTenant(TenantIdNames.MYDB1); + initTenant(TenantIdNames.MYDB2); + } + + protected void initTenant(String tenantId) { + whenCurrentTenantIs(tenantId); + createCarTable(); + } + + protected void whenCurrentTenantIs(String tenantId) { + Mockito.when(currentTenantIdentifierResolver.resolveCurrentTenantIdentifier()) + .thenReturn(tenantId); + } + + protected void whenAddCar(String brand) { + Session session = sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + Car car = new Car(); + car.setBrand(brand); + session.save(car); + tx.commit(); + } + + protected void thenCarFound(String brand) { + Session session = sessionFactory.openSession(); + assertNotNull(session.get(Car.class, brand)); + } + + protected void thenCarNotFound(String brand) { + Session session = sessionFactory.openSession(); + assertNull(session.get(Car.class, brand)); + } + + @SuppressWarnings("deprecation") + private void createCarTable() { + Session session = sessionFactory.openSession(); + Transaction tx = session.beginTransaction(); + session.createSQLQuery("drop table Car if exists") + .executeUpdate(); + session.createSQLQuery("create table Car (brand varchar(255) primary key)") + .executeUpdate(); + tx.commit(); + } + + private Properties getHibernateProperties() throws IOException { + Properties properties = new Properties(); + properties.load(getClass().getResourceAsStream(getPropertyFile())); + return properties; + } + + private static SessionFactory buildSessionFactory(Properties properties) { + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + metadataSources.addAnnotatedClass(Car.class); + return metadataSources.buildMetadata() + .buildSessionFactory(); + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java new file mode 100644 index 0000000000..92f477a646 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java @@ -0,0 +1,25 @@ +package com.baeldung.hibernate.multitenancy.database; + +import java.io.IOException; + +import org.junit.Test; + +import com.baeldung.hibernate.multitenancy.MultitenancyIntegrationTest; + +public class DatabaseApproachMultitenancyIntegrationTest extends MultitenancyIntegrationTest { + + @Override + public String getPropertyFile() { + return "/hibernate-database-multitenancy.properties"; + } + + @Test + public void givenDatabaseApproach_whenAddingEntries_thenOnlyAddedToConcreteDatabase() throws IOException { + whenCurrentTenantIs(TenantIdNames.MYDB1); + whenAddCar("myCar"); + thenCarFound("myCar"); + whenCurrentTenantIs(TenantIdNames.MYDB2); + thenCarNotFound("myCar"); + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java new file mode 100644 index 0000000000..eb1f410622 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java @@ -0,0 +1,42 @@ +package com.baeldung.hibernate.multitenancy.database; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; + +import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; +import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; + +@SuppressWarnings("serial") +public class MapMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider { + + private final Map connectionProviderMap = new HashMap<>(); + + public MapMultiTenantConnectionProvider() throws IOException { + initConnectionProviderForTenant(TenantIdNames.MYDB1); + initConnectionProviderForTenant(TenantIdNames.MYDB2); + } + + @Override + protected ConnectionProvider getAnyConnectionProvider() { + return connectionProviderMap.values() + .iterator() + .next(); + } + + @Override + protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) { + return connectionProviderMap.get(tenantIdentifier); + } + + private void initConnectionProviderForTenant(String tenantId) throws IOException { + Properties properties = new Properties(); + properties.load(getClass().getResourceAsStream(String.format("/hibernate-database-%s.properties", tenantId))); + DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); + connectionProvider.configure(properties); + this.connectionProviderMap.put(tenantId, connectionProvider); + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java new file mode 100644 index 0000000000..231272fa63 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java @@ -0,0 +1,6 @@ +package com.baeldung.hibernate.multitenancy.database; + +public class TenantIdNames { + public static final String MYDB1 = "mydb1"; + public static final String MYDB2 = "mydb2"; +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java new file mode 100644 index 0000000000..304af65fca --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java @@ -0,0 +1,26 @@ +package com.baeldung.hibernate.multitenancy.schema; + +import java.io.IOException; + +import org.junit.Test; + +import com.baeldung.hibernate.multitenancy.MultitenancyIntegrationTest; +import com.baeldung.hibernate.multitenancy.database.TenantIdNames; + +public class SchemaApproachMultitenancyIntegrationTest extends MultitenancyIntegrationTest { + + @Override + public String getPropertyFile() { + return "/hibernate-schema-multitenancy.properties"; + } + + @Test + public void givenSchemaApproach_whenAddingEntries_thenOnlyAddedToConcreteSchema() throws IOException { + whenCurrentTenantIs(TenantIdNames.MYDB1); + whenAddCar("Ferrari"); + thenCarFound("Ferrari"); + whenCurrentTenantIs(TenantIdNames.MYDB2); + thenCarNotFound("Ferrari"); + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java new file mode 100644 index 0000000000..601eba651c --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java @@ -0,0 +1,48 @@ +package com.baeldung.hibernate.multitenancy.schema; + +import java.io.IOException; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Properties; + +import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl; +import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider; +import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; + +@SuppressWarnings("serial") +public class SchemaMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider { + + private final ConnectionProvider connectionProvider; + + public SchemaMultiTenantConnectionProvider() throws IOException { + connectionProvider = initConnectionProvider(); + } + + @Override + protected ConnectionProvider getAnyConnectionProvider() { + return connectionProvider; + } + + @Override + protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) { + return connectionProvider; + } + + @Override + public Connection getConnection(String tenantIdentifier) throws SQLException { + Connection connection = super.getConnection(tenantIdentifier); + connection.createStatement() + .execute(String.format("SET SCHEMA %s;", tenantIdentifier)); + return connection; + } + + private ConnectionProvider initConnectionProvider() throws IOException { + Properties properties = new Properties(); + properties.load(getClass().getResourceAsStream("/hibernate-schema-multitenancy.properties")); + + DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl(); + connectionProvider.configure(properties); + return connectionProvider; + } + +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java new file mode 100644 index 0000000000..2eba94e307 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java @@ -0,0 +1,6 @@ +package com.baeldung.hibernate.multitenancy.schema; + +public class TenantIdNames { + public static final String MYDB1 = "mydb1"; + public static final String MYDB2 = "mydb2"; +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java new file mode 100644 index 0000000000..4efa1e1f68 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java @@ -0,0 +1,73 @@ +package com.baeldung.hibernateparameters; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistry; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.query.Query; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; + +public class NamedParameterUnitTest { + private SessionFactory sessionFactory; + + @Before + public void setUp() throws Exception { + final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() + .configure() + .build(); + try { + sessionFactory = new MetadataSources(registry).buildMetadata().buildSessionFactory(); + Session session = sessionFactory.openSession(); + session.beginTransaction(); + session.save(new Event("Event 1")); + session.save(new Event("Event 2")); + session.getTransaction().commit(); + session.close(); + } catch (Exception e) { + fail(e); + StandardServiceRegistryBuilder.destroy(registry); + } + } + + @After + public void tearDown() throws Exception { + if (sessionFactory != null) { + sessionFactory.close(); + } + } + + @Test + public void whenNamedParameterProvided_thenCorrect() { + Session session = sessionFactory.openSession(); + session.beginTransaction(); + Query query = session.createQuery("from Event E WHERE E.title = :eventTitle", Event.class); + + // This binds the value "Event1" to the parameter :eventTitle + query.setParameter("eventTitle", "Event 1"); + + assertEquals(1, query.list().size()); + session.getTransaction().commit(); + session.close(); + } + + @Test(expected = org.hibernate.QueryException.class) + public void whenNamedParameterMissing_thenThrowsQueryException() { + Session session = sessionFactory.openSession(); + session.beginTransaction(); + Query query = session.createQuery("from Event E WHERE E.title = :eventTitle", Event.class); + + try { + query.list(); + fail("We are expecting an exception!"); + } finally { + session.getTransaction().commit(); + session.close(); + } + } +} diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-multitenancy.properties b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-multitenancy.properties new file mode 100644 index 0000000000..853fa80dfc --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-multitenancy.properties @@ -0,0 +1,2 @@ +hibernate.multiTenancy=DATABASE +hibernate.multi_tenant_connection_provider=com.baeldung.hibernate.multitenancy.database.MapMultiTenantConnectionProvider \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb1.properties b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb1.properties new file mode 100644 index 0000000000..345f1dbbea --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb1.properties @@ -0,0 +1,4 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.dialect=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb2.properties b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb2.properties new file mode 100644 index 0000000000..626b7853c6 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb2.properties @@ -0,0 +1,4 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb2;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.dialect=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-exception.properties b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-exception.properties new file mode 100644 index 0000000000..e08a23166d --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-exception.properties @@ -0,0 +1,16 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:myexceptiondb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 + +hibernate.transaction.factory_class=org.hibernate.transaction.JTATransactionFactory diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-schema-multitenancy.properties b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-schema-multitenancy.properties new file mode 100644 index 0000000000..4abb621355 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-schema-multitenancy.properties @@ -0,0 +1,7 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;INIT=CREATE SCHEMA IF NOT EXISTS MYDB1\\;CREATE SCHEMA IF NOT EXISTS MYDB2\\; +hibernate.connection.username=sa +hibernate.connection.autocommit=true +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.multiTenancy=SCHEMA +hibernate.multi_tenant_connection_provider=com.baeldung.hibernate.multitenancy.schema.SchemaMultiTenantConnectionProvider \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-spatial.properties b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-spatial.properties new file mode 100644 index 0000000000..1657c838e3 --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-spatial.properties @@ -0,0 +1,14 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.spatial.dialect.h2geodb.GeoDBDialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate.properties b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate.properties new file mode 100644 index 0000000000..c14782ce0f --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate.properties @@ -0,0 +1,14 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/lifecycle-init.sql b/persistence-modules/hibernate5-enterprise/src/test/resources/lifecycle-init.sql new file mode 100644 index 0000000000..c0c9a3f34d --- /dev/null +++ b/persistence-modules/hibernate5-enterprise/src/test/resources/lifecycle-init.sql @@ -0,0 +1,25 @@ +create sequence hibernate_sequence start with 1 increment by 1; + +create table Football_Player ( + id bigint not null, + name varchar(255), + primary key (id) +); + +insert into + Football_Player + (name, id) + values + ('Cristiano Ronaldo', next value for hibernate_sequence); + +insert into + Football_Player + (name, id) + values + ('Lionel Messi', next value for hibernate_sequence); + +insert into + Football_Player + (name, id) + values + ('Gigi Buffon', next value for hibernate_sequence); \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/profile.png b/persistence-modules/hibernate5-enterprise/src/test/resources/profile.png new file mode 100644 index 0000000000000000000000000000000000000000..1cd4e978b96d0f59a6e48692fcb68d1c6c565a20 GIT binary patch literal 1117 zcmV-j1fu(iP)%yyh@V&OYl(_AFwE`D&8)` zPnvkdvc#Z>pRh2kBHk{=qaGfCG;?<;rVe;D+%LyZS~!K}c+|op81YK@rzPHU@Th|m z4Dk`HcojTY;+}_-W%HGqKH@C!LiH8Tp>1lC@aTqoy zBU~QK<}hs@q|M8($ee`o<9#`B3-PL4Y7d9kW#<;n>t}6VNpYCswLrJTtEa_lFwgN$52-_vxvvfJs@B6-OYs%-@M_JTx*UfozG6(Bhs)>w z!pG%vU$b%f++EGa<#Tu1FZ^c#{;G|y5=kM3Y#X^mtSrFA_-o-vX7e_$5-udx(>S4U)i|4)(UJ~zR(vwE+6VTAzoo7wIS|c zh*yt`3wK%<+yX~Z9G1z2GQgf3~qx jc9u$WjpqGof00000NkvXXu0mjfJX<<= literal 0 HcmV?d00001 From 0bb56912ff21f25c7386b6b2dc0e9350b2d31ac5 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:20:26 +0530 Subject: [PATCH 029/278] JAVA-4 : added new module hibernate5-jpa --- persistence-modules/hibernate5-jpa/README.md | 16 ++ persistence-modules/hibernate5-jpa/pom.xml | 95 +++++++++ .../com/baeldung/hibernate/HibernateUtil.java | 89 ++++++++ .../UnsupportedTenancyException.java | 8 + .../converters/PersonNameConverter.java | 61 ++++++ .../hibernate/entities/Department.java | 45 ++++ .../hibernate/entities/DeptEmployee.java | 83 ++++++++ .../jpabootstrap/application/Application.java | 34 +++ .../config/HibernatePersistenceUnitInfo.java | 131 ++++++++++++ .../config/JpaEntityManagerFactory.java | 69 ++++++ .../hibernate/jpabootstrap/entities/User.java | 45 ++++ .../service/EmployeeSearchService.java | 15 ++ .../service/EmployeeSearchServiceImpl.java | 77 +++++++ .../hibernate/onetoone/HibernateUtil.java | 61 ++++++ .../baeldung/hibernate/onetoone/Strategy.java | 25 +++ .../onetoone/foreignkeybased/Address.java | 60 ++++++ .../onetoone/foreignkeybased/User.java | 51 +++++ .../onetoone/jointablebased/Employee.java | 53 +++++ .../onetoone/jointablebased/WorkStation.java | 61 ++++++ .../onetoone/sharedkeybased/Address.java | 60 ++++++ .../onetoone/sharedkeybased/User.java | 50 +++++ .../OptimisticLockingCourse.java | 48 +++++ .../OptimisticLockingStudent.java | 70 ++++++ .../hibernate/pessimisticlocking/Address.java | 34 +++ .../pessimisticlocking/Customer.java | 58 +++++ .../pessimisticlocking/Individual.java | 49 +++++ .../PessimisticLockingCourse.java | 47 ++++ .../PessimisticLockingEmployee.java | 27 +++ .../PessimisticLockingStudent.java | 46 ++++ .../com/baeldung/hibernate/pojo/Movie.java | 52 +++++ .../com/baeldung/hibernate/pojo/Person.java | 32 +++ .../baeldung/hibernate/pojo/PersonName.java | 29 +++ .../com/baeldung/hibernate/pojo/Post.java | 59 ++++++ .../com/baeldung/hibernate/pojo/Student.java | 51 +++++ .../hibernate/transaction/PostService.java | 29 +++ .../PersistenceContextDemoApplication.java | 13 ++ .../persistencecontext/entity/User.java | 36 ++++ ...ExtendedPersistenceContextUserService.java | 33 +++ ...ansctionPersistenceContextUserService.java | 32 +++ .../main/resources/META-INF/persistence.xml | 19 ++ .../src/main/resources/init_database.sql | 10 + .../src/main/resources/logback.xml | 13 ++ .../PersonNameConverterUnitTest.java | 200 ++++++++++++++++++ .../EmployeeSearchServiceIntegrationTest.java | 121 +++++++++++ ...ToOneAnnotationFKBasedIntegrationTest.java | 80 +++++++ ...ToOneAnnotationJTBasedIntegrationTest.java | 80 +++++++ ...oOneAnnotationSPKBasedIntegrationTest.java | 79 +++++++ .../OptimisticLockingIntegrationTest.java | 146 +++++++++++++ ...asicPessimisticLockingIntegrationTest.java | 162 ++++++++++++++ .../PessimisticLockScopesIntegrationTest.java | 125 +++++++++++ .../TransactionIntegrationTest.java | 57 +++++ .../PersistenceContextIntegrationTest.java | 90 ++++++++ .../resources/hibernate-namedquery.properties | 9 + .../hibernate-pessimistic-locking.properties | 8 + .../src/test/resources/hibernate.properties | 14 ++ .../src/test/resources/profile.png | Bin 0 -> 1117 bytes 56 files changed, 3147 insertions(+) create mode 100644 persistence-modules/hibernate5-jpa/README.md create mode 100644 persistence-modules/hibernate5-jpa/pom.xml create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java create mode 100644 persistence-modules/hibernate5-jpa/src/main/resources/META-INF/persistence.xml create mode 100644 persistence-modules/hibernate5-jpa/src/main/resources/init_database.sql create mode 100644 persistence-modules/hibernate5-jpa/src/main/resources/logback.xml create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java create mode 100644 persistence-modules/hibernate5-jpa/src/test/resources/hibernate-namedquery.properties create mode 100644 persistence-modules/hibernate5-jpa/src/test/resources/hibernate-pessimistic-locking.properties create mode 100644 persistence-modules/hibernate5-jpa/src/test/resources/hibernate.properties create mode 100644 persistence-modules/hibernate5-jpa/src/test/resources/profile.png diff --git a/persistence-modules/hibernate5-jpa/README.md b/persistence-modules/hibernate5-jpa/README.md new file mode 100644 index 0000000000..bffba85d54 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/README.md @@ -0,0 +1,16 @@ +## Hibernate 5 + +This module contains articles about Hibernate 5. + +### Relevant articles: + +- [JPA Attribute Converters](http://www.baeldung.com/jpa-attribute-converters) +- [Pessimistic Locking in JPA](http://www.baeldung.com/jpa-pessimistic-locking) +- [Bootstrapping JPA Programmatically in Java](http://www.baeldung.com/java-bootstrap-jpa) +- [Optimistic Locking in JPA](http://www.baeldung.com/jpa-optimistic-locking) +- [Criteria API – An Example of IN Expressions](https://www.baeldung.com/jpa-criteria-api-in-expressions) +- [One-to-One Relationship in JPA](https://www.baeldung.com/jpa-one-to-one) +- [Enabling Transaction Locks in Spring Data JPA](https://www.baeldung.com/java-jpa-transaction-locks) +- [TransactionRequiredException Error](https://www.baeldung.com/jpa-transaction-required-exception) +- [FetchMode in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-fetchmode) +- [JPA/Hibernate Persistence Context](https://www.baeldung.com/jpa-hibernate-persistence-context) diff --git a/persistence-modules/hibernate5-jpa/pom.xml b/persistence-modules/hibernate5-jpa/pom.xml new file mode 100644 index 0000000000..b181fff36b --- /dev/null +++ b/persistence-modules/hibernate5-jpa/pom.xml @@ -0,0 +1,95 @@ + + + 4.0.0 + hibernate5-jpa + 0.0.1-SNAPSHOT + hibernate5-jpa + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.springframework.boot + spring-boot-starter-web + ${spring-boot.version} + + + org.springframework.boot + spring-boot-starter-thymeleaf + ${spring-boot.version} + + + org.springframework.boot + spring-boot-starter-data-jpa + ${spring-boot.version} + + + com.zaxxer + HikariCP + + + + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + com.h2database + h2 + ${h2.version} + + + org.hibernate + hibernate-spatial + ${hibernate.version} + + + mysql + mysql-connector-java + ${mysql.version} + + + ch.vorburger.mariaDB4j + mariaDB4j + ${mariaDB4j.version} + + + org.hibernate + hibernate-testing + ${hibernate.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${openjdk-jmh.version} + + + + + 5.3.7.Final + 6.0.6 + 2.2.3 + 3.8.0 + 1.21 + 2.1.7.RELEASE + + + diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java new file mode 100644 index 0000000000..cf59fe4855 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -0,0 +1,89 @@ +package com.baeldung.hibernate; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.entities.DeptEmployee; +import com.baeldung.hibernate.optimisticlocking.OptimisticLockingCourse; +import com.baeldung.hibernate.optimisticlocking.OptimisticLockingStudent; +import com.baeldung.hibernate.pessimisticlocking.Individual; +import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingCourse; +import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingEmployee; +import com.baeldung.hibernate.pessimisticlocking.PessimisticLockingStudent; +import com.baeldung.hibernate.pojo.Person; +import com.baeldung.hibernate.pojo.Post; +import com.baeldung.hibernate.pojo.Student; + +public class HibernateUtil { + private static String PROPERTY_FILE_NAME; + + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(null); + } + + public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { + PROPERTY_FILE_NAME = propertyFileName; + ServiceRegistry serviceRegistry = configureServiceRegistry(); + return makeSessionFactory(serviceRegistry); + } + + public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException { + ServiceRegistry serviceRegistry = configureServiceRegistry(properties); + return makeSessionFactory(serviceRegistry); + } + + private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + metadataSources.addPackage("com.baeldung.hibernate.pojo"); + metadataSources.addAnnotatedClass(Person.class); + metadataSources.addAnnotatedClass(Student.class); + metadataSources.addAnnotatedClass(Individual.class); + metadataSources.addAnnotatedClass(PessimisticLockingEmployee.class); + metadataSources.addAnnotatedClass(PessimisticLockingStudent.class); + metadataSources.addAnnotatedClass(PessimisticLockingCourse.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Customer.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Address.class); + metadataSources.addAnnotatedClass(DeptEmployee.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); + metadataSources.addAnnotatedClass(OptimisticLockingCourse.class); + metadataSources.addAnnotatedClass(OptimisticLockingStudent.class); + metadataSources.addAnnotatedClass(Post.class); + + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + + } + + private static ServiceRegistry configureServiceRegistry() throws IOException { + return configureServiceRegistry(getProperties()); + } + + private static ServiceRegistry configureServiceRegistry(Properties properties) throws IOException { + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + public static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java new file mode 100644 index 0000000000..99d9505ea3 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java @@ -0,0 +1,8 @@ +package com.baeldung.hibernate; + +public class UnsupportedTenancyException extends Exception { + public UnsupportedTenancyException (String message) { + super(message); + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java new file mode 100644 index 0000000000..506e674984 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java @@ -0,0 +1,61 @@ +package com.baeldung.hibernate.converters; + +import javax.persistence.AttributeConverter; +import javax.persistence.Converter; + +import com.baeldung.hibernate.pojo.PersonName; + +@Converter +public class PersonNameConverter implements AttributeConverter { + + private static final String SEPARATOR = ", "; + + @Override + public String convertToDatabaseColumn(PersonName personName) { + if (personName == null) { + return null; + } + + StringBuilder sb = new StringBuilder(); + if (personName.getSurname() != null && !personName.getSurname() + .isEmpty()) { + sb.append(personName.getSurname()); + sb.append(SEPARATOR); + } + + if (personName.getName() != null && !personName.getName() + .isEmpty()) { + sb.append(personName.getName()); + } + + return sb.toString(); + } + + @Override + public PersonName convertToEntityAttribute(String dbPersonName) { + if (dbPersonName == null || dbPersonName.isEmpty()) { + return null; + } + + String[] pieces = dbPersonName.split(SEPARATOR); + + if (pieces == null || pieces.length == 0) { + return null; + } + + PersonName personName = new PersonName(); + String firstPiece = !pieces[0].isEmpty() ? pieces[0] : null; + if (dbPersonName.contains(SEPARATOR)) { + personName.setSurname(firstPiece); + + if (pieces.length >= 2 && pieces[1] != null && !pieces[1].isEmpty()) { + personName.setName(pieces[1]); + } + } else { + personName.setName(firstPiece); + } + + return personName; + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java new file mode 100644 index 0000000000..ff94f4f849 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java @@ -0,0 +1,45 @@ +package com.baeldung.hibernate.entities; + +import java.util.List; + +import javax.persistence.*; + +@Entity +public class Department { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @OneToMany(mappedBy="department") + private List employees; + + public Department(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getEmployees() { + return employees; + } + + public void setEmployees(List employees) { + this.employees = employees; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java new file mode 100644 index 0000000000..6510e70650 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java @@ -0,0 +1,83 @@ +package com.baeldung.hibernate.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@org.hibernate.annotations.NamedQueries({ @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindByEmployeeNumber", query = "from DeptEmployee where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDesgination", query = "from DeptEmployee where designation = :designation"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_UpdateEmployeeDepartment", query = "Update DeptEmployee set department = :newDepartment where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDepartment", query = "from DeptEmployee where department = :department", timeout = 1, fetchSize = 10) }) +@org.hibernate.annotations.NamedNativeQueries({ @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_FindByEmployeeName", query = "select * from deptemployee emp where name=:name", resultClass = DeptEmployee.class), + @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_UpdateEmployeeDesignation", query = "call UPDATE_EMPLOYEE_DESIGNATION(:employeeNumber, :newDesignation)", resultClass = DeptEmployee.class) }) +@Entity +public class DeptEmployee { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String employeeNumber; + + private String title; + + private String name; + + @ManyToOne + private Department department; + + public DeptEmployee(String name, String employeeNumber, Department department) { + this.name = name; + this.employeeNumber = employeeNumber; + this.department = department; + } + + public DeptEmployee(String name, String employeeNumber, String title, Department department) { + super(); + this.name = name; + this.employeeNumber = employeeNumber; + this.title = title; + this.department = department; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getEmployeeNumber() { + return employeeNumber; + } + + public void setEmployeeNumber(String employeeNumber) { + this.employeeNumber = employeeNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java new file mode 100644 index 0000000000..f7b8e6bf6d --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.jpabootstrap.application; + +import com.baeldung.hibernate.jpabootstrap.config.JpaEntityManagerFactory; +import com.baeldung.hibernate.jpabootstrap.entities.User; +import javax.persistence.EntityManager; + +public class Application { + + public static void main(String[] args) { + EntityManager entityManager = getJpaEntityManager(); + User user = entityManager.find(User.class, 1); + System.out.println(user); + entityManager.getTransaction().begin(); + user.setName("John"); + user.setEmail("john@domain.com"); + entityManager.merge(user); + entityManager.getTransaction().commit(); + entityManager.getTransaction().begin(); + entityManager.persist(new User("Monica", "monica@domain.com")); + entityManager.getTransaction().commit(); + + // additional CRUD operations + + } + + private static class EntityManagerHolder { + private static final EntityManager ENTITY_MANAGER = new JpaEntityManagerFactory( + new Class[]{User.class}).getEntityManager(); + } + + public static EntityManager getJpaEntityManager() { + return EntityManagerHolder.ENTITY_MANAGER; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java new file mode 100644 index 0000000000..3852b44b64 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java @@ -0,0 +1,131 @@ +package com.baeldung.hibernate.jpabootstrap.config; + +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Properties; +import javax.sql.DataSource; +import javax.persistence.SharedCacheMode; +import javax.persistence.ValidationMode; +import javax.persistence.spi.ClassTransformer; +import javax.persistence.spi.PersistenceUnitInfo; +import javax.persistence.spi.PersistenceUnitTransactionType; +import org.hibernate.jpa.HibernatePersistenceProvider; + +public class HibernatePersistenceUnitInfo implements PersistenceUnitInfo { + + public static final String JPA_VERSION = "2.1"; + private final String persistenceUnitName; + private PersistenceUnitTransactionType transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; + private final List managedClassNames; + private final List mappingFileNames = new ArrayList<>(); + private final Properties properties; + private DataSource jtaDataSource; + private DataSource nonjtaDataSource; + private final List transformers = new ArrayList<>(); + + public HibernatePersistenceUnitInfo(String persistenceUnitName, List managedClassNames, Properties properties) { + this.persistenceUnitName = persistenceUnitName; + this.managedClassNames = managedClassNames; + this.properties = properties; + } + + @Override + public String getPersistenceUnitName() { + return persistenceUnitName; + } + + @Override + public String getPersistenceProviderClassName() { + return HibernatePersistenceProvider.class.getName(); + } + + @Override + public PersistenceUnitTransactionType getTransactionType() { + return transactionType; + } + + public HibernatePersistenceUnitInfo setJtaDataSource(DataSource jtaDataSource) { + this.jtaDataSource = jtaDataSource; + this.nonjtaDataSource = null; + transactionType = PersistenceUnitTransactionType.JTA; + return this; + } + + @Override + public DataSource getJtaDataSource() { + return jtaDataSource; + } + + public HibernatePersistenceUnitInfo setNonJtaDataSource(DataSource nonJtaDataSource) { + this.nonjtaDataSource = nonJtaDataSource; + this.jtaDataSource = null; + transactionType = PersistenceUnitTransactionType.RESOURCE_LOCAL; + return this; + } + + @Override + public DataSource getNonJtaDataSource() { + return nonjtaDataSource; + } + + @Override + public List getMappingFileNames() { + return mappingFileNames; + } + + @Override + public List getJarFileUrls() { + return Collections.emptyList(); + } + + @Override + public URL getPersistenceUnitRootUrl() { + return null; + } + + @Override + public List getManagedClassNames() { + return managedClassNames; + } + + @Override + public boolean excludeUnlistedClasses() { + return false; + } + + @Override + public SharedCacheMode getSharedCacheMode() { + return SharedCacheMode.UNSPECIFIED; + } + + @Override + public ValidationMode getValidationMode() { + return ValidationMode.AUTO; + } + + public Properties getProperties() { + return properties; + } + + @Override + public String getPersistenceXMLSchemaVersion() { + return JPA_VERSION; + } + + @Override + public ClassLoader getClassLoader() { + return Thread.currentThread().getContextClassLoader(); + } + + @Override + public void addTransformer(ClassTransformer transformer) { + transformers.add(transformer); + } + + @Override + public ClassLoader getNewTempClassLoader() { + return null; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java new file mode 100644 index 0000000000..bc1932af6f --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java @@ -0,0 +1,69 @@ +package com.baeldung.hibernate.jpabootstrap.config; + +import com.mysql.cj.jdbc.MysqlDataSource; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.stream.Collectors; +import javax.persistence.EntityManager; +import javax.sql.DataSource; +import javax.persistence.EntityManagerFactory; +import javax.persistence.spi.PersistenceUnitInfo; +import org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl; +import org.hibernate.jpa.boot.internal.PersistenceUnitInfoDescriptor; + +public class JpaEntityManagerFactory { + + private final String DB_URL = "jdbc:mysql://databaseurl"; + private final String DB_USER_NAME = "username"; + private final String DB_PASSWORD = "password"; + private final Class[] entityClasses; + + public JpaEntityManagerFactory(Class[] entityClasses) { + this.entityClasses = entityClasses; + } + + public EntityManager getEntityManager() { + return getEntityManagerFactory().createEntityManager(); + } + + protected EntityManagerFactory getEntityManagerFactory() { + PersistenceUnitInfo persistenceUnitInfo = getPersistenceUnitInfo(getClass().getSimpleName()); + Map configuration = new HashMap<>(); + return new EntityManagerFactoryBuilderImpl(new PersistenceUnitInfoDescriptor(persistenceUnitInfo), configuration) + .build(); + } + + protected HibernatePersistenceUnitInfo getPersistenceUnitInfo(String name) { + return new HibernatePersistenceUnitInfo(name, getEntityClassNames(), getProperties()); + } + + protected List getEntityClassNames() { + return Arrays.asList(getEntities()) + .stream() + .map(Class::getName) + .collect(Collectors.toList()); + } + + protected Properties getProperties() { + Properties properties = new Properties(); + properties.put("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); + properties.put("hibernate.id.new_generator_mappings", false); + properties.put("hibernate.connection.datasource", getMysqlDataSource()); + return properties; + } + + protected Class[] getEntities() { + return entityClasses; + } + + protected DataSource getMysqlDataSource() { + MysqlDataSource mysqlDataSource = new MysqlDataSource(); + mysqlDataSource.setURL(DB_URL); + mysqlDataSource.setUser(DB_USER_NAME); + mysqlDataSource.setPassword(DB_PASSWORD); + return mysqlDataSource; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java new file mode 100644 index 0000000000..86ca1dfa19 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java @@ -0,0 +1,45 @@ +package com.baeldung.hibernate.jpabootstrap.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + private String name; + private String email; + + public User(){} + + public User(String name, String email) { + this.name = name; + this.email = email; + } + + public void setName(String name) { + this.name = name; + } + + public void setEmail(String email) { + this.email = email; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java new file mode 100644 index 0000000000..b7d1a537f0 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java @@ -0,0 +1,15 @@ +package com.baeldung.hibernate.jpacriteriabuilder.service; + +import java.util.List; + +import com.baeldung.hibernate.entities.DeptEmployee; + +public interface EmployeeSearchService { + + List filterbyTitleUsingCriteriaBuilder(List titles); + + List filterbyTitleUsingExpression(List titles); + + List searchByDepartmentQuery(String query); + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java new file mode 100644 index 0000000000..e79168a451 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java @@ -0,0 +1,77 @@ +package com.baeldung.hibernate.jpacriteriabuilder.service; + +import java.util.List; + +import javax.persistence.EntityManager; +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaBuilder.In; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import javax.persistence.criteria.Subquery; + +import com.baeldung.hibernate.entities.Department; +import com.baeldung.hibernate.entities.DeptEmployee; + +public class EmployeeSearchServiceImpl implements EmployeeSearchService { + + private EntityManager entityManager; + private CriteriaBuilder criteriaBuilder; + + public EmployeeSearchServiceImpl(EntityManager entityManager) { + this.entityManager = entityManager; + this.criteriaBuilder = entityManager.getCriteriaBuilder(); + + } + + @Override + public List filterbyTitleUsingCriteriaBuilder(List titles) { + CriteriaQuery criteriaQuery = createCriteriaQuery(DeptEmployee.class); + Root root = criteriaQuery.from(DeptEmployee.class); + In inClause = criteriaBuilder.in(root.get("title")); + for (String title : titles) { + inClause.value(title); + } + criteriaQuery.select(root) + .where(inClause); + TypedQuery query = entityManager.createQuery(criteriaQuery); + return query.getResultList(); + } + + @Override + public List filterbyTitleUsingExpression(List titles) { + CriteriaQuery criteriaQuery = createCriteriaQuery(DeptEmployee.class); + Root root = criteriaQuery.from(DeptEmployee.class); + criteriaQuery.select(root) + .where(root.get("title") + .in(titles)); + TypedQuery query = entityManager.createQuery(criteriaQuery); + return query.getResultList(); + } + + @Override + public List searchByDepartmentQuery(String searchKey) { + CriteriaQuery criteriaQuery = createCriteriaQuery(DeptEmployee.class); + Root emp = criteriaQuery.from(DeptEmployee.class); + + Subquery subquery = criteriaQuery.subquery(Department.class); + Root dept = subquery.from(Department.class); + subquery.select(dept) + .distinct(true) + .where(criteriaBuilder.like(dept.get("name"), new StringBuffer("%").append(searchKey) + .append("%") + .toString())); + + criteriaQuery.select(emp) + .where(criteriaBuilder.in(emp.get("department")) + .value(subquery)); + + TypedQuery query = entityManager.createQuery(criteriaQuery); + return query.getResultList(); + } + + private CriteriaQuery createCriteriaQuery(Class klass) { + return criteriaBuilder.createQuery(klass); + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java new file mode 100644 index 0000000000..18fa2a41db --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java @@ -0,0 +1,61 @@ +package com.baeldung.hibernate.onetoone; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + + private HibernateUtil() { + } + + public static SessionFactory getSessionFactory(Strategy strategy) { + return buildSessionFactory(strategy); + } + + private static SessionFactory buildSessionFactory(Strategy strategy) { + try { + ServiceRegistry serviceRegistry = configureServiceRegistry(); + + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + for (Class entityClass : strategy.getEntityClasses()) { + metadataSources.addAnnotatedClass(entityClass); + } + + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + } catch (IOException ex) { + throw new ExceptionInInitializerError(ex); + } + } + + + private static ServiceRegistry configureServiceRegistry() throws IOException { + Properties properties = getProperties(); + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + private static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource("hibernate.properties"); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java new file mode 100644 index 0000000000..3180566ca5 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java @@ -0,0 +1,25 @@ +package com.baeldung.hibernate.onetoone; + + +import java.util.Arrays; +import java.util.List; + +public enum Strategy { + //See that the classes belongs to different packages + FOREIGN_KEY(Arrays.asList(com.baeldung.hibernate.onetoone.foreignkeybased.User.class, + com.baeldung.hibernate.onetoone.foreignkeybased.Address.class)), + SHARED_PRIMARY_KEY(Arrays.asList(com.baeldung.hibernate.onetoone.sharedkeybased.User.class, + com.baeldung.hibernate.onetoone.sharedkeybased.Address.class)), + JOIN_TABLE_BASED(Arrays.asList(com.baeldung.hibernate.onetoone.jointablebased.Employee.class, + com.baeldung.hibernate.onetoone.jointablebased.WorkStation.class)); + + private List> entityClasses; + + Strategy(List> entityClasses) { + this.entityClasses = entityClasses; + } + + public List> getEntityClasses() { + return entityClasses; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java new file mode 100644 index 0000000000..e05eb46030 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java @@ -0,0 +1,60 @@ +package com.baeldung.hibernate.onetoone.foreignkeybased; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "address") +public class Address { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "street") + private String street; + + @Column(name = "city") + private String city; + + @OneToOne(mappedBy = "address") + private User user; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java new file mode 100644 index 0000000000..dda972f29c --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.onetoone.foreignkeybased; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "username") + private String userName; + + @OneToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "address_id", referencedColumnName = "id") + private Address address; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java new file mode 100644 index 0000000000..a0bc101b9f --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java @@ -0,0 +1,53 @@ +package com.baeldung.hibernate.onetoone.jointablebased; + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "employee") +public class Employee { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "ename") + private String name; + + @OneToOne(cascade = CascadeType.ALL) + @JoinTable(name = "emp_workstation", joinColumns = {@JoinColumn(name = "employee_id", referencedColumnName = "id")}, + inverseJoinColumns = {@JoinColumn(name = "workstation_id", referencedColumnName = "id")}) + private WorkStation workStation; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public WorkStation getWorkStation() { + return workStation; + } + + public void setWorkStation(WorkStation workStation) { + this.workStation = workStation; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java new file mode 100644 index 0000000000..f530611f6e --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java @@ -0,0 +1,61 @@ +package com.baeldung.hibernate.onetoone.jointablebased; + + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "workstation") +public class WorkStation { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "workstation_number") + private Integer workstationNumber; + + @Column(name = "floor") + private String floor; + + @OneToOne(mappedBy = "workStation") + private Employee employee; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getWorkstationNumber() { + return workstationNumber; + } + + public void setWorkstationNumber(Integer workstationNumber) { + this.workstationNumber = workstationNumber; + } + + public String getFloor() { + return floor; + } + + public void setFloor(String floor) { + this.floor = floor; + } + + public Employee getEmployee() { + return employee; + } + + public void setEmployee(Employee employee) { + this.employee = employee; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java new file mode 100644 index 0000000000..927516f6bb --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java @@ -0,0 +1,60 @@ +package com.baeldung.hibernate.onetoone.sharedkeybased; + + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.MapsId; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "address") +public class Address { + + @Id + @Column(name = "id") + private Long id; + + @Column(name = "street") + private String street; + + @Column(name = "city") + private String city; + + @OneToOne + @MapsId + private User user; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getStreet() { + return street; + } + + public void setStreet(String street) { + this.street = street; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java new file mode 100644 index 0000000000..fa00db1271 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java @@ -0,0 +1,50 @@ +package com.baeldung.hibernate.onetoone.sharedkeybased; + + +import javax.persistence.CascadeType; +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "users") +public class User { + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private Long id; + + @Column(name = "username") + private String userName; + + @OneToOne(mappedBy = "user", cascade = CascadeType.ALL) + private Address address; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public Address getAddress() { + return address; + } + + public void setAddress(Address address) { + this.address = address; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java new file mode 100644 index 0000000000..1af3e3e21b --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java @@ -0,0 +1,48 @@ +package com.baeldung.hibernate.optimisticlocking; + +import javax.persistence.*; + +@Entity +public class OptimisticLockingCourse { + + @Id + private Long id; + + private String name; + + @ManyToOne + @JoinTable(name = "optimistic_student_course") + private OptimisticLockingStudent student; + + public OptimisticLockingCourse(Long id, String name) { + this.id = id; + this.name = name; + } + + public OptimisticLockingCourse() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public OptimisticLockingStudent getStudent() { + return student; + } + + public void setStudent(OptimisticLockingStudent student) { + this.student = student; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java new file mode 100644 index 0000000000..b79212ae8d --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java @@ -0,0 +1,70 @@ +package com.baeldung.hibernate.optimisticlocking; + +import javax.persistence.*; +import java.util.List; + +@Entity +public class OptimisticLockingStudent { + + @Id + private Long id; + + private String name; + + private String lastName; + @Version + private Integer version; + + @OneToMany(mappedBy = "student") + private List courses; + + public OptimisticLockingStudent(Long id, String name, String lastName, List courses) { + this.id = id; + this.name = name; + this.lastName = lastName; + this.courses = courses; + } + + public OptimisticLockingStudent() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getVersion() { + return version; + } + + public void setVersion(Integer version) { + this.version = version; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public List getCourses() { + return courses; + } + + public void setCourses(List courses) { + this.courses = courses; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java new file mode 100644 index 0000000000..c889cb6127 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import javax.persistence.Embeddable; + +@Embeddable +public class Address { + + private String country; + private String city; + + public Address(String country, String city) { + this.country = country; + this.city = city; + } + + public Address() { + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getCity() { + return city; + } + + public void setCity(String city) { + this.city = city; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java new file mode 100644 index 0000000000..cb73cbc958 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java @@ -0,0 +1,58 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import javax.persistence.*; +import java.util.List; + +@Entity +public class Customer { + + @Id + private Long customerId; + private String name; + private String lastName; + @ElementCollection + @CollectionTable(name = "customer_address") + private List
addressList; + + public Customer() { + } + + public Customer(Long customerId, String name, String lastName, List
addressList) { + this.customerId = customerId; + this.name = name; + this.lastName = lastName; + this.addressList = addressList; + } + + public Long getCustomerId() { + return customerId; + } + + public void setCustomerId(Long customerId) { + this.customerId = customerId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public List
getAddressList() { + return addressList; + } + + public void setAddressList(List
addressList) { + this.addressList = addressList; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java new file mode 100644 index 0000000000..e491c09eb5 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java @@ -0,0 +1,49 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +@Entity +@Inheritance(strategy = InheritanceType.JOINED) +public class Individual { + + @Id + private Long id; + private String name; + private String lastName; + + public Individual(Long id, String name, String lastName) { + this.id = id; + this.name = name; + this.lastName = lastName; + } + + public Individual() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java new file mode 100644 index 0000000000..aea7d5fc87 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java @@ -0,0 +1,47 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import javax.persistence.*; + +@Entity +public class PessimisticLockingCourse { + + @Id + private Long courseId; + private String name; + @ManyToOne + @JoinTable(name = "student_course") + private PessimisticLockingStudent student; + + public PessimisticLockingCourse(Long courseId, String name, PessimisticLockingStudent student) { + this.courseId = courseId; + this.name = name; + this.student = student; + } + + public PessimisticLockingCourse() { + } + + public Long getCourseId() { + return courseId; + } + + public void setCourseId(Long courseId) { + this.courseId = courseId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public PessimisticLockingStudent getStudent() { + return student; + } + + public void setStudent(PessimisticLockingStudent students) { + this.student = students; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java new file mode 100644 index 0000000000..a1328cbdad --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java @@ -0,0 +1,27 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import javax.persistence.Entity; +import java.math.BigDecimal; + +@Entity +public class PessimisticLockingEmployee extends Individual { + + private BigDecimal salary; + + public PessimisticLockingEmployee(Long id, String name, String lastName, BigDecimal salary) { + super(id, name, lastName); + this.salary = salary; + } + + public PessimisticLockingEmployee() { + super(); + } + + public BigDecimal getSalary() { + return salary; + } + + public void setSalary(BigDecimal average) { + this.salary = average; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java new file mode 100644 index 0000000000..e6c5f476b4 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java @@ -0,0 +1,46 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import javax.persistence.*; +import java.util.List; + +@Entity +public class PessimisticLockingStudent { + + @Id + private Long id; + private String name; + @OneToMany(mappedBy = "student") + private List courses; + + public PessimisticLockingStudent(Long id, String name) { + this.id = id; + this.name = name; + } + + public PessimisticLockingStudent() { + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getCourses() { + return courses; + } + + public void setCourses(List courses) { + this.courses = courses; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java new file mode 100644 index 0000000000..5fae7f6a97 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java @@ -0,0 +1,52 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "MOVIE") +public class Movie { + + @Id + private Long id; + + private String movieName; + + private Integer releaseYear; + + private String language; + + public String getMovieName() { + return movieName; + } + + public void setMovieName(String movieName) { + this.movieName = movieName; + } + + public Integer getReleaseYear() { + return releaseYear; + } + + public void setReleaseYear(Integer releaseYear) { + this.releaseYear = releaseYear; + } + + public String getLanguage() { + return language; + } + + public void setLanguage(String language) { + this.language = language; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java new file mode 100644 index 0000000000..390a5954ed --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java @@ -0,0 +1,32 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Convert; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; + +import com.baeldung.hibernate.converters.PersonNameConverter; + +@Entity(name = "PersonTable") +public class Person { + + @Id + @GeneratedValue + private Long id; + + @Convert(converter = PersonNameConverter.class) + private PersonName personName; + + public PersonName getPersonName() { + return personName; + } + + public void setPersonName(PersonName personName) { + this.personName = personName; + } + + public Long getId() { + return id; + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java new file mode 100644 index 0000000000..335fe73f75 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java @@ -0,0 +1,29 @@ +package com.baeldung.hibernate.pojo; + +import java.io.Serializable; + +public class PersonName implements Serializable { + + private static final long serialVersionUID = 7883094644631050150L; + + private String name; + + private String surname; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getSurname() { + return surname; + } + + public void setSurname(String surname) { + this.surname = surname; + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java new file mode 100644 index 0000000000..25e51e35d0 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java @@ -0,0 +1,59 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "posts") +public class Post { + + @Id + @GeneratedValue + private int id; + + private String title; + + private String body; + + public Post() { } + + public Post(String title, String body) { + this.title = title; + this.body = body; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getBody() { + return body; + } + + public void setBody(String body) { + this.body = body; + } + + @Override + public String toString() { + return "Post{" + + "id=" + id + + ", title='" + title + '\'' + + ", body='" + body + '\'' + + '}'; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java new file mode 100644 index 0000000000..9b26c117eb --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long studentId; + + private String name; + + private int age; + + public Student() { + } + + public Student(String name, int age) { + this.name = name; + this.age = age; + } + + public long getStudentId() { + return studentId; + } + + public void setStudentId(long studentId) { + this.studentId = studentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java new file mode 100644 index 0000000000..5a4eb20079 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java @@ -0,0 +1,29 @@ +package com.baeldung.hibernate.transaction; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.query.Query; + +public class PostService { + + + private Session session; + + public PostService(Session session) { + this.session = session; + } + + + public void updatePost(String title, String body, int id) { + Transaction txn = session.beginTransaction(); + Query updateQuery = session.createQuery("UPDATE Post p SET p.title = ?1, p.body = ?2 WHERE p.id = ?3"); + updateQuery.setParameter(1, title); + updateQuery.setParameter(2, body); + updateQuery.setParameter(3, id); + updateQuery.executeUpdate(); + txn.commit(); + } + + + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java new file mode 100644 index 0000000000..17fa582e10 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.persistencecontext; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages="com.baeldung.persistencecontext") +public class PersistenceContextDemoApplication { + public static void main(String[] args) { + SpringApplication.run(PersistenceContextDemoApplication.class, args); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java new file mode 100644 index 0000000000..7252ac46f5 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java @@ -0,0 +1,36 @@ +package com.baeldung.persistencecontext.entity; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class User { + + @Id + private Long id; + private String name; + private String role; + + public User() { + + } + + public User(Long id, String name, String role) { + this.id = id; + this.name = name; + this.role = role; + } + + public Long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getRole() { + return role; + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java new file mode 100644 index 0000000000..ef25aac69f --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java @@ -0,0 +1,33 @@ +package com.baeldung.persistencecontext.service; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.PersistenceContextType; +import javax.transaction.Transactional; + +import org.springframework.stereotype.Component; + +import com.baeldung.persistencecontext.entity.User; + +@Component +public class ExtendedPersistenceContextUserService { + + @PersistenceContext(type = PersistenceContextType.EXTENDED) + private EntityManager entityManager; + + @Transactional + public User insertWithTransaction(User user) { + entityManager.persist(user); + return user; + } + + public User insertWithoutTransaction(User user) { + entityManager.persist(user); + return user; + } + + public User find(long id) { + User user = entityManager.find(User.class, id); + return user; + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java new file mode 100644 index 0000000000..481defcf08 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java @@ -0,0 +1,32 @@ +package com.baeldung.persistencecontext.service; + + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.transaction.Transactional; + +import org.springframework.stereotype.Component; + +import com.baeldung.persistencecontext.entity.User; + +@Component +public class TransctionPersistenceContextUserService { + + @PersistenceContext + private EntityManager entityManager; + + @Transactional + public User insertWithTransaction(User user) { + entityManager.persist(user); + return user; + } + + public User insertWithoutTransaction(User user) { + entityManager.persist(user); + return user; + } + + public User find(long id) { + return entityManager.find(User.class, id); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate5-jpa/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..4dfade1af3 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,19 @@ + + + + Hibernate EntityManager Demo + com.baeldung.hibernate.pojo.Movie + true + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/resources/init_database.sql b/persistence-modules/hibernate5-jpa/src/main/resources/init_database.sql new file mode 100644 index 0000000000..b2848aa256 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/resources/init_database.sql @@ -0,0 +1,10 @@ +CREATE ALIAS UPDATE_EMPLOYEE_DESIGNATION AS $$ +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +@CODE +void updateEmployeeDesignation(final Connection conn, final String employeeNumber, final String title) throws SQLException { + CallableStatement updateStatement = conn.prepareCall("update deptemployee set title = '" + title + "' where employeeNumber = '" + employeeNumber + "'"); + updateStatement.execute(); +} +$$; \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/main/resources/logback.xml b/persistence-modules/hibernate5-jpa/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java new file mode 100644 index 0000000000..3cd4761a7b --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java @@ -0,0 +1,200 @@ +package com.baeldung.hibernate.converter; + +import java.io.IOException; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.pojo.Person; +import com.baeldung.hibernate.pojo.PersonName; + +import static org.junit.Assert.assertEquals; + +public class PersonNameConverterUnitTest { + + private Session session; + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory() + .openSession(); + transaction = session.beginTransaction(); + + session.createNativeQuery("delete from personTable") + .executeUpdate(); + + transaction.commit(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenPersonName_WhenSaving_ThenNameAndSurnameConcat() { + final String name = "name"; + final String surname = "surname"; + + PersonName personName = new PersonName(); + personName.setName(name); + personName.setSurname(surname); + + Person person = new Person(); + person.setPersonName(personName); + + Long id = (Long) session.save(person); + + session.flush(); + session.clear(); + + String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") + .setParameter("id", id) + .getSingleResult(); + + assertEquals(surname + ", " + name, dbPersonName); + + Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) + .setParameter("id", id) + .getSingleResult(); + + assertEquals(dbPerson.getPersonName() + .getName(), name); + assertEquals(dbPerson.getPersonName() + .getSurname(), surname); + } + + @Test + public void givenPersonNameNull_WhenSaving_ThenNullStored() { + final String name = null; + final String surname = null; + + PersonName personName = new PersonName(); + personName.setName(name); + personName.setSurname(surname); + + Person person = new Person(); + person.setPersonName(personName); + + Long id = (Long) session.save(person); + + session.flush(); + session.clear(); + + String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") + .setParameter("id", id) + .getSingleResult(); + + assertEquals("", dbPersonName); + + Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) + .setParameter("id", id) + .getSingleResult(); + + assertEquals(dbPerson.getPersonName(), null); + } + + @Test + public void givenPersonNameWithoutName_WhenSaving_ThenNotNameStored() { + final String name = null; + final String surname = "surname"; + + PersonName personName = new PersonName(); + personName.setName(name); + personName.setSurname(surname); + + Person person = new Person(); + person.setPersonName(personName); + + Long id = (Long) session.save(person); + + session.flush(); + session.clear(); + + String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") + .setParameter("id", id) + .getSingleResult(); + + assertEquals("surname, ", dbPersonName); + + Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) + .setParameter("id", id) + .getSingleResult(); + + assertEquals(dbPerson.getPersonName() + .getName(), name); + assertEquals(dbPerson.getPersonName() + .getSurname(), surname); + } + + @Test + public void givenPersonNameWithoutSurName_WhenSaving_ThenNotSurNameStored() { + final String name = "name"; + final String surname = null; + + PersonName personName = new PersonName(); + personName.setName(name); + personName.setSurname(surname); + + Person person = new Person(); + person.setPersonName(personName); + + Long id = (Long) session.save(person); + + session.flush(); + session.clear(); + + String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") + .setParameter("id", id) + .getSingleResult(); + + assertEquals("name", dbPersonName); + + Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) + .setParameter("id", id) + .getSingleResult(); + + assertEquals(dbPerson.getPersonName() + .getName(), name); + assertEquals(dbPerson.getPersonName() + .getSurname(), surname); + } + + @Test + public void givenPersonNameEmptyFields_WhenSaving_ThenFielsNotStored() { + final String name = ""; + final String surname = ""; + + PersonName personName = new PersonName(); + personName.setName(name); + personName.setSurname(surname); + + Person person = new Person(); + person.setPersonName(personName); + + Long id = (Long) session.save(person); + + session.flush(); + session.clear(); + + String dbPersonName = (String) session.createNativeQuery("select p.personName from PersonTable p where p.id = :id") + .setParameter("id", id) + .getSingleResult(); + + assertEquals("", dbPersonName); + + Person dbPerson = session.createNativeQuery("select * from PersonTable p where p.id = :id", Person.class) + .setParameter("id", id) + .getSingleResult(); + + assertEquals(dbPerson.getPersonName(), null); + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java new file mode 100644 index 0000000000..2b12734a10 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java @@ -0,0 +1,121 @@ +package com.baeldung.hibernate.jpacriteriabuilder; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +import javax.persistence.EntityManager; + +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.entities.Department; +import com.baeldung.hibernate.entities.DeptEmployee; +import com.baeldung.hibernate.jpacriteriabuilder.service.EmployeeSearchService; +import com.baeldung.hibernate.jpacriteriabuilder.service.EmployeeSearchServiceImpl; + +public class EmployeeSearchServiceIntegrationTest { + + private EntityManager entityManager; + private EmployeeSearchService searchService; + private Session session; + + @Before + public final void setup() throws HibernateException, IOException { + session = HibernateUtil.getSessionFactory() + .openSession(); + entityManager = session.getEntityManagerFactory() + .createEntityManager(); + searchService = new EmployeeSearchServiceImpl(entityManager); + + entityManager.getTransaction() + .begin(); + Department department = new Department("Pre Sales"); + DeptEmployee employee = new DeptEmployee("John Smith", "001", "Manager", department); + entityManager.persist(department); + entityManager.persist(employee); + employee = new DeptEmployee("Ian Evans", "002", "Associate", department); + entityManager.persist(department); + entityManager.persist(employee); + department = new Department("Copporate Sales"); + employee = new DeptEmployee("Robert Carter", "003", "Manager", department); + entityManager.persist(department); + entityManager.persist(employee); + employee = new DeptEmployee("John Carter", "004", "Senior Manager", department); + entityManager.persist(employee); + employee = new DeptEmployee("David Guetta", "009", "Associate", department); + entityManager.persist(department); + entityManager.persist(employee); + department = new Department("Post Sales"); + employee = new DeptEmployee("Robert Jonas", "005", "Director", department); + entityManager.persist(department); + entityManager.persist(employee); + employee = new DeptEmployee("John Ferros", "006", "Junior Associate", department); + entityManager.persist(department); + entityManager.persist(employee); + department = new Department("Client Support"); + employee = new DeptEmployee("Robert Mcclements", "007", "Director", department); + entityManager.persist(department); + entityManager.persist(employee); + employee = new DeptEmployee("Peter Parker", "008", "Manager", department); + entityManager.persist(department); + entityManager.persist(employee); + + } + + @After + public final void teardown() { + entityManager.getTransaction() + .rollback(); + entityManager.close(); + } + + @Test + public final void givenCriteriaQuery_whenSearchedUsingCriteriaBuilderWithListofAuthors_thenResultIsFilteredByAuthorNames() { + List titles = new ArrayList() { + { + add("Manager"); + add("Senior Manager"); + add("Director"); + } + }; + List result = searchService.filterbyTitleUsingCriteriaBuilder(titles); + assertEquals("Number of Employees does not match with expected.", 6, result.size()); + assertThat(result.stream() + .map(DeptEmployee::getTitle) + .distinct() + .collect(Collectors.toList()), containsInAnyOrder(titles.toArray())); + } + + @Test + public final void givenCriteriaQuery_whenSearchedUsingExpressionWithListofAuthors_thenResultIsFilteredByAuthorNames() { + List titles = new ArrayList() { + { + add("Manager"); + add("Senior Manager"); + add("Director"); + } + }; + List result = searchService.filterbyTitleUsingExpression(titles); + assertEquals("Number of Employees does not match with expected.", 6, result.size()); + assertThat(result.stream() + .map(DeptEmployee::getTitle) + .distinct() + .collect(Collectors.toList()), containsInAnyOrder(titles.toArray())); + } + + @Test + public final void givenCriteriaQuery_whenSearchedDepartmentLike_thenResultIsFilteredByDepartment() { + List result = searchService.searchByDepartmentQuery("Sales"); + assertEquals("Number of Employees does not match with expected.", 7, result.size()); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java new file mode 100644 index 0000000000..475c93f6ff --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java @@ -0,0 +1,80 @@ +package com.baeldung.hibernate.onetoone; + +import com.baeldung.hibernate.onetoone.foreignkeybased.Address; +import com.baeldung.hibernate.onetoone.foreignkeybased.User; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class HibernateOneToOneAnnotationFKBasedIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.FOREIGN_KEY); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsert_thenCreates1to1relationship() { + User user = new User(); + user.setUserName("alice@baeldung.com"); + + Address address = new Address(); + address.setStreet("FK Street"); + address.setCity("FK City"); + + address.setUser(user); + user.setAddress(address); + + //Address entry will automatically be created by hibernate, since cascade type is specified as ALL + session.persist(user); + session.getTransaction().commit(); + + assert1to1InsertedData(); + } + + private void assert1to1InsertedData() { + @SuppressWarnings("unchecked") + List userList = session.createQuery("FROM User").list(); + + assertNotNull(userList); + assertEquals(1, userList.size()); + + User user = userList.get(0); + assertEquals("alice@baeldung.com", user.getUserName()); + + Address address = user.getAddress(); + assertNotNull(address); + assertEquals("FK Street", address.getStreet()); + assertEquals("FK City", address.getCity()); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java new file mode 100644 index 0000000000..df4cd4d137 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java @@ -0,0 +1,80 @@ +package com.baeldung.hibernate.onetoone; + +import com.baeldung.hibernate.onetoone.jointablebased.Employee; +import com.baeldung.hibernate.onetoone.jointablebased.WorkStation; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class HibernateOneToOneAnnotationJTBasedIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.JOIN_TABLE_BASED); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsert_thenCreates1to1relationship() { + Employee employee = new Employee(); + employee.setName("bob@baeldung.com"); + + WorkStation workStation = new WorkStation(); + workStation.setWorkstationNumber(626); + workStation.setFloor("Sixth Floor"); + + + employee.setWorkStation(workStation); + workStation.setEmployee(employee); + + session.persist(employee); + session.getTransaction().commit(); + + assert1to1InsertedData(); + } + + private void assert1to1InsertedData() { + @SuppressWarnings("unchecked") + List employeeList = session.createQuery("FROM Employee").list(); + assertNotNull(employeeList); + assertEquals(1, employeeList.size()); + + Employee employee = employeeList.get(0); + assertEquals("bob@baeldung.com", employee.getName()); + + WorkStation workStation = employee.getWorkStation(); + + assertNotNull(workStation); + assertEquals((long) 626, (long) workStation.getWorkstationNumber()); + assertEquals("Sixth Floor", workStation.getFloor()); + + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java new file mode 100644 index 0000000000..7931a8e3fe --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java @@ -0,0 +1,79 @@ +package com.baeldung.hibernate.onetoone; + +import com.baeldung.hibernate.onetoone.sharedkeybased.Address; +import com.baeldung.hibernate.onetoone.sharedkeybased.User; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class HibernateOneToOneAnnotationSPKBasedIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() { + sessionFactory = HibernateUtil.getSessionFactory(Strategy.SHARED_PRIMARY_KEY); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenData_whenInsert_thenCreates1to1relationship() { + User user = new User(); + user.setUserName("alice@baeldung.com"); + + Address address = new Address(); + address.setStreet("SPK Street"); + address.setCity("SPK City"); + + address.setUser(user); + user.setAddress(address); + + //Address entry will automatically be created by hibernate, since cascade type is specified as ALL + session.persist(user); + session.getTransaction().commit(); + + assert1to1InsertedData(); + } + + + private void assert1to1InsertedData() { + @SuppressWarnings("unchecked") + List userList = session.createQuery("FROM User").list(); + assertNotNull(userList); + assertEquals(1, userList.size()); + + User user = userList.get(0); + assertEquals("alice@baeldung.com", user.getUserName()); + + Address address = user.getAddress(); + assertNotNull(address); + assertEquals("SPK Street", address.getStreet()); + assertEquals("SPK City", address.getCity()); + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java new file mode 100644 index 0000000000..37c490f297 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java @@ -0,0 +1,146 @@ +package com.baeldung.hibernate.optimisticlocking; + +import java.io.IOException; +import java.util.Arrays; + +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; +import javax.persistence.OptimisticLockException; + +import org.hibernate.SessionFactory; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.HibernateUtil; + +public class OptimisticLockingIntegrationTest { + + private static SessionFactory sessionFactory; + + @Before + public void setUp() throws IOException { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + OptimisticLockingCourse course = new OptimisticLockingCourse(1L, "MATH"); + OptimisticLockingStudent student = new OptimisticLockingStudent(1L, "John", "Doe", Arrays.asList(course)); + course.setStudent(student); + entityManager.persist(course); + entityManager.persist(student); + entityManager.getTransaction() + .commit(); + entityManager.close(); + } + + @After + public void clean() throws IOException { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + OptimisticLockingCourse course = entityManager.find(OptimisticLockingCourse.class, 1L); + OptimisticLockingStudent student = entityManager.find(OptimisticLockingStudent.class, 1L); + entityManager.remove(course); + entityManager.remove(student); + entityManager.getTransaction() + .commit(); + entityManager.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntities_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntitiesWithLockByFindMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L, LockModeType.OPTIMISTIC); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L, LockModeType.OPTIMISTIC_FORCE_INCREMENT); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntitiesWithLockByRefreshMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); + em.refresh(student, LockModeType.OPTIMISTIC); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); + em.refresh(student, LockModeType.OPTIMISTIC_FORCE_INCREMENT); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + @Test(expected = OptimisticLockException.class) + public void givenVersionedEntitiesWithLockByLockMethod_whenConcurrentUpdate_thenOptimisticLockException() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student = em.find(OptimisticLockingStudent.class, 1L); + em.lock(student, LockModeType.OPTIMISTIC); + + EntityManager em2 = getEntityManagerWithOpenTransaction(); + OptimisticLockingStudent student2 = em2.find(OptimisticLockingStudent.class, 1L); + em.lock(student, LockModeType.OPTIMISTIC_FORCE_INCREMENT); + student2.setName("RICHARD"); + em2.persist(student2); + em2.getTransaction() + .commit(); + em2.close(); + + student.setName("JOHN"); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + } + + protected static EntityManager getEntityManagerWithOpenTransaction() throws IOException { + String propertyFileName = "hibernate-pessimistic-locking.properties"; + if (sessionFactory == null) { + sessionFactory = HibernateUtil.getSessionFactory(propertyFileName); + } + EntityManager entityManager = sessionFactory.openSession(); + entityManager.getTransaction().begin(); + + return entityManager; + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java new file mode 100644 index 0000000000..4b9c7720fd --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java @@ -0,0 +1,162 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import com.baeldung.hibernate.HibernateUtil; +import com.vividsolutions.jts.util.Assert; + +import org.hibernate.SessionFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.persistence.*; +import java.io.IOException; +import java.util.Arrays; + +public class BasicPessimisticLockingIntegrationTest { + + private static SessionFactory sessionFactory; + + @BeforeClass + public static void setUp() throws IOException { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent student = new PessimisticLockingStudent(1L, "JOHN"); + PessimisticLockingCourse course = new PessimisticLockingCourse(1L, "MATH", student); + student.setCourses(Arrays.asList(course)); + entityManager.persist(course); + entityManager.persist(student); + entityManager.getTransaction() + .commit(); + entityManager.close(); + } + + @Test + public void givenFoundRecordWithPessimisticRead_whenFindingNewOne_PessimisticLockExceptionThrown() { + try { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + entityManager.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_READ); + + EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); + entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_READ); + + entityManager.close(); + entityManager2.close(); + } catch (Exception e) { + Assert.isTrue(e instanceof PessimisticLockException); + } + } + + @Test + public void givenRecordWithPessimisticReadQuery_whenQueryingNewOne_PessimisticLockExceptionThrown() throws IOException { + try { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + Query query = entityManager.createQuery("from Student where studentId = :studentId"); + query.setParameter("studentId", 1L); + query.setLockMode(LockModeType.PESSIMISTIC_WRITE); + query.getResultList(); + + EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); + Query query2 = entityManager2.createQuery("from Student where studentId = :studentId"); + query2.setParameter("studentId", 1L); + query2.setLockMode(LockModeType.PESSIMISTIC_READ); + query2.getResultList(); + + entityManager.close(); + entityManager2.close(); + } catch (Exception e) { + Assert.isTrue(e instanceof PessimisticLockException); + } + } + + @Test + public void givenRecordWithPessimisticReadLock_whenFindingNewOne_PessimisticLockExceptionThrown() { + try { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); + entityManager.lock(resultStudent, LockModeType.PESSIMISTIC_READ); + + EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); + entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_FORCE_INCREMENT); + + entityManager.close(); + entityManager2.close(); + } catch (Exception e) { + Assert.isTrue(e instanceof PessimisticLockException); + } + } + + @Test + public void givenRecordAndRefreshWithPessimisticRead_whenFindingWithPessimisticWrite_PessimisticLockExceptionThrown() { + try { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); + entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_FORCE_INCREMENT); + + EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); + entityManager2.find(PessimisticLockingStudent.class, 1L, LockModeType.PESSIMISTIC_WRITE); + + entityManager.close(); + entityManager2.close(); + } catch (Exception e) { + Assert.isTrue(e instanceof PessimisticLockException); + } + } + + @Test + public void givenRecordWithPessimisticRead_whenUpdatingRecord_PessimisticLockExceptionThrown() { + try { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); + entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_READ); + + EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent resultStudent2 = entityManager2.find(PessimisticLockingStudent.class, 1L); + resultStudent2.setName("Change"); + entityManager2.persist(resultStudent2); + entityManager2.getTransaction() + .commit(); + + entityManager.close(); + entityManager2.close(); + } catch (Exception e) { + Assert.isTrue(e instanceof PessimisticLockException); + } + } + + @Test + public void givenRecordWithPessimisticWrite_whenUpdatingRecord_PessimisticLockExceptionThrown() { + try { + EntityManager entityManager = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent resultStudent = entityManager.find(PessimisticLockingStudent.class, 1L); + entityManager.refresh(resultStudent, LockModeType.PESSIMISTIC_WRITE); + + EntityManager entityManager2 = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent resultStudent2 = entityManager2.find(PessimisticLockingStudent.class, 1L); + resultStudent2.setName("Change"); + entityManager2.persist(resultStudent2); + entityManager2.getTransaction() + .commit(); + + entityManager.close(); + entityManager2.close(); + } catch (Exception e) { + Assert.isTrue(e instanceof PessimisticLockException); + } + } + + protected static EntityManager getEntityManagerWithOpenTransaction() throws IOException { + String propertyFileName = "hibernate-pessimistic-locking.properties"; + if (sessionFactory == null) { + sessionFactory = HibernateUtil.getSessionFactory(propertyFileName); + } + EntityManager entityManager = sessionFactory.openSession(); + entityManager.getTransaction().begin(); + + return entityManager; + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java new file mode 100644 index 0000000000..81cb7d95f8 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java @@ -0,0 +1,125 @@ +package com.baeldung.hibernate.pessimisticlocking; + +import com.baeldung.hibernate.HibernateUtil; + +import org.hibernate.SessionFactory; +import org.junit.AfterClass; +import org.junit.Test; + +import javax.persistence.EntityManager; +import javax.persistence.LockModeType; +import javax.persistence.PessimisticLockScope; +import java.io.IOException; +import java.math.BigDecimal; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class PessimisticLockScopesIntegrationTest { + + private static SessionFactory sessionFactory; + + @Test + public void givenEclipseEntityWithJoinInheritance_whenNormalLock_thenShouldChildAndParentEntity() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + PessimisticLockingEmployee employee = new PessimisticLockingEmployee(1L, "JOHN", "SMITH", new BigDecimal(4.5)); + em.persist(employee); + em.getTransaction() + .commit(); + em.close(); + + // NORMAL SCOPE + EntityManager em2 = getEntityManagerWithOpenTransaction(); + PessimisticLockingEmployee foundEmployee = em2.find(PessimisticLockingEmployee.class, 1L, LockModeType.PESSIMISTIC_WRITE); + em2.getTransaction() + .rollback(); + + // EXTENDED SCOPE + Map map = new HashMap<>(); + map.put("javax.persistence.lock.scope", PessimisticLockScope.EXTENDED); + + EntityManager em3 = getEntityManagerWithOpenTransaction(); + foundEmployee = em3.find(PessimisticLockingEmployee.class, 1L, LockModeType.PESSIMISTIC_WRITE, map); + em3.getTransaction() + .rollback(); + + em2.close(); + em3.close(); + } + + @Test + public void givenEntityWithElementCollection_whenLock_thenHibernateExtendedScopeLockOnlyOwningEntity() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + Address address = new Address("Poland", "Warsaw"); + Customer customer = new Customer(1L, "JOE", "DOE", Arrays.asList(address)); + em.persist(customer); + em.getTransaction() + .commit(); + em.close(); + + // NORMAL SCOPE + EntityManager em2 = getEntityManagerWithOpenTransaction(); + Customer foundCustomer = em2.find(Customer.class, 1L, LockModeType.PESSIMISTIC_WRITE); + em2.getTransaction() + .rollback(); + + // EXTENDED SCOPE + Map map = new HashMap<>(); + map.put("javax.persistence.lock.scope", PessimisticLockScope.EXTENDED); + + EntityManager em3 = getEntityManagerWithOpenTransaction(); + foundCustomer = em3.find(Customer.class, 1L, LockModeType.PESSIMISTIC_WRITE, map); + em2.getTransaction() + .rollback(); + + em2.close(); + em3.close(); + } + + @Test + public void givenEntityWithOneToMany_whenLock_thenHibernateExtendedScopeLockOnlyOwningEntity() throws IOException { + EntityManager em = getEntityManagerWithOpenTransaction(); + PessimisticLockingStudent student = new PessimisticLockingStudent(1L, "JOE"); + PessimisticLockingCourse course = new PessimisticLockingCourse(1L, "COURSE", student); + student.setCourses(Arrays.asList(course)); + em.persist(course); + em.persist(student); + em.getTransaction() + .commit(); + em.close(); + + // NORMAL SCOPE + EntityManager em2 = getEntityManagerWithOpenTransaction(); + PessimisticLockingCourse foundCourse = em2.find(PessimisticLockingCourse.class, 1L, LockModeType.PESSIMISTIC_WRITE); + em2.getTransaction() + .rollback(); + + // EXTENDED SCOPE + Map map = new HashMap<>(); + map.put("javax.persistence.lock.scope", PessimisticLockScope.EXTENDED); + + EntityManager em3 = getEntityManagerWithOpenTransaction(); + foundCourse = em3.find(PessimisticLockingCourse.class, 1L, LockModeType.PESSIMISTIC_WRITE, map); + em3.getTransaction() + .rollback(); + + em2.close(); + em3.close(); + } + + protected EntityManager getEntityManagerWithOpenTransaction() throws IOException { + String propertyFileName = "hibernate-pessimistic-locking.properties"; + if (sessionFactory == null) { + sessionFactory = HibernateUtil.getSessionFactory(propertyFileName); + } + EntityManager entityManager = sessionFactory.openSession(); + entityManager.getTransaction().begin(); + + return entityManager; + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java new file mode 100644 index 0000000000..246a7d59f9 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java @@ -0,0 +1,57 @@ +package com.baeldung.hibernate.transaction; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.pojo.Post; +import com.baeldung.hibernate.transaction.PostService; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Properties; + +import static org.junit.Assert.assertEquals; + +public class TransactionIntegrationTest { + + private static PostService postService; + private static Session session; + private static Logger logger = LoggerFactory.getLogger(TransactionIntegrationTest.class); + + @BeforeClass + public static void init() throws IOException { + Properties properties = new Properties(); + properties.setProperty("hibernate.connection.driver_class", "org.h2.Driver"); + properties.setProperty("hibernate.connection.url", "jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1"); + properties.setProperty("hibernate.connection.username", "sa"); + properties.setProperty("hibernate.show_sql", "true"); + properties.setProperty("jdbc.password", ""); + properties.setProperty("hibernate.dialect", "org.hibernate.dialect.H2Dialect"); + properties.setProperty("hibernate.hbm2ddl.auto", "create-drop"); + SessionFactory sessionFactory = HibernateUtil.getSessionFactoryByProperties(properties); + session = sessionFactory.openSession(); + postService = new PostService(session); + } + + @Test + public void givenTitleAndBody_whenRepositoryUpdatePost_thenUpdatePost() { + + Post post = new Post("This is a title", "This is a sample post"); + session.persist(post); + + String title = "[UPDATE] Java HowTos"; + String body = "This is an updated posts on Java how-tos"; + postService.updatePost(title, body, post.getId()); + + session.refresh(post); + + assertEquals(post.getTitle(), title); + assertEquals(post.getBody(), body); + } + + +} diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java new file mode 100644 index 0000000000..b299dd5834 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java @@ -0,0 +1,90 @@ +package com.baeldung.persistencecontext; + +import com.baeldung.persistencecontext.entity.User; +import com.baeldung.persistencecontext.service.ExtendedPersistenceContextUserService; +import com.baeldung.persistencecontext.service.TransctionPersistenceContextUserService; + +import javax.persistence.EntityExistsException; +import javax.persistence.TransactionRequiredException; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = com.baeldung.persistencecontext.PersistenceContextDemoApplication.class) +public class PersistenceContextIntegrationTest { + + @Autowired + private TransctionPersistenceContextUserService transctionPersistenceContext; + @Autowired + private ExtendedPersistenceContextUserService extendedPersistenceContext; + + @Test + public void testThatWhenUserSavedWithTransctionPersistenceContextThenUserShouldGetSavedInDB() { + User user = new User(121L, "Devender", "admin"); + transctionPersistenceContext.insertWithTransaction(user); + + User userFromTransctionPersistenceContext = transctionPersistenceContext.find(user.getId()); + assertNotNull(userFromTransctionPersistenceContext); + + User userFromExtendedPersistenceContext = extendedPersistenceContext.find(user.getId()); + assertNotNull(userFromExtendedPersistenceContext); + } + + @Test(expected = TransactionRequiredException.class) + public void testThatUserSaveWithoutTransactionThrowException() { + User user = new User(122L, "Devender", "admin"); + transctionPersistenceContext.insertWithoutTransaction(user); + } + + @Test + public void testThatWhenUserSavedWithExtendedPersistenceContextWithoutTransactionThenUserShouldGetCached() { + User user = new User(123L, "Devender", "admin"); + extendedPersistenceContext.insertWithoutTransaction(user); + + User userFromExtendedPersistenceContext = extendedPersistenceContext.find(user.getId()); + assertNotNull(userFromExtendedPersistenceContext); + + User userFromTransctionPersistenceContext = transctionPersistenceContext.find(user.getId()); + assertNull(userFromTransctionPersistenceContext); + } + + @Test(expected = EntityExistsException.class) + public void testThatPersistUserWithSameIdentifierThrowException() { + User user1 = new User(126L, "Devender", "admin"); + User user2 = new User(126L, "Devender", "admin"); + extendedPersistenceContext.insertWithoutTransaction(user1); + extendedPersistenceContext.insertWithoutTransaction(user2); + } + + @Test + public void testThatWhenUserSavedWithExtendedPersistenceContextWithTransactionThenUserShouldSaveEntityIntoDB() { + User user = new User(127L, "Devender", "admin"); + extendedPersistenceContext.insertWithTransaction(user); + + User userFromDB = transctionPersistenceContext.find(user.getId()); + assertNotNull(userFromDB); + } + + @Test + public void testThatWhenUserSavedWithExtendedPersistenceContextWithTransactionThenUserShouldFlushCachedEntityIntoDB() { + User user1 = new User(124L, "Devender", "admin"); + extendedPersistenceContext.insertWithoutTransaction(user1); + + User user2 = new User(125L, "Devender", "admin"); + extendedPersistenceContext.insertWithTransaction(user2); + + User user1FromTransctionPersistenceContext = transctionPersistenceContext.find(user1.getId()); + assertNotNull(user1FromTransctionPersistenceContext); + + User user2FromTransctionPersistenceContext = transctionPersistenceContext.find(user2.getId()); + assertNotNull(user2FromTransctionPersistenceContext); + } + +} diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-namedquery.properties b/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-namedquery.properties new file mode 100644 index 0000000000..457f965347 --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-namedquery.properties @@ -0,0 +1,9 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'src/main/resources/init_database.sql' +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-pessimistic-locking.properties b/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-pessimistic-locking.properties new file mode 100644 index 0000000000..4f1ff5e93a --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-pessimistic-locking.properties @@ -0,0 +1,8 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb3;DB_CLOSE_DELAY=-1;LOCK_TIMEOUT=100;MVCC=FALSE +hibernate.connection.username=sa +hibernate.connection.autocommit=true +hibernate.dialect=org.hibernate.dialect.H2Dialect + +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/hibernate.properties b/persistence-modules/hibernate5-jpa/src/test/resources/hibernate.properties new file mode 100644 index 0000000000..c14782ce0f --- /dev/null +++ b/persistence-modules/hibernate5-jpa/src/test/resources/hibernate.properties @@ -0,0 +1,14 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/profile.png b/persistence-modules/hibernate5-jpa/src/test/resources/profile.png new file mode 100644 index 0000000000000000000000000000000000000000..1cd4e978b96d0f59a6e48692fcb68d1c6c565a20 GIT binary patch literal 1117 zcmV-j1fu(iP)%yyh@V&OYl(_AFwE`D&8)` zPnvkdvc#Z>pRh2kBHk{=qaGfCG;?<;rVe;D+%LyZS~!K}c+|op81YK@rzPHU@Th|m z4Dk`HcojTY;+}_-W%HGqKH@C!LiH8Tp>1lC@aTqoy zBU~QK<}hs@q|M8($ee`o<9#`B3-PL4Y7d9kW#<;n>t}6VNpYCswLrJTtEa_lFwgN$52-_vxvvfJs@B6-OYs%-@M_JTx*UfozG6(Bhs)>w z!pG%vU$b%f++EGa<#Tu1FZ^c#{;G|y5=kM3Y#X^mtSrFA_-o-vX7e_$5-udx(>S4U)i|4)(UJ~zR(vwE+6VTAzoo7wIS|c zh*yt`3wK%<+yX~Z9G1z2GQgf3~qx jc9u$WjpqGof00000NkvXXu0mjfJX<<= literal 0 HcmV?d00001 From 9f8e1b51b3d5fad0f3499120e2bd41a96c0de3c2 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:20:46 +0530 Subject: [PATCH 030/278] JAVA-4 : added new module hibernate5-mapping --- .../hibernate5-mapping/README.md | 11 + .../hibernate5-mapping/pom.xml | 76 +++++++ .../com/baeldung/hibernate/HibernateUtil.java | 96 +++++++++ .../hibernate/entities/Department.java | 45 ++++ .../hibernate/entities/DeptEmployee.java | 83 ++++++++ .../hibernate/lob/HibernateSessionUtil.java | 61 ++++++ .../baeldung/hibernate/lob/model/User.java | 46 +++++ .../com/baeldung/hibernate/pojo/Employee.java | 87 ++++++++ .../hibernate/pojo/EntityDescription.java | 55 +++++ .../com/baeldung/hibernate/pojo/Phone.java | 50 +++++ .../com/baeldung/hibernate/pojo/Result.java | 31 +++ .../hibernate/pojo/TemporalValues.java | 195 ++++++++++++++++++ .../hibernate/pojo/generator/MyGenerator.java | 41 ++++ .../hibernate/pojo/inheritance/Animal.java | 40 ++++ .../hibernate/pojo/inheritance/Bag.java | 38 ++++ .../hibernate/pojo/inheritance/Book.java | 27 +++ .../hibernate/pojo/inheritance/Car.java | 25 +++ .../hibernate/pojo/inheritance/Item.java | 5 + .../pojo/inheritance/MyEmployee.java | 22 ++ .../hibernate/pojo/inheritance/MyProduct.java | 47 +++++ .../hibernate/pojo/inheritance/Pen.java | 27 +++ .../hibernate/pojo/inheritance/Person.java | 38 ++++ .../hibernate/pojo/inheritance/Pet.java | 27 +++ .../hibernate/pojo/inheritance/Vehicle.java | 40 ++++ .../baeldung/hibernate/pojo/package-info.java | 9 + .../main/resources/META-INF/persistence.xml | 18 ++ .../src/main/resources/logback.xml | 13 ++ .../hibernate/CustomClassIntegrationTest.java | 78 +++++++ .../DynamicMappingIntegrationTest.java | 160 ++++++++++++++ .../InheritanceMappingIntegrationTest.java | 89 ++++++++ .../hibernate/TemporalValuesUnitTest.java | 128 ++++++++++++ .../baeldung/hibernate/lob/LobUnitTest.java | 61 ++++++ .../src/test/resources/hibernate.properties | 14 ++ .../src/test/resources/lifecycle-init.sql | 25 +++ .../src/test/resources/profile.png | Bin 0 -> 1117 bytes 35 files changed, 1808 insertions(+) create mode 100644 persistence-modules/hibernate5-mapping/README.md create mode 100644 persistence-modules/hibernate5-mapping/pom.xml create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java create mode 100644 persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml create mode 100644 persistence-modules/hibernate5-mapping/src/main/resources/logback.xml create mode 100644 persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java create mode 100644 persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java create mode 100644 persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java create mode 100644 persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java create mode 100644 persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java create mode 100644 persistence-modules/hibernate5-mapping/src/test/resources/hibernate.properties create mode 100644 persistence-modules/hibernate5-mapping/src/test/resources/lifecycle-init.sql create mode 100644 persistence-modules/hibernate5-mapping/src/test/resources/profile.png diff --git a/persistence-modules/hibernate5-mapping/README.md b/persistence-modules/hibernate5-mapping/README.md new file mode 100644 index 0000000000..f18b0b63de --- /dev/null +++ b/persistence-modules/hibernate5-mapping/README.md @@ -0,0 +1,11 @@ +## Hibernate 5 + +This module contains articles about Hibernate 5. + +### Relevant articles: + +- [Dynamic Mapping with Hibernate](http://www.baeldung.com/hibernate-dynamic-mapping) +- [Hibernate Inheritance Mapping](http://www.baeldung.com/hibernate-inheritance) +- [Mapping A Hibernate Query to a Custom Class](https://www.baeldung.com/hibernate-query-to-custom-class) +- [Hibernate – Mapping Date and Time](http://www.baeldung.com/hibernate-date-time) +- [Mapping LOB Data in Hibernate](http://www.baeldung.com/hibernate-lob) \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/pom.xml b/persistence-modules/hibernate5-mapping/pom.xml new file mode 100644 index 0000000000..59e0547671 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/pom.xml @@ -0,0 +1,76 @@ + + + 4.0.0 + hibernate5-mapping + 0.0.1-SNAPSHOT + hibernate5-mapping + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + com.h2database + h2 + ${h2.version} + + + org.hibernate + hibernate-spatial + ${hibernate.version} + + + org.opengeo + geodb + ${geodb.version} + + + mysql + mysql-connector-java + ${mysql.version} + + + ch.vorburger.mariaDB4j + mariaDB4j + ${mariaDB4j.version} + + + org.hibernate + hibernate-testing + ${hibernate.version} + + + + + + geodb-repo + GeoDB repository + http://repo.boundlessgeo.com/main/ + + + + + 5.3.7.Final + 6.0.6 + 2.2.3 + 3.8.0 + 0.9 + + + diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java new file mode 100644 index 0000000000..28e1af49ed --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -0,0 +1,96 @@ +package com.baeldung.hibernate; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.entities.DeptEmployee; +import com.baeldung.hibernate.pojo.Employee; +import com.baeldung.hibernate.pojo.EntityDescription; +import com.baeldung.hibernate.pojo.Phone; +import com.baeldung.hibernate.pojo.TemporalValues; +import com.baeldung.hibernate.pojo.inheritance.Animal; +import com.baeldung.hibernate.pojo.inheritance.Bag; +import com.baeldung.hibernate.pojo.inheritance.Book; +import com.baeldung.hibernate.pojo.inheritance.Car; +import com.baeldung.hibernate.pojo.inheritance.MyEmployee; +import com.baeldung.hibernate.pojo.inheritance.MyProduct; +import com.baeldung.hibernate.pojo.inheritance.Pen; +import com.baeldung.hibernate.pojo.inheritance.Pet; +import com.baeldung.hibernate.pojo.inheritance.Vehicle; + +public class HibernateUtil { + private static String PROPERTY_FILE_NAME; + + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(null); + } + + public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { + PROPERTY_FILE_NAME = propertyFileName; + ServiceRegistry serviceRegistry = configureServiceRegistry(); + return makeSessionFactory(serviceRegistry); + } + + public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException { + ServiceRegistry serviceRegistry = configureServiceRegistry(properties); + return makeSessionFactory(serviceRegistry); + } + + private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + metadataSources.addPackage("com.baeldung.hibernate.pojo"); + metadataSources.addAnnotatedClass(Employee.class); + metadataSources.addAnnotatedClass(Phone.class); + metadataSources.addAnnotatedClass(EntityDescription.class); + metadataSources.addAnnotatedClass(TemporalValues.class); + metadataSources.addAnnotatedClass(DeptEmployee.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); + metadataSources.addAnnotatedClass(Animal.class); + metadataSources.addAnnotatedClass(Bag.class); + metadataSources.addAnnotatedClass(Book.class); + metadataSources.addAnnotatedClass(Car.class); + metadataSources.addAnnotatedClass(MyEmployee.class); + metadataSources.addAnnotatedClass(MyProduct.class); + metadataSources.addAnnotatedClass(Pen.class); + metadataSources.addAnnotatedClass(Pet.class); + metadataSources.addAnnotatedClass(Vehicle.class); + + + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + + } + + private static ServiceRegistry configureServiceRegistry() throws IOException { + return configureServiceRegistry(getProperties()); + } + + private static ServiceRegistry configureServiceRegistry(Properties properties) throws IOException { + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + public static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java new file mode 100644 index 0000000000..ff94f4f849 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java @@ -0,0 +1,45 @@ +package com.baeldung.hibernate.entities; + +import java.util.List; + +import javax.persistence.*; + +@Entity +public class Department { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @OneToMany(mappedBy="department") + private List employees; + + public Department(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getEmployees() { + return employees; + } + + public void setEmployees(List employees) { + this.employees = employees; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java new file mode 100644 index 0000000000..6510e70650 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java @@ -0,0 +1,83 @@ +package com.baeldung.hibernate.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@org.hibernate.annotations.NamedQueries({ @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindByEmployeeNumber", query = "from DeptEmployee where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDesgination", query = "from DeptEmployee where designation = :designation"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_UpdateEmployeeDepartment", query = "Update DeptEmployee set department = :newDepartment where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDepartment", query = "from DeptEmployee where department = :department", timeout = 1, fetchSize = 10) }) +@org.hibernate.annotations.NamedNativeQueries({ @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_FindByEmployeeName", query = "select * from deptemployee emp where name=:name", resultClass = DeptEmployee.class), + @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_UpdateEmployeeDesignation", query = "call UPDATE_EMPLOYEE_DESIGNATION(:employeeNumber, :newDesignation)", resultClass = DeptEmployee.class) }) +@Entity +public class DeptEmployee { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String employeeNumber; + + private String title; + + private String name; + + @ManyToOne + private Department department; + + public DeptEmployee(String name, String employeeNumber, Department department) { + this.name = name; + this.employeeNumber = employeeNumber; + this.department = department; + } + + public DeptEmployee(String name, String employeeNumber, String title, Department department) { + super(); + this.name = name; + this.employeeNumber = employeeNumber; + this.title = title; + this.department = department; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getEmployeeNumber() { + return employeeNumber; + } + + public void setEmployeeNumber(String employeeNumber) { + this.employeeNumber = employeeNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java new file mode 100644 index 0000000000..dc5242ee7c --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java @@ -0,0 +1,61 @@ +package com.baeldung.hibernate.lob; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.lob.model.User; + +public class HibernateSessionUtil { + + private static SessionFactory sessionFactory; + private static String PROPERTY_FILE_NAME; + + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(null); + } + + public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { + PROPERTY_FILE_NAME = propertyFileName; + if (sessionFactory == null) { + ServiceRegistry serviceRegistry = configureServiceRegistry(); + sessionFactory = makeSessionFactory(serviceRegistry); + } + return sessionFactory; + } + + private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + metadataSources.addAnnotatedClass(User.class); + + Metadata metadata = metadataSources.buildMetadata(); + return metadata.getSessionFactoryBuilder() + .build(); + + } + + private static ServiceRegistry configureServiceRegistry() throws IOException { + Properties properties = getProperties(); + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + private static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java new file mode 100644 index 0000000000..21f725b388 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java @@ -0,0 +1,46 @@ +package com.baeldung.hibernate.lob.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Lob; +import javax.persistence.Table; + +@Entity +@Table(name="user") +public class User { + + @Id + private String id; + + @Column(name = "name", columnDefinition="VARCHAR(128)") + private String name; + + @Lob + @Column(name = "photo", columnDefinition="BLOB") + private byte[] photo; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public byte[] getPhoto() { + return photo; + } + + public void setPhoto(byte[] photo) { + this.photo = photo; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java new file mode 100644 index 0000000000..e9732b2b67 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java @@ -0,0 +1,87 @@ +package com.baeldung.hibernate.pojo; + +import org.hibernate.annotations.*; + +import javax.persistence.Entity; +import javax.persistence.*; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +@Entity +@Where(clause = "deleted = false") +@FilterDef(name = "incomeLevelFilter", parameters = @ParamDef(name = "incomeLimit", type = "int")) +@Filter(name = "incomeLevelFilter", condition = "grossIncome > :incomeLimit") +public class Employee implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private long grossIncome; + + private int taxInPercents; + + private boolean deleted; + + public long getTaxJavaWay() { + return grossIncome * taxInPercents / 100; + } + + @Formula("grossIncome * taxInPercents / 100") + private long tax; + + @OneToMany + @JoinColumn(name = "employee_id") + @Where(clause = "deleted = false") + private Set phones = new HashSet<>(0); + + public Employee() { + } + + public Employee(long grossIncome, int taxInPercents) { + this.grossIncome = grossIncome; + this.taxInPercents = taxInPercents; + } + + public Integer getId() { + return id; + } + + public long getGrossIncome() { + return grossIncome; + } + + public int getTaxInPercents() { + return taxInPercents; + } + + public long getTax() { + return tax; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setGrossIncome(long grossIncome) { + this.grossIncome = grossIncome; + } + + public void setTaxInPercents(int taxInPercents) { + this.taxInPercents = taxInPercents; + } + + public boolean getDeleted() { + return deleted; + } + + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + public Set getPhones() { + return phones; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java new file mode 100644 index 0000000000..131bb73a80 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java @@ -0,0 +1,55 @@ +package com.baeldung.hibernate.pojo; + +import org.hibernate.annotations.Any; + +import javax.persistence.*; +import java.io.Serializable; + +@Entity +public class EntityDescription implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private String description; + + @Any( + metaDef = "EntityDescriptionMetaDef", + metaColumn = @Column(name = "entity_type") + ) + @JoinColumn(name = "entity_id") + private Serializable entity; + + public EntityDescription() { + } + + public EntityDescription(String description, Serializable entity) { + this.description = description; + this.entity = entity; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public Serializable getEntity() { + return entity; + } + + public void setEntity(Serializable entity) { + this.entity = entity; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java new file mode 100644 index 0000000000..d923bda5de --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java @@ -0,0 +1,50 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import java.io.Serializable; + +@Entity +public class Phone implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + private boolean deleted; + + private String number; + + public Phone() { + } + + public Phone(String number) { + this.number = number; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public boolean isDeleted() { + return deleted; + } + + public void setDeleted(boolean deleted) { + this.deleted = deleted; + } + + public String getNumber() { + return number; + } + + public void setNumber(String number) { + this.number = number; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java new file mode 100644 index 0000000000..607269a267 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java @@ -0,0 +1,31 @@ +package com.baeldung.hibernate.pojo; + +public class Result { + private String employeeName; + + private String departmentName; + + public Result(String employeeName, String departmentName) { + this.employeeName = employeeName; + this.departmentName = departmentName; + } + + public Result() { + } + + public String getEmployeeName() { + return employeeName; + } + + public void setEmployeeName(String employeeName) { + this.employeeName = employeeName; + } + + public String getDepartmentName() { + return departmentName; + } + + public void setDepartmentName(String departmentName) { + this.departmentName = departmentName; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java new file mode 100644 index 0000000000..f3fe095cae --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java @@ -0,0 +1,195 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.*; +import java.io.Serializable; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; +import java.time.*; +import java.util.Calendar; + +@Entity +public class TemporalValues implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Basic + private java.sql.Date sqlDate; + + @Basic + private java.sql.Time sqlTime; + + @Basic + private java.sql.Timestamp sqlTimestamp; + + @Basic + @Temporal(TemporalType.DATE) + private java.util.Date utilDate; + + @Basic + @Temporal(TemporalType.TIME) + private java.util.Date utilTime; + + @Basic + @Temporal(TemporalType.TIMESTAMP) + private java.util.Date utilTimestamp; + + @Basic + @Temporal(TemporalType.DATE) + private java.util.Calendar calendarDate; + + @Basic + @Temporal(TemporalType.TIMESTAMP) + private java.util.Calendar calendarTimestamp; + + @Basic + private java.time.LocalDate localDate; + + @Basic + private java.time.LocalTime localTime; + + @Basic + private java.time.OffsetTime offsetTime; + + @Basic + private java.time.Instant instant; + + @Basic + private java.time.LocalDateTime localDateTime; + + @Basic + private java.time.OffsetDateTime offsetDateTime; + + @Basic + private java.time.ZonedDateTime zonedDateTime; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Date getSqlDate() { + return sqlDate; + } + + public void setSqlDate(Date sqlDate) { + this.sqlDate = sqlDate; + } + + public Time getSqlTime() { + return sqlTime; + } + + public void setSqlTime(Time sqlTime) { + this.sqlTime = sqlTime; + } + + public Timestamp getSqlTimestamp() { + return sqlTimestamp; + } + + public void setSqlTimestamp(Timestamp sqlTimestamp) { + this.sqlTimestamp = sqlTimestamp; + } + + public java.util.Date getUtilDate() { + return utilDate; + } + + public void setUtilDate(java.util.Date utilDate) { + this.utilDate = utilDate; + } + + public java.util.Date getUtilTime() { + return utilTime; + } + + public void setUtilTime(java.util.Date utilTime) { + this.utilTime = utilTime; + } + + public java.util.Date getUtilTimestamp() { + return utilTimestamp; + } + + public void setUtilTimestamp(java.util.Date utilTimestamp) { + this.utilTimestamp = utilTimestamp; + } + + public Calendar getCalendarDate() { + return calendarDate; + } + + public void setCalendarDate(Calendar calendarDate) { + this.calendarDate = calendarDate; + } + + public Calendar getCalendarTimestamp() { + return calendarTimestamp; + } + + public void setCalendarTimestamp(Calendar calendarTimestamp) { + this.calendarTimestamp = calendarTimestamp; + } + + public LocalDate getLocalDate() { + return localDate; + } + + public void setLocalDate(LocalDate localDate) { + this.localDate = localDate; + } + + public LocalTime getLocalTime() { + return localTime; + } + + public void setLocalTime(LocalTime localTime) { + this.localTime = localTime; + } + + public OffsetTime getOffsetTime() { + return offsetTime; + } + + public void setOffsetTime(OffsetTime offsetTime) { + this.offsetTime = offsetTime; + } + + public Instant getInstant() { + return instant; + } + + public void setInstant(Instant instant) { + this.instant = instant; + } + + public LocalDateTime getLocalDateTime() { + return localDateTime; + } + + public void setLocalDateTime(LocalDateTime localDateTime) { + this.localDateTime = localDateTime; + } + + public OffsetDateTime getOffsetDateTime() { + return offsetDateTime; + } + + public void setOffsetDateTime(OffsetDateTime offsetDateTime) { + this.offsetDateTime = offsetDateTime; + } + + public ZonedDateTime getZonedDateTime() { + return zonedDateTime; + } + + public void setZonedDateTime(ZonedDateTime zonedDateTime) { + this.zonedDateTime = zonedDateTime; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java new file mode 100644 index 0000000000..17ffe9b7e1 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java @@ -0,0 +1,41 @@ +package com.baeldung.hibernate.pojo.generator; + +import java.io.Serializable; +import java.util.Properties; +import java.util.stream.Stream; + +import org.hibernate.HibernateException; +import org.hibernate.MappingException; +import org.hibernate.engine.spi.SharedSessionContractImplementor; +import org.hibernate.id.Configurable; +import org.hibernate.id.IdentifierGenerator; +import org.hibernate.service.ServiceRegistry; +import org.hibernate.type.Type; + +public class MyGenerator implements IdentifierGenerator, Configurable { + + private String prefix; + + @Override + public Serializable generate(SharedSessionContractImplementor session, Object obj) throws HibernateException { + + String query = String.format("select %s from %s", + session.getEntityPersister(obj.getClass().getName(), obj).getIdentifierPropertyName(), + obj.getClass().getSimpleName()); + + Stream ids = session.createQuery(query).stream(); + + Long max = ids.map(o -> o.replace(prefix + "-", "")) + .mapToLong(Long::parseLong) + .max() + .orElse(0L); + + return prefix + "-" + (max + 1); + } + + @Override + public void configure(Type type, Properties properties, ServiceRegistry serviceRegistry) throws MappingException { + prefix = properties.getProperty("prefix"); + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java new file mode 100644 index 0000000000..6fe7f915fc --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java @@ -0,0 +1,40 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +@Entity +@Inheritance(strategy = InheritanceType.JOINED) +public class Animal { + + @Id + private long animalId; + + private String species; + + public Animal() {} + + public Animal(long animalId, String species) { + this.animalId = animalId; + this.species = species; + } + + public long getAnimalId() { + return animalId; + } + + public void setAnimalId(long animalId) { + this.animalId = animalId; + } + + public String getSpecies() { + return species; + } + + public void setSpecies(String species) { + this.species = species; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java new file mode 100644 index 0000000000..fa6e1b4bef --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java @@ -0,0 +1,38 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.Entity; +import javax.persistence.Id; + +import org.hibernate.annotations.Polymorphism; +import org.hibernate.annotations.PolymorphismType; + +@Entity +@Polymorphism(type = PolymorphismType.EXPLICIT) +public class Bag implements Item { + + @Id + private long bagId; + + private String type; + + public Bag(long bagId, String type) { + this.bagId = bagId; + this.type = type; + } + + public long getBagId() { + return bagId; + } + + public void setBagId(long bagId) { + this.bagId = bagId; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java new file mode 100644 index 0000000000..36ca8dd77c --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java @@ -0,0 +1,27 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity +@DiscriminatorValue("1") +public class Book extends MyProduct { + private String author; + + public Book() { + } + + public Book(long productId, String name, String author) { + super(productId, name); + this.author = author; + } + + public String getAuthor() { + return author; + } + + public void setAuthor(String author) { + this.author = author; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java new file mode 100644 index 0000000000..49d1f7749a --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java @@ -0,0 +1,25 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.Entity; + +@Entity +public class Car extends Vehicle { + private String engine; + + public Car() { + } + + public Car(long vehicleId, String manufacturer, String engine) { + super(vehicleId, manufacturer); + this.engine = engine; + } + + public String getEngine() { + return engine; + } + + public void setEngine(String engine) { + this.engine = engine; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java new file mode 100644 index 0000000000..9656030736 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java @@ -0,0 +1,5 @@ +package com.baeldung.hibernate.pojo.inheritance; + +public interface Item { + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java new file mode 100644 index 0000000000..9a6bce16cf --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java @@ -0,0 +1,22 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.Entity; + +@Entity +public class MyEmployee extends Person { + private String company; + + public MyEmployee(long personId, String name, String company) { + super(personId, name); + this.company = company; + } + + public String getCompany() { + return company; + } + + public void setCompany(String company) { + this.company = company; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java new file mode 100644 index 0000000000..13f04d8904 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java @@ -0,0 +1,47 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +import org.hibernate.annotations.DiscriminatorFormula; + +@Entity +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "product_type", discriminatorType = DiscriminatorType.INTEGER) +// @DiscriminatorFormula("case when author is not null then 1 else 2 end") +public class MyProduct { + @Id + private long productId; + + private String name; + + public MyProduct() { + } + + public MyProduct(long productId, String name) { + super(); + this.productId = productId; + this.name = name; + } + + public long getProductId() { + return productId; + } + + public void setProductId(long productId) { + this.productId = productId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java new file mode 100644 index 0000000000..32b77e52af --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java @@ -0,0 +1,27 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity +@DiscriminatorValue("2") +public class Pen extends MyProduct { + private String color; + + public Pen() { + } + + public Pen(long productId, String name, String color) { + super(productId, name); + this.color = color; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java new file mode 100644 index 0000000000..99084b88af --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java @@ -0,0 +1,38 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class Person { + + @Id + private long personId; + + private String name; + + public Person() { + } + + public Person(long personId, String name) { + this.personId = personId; + this.name = name; + } + + public long getPersonId() { + return personId; + } + + public void setPersonId(long personId) { + this.personId = personId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java new file mode 100644 index 0000000000..870b3cd684 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java @@ -0,0 +1,27 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.Entity; +import javax.persistence.PrimaryKeyJoinColumn; + +@Entity +@PrimaryKeyJoinColumn(name = "petId") +public class Pet extends Animal { + private String name; + + public Pet() { + } + + public Pet(long animalId, String species, String name) { + super(animalId, species); + this.name = name; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java new file mode 100644 index 0000000000..b2a920573e --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java @@ -0,0 +1,40 @@ +package com.baeldung.hibernate.pojo.inheritance; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +@Entity +@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) +public class Vehicle { + @Id + private long vehicleId; + + private String manufacturer; + + public Vehicle() { + } + + public Vehicle(long vehicleId, String manufacturer) { + this.vehicleId = vehicleId; + this.manufacturer = manufacturer; + } + + public long getVehicleId() { + return vehicleId; + } + + public void setVehicleId(long vehicleId) { + this.vehicleId = vehicleId; + } + + public String getManufacturer() { + return manufacturer; + } + + public void setManufacturer(String manufacturer) { + this.manufacturer = manufacturer; + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java new file mode 100644 index 0000000000..992cda7c1d --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java @@ -0,0 +1,9 @@ +@AnyMetaDef(name = "EntityDescriptionMetaDef", metaType = "string", idType = "int", + metaValues = { + @MetaValue(value = "Employee", targetEntity = Employee.class), + @MetaValue(value = "Phone", targetEntity = Phone.class) + }) +package com.baeldung.hibernate.pojo; + +import org.hibernate.annotations.AnyMetaDef; +import org.hibernate.annotations.MetaValue; \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..474eeb7a44 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,18 @@ + + + + Hibernate EntityManager Demo + true + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/src/main/resources/logback.xml b/persistence-modules/hibernate5-mapping/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java new file mode 100644 index 0000000000..699890c457 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java @@ -0,0 +1,78 @@ +package com.baeldung.hibernate; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.io.IOException; +import java.util.List; + +import com.baeldung.hibernate.entities.DeptEmployee; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.query.Query; +import org.hibernate.transform.Transformers; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import com.baeldung.hibernate.entities.Department; +import com.baeldung.hibernate.pojo.Result; + +public class CustomClassIntegrationTest { + + private Session session; + + private Transaction transaction; + + @BeforeEach + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory().openSession(); + transaction = session.beginTransaction(); + session.createNativeQuery("delete from department").executeUpdate(); + Department department = new Department("Sales"); + DeptEmployee employee = new DeptEmployee("John Smith", "001", department); + session.persist(department); + session.persist(employee); + transaction.commit(); + transaction = session.beginTransaction(); + } + + @Test + public void whenAllManagersAreSelected_ThenObjectGraphIsReturned() { + Query query = session.createQuery("from com.baeldung.hibernate.entities.DeptEmployee"); + List deptEmployees = query.list(); + DeptEmployee deptEmployee = deptEmployees.get(0); + assertEquals("John Smith", deptEmployee.getName()); + assertEquals("Sales", deptEmployee.getDepartment().getName()); + } + + @Test + public void whenIndividualPropertiesAreSelected_ThenObjectArrayIsReturned() { + Query query = session.createQuery("select m.name, m.department.name from com.baeldung.hibernate.entities.DeptEmployee m"); + List managers = query.list(); + Object[] manager = (Object[]) managers.get(0); + assertEquals("John Smith", manager[0]); + assertEquals("Sales", manager[1]); + } + + @Test + public void whenResultConstructorInSelect_ThenListOfResultIsReturned() { + Query query = session.createQuery("select new com.baeldung.hibernate.pojo.Result(m.name, m.department.name) " + + "from DeptEmployee m"); + List results = query.list(); + Result result = results.get(0); + assertEquals("John Smith", result.getEmployeeName()); + assertEquals("Sales", result.getDepartmentName()); + } + + @Test + public void whenResultTransformerOnQuery_ThenListOfResultIsReturned() { + Query query = session.createQuery("select m.name as employeeName, m.department.name as departmentName " + + "from com.baeldung.hibernate.entities.DeptEmployee m"); + query.setResultTransformer(Transformers.aliasToBean(Result.class)); + List results = query.list(); + Result result = results.get(0); + assertEquals("John Smith", result.getEmployeeName()); + assertEquals("Sales", result.getDepartmentName()); + } + + +} diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java new file mode 100644 index 0000000000..7a112200b5 --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java @@ -0,0 +1,160 @@ +package com.baeldung.hibernate; + +import com.baeldung.hibernate.pojo.Employee; +import com.baeldung.hibernate.pojo.EntityDescription; +import com.baeldung.hibernate.pojo.Phone; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class DynamicMappingIntegrationTest { + + private Session session; + + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory().openSession(); + transaction = session.beginTransaction(); + + session.createNativeQuery("delete from phone").executeUpdate(); + session.createNativeQuery("delete from employee").executeUpdate(); + + transaction.commit(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenEntity_whenFieldMappedWithFormula_thenFieldIsCalculated() { + Employee employee = new Employee(10_000L, 25); + assertThat(employee.getTaxJavaWay()).isEqualTo(2_500L); + + session.save(employee); + session.flush(); + session.clear(); + + employee = session.get(Employee.class, employee.getId()); + assertThat(employee.getTax()).isEqualTo(2_500L); + } + + @Test + public void givenEntityMappedWithWhere_whenDeletedIsTrue_thenEntityNotFetched() { + Employee employee = new Employee(); + + session.save(employee); + session.clear(); + + employee = session.find(Employee.class, employee.getId()); + assertThat(employee).isNotNull(); + + employee.setDeleted(true); + session.flush(); + + employee = session.find(Employee.class, employee.getId()); + assertThat(employee).isNotNull(); + + session.clear(); + + employee = session.find(Employee.class, employee.getId()); + assertThat(employee).isNull(); + + } + + @Test + public void givenCollectionMappedWithWhere_whenDeletedIsTrue_thenEntityNotFetched() { + Employee employee = new Employee(); + Phone phone1 = new Phone("555-45-67"); + Phone phone2 = new Phone("555-89-01"); + employee.getPhones().add(phone1); + employee.getPhones().add(phone2); + + session.save(phone1); + session.save(phone2); + session.save(employee); + session.flush(); + session.clear(); + + employee = session.find(Employee.class, employee.getId()); + assertThat(employee.getPhones()).hasSize(2); + + employee.getPhones().iterator().next().setDeleted(true); + session.flush(); + session.clear(); + + employee = session.find(Employee.class, employee.getId()); + assertThat(employee.getPhones()).hasSize(1); + + List fullPhoneList = session.createQuery("from Phone").getResultList(); + assertThat(fullPhoneList).hasSize(2); + + } + + @Test + public void givenFilterByIncome_whenIncomeLimitSet_thenFilterIsApplied() throws IOException { + session.save(new Employee(10_000, 25)); + session.save(new Employee(12_000, 25)); + session.save(new Employee(15_000, 25)); + + session.flush(); + session.clear(); + + session.enableFilter("incomeLevelFilter") + .setParameter("incomeLimit", 11_000); + + List employees = session.createQuery("from Employee").getResultList(); + + assertThat(employees).hasSize(2); + + Employee employee = session.get(Employee.class, 1); + assertThat(employee.getGrossIncome()).isEqualTo(10_000); + + session.disableFilter("incomeLevelFilter"); + employees = session.createQuery("from Employee").getResultList(); + + assertThat(employees).hasSize(3); + + } + + @Test + public void givenMappingWithAny_whenDescriptionAddedToEntity_thenDescriptionCanReferAnyEntity() { + Employee employee = new Employee(); + Phone phone1 = new Phone("555-45-67"); + Phone phone2 = new Phone("555-89-01"); + employee.getPhones().add(phone1); + employee.getPhones().add(phone2); + + EntityDescription employeeDescription = new EntityDescription("Send to conference next year", employee); + EntityDescription phone1Description = new EntityDescription("Home phone (do not call after 10PM)", phone1); + EntityDescription phone2Description = new EntityDescription("Work phone", phone1); + + session.save(phone1); + session.save(phone2); + session.save(employee); + session.save(employeeDescription); + session.save(phone1Description); + session.save(phone2Description); + session.flush(); + session.clear(); + + List descriptions = session.createQuery("from EntityDescription").getResultList(); + + assertThat(Employee.class.isAssignableFrom(descriptions.get(0).getEntity().getClass())).isTrue(); + assertThat(Phone.class.isAssignableFrom(descriptions.get(1).getEntity().getClass())).isTrue(); + assertThat(Phone.class.isAssignableFrom(descriptions.get(2).getEntity().getClass())).isTrue(); + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java new file mode 100644 index 0000000000..0f35dbb8af --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java @@ -0,0 +1,89 @@ +package com.baeldung.hibernate; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.pojo.inheritance.Bag; +import com.baeldung.hibernate.pojo.inheritance.Book; +import com.baeldung.hibernate.pojo.inheritance.Car; +import com.baeldung.hibernate.pojo.inheritance.MyEmployee; +import com.baeldung.hibernate.pojo.inheritance.Pen; +import com.baeldung.hibernate.pojo.inheritance.Pet; + +public class InheritanceMappingIntegrationTest { + private Session session; + + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory() + .openSession(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenSubclasses_whenQuerySingleTableSuperclass_thenOk() { + Book book = new Book(1, "1984", "George Orwell"); + session.save(book); + Pen pen = new Pen(2, "my pen", "blue"); + session.save(pen); + + assertThat(session.createQuery("from MyProduct") + .getResultList() + .size()).isEqualTo(2); + } + + @Test + public void givenSubclasses_whenQueryMappedSuperclass_thenOk() { + MyEmployee emp = new MyEmployee(1, "john", "baeldung"); + session.save(emp); + + assertThat(session.createQuery("from com.baeldung.hibernate.pojo.inheritance.Person") + .getResultList() + .size()).isEqualTo(1); + } + + @Test + public void givenSubclasses_whenQueryJoinedTableSuperclass_thenOk() { + Pet pet = new Pet(1, "dog", "lassie"); + session.save(pet); + + assertThat(session.createQuery("from Animal") + .getResultList() + .size()).isEqualTo(1); + } + + @Test + public void givenSubclasses_whenQueryTablePerClassSuperclass_thenOk() { + Car car = new Car(1, "audi", "xyz"); + session.save(car); + + assertThat(session.createQuery("from Vehicle") + .getResultList() + .size()).isEqualTo(1); + } + + @Test + public void givenSubclasses_whenQueryNonMappedInterface_thenOk() { + Bag bag = new Bag(1, "large"); + session.save(bag); + + assertThat(session.createQuery("from com.baeldung.hibernate.pojo.inheritance.Item") + .getResultList() + .size()).isEqualTo(0); + } +} diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java new file mode 100644 index 0000000000..91c41af0fe --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java @@ -0,0 +1,128 @@ +package com.baeldung.hibernate; + +import com.baeldung.hibernate.pojo.TemporalValues; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.time.*; +import java.util.Calendar; +import java.util.TimeZone; + +import static org.assertj.core.api.Assertions.assertThat; + +public class TemporalValuesUnitTest { + + private Session session; + + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory().withOptions() + .jdbcTimeZone(TimeZone.getTimeZone("UTC")) + .openSession(); + transaction = session.beginTransaction(); + session.createNativeQuery("delete from temporalvalues").executeUpdate(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenEntity_whenMappingSqlTypes_thenTemporalIsSelectedAutomatically() { + TemporalValues temporalValues = new TemporalValues(); + temporalValues.setSqlDate(java.sql.Date.valueOf("2017-11-15")); + temporalValues.setSqlTime(java.sql.Time.valueOf("15:30:14")); + temporalValues.setSqlTimestamp(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getSqlDate()).isEqualTo(java.sql.Date.valueOf("2017-11-15")); + assertThat(temporalValues.getSqlTime()).isEqualTo(java.sql.Time.valueOf("15:30:14")); + assertThat(temporalValues.getSqlTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); + + } + + @Test + public void givenEntity_whenMappingUtilDateType_thenTemporalIsSpecifiedExplicitly() throws Exception { + TemporalValues temporalValues = new TemporalValues(); + temporalValues.setUtilDate(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); + temporalValues.setUtilTime(new SimpleDateFormat("HH:mm:ss").parse("15:30:14")); + temporalValues.setUtilTimestamp(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.332")); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getUtilDate()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); + assertThat(temporalValues.getUtilTime()).isEqualTo(new SimpleDateFormat("HH:mm:ss").parse("15:30:14")); + assertThat(temporalValues.getUtilTimestamp()).isEqualTo(java.sql.Timestamp.valueOf("2017-11-15 15:30:14.332")); + + } + + @Test + public void givenEntity_whenMappingCalendarType_thenTemporalIsSpecifiedExplicitly() throws Exception { + TemporalValues temporalValues = new TemporalValues(); + + Calendar calendarDate = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + calendarDate.set(Calendar.YEAR, 2017); + calendarDate.set(Calendar.MONTH, 10); + calendarDate.set(Calendar.DAY_OF_MONTH, 15); + temporalValues.setCalendarDate(calendarDate); + + Calendar calendarTimestamp = Calendar.getInstance(TimeZone.getTimeZone("UTC")); + calendarTimestamp.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322")); + temporalValues.setCalendarTimestamp(calendarTimestamp); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getCalendarDate().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd").parse("2017-11-15")); + assertThat(temporalValues.getCalendarTimestamp().getTime()).isEqualTo(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS").parse("2017-11-15 15:30:14.322")); + + } + + @Test + public void givenEntity_whenMappingJavaTimeTypes_thenTemporalIsSelectedAutomatically() { + TemporalValues temporalValues = new TemporalValues(); + + temporalValues.setLocalDate(LocalDate.parse("2017-11-15")); + temporalValues.setLocalTime(LocalTime.parse("15:30:18")); + temporalValues.setOffsetTime(OffsetTime.parse("08:22:12+01:00")); + + System.out.println("********"+OffsetTime.parse("08:22:12+01:00").toString()); + temporalValues.setInstant(Instant.parse("2017-11-15T08:22:12Z")); + temporalValues.setLocalDateTime(LocalDateTime.parse("2017-11-15T08:22:12")); + temporalValues.setOffsetDateTime(OffsetDateTime.parse("2017-11-15T08:22:12+01:00")); + temporalValues.setZonedDateTime(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]")); + + session.save(temporalValues); + session.flush(); + session.clear(); + + temporalValues = session.get(TemporalValues.class, temporalValues.getId()); + assertThat(temporalValues.getLocalDate()).isEqualTo(LocalDate.parse("2017-11-15")); + assertThat(temporalValues.getLocalTime()).isEqualTo(LocalTime.parse("15:30:18")); + //assertThat(temporalValues.getOffsetTime()).isEqualTo(OffsetTime.parse("08:22:12+01:00")); + assertThat(temporalValues.getInstant()).isEqualTo(Instant.parse("2017-11-15T08:22:12Z")); + assertThat(temporalValues.getLocalDateTime()).isEqualTo(LocalDateTime.parse("2017-11-15T08:22:12")); + //assertThat(temporalValues.getOffsetDateTime()).isEqualTo(OffsetDateTime.parse("2017-11-15T08:22:12+01:00")); + assertThat(temporalValues.getZonedDateTime()).isEqualTo(ZonedDateTime.parse("2017-11-15T08:22:12+01:00[Europe/Paris]")); + + } + +} diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java new file mode 100644 index 0000000000..398b2290fa --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java @@ -0,0 +1,61 @@ +package com.baeldung.hibernate.lob; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; + +import org.apache.commons.io.IOUtils; +import org.hibernate.HibernateException; +import org.hibernate.Session; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.lob.model.User; + +public class LobUnitTest { + + private Session session; + + @Before + public void init(){ + try { + session = HibernateSessionUtil.getSessionFactory("hibernate.properties") + .openSession(); + } catch (HibernateException | IOException e) { + fail("Failed to initiate Hibernate Session [Exception:" + e.toString() + "]"); + } + } + + @After + public void close(){ + if(session != null) session.close(); + } + + @Test + public void givenValidInsertLobObject_whenQueried_returnSameDataAsInserted(){ + User user = new User(); + try(InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream("profile.png");) { + // Get Image file from the resource + if(inputStream == null) fail("Unable to get resources"); + user.setId("1"); + user.setName("User"); + user.setPhoto(IOUtils.toByteArray(inputStream)); + + session.persist(user); + } catch (IOException e) { + fail("Unable to read input stream"); + } + + User result = session.find(User.class, "1"); + + assertNotNull("Query result is null", result); + assertEquals("User's name is invalid", user.getName(), result.getName() ); + assertTrue("User's photo is corrupted", Arrays.equals(user.getPhoto(), result.getPhoto()) ); + } +} diff --git a/persistence-modules/hibernate5-mapping/src/test/resources/hibernate.properties b/persistence-modules/hibernate5-mapping/src/test/resources/hibernate.properties new file mode 100644 index 0000000000..c14782ce0f --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/test/resources/hibernate.properties @@ -0,0 +1,14 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5-mapping/src/test/resources/lifecycle-init.sql b/persistence-modules/hibernate5-mapping/src/test/resources/lifecycle-init.sql new file mode 100644 index 0000000000..c0c9a3f34d --- /dev/null +++ b/persistence-modules/hibernate5-mapping/src/test/resources/lifecycle-init.sql @@ -0,0 +1,25 @@ +create sequence hibernate_sequence start with 1 increment by 1; + +create table Football_Player ( + id bigint not null, + name varchar(255), + primary key (id) +); + +insert into + Football_Player + (name, id) + values + ('Cristiano Ronaldo', next value for hibernate_sequence); + +insert into + Football_Player + (name, id) + values + ('Lionel Messi', next value for hibernate_sequence); + +insert into + Football_Player + (name, id) + values + ('Gigi Buffon', next value for hibernate_sequence); \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/src/test/resources/profile.png b/persistence-modules/hibernate5-mapping/src/test/resources/profile.png new file mode 100644 index 0000000000000000000000000000000000000000..1cd4e978b96d0f59a6e48692fcb68d1c6c565a20 GIT binary patch literal 1117 zcmV-j1fu(iP)%yyh@V&OYl(_AFwE`D&8)` zPnvkdvc#Z>pRh2kBHk{=qaGfCG;?<;rVe;D+%LyZS~!K}c+|op81YK@rzPHU@Th|m z4Dk`HcojTY;+}_-W%HGqKH@C!LiH8Tp>1lC@aTqoy zBU~QK<}hs@q|M8($ee`o<9#`B3-PL4Y7d9kW#<;n>t}6VNpYCswLrJTtEa_lFwgN$52-_vxvvfJs@B6-OYs%-@M_JTx*UfozG6(Bhs)>w z!pG%vU$b%f++EGa<#Tu1FZ^c#{;G|y5=kM3Y#X^mtSrFA_-o-vX7e_$5-udx(>S4U)i|4)(UJ~zR(vwE+6VTAzoo7wIS|c zh*yt`3wK%<+yX~Z9G1z2GQgf3~qx jc9u$WjpqGof00000NkvXXu0mjfJX<<= literal 0 HcmV?d00001 From 901708063381684ec81918283dcc1f83ab05f7a7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 11 Mar 2020 18:21:07 +0530 Subject: [PATCH 031/278] JAVA-4 : added new module hibernate5-queries --- .../hibernate5-queries/README.md | 10 ++ .../hibernate5-queries/pom.xml | 82 ++++++++++++++ .../com/baeldung/hibernate/HibernateUtil.java | 73 ++++++++++++ .../UnsupportedTenancyException.java | 8 ++ .../criteriaquery/HibernateUtil.java | 60 ++++++++++ .../hibernate/criteriaquery/Student.java | 58 ++++++++++ .../LocalDateStringJavaDescriptor.java | 51 +++++++++ .../customtypes/LocalDateStringType.java | 34 ++++++ .../hibernate/entities/Department.java | 45 ++++++++ .../hibernate/entities/DeptEmployee.java | 83 ++++++++++++++ .../baeldung/hibernate/findall/FindAll.java | 35 ++++++ .../com/baeldung/hibernate/pojo/Student.java | 51 +++++++++ .../main/resources/META-INF/persistence.xml | 18 +++ .../src/main/resources/init_database.sql | 10 ++ .../src/main/resources/logback.xml | 13 +++ .../hibernate/NamedQueryIntegrationTest.java | 98 ++++++++++++++++ .../TypeSafeCriteriaIntegrationTest.java | 89 +++++++++++++++ .../hibernate/findall/FindAllUnitTest.java | 63 +++++++++++ .../QueryPlanCacheBenchmark.java | 106 ++++++++++++++++++ .../hibernate-customtypes.properties | 14 +++ .../resources/hibernate-namedquery.properties | 9 ++ .../src/test/resources/hibernate.properties | 14 +++ .../src/test/resources/lifecycle-init.sql | 25 +++++ .../src/test/resources/profile.png | Bin 0 -> 1117 bytes 24 files changed, 1049 insertions(+) create mode 100644 persistence-modules/hibernate5-queries/README.md create mode 100644 persistence-modules/hibernate5-queries/pom.xml create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/Department.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java create mode 100644 persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java create mode 100644 persistence-modules/hibernate5-queries/src/main/resources/META-INF/persistence.xml create mode 100644 persistence-modules/hibernate5-queries/src/main/resources/init_database.sql create mode 100644 persistence-modules/hibernate5-queries/src/main/resources/logback.xml create mode 100644 persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java create mode 100644 persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java create mode 100644 persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java create mode 100644 persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java create mode 100644 persistence-modules/hibernate5-queries/src/test/resources/hibernate-customtypes.properties create mode 100644 persistence-modules/hibernate5-queries/src/test/resources/hibernate-namedquery.properties create mode 100644 persistence-modules/hibernate5-queries/src/test/resources/hibernate.properties create mode 100644 persistence-modules/hibernate5-queries/src/test/resources/lifecycle-init.sql create mode 100644 persistence-modules/hibernate5-queries/src/test/resources/profile.png diff --git a/persistence-modules/hibernate5-queries/README.md b/persistence-modules/hibernate5-queries/README.md new file mode 100644 index 0000000000..1edf4ded1e --- /dev/null +++ b/persistence-modules/hibernate5-queries/README.md @@ -0,0 +1,10 @@ +## Hibernate 5 + +This module contains articles about Hibernate 5. + +### Relevant articles: + +- [Criteria Queries Using JPA Metamodel](https://www.baeldung.com/hibernate-criteria-queries-metamodel) +- [Get All Data from a Table with Hibernate](https://www.baeldung.com/hibernate-select-all) +- [Hibernate Named Query](https://www.baeldung.com/hibernate-named-query) +- [Hibernate Query Plan Cache](https://www.baeldung.com/hibernate-query-plan-cache) \ No newline at end of file diff --git a/persistence-modules/hibernate5-queries/pom.xml b/persistence-modules/hibernate5-queries/pom.xml new file mode 100644 index 0000000000..544d22c0a3 --- /dev/null +++ b/persistence-modules/hibernate5-queries/pom.xml @@ -0,0 +1,82 @@ + + + 4.0.0 + hibernate5-queries + 0.0.1-SNAPSHOT + hibernate5-queries + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + org.hibernate + hibernate-core + ${hibernate.version} + + + org.assertj + assertj-core + ${assertj-core.version} + test + + + com.h2database + h2 + ${h2.version} + + + org.hibernate + hibernate-spatial + ${hibernate.version} + + + org.opengeo + geodb + ${geodb.version} + + + mysql + mysql-connector-java + ${mysql.version} + + + ch.vorburger.mariaDB4j + mariaDB4j + ${mariaDB4j.version} + + + org.hibernate + hibernate-testing + ${hibernate.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${openjdk-jmh.version} + + + + + + geodb-repo + GeoDB repository + http://repo.boundlessgeo.com/main/ + + + + + 5.3.7.Final + 6.0.6 + 2.2.3 + 3.8.0 + 0.9 + 1.21 + + + diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java new file mode 100644 index 0000000000..58724e690c --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -0,0 +1,73 @@ +package com.baeldung.hibernate; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import com.baeldung.hibernate.customtypes.LocalDateStringType; +import com.baeldung.hibernate.entities.DeptEmployee; +import com.baeldung.hibernate.pojo.Student; + +public class HibernateUtil { + private static String PROPERTY_FILE_NAME; + + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(null); + } + + public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { + PROPERTY_FILE_NAME = propertyFileName; + ServiceRegistry serviceRegistry = configureServiceRegistry(); + return makeSessionFactory(serviceRegistry); + } + + public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException { + ServiceRegistry serviceRegistry = configureServiceRegistry(properties); + return makeSessionFactory(serviceRegistry); + } + + private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + metadataSources.addPackage("com.baeldung.hibernate.pojo"); + metadataSources.addAnnotatedClass(Student.class); + metadataSources.addAnnotatedClass(DeptEmployee.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); + + Metadata metadata = metadataSources.getMetadataBuilder() + .applyBasicType(LocalDateStringType.INSTANCE) + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + + } + + private static ServiceRegistry configureServiceRegistry() throws IOException { + return configureServiceRegistry(getProperties()); + } + + private static ServiceRegistry configureServiceRegistry(Properties properties) throws IOException { + return new StandardServiceRegistryBuilder().applySettings(properties) + .build(); + } + + public static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} \ No newline at end of file diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java new file mode 100644 index 0000000000..99d9505ea3 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java @@ -0,0 +1,8 @@ +package com.baeldung.hibernate; + +public class UnsupportedTenancyException extends Exception { + public UnsupportedTenancyException (String message) { + super(message); + } + +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java new file mode 100644 index 0000000000..35cfe55ba6 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java @@ -0,0 +1,60 @@ +package com.baeldung.hibernate.criteriaquery; + +import com.baeldung.hibernate.customtypes.LocalDateStringType; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.util.Properties; + +public class HibernateUtil { + private static SessionFactory sessionFactory; + + private HibernateUtil() { + } + + public static SessionFactory getSessionFactory() { + if (sessionFactory == null) { + sessionFactory = buildSessionFactory(); + } + return sessionFactory; + } + + private static SessionFactory buildSessionFactory() { + try { + ServiceRegistry serviceRegistry = configureServiceRegistry(); + + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + metadataSources.addAnnotatedClass(Student.class); + Metadata metadata = metadataSources.getMetadataBuilder() + .applyBasicType(LocalDateStringType.INSTANCE) + .build(); + return metadata.getSessionFactoryBuilder().build(); + } catch (IOException ex) { + throw new ExceptionInInitializerError(ex); + } + } + + + private static ServiceRegistry configureServiceRegistry() throws IOException { + Properties properties = getProperties(); + return new StandardServiceRegistryBuilder().applySettings(properties).build(); + } + + private static Properties getProperties() throws IOException { + Properties properties = new Properties(); + URL propertiesURL = Thread.currentThread() + .getContextClassLoader() + .getResource("hibernate.properties"); + try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { + properties.load(inputStream); + } + return properties; + } +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java new file mode 100644 index 0000000000..314e7ca557 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java @@ -0,0 +1,58 @@ +package com.baeldung.hibernate.criteriaquery; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Table; + +@Entity +@Table(name = "students") +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private int id; + + @Column(name = "first_name") + private String firstName; + + @Column(name = "last_name") + private String lastName; + + @Column(name = "grad_year") + private int gradYear; + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public int getGradYear() { + return gradYear; + } + + public void setGradYear(int gradYear) { + this.gradYear = gradYear; + } +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java new file mode 100644 index 0000000000..56be9e693f --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.customtypes; + +import org.hibernate.type.LocalDateType; +import org.hibernate.type.descriptor.WrapperOptions; +import org.hibernate.type.descriptor.java.AbstractTypeDescriptor; +import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan; +import org.hibernate.type.descriptor.java.MutabilityPlan; + +import java.time.LocalDate; + +public class LocalDateStringJavaDescriptor extends AbstractTypeDescriptor { + + public static final LocalDateStringJavaDescriptor INSTANCE = new LocalDateStringJavaDescriptor(); + + public LocalDateStringJavaDescriptor() { + super(LocalDate.class, ImmutableMutabilityPlan.INSTANCE); + } + + @Override + public String toString(LocalDate value) { + return LocalDateType.FORMATTER.format(value); + } + + @Override + public LocalDate fromString(String string) { + return LocalDate.from(LocalDateType.FORMATTER.parse(string)); + } + + @Override + public X unwrap(LocalDate value, Class type, WrapperOptions options) { + + if (value == null) + return null; + + if (String.class.isAssignableFrom(type)) + return (X) LocalDateType.FORMATTER.format(value); + + throw unknownUnwrap(type); + } + + @Override + public LocalDate wrap(X value, WrapperOptions options) { + if (value == null) + return null; + + if(String.class.isInstance(value)) + return LocalDate.from(LocalDateType.FORMATTER.parse((CharSequence) value)); + + throw unknownWrap(value.getClass()); + } +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java new file mode 100644 index 0000000000..c8d37073e8 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.customtypes; + +import org.hibernate.dialect.Dialect; +import org.hibernate.type.AbstractSingleColumnStandardBasicType; +import org.hibernate.type.DiscriminatorType; +import org.hibernate.type.descriptor.java.LocalDateJavaDescriptor; +import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor; + +import java.time.LocalDate; + +public class LocalDateStringType extends AbstractSingleColumnStandardBasicType implements DiscriminatorType { + + public static final LocalDateStringType INSTANCE = new LocalDateStringType(); + + public LocalDateStringType() { + super(VarcharTypeDescriptor.INSTANCE, LocalDateStringJavaDescriptor.INSTANCE); + } + + @Override + public String getName() { + return "LocalDateString"; + } + + @Override + public LocalDate stringToObject(String xml) throws Exception { + return fromString(xml); + } + + @Override + public String objectToSQLString(LocalDate value, Dialect dialect) throws Exception { + return '\'' + toString(value) + '\''; + } + +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/Department.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/Department.java new file mode 100644 index 0000000000..ff94f4f849 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/Department.java @@ -0,0 +1,45 @@ +package com.baeldung.hibernate.entities; + +import java.util.List; + +import javax.persistence.*; + +@Entity +public class Department { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @OneToMany(mappedBy="department") + private List employees; + + public Department(String name) { + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getEmployees() { + return employees; + } + + public void setEmployees(List employees) { + this.employees = employees; + } +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java new file mode 100644 index 0000000000..6510e70650 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java @@ -0,0 +1,83 @@ +package com.baeldung.hibernate.entities; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@org.hibernate.annotations.NamedQueries({ @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindByEmployeeNumber", query = "from DeptEmployee where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDesgination", query = "from DeptEmployee where designation = :designation"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_UpdateEmployeeDepartment", query = "Update DeptEmployee set department = :newDepartment where employeeNumber = :employeeNo"), + @org.hibernate.annotations.NamedQuery(name = "DeptEmployee_FindAllByDepartment", query = "from DeptEmployee where department = :department", timeout = 1, fetchSize = 10) }) +@org.hibernate.annotations.NamedNativeQueries({ @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_FindByEmployeeName", query = "select * from deptemployee emp where name=:name", resultClass = DeptEmployee.class), + @org.hibernate.annotations.NamedNativeQuery(name = "DeptEmployee_UpdateEmployeeDesignation", query = "call UPDATE_EMPLOYEE_DESIGNATION(:employeeNumber, :newDesignation)", resultClass = DeptEmployee.class) }) +@Entity +public class DeptEmployee { + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String employeeNumber; + + private String title; + + private String name; + + @ManyToOne + private Department department; + + public DeptEmployee(String name, String employeeNumber, Department department) { + this.name = name; + this.employeeNumber = employeeNumber; + this.department = department; + } + + public DeptEmployee(String name, String employeeNumber, String title, Department department) { + super(); + this.name = name; + this.employeeNumber = employeeNumber; + this.title = title; + this.department = department; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getEmployeeNumber() { + return employeeNumber; + } + + public void setEmployeeNumber(String employeeNumber) { + this.employeeNumber = employeeNumber; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Department getDepartment() { + return department; + } + + public void setDepartment(Department department) { + this.department = department; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java new file mode 100644 index 0000000000..cc0c234df0 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java @@ -0,0 +1,35 @@ +package com.baeldung.hibernate.findall; + +import java.util.List; + +import javax.persistence.TypedQuery; +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; + +import org.hibernate.Session; + +import com.baeldung.hibernate.pojo.Student; + +public class FindAll { + + private Session session; + + public FindAll(Session session) { + super(); + this.session = session; + } + + public List findAllWithJpql() { + return session.createQuery("SELECT a FROM Student a", Student.class).getResultList(); + } + + public List findAllWithCriteriaQuery() { + CriteriaBuilder cb = session.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(Student.class); + Root rootEntry = cq.from(Student.class); + CriteriaQuery all = cq.select(rootEntry); + TypedQuery allQuery = session.createQuery(all); + return allQuery.getResultList(); + } +} diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java new file mode 100644 index 0000000000..9b26c117eb --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java @@ -0,0 +1,51 @@ +package com.baeldung.hibernate.pojo; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; + +@Entity +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long studentId; + + private String name; + + private int age; + + public Student() { + } + + public Student(String name, int age) { + this.name = name; + this.age = age; + } + + public long getStudentId() { + return studentId; + } + + public void setStudentId(long studentId) { + this.studentId = studentId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + +} diff --git a/persistence-modules/hibernate5-queries/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate5-queries/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000000..474eeb7a44 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,18 @@ + + + + Hibernate EntityManager Demo + true + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-queries/src/main/resources/init_database.sql b/persistence-modules/hibernate5-queries/src/main/resources/init_database.sql new file mode 100644 index 0000000000..b2848aa256 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/resources/init_database.sql @@ -0,0 +1,10 @@ +CREATE ALIAS UPDATE_EMPLOYEE_DESIGNATION AS $$ +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.SQLException; +@CODE +void updateEmployeeDesignation(final Connection conn, final String employeeNumber, final String title) throws SQLException { + CallableStatement updateStatement = conn.prepareCall("update deptemployee set title = '" + title + "' where employeeNumber = '" + employeeNumber + "'"); + updateStatement.execute(); +} +$$; \ No newline at end of file diff --git a/persistence-modules/hibernate5-queries/src/main/resources/logback.xml b/persistence-modules/hibernate5-queries/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java new file mode 100644 index 0000000000..cb73fe348c --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java @@ -0,0 +1,98 @@ +package com.baeldung.hibernate; + +import com.baeldung.hibernate.entities.Department; +import com.baeldung.hibernate.entities.DeptEmployee; +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.query.NativeQuery; +import org.hibernate.query.Query; +import org.junit.*; + +import java.io.IOException; + +public class NamedQueryIntegrationTest { + private static Session session; + + private Transaction transaction; + + private Long purchaseDeptId; + + @BeforeClass + public static void setUpClass() throws IOException { + session = HibernateUtil.getSessionFactory("hibernate-namedquery.properties").openSession(); + } + + @Before + public void setUp() throws IOException { + transaction = session.beginTransaction(); + session.createNativeQuery("delete from deptemployee").executeUpdate(); + session.createNativeQuery("delete from department").executeUpdate(); + Department salesDepartment = new Department("Sales"); + Department purchaseDepartment = new Department("Purchase"); + DeptEmployee employee1 = new DeptEmployee("John Wayne", "001", salesDepartment); + DeptEmployee employee2 = new DeptEmployee("Sarah Vinton", "002", salesDepartment); + DeptEmployee employee3 = new DeptEmployee("Lisa Carter", "003", salesDepartment); + session.persist(salesDepartment); + session.persist(purchaseDepartment); + purchaseDeptId = purchaseDepartment.getId(); + session.persist(employee1); + session.persist(employee2); + session.persist(employee3); + transaction.commit(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + if(transaction.isActive()) { + transaction.rollback(); + } + } + + @Test + public void whenNamedQueryIsCalledUsingCreateNamedQuery_ThenOk() { + Query query = session.createNamedQuery("DeptEmployee_FindByEmployeeNumber", DeptEmployee.class); + query.setParameter("employeeNo", "001"); + DeptEmployee result = query.getSingleResult(); + Assert.assertNotNull(result); + Assert.assertEquals("John Wayne", result.getName()); + } + + @Test + public void whenNamedNativeQueryIsCalledUsingCreateNamedQuery_ThenOk() { + Query query = session.createNamedQuery("DeptEmployee_FindByEmployeeName", DeptEmployee.class); + query.setParameter("name", "John Wayne"); + DeptEmployee result = query.getSingleResult(); + Assert.assertNotNull(result); + Assert.assertEquals("001", result.getEmployeeNumber()); + } + + @Test + public void whenNamedNativeQueryIsCalledUsingGetNamedNativeQuery_ThenOk() { + @SuppressWarnings("rawtypes") + NativeQuery query = session.getNamedNativeQuery("DeptEmployee_FindByEmployeeName"); + query.setParameter("name", "John Wayne"); + DeptEmployee result = (DeptEmployee) query.getSingleResult(); + Assert.assertNotNull(result); + Assert.assertEquals("001", result.getEmployeeNumber()); + } + + @Test + public void whenUpdateQueryIsCalledWithCreateNamedQuery_ThenOk() { + Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDepartment"); + spQuery.setParameter("employeeNo", "001"); + Department newDepartment = session.find(Department.class, purchaseDeptId); + spQuery.setParameter("newDepartment", newDepartment); + spQuery.executeUpdate(); + transaction.commit(); + } + + @Test + public void whenNamedStoredProcedureIsCalledWithCreateNamedQuery_ThenOk() { + Query spQuery = session.createNamedQuery("DeptEmployee_UpdateEmployeeDesignation"); + spQuery.setParameter("employeeNumber", "002"); + spQuery.setParameter("newDesignation", "Supervisor"); + spQuery.executeUpdate(); + transaction.commit(); + } +} diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java new file mode 100644 index 0000000000..cedba412d9 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java @@ -0,0 +1,89 @@ +package com.baeldung.hibernate.criteriaquery; + +import com.baeldung.hibernate.criteriaquery.HibernateUtil; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.query.Query; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import javax.persistence.criteria.CriteriaBuilder; +import javax.persistence.criteria.CriteriaQuery; +import javax.persistence.criteria.Root; +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + + +public class TypeSafeCriteriaIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + @BeforeClass + public static void beforeTests() throws IOException { + sessionFactory = HibernateUtil.getSessionFactory(); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenStudentData_whenUsingTypeSafeCriteriaQuery_thenSearchAllStudentsOfAGradYear() { + + prepareData(); + CriteriaBuilder cb = session.getCriteriaBuilder(); + CriteriaQuery criteriaQuery = cb.createQuery(Student.class); + + Root root = criteriaQuery.from(Student.class); + criteriaQuery.select(root).where(cb.equal(root.get("gradYear"), 1965)); + + Query query = session.createQuery(criteriaQuery); + List results = query.getResultList(); + + assertNotNull(results); + assertEquals(1, results.size()); + + Student student = results.get(0); + + assertEquals("Ken", student.getFirstName()); + assertEquals("Thompson", student.getLastName()); + assertEquals(1965, student.getGradYear()); + } + + private void prepareData() { + Student student1 = new Student(); + student1.setFirstName("Ken"); + student1.setLastName("Thompson"); + student1.setGradYear(1965); + + session.save(student1); + + Student student2 = new Student(); + student2.setFirstName("Dennis"); + student2.setLastName("Ritchie"); + student2.setGradYear(1963); + + session.save(student2); + session.getTransaction().commit(); + } + + @After + public void tearDown() { + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } +} diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java new file mode 100644 index 0000000000..8a1b9e9791 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java @@ -0,0 +1,63 @@ +package com.baeldung.hibernate.findall; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.baeldung.hibernate.HibernateUtil; +import com.baeldung.hibernate.pojo.Student; + +public class FindAllUnitTest { + + private Session session; + private Transaction transaction; + + private FindAll findAll; + + @Before + public void setUp() throws IOException { + + session = HibernateUtil.getSessionFactory().openSession(); + transaction = session.beginTransaction(); + findAll = new FindAll(session); + + session.createNativeQuery("delete from Student").executeUpdate(); + + Student student1 = new Student(); + session.persist(student1); + + Student student2 = new Student(); + session.persist(student2); + + Student student3 = new Student(); + session.persist(student3); + + transaction.commit(); + transaction = session.beginTransaction(); + } + + @After + public void tearDown() { + transaction.rollback(); + session.close(); + } + + @Test + public void givenCriteriaQuery_WhenFindAll_ThenGetAllPersons() { + List list = findAll.findAllWithCriteriaQuery(); + assertEquals(3, list.size()); + } + + @Test + public void givenJpql_WhenFindAll_ThenGetAllPersons() { + List list = findAll.findAllWithJpql(); + assertEquals(3, list.size()); + } +} diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java new file mode 100644 index 0000000000..13eae3d877 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java @@ -0,0 +1,106 @@ +package com.baeldung.hibernate.queryplancache; + +import com.baeldung.hibernate.HibernateUtil; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.jpa.QueryHints; +import org.hibernate.query.Query; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.TearDown; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.runner.RunnerException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +public class QueryPlanCacheBenchmark { + + private static final Logger LOGGER = LoggerFactory.getLogger(QueryPlanCacheBenchmark.class); + + @State(Scope.Thread) + public static class QueryPlanCacheBenchMarkState { + @Param({"1", "2", "3"}) + public int planCacheSize; + + public Session session; + + @Setup + public void stateSetup() throws IOException { + LOGGER.info("State - Setup"); + session = initSession(planCacheSize); + LOGGER.info("State - Setup Complete"); + } + + private Session initSession(int planCacheSize) throws IOException { + Properties properties = HibernateUtil.getProperties(); + properties.put("hibernate.query.plan_cache_max_size", planCacheSize); + properties.put("hibernate.query.plan_parameter_metadata_max_size", planCacheSize); + SessionFactory sessionFactory = HibernateUtil.getSessionFactoryByProperties(properties); + return sessionFactory.openSession(); + } + + @TearDown + public void tearDownState() { + LOGGER.info("State - Teardown"); + SessionFactory sessionFactory = session.getSessionFactory(); + session.close(); + sessionFactory.close(); + LOGGER.info("State - Teardown complete"); + } + } + + @Benchmark + @BenchmarkMode(Mode.AverageTime) + @OutputTimeUnit(TimeUnit.MICROSECONDS) + @Fork(1) + @Warmup(iterations = 2) + @Measurement(iterations = 5) + public void givenQueryPlanCacheSize_thenCompileQueries(QueryPlanCacheBenchMarkState state, Blackhole blackhole) { + + Query query1 = findEmployeesByDepartmentNameQuery(state.session); + Query query2 = findEmployeesByDesignationQuery(state.session); + Query query3 = findDepartmentOfAnEmployeeQuery(state.session); + + blackhole.consume(query1); + blackhole.consume(query2); + blackhole.consume(query3); + + } + + private Query findEmployeesByDepartmentNameQuery(Session session) { + return session.createQuery("SELECT e FROM DeptEmployee e " + + "JOIN e.department WHERE e.department.name = :deptName") + .setMaxResults(30) + .setHint(QueryHints.HINT_FETCH_SIZE, 30); + } + + private Query findEmployeesByDesignationQuery(Session session) { + return session.createQuery("SELECT e FROM DeptEmployee e " + + "WHERE e.title = :designation") + .setHint(QueryHints.SPEC_HINT_TIMEOUT, 1000); + } + + private Query findDepartmentOfAnEmployeeQuery(Session session) { + return session.createQuery("SELECT e.department FROM DeptEmployee e " + + "JOIN e.department WHERE e.employeeNumber = :empId"); + + } + + public static void main(String... args) throws IOException, RunnerException { + //main-class to run the benchmark + org.openjdk.jmh.Main.main(args); + } +} diff --git a/persistence-modules/hibernate5-queries/src/test/resources/hibernate-customtypes.properties b/persistence-modules/hibernate5-queries/src/test/resources/hibernate-customtypes.properties new file mode 100644 index 0000000000..c14782ce0f --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/resources/hibernate-customtypes.properties @@ -0,0 +1,14 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5-queries/src/test/resources/hibernate-namedquery.properties b/persistence-modules/hibernate5-queries/src/test/resources/hibernate-namedquery.properties new file mode 100644 index 0000000000..457f965347 --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/resources/hibernate-namedquery.properties @@ -0,0 +1,9 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1;INIT=RUNSCRIPT FROM 'src/main/resources/init_database.sql' +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/persistence-modules/hibernate5-queries/src/test/resources/hibernate.properties b/persistence-modules/hibernate5-queries/src/test/resources/hibernate.properties new file mode 100644 index 0000000000..c14782ce0f --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/resources/hibernate.properties @@ -0,0 +1,14 @@ +hibernate.connection.driver_class=org.h2.Driver +hibernate.connection.url=jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1 +hibernate.connection.username=sa +hibernate.connection.autocommit=true +jdbc.password= + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop + +hibernate.c3p0.min_size=5 +hibernate.c3p0.max_size=20 +hibernate.c3p0.acquire_increment=5 +hibernate.c3p0.timeout=1800 diff --git a/persistence-modules/hibernate5-queries/src/test/resources/lifecycle-init.sql b/persistence-modules/hibernate5-queries/src/test/resources/lifecycle-init.sql new file mode 100644 index 0000000000..c0c9a3f34d --- /dev/null +++ b/persistence-modules/hibernate5-queries/src/test/resources/lifecycle-init.sql @@ -0,0 +1,25 @@ +create sequence hibernate_sequence start with 1 increment by 1; + +create table Football_Player ( + id bigint not null, + name varchar(255), + primary key (id) +); + +insert into + Football_Player + (name, id) + values + ('Cristiano Ronaldo', next value for hibernate_sequence); + +insert into + Football_Player + (name, id) + values + ('Lionel Messi', next value for hibernate_sequence); + +insert into + Football_Player + (name, id) + values + ('Gigi Buffon', next value for hibernate_sequence); \ No newline at end of file diff --git a/persistence-modules/hibernate5-queries/src/test/resources/profile.png b/persistence-modules/hibernate5-queries/src/test/resources/profile.png new file mode 100644 index 0000000000000000000000000000000000000000..1cd4e978b96d0f59a6e48692fcb68d1c6c565a20 GIT binary patch literal 1117 zcmV-j1fu(iP)%yyh@V&OYl(_AFwE`D&8)` zPnvkdvc#Z>pRh2kBHk{=qaGfCG;?<;rVe;D+%LyZS~!K}c+|op81YK@rzPHU@Th|m z4Dk`HcojTY;+}_-W%HGqKH@C!LiH8Tp>1lC@aTqoy zBU~QK<}hs@q|M8($ee`o<9#`B3-PL4Y7d9kW#<;n>t}6VNpYCswLrJTtEa_lFwgN$52-_vxvvfJs@B6-OYs%-@M_JTx*UfozG6(Bhs)>w z!pG%vU$b%f++EGa<#Tu1FZ^c#{;G|y5=kM3Y#X^mtSrFA_-o-vX7e_$5-udx(>S4U)i|4)(UJ~zR(vwE+6VTAzoo7wIS|c zh*yt`3wK%<+yX~Z9G1z2GQgf3~qx jc9u$WjpqGof00000NkvXXu0mjfJX<<= literal 0 HcmV?d00001 From 2302a4abb7ee65da888823e0362a65011f95ee8b Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Mar 2020 14:31:36 +0100 Subject: [PATCH 032/278] BAEL-3855 --- .../lock/ConcurrentAccessBenchmark.java | 49 +++++++++++++++++++ .../lock/ConcurrentAccessExperiment.java | 40 +++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java create mode 100644 core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java new file mode 100644 index 0000000000..7c84c39804 --- /dev/null +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java @@ -0,0 +1,49 @@ +package com.baeldung.concurrent.lock; + +import java.util.concurrent.TimeUnit; + +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.annotations.Warmup; + +@State(Scope.Thread) +@Fork(value = 1) +@Warmup(iterations = 0) +public class ConcurrentAccessBenchmark { + ConcurrentAccessExperiment accessMyMap; + static final int SLOTS = 4; + static final int THREADS = 10000; + static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; + + @Param({"Single Lock", "Striped Lock"}) + private String lockType; + + @Param({"HashMap", "ConcurrentHashMap"}) + private String mapType; + + @Setup + public void setup() { + switch (lockType) { + case "Single Lock": + accessMyMap = new SingleLock(); + break; + case "Striped Lock": + accessMyMap = new StripedLock(BUCKETS); + break; + } + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public void test() throws InterruptedException { + accessMyMap.doWork(mapType, THREADS, SLOTS); + } +} diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java new file mode 100644 index 0000000000..b1276410ce --- /dev/null +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java @@ -0,0 +1,40 @@ +package com.baeldung.concurrent.lock; + +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; + +import com.google.common.base.Supplier; + +public abstract class ConcurrentAccessExperiment { + + public ConcurrentAccessExperiment() { + } + + private Map doMapSetup(String typeOfMap) { + switch (typeOfMap) { + case "HashMap": + return new HashMap(); + case "ConcurrentHashMap": + return new ConcurrentHashMap(); + } + return null; + } + + public final void doWork(String typeOfMap, int threads, int slots) { + CompletableFuture[] requests = new CompletableFuture[threads * slots]; + Map map = doMapSetup(typeOfMap); + + for (int i = 0; i < threads; i++) { + requests[slots * i + 0] = CompletableFuture.supplyAsync(putSupplier(map, i)); + requests[slots * i + 1] = CompletableFuture.supplyAsync(getSupplier(map, i)); + requests[slots * i + 2] = CompletableFuture.supplyAsync(getSupplier(map, i)); + requests[slots * i + 3] = CompletableFuture.supplyAsync(getSupplier(map, i)); + } + CompletableFuture.allOf(requests).join(); + } + + protected abstract Supplier putSupplier(Map map, int key); + protected abstract Supplier getSupplier(Map map, int key); +} \ No newline at end of file From 407861afac9e1b78ed19206280e3d0f23a7e90b5 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Mar 2020 18:18:05 +0100 Subject: [PATCH 033/278] BAEL-3855 --- .../lock/ConcurrentAccessBenchmark.java | 45 ++++++++++--------- .../lock/ConcurrentAccessExperiment.java | 20 ++------- .../baeldung/concurrent/lock/StripedLock.java | 7 +-- 3 files changed, 28 insertions(+), 44 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java index 7c84c39804..4dfbd8ea18 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java @@ -1,5 +1,7 @@ package com.baeldung.concurrent.lock; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; import org.openjdk.jmh.annotations.Benchmark; @@ -7,14 +9,12 @@ import org.openjdk.jmh.annotations.BenchmarkMode; import org.openjdk.jmh.annotations.Fork; import org.openjdk.jmh.annotations.Mode; import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.annotations.Warmup; @State(Scope.Thread) -@Fork(value = 1) +@Fork(value = 2) @Warmup(iterations = 0) public class ConcurrentAccessBenchmark { ConcurrentAccessExperiment accessMyMap; @@ -22,28 +22,31 @@ public class ConcurrentAccessBenchmark { static final int THREADS = 10000; static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; - @Param({"Single Lock", "Striped Lock"}) - private String lockType; - - @Param({"HashMap", "ConcurrentHashMap"}) - private String mapType; - - @Setup - public void setup() { - switch (lockType) { - case "Single Lock": - accessMyMap = new SingleLock(); - break; - case "Striped Lock": - accessMyMap = new StripedLock(BUCKETS); - break; - } + @Benchmark + @BenchmarkMode(Mode.Throughput) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public void singleLockHashMap() throws InterruptedException { + (new SingleLock()).doWork(new HashMap(), THREADS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void test() throws InterruptedException { - accessMyMap.doWork(mapType, THREADS, SLOTS); + public void stripedLockHashMap() throws InterruptedException { + (new StripedLock(BUCKETS)).doWork(new HashMap(), THREADS, SLOTS); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public void singleLockConcurrentHashMap() throws InterruptedException { + (new SingleLock()).doWork(new ConcurrentHashMap(), THREADS, SLOTS); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + @OutputTimeUnit(TimeUnit.MILLISECONDS) + public void stripedLockConcurrentHashMap() throws InterruptedException { + (new StripedLock(BUCKETS)).doWork(new ConcurrentHashMap(), THREADS, SLOTS); } } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java index b1276410ce..ec6d3895da 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessExperiment.java @@ -1,30 +1,14 @@ package com.baeldung.concurrent.lock; -import java.util.HashMap; import java.util.Map; import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; import com.google.common.base.Supplier; public abstract class ConcurrentAccessExperiment { - public ConcurrentAccessExperiment() { - } - - private Map doMapSetup(String typeOfMap) { - switch (typeOfMap) { - case "HashMap": - return new HashMap(); - case "ConcurrentHashMap": - return new ConcurrentHashMap(); - } - return null; - } - - public final void doWork(String typeOfMap, int threads, int slots) { + public final Map doWork(Map map, int threads, int slots) { CompletableFuture[] requests = new CompletableFuture[threads * slots]; - Map map = doMapSetup(typeOfMap); for (int i = 0; i < threads; i++) { requests[slots * i + 0] = CompletableFuture.supplyAsync(putSupplier(map, i)); @@ -33,6 +17,8 @@ public abstract class ConcurrentAccessExperiment { requests[slots * i + 3] = CompletableFuture.supplyAsync(getSupplier(map, i)); } CompletableFuture.allOf(requests).join(); + + return map; } protected abstract Supplier putSupplier(Map map, int key); diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index fad7243bf4..77bf2de7c0 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -10,12 +10,7 @@ public class StripedLock extends ConcurrentAccessExperiment { Striped lock; public StripedLock(int buckets) { - lock = getStripedLock(buckets); - } - - private Striped getStripedLock(int buckets) { - Striped map = Striped.lock(buckets); - return map; + lock = Striped.lock(buckets); } protected synchronized Supplier putSupplier(Map map, int key) { From e09d87a60494ff1f4296fc8c8f11c7ae867d5bf8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Mar 2020 19:56:30 +0100 Subject: [PATCH 034/278] BAEL-3855 --- .../baeldung/concurrent/lock/SingleLock.java | 24 +++++++------- .../baeldung/concurrent/lock/StripedLock.java | 32 +++++++++++-------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java index 8a3106f650..84a82baff2 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -14,30 +14,30 @@ public class SingleLock extends ConcurrentAccessExperiment { protected synchronized Supplier putSupplier(Map map, int key) { return (()-> { - boolean done = false; try { - while(!done) { - done = lock.tryLock(); - } + lock.lock(); map.put("key" + key, "value" + key); + } catch (Exception e) { + this.putSupplier(map, key); } finally { - lock.unlock(); - } + try { + lock.unlock(); + } catch (Exception e) {} } return null; }); } protected synchronized Supplier getSupplier(Map map, int key) { return (()-> { - boolean done = false; try { - while(!done) { - done = lock.tryLock(); - } + lock.lock(); map.get("key" + key); + } catch (Exception e) { + this.getSupplier(map, key); } finally { - lock.unlock(); - } + try { + lock.unlock(); + } catch (Exception e) {} } return null; }); } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index 77bf2de7c0..ac94de6451 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -7,23 +7,25 @@ import com.google.common.base.Supplier; import com.google.common.util.concurrent.Striped; public class StripedLock extends ConcurrentAccessExperiment { - Striped lock; + Striped stripedLock; public StripedLock(int buckets) { - lock = Striped.lock(buckets); + stripedLock = Striped.lock(buckets); } protected synchronized Supplier putSupplier(Map map, int key) { return (()-> { - Lock currentLock = lock.get("key" + key); - boolean done = false; + int bucket = key % stripedLock.size(); + Lock lock = stripedLock.get(bucket); try { - while(!done) { - done = currentLock.tryLock(); - } + lock.tryLock(); map.put("key" + key, "value" + key); + } catch (Exception e) { + this.putSupplier(map, key); } finally { - currentLock.unlock(); + try { + lock.unlock(); + } catch (Exception e) {} } return null; }); @@ -31,15 +33,17 @@ public class StripedLock extends ConcurrentAccessExperiment { protected synchronized Supplier getSupplier(Map map, int key) { return (()-> { - Lock currentLock = lock.get("key" + key); - boolean done = false; + int bucket = key % stripedLock.size(); + Lock lock = stripedLock.get(bucket); try { - while(!done) { - done = currentLock.tryLock(); - } + lock.tryLock(); map.get("key" + key); + } catch (Exception e) { + this.getSupplier(map, key); } finally { - currentLock.unlock(); + try { + lock.unlock(); + } catch (Exception e) {} } return null; }); From e501b2092f1b6872dd9f483800d5e8f9d3148c72 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Mar 2020 20:09:14 +0100 Subject: [PATCH 035/278] BAEL-3855 --- .../main/java/com/baeldung/concurrent/lock/SingleLock.java | 4 ++-- .../main/java/com/baeldung/concurrent/lock/StripedLock.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java index 84a82baff2..43c6c3e747 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -12,7 +12,7 @@ public class SingleLock extends ConcurrentAccessExperiment { lock = new ReentrantLock(); } - protected synchronized Supplier putSupplier(Map map, int key) { + protected Supplier putSupplier(Map map, int key) { return (()-> { try { lock.lock(); @@ -27,7 +27,7 @@ public class SingleLock extends ConcurrentAccessExperiment { }); } - protected synchronized Supplier getSupplier(Map map, int key) { + protected Supplier getSupplier(Map map, int key) { return (()-> { try { lock.lock(); diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index ac94de6451..8b661ecedc 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -13,7 +13,7 @@ public class StripedLock extends ConcurrentAccessExperiment { stripedLock = Striped.lock(buckets); } - protected synchronized Supplier putSupplier(Map map, int key) { + protected Supplier putSupplier(Map map, int key) { return (()-> { int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); @@ -31,7 +31,7 @@ public class StripedLock extends ConcurrentAccessExperiment { }); } - protected synchronized Supplier getSupplier(Map map, int key) { + protected Supplier getSupplier(Map map, int key) { return (()-> { int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); From 880f922df3c4ae9cad08fd3ccb1c1d6f701fbabc Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Mar 2020 20:13:12 +0100 Subject: [PATCH 036/278] BAEL-3855 identation --- .../main/java/com/baeldung/concurrent/lock/SingleLock.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java index 43c6c3e747..9bbac82c6d 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -22,7 +22,8 @@ public class SingleLock extends ConcurrentAccessExperiment { } finally { try { lock.unlock(); - } catch (Exception e) {} } + } catch (Exception e) {} + } return null; }); } @@ -37,7 +38,8 @@ public class SingleLock extends ConcurrentAccessExperiment { } finally { try { lock.unlock(); - } catch (Exception e) {} } + } catch (Exception e) {} + } return null; }); } From fad2d2a67ccc4d709f817ae902fa5078cca00d68 Mon Sep 17 00:00:00 2001 From: Roger Yates <587230+rojyates@users.noreply.github.com> Date: Thu, 12 Mar 2020 06:12:42 +1000 Subject: [PATCH 037/278] BAEL-3603 Add line separator to preserve lines read --- .../com/baeldung/blockingnonblocking/BlockingClientUnitTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java index eca2a2638f..3fc968ded0 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java @@ -40,6 +40,7 @@ public class BlockingClientUnitTest { for (String line; (line = reader.readLine()) != null; ) { ourStore.append(line); + ourStore.append(System.lineSeparator()); } } From 0e3a4221fe622b572358ea8a656082f59f190f48 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 13 Mar 2020 16:33:34 +0100 Subject: [PATCH 038/278] BAEL-3855 --- .../lock/ConcurrentAccessBenchmark.java | 21 ++++++++++--------- .../baeldung/concurrent/lock/StripedLock.java | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java index 4dfbd8ea18..2dcaa5cb53 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java @@ -3,6 +3,7 @@ package com.baeldung.concurrent.lock; import java.util.HashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import java.util.Map; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.BenchmarkMode; @@ -25,28 +26,28 @@ public class ConcurrentAccessBenchmark { @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void singleLockHashMap() throws InterruptedException { - (new SingleLock()).doWork(new HashMap(), THREADS, SLOTS); + public Map singleLockHashMap() throws InterruptedException { + return (new SingleLock()).doWork(new HashMap(), THREADS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void stripedLockHashMap() throws InterruptedException { - (new StripedLock(BUCKETS)).doWork(new HashMap(), THREADS, SLOTS); + public Map stripedLockHashMap() throws InterruptedException { + return (new StripedLock(BUCKETS)).doWork(new HashMap(), THREADS, SLOTS); } - + @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void singleLockConcurrentHashMap() throws InterruptedException { - (new SingleLock()).doWork(new ConcurrentHashMap(), THREADS, SLOTS); + public Map singleLockConcurrentHashMap() throws InterruptedException { + return (new SingleLock()).doWork(new ConcurrentHashMap(), THREADS, SLOTS); } - + @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) - public void stripedLockConcurrentHashMap() throws InterruptedException { - (new StripedLock(BUCKETS)).doWork(new ConcurrentHashMap(), THREADS, SLOTS); + public Map stripedLockConcurrentHashMap() throws InterruptedException { + return (new StripedLock(BUCKETS)).doWork(new ConcurrentHashMap(), THREADS, SLOTS); } } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index 8b661ecedc..46610c3b78 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -15,7 +15,7 @@ public class StripedLock extends ConcurrentAccessExperiment { protected Supplier putSupplier(Map map, int key) { return (()-> { - int bucket = key % stripedLock.size(); + int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); try { lock.tryLock(); @@ -33,7 +33,7 @@ public class StripedLock extends ConcurrentAccessExperiment { protected Supplier getSupplier(Map map, int key) { return (()-> { - int bucket = key % stripedLock.size(); + int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); try { lock.tryLock(); From 205ee99874c09154d3416729ca964149a72e57a1 Mon Sep 17 00:00:00 2001 From: Florin Hriscu Date: Fri, 13 Mar 2020 21:25:17 +0200 Subject: [PATCH 039/278] BAEL-3859 Remove unnecessary equals and hashcode overriden methods. --- .../AtomicMarkableReferenceUnitTest.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java index b864c78559..4ac9e53a43 100644 --- a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java @@ -1,6 +1,5 @@ package com.baeldung.concurrent.atomic; -import java.util.Objects; import java.util.concurrent.atomic.AtomicMarkableReference; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -18,24 +17,21 @@ public class AtomicMarkableReferenceUnitTest { this.name = name; } - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof Employee)) - return false; - Employee employee = (Employee) obj; - return id == employee.id && name.equals(employee.name); + public int getId() { + return id; } - @Override - public int hashCode() { - return Objects.hash(id, name); + public void setId(int id) { + this.id = id; } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } } @Test From f7ae2095371e0c0852724a63c53ea3d14d78367e Mon Sep 17 00:00:00 2001 From: Florin Hriscu Date: Fri, 13 Mar 2020 22:46:41 +0200 Subject: [PATCH 040/278] BAEL-3859 Add type to employeeNode and fix order of parameters in assertEquals method calls. --- .../AtomicMarkableReferenceUnitTest.java | 56 +++++++++---------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java index 4ac9e53a43..d83146c6e8 100644 --- a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java @@ -6,8 +6,6 @@ import org.junit.jupiter.api.Test; public class AtomicMarkableReferenceUnitTest { - private AtomicMarkableReference employeeNode; - class Employee { private int id; private String name; @@ -31,19 +29,19 @@ public class AtomicMarkableReferenceUnitTest { public void setName(String name) { this.name = name; - } + } } @Test void givenMarkValueAsTrue_whenUsingIsMarkedMethod_thenMarkValueShouldBeTrue() { - employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), true); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenMarkValueAsFalse_whenUsingIsMarkedMethod_thenMarkValueShouldBeFalse() { - employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), false); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), false); Assertions.assertFalse(employeeNode.isMarked()); } @@ -51,39 +49,39 @@ public class AtomicMarkableReferenceUnitTest { @Test void whenUsingGetReferenceMethod_thenCurrentReferenceShouldBeReturned() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, false); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, false); - Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertEquals(employee, employeeNode.getReference()); } @Test void whenUsingGetMethod_thenCurrentReferenceAndMarkShouldBeReturned() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); boolean[] markHolder = new boolean[1]; Employee currentEmployee = employeeNode.get(markHolder); - Assertions.assertEquals(currentEmployee, employee); + Assertions.assertEquals(employee, currentEmployee); Assertions.assertTrue(markHolder[0]); } @Test void givenNewReferenceAndMark_whenUsingSetMethod_thenCurrentReferenceAndMarkShouldBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); employeeNode.set(newEmployee, false); - Assertions.assertEquals(employeeNode.getReference(), newEmployee); + Assertions.assertEquals(newEmployee, employeeNode.getReference()); Assertions.assertFalse(employeeNode.isMarked()); } @Test void givenTheSameObjectReference_whenUsingAttemptMarkMethod_thenMarkShouldBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Assertions.assertTrue(employeeNode.attemptMark(employee, false)); Assertions.assertFalse(employeeNode.isMarked()); @@ -93,7 +91,7 @@ public class AtomicMarkableReferenceUnitTest { void givenDifferentObjectReference_whenUsingAttemptMarkMethod_thenMarkShouldNotBeUpdated() { Employee employee = new Employee(123, "Mike"); Employee expectedEmployee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Assertions.assertFalse(employeeNode.attemptMark(expectedEmployee, false)); Assertions.assertTrue(employeeNode.isMarked()); @@ -102,88 +100,88 @@ public class AtomicMarkableReferenceUnitTest { @Test void givenCurrentReferenceAndCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertTrue(employeeNode.compareAndSet(employee, newEmployee, true, false)); - Assertions.assertEquals(employeeNode.getReference(), newEmployee); + Assertions.assertEquals(newEmployee, employeeNode.getReference()); Assertions.assertFalse(employeeNode.isMarked()); } @Test void givenNotCurrentReferenceAndCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertFalse(employeeNode.compareAndSet(new Employee(1234, "Steve"), newEmployee, true, false)); - Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertEquals(employee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenCurrentReferenceAndNotCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertFalse(employeeNode.compareAndSet(employee, newEmployee, false, true)); - Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertEquals(employee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenNotCurrentReferenceAndNotCurrentMark_whenUsingCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertFalse(employeeNode.compareAndSet(new Employee(1234, "Steve"), newEmployee, false, true)); - Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertEquals(employee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenCurrentReferenceAndCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertTrue(employeeNode.weakCompareAndSet(employee, newEmployee, true, false)); - Assertions.assertEquals(employeeNode.getReference(), newEmployee); + Assertions.assertEquals(newEmployee, employeeNode.getReference()); Assertions.assertFalse(employeeNode.isMarked()); } @Test void givenNotCurrentReferenceAndCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { Employee expectedEmployee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(expectedEmployee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(expectedEmployee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertFalse(employeeNode.weakCompareAndSet(new Employee(1234, "Steve"), newEmployee, true, false)); - Assertions.assertEquals(employeeNode.getReference(), expectedEmployee); + Assertions.assertEquals(expectedEmployee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenCurrentReferenceAndNotCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { Employee expectedEmployee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(expectedEmployee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(expectedEmployee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertFalse(employeeNode.weakCompareAndSet(expectedEmployee, newEmployee, false, true)); - Assertions.assertEquals(employeeNode.getReference(), expectedEmployee); + Assertions.assertEquals(expectedEmployee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenNotCurrentReferenceAndNotCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { Employee employee = new Employee(123, "Mike"); - employeeNode = new AtomicMarkableReference(employee, true); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertFalse(employeeNode.weakCompareAndSet(new Employee(1234, "Steve"), newEmployee, false, true)); - Assertions.assertEquals(employeeNode.getReference(), employee); + Assertions.assertEquals(employee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } } From 8e3d81fcb962c262bd306bb8e5d1ac6c97566db6 Mon Sep 17 00:00:00 2001 From: chirag d Date: Sat, 14 Mar 2020 12:24:44 +0530 Subject: [PATCH 041/278] BAEL-3901 Clear Site Data Header in Spring Security --- spring-security-modules/pom.xml | 1 + .../spring-security-clear-site-data/pom.xml | 54 +++++++++++++++++++ .../LogoutClearSiteDataController.java | 16 ++++++ .../com/baeldung/SpringSecurityConfig.java | 35 ++++++++++++ .../src/main/java/com/baeldung/WebConfig.java | 19 +++++++ ...LogoutClearSiteDataControllerUnitTest.java | 47 ++++++++++++++++ 6 files changed, 172 insertions(+) create mode 100644 spring-security-modules/spring-security-clear-site-data/pom.xml create mode 100644 spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/LogoutClearSiteDataController.java create mode 100644 spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/SpringSecurityConfig.java create mode 100644 spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/WebConfig.java create mode 100644 spring-security-modules/spring-security-clear-site-data/src/test/java/com/baeldung/LogoutClearSiteDataControllerUnitTest.java diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 49a0db03ed..07c326c10e 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -17,6 +17,7 @@ spring-security-acl spring-security-angular/server spring-security-cache-control + spring-security-clear-site-data spring-security-core spring-security-cors spring-security-kerberos diff --git a/spring-security-modules/spring-security-clear-site-data/pom.xml b/spring-security-modules/spring-security-clear-site-data/pom.xml new file mode 100644 index 0000000000..e58debc0aa --- /dev/null +++ b/spring-security-modules/spring-security-clear-site-data/pom.xml @@ -0,0 +1,54 @@ + + + + 4.0.0 + + com.baeldung + spring-security-clear-site-data + 1.0-SNAPSHOT + spring-security-clear-site-data + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.security + spring-security-web + ${spring.mvc.version} + + + org.springframework.security + spring-security-config + ${spring.mvc.version} + + + org.springframework.security + spring-security-test + ${spring.mvc.version} + test + + + org.springframework + spring-webmvc + ${spring.mvc.version} + + + javax.servlet + javax.servlet-api + ${javax.version} + + + + + + 5.2.2.RELEASE + 4.0.1 + + + diff --git a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/LogoutClearSiteDataController.java b/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/LogoutClearSiteDataController.java new file mode 100644 index 0000000000..d27fa18116 --- /dev/null +++ b/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/LogoutClearSiteDataController.java @@ -0,0 +1,16 @@ +package com.baeldung; + +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; + +@Controller +public class LogoutClearSiteDataController { + + @GetMapping(value = "/baeldung/logout") + public ResponseEntity logout(@PathVariable String name) { + return ResponseEntity.ok().build(); + } + +} diff --git a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/SpringSecurityConfig.java b/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/SpringSecurityConfig.java new file mode 100644 index 0000000000..fd43fb2c9e --- /dev/null +++ b/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/SpringSecurityConfig.java @@ -0,0 +1,35 @@ +package com.baeldung; + + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.web.authentication.logout.HeaderWriterLogoutHandler; +import org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter; + +import static org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter.Directive.CACHE; +import static org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter.Directive.COOKIES; +import static org.springframework.security.web.header.writers.ClearSiteDataHeaderWriter.Directive.STORAGE; + +@Configuration +@EnableWebSecurity +@EnableGlobalMethodSecurity(prePostEnabled = true) +public class SpringSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + + http.csrf() + .disable() + .formLogin() + .loginPage("/login.html") + .loginProcessingUrl("/perform_login") + .defaultSuccessUrl("/homepage.html", true) + .and() + .logout().logoutUrl("/baeldung/logout") + .addLogoutHandler(new HeaderWriterLogoutHandler( + new ClearSiteDataHeaderWriter(CACHE, COOKIES, STORAGE))); + } +} diff --git a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/WebConfig.java b/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/WebConfig.java new file mode 100644 index 0000000000..16826e28b8 --- /dev/null +++ b/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/WebConfig.java @@ -0,0 +1,19 @@ +package com.baeldung; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.CacheControl; +import org.springframework.web.servlet.config.annotation.EnableWebMvc; +import org.springframework.web.servlet.config.annotation.InterceptorRegistry; +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import org.springframework.web.servlet.mvc.WebContentInterceptor; + +import java.util.concurrent.TimeUnit; + +@EnableWebMvc +@Configuration +@ComponentScan(basePackages = {"com.baeldung"}) +public class WebConfig implements WebMvcConfigurer { +} \ No newline at end of file diff --git a/spring-security-modules/spring-security-clear-site-data/src/test/java/com/baeldung/LogoutClearSiteDataControllerUnitTest.java b/spring-security-modules/spring-security-clear-site-data/src/test/java/com/baeldung/LogoutClearSiteDataControllerUnitTest.java new file mode 100644 index 0000000000..905a866413 --- /dev/null +++ b/spring-security-modules/spring-security-clear-site-data/src/test/java/com/baeldung/LogoutClearSiteDataControllerUnitTest.java @@ -0,0 +1,47 @@ +package com.baeldung; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.web.context.WebApplicationContext; +import javax.servlet.Filter; + +@ExtendWith(SpringExtension.class) +@WebAppConfiguration +@ContextConfiguration(classes = {SpringSecurityConfig.class, WebConfig.class}) +public class LogoutClearSiteDataControllerUnitTest { + + @Autowired + private WebApplicationContext wac; + + @Autowired + private Filter springSecurityFilterChain; + + private MockMvc mockMvc; + + @BeforeEach + void setup() throws Exception { + this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).addFilters(springSecurityFilterChain).build(); + } + + @Test + void whenResponseBody_thenReturnCacheHeader() throws Exception { + this.mockMvc + .perform(MockMvcRequestBuilders + .get("/baeldung/logout").secure(true)) + .andDo(MockMvcResultHandlers.print()) + .andExpect(MockMvcResultMatchers.status().is(302)) + .andExpect(MockMvcResultMatchers.header() + .string("Clear-Site-Data", "\"cache\", \"cookies\", \"storage\"")); + } + +} From 2833ef5bcdea6fd5088504c6b2a1ec4b2618c7f1 Mon Sep 17 00:00:00 2001 From: catalin-burcea Date: Sat, 14 Mar 2020 22:07:49 +0200 Subject: [PATCH 042/278] JAVA-911 Need to move existing scala code from java to scala repository --- .gitignore | 2 - core-scala/README.md | 8 - core-scala/pom.xml | 55 ----- .../scala/ControlStructuresDemo.scala | 44 ---- .../scala/com/baeldung/scala/Employee.scala | 27 --- .../scala/com/baeldung/scala/HelloWorld.scala | 6 - .../baeldung/scala/HigherOrderFunctions.scala | 27 --- .../scala/com/baeldung/scala/IntSet.scala | 34 --- .../com/baeldung/scala/PatternMatching.scala | 137 ------------ .../main/scala/com/baeldung/scala/Utils.scala | 33 --- .../scala/ControlStructuresDemoUnitTest.scala | 33 --- .../com/baeldung/scala/EmployeeUnitTest.scala | 30 --- ...HigherOrderFunctionsExamplesUnitTest.scala | 82 ------- .../scala/HigherOrderFunctionsUnitTest.scala | 48 ---- .../com/baeldung/scala/IntSetUnitTest.scala | 21 -- .../scala/PatternMatchingUnitTest.scala | 208 ------------------ .../com/baeldung/scala/UtilsUnitTest.scala | 32 --- .../baeldung/scala/regex/RegexUnitTest.scala | 73 ------ pom.xml | 2 - 19 files changed, 902 deletions(-) delete mode 100644 core-scala/README.md delete mode 100644 core-scala/pom.xml delete mode 100644 core-scala/src/main/scala/com/baeldung/scala/ControlStructuresDemo.scala delete mode 100644 core-scala/src/main/scala/com/baeldung/scala/Employee.scala delete mode 100644 core-scala/src/main/scala/com/baeldung/scala/HelloWorld.scala delete mode 100644 core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala delete mode 100644 core-scala/src/main/scala/com/baeldung/scala/IntSet.scala delete mode 100644 core-scala/src/main/scala/com/baeldung/scala/PatternMatching.scala delete mode 100644 core-scala/src/main/scala/com/baeldung/scala/Utils.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsExamplesUnitTest.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/PatternMatchingUnitTest.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala delete mode 100644 core-scala/src/test/scala/com/baeldung/scala/regex/RegexUnitTest.scala diff --git a/.gitignore b/.gitignore index 729dea62d5..d3a5dae06d 100644 --- a/.gitignore +++ b/.gitignore @@ -73,8 +73,6 @@ ninja/devDb.mv.db **/out-tsc **/nbproject/ **/nb-configuration.xml -core-scala/.cache-main -core-scala/.cache-tests persistence-modules/hibernate5/transaction.log diff --git a/core-scala/README.md b/core-scala/README.md deleted file mode 100644 index 13929ff721..0000000000 --- a/core-scala/README.md +++ /dev/null @@ -1,8 +0,0 @@ -## Core Scala - -This module contains articles about Scala's core features - -### Relevant Articles: - -- [Introduction to Scala](https://www.baeldung.com/scala-intro) -- [Regular Expressions in Scala](https://www.baeldung.com/scala/regular-expressions) diff --git a/core-scala/pom.xml b/core-scala/pom.xml deleted file mode 100644 index d72727dd39..0000000000 --- a/core-scala/pom.xml +++ /dev/null @@ -1,55 +0,0 @@ - - - 4.0.0 - core-scala - 1.0-SNAPSHOT - core-scala - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.scala-lang - scala-library - ${scala.version} - - - - - src/main/scala - src/test/scala - - - net.alchim31.maven - scala-maven-plugin - ${scala.plugin.version} - - - - compile - testCompile - - - - -dependencyfile - ${project.build.directory}/.scala_dependencies - - - - - - - - - - 2.12.7 - 3.3.2 - - - diff --git a/core-scala/src/main/scala/com/baeldung/scala/ControlStructuresDemo.scala b/core-scala/src/main/scala/com/baeldung/scala/ControlStructuresDemo.scala deleted file mode 100644 index 7c1281e573..0000000000 --- a/core-scala/src/main/scala/com/baeldung/scala/ControlStructuresDemo.scala +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.scala - -/** - * Sample code demonstrating the various control structured. - * - * @author Chandra Prakash - * - */ -object ControlStructuresDemo { - def gcd(x : Int, y : Int) : Int = { - if (y == 0) x else gcd(y, x % y) - } - - def gcdIter(x : Int, y : Int) : Int = { - var a = x - var b = y - while (b > 0) { - a = a % b - val t = a - a = b - b = t - } - a - } - - def rangeSum(a : Int, b : Int) = { - var sum = 0; - for (i <- a to b) { - sum += i - } - sum - } - - def factorial(a : Int) : Int = { - var result = 1; - var i = 1; - do { - result *= i - i = i + 1 - } while (i <= a) - result - } - -} \ No newline at end of file diff --git a/core-scala/src/main/scala/com/baeldung/scala/Employee.scala b/core-scala/src/main/scala/com/baeldung/scala/Employee.scala deleted file mode 100644 index 9291d958b3..0000000000 --- a/core-scala/src/main/scala/com/baeldung/scala/Employee.scala +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.scala - -/** - * Sample Code demonstrating a class. - * - * @author Chandra Prakash - * - */ -class Employee(val name : String, - var salary : Int, - annualIncrement : Int = 20) { - - def incrementSalary() : Unit = { - salary += annualIncrement - } - - override def toString = - s"Employee(name=$name, salary=$salary)" -} - -/** - * A Trait which will make the toString return upper case value. - */ -trait UpperCasePrinter { - override def toString: String = super.toString toUpperCase -} - diff --git a/core-scala/src/main/scala/com/baeldung/scala/HelloWorld.scala b/core-scala/src/main/scala/com/baeldung/scala/HelloWorld.scala deleted file mode 100644 index b3f0ce09a5..0000000000 --- a/core-scala/src/main/scala/com/baeldung/scala/HelloWorld.scala +++ /dev/null @@ -1,6 +0,0 @@ -package com.baeldung.scala - -object HelloWorld extends App { - println("Hello World!") - args foreach println -} diff --git a/core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala b/core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala deleted file mode 100644 index 02c41a5f8c..0000000000 --- a/core-scala/src/main/scala/com/baeldung/scala/HigherOrderFunctions.scala +++ /dev/null @@ -1,27 +0,0 @@ -package com.baeldung.scala - -/** - * Sample higher order functions. - * - * @author Chandra Prakash - * - */ -object HigherOrderFunctions { - - def mapReduce(r : (Int, Int) => Int, - i : Int, - m : Int => Int, - a : Int, b : Int): Int = { - def iter(a : Int, result : Int) : Int = { - if (a > b) result - else iter(a + 1, r(m(a), result)) - } - iter(a, i) - } - - def whileLoop(condition : => Boolean)(body : => Unit) : Unit = - if (condition) { - body - whileLoop(condition)(body) - } -} \ No newline at end of file diff --git a/core-scala/src/main/scala/com/baeldung/scala/IntSet.scala b/core-scala/src/main/scala/com/baeldung/scala/IntSet.scala deleted file mode 100644 index f1a5722a4e..0000000000 --- a/core-scala/src/main/scala/com/baeldung/scala/IntSet.scala +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.scala - -/** - * An abstract class for set of integers and its implementation. - * - * @author Chandra Prakash - * - */ -abstract class IntSet { - // add an element to the set - def incl(x : Int) : IntSet - - // whether an element belongs to the set - def contains(x : Int) : Boolean -} - -class EmptyIntSet extends IntSet { - - def contains(x : Int) : Boolean = false - - def incl(x : Int) = - new NonEmptyIntSet(x, this) -} - -class NonEmptyIntSet(val head : Int, val tail : IntSet) - extends IntSet { - - def contains(x : Int) : Boolean = - head == x || (tail contains x) - - def incl(x : Int) : IntSet = - if (this contains x) this - else new NonEmptyIntSet(x, this) -} \ No newline at end of file diff --git a/core-scala/src/main/scala/com/baeldung/scala/PatternMatching.scala b/core-scala/src/main/scala/com/baeldung/scala/PatternMatching.scala deleted file mode 100644 index 71458237d6..0000000000 --- a/core-scala/src/main/scala/com/baeldung/scala/PatternMatching.scala +++ /dev/null @@ -1,137 +0,0 @@ -package com.baeldung.scala - -// Case Class -abstract class Animal - -case class Mammal(name: String, fromSea: Boolean) extends Animal - -case class Bird(name: String) extends Animal - -case class Fish(name: String) extends Animal - -// Sealed Class -sealed abstract class CardSuit - -case class Spike() extends CardSuit - -case class Diamond() extends CardSuit - -case class Heart() extends CardSuit - -case class Club() extends CardSuit - -object Person { - def apply(fullName: String) = fullName - - def unapply(fullName: String): Option[String] = { - if (!fullName.isEmpty) - Some(fullName.replaceAll("(?<=\\w)(\\w+)", ".")) - else - None - } -} - -class PatternMatching { - - def caseClassesPatternMatching(animal: Animal): String = { - animal match { - case Mammal(name, fromSea) => s"I'm a $name, a kind of mammal. Am I from the sea? $fromSea" - case Bird(name) => s"I'm a $name, a kind of bird" - case _ => "I'm an unknown animal" - } - } - - def constantsPatternMatching(constant: Any): String = { - constant match { - case 0 => "I'm equal to zero" - case 4.5d => "I'm a double" - case false => "I'm the contrary of true" - case _ => s"I'm unknown and equal to $constant" - } - } - - def sequencesPatternMatching(sequence: Any): String = { - sequence match { - case List(singleElement) => s"I'm a list with one element: $singleElement" - case List(_, _*) => s"I'm a list with one or multiple elements: $sequence" - case Vector(1, 2, _*) => s"I'm a vector: $sequence" - case _ => s"I'm an unrecognized sequence. My value: $sequence" - } - } - - def tuplesPatternMatching(tuple: Any): String = { - tuple match { - case (first, second) => s"I'm a tuple with two elements: $first & $second" - case (first, second, third) => s"I'm a tuple with three elements: $first & $second & $third" - case _ => s"Unrecognized pattern. My value: $tuple" - } - } - - def typedPatternMatching(any: Any): String = { - any match { - case string: String => s"I'm a string. My value: $string" - case integer: Int => s"I'm an integer. My value: $integer" - case _ => s"I'm from an unknown type. My value: $any" - } - } - - def regexPatterns(toMatch: String): String = { - val numeric = """([0-9]+)""".r - val alphabetic = """([a-zA-Z]+)""".r - val alphanumeric = """([a-zA-Z0-9]+)""".r - - toMatch match { - case numeric(value) => s"I'm a numeric with value $value" - case alphabetic(value) => s"I'm an alphabetic with value $value" - case alphanumeric(value) => s"I'm an alphanumeric with value $value" - case _ => s"I contain other characters than alphanumerics. My value $toMatch" - } - } - - def optionsPatternMatching(option: Option[String]): String = { - option match { - case Some(value) => s"I'm not an empty option. Value $value" - case None => "I'm an empty option" - } - } - - def patternGuards(toMatch: Any, maxLength: Int): String = { - toMatch match { - case list: List[Any] if (list.size <= maxLength) => "List is of acceptable size" - case list: List[Any] => "List has not an acceptable size" - case string: String if (string.length <= maxLength) => "String is of acceptable size" - case string: String => "String has not an acceptable size" - case _ => "Input is neither a List or a String" - } - } - - def sealedClass(cardSuit: CardSuit): String = { - cardSuit match { - case Spike() => "Card is spike" - case Club() => "Card is club" - case Heart() => "Card is heart" - case Diamond() => "Card is diamond" - } - } - - def extractors(person: Any): String = { - person match { - case Person(initials) => s"My initials are $initials" - case _ => "Could not extract initials" - } - } - - def closuresPatternMatching(list: List[Any]): List[Any] = { - list.collect { case i: Int if (i < 10) => i } - } - - def catchBlocksPatternMatching(exception: Exception): String = { - try { - throw exception - } catch { - case ex: IllegalArgumentException => "It's an IllegalArgumentException" - case ex: RuntimeException => "It's a RuntimeException" - case _ => "It's an unknown kind of exception" - } - } -} \ No newline at end of file diff --git a/core-scala/src/main/scala/com/baeldung/scala/Utils.scala b/core-scala/src/main/scala/com/baeldung/scala/Utils.scala deleted file mode 100644 index 20bc413646..0000000000 --- a/core-scala/src/main/scala/com/baeldung/scala/Utils.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.scala - -/** - * Some utility methods. - * - * @author Chandra Prakash - * - */ -object Utils { - def average(x : Double, y : Double): Double = (x + y) / 2 - - def randomLessThan(d : Double): Double = { - var random = 0d - do { - random = Math.random() - } while (random >= d) - random - } - - def power(x : Int, y : Int) : Int = { - def powNested(i : Int, accumulator : Int) : Int = { - if (i <= 0) accumulator - else powNested(i - 1, x * accumulator) - } - powNested(y, 1) - } - - def fibonacci(n : Int) : Int = n match { - case 0 | 1 => 1 - case x if x > 1 => - fibonacci(x - 1) + fibonacci(x - 2) - } -} \ No newline at end of file diff --git a/core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala deleted file mode 100644 index 584038ee2c..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/ControlStructuresDemoUnitTest.scala +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.scala - -import com.baeldung.scala.ControlStructuresDemo._ -import org.junit.Assert.assertEquals -import org.junit.Test - -class ControlStructuresDemoUnitTest { - @Test - def givenTwoIntegers_whenGcdCalled_thenCorrectValueReturned() = { - assertEquals(3, gcd(15, 27)) - } - - @Test - def givenTwoIntegers_whenGcdIterCalled_thenCorrectValueReturned() = { - assertEquals(3, gcdIter(15, 27)) - } - - @Test - def givenTwoIntegers_whenRangeSumcalled_thenCorrectValueReturned() = { - assertEquals(55, rangeSum(1, 10)) - } - - @Test - def givenPositiveInteger_whenFactorialInvoked_thenCorrectValueReturned() = { - assertEquals(720, factorial(6)) - } - - @Test - def whenFactorialOf0Invoked_then1Returned() = { - assertEquals(1, factorial(0)) - } - -} \ No newline at end of file diff --git a/core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala deleted file mode 100644 index 0828752a8a..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/EmployeeUnitTest.scala +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.scala - -import org.junit.Assert.assertEquals -import org.junit.Test - -class EmployeeUnitTest { - - @Test - def whenEmployeeSalaryIncremented_thenCorrectSalary() = { - val employee = new Employee("John Doe", 1000) - employee.incrementSalary() - assertEquals(1020, employee.salary) - } - - @Test - def givenEmployee_whenToStringCalled_thenCorrectStringReturned() = { - val employee = new Employee("John Doe", 1000) - assertEquals("Employee(name=John Doe, salary=1000)", employee.toString) - } - - @Test - def givenEmployeeWithTrait_whenToStringCalled_thenCorrectStringReturned() = { - val employee = - new Employee("John Doe", 1000) with UpperCasePrinter - assertEquals("EMPLOYEE(NAME=JOHN DOE, SALARY=1000)", employee.toString) - } - -} - - diff --git a/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsExamplesUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsExamplesUnitTest.scala deleted file mode 100644 index cb43266a48..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsExamplesUnitTest.scala +++ /dev/null @@ -1,82 +0,0 @@ -package com.baeldung.scala - -import org.junit.Assert.assertEquals -import org.junit.Test - - -class HigherOrderFunctionsExamplesUnitTest { - - @Test - def whenCallingMapWithAnonymousFunction_thenTransformationIsApplied() = { - val expected = Seq("sir Alex Ferguson", "sir Bobby Charlton", "sir Frank Lampard") - - val names = Seq("Alex Ferguson", "Bobby Charlton", "Frank Lampard") - val sirNames = names.map(name => "sir " + name) - - assertEquals(expected, sirNames) - } - - @Test - def whenCallingMapWithDefined_thenTransformationIsApplied() = { - val expected = Seq("sir Alex Ferguson", "sir Bobby Charlton", "sir Frank Lampard") - - val names = Seq("Alex Ferguson", "Bobby Charlton", "Frank Lampard") - - def prefixWithSir(name: String) = "sir " + name - val sirNames = names.map(prefixWithSir) - - assertEquals(expected, sirNames) - } - - @Test - def whenCallingFilter_thenUnecessaryElementsAreRemoved() = { - val expected = Seq("John O'Shea", "John Hartson") - - val names = Seq("John O'Shea", "Aiden McGeady", "John Hartson") - val johns = names.filter(name => name.matches("^John .*")) - - assertEquals(expected, johns) - } - - @Test - def whenCallingReduce_thenProperSumIsCalculated() = { - val expected = 2750 - - val earnings = Seq(1000, 1300, 450) - val sumEarnings = earnings.reduce((acc, x) => acc + x) - - assertEquals(expected, sumEarnings) - } - - @Test - def whenCallingFold_thenNumberOfWordsShouldBeCalculated() = { - val expected = 6 - - val strings = Seq("bunch of words", "just me", "it") - val sumEarnings = strings.foldLeft(0)((acc, x) => acc + x.split(" ").size) - - assertEquals(expected, sumEarnings) - } - - @Test - def whenCallingOwnHigherOrderFunction_thenProperFunctionIsReturned() = { - def mathOperation(name: String): (Int, Int) => Int = (x: Int, y: Int) => { - name match { - case "addition" => x + y - case "multiplication" => x * y - case "division" => x/y - case "subtraction" => x - y - } - } - - def add: (Int, Int) => Int = mathOperation("addition") - def mul: (Int, Int) => Int = mathOperation("multiplication") - def div: (Int, Int) => Int = mathOperation("division") - def sub: (Int, Int) => Int = mathOperation("subtraction") - - assertEquals(15, add(10, 5)) - assertEquals(50, mul(10, 5)) - assertEquals(2, div(10, 5)) - assertEquals(5, sub(10, 5)) - } -} \ No newline at end of file diff --git a/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala deleted file mode 100644 index 240c879d7f..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/HigherOrderFunctionsUnitTest.scala +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.scala - -import com.baeldung.scala.HigherOrderFunctions.mapReduce -import org.junit.Assert.assertEquals -import org.junit.Test - -class HigherOrderFunctionsUnitTest { - - @Test - def whenCalledWithSumAndSquareFunctions_thenCorrectValueReturned() = { - def square(x : Int) = x * x - - def sum(x : Int, y : Int) = x + y - - def sumSquares(a : Int, b : Int) = - mapReduce(sum, 0, square, a, b) - - assertEquals(385, sumSquares(1, 10)) - } - - @Test - def whenComputingSumOfSquaresWithAnonymousFunctions_thenCorrectValueReturned() = { - def sumSquares(a : Int, b : Int) = - mapReduce((x, y) => x + y, 0, x => x * x, a, b) - - assertEquals(385, sumSquares(1, 10)) - } - - @Test - def givenCurriedFunctions_whenInvoked_thenCorrectValueReturned() = { - // a curried function - def sum(f : Int => Int)(a : Int, - b : Int) : Int = - if (a > b) 0 else f(a) + sum(f)(a + 1, b) - - // another curried function - def mod(n : Int)(x : Int) = x % n - - // application of a curried function - assertEquals(1, mod(5)(6)) - - // partial application of curried function - // trailing underscore is required to make function type explicit - val sumMod5 = sum(mod(5)) _ - - assertEquals(10, sumMod5(6, 10)) - } -} \ No newline at end of file diff --git a/core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala deleted file mode 100644 index ac27389d70..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/IntSetUnitTest.scala +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.scala - -import org.junit.Assert.assertFalse -import org.junit.Test - -class IntSetUnitTest { - - @Test - def givenSetof1To10_whenContains11Called_thenFalse() = { - - // Set up a set containing integers 1 to 10. - val set1To10 = - Range(1, 10) - .foldLeft(new EmptyIntSet() : IntSet) { - (x, y) => x incl y - } - - assertFalse(set1To10 contains 11) - } - -} \ No newline at end of file diff --git a/core-scala/src/test/scala/com/baeldung/scala/PatternMatchingUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/PatternMatchingUnitTest.scala deleted file mode 100644 index 21a2f0e871..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/PatternMatchingUnitTest.scala +++ /dev/null @@ -1,208 +0,0 @@ -package com.baeldung.scala - -import java.io.FileNotFoundException - -import org.junit.Assert.assertEquals -import org.junit.Test - -class PatternMatchingUnitTest { - @Test - def whenAMammalIsGivenToTheMatchExpression_ThenItsRecognizedAsMammal(): Unit = { - val result = new PatternMatching().caseClassesPatternMatching(Mammal("Lion", fromSea = false)) - assertEquals("I'm a Lion, a kind of mammal. Am I from the sea? false", result) - } - - @Test - def whenABirdIsGivenToTheMatchExpression_ThenItsRecognizedAsBird(): Unit = { - val result = new PatternMatching().caseClassesPatternMatching(Bird("Pigeon")) - assertEquals("I'm a Pigeon, a kind of bird", result) - } - - @Test - def whenAnUnkownAnimalIsGivenToTheMatchExpression_TheDefaultClauseIsUsed(): Unit = { - val result = new PatternMatching().caseClassesPatternMatching(Fish("Tuna")) - assertEquals("I'm an unknown animal", result) - } - - @Test - def whenTheConstantZeroIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().constantsPatternMatching(0) - assertEquals("I'm equal to zero", result) - } - - @Test - def whenFourAndAHalfIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().constantsPatternMatching(4.5d) - assertEquals("I'm a double", result) - } - - @Test - def whenTheBooleanFalseIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().constantsPatternMatching(false) - assertEquals("I'm the contrary of true", result) - } - - @Test - def whenAnUnkownConstantIsPassed_ThenTheDefaultPatternIsUsed(): Unit = { - val result = new PatternMatching().constantsPatternMatching(true) - assertEquals("I'm unknown and equal to true", result) - } - - @Test - def whenASingleElementListIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().sequencesPatternMatching(List("String")) - assertEquals("I'm a list with one element: String", result) - } - - @Test - def whenAMultipleElementsListIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().sequencesPatternMatching(List("Multiple", "Elements")) - assertEquals("I'm a list with one or multiple elements: List(Multiple, Elements)", result) - } - - @Test - def whenAVectorBeginningWithOneAndTwoIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().sequencesPatternMatching(Vector(1, 2, 3)) - assertEquals("I'm a vector: Vector(1, 2, 3)", result) - } - - @Test - def whenANotMatchingVectorIsPassed_ThenItShouldntMatchAndEnterTheDefaultClause(): Unit = { - val result = new PatternMatching().sequencesPatternMatching(Vector(2, 1)) - assertEquals("I'm an unrecognized sequence. My value: Vector(2, 1)", result) - } - - @Test - def whenAnEmptyListIsPassed_ThenItShouldntMatchAndEnterTheDefaultClause(): Unit = { - val result = new PatternMatching().sequencesPatternMatching(List()) - assertEquals("I'm an unrecognized sequence. My value: List()", result) - } - - @Test - def whenATwoElementsTupleIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().tuplesPatternMatching(("First", "Second")) - assertEquals("I'm a tuple with two elements: First & Second", result) - } - - @Test - def whenAThreeElementsTupleIsPassed_ThenItMatchesTheCorrespondingPattern(): Unit = { - val result = new PatternMatching().tuplesPatternMatching(("First", "Second", "Third")) - assertEquals("I'm a tuple with three elements: First & Second & Third", result) - } - - @Test - def whenAnoterKindOfTupleIsPassed_ThenItShouldntMatchAndReturnTheDefaultPattern(): Unit = { - val result = new PatternMatching().tuplesPatternMatching(("First")) - assertEquals("Unrecognized pattern. My value: First", result) - } - - @Test - def whenAStringConsistingOfNumericsOnlyIsPassed_ThenItShouldMatchTheNumericRegex(): Unit = { - val result = new PatternMatching().regexPatterns("123") - assertEquals("I'm a numeric with value 123", result) - } - - @Test - def whenAStringConsistignOfAlphabeticsOnlyIsPassed_ThenItShouldMatchTheAlphabeticRegex(): Unit = { - val result = new PatternMatching().regexPatterns("abc") - assertEquals("I'm an alphabetic with value abc", result) - } - - @Test - def whenAStringConsistignOfAlphanumericsOnlyIsPassed_ThenItShouldMatchTheAlphanumericRegex(): Unit = { - val result = new PatternMatching().regexPatterns("abc123") - assertEquals("I'm an alphanumeric with value abc123", result) - } - - @Test - def whenAnotherTypeOfStringIsPassed_ThenItShouldntMatchAndReturnTheDefaultPattern(): Unit = { - val result = new PatternMatching().regexPatterns("abc_123") - assertEquals("I contain other characters than alphanumerics. My value abc_123", result) - } - - @Test - def whenAFilledOptionIsPassed_ThenItShouldMatchTheSomeClause(): Unit = { - val result = new PatternMatching().optionsPatternMatching(Option.apply("something")) - assertEquals("I'm not an empty option. Value something", result) - } - - @Test - def whenAnEmptyOptionIsPassed_ThenItShouldMatchTheNoneClause(): Unit = { - val result = new PatternMatching().optionsPatternMatching(Option.empty) - assertEquals("I'm an empty option", result) - } - - @Test - def whenAListWithAcceptedSizeIsPassed_ThenThePositiveMessageIsSent(): Unit = { - val result = new PatternMatching().patternGuards(List(1, 2), 3) - assertEquals("List is of acceptable size", result) - } - - @Test - def whenAListWithAnUnacceptedSizeIsPassed_ThenTheNegativeMessageIsSent(): Unit = { - val result = new PatternMatching().patternGuards(List(1, 2, 3, 4), 3) - assertEquals("List has not an acceptable size", result) - } - - @Test - def whenAStringWithAcceptedSizeIsPassed_ThenThePositiveMessageIsSent(): Unit = { - val result = new PatternMatching().patternGuards("OK", 3) - assertEquals("String is of acceptable size", result) - } - - @Test - def whenAStringWithAnUnacceptedSizeIsPassed_ThenTheNegativeMessageIsSent(): Unit = { - val result = new PatternMatching().patternGuards("Not OK", 3) - assertEquals("String has not an acceptable size", result) - } - - @Test - def whenAnObjectWhichIsNotAListOrAStringIsPassed_thenTheDefaultClauseIsUsed(): Unit = { - val result = new PatternMatching().patternGuards(1, 1) - assertEquals("Input is neither a List or a String", result) - } - - @Test - def whenACardSuitIsPassed_ThenTheCorrespondingMatchCaseClauseIsUsed(): Unit = { - assertEquals("Card is spike", new PatternMatching().sealedClass(Spike())) - assertEquals("Card is club", new PatternMatching().sealedClass(Club())) - assertEquals("Card is heart", new PatternMatching().sealedClass(Heart())) - assertEquals("Card is diamond", new PatternMatching().sealedClass(Diamond())) - } - - @Test - def whenAnObjectWithExtractorIsPassed_ThenTheExtractedValueIsUsedInTheCaseClause(): Unit = { - val person = Person("John Smith") - val result = new PatternMatching().extractors(person) - assertEquals("My initials are J. S.", result) - } - - @Test - def whenAnObjectWithExtractorIsPassed_AndTheValueIsEmpty_ThenTheDefaultCaseClauseIsUsed(): Unit = { - val person = Person("") - val result = new PatternMatching().extractors(person) - assertEquals("Could not extract initials", result) - } - - @Test - def whenAListOfRandomElementsIsPassed_ThenOnlyTheIntegersBelowTenAreReturned(): Unit = { - val input = List(1, 2, "5", 11, true) - val result = new PatternMatching().closuresPatternMatching(input) - assertEquals(List(1, 2), result) - } - - @Test - def whenAnExceptionIsPassed_ThenTheCorrespondingMessageIsReturned(): Unit = { - val pm = new PatternMatching() - - val iae = new IllegalArgumentException() - val re = new RuntimeException() - val fnfe = new FileNotFoundException() - - assertEquals("It's an IllegalArgumentException", pm.catchBlocksPatternMatching(iae)) - assertEquals("It's a RuntimeException", pm.catchBlocksPatternMatching(re)) - assertEquals("It's an unknown kind of exception", pm.catchBlocksPatternMatching(fnfe)) - } -} - - diff --git a/core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala deleted file mode 100644 index e4995201d8..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/UtilsUnitTest.scala +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.scala - -import com.baeldung.scala.Utils.{average, fibonacci, power, randomLessThan} -import org.junit.Assert.{assertEquals, assertTrue} -import org.junit.Test - -class UtilsUnitTest { - - @Test - def whenAverageCalled_thenCorrectValueReturned(): Unit = { - assertEquals(15.0, average(10, 20), 1e-5) - } - - @Test - def whenRandomLessThanInvokedWithANumber_thenARandomLessThanItReturned: Unit = { - val d = 0.1 - assertTrue(randomLessThan(d) < d) - } - - @Test - def whenPowerInvokedWith2And3_then8Returned: Unit = { - assertEquals(8, power(2, 3)) - } - - @Test - def whenFibonacciCalled_thenCorrectValueReturned: Unit = { - assertEquals(1, fibonacci(0)) - assertEquals(1, fibonacci(1)) - assertEquals(fibonacci(6), - fibonacci(4) + fibonacci(5)) - } -} \ No newline at end of file diff --git a/core-scala/src/test/scala/com/baeldung/scala/regex/RegexUnitTest.scala b/core-scala/src/test/scala/com/baeldung/scala/regex/RegexUnitTest.scala deleted file mode 100644 index 27ed9e1172..0000000000 --- a/core-scala/src/test/scala/com/baeldung/scala/regex/RegexUnitTest.scala +++ /dev/null @@ -1,73 +0,0 @@ -package com.baeldung.scala.regex - -import org.junit.Test -import org.junit.Assert.assertEquals - -class RegexUnitTest { - private val polishPostalCode = "([0-9]{2})\\-([0-9]{3})".r - private val timestamp = "([0-9]{2}):([0-9]{2}):([0-9]{2}).([0-9]{3})".r - private val timestampUnanchored = timestamp.unanchored - - @Test - def givenRegularExpression_whenCallingFindFirstIn_thenShouldFindCorrectMatches(): Unit = { - val postCode = polishPostalCode.findFirstIn("Warsaw 01-011, Jerusalem Avenue") - assertEquals(Some("01-011"), postCode) - } - - @Test - def givenRegularExpression_whenCallingFindFirstMatchIn_thenShouldFindCorrectMatches(): Unit = { - val postCodes = polishPostalCode.findFirstMatchIn("Warsaw 01-011, Jerusalem Avenue") - assertEquals(Some("011"), for (m <- postCodes) yield m.group(2)) - } - - @Test - def givenRegularExpression_whenCallingFindAllIn_thenShouldFindCorrectMatches(): Unit = { - val postCodes = polishPostalCode.findAllIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue") - .toList - assertEquals(List("01-011", "30-059"), postCodes) - - polishPostalCode.findAllIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue") - } - - @Test - def givenRegularExpression_whenCallingFindAlMatchlIn_thenShouldFindCorrectMatches(): Unit = { - val postCodes = polishPostalCode.findAllMatchIn("Warsaw 01-011, Jerusalem Avenue, Cracow 30-059, Mickiewicza Avenue") - .toList - val postalDistricts = for (m <- postCodes) yield m.group(1) - assertEquals(List("01", "30"), postalDistricts) - } - - @Test - def givenRegularExpression_whenExtractingValues_thenShouldExtractCorrectValues(): Unit = { - val description = "11:34:01.411" match { - case timestamp(hour, minutes, _, _) => s"It's $minutes minutes after $hour" - } - - assertEquals("It's 34 minutes after 11", description) - } - - @Test - def givenUnanchoredRegularExpression_whenExtractingValues_thenShouldExtractCorrectValues(): Unit = { - val description = "Timestamp: 11:34:01.411 error appeared" match { - case timestampUnanchored(hour, minutes, _, _) => s"It's $minutes minutes after $hour" - } - - assertEquals("It's 34 minutes after 11", description) - } - - @Test - def givenRegularExpression_whenCallingReplaceAllIn_thenShouldReplaceText(): Unit = { - val minutes = timestamp.replaceAllIn("11:34:01.311", m => m.group(2)) - - assertEquals("34", minutes) - } - - @Test - def givenRegularExpression_whenCallingReplaceAllInWithMatcher_thenShouldReplaceText(): Unit = { - val secondsThatDayInTotal = timestamp.replaceAllIn("11:34:01.311", _ match { - case timestamp(hours, minutes, seconds, _) => s"$hours-$minutes" - }) - - assertEquals("11-34", secondsThatDayInTotal) - } -} diff --git a/pom.xml b/pom.xml index 6a78faca23..84b1d31c61 100644 --- a/pom.xml +++ b/pom.xml @@ -394,7 +394,6 @@ core-java-modules core-kotlin-modules - core-scala couchbase custom-pmd @@ -907,7 +906,6 @@ core-java-modules core-kotlin-modules - core-scala couchbase custom-pmd From e2b7e620a607241bf3d89f8e85b5b0ff8bc2c6d2 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Sat, 14 Mar 2020 18:58:02 -0400 Subject: [PATCH 043/278] BAEL-3806 fixed integration test --- .../consumer/ConsumerFooServiceIntegrationTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java b/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java index b7ed031ec7..9d04541f8d 100644 --- a/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java +++ b/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceIntegrationTest.java @@ -52,14 +52,13 @@ public class ConsumerFooServiceIntegrationTest { .map(Arrays::stream) .orElse(Stream.empty()); }) - .map(IThrowableProxy::getMessage) + .map(IThrowableProxy::getClassName) .collect(Collectors.toList()); assertThat(allLoggedEntries).anyMatch(entry -> entry.contains("The following error happened on processFoo method!")) .anyMatch(entry -> entry.contains("| onSubscribe")) .anyMatch(entry -> entry.contains("| cancel()")); - assertThat(allSuppressedEntries).anyMatch(entry -> entry.contains("Assembly trace from producer")) - .anyMatch(entry -> entry.contains("Error has been observed by the following operator(s)")); + assertThat(allSuppressedEntries) + .anyMatch(entry -> entry.contains("reactor.core.publisher.FluxOnAssembly$OnAssemblyException")); } - } From d2d2a890fac064b3fcb48ffcb09fd1ceb0a13b2d Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:37:57 +0530 Subject: [PATCH 044/278] JAVA-4: renamed to hibernate-annotations, moved couple of articles --- .../hibernate5-annotations/README.md | 8 +- .../config/HibernateAnnotationUtil.java | 34 +++++ .../main/HibernateManyisOwningSide.java | 71 +++++++++++ .../HibernateOneToManyAnnotationMain.java | 60 +++++++++ .../main/HibernateOneisOwningSide.java | 67 ++++++++++ .../hibernate/oneToMany/model/Cart.java | 43 +++++++ .../hibernate/oneToMany/model/CartOIO.java | 42 +++++++ .../hibernate/oneToMany/model/Items.java | 50 ++++++++ .../hibernate/oneToMany/model/ItemsOIO.java | 47 +++++++ .../hibernate/wherejointable/Group.java | 56 +++++++++ .../hibernate/wherejointable/User.java | 74 +++++++++++ .../wherejointable/UserGroupRelation.java | 31 +++++ .../wherejointable/UserGroupRole.java | 7 ++ ...neToManyAnnotationMainIntegrationTest.java | 95 ++++++++++++++ ...ibernateWhereJoinTableIntegrationTest.java | 118 ++++++++++++++++++ 15 files changed, 799 insertions(+), 4 deletions(-) create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java create mode 100644 persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java create mode 100644 persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java create mode 100644 persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java diff --git a/persistence-modules/hibernate5-annotations/README.md b/persistence-modules/hibernate5-annotations/README.md index da3c5ad1fd..2813dbdda3 100644 --- a/persistence-modules/hibernate5-annotations/README.md +++ b/persistence-modules/hibernate5-annotations/README.md @@ -1,10 +1,10 @@ -## Hibernate 5 +## Hibernate Annotations -This module contains articles about Hibernate 5. +This module contains articles about Hibernate Annotations. ### Relevant Articles: - [Custom Types in Hibernate and the @Type Annotation](https://www.baeldung.com/hibernate-custom-types) -- [@Immutable in Hibernate](http://www.baeldung.com/hibernate-immutable) - [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column) - [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby) - +- [Hibernate One to Many Annotation Tutorial](http://www.baeldung.com/hibernate-one-to-many) +- [Hibernate @WhereJoinTable Annotation](https://www.baeldung.com/hibernate-wherejointable) diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java new file mode 100644 index 0000000000..46e6824f42 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java @@ -0,0 +1,34 @@ +package com.baeldung.hibernate.oneToMany.config; + +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; + +public class HibernateAnnotationUtil { + + private static SessionFactory sessionFactory; + + private static SessionFactory buildSessionFactory() { + try { + // Create the SessionFactory from hibernate-annotation.cfg.xml + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure("hibernate-annotation.cfg.xml").build(); + Metadata metadata = new MetadataSources(serviceRegistry).getMetadataBuilder().build(); + SessionFactory sessionFactory = metadata.getSessionFactoryBuilder().build(); + + return sessionFactory; + + } catch (Throwable ex) { + System.err.println("Initial SessionFactory creation failed." + ex); + ex.printStackTrace(); + throw new ExceptionInInitializerError(ex); + } + } + + public static SessionFactory getSessionFactory() { + if (sessionFactory == null) + sessionFactory = buildSessionFactory(); + return sessionFactory; + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java new file mode 100644 index 0000000000..372fb2fc07 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java @@ -0,0 +1,71 @@ +package com.baeldung.hibernate.oneToMany.main; + +import java.util.HashSet; +import java.util.Set; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + +import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil; +import com.baeldung.hibernate.oneToMany.model.Cart; +import com.baeldung.hibernate.oneToMany.model.Items; +import com.baeldung.hibernate.oneToMany.model.ItemsOIO; + +public class HibernateManyisOwningSide { + public static void main(String[] args) { + + Cart cart = new Cart(); + Cart cart2 = new Cart(); + + Items item1 = new Items(cart); + Items item2 = new Items(cart2); + Set itemsSet = new HashSet(); + itemsSet.add(item1); + itemsSet.add(item2); + + cart.setItems(itemsSet); + + + + SessionFactory sessionFactory = null; + Session session = null; + Transaction tx = null; + try { + // Get Session + sessionFactory = HibernateAnnotationUtil.getSessionFactory(); + session = sessionFactory.getCurrentSession(); + System.out.println("Session created"); + // start transaction + tx = session.beginTransaction(); + // Save the Model object + session.save(cart); + session.save(cart2); + session.save(item1); + session.save(item2); + // Commit transaction + tx.commit(); + session = sessionFactory.getCurrentSession(); + tx = session.beginTransaction(); + + item1 = (Items) session.get(Items.class, new Long(1)); + item2 = (Items) session.get(Items.class, new Long(2)); + tx.commit(); + + + System.out.println("item1 ID=" + item1.getId() + ", Foreign Key CartOIO ID=" + item1.getCart() + .getId()); + System.out.println("item2 ID=" + item2.getId() + ", Foreign Key CartOIO ID=" + item2.getCart() + .getId()); + + } catch (Exception e) { + System.out.println("Exception occured. " + e.getMessage()); + e.printStackTrace(); + } finally { + if (!sessionFactory.isClosed()) { + System.out.println("Closing SessionFactory"); + sessionFactory.close(); + } + } + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java new file mode 100644 index 0000000000..2bc5e514f7 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java @@ -0,0 +1,60 @@ +package com.baeldung.hibernate.oneToMany.main; + +import java.util.HashSet; +import java.util.Set; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + +import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil; +import com.baeldung.hibernate.oneToMany.model.Cart; +import com.baeldung.hibernate.oneToMany.model.Items; + +public class HibernateOneToManyAnnotationMain { + + public static void main(String[] args) { + + Cart cart = new Cart(); + + Items item1 = new Items(cart); + Items item2 = new Items(cart); + Set itemsSet = new HashSet(); + itemsSet.add(item1); + itemsSet.add(item2); + + cart.setItems(itemsSet); + + + SessionFactory sessionFactory = null; + Session session = null; + Transaction tx = null; + try { + // Get Session + sessionFactory = HibernateAnnotationUtil.getSessionFactory(); + session = sessionFactory.getCurrentSession(); + System.out.println("Session created"); + // start transaction + tx = session.beginTransaction(); + // Save the Model object + session.save(cart); + session.save(item1); + session.save(item2); + // Commit transaction + tx.commit(); + System.out.println("Cart ID=" + cart.getId()); + System.out.println("item1 ID=" + item1.getId() + ", Foreign Key Cart ID=" + item1.getCart().getId()); + System.out.println("item2 ID=" + item2.getId() + ", Foreign Key Cart ID=" + item1.getCart().getId()); + + } catch (Exception e) { + System.out.println("Exception occured. " + e.getMessage()); + e.printStackTrace(); + } finally { + if (!sessionFactory.isClosed()) { + System.out.println("Closing SessionFactory"); + sessionFactory.close(); + } + } + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java new file mode 100644 index 0000000000..0777664dd0 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java @@ -0,0 +1,67 @@ +package com.baeldung.hibernate.oneToMany.main; + +import java.util.HashSet; +import java.util.Set; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.Transaction; + +import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil; +import com.baeldung.hibernate.oneToMany.model.CartOIO; +import com.baeldung.hibernate.oneToMany.model.ItemsOIO; + +public class HibernateOneisOwningSide { + public static void main(String[] args) { + + CartOIO cart = new CartOIO(); + CartOIO cart2 = new CartOIO(); + + ItemsOIO item1 = new ItemsOIO(cart); + ItemsOIO item2 = new ItemsOIO(cart2); + Set itemsSet = new HashSet(); + itemsSet.add(item1); + itemsSet.add(item2); + + cart.setItems(itemsSet); + + SessionFactory sessionFactory = null; + Session session = null; + Transaction tx = null; + try { + // Get Session + sessionFactory = HibernateAnnotationUtil.getSessionFactory(); + session = sessionFactory.getCurrentSession(); + System.out.println("Session created"); + // start transaction + tx = session.beginTransaction(); + // Save the Model object + session.save(cart); + session.save(cart2); + session.save(item1); + session.save(item2); + // Commit transaction + tx.commit(); + + session = sessionFactory.getCurrentSession(); + tx = session.beginTransaction(); + item1 = (ItemsOIO) session.get(ItemsOIO.class, new Long(1)); + item2 = (ItemsOIO) session.get(ItemsOIO.class, new Long(2)); + tx.commit(); + + System.out.println("item1 ID=" + item1.getId() + ", Foreign Key CartOIO ID=" + item1.getCartOIO() + .getId()); + System.out.println("item2 ID=" + item2.getId() + ", Foreign Key CartOIO ID=" + item2.getCartOIO() + .getId()); + + } catch (Exception e) { + System.out.println("Exception occured. " + e.getMessage()); + e.printStackTrace(); + } finally { + if (!sessionFactory.isClosed()) { + System.out.println("Closing SessionFactory"); + sessionFactory.close(); + } + } + } +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java new file mode 100644 index 0000000000..b8b991831e --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java @@ -0,0 +1,43 @@ +package com.baeldung.hibernate.oneToMany.model; + +import java.util.Set; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import javax.persistence.Table; + +@Entity +@Table(name = "CART") +public class Cart { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "cart_id") + private long id; + + + @OneToMany(mappedBy = "cart") + private Set items; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + + public Set getItems() { + return items; + } + + public void setItems(Set items) { + this.items = items; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java new file mode 100644 index 0000000000..8a5ed5e7a4 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java @@ -0,0 +1,42 @@ +package com.baeldung.hibernate.oneToMany.model; + +import java.util.Set; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.OneToMany; +import javax.persistence.Table; + + + +@Entity +@Table(name = "CARTOIO") +public class CartOIO { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @OneToMany + @JoinColumn(name = "cart_id") // we need to duplicate the physical information + private Set items; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public Set getItems() { + return items; + } + + public void setItems(Set items) { + this.items = items; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java new file mode 100644 index 0000000000..f63a4855b5 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java @@ -0,0 +1,50 @@ +package com.baeldung.hibernate.oneToMany.model; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "ITEMS") +public class Items { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "id") + private long id; + + + @ManyToOne + @JoinColumn(name = "cart_id", nullable = false) + private Cart cart; + + // Hibernate requires no-args constructor + public Items() { + } + + public Items(Cart c) { + this.cart = c; + } + + public Cart getCart() { + return cart; + } + + public void setCart(Cart cart) { + this.cart = cart; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java new file mode 100644 index 0000000000..a3d6a796c5 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java @@ -0,0 +1,47 @@ +package com.baeldung.hibernate.oneToMany.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "ITEMSOIO") +public class ItemsOIO { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @ManyToOne + @JoinColumn(name = "cart_id", insertable = false, updatable = false) + private CartOIO cart; + + // Hibernate requires no-args constructor + public ItemsOIO() { + } + + public ItemsOIO(CartOIO c) { + this.cart = c; + } + + public CartOIO getCartOIO() { + return cart; + } + + public void setCartOIO(CartOIO cart) { + this.cart = cart; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java new file mode 100644 index 0000000000..04684eceac --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java @@ -0,0 +1,56 @@ +package com.baeldung.hibernate.wherejointable; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.ManyToMany; + +@Entity(name = "e_group") +public class Group { + + @Id + @GeneratedValue + private Long id; + + private String name; + + @ManyToMany(mappedBy = "groups") + private List users = new ArrayList<>(); + + public Group(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getUsers() { + return users; + } + + public void setUsers(List users) { + this.users = users; + } + + @Override + public String toString() { + return "Group [name=" + name + "]"; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java new file mode 100644 index 0000000000..7fc077eeb2 --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java @@ -0,0 +1,74 @@ +package com.baeldung.hibernate.wherejointable; + +import java.util.ArrayList; +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; + +import org.hibernate.annotations.WhereJoinTable; + +@Entity +public class User { + + @Id + @GeneratedValue + private Long id; + + private String name; + + @ManyToMany + @JoinTable(name = "r_user_group", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "group_id")) + private List groups = new ArrayList<>(); + + @WhereJoinTable(clause = "role='MODERATOR'") + @ManyToMany + @JoinTable(name = "r_user_group", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "group_id")) + private List moderatorGroups = new ArrayList<>(); + + public User(String name) { + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getGroups() { + return groups; + } + + public void setGroups(List groups) { + this.groups = groups; + } + + public void setModeratorGroups(List moderatorGroups) { + this.moderatorGroups = moderatorGroups; + } + + public List getModeratorGroups() { + return moderatorGroups; + } + + @Override + public String toString() { + return "User [name=" + name + "]"; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java new file mode 100644 index 0000000000..00dd19699c --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java @@ -0,0 +1,31 @@ +package com.baeldung.hibernate.wherejointable; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.EnumType; +import javax.persistence.Enumerated; +import javax.persistence.Id; + +@Entity(name = "r_user_group") +public class UserGroupRelation implements Serializable { + + @Id + @Column(name = "user_id", insertable = false, updatable = false) + private final Long userId; + + @Id + @Column(name = "group_id", insertable = false, updatable = false) + private final Long groupId; + + @Enumerated(EnumType.STRING) + private final UserGroupRole role; + + public UserGroupRelation(Long userId, Long groupId, UserGroupRole role) { + this.userId = userId; + this.groupId = groupId; + this.role = role; + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java new file mode 100644 index 0000000000..62d9cb28ea --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java @@ -0,0 +1,7 @@ +package com.baeldung.hibernate.wherejointable; + +public enum UserGroupRole { + + MEMBER, MODERATOR + +} diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java new file mode 100644 index 0000000000..3bc5a6e12a --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java @@ -0,0 +1,95 @@ +package com.baeldung.hibernate.oneToMany.main; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.HashSet; +import java.util.Set; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.service.ServiceRegistry; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +import com.baeldung.hibernate.oneToMany.model.Cart; +import com.baeldung.hibernate.oneToMany.model.Items; + +public class HibernateOneToManyAnnotationMainIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + public HibernateOneToManyAnnotationMainIntegrationTest() { + } + + @BeforeClass + public static void beforeTests() { + Configuration configuration = new Configuration().addAnnotatedClass(Cart.class).addAnnotatedClass(Items.class) + .setProperty("hibernate.dialect", H2Dialect.class.getName()) + .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) + .setProperty("hibernate.connection.url", "jdbc:h2:mem:test") + .setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "") + .setProperty("hibernate.hbm2ddl.auto", "update"); + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .applySettings(configuration.getProperties()).build(); + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + } + + @Test + public void givenSession_checkIfDatabaseIsEmpty() { + Cart cart = (Cart) session.get(Cart.class, new Long(1)); + assertNull(cart); + + } + + @Test + public void givenSession_checkIfDatabaseIsPopulated_afterCommit() { + Cart cart = new Cart(); + Set cartItems = new HashSet<>(); + cartItems = cart.getItems(); + Assert.assertNull(cartItems); + Items item1 = new Items(); + item1.setCart(cart); + assertNotNull(item1); + Set itemsSet = new HashSet(); + itemsSet.add(item1); + assertNotNull(itemsSet); + cart.setItems(itemsSet); + assertNotNull(cart); + session.persist(cart); + session.getTransaction().commit(); + session.close(); + + session = sessionFactory.openSession(); + session.beginTransaction(); + cart = (Cart) session.get(Cart.class, new Long(1)); + assertNotNull(cart); + } + + @After + public void tearDown() { + session.getTransaction().commit(); + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } + +} diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java new file mode 100644 index 0000000000..93783216ce --- /dev/null +++ b/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java @@ -0,0 +1,118 @@ +package com.baeldung.hibernate.wherejointable; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.cfg.Configuration; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.service.ServiceRegistry; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +public class HibernateWhereJoinTableIntegrationTest { + + private static SessionFactory sessionFactory; + + private Session session; + + /** + * Test data + */ + private User user1; + private User user2; + private User user3; + private Group group1; + private Group group2; + + @BeforeClass + public static void beforeTests() { + Configuration configuration = new Configuration().addAnnotatedClass(User.class) + .addAnnotatedClass(Group.class) + .addAnnotatedClass(UserGroupRelation.class) + .setProperty("hibernate.dialect", H2Dialect.class.getName()) + .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) + .setProperty("hibernate.connection.url", "jdbc:h2:mem:test") + .setProperty("hibernate.connection.username", "sa") + .setProperty("hibernate.connection.password", "") + .setProperty("hibernate.hbm2ddl.auto", "update"); + + ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() + .applySettings(configuration.getProperties()) + .build(); + + sessionFactory = configuration.buildSessionFactory(serviceRegistry); + } + + @Before + public void setUp() { + session = sessionFactory.openSession(); + session.beginTransaction(); + + user1 = new User("user1"); + user2 = new User("user2"); + user3 = new User("user3"); + + group1 = new Group("group1"); + group2 = new Group("group2"); + + session.save(group1); + session.save(group2); + + session.save(user1); + session.save(user2); + session.save(user3); + + saveRelation(user1, group1, UserGroupRole.MODERATOR); + saveRelation(user2, group1, UserGroupRole.MODERATOR); + saveRelation(user3, group1, UserGroupRole.MEMBER); + + saveRelation(user1, group2, UserGroupRole.MEMBER); + saveRelation(user2, group2, UserGroupRole.MODERATOR); + } + + @After + public void tearDown() { + session.getTransaction().commit(); + session.close(); + } + + @AfterClass + public static void afterTests() { + sessionFactory.close(); + } + + @Test + public void givenUser1_getGroups_returnsAllGroups() { + List groups = user1.getGroups(); + assertEquals(2, groups.size()); + + assertTrue(groups.contains(group1)); + assertTrue(groups.contains(group2)); + } + + @Test + public void givenUser1_getModeratorGroups_returnsOnlyModeratorGroups() { + List groups = user1.getModeratorGroups(); + assertEquals(1, groups.size()); + + assertTrue(groups.contains(group1)); + } + + private void saveRelation(User user, Group group, UserGroupRole role) { + UserGroupRelation relation = new UserGroupRelation(user.getId(), group.getId(), role); + + session.save(relation); + session.flush(); + session.refresh(user); + session.refresh(group); + } + +} From 12a7e6fdf92f47a451fe64a66fc5bd22176fdae6 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:48:26 +0530 Subject: [PATCH 045/278] JAVA-4: Renamed hibernate5-annotations to hibernate-annotations --- .../README.md | 0 .../pom.xml | 4 ++-- .../java/com/baeldung/hibernate/HibernateUtil.java | 0 .../hibernate/UnsupportedTenancyException.java | 0 .../com/baeldung/hibernate/customtypes/Address.java | 0 .../baeldung/hibernate/customtypes/AddressType.java | 0 .../customtypes/LocalDateStringJavaDescriptor.java | 0 .../hibernate/customtypes/LocalDateStringType.java | 0 .../hibernate/customtypes/OfficeEmployee.java | 0 .../baeldung/hibernate/customtypes/PhoneNumber.java | 0 .../hibernate/customtypes/PhoneNumberType.java | 0 .../com/baeldung/hibernate/customtypes/Salary.java | 0 .../customtypes/SalaryCurrencyConvertor.java | 0 .../baeldung/hibernate/customtypes/SalaryType.java | 0 .../com/baeldung/hibernate/joincolumn/Email.java | 0 .../com/baeldung/hibernate/joincolumn/Office.java | 0 .../hibernate/joincolumn/OfficeAddress.java | 0 .../hibernate/joincolumn/OfficialEmployee.java | 0 .../oneToMany/config/HibernateAnnotationUtil.java | 0 .../oneToMany/main/HibernateManyisOwningSide.java | 0 .../main/HibernateOneToManyAnnotationMain.java | 0 .../oneToMany/main/HibernateOneisOwningSide.java | 0 .../baeldung/hibernate/oneToMany/model/Cart.java | 0 .../baeldung/hibernate/oneToMany/model/CartOIO.java | 0 .../baeldung/hibernate/oneToMany/model/Items.java | 0 .../hibernate/oneToMany/model/ItemsOIO.java | 0 .../java/com/baeldung/hibernate/pojo/Phone.java | 0 .../baeldung/hibernate/wherejointable/Group.java | 0 .../com/baeldung/hibernate/wherejointable/User.java | 0 .../hibernate/wherejointable/UserGroupRelation.java | 0 .../hibernate/wherejointable/UserGroupRole.java | 0 .../src/main/resources/META-INF/persistence.xml | 0 .../src/main/resources/logback.xml | 0 .../customtypes/HibernateCustomTypesManualTest.java | 0 .../joincolumn/JoinColumnIntegrationTest.java | 0 ...rnateOneToManyAnnotationMainIntegrationTest.java | 0 .../HibernateWhereJoinTableIntegrationTest.java | 0 .../src/test/resources/hibernate-spatial.properties | 0 .../src/test/resources/log4j.xml | 0 .../src/test/resources/log4j2.xml | 0 .../src/test/resources/logback.xml | 0 .../src/test/resources/profile.png | Bin 42 files changed, 2 insertions(+), 2 deletions(-) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/README.md (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/pom.xml (96%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/HibernateUtil.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/Address.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/Salary.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/joincolumn/Email.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/joincolumn/Office.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/pojo/Phone.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/wherejointable/Group.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/wherejointable/User.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/resources/META-INF/persistence.xml (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/main/resources/logback.xml (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/resources/hibernate-spatial.properties (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/resources/log4j.xml (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/resources/log4j2.xml (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/resources/logback.xml (100%) rename persistence-modules/{hibernate5-annotations => hibernate-annotations}/src/test/resources/profile.png (100%) diff --git a/persistence-modules/hibernate5-annotations/README.md b/persistence-modules/hibernate-annotations/README.md similarity index 100% rename from persistence-modules/hibernate5-annotations/README.md rename to persistence-modules/hibernate-annotations/README.md diff --git a/persistence-modules/hibernate5-annotations/pom.xml b/persistence-modules/hibernate-annotations/pom.xml similarity index 96% rename from persistence-modules/hibernate5-annotations/pom.xml rename to persistence-modules/hibernate-annotations/pom.xml index ab242333fe..5367921f31 100644 --- a/persistence-modules/hibernate5-annotations/pom.xml +++ b/persistence-modules/hibernate-annotations/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - hibernate5-annotations + hibernate-annotations 0.1-SNAPSHOT - hibernate5-annotations + hibernate-annotations jar Hibernate tutorial illustrating the use of named parameters diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/HibernateUtil.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/Address.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/AddressType.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/OfficeEmployee.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumber.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/PhoneNumberType.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/Salary.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryCurrencyConvertor.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/customtypes/SalaryType.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Email.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/Office.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficeAddress.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/joincolumn/OfficialEmployee.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/pojo/Phone.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/Group.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/User.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java diff --git a/persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java b/persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java rename to persistence-modules/hibernate-annotations/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java diff --git a/persistence-modules/hibernate5-annotations/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate-annotations/src/main/resources/META-INF/persistence.xml similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/resources/META-INF/persistence.xml rename to persistence-modules/hibernate-annotations/src/main/resources/META-INF/persistence.xml diff --git a/persistence-modules/hibernate5-annotations/src/main/resources/logback.xml b/persistence-modules/hibernate-annotations/src/main/resources/logback.xml similarity index 100% rename from persistence-modules/hibernate5-annotations/src/main/resources/logback.xml rename to persistence-modules/hibernate-annotations/src/main/resources/logback.xml diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java rename to persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/customtypes/HibernateCustomTypesManualTest.java diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java rename to persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/joincolumn/JoinColumnIntegrationTest.java diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java rename to persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java diff --git a/persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java b/persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java rename to persistence-modules/hibernate-annotations/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/hibernate-spatial.properties b/persistence-modules/hibernate-annotations/src/test/resources/hibernate-spatial.properties similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/resources/hibernate-spatial.properties rename to persistence-modules/hibernate-annotations/src/test/resources/hibernate-spatial.properties diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/log4j.xml b/persistence-modules/hibernate-annotations/src/test/resources/log4j.xml similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/resources/log4j.xml rename to persistence-modules/hibernate-annotations/src/test/resources/log4j.xml diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/log4j2.xml b/persistence-modules/hibernate-annotations/src/test/resources/log4j2.xml similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/resources/log4j2.xml rename to persistence-modules/hibernate-annotations/src/test/resources/log4j2.xml diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/logback.xml b/persistence-modules/hibernate-annotations/src/test/resources/logback.xml similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/resources/logback.xml rename to persistence-modules/hibernate-annotations/src/test/resources/logback.xml diff --git a/persistence-modules/hibernate5-annotations/src/test/resources/profile.png b/persistence-modules/hibernate-annotations/src/test/resources/profile.png similarity index 100% rename from persistence-modules/hibernate5-annotations/src/test/resources/profile.png rename to persistence-modules/hibernate-annotations/src/test/resources/profile.png From 5f8123f80493e8c85a09db24075146bd6c8f1715 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:50:17 +0530 Subject: [PATCH 046/278] JAVA-4: Renamed hibernate5-enterprise to hibernate-enterprise --- .../README.md | 5 ++--- .../pom.xml | 4 ++-- .../java/com/baeldung/hibernate/HibernateUtil.java | 0 .../hibernate/UnsupportedTenancyException.java | 0 .../hibernate/exception/EntityWithNoId.java | 0 .../baeldung/hibernate/exception/HibernateUtil.java | 0 .../com/baeldung/hibernate/exception/Product.java | 0 .../com/baeldung/hibernate/logging/Employee.java | 0 .../com/baeldung/hibernate/pojo/PointEntity.java | 0 .../com/baeldung/hibernate/pojo/PolygonEntity.java | 0 .../java/com/baeldung/hibernate/pojo/Student.java | 0 .../com/baeldung/hibernateparameters/Event.java | 0 .../src/main/resources/META-INF/persistence.xml | 0 .../com/baeldung/hibernateparameters/Event.hbm.xml | 0 .../src/main/resources/hibernate-logging.cfg.xml | 0 .../src/main/resources/hibernate.cfg.xml | 0 .../src/main/resources/init_database.sql | 0 .../src/main/resources/logback.xml | 0 .../hibernate/HibernateSpatialIntegrationTest.java | 0 .../AggregateFunctionsIntegrationTest.java | 0 .../exception/HibernateExceptionUnitTest.java | 0 .../logging/HibernateLoggingIntegrationTest.java | 0 .../com/baeldung/hibernate/multitenancy/Car.java | 0 .../multitenancy/MultitenancyIntegrationTest.java | 0 ...DatabaseApproachMultitenancyIntegrationTest.java | 0 .../database/MapMultiTenantConnectionProvider.java | 0 .../multitenancy/database/TenantIdNames.java | 0 .../SchemaApproachMultitenancyIntegrationTest.java | 0 .../schema/SchemaMultiTenantConnectionProvider.java | 0 .../multitenancy/schema/TenantIdNames.java | 0 .../hibernateparameters/NamedParameterUnitTest.java | 0 .../hibernate-database-multitenancy.properties | 0 .../resources/hibernate-database-mydb1.properties | 0 .../resources/hibernate-database-mydb2.properties | 0 .../test/resources/hibernate-exception.properties | 0 .../hibernate-schema-multitenancy.properties | 0 .../src/test/resources/hibernate-spatial.properties | 0 .../src/test/resources/hibernate.properties | 0 .../src/test/resources/lifecycle-init.sql | 0 .../src/test/resources/profile.png | Bin 40 files changed, 4 insertions(+), 5 deletions(-) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/README.md (81%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/pom.xml (96%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/HibernateUtil.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/exception/Product.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/logging/Employee.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernate/pojo/Student.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/java/com/baeldung/hibernateparameters/Event.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/resources/META-INF/persistence.xml (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/resources/hibernate-logging.cfg.xml (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/resources/hibernate.cfg.xml (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/resources/init_database.sql (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/main/resources/logback.xml (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/Car.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/hibernate-database-multitenancy.properties (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/hibernate-database-mydb1.properties (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/hibernate-database-mydb2.properties (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/hibernate-exception.properties (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/hibernate-schema-multitenancy.properties (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/hibernate-spatial.properties (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/hibernate.properties (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/lifecycle-init.sql (100%) rename persistence-modules/{hibernate5-enterprise => hibernate-enterprise}/src/test/resources/profile.png (100%) diff --git a/persistence-modules/hibernate5-enterprise/README.md b/persistence-modules/hibernate-enterprise/README.md similarity index 81% rename from persistence-modules/hibernate5-enterprise/README.md rename to persistence-modules/hibernate-enterprise/README.md index 994d8f062a..c48092e6a2 100644 --- a/persistence-modules/hibernate5-enterprise/README.md +++ b/persistence-modules/hibernate-enterprise/README.md @@ -1,6 +1,6 @@ -## Hibernate 5 +## Hibernate Enterprise -This module contains articles about Hibernate 5. +This module contains articles about Hibernate. ### Relevant articles: @@ -9,5 +9,4 @@ This module contains articles about Hibernate 5. - [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions) - [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions) - [Hibernate Error “Not all named parameters have been set”](https://www.baeldung.com/hibernate-error-named-parameters-not-set) -- [FetchMode in Hibernate](https://www.baeldung.com/hibernate-fetchmode) - [Various Logging Levels in Hibernate](https://www.baeldung.com/hibernate-logging-levels) \ No newline at end of file diff --git a/persistence-modules/hibernate5-enterprise/pom.xml b/persistence-modules/hibernate-enterprise/pom.xml similarity index 96% rename from persistence-modules/hibernate5-enterprise/pom.xml rename to persistence-modules/hibernate-enterprise/pom.xml index f12bb7e081..060cb4c904 100644 --- a/persistence-modules/hibernate5-enterprise/pom.xml +++ b/persistence-modules/hibernate-enterprise/pom.xml @@ -3,9 +3,9 @@ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 - hibernate5-enterprise + hibernate-enterprise 0.0.1-SNAPSHOT - hibernate5-enterprise + hibernate-enterprise com.baeldung diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/HibernateUtil.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/exception/EntityWithNoId.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/exception/HibernateUtil.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/exception/Product.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/logging/Employee.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernate/pojo/Student.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java b/persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java rename to persistence-modules/hibernate-enterprise/src/main/java/com/baeldung/hibernateparameters/Event.java diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate-enterprise/src/main/resources/META-INF/persistence.xml similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/resources/META-INF/persistence.xml rename to persistence-modules/hibernate-enterprise/src/main/resources/META-INF/persistence.xml diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml b/persistence-modules/hibernate-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml rename to persistence-modules/hibernate-enterprise/src/main/resources/com/baeldung/hibernateparameters/Event.hbm.xml diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate-logging.cfg.xml b/persistence-modules/hibernate-enterprise/src/main/resources/hibernate-logging.cfg.xml similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/resources/hibernate-logging.cfg.xml rename to persistence-modules/hibernate-enterprise/src/main/resources/hibernate-logging.cfg.xml diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/hibernate.cfg.xml b/persistence-modules/hibernate-enterprise/src/main/resources/hibernate.cfg.xml similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/resources/hibernate.cfg.xml rename to persistence-modules/hibernate-enterprise/src/main/resources/hibernate.cfg.xml diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/init_database.sql b/persistence-modules/hibernate-enterprise/src/main/resources/init_database.sql similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/resources/init_database.sql rename to persistence-modules/hibernate-enterprise/src/main/resources/init_database.sql diff --git a/persistence-modules/hibernate5-enterprise/src/main/resources/logback.xml b/persistence-modules/hibernate-enterprise/src/main/resources/logback.xml similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/main/resources/logback.xml rename to persistence-modules/hibernate-enterprise/src/main/resources/logback.xml diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/HibernateSpatialIntegrationTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/aggregatefunctions/AggregateFunctionsIntegrationTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/exception/HibernateExceptionUnitTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/logging/HibernateLoggingIntegrationTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/Car.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/MultitenancyIntegrationTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/DatabaseApproachMultitenancyIntegrationTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/MapMultiTenantConnectionProvider.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/database/TenantIdNames.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaApproachMultitenancyIntegrationTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/SchemaMultiTenantConnectionProvider.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernate/multitenancy/schema/TenantIdNames.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java b/persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java rename to persistence-modules/hibernate-enterprise/src/test/java/com/baeldung/hibernateparameters/NamedParameterUnitTest.java diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-multitenancy.properties b/persistence-modules/hibernate-enterprise/src/test/resources/hibernate-database-multitenancy.properties similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-multitenancy.properties rename to persistence-modules/hibernate-enterprise/src/test/resources/hibernate-database-multitenancy.properties diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb1.properties b/persistence-modules/hibernate-enterprise/src/test/resources/hibernate-database-mydb1.properties similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb1.properties rename to persistence-modules/hibernate-enterprise/src/test/resources/hibernate-database-mydb1.properties diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb2.properties b/persistence-modules/hibernate-enterprise/src/test/resources/hibernate-database-mydb2.properties similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-database-mydb2.properties rename to persistence-modules/hibernate-enterprise/src/test/resources/hibernate-database-mydb2.properties diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-exception.properties b/persistence-modules/hibernate-enterprise/src/test/resources/hibernate-exception.properties similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-exception.properties rename to persistence-modules/hibernate-enterprise/src/test/resources/hibernate-exception.properties diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-schema-multitenancy.properties b/persistence-modules/hibernate-enterprise/src/test/resources/hibernate-schema-multitenancy.properties similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-schema-multitenancy.properties rename to persistence-modules/hibernate-enterprise/src/test/resources/hibernate-schema-multitenancy.properties diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-spatial.properties b/persistence-modules/hibernate-enterprise/src/test/resources/hibernate-spatial.properties similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/hibernate-spatial.properties rename to persistence-modules/hibernate-enterprise/src/test/resources/hibernate-spatial.properties diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/hibernate.properties b/persistence-modules/hibernate-enterprise/src/test/resources/hibernate.properties similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/hibernate.properties rename to persistence-modules/hibernate-enterprise/src/test/resources/hibernate.properties diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/lifecycle-init.sql b/persistence-modules/hibernate-enterprise/src/test/resources/lifecycle-init.sql similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/lifecycle-init.sql rename to persistence-modules/hibernate-enterprise/src/test/resources/lifecycle-init.sql diff --git a/persistence-modules/hibernate5-enterprise/src/test/resources/profile.png b/persistence-modules/hibernate-enterprise/src/test/resources/profile.png similarity index 100% rename from persistence-modules/hibernate5-enterprise/src/test/resources/profile.png rename to persistence-modules/hibernate-enterprise/src/test/resources/profile.png From 376d0a6ff6389def371ecef2fde4aefc8aa821eb Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:51:47 +0530 Subject: [PATCH 047/278] JAVA-4: Renamed hibernate5-jpa to hibernate-jpa --- .../{hibernate5-jpa => hibernate-jpa}/README.md | 5 ++--- .../{hibernate5-jpa => hibernate-jpa}/pom.xml | 4 ++-- .../java/com/baeldung/hibernate/HibernateUtil.java | 0 .../hibernate/UnsupportedTenancyException.java | 0 .../hibernate/converters/PersonNameConverter.java | 0 .../com/baeldung/hibernate/entities/Department.java | 0 .../baeldung/hibernate/entities/DeptEmployee.java | 0 .../jpabootstrap/application/Application.java | 0 .../config/HibernatePersistenceUnitInfo.java | 0 .../config/JpaEntityManagerFactory.java | 0 .../hibernate/jpabootstrap/entities/User.java | 0 .../service/EmployeeSearchService.java | 0 .../service/EmployeeSearchServiceImpl.java | 0 .../baeldung/hibernate/onetoone/HibernateUtil.java | 0 .../com/baeldung/hibernate/onetoone/Strategy.java | 0 .../hibernate/onetoone/foreignkeybased/Address.java | 0 .../hibernate/onetoone/foreignkeybased/User.java | 0 .../hibernate/onetoone/jointablebased/Employee.java | 0 .../onetoone/jointablebased/WorkStation.java | 0 .../hibernate/onetoone/sharedkeybased/Address.java | 0 .../hibernate/onetoone/sharedkeybased/User.java | 0 .../optimisticlocking/OptimisticLockingCourse.java | 0 .../optimisticlocking/OptimisticLockingStudent.java | 0 .../hibernate/pessimisticlocking/Address.java | 0 .../hibernate/pessimisticlocking/Customer.java | 0 .../hibernate/pessimisticlocking/Individual.java | 0 .../PessimisticLockingCourse.java | 0 .../PessimisticLockingEmployee.java | 0 .../PessimisticLockingStudent.java | 0 .../java/com/baeldung/hibernate/pojo/Movie.java | 0 .../java/com/baeldung/hibernate/pojo/Person.java | 0 .../com/baeldung/hibernate/pojo/PersonName.java | 0 .../main/java/com/baeldung/hibernate/pojo/Post.java | 0 .../java/com/baeldung/hibernate/pojo/Student.java | 0 .../baeldung/hibernate/transaction/PostService.java | 0 .../PersistenceContextDemoApplication.java | 0 .../baeldung/persistencecontext/entity/User.java | 0 .../ExtendedPersistenceContextUserService.java | 0 .../TransctionPersistenceContextUserService.java | 0 .../src/main/resources/META-INF/persistence.xml | 0 .../src/main/resources/init_database.sql | 0 .../src/main/resources/logback.xml | 0 .../converter/PersonNameConverterUnitTest.java | 0 .../EmployeeSearchServiceIntegrationTest.java | 0 ...ateOneToOneAnnotationFKBasedIntegrationTest.java | 0 ...ateOneToOneAnnotationJTBasedIntegrationTest.java | 0 ...teOneToOneAnnotationSPKBasedIntegrationTest.java | 0 .../OptimisticLockingIntegrationTest.java | 0 .../BasicPessimisticLockingIntegrationTest.java | 0 .../PessimisticLockScopesIntegrationTest.java | 0 .../transaction/TransactionIntegrationTest.java | 0 .../PersistenceContextIntegrationTest.java | 0 .../test/resources/hibernate-namedquery.properties | 0 .../hibernate-pessimistic-locking.properties | 0 .../src/test/resources/hibernate.properties | 0 .../src/test/resources/profile.png | Bin 56 files changed, 4 insertions(+), 5 deletions(-) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/README.md (84%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/pom.xml (97%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/HibernateUtil.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/entities/Department.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pojo/Movie.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pojo/Person.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pojo/PersonName.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pojo/Post.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/pojo/Student.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/hibernate/transaction/PostService.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/persistencecontext/entity/User.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/resources/META-INF/persistence.xml (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/resources/init_database.sql (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/main/resources/logback.xml (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/resources/hibernate-namedquery.properties (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/resources/hibernate-pessimistic-locking.properties (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/resources/hibernate.properties (100%) rename persistence-modules/{hibernate5-jpa => hibernate-jpa}/src/test/resources/profile.png (100%) diff --git a/persistence-modules/hibernate5-jpa/README.md b/persistence-modules/hibernate-jpa/README.md similarity index 84% rename from persistence-modules/hibernate5-jpa/README.md rename to persistence-modules/hibernate-jpa/README.md index bffba85d54..fb1d46cf9b 100644 --- a/persistence-modules/hibernate5-jpa/README.md +++ b/persistence-modules/hibernate-jpa/README.md @@ -1,6 +1,6 @@ -## Hibernate 5 +## Hibernate JPA -This module contains articles about Hibernate 5. +This module contains articles about Hibernate JPA. ### Relevant articles: @@ -12,5 +12,4 @@ This module contains articles about Hibernate 5. - [One-to-One Relationship in JPA](https://www.baeldung.com/jpa-one-to-one) - [Enabling Transaction Locks in Spring Data JPA](https://www.baeldung.com/java-jpa-transaction-locks) - [TransactionRequiredException Error](https://www.baeldung.com/jpa-transaction-required-exception) -- [FetchMode in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-fetchmode) - [JPA/Hibernate Persistence Context](https://www.baeldung.com/jpa-hibernate-persistence-context) diff --git a/persistence-modules/hibernate5-jpa/pom.xml b/persistence-modules/hibernate-jpa/pom.xml similarity index 97% rename from persistence-modules/hibernate5-jpa/pom.xml rename to persistence-modules/hibernate-jpa/pom.xml index b181fff36b..67f40d5017 100644 --- a/persistence-modules/hibernate5-jpa/pom.xml +++ b/persistence-modules/hibernate-jpa/pom.xml @@ -3,9 +3,9 @@ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 - hibernate5-jpa + hibernate-jpa 0.0.1-SNAPSHOT - hibernate5-jpa + hibernate-jpa com.baeldung diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/HibernateUtil.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/converters/PersonNameConverter.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entities/Department.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/application/Application.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/HibernatePersistenceUnitInfo.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/config/JpaEntityManagerFactory.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpabootstrap/entities/User.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchService.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/jpacriteriabuilder/service/EmployeeSearchServiceImpl.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/HibernateUtil.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/Strategy.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/Address.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/foreignkeybased/User.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/Employee.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/jointablebased/WorkStation.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/Address.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/onetoone/sharedkeybased/User.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingCourse.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingStudent.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Address.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Customer.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/Individual.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingCourse.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingEmployee.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockingStudent.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Movie.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Person.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/PersonName.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Post.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/pojo/Student.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/transaction/PostService.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/PersistenceContextDemoApplication.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/entity/User.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/service/ExtendedPersistenceContextUserService.java diff --git a/persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java rename to persistence-modules/hibernate-jpa/src/main/java/com/baeldung/persistencecontext/service/TransctionPersistenceContextUserService.java diff --git a/persistence-modules/hibernate5-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/persistence.xml similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/resources/META-INF/persistence.xml rename to persistence-modules/hibernate-jpa/src/main/resources/META-INF/persistence.xml diff --git a/persistence-modules/hibernate5-jpa/src/main/resources/init_database.sql b/persistence-modules/hibernate-jpa/src/main/resources/init_database.sql similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/resources/init_database.sql rename to persistence-modules/hibernate-jpa/src/main/resources/init_database.sql diff --git a/persistence-modules/hibernate5-jpa/src/main/resources/logback.xml b/persistence-modules/hibernate-jpa/src/main/resources/logback.xml similarity index 100% rename from persistence-modules/hibernate5-jpa/src/main/resources/logback.xml rename to persistence-modules/hibernate-jpa/src/main/resources/logback.xml diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/converter/PersonNameConverterUnitTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/jpacriteriabuilder/EmployeeSearchServiceIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationFKBasedIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationJTBasedIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/onetoone/HibernateOneToOneAnnotationSPKBasedIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/optimisticlocking/OptimisticLockingIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/BasicPessimisticLockingIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/pessimisticlocking/PessimisticLockScopesIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/transaction/TransactionIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java rename to persistence-modules/hibernate-jpa/src/test/java/com/baeldung/persistencecontext/PersistenceContextIntegrationTest.java diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-namedquery.properties b/persistence-modules/hibernate-jpa/src/test/resources/hibernate-namedquery.properties similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/resources/hibernate-namedquery.properties rename to persistence-modules/hibernate-jpa/src/test/resources/hibernate-namedquery.properties diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/hibernate-pessimistic-locking.properties b/persistence-modules/hibernate-jpa/src/test/resources/hibernate-pessimistic-locking.properties similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/resources/hibernate-pessimistic-locking.properties rename to persistence-modules/hibernate-jpa/src/test/resources/hibernate-pessimistic-locking.properties diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/hibernate.properties b/persistence-modules/hibernate-jpa/src/test/resources/hibernate.properties similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/resources/hibernate.properties rename to persistence-modules/hibernate-jpa/src/test/resources/hibernate.properties diff --git a/persistence-modules/hibernate5-jpa/src/test/resources/profile.png b/persistence-modules/hibernate-jpa/src/test/resources/profile.png similarity index 100% rename from persistence-modules/hibernate5-jpa/src/test/resources/profile.png rename to persistence-modules/hibernate-jpa/src/test/resources/profile.png From 729d35140e65bcf949bccb4faa37a76c20f8bd89 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:52:48 +0530 Subject: [PATCH 048/278] JAVA-4: Renamed hibernate5-queries to hibernate-queries --- .../README.md | 4 ++-- .../pom.xml | 4 ++-- .../java/com/baeldung/hibernate/HibernateUtil.java | 0 .../hibernate/UnsupportedTenancyException.java | 0 .../hibernate/criteriaquery/HibernateUtil.java | 0 .../baeldung/hibernate/criteriaquery/Student.java | 0 .../customtypes/LocalDateStringJavaDescriptor.java | 0 .../hibernate/customtypes/LocalDateStringType.java | 0 .../com/baeldung/hibernate/entities/Department.java | 0 .../baeldung/hibernate/entities/DeptEmployee.java | 0 .../com/baeldung/hibernate/findall/FindAll.java | 0 .../java/com/baeldung/hibernate/pojo/Student.java | 0 .../src/main/resources/META-INF/persistence.xml | 0 .../src/main/resources/init_database.sql | 0 .../src/main/resources/logback.xml | 0 .../hibernate/NamedQueryIntegrationTest.java | 0 .../TypeSafeCriteriaIntegrationTest.java | 0 .../baeldung/hibernate/findall/FindAllUnitTest.java | 0 .../queryplancache/QueryPlanCacheBenchmark.java | 0 .../test/resources/hibernate-customtypes.properties | 0 .../test/resources/hibernate-namedquery.properties | 0 .../src/test/resources/hibernate.properties | 0 .../src/test/resources/lifecycle-init.sql | 0 .../src/test/resources/profile.png | Bin 24 files changed, 4 insertions(+), 4 deletions(-) rename persistence-modules/{hibernate5-queries => hibernate-queries}/README.md (81%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/pom.xml (97%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/HibernateUtil.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/entities/Department.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/findall/FindAll.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/java/com/baeldung/hibernate/pojo/Student.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/resources/META-INF/persistence.xml (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/resources/init_database.sql (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/main/resources/logback.xml (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/resources/hibernate-customtypes.properties (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/resources/hibernate-namedquery.properties (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/resources/hibernate.properties (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/resources/lifecycle-init.sql (100%) rename persistence-modules/{hibernate5-queries => hibernate-queries}/src/test/resources/profile.png (100%) diff --git a/persistence-modules/hibernate5-queries/README.md b/persistence-modules/hibernate-queries/README.md similarity index 81% rename from persistence-modules/hibernate5-queries/README.md rename to persistence-modules/hibernate-queries/README.md index 1edf4ded1e..61d94e32de 100644 --- a/persistence-modules/hibernate5-queries/README.md +++ b/persistence-modules/hibernate-queries/README.md @@ -1,6 +1,6 @@ -## Hibernate 5 +## Hibernate Queries -This module contains articles about Hibernate 5. +This module contains articles about use of Queries in Hibernate. ### Relevant articles: diff --git a/persistence-modules/hibernate5-queries/pom.xml b/persistence-modules/hibernate-queries/pom.xml similarity index 97% rename from persistence-modules/hibernate5-queries/pom.xml rename to persistence-modules/hibernate-queries/pom.xml index 544d22c0a3..a439ded9df 100644 --- a/persistence-modules/hibernate5-queries/pom.xml +++ b/persistence-modules/hibernate-queries/pom.xml @@ -3,9 +3,9 @@ xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 4.0.0 - hibernate5-queries + hibernate-queries 0.0.1-SNAPSHOT - hibernate5-queries + hibernate-queries com.baeldung diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/HibernateUtil.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/UnsupportedTenancyException.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteriaquery/HibernateUtil.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/criteriaquery/Student.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringJavaDescriptor.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/customtypes/LocalDateStringType.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/Department.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/entities/Department.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/Department.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/entities/Department.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/findall/FindAll.java diff --git a/persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java b/persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java rename to persistence-modules/hibernate-queries/src/main/java/com/baeldung/hibernate/pojo/Student.java diff --git a/persistence-modules/hibernate5-queries/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate-queries/src/main/resources/META-INF/persistence.xml similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/resources/META-INF/persistence.xml rename to persistence-modules/hibernate-queries/src/main/resources/META-INF/persistence.xml diff --git a/persistence-modules/hibernate5-queries/src/main/resources/init_database.sql b/persistence-modules/hibernate-queries/src/main/resources/init_database.sql similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/resources/init_database.sql rename to persistence-modules/hibernate-queries/src/main/resources/init_database.sql diff --git a/persistence-modules/hibernate5-queries/src/main/resources/logback.xml b/persistence-modules/hibernate-queries/src/main/resources/logback.xml similarity index 100% rename from persistence-modules/hibernate5-queries/src/main/resources/logback.xml rename to persistence-modules/hibernate-queries/src/main/resources/logback.xml diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java b/persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java rename to persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/NamedQueryIntegrationTest.java diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java b/persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java rename to persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/criteriaquery/TypeSafeCriteriaIntegrationTest.java diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java b/persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java rename to persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/findall/FindAllUnitTest.java diff --git a/persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java b/persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java rename to persistence-modules/hibernate-queries/src/test/java/com/baeldung/hibernate/queryplancache/QueryPlanCacheBenchmark.java diff --git a/persistence-modules/hibernate5-queries/src/test/resources/hibernate-customtypes.properties b/persistence-modules/hibernate-queries/src/test/resources/hibernate-customtypes.properties similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/resources/hibernate-customtypes.properties rename to persistence-modules/hibernate-queries/src/test/resources/hibernate-customtypes.properties diff --git a/persistence-modules/hibernate5-queries/src/test/resources/hibernate-namedquery.properties b/persistence-modules/hibernate-queries/src/test/resources/hibernate-namedquery.properties similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/resources/hibernate-namedquery.properties rename to persistence-modules/hibernate-queries/src/test/resources/hibernate-namedquery.properties diff --git a/persistence-modules/hibernate5-queries/src/test/resources/hibernate.properties b/persistence-modules/hibernate-queries/src/test/resources/hibernate.properties similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/resources/hibernate.properties rename to persistence-modules/hibernate-queries/src/test/resources/hibernate.properties diff --git a/persistence-modules/hibernate5-queries/src/test/resources/lifecycle-init.sql b/persistence-modules/hibernate-queries/src/test/resources/lifecycle-init.sql similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/resources/lifecycle-init.sql rename to persistence-modules/hibernate-queries/src/test/resources/lifecycle-init.sql diff --git a/persistence-modules/hibernate5-queries/src/test/resources/profile.png b/persistence-modules/hibernate-queries/src/test/resources/profile.png similarity index 100% rename from persistence-modules/hibernate5-queries/src/test/resources/profile.png rename to persistence-modules/hibernate-queries/src/test/resources/profile.png From bf60206022d577f030e939dae58e1aece5b45a8a Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:53:28 +0530 Subject: [PATCH 049/278] JAVA-4: Removed hibernate5-mapping; merged into to hibernate-mapping --- .../hibernate-mapping/README.md | 8 +- persistence-modules/hibernate-mapping/pom.xml | 13 ++ .../com/baeldung/hibernate/HibernateUtil.java | 72 +++++++++-- .../hibernate/entities/Department.java | 0 .../hibernate/entities/DeptEmployee.java | 0 .../hibernate/lob/HibernateSessionUtil.java | 0 .../baeldung/hibernate/lob/model/User.java | 0 .../config/HibernateAnnotationUtil.java | 34 ----- .../main/HibernateManyisOwningSide.java | 71 ----------- .../HibernateOneToManyAnnotationMain.java | 60 --------- .../main/HibernateOneisOwningSide.java | 67 ---------- .../hibernate/oneToMany/model/Cart.java | 43 ------- .../hibernate/oneToMany/model/CartOIO.java | 42 ------- .../hibernate/oneToMany/model/Items.java | 50 -------- .../hibernate/oneToMany/model/ItemsOIO.java | 47 ------- .../com/baeldung/hibernate/pojo/Employee.java | 0 .../hibernate/pojo/EntityDescription.java | 0 .../com/baeldung/hibernate/pojo/Phone.java | 0 .../com/baeldung/hibernate/pojo/Result.java | 0 .../hibernate/pojo/TemporalValues.java | 0 .../hibernate/pojo/generator/MyGenerator.java | 0 .../hibernate/pojo/inheritance/Animal.java | 0 .../hibernate/pojo/inheritance/Bag.java | 0 .../hibernate/pojo/inheritance/Book.java | 0 .../hibernate/pojo/inheritance/Car.java | 0 .../hibernate/pojo/inheritance/Item.java | 0 .../pojo/inheritance/MyEmployee.java | 0 .../hibernate/pojo/inheritance/MyProduct.java | 0 .../hibernate/pojo/inheritance/Pen.java | 0 .../hibernate/pojo/inheritance/Person.java | 0 .../hibernate/pojo/inheritance/Pet.java | 0 .../hibernate/pojo/inheritance/Vehicle.java | 0 .../baeldung/hibernate/pojo/package-info.java | 0 .../hibernate/wherejointable/Group.java | 56 --------- .../hibernate/wherejointable/User.java | 74 ----------- .../wherejointable/UserGroupRelation.java | 31 ----- .../wherejointable/UserGroupRole.java | 7 -- .../hibernate/CustomClassIntegrationTest.java | 0 .../DynamicMappingIntegrationTest.java | 0 .../InheritanceMappingIntegrationTest.java | 0 .../hibernate/TemporalValuesUnitTest.java | 0 .../baeldung/hibernate/lob/LobUnitTest.java | 0 ...neToManyAnnotationMainIntegrationTest.java | 95 -------------- ...ibernateWhereJoinTableIntegrationTest.java | 118 ------------------ .../src/test/resources/hibernate.properties | 0 .../src/test/resources/lifecycle-init.sql | 0 .../src/test/resources/profile.png | Bin 47 files changed, 83 insertions(+), 805 deletions(-) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/entities/Department.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/lob/model/User.java (100%) delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/Employee.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/Phone.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/Result.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/main/java/com/baeldung/hibernate/pojo/package-info.java (100%) delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/Group.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/User.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java delete mode 100644 persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java (100%) delete mode 100644 persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java delete mode 100644 persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/resources/hibernate.properties (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/resources/lifecycle-init.sql (100%) rename persistence-modules/{hibernate5-mapping => hibernate-mapping}/src/test/resources/profile.png (100%) diff --git a/persistence-modules/hibernate-mapping/README.md b/persistence-modules/hibernate-mapping/README.md index 5bbdeecbea..5ba73f35f3 100644 --- a/persistence-modules/hibernate-mapping/README.md +++ b/persistence-modules/hibernate-mapping/README.md @@ -7,5 +7,9 @@ This module contains articles about Object-relational Mapping (ORM) with Hiberna - [Persisting Maps with Hibernate](https://www.baeldung.com/hibernate-persisting-maps) - [Difference Between @Size, @Length, and @Column(length=value)](https://www.baeldung.com/jpa-size-length-column-differences) - [Hibernate Validator Specific Constraints](https://www.baeldung.com/hibernate-validator-constraints) -- [Hibernate One to Many Annotation Tutorial](http://www.baeldung.com/hibernate-one-to-many) -- [Hibernate @WhereJoinTable Annotation](https://www.baeldung.com/hibernate-wherejointable) +- [Dynamic Mapping with Hibernate](http://www.baeldung.com/hibernate-dynamic-mapping) +- [Hibernate Inheritance Mapping](http://www.baeldung.com/hibernate-inheritance) +- [Mapping A Hibernate Query to a Custom Class](https://www.baeldung.com/hibernate-query-to-custom-class) +- [Hibernate – Mapping Date and Time](http://www.baeldung.com/hibernate-date-time) +- [Mapping LOB Data in Hibernate](http://www.baeldung.com/hibernate-lob) +- [FetchMode in Hibernate](https://www.baeldung.com/hibernate-fetchmode) diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index ac7952fa2b..c7318ee425 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -51,6 +51,17 @@ ${moneta.version} pom + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + commons-io + commons-io + ${commons-io.version} + + @@ -60,6 +71,8 @@ 3.0.1-b11 1.0.3 1.3 + 3.9 + 2.6 diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java index 7de13db8d3..fbd8bd487b 100644 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -1,21 +1,48 @@ package com.baeldung.hibernate; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.service.ServiceRegistry; - import java.io.FileInputStream; import java.io.IOException; import java.net.URL; import java.util.Properties; -public class HibernateUtil { +import org.apache.commons.lang3.StringUtils; +import org.hibernate.SessionFactory; +import org.hibernate.boot.Metadata; +import org.hibernate.boot.MetadataSources; +import org.hibernate.boot.registry.StandardServiceRegistryBuilder; +import org.hibernate.service.ServiceRegistry; +import com.baeldung.hibernate.entities.DeptEmployee; +import com.baeldung.hibernate.pojo.Employee; +import com.baeldung.hibernate.pojo.EntityDescription; +import com.baeldung.hibernate.pojo.Phone; +import com.baeldung.hibernate.pojo.TemporalValues; +import com.baeldung.hibernate.pojo.inheritance.Animal; +import com.baeldung.hibernate.pojo.inheritance.Bag; +import com.baeldung.hibernate.pojo.inheritance.Book; +import com.baeldung.hibernate.pojo.inheritance.Car; +import com.baeldung.hibernate.pojo.inheritance.MyEmployee; +import com.baeldung.hibernate.pojo.inheritance.MyProduct; +import com.baeldung.hibernate.pojo.inheritance.Pen; +import com.baeldung.hibernate.pojo.inheritance.Pet; +import com.baeldung.hibernate.pojo.inheritance.Vehicle; + +public class HibernateUtil { + private static String PROPERTY_FILE_NAME; private HibernateUtil() { } + public static SessionFactory getSessionFactory() throws IOException { + return getSessionFactory(""); + } + + public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { + if(propertyFileName.equals("")) propertyFileName = null; + PROPERTY_FILE_NAME = propertyFileName; + ServiceRegistry serviceRegistry = configureServiceRegistry(); + return makeSessionFactory(serviceRegistry); + } + public static SessionFactory getSessionFactory(Strategy strategy) { return buildSessionFactory(strategy); } @@ -40,6 +67,35 @@ public class HibernateUtil { } } + private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { + MetadataSources metadataSources = new MetadataSources(serviceRegistry); + + metadataSources.addPackage("com.baeldung.hibernate.pojo"); + metadataSources.addAnnotatedClass(Employee.class); + metadataSources.addAnnotatedClass(Phone.class); + metadataSources.addAnnotatedClass(EntityDescription.class); + metadataSources.addAnnotatedClass(TemporalValues.class); + metadataSources.addAnnotatedClass(DeptEmployee.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); + metadataSources.addAnnotatedClass(Animal.class); + metadataSources.addAnnotatedClass(Bag.class); + metadataSources.addAnnotatedClass(Book.class); + metadataSources.addAnnotatedClass(Car.class); + metadataSources.addAnnotatedClass(MyEmployee.class); + metadataSources.addAnnotatedClass(MyProduct.class); + metadataSources.addAnnotatedClass(Pen.class); + metadataSources.addAnnotatedClass(Pet.class); + metadataSources.addAnnotatedClass(Vehicle.class); + + + Metadata metadata = metadataSources.getMetadataBuilder() + .build(); + + return metadata.getSessionFactoryBuilder() + .build(); + + } + private static ServiceRegistry configureServiceRegistry() throws IOException { Properties properties = getProperties(); @@ -51,7 +107,7 @@ public class HibernateUtil { Properties properties = new Properties(); URL propertiesURL = Thread.currentThread() .getContextClassLoader() - .getResource("hibernate.properties"); + .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { properties.load(inputStream); } diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/entities/Department.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/lob/HibernateSessionUtil.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/lob/model/User.java diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java deleted file mode 100644 index 46e6824f42..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/config/HibernateAnnotationUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.hibernate.oneToMany.config; - -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.service.ServiceRegistry; - -public class HibernateAnnotationUtil { - - private static SessionFactory sessionFactory; - - private static SessionFactory buildSessionFactory() { - try { - // Create the SessionFactory from hibernate-annotation.cfg.xml - ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure("hibernate-annotation.cfg.xml").build(); - Metadata metadata = new MetadataSources(serviceRegistry).getMetadataBuilder().build(); - SessionFactory sessionFactory = metadata.getSessionFactoryBuilder().build(); - - return sessionFactory; - - } catch (Throwable ex) { - System.err.println("Initial SessionFactory creation failed." + ex); - ex.printStackTrace(); - throw new ExceptionInInitializerError(ex); - } - } - - public static SessionFactory getSessionFactory() { - if (sessionFactory == null) - sessionFactory = buildSessionFactory(); - return sessionFactory; - } -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java deleted file mode 100644 index 372fb2fc07..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateManyisOwningSide.java +++ /dev/null @@ -1,71 +0,0 @@ -package com.baeldung.hibernate.oneToMany.main; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; - -import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil; -import com.baeldung.hibernate.oneToMany.model.Cart; -import com.baeldung.hibernate.oneToMany.model.Items; -import com.baeldung.hibernate.oneToMany.model.ItemsOIO; - -public class HibernateManyisOwningSide { - public static void main(String[] args) { - - Cart cart = new Cart(); - Cart cart2 = new Cart(); - - Items item1 = new Items(cart); - Items item2 = new Items(cart2); - Set itemsSet = new HashSet(); - itemsSet.add(item1); - itemsSet.add(item2); - - cart.setItems(itemsSet); - - - - SessionFactory sessionFactory = null; - Session session = null; - Transaction tx = null; - try { - // Get Session - sessionFactory = HibernateAnnotationUtil.getSessionFactory(); - session = sessionFactory.getCurrentSession(); - System.out.println("Session created"); - // start transaction - tx = session.beginTransaction(); - // Save the Model object - session.save(cart); - session.save(cart2); - session.save(item1); - session.save(item2); - // Commit transaction - tx.commit(); - session = sessionFactory.getCurrentSession(); - tx = session.beginTransaction(); - - item1 = (Items) session.get(Items.class, new Long(1)); - item2 = (Items) session.get(Items.class, new Long(2)); - tx.commit(); - - - System.out.println("item1 ID=" + item1.getId() + ", Foreign Key CartOIO ID=" + item1.getCart() - .getId()); - System.out.println("item2 ID=" + item2.getId() + ", Foreign Key CartOIO ID=" + item2.getCart() - .getId()); - - } catch (Exception e) { - System.out.println("Exception occured. " + e.getMessage()); - e.printStackTrace(); - } finally { - if (!sessionFactory.isClosed()) { - System.out.println("Closing SessionFactory"); - sessionFactory.close(); - } - } - } -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java deleted file mode 100644 index 2bc5e514f7..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMain.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.baeldung.hibernate.oneToMany.main; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; - -import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil; -import com.baeldung.hibernate.oneToMany.model.Cart; -import com.baeldung.hibernate.oneToMany.model.Items; - -public class HibernateOneToManyAnnotationMain { - - public static void main(String[] args) { - - Cart cart = new Cart(); - - Items item1 = new Items(cart); - Items item2 = new Items(cart); - Set itemsSet = new HashSet(); - itemsSet.add(item1); - itemsSet.add(item2); - - cart.setItems(itemsSet); - - - SessionFactory sessionFactory = null; - Session session = null; - Transaction tx = null; - try { - // Get Session - sessionFactory = HibernateAnnotationUtil.getSessionFactory(); - session = sessionFactory.getCurrentSession(); - System.out.println("Session created"); - // start transaction - tx = session.beginTransaction(); - // Save the Model object - session.save(cart); - session.save(item1); - session.save(item2); - // Commit transaction - tx.commit(); - System.out.println("Cart ID=" + cart.getId()); - System.out.println("item1 ID=" + item1.getId() + ", Foreign Key Cart ID=" + item1.getCart().getId()); - System.out.println("item2 ID=" + item2.getId() + ", Foreign Key Cart ID=" + item1.getCart().getId()); - - } catch (Exception e) { - System.out.println("Exception occured. " + e.getMessage()); - e.printStackTrace(); - } finally { - if (!sessionFactory.isClosed()) { - System.out.println("Closing SessionFactory"); - sessionFactory.close(); - } - } - } - -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java deleted file mode 100644 index 0777664dd0..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/main/HibernateOneisOwningSide.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.hibernate.oneToMany.main; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.Transaction; - -import com.baeldung.hibernate.oneToMany.config.HibernateAnnotationUtil; -import com.baeldung.hibernate.oneToMany.model.CartOIO; -import com.baeldung.hibernate.oneToMany.model.ItemsOIO; - -public class HibernateOneisOwningSide { - public static void main(String[] args) { - - CartOIO cart = new CartOIO(); - CartOIO cart2 = new CartOIO(); - - ItemsOIO item1 = new ItemsOIO(cart); - ItemsOIO item2 = new ItemsOIO(cart2); - Set itemsSet = new HashSet(); - itemsSet.add(item1); - itemsSet.add(item2); - - cart.setItems(itemsSet); - - SessionFactory sessionFactory = null; - Session session = null; - Transaction tx = null; - try { - // Get Session - sessionFactory = HibernateAnnotationUtil.getSessionFactory(); - session = sessionFactory.getCurrentSession(); - System.out.println("Session created"); - // start transaction - tx = session.beginTransaction(); - // Save the Model object - session.save(cart); - session.save(cart2); - session.save(item1); - session.save(item2); - // Commit transaction - tx.commit(); - - session = sessionFactory.getCurrentSession(); - tx = session.beginTransaction(); - item1 = (ItemsOIO) session.get(ItemsOIO.class, new Long(1)); - item2 = (ItemsOIO) session.get(ItemsOIO.class, new Long(2)); - tx.commit(); - - System.out.println("item1 ID=" + item1.getId() + ", Foreign Key CartOIO ID=" + item1.getCartOIO() - .getId()); - System.out.println("item2 ID=" + item2.getId() + ", Foreign Key CartOIO ID=" + item2.getCartOIO() - .getId()); - - } catch (Exception e) { - System.out.println("Exception occured. " + e.getMessage()); - e.printStackTrace(); - } finally { - if (!sessionFactory.isClosed()) { - System.out.println("Closing SessionFactory"); - sessionFactory.close(); - } - } - } -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java deleted file mode 100644 index b8b991831e..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Cart.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.hibernate.oneToMany.model; - -import java.util.Set; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.OneToMany; -import javax.persistence.Table; - -@Entity -@Table(name = "CART") -public class Cart { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "cart_id") - private long id; - - - @OneToMany(mappedBy = "cart") - private Set items; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - - public Set getItems() { - return items; - } - - public void setItems(Set items) { - this.items = items; - } - -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java deleted file mode 100644 index 8a5ed5e7a4..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/CartOIO.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.hibernate.oneToMany.model; - -import java.util.Set; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.OneToMany; -import javax.persistence.Table; - - - -@Entity -@Table(name = "CARTOIO") -public class CartOIO { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - @OneToMany - @JoinColumn(name = "cart_id") // we need to duplicate the physical information - private Set items; - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public Set getItems() { - return items; - } - - public void setItems(Set items) { - this.items = items; - } - -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java deleted file mode 100644 index f63a4855b5..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/Items.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.baeldung.hibernate.oneToMany.model; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "ITEMS") -public class Items { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - @Column(name = "id") - private long id; - - - @ManyToOne - @JoinColumn(name = "cart_id", nullable = false) - private Cart cart; - - // Hibernate requires no-args constructor - public Items() { - } - - public Items(Cart c) { - this.cart = c; - } - - public Cart getCart() { - return cart; - } - - public void setCart(Cart cart) { - this.cart = cart; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java deleted file mode 100644 index a3d6a796c5..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/oneToMany/model/ItemsOIO.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.hibernate.oneToMany.model; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.GenerationType; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; -import javax.persistence.Table; - -@Entity -@Table(name = "ITEMSOIO") -public class ItemsOIO { - - @Id - @GeneratedValue(strategy = GenerationType.IDENTITY) - private long id; - - @ManyToOne - @JoinColumn(name = "cart_id", insertable = false, updatable = false) - private CartOIO cart; - - // Hibernate requires no-args constructor - public ItemsOIO() { - } - - public ItemsOIO(CartOIO c) { - this.cart = c; - } - - public CartOIO getCartOIO() { - return cart; - } - - public void setCartOIO(CartOIO cart) { - this.cart = cart; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - -} diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/Employee.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/EntityDescription.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/Phone.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/Result.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/TemporalValues.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/generator/MyGenerator.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Animal.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Bag.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Book.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Car.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Item.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyEmployee.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/MyProduct.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pen.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Person.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Pet.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/inheritance/Vehicle.java diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java rename to persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/pojo/package-info.java diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/Group.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/Group.java deleted file mode 100644 index 04684eceac..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/Group.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.baeldung.hibernate.wherejointable; - -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.ManyToMany; - -@Entity(name = "e_group") -public class Group { - - @Id - @GeneratedValue - private Long id; - - private String name; - - @ManyToMany(mappedBy = "groups") - private List users = new ArrayList<>(); - - public Group(String name) { - this.name = name; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getUsers() { - return users; - } - - public void setUsers(List users) { - this.users = users; - } - - @Override - public String toString() { - return "Group [name=" + name + "]"; - } - -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/User.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/User.java deleted file mode 100644 index 7fc077eeb2..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/User.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.hibernate.wherejointable; - -import java.util.ArrayList; -import java.util.List; - -import javax.persistence.Entity; -import javax.persistence.GeneratedValue; -import javax.persistence.Id; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.ManyToMany; - -import org.hibernate.annotations.WhereJoinTable; - -@Entity -public class User { - - @Id - @GeneratedValue - private Long id; - - private String name; - - @ManyToMany - @JoinTable(name = "r_user_group", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "group_id")) - private List groups = new ArrayList<>(); - - @WhereJoinTable(clause = "role='MODERATOR'") - @ManyToMany - @JoinTable(name = "r_user_group", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "group_id")) - private List moderatorGroups = new ArrayList<>(); - - public User(String name) { - this.name = name; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public List getGroups() { - return groups; - } - - public void setGroups(List groups) { - this.groups = groups; - } - - public void setModeratorGroups(List moderatorGroups) { - this.moderatorGroups = moderatorGroups; - } - - public List getModeratorGroups() { - return moderatorGroups; - } - - @Override - public String toString() { - return "User [name=" + name + "]"; - } - -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java deleted file mode 100644 index 00dd19699c..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRelation.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.hibernate.wherejointable; - -import java.io.Serializable; - -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; -import javax.persistence.Id; - -@Entity(name = "r_user_group") -public class UserGroupRelation implements Serializable { - - @Id - @Column(name = "user_id", insertable = false, updatable = false) - private final Long userId; - - @Id - @Column(name = "group_id", insertable = false, updatable = false) - private final Long groupId; - - @Enumerated(EnumType.STRING) - private final UserGroupRole role; - - public UserGroupRelation(Long userId, Long groupId, UserGroupRole role) { - this.userId = userId; - this.groupId = groupId; - this.role = role; - } - -} diff --git a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java b/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java deleted file mode 100644 index 62d9cb28ea..0000000000 --- a/persistence-modules/hibernate-mapping/src/main/java/com/baeldung/hibernate/wherejointable/UserGroupRole.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.hibernate.wherejointable; - -public enum UserGroupRole { - - MEMBER, MODERATOR - -} diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java rename to persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java rename to persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/DynamicMappingIntegrationTest.java diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java rename to persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/InheritanceMappingIntegrationTest.java diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java rename to persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/TemporalValuesUnitTest.java diff --git a/persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java rename to persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/lob/LobUnitTest.java diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java deleted file mode 100644 index 3bc5a6e12a..0000000000 --- a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/oneToMany/main/HibernateOneToManyAnnotationMainIntegrationTest.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.baeldung.hibernate.oneToMany.main; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; - -import java.util.HashSet; -import java.util.Set; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Configuration; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.service.ServiceRegistry; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Assert; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -import com.baeldung.hibernate.oneToMany.model.Cart; -import com.baeldung.hibernate.oneToMany.model.Items; - -public class HibernateOneToManyAnnotationMainIntegrationTest { - - private static SessionFactory sessionFactory; - - private Session session; - - public HibernateOneToManyAnnotationMainIntegrationTest() { - } - - @BeforeClass - public static void beforeTests() { - Configuration configuration = new Configuration().addAnnotatedClass(Cart.class).addAnnotatedClass(Items.class) - .setProperty("hibernate.dialect", H2Dialect.class.getName()) - .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) - .setProperty("hibernate.connection.url", "jdbc:h2:mem:test") - .setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "") - .setProperty("hibernate.hbm2ddl.auto", "update"); - ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() - .applySettings(configuration.getProperties()).build(); - sessionFactory = configuration.buildSessionFactory(serviceRegistry); - } - - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - } - - @Test - public void givenSession_checkIfDatabaseIsEmpty() { - Cart cart = (Cart) session.get(Cart.class, new Long(1)); - assertNull(cart); - - } - - @Test - public void givenSession_checkIfDatabaseIsPopulated_afterCommit() { - Cart cart = new Cart(); - Set cartItems = new HashSet<>(); - cartItems = cart.getItems(); - Assert.assertNull(cartItems); - Items item1 = new Items(); - item1.setCart(cart); - assertNotNull(item1); - Set itemsSet = new HashSet(); - itemsSet.add(item1); - assertNotNull(itemsSet); - cart.setItems(itemsSet); - assertNotNull(cart); - session.persist(cart); - session.getTransaction().commit(); - session.close(); - - session = sessionFactory.openSession(); - session.beginTransaction(); - cart = (Cart) session.get(Cart.class, new Long(1)); - assertNotNull(cart); - } - - @After - public void tearDown() { - session.getTransaction().commit(); - session.close(); - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } - -} diff --git a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java b/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java deleted file mode 100644 index 93783216ce..0000000000 --- a/persistence-modules/hibernate-mapping/src/test/java/com/baeldung/hibernate/wherejointable/HibernateWhereJoinTableIntegrationTest.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.baeldung.hibernate.wherejointable; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.hibernate.Session; -import org.hibernate.SessionFactory; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.cfg.Configuration; -import org.hibernate.dialect.H2Dialect; -import org.hibernate.service.ServiceRegistry; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; - -public class HibernateWhereJoinTableIntegrationTest { - - private static SessionFactory sessionFactory; - - private Session session; - - /** - * Test data - */ - private User user1; - private User user2; - private User user3; - private Group group1; - private Group group2; - - @BeforeClass - public static void beforeTests() { - Configuration configuration = new Configuration().addAnnotatedClass(User.class) - .addAnnotatedClass(Group.class) - .addAnnotatedClass(UserGroupRelation.class) - .setProperty("hibernate.dialect", H2Dialect.class.getName()) - .setProperty("hibernate.connection.driver_class", org.h2.Driver.class.getName()) - .setProperty("hibernate.connection.url", "jdbc:h2:mem:test") - .setProperty("hibernate.connection.username", "sa") - .setProperty("hibernate.connection.password", "") - .setProperty("hibernate.hbm2ddl.auto", "update"); - - ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder() - .applySettings(configuration.getProperties()) - .build(); - - sessionFactory = configuration.buildSessionFactory(serviceRegistry); - } - - @Before - public void setUp() { - session = sessionFactory.openSession(); - session.beginTransaction(); - - user1 = new User("user1"); - user2 = new User("user2"); - user3 = new User("user3"); - - group1 = new Group("group1"); - group2 = new Group("group2"); - - session.save(group1); - session.save(group2); - - session.save(user1); - session.save(user2); - session.save(user3); - - saveRelation(user1, group1, UserGroupRole.MODERATOR); - saveRelation(user2, group1, UserGroupRole.MODERATOR); - saveRelation(user3, group1, UserGroupRole.MEMBER); - - saveRelation(user1, group2, UserGroupRole.MEMBER); - saveRelation(user2, group2, UserGroupRole.MODERATOR); - } - - @After - public void tearDown() { - session.getTransaction().commit(); - session.close(); - } - - @AfterClass - public static void afterTests() { - sessionFactory.close(); - } - - @Test - public void givenUser1_getGroups_returnsAllGroups() { - List groups = user1.getGroups(); - assertEquals(2, groups.size()); - - assertTrue(groups.contains(group1)); - assertTrue(groups.contains(group2)); - } - - @Test - public void givenUser1_getModeratorGroups_returnsOnlyModeratorGroups() { - List groups = user1.getModeratorGroups(); - assertEquals(1, groups.size()); - - assertTrue(groups.contains(group1)); - } - - private void saveRelation(User user, Group group, UserGroupRole role) { - UserGroupRelation relation = new UserGroupRelation(user.getId(), group.getId(), role); - - session.save(relation); - session.flush(); - session.refresh(user); - session.refresh(group); - } - -} diff --git a/persistence-modules/hibernate5-mapping/src/test/resources/hibernate.properties b/persistence-modules/hibernate-mapping/src/test/resources/hibernate.properties similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/resources/hibernate.properties rename to persistence-modules/hibernate-mapping/src/test/resources/hibernate.properties diff --git a/persistence-modules/hibernate5-mapping/src/test/resources/lifecycle-init.sql b/persistence-modules/hibernate-mapping/src/test/resources/lifecycle-init.sql similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/resources/lifecycle-init.sql rename to persistence-modules/hibernate-mapping/src/test/resources/lifecycle-init.sql diff --git a/persistence-modules/hibernate5-mapping/src/test/resources/profile.png b/persistence-modules/hibernate-mapping/src/test/resources/profile.png similarity index 100% rename from persistence-modules/hibernate5-mapping/src/test/resources/profile.png rename to persistence-modules/hibernate-mapping/src/test/resources/profile.png From e1d9086ef76e62eed66de4aa35c03b2e2015a145 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:54:52 +0530 Subject: [PATCH 050/278] JAVA-4: Updated README for original module hibernate5 --- persistence-modules/hibernate5/README.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index 7b5e3bb189..b7a254d836 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -1,6 +1,6 @@ ## Hibernate 5 -This module contains articles about Hibernate 5. +This module contains articles about Hibernate 5. Let's not add more articles here, we should not be creating a -2 out of it. Please add to other existing hibernate-* modules, or create a new one. ### Relevant articles: @@ -12,5 +12,4 @@ This module contains articles about Hibernate 5. - [Hibernate 5 Bootstrapping API](https://www.baeldung.com/hibernate-5-bootstrapping-api) - [Guide to the Hibernate EntityManager](https://www.baeldung.com/hibernate-entitymanager) - [Using c3p0 with Hibernate](https://www.baeldung.com/hibernate-c3p0) -- [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) -- [[Next -->]](/hibernate5-2) \ No newline at end of file +- [Persist a JSON Object Using Hibernate](https://www.baeldung.com/hibernate-persist-json-object) \ No newline at end of file From 6023de1b93d8359df2a916b4af265e31102fd028 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:55:19 +0530 Subject: [PATCH 051/278] JAVA-4: Updated module pom --- persistence-modules/pom.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 2e9b033b79..f1b7c407bd 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -23,11 +23,10 @@ hibernate5 hibernate-mapping hibernate-ogm - hibernate5-mapping - hibernate5-annotations - hibernate5-jpa - hibernate5-queries - hibernate5-enterprise + hibernate-annotations + hibernate-jpa + hibernate-queries + hibernate-enterprise influxdb java-cassandra java-cockroachdb From 12034cd05ceab769408c8b262d072b2b2e0c3650 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 15 Mar 2020 12:56:22 +0530 Subject: [PATCH 052/278] JAVA-4: Included article in README for which code belongs here --- persistence-modules/spring-hibernate-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-hibernate-5/README.md b/persistence-modules/spring-hibernate-5/README.md index a74600a47f..4a97368537 100644 --- a/persistence-modules/spring-hibernate-5/README.md +++ b/persistence-modules/spring-hibernate-5/README.md @@ -12,3 +12,4 @@ This module contains articles about Hibernate 5 with Spring. - [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) +- [@Immutable in Hibernate](http://www.baeldung.com/hibernate-immutable) From 2ce585c3eab9f7167b8ddd87847bed44400d0a2c Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 09:51:11 +0100 Subject: [PATCH 053/278] JAVA-86: Initial migration - spring-boot-change-port --- .../spring-boot-basic-customization/README.md | 7 +++++ .../spring-boot-basic-customization/pom.xml | 31 +++++++++++++++++++ .../changeport/CustomApplication.java | 17 ++++++++++ .../changeport/ServerPortCustomizer.java | 15 +++++++++ .../src/main/resources/application.properties | 7 +++++ .../src/main/resources/logback.xml | 13 ++++++++ 6 files changed, 90 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization/README.md create mode 100644 spring-boot-modules/spring-boot-basic-customization/pom.xml create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/CustomApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/logback.xml diff --git a/spring-boot-modules/spring-boot-basic-customization/README.md b/spring-boot-modules/spring-boot-basic-customization/README.md new file mode 100644 index 0000000000..fdf414b252 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/README.md @@ -0,0 +1,7 @@ +## Spring Boot Basic Customization + +This module contains articles about Spring Boot customization + +### Relevant Articles: + + - [How to Change the Default Port in Spring Boot](https://www.baeldung.com/spring-boot-change-port) diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml new file mode 100644 index 0000000000..828ee42b95 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + spring-boot-basic-customization + spring-boot-basic-customization + jar + Module For Spring Boot Basic Customization + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../../parent-boot-2 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/CustomApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/CustomApplication.java new file mode 100644 index 0000000000..3fce0f1289 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/CustomApplication.java @@ -0,0 +1,17 @@ +package com.baeldung.changeport; + +import java.util.Collections; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class CustomApplication { + + public static void main(String[] args) { + SpringApplication app = new SpringApplication(CustomApplication.class); + app.setDefaultProperties(Collections.singletonMap("server.port", "8083")); + app.run(args); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java new file mode 100644 index 0000000000..f3610aeac6 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java @@ -0,0 +1,15 @@ +package com.baeldung.changeport; + +import org.springframework.boot.web.server.ConfigurableWebServerFactory; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; + +//@Component +public class ServerPortCustomizer implements WebServerFactoryCustomizer { + + @Override + public void customize(ConfigurableWebServerFactory factory) { + factory.setPort(8086); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties new file mode 100644 index 0000000000..27b7915cff --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties @@ -0,0 +1,7 @@ +management.endpoints.web.exposure.include=* +management.metrics.enable.root=true +management.metrics.enable.jvm=true +management.endpoint.restart.enabled=true +spring.datasource.jmx-enabled=false +spring.main.allow-bean-definition-overriding=true +management.endpoint.shutdown.enabled=true \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/logback.xml b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file From afcd5d23c514b5af47eecd61009a1d8f637f09ca Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 11:32:12 +0100 Subject: [PATCH 054/278] JAVA-86: Migrate spring-boot-custom-banners --- .../spring-boot-basic-customization/README.md | 1 + .../src/main/resources/application.properties | 14 +++++++------- .../src/main/resources/banner.txt | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/banner.txt diff --git a/spring-boot-modules/spring-boot-basic-customization/README.md b/spring-boot-modules/spring-boot-basic-customization/README.md index fdf414b252..1a899fd13a 100644 --- a/spring-boot-modules/spring-boot-basic-customization/README.md +++ b/spring-boot-modules/spring-boot-basic-customization/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring Boot customization ### Relevant Articles: - [How to Change the Default Port in Spring Boot](https://www.baeldung.com/spring-boot-change-port) + - [Using Custom Banners in Spring Boot](https://www.baeldung.com/spring-boot-custom-banners) diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties index 27b7915cff..2063d36b46 100644 --- a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties @@ -1,7 +1,7 @@ -management.endpoints.web.exposure.include=* -management.metrics.enable.root=true -management.metrics.enable.jvm=true -management.endpoint.restart.enabled=true -spring.datasource.jmx-enabled=false -spring.main.allow-bean-definition-overriding=true -management.endpoint.shutdown.enabled=true \ No newline at end of file +#spring.banner.charset=UTF-8 +#spring.banner.location=classpath:banner.txt +#spring.banner.image.location=classpath:banner.gif +#spring.banner.image.width= //TODO +#spring.banner.image.height= //TODO +#spring.banner.image.margin= //TODO +#spring.banner.image.invert= //TODO \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/banner.txt b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/banner.txt new file mode 100644 index 0000000000..abfa666eb6 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/banner.txt @@ -0,0 +1,14 @@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@########@@@@@@@@@@@@@@@@@@@@@@@@...@@@@@@@@@:..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@#. @@@@@* *@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@#o @@@@@* @@@@@* @@@:*.*@@@@@@@: *8@@@ @@@@&:.#@. @o**@@@@**:@o*o@@:.:@@@@@:.o#@&*:@@@@ +@@@@@@@@@@@@* @@@@@* 8888 8@ @@@8 #@o 8@# .@ @@* :. @* @@@@ @. : &@ ** .@@@@ +@@@@@@@@@@. @ o@@@@@* *@@@o::& .* 8@@@@. @@ 8@@@@. @* @@@@ @. @@@& * @@@@# .@@@@ +@@@@@@@@@& @ @@@@@@* @@@@@@ 8 @@@@ .. o&&&&&&& @@ #@@@@. @* @@@@ @. @@@# * @@@@@ .@@@@ +@@@@@@@@@ @@o @@@@@@@* oooo* 8 @@@& @* @@@ # 88. 88. *& o#: @. @@@# *@ &#& .@@@@ +@@@@@@@@# @@@8 @@@@@@@* .*@@@#. *@@ @@@& :#@@@o .@@: *&@8 @o o@@: @. @@@# *@@#. :8# .@@@@ +@@@@@@@@@ @@@@ &@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# o@@@@ @@@@@ +@@@@@& &@@@@ 8@@@@@@@@@8&8@@@@@#8#@@@o8@#&@@o&@@@&@@8@@&@@@@88@@8#@8&@@##@@@@@@#8@@#8@@88@@@@@ *@@@@@@@ +@@@# #@@@@#. @@@@@@@@@@@@@8@@8#o@&#@@@@o.@o*@@*.@@@.@&:8o8*@@@8&@@#@@@8@@@@8@#@@@8&@@@@@@#@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ +@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \ No newline at end of file From 3750e28487a7250117240518509acd4d37c5467a Mon Sep 17 00:00:00 2001 From: Ashley Frieze Date: Sun, 15 Mar 2020 11:07:17 +0000 Subject: [PATCH 055/278] BAEL-3339 Remove unnecessary Spring Security Core dependency --- spring-boot-modules/spring-boot-security/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spring-boot-modules/spring-boot-security/pom.xml b/spring-boot-modules/spring-boot-security/pom.xml index a72113ce2f..98eceaff96 100644 --- a/spring-boot-modules/spring-boot-security/pom.xml +++ b/spring-boot-modules/spring-boot-security/pom.xml @@ -24,11 +24,6 @@ spring-security-oauth2 2.4.0.RELEASE - - org.springframework.security - spring-security-core - 5.2.1.RELEASE - commons-io commons-io From 5065a7353dd2d4856c4bf8997d511a7c3ce6f650 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 15 Mar 2020 12:50:43 +0100 Subject: [PATCH 056/278] BAEL-3855 --- .../lock/ConcurrentAccessBenchmark.java | 11 ++++++----- .../com/baeldung/concurrent/lock/SingleLock.java | 12 ++---------- .../baeldung/concurrent/lock/StripedLock.java | 16 ++++------------ 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java index 2dcaa5cb53..ceb53ce077 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/ConcurrentAccessBenchmark.java @@ -18,36 +18,37 @@ import org.openjdk.jmh.annotations.Warmup; @Fork(value = 2) @Warmup(iterations = 0) public class ConcurrentAccessBenchmark { - ConcurrentAccessExperiment accessMyMap; static final int SLOTS = 4; static final int THREADS = 10000; static final int BUCKETS = Runtime.getRuntime().availableProcessors() * SLOTS; + SingleLock singleLock = new SingleLock(); + StripedLock stripedLock = new StripedLock(BUCKETS); @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map singleLockHashMap() throws InterruptedException { - return (new SingleLock()).doWork(new HashMap(), THREADS, SLOTS); + return singleLock.doWork(new HashMap(), THREADS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map stripedLockHashMap() throws InterruptedException { - return (new StripedLock(BUCKETS)).doWork(new HashMap(), THREADS, SLOTS); + return stripedLock.doWork(new HashMap(), THREADS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map singleLockConcurrentHashMap() throws InterruptedException { - return (new SingleLock()).doWork(new ConcurrentHashMap(), THREADS, SLOTS); + return singleLock.doWork(new ConcurrentHashMap(), THREADS, SLOTS); } @Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS) public Map stripedLockConcurrentHashMap() throws InterruptedException { - return (new StripedLock(BUCKETS)).doWork(new ConcurrentHashMap(), THREADS, SLOTS); + return stripedLock.doWork(new ConcurrentHashMap(), THREADS, SLOTS); } } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java index 9bbac82c6d..762053c4c9 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -17,12 +17,8 @@ public class SingleLock extends ConcurrentAccessExperiment { try { lock.lock(); map.put("key" + key, "value" + key); - } catch (Exception e) { - this.putSupplier(map, key); } finally { - try { - lock.unlock(); - } catch (Exception e) {} + lock.unlock(); } return null; }); @@ -33,12 +29,8 @@ public class SingleLock extends ConcurrentAccessExperiment { try { lock.lock(); map.get("key" + key); - } catch (Exception e) { - this.getSupplier(map, key); } finally { - try { - lock.unlock(); - } catch (Exception e) {} + lock.unlock(); } return null; }); diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index 46610c3b78..e132cb061d 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -18,14 +18,10 @@ public class StripedLock extends ConcurrentAccessExperiment { int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); try { - lock.tryLock(); + lock.lock(); map.put("key" + key, "value" + key); - } catch (Exception e) { - this.putSupplier(map, key); } finally { - try { - lock.unlock(); - } catch (Exception e) {} + lock.unlock(); } return null; }); @@ -36,14 +32,10 @@ public class StripedLock extends ConcurrentAccessExperiment { int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); try { - lock.tryLock(); + lock.lock(); map.get("key" + key); - } catch (Exception e) { - this.getSupplier(map, key); } finally { - try { - lock.unlock(); - } catch (Exception e) {} + lock.unlock(); } return null; }); From dae03d6a87137322cf5f5a67d8a33e86dfbbf7f4 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 15 Mar 2020 13:04:55 +0100 Subject: [PATCH 057/278] BAEL-3855 --- .../main/java/com/baeldung/concurrent/lock/SingleLock.java | 6 ++---- .../main/java/com/baeldung/concurrent/lock/StripedLock.java | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java index 762053c4c9..19b3ba4510 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -16,11 +16,10 @@ public class SingleLock extends ConcurrentAccessExperiment { return (()-> { try { lock.lock(); - map.put("key" + key, "value" + key); + return map.put("key" + key, "value" + key); } finally { lock.unlock(); } - return null; }); } @@ -28,11 +27,10 @@ public class SingleLock extends ConcurrentAccessExperiment { return (()-> { try { lock.lock(); - map.get("key" + key); + return map.get("key" + key); } finally { lock.unlock(); } - return null; }); } } diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index e132cb061d..7adca428ba 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -19,11 +19,10 @@ public class StripedLock extends ConcurrentAccessExperiment { Lock lock = stripedLock.get(bucket); try { lock.lock(); - map.put("key" + key, "value" + key); + return map.put("key" + key, "value" + key); } finally { lock.unlock(); } - return null; }); } @@ -33,11 +32,10 @@ public class StripedLock extends ConcurrentAccessExperiment { Lock lock = stripedLock.get(bucket); try { lock.lock(); - map.get("key" + key); + return map.get("key" + key); } finally { lock.unlock(); } - return null; }); } } From 1f4a4e24ec8cf6b1d389421e62a0b079815c33c9 Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 15 Mar 2020 18:22:24 +0530 Subject: [PATCH 058/278] pom formatting --- akka-http/pom.xml | 7 +- akka-streams/pom.xml | 6 +- algorithms-genetic/pom.xml | 6 +- algorithms-miscellaneous-1/pom.xml | 6 +- algorithms-miscellaneous-2/pom.xml | 6 +- algorithms-miscellaneous-3/pom.xml | 6 +- algorithms-miscellaneous-4/pom.xml | 6 +- algorithms-miscellaneous-5/pom.xml | 6 +- algorithms-searching/pom.xml | 6 +- algorithms-sorting-2/pom.xml | 6 +- algorithms-sorting/pom.xml | 6 +- animal-sniffer-mvn-plugin/pom.xml | 8 +- annotations/annotation-processing/pom.xml | 6 +- annotations/annotation-user/pom.xml | 6 +- annotations/pom.xml | 6 +- antlr/pom.xml | 8 +- apache-avro/pom.xml | 7 +- apache-bval/pom.xml | 6 +- apache-curator/pom.xml | 6 +- apache-cxf/cxf-aegis/pom.xml | 6 +- apache-cxf/cxf-introduction/pom.xml | 6 +- apache-cxf/cxf-jaxrs-implementation/pom.xml | 6 +- apache-cxf/cxf-spring/pom.xml | 6 +- apache-cxf/pom.xml | 6 +- apache-cxf/sse-jaxrs/pom.xml | 7 +- apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml | 7 +- apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml | 9 +- apache-fop/pom.xml | 6 +- apache-geode/pom.xml | 7 +- apache-meecrowave/pom.xml | 6 +- apache-olingo/olingo2/pom.xml | 7 +- apache-opennlp/pom.xml | 6 +- apache-poi/pom.xml | 6 +- apache-pulsar/pom.xml | 6 +- apache-rocketmq/pom.xml | 7 +- apache-shiro/pom.xml | 7 +- apache-solrj/pom.xml | 6 +- apache-spark/pom.xml | 7 +- apache-tapestry/pom.xml | 35 ++-- apache-thrift/pom.xml | 6 +- apache-tika/pom.xml | 6 +- apache-velocity/pom.xml | 6 +- apache-zookeeper/pom.xml | 6 +- asciidoctor/pom.xml | 6 +- asm/pom.xml | 6 +- atomix/pom.xml | 6 +- aws-lambda/pom.xml | 6 +- aws-reactive/pom.xml | 171 +++++++++--------- aws/pom.xml | 6 +- axon/pom.xml | 6 +- azure/pom.xml | 6 +- bazel/bazelapp/pom.xml | 7 +- bazel/bazelgreeting/pom.xml | 7 +- bazel/pom.xml | 7 +- blade/pom.xml | 7 +- bootique/pom.xml | 6 +- cas/cas-secured-app/pom.xml | 6 +- cas/cas-server/pom.xml | 6 +- cas/pom.xml | 6 +- cdi/pom.xml | 6 +- checker-plugin/pom.xml | 17 +- .../cf-uaa-oauth2-client/pom.xml | 6 +- .../cf-uaa-oauth2-resource-server/pom.xml | 6 +- cloud-foundry-uaa/pom.xml | 6 +- code-generation/pom.xml | 6 +- core-groovy-2/pom.xml | 6 +- core-groovy-collections/pom.xml | 6 +- core-groovy/pom.xml | 6 +- core-java-modules/core-java-10/pom.xml | 6 +- core-java-modules/core-java-11/pom.xml | 14 +- core-java-modules/core-java-12/pom.xml | 7 +- core-java-modules/core-java-13/pom.xml | 4 +- core-java-modules/core-java-14/pom.xml | 7 +- core-java-modules/core-java-8-2/pom.xml | 7 +- core-java-modules/core-java-8/pom.xml | 6 +- .../core-java-9-improvements/pom.xml | 6 +- core-java-modules/core-java-9-jigsaw/pom.xml | 6 +- .../core-java-9-new-features/pom.xml | 6 +- core-java-modules/core-java-9-streams/pom.xml | 6 +- core-java-modules/core-java-9/pom.xml | 6 +- .../core-java-annotations/pom.xml | 6 +- core-java-modules/core-java-arrays-2/pom.xml | 57 +++--- core-java-modules/core-java-arrays-3/pom.xml | 51 +++--- core-java-modules/core-java-arrays/pom.xml | 12 +- .../core-java-collections-2/pom.xml | 6 +- .../core-java-collections-3/pom.xml | 6 +- .../core-java-collections-array-list/pom.xml | 6 +- .../core-java-collections-list-2/pom.xml | 6 +- .../core-java-collections-list-3/pom.xml | 6 +- .../core-java-collections-list/pom.xml | 6 +- .../core-java-collections-set/pom.xml | 6 +- .../core-java-collections/pom.xml | 6 +- .../core-java-concurrency-2/pom.xml | 6 +- .../core-java-concurrency-advanced-2/pom.xml | 6 +- .../core-java-concurrency-advanced-3/pom.xml | 15 +- .../core-java-concurrency-advanced/pom.xml | 6 +- .../core-java-concurrency-basic-2/pom.xml | 6 +- .../core-java-concurrency-basic/pom.xml | 6 +- .../core-java-concurrency-collections/pom.xml | 6 +- .../core-java-date-operations-1/pom.xml | 6 +- .../core-java-date-operations-2/pom.xml | 3 +- .../core-java-datetime-conversion/pom.xml | 6 +- .../core-java-datetime-java8-2/pom.xml | 6 +- .../core-java-datetime-java8/pom.xml | 6 +- .../core-java-datetime-string/pom.xml | 6 +- .../core-java-exceptions-2/pom.xml | 51 +++--- .../core-java-exceptions/pom.xml | 7 +- core-java-modules/core-java-function/pom.xml | 6 +- core-java-modules/core-java-io-2/pom.xml | 6 +- core-java-modules/core-java-io-apis/pom.xml | 6 +- .../core-java-io-conversions/pom.xml | 6 +- core-java-modules/core-java-io/pom.xml | 10 +- core-java-modules/core-java-jar/pom.xml | 10 +- core-java-modules/core-java-jndi/pom.xml | 9 +- .../consumermodule/pom.xml | 6 +- .../decoupling-pattern1/pom.xml | 7 +- .../decoupling-pattern1/servicemodule/pom.xml | 6 +- .../consumermodule/pom.xml | 9 +- .../decoupling-pattern2/pom.xml | 9 +- .../providermodule/pom.xml | 9 +- .../decoupling-pattern2/servicemodule/pom.xml | 7 +- core-java-modules/core-java-jpms/pom.xml | 6 +- core-java-modules/core-java-jvm/pom.xml | 6 +- core-java-modules/core-java-lambdas/pom.xml | 7 +- core-java-modules/core-java-lang-2/pom.xml | 6 +- core-java-modules/core-java-lang-math/pom.xml | 6 +- .../core-java-lang-oop-2/pom.xml | 6 +- .../core-java-lang-oop-3/pom.xml | 6 +- .../core-java-lang-oop-4/pom.xml | 6 +- core-java-modules/core-java-lang-oop/pom.xml | 6 +- .../core-java-lang-operators/pom.xml | 7 +- .../core-java-lang-syntax-2/pom.xml | 6 +- .../core-java-lang-syntax/pom.xml | 6 +- core-java-modules/core-java-lang/pom.xml | 6 +- .../core-java-networking-2/pom.xml | 6 +- .../core-java-networking/pom.xml | 6 +- core-java-modules/core-java-nio-2/pom.xml | 7 +- core-java-modules/core-java-nio/pom.xml | 7 +- core-java-modules/core-java-optional/pom.xml | 6 +- core-java-modules/core-java-os/pom.xml | 6 +- core-java-modules/core-java-perf/pom.xml | 6 +- .../core-java-reflection/pom.xml | 7 +- core-java-modules/core-java-regex/pom.xml | 6 +- .../core-java-security-2/pom.xml | 6 +- core-java-modules/core-java-security/pom.xml | 6 +- core-java-modules/core-java-streams-2/pom.xml | 6 +- core-java-modules/core-java-streams-3/pom.xml | 6 +- core-java-modules/core-java-streams/pom.xml | 6 +- .../core-java-string-algorithms-2/pom.xml | 6 +- .../core-java-string-algorithms-3/pom.xml | 101 ++++++----- .../core-java-string-algorithms/pom.xml | 6 +- .../core-java-string-apis/pom.xml | 6 +- .../core-java-string-conversions-2/pom.xml | 6 +- .../core-java-string-conversions/pom.xml | 6 +- .../core-java-string-operations-2/pom.xml | 6 +- .../core-java-string-operations/pom.xml | 6 +- core-java-modules/core-java-strings/pom.xml | 6 +- core-java-modules/core-java-sun/pom.xml | 10 +- .../core-java-time-measurements/pom.xml | 7 +- core-java-modules/core-java/pom.xml | 10 +- .../multimodulemavenproject/daomodule/pom.xml | 6 +- .../entitymodule/pom.xml | 6 +- .../mainappmodule/pom.xml | 6 +- .../userdaomodule/pom.xml | 6 +- core-java-modules/pom.xml | 19 +- core-java-modules/pre-jpms/pom.xml | 9 +- parent-boot-1/pom.xml | 6 +- parent-boot-2/pom.xml | 6 +- parent-java/pom.xml | 6 +- parent-kotlin/pom.xml | 6 +- parent-spring-4/pom.xml | 6 +- parent-spring-5/pom.xml | 7 +- spring-5-reactive-client/pom.xml | 6 +- webrtc/pom.xml | 3 +- wicket/pom.xml | 6 +- wildfly/pom.xml | 6 +- xml/pom.xml | 16 +- xstream/pom.xml | 6 +- 178 files changed, 948 insertions(+), 663 deletions(-) diff --git a/akka-http/pom.xml b/akka-http/pom.xml index e276ef1aa4..c0b460dd8e 100644 --- a/akka-http/pom.xml +++ b/akka-http/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 akka-http akka-http diff --git a/akka-streams/pom.xml b/akka-streams/pom.xml index 967556d976..f87f9dd667 100644 --- a/akka-streams/pom.xml +++ b/akka-streams/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 akka-streams akka-streams diff --git a/algorithms-genetic/pom.xml b/algorithms-genetic/pom.xml index eeccb89d6f..942acd69c6 100644 --- a/algorithms-genetic/pom.xml +++ b/algorithms-genetic/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-genetic 0.0.1-SNAPSHOT diff --git a/algorithms-miscellaneous-1/pom.xml b/algorithms-miscellaneous-1/pom.xml index b7c32bda43..d9ecbd78e8 100644 --- a/algorithms-miscellaneous-1/pom.xml +++ b/algorithms-miscellaneous-1/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-miscellaneous-1 0.0.1-SNAPSHOT diff --git a/algorithms-miscellaneous-2/pom.xml b/algorithms-miscellaneous-2/pom.xml index e4f4e5c2ea..7144a7a391 100644 --- a/algorithms-miscellaneous-2/pom.xml +++ b/algorithms-miscellaneous-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-miscellaneous-2 0.0.1-SNAPSHOT diff --git a/algorithms-miscellaneous-3/pom.xml b/algorithms-miscellaneous-3/pom.xml index 673ac0121d..877e8bfefa 100644 --- a/algorithms-miscellaneous-3/pom.xml +++ b/algorithms-miscellaneous-3/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-miscellaneous-3 0.0.1-SNAPSHOT diff --git a/algorithms-miscellaneous-4/pom.xml b/algorithms-miscellaneous-4/pom.xml index 682234ad07..50fef5ff71 100644 --- a/algorithms-miscellaneous-4/pom.xml +++ b/algorithms-miscellaneous-4/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-miscellaneous-4 0.0.1-SNAPSHOT diff --git a/algorithms-miscellaneous-5/pom.xml b/algorithms-miscellaneous-5/pom.xml index 2799c39971..f2db71a6da 100644 --- a/algorithms-miscellaneous-5/pom.xml +++ b/algorithms-miscellaneous-5/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-miscellaneous-5 0.0.1-SNAPSHOT diff --git a/algorithms-searching/pom.xml b/algorithms-searching/pom.xml index da32874a18..80443155ff 100644 --- a/algorithms-searching/pom.xml +++ b/algorithms-searching/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-searching 0.0.1-SNAPSHOT diff --git a/algorithms-sorting-2/pom.xml b/algorithms-sorting-2/pom.xml index d862c91430..529474afda 100644 --- a/algorithms-sorting-2/pom.xml +++ b/algorithms-sorting-2/pom.xml @@ -1,5 +1,7 @@ - + 4.0.0 algorithms-sorting-2 0.0.1-SNAPSHOT diff --git a/algorithms-sorting/pom.xml b/algorithms-sorting/pom.xml index 84856235d9..2de8eed04e 100644 --- a/algorithms-sorting/pom.xml +++ b/algorithms-sorting/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 algorithms-sorting 0.0.1-SNAPSHOT diff --git a/animal-sniffer-mvn-plugin/pom.xml b/animal-sniffer-mvn-plugin/pom.xml index d04581aaac..82726aa7bc 100644 --- a/animal-sniffer-mvn-plugin/pom.xml +++ b/animal-sniffer-mvn-plugin/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 animal-sniffer-mvn-plugin 1.0-SNAPSHOT @@ -44,5 +46,5 @@ 1.16 1.0 - + \ No newline at end of file diff --git a/annotations/annotation-processing/pom.xml b/annotations/annotation-processing/pom.xml index 645bbd7a0f..f94cee04f0 100644 --- a/annotations/annotation-processing/pom.xml +++ b/annotations/annotation-processing/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 annotation-processing annotation-processing diff --git a/annotations/annotation-user/pom.xml b/annotations/annotation-user/pom.xml index ae47e19f05..f38e93528d 100644 --- a/annotations/annotation-user/pom.xml +++ b/annotations/annotation-user/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 annotation-user annotation-user diff --git a/annotations/pom.xml b/annotations/pom.xml index 41e1e8735b..c3c23cf5ab 100644 --- a/annotations/pom.xml +++ b/annotations/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 annotations annotations diff --git a/antlr/pom.xml b/antlr/pom.xml index 641382d450..c8e48706fb 100644 --- a/antlr/pom.xml +++ b/antlr/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 antlr antlr @@ -58,5 +60,5 @@ 4.7.1 3.0.0 - + \ No newline at end of file diff --git a/apache-avro/pom.xml b/apache-avro/pom.xml index 35898711c8..ad32ebb702 100644 --- a/apache-avro/pom.xml +++ b/apache-avro/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 apache-avro 0.0.1-SNAPSHOT diff --git a/apache-bval/pom.xml b/apache-bval/pom.xml index 4254242e55..49484f4959 100644 --- a/apache-bval/pom.xml +++ b/apache-bval/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-bval 0.0.1-SNAPSHOT diff --git a/apache-curator/pom.xml b/apache-curator/pom.xml index ea8fb358ad..5b249127d9 100644 --- a/apache-curator/pom.xml +++ b/apache-curator/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-curator 0.0.1-SNAPSHOT diff --git a/apache-cxf/cxf-aegis/pom.xml b/apache-cxf/cxf-aegis/pom.xml index 6e6c5b093c..c10f019f82 100644 --- a/apache-cxf/cxf-aegis/pom.xml +++ b/apache-cxf/cxf-aegis/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cxf-aegis cxf-aegis diff --git a/apache-cxf/cxf-introduction/pom.xml b/apache-cxf/cxf-introduction/pom.xml index 0572b01a9d..be604fa401 100644 --- a/apache-cxf/cxf-introduction/pom.xml +++ b/apache-cxf/cxf-introduction/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cxf-introduction cxf-introduction diff --git a/apache-cxf/cxf-jaxrs-implementation/pom.xml b/apache-cxf/cxf-jaxrs-implementation/pom.xml index 37b81882bb..7b77969075 100644 --- a/apache-cxf/cxf-jaxrs-implementation/pom.xml +++ b/apache-cxf/cxf-jaxrs-implementation/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cxf-jaxrs-implementation cxf-jaxrs-implementation diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 01ee7d9411..f9581515b2 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cxf-spring cxf-spring diff --git a/apache-cxf/pom.xml b/apache-cxf/pom.xml index c993eff3a5..3d64000c2e 100644 --- a/apache-cxf/pom.xml +++ b/apache-cxf/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-cxf 0.0.1-SNAPSHOT diff --git a/apache-cxf/sse-jaxrs/pom.xml b/apache-cxf/sse-jaxrs/pom.xml index 89bd5d4191..5c46547b9a 100644 --- a/apache-cxf/sse-jaxrs/pom.xml +++ b/apache-cxf/sse-jaxrs/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 sse-jaxrs sse-jaxrs diff --git a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml index 37a068003c..92a6165f04 100644 --- a/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml +++ b/apache-cxf/sse-jaxrs/sse-jaxrs-client/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 sse-jaxrs-client sse-jaxrs-client diff --git a/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml b/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml index 1d7ecdb58f..efebb328a2 100644 --- a/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml +++ b/apache-cxf/sse-jaxrs/sse-jaxrs-server/pom.xml @@ -1,12 +1,13 @@ - + 4.0.0 sse-jaxrs-server sse-jaxrs-server war - + com.baeldung sse-jaxrs diff --git a/apache-fop/pom.xml b/apache-fop/pom.xml index 41a6761eaf..fdcfe2c538 100644 --- a/apache-fop/pom.xml +++ b/apache-fop/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-fop 0.1-SNAPSHOT diff --git a/apache-geode/pom.xml b/apache-geode/pom.xml index 78c6390f80..fc5b253c01 100644 --- a/apache-geode/pom.xml +++ b/apache-geode/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 apache-geode 1.0-SNAPSHOT diff --git a/apache-meecrowave/pom.xml b/apache-meecrowave/pom.xml index 9e79780e22..e046599be3 100644 --- a/apache-meecrowave/pom.xml +++ b/apache-meecrowave/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-meecrowave 0.0.1 diff --git a/apache-olingo/olingo2/pom.xml b/apache-olingo/olingo2/pom.xml index 4689fa0ca9..3456d4f362 100644 --- a/apache-olingo/olingo2/pom.xml +++ b/apache-olingo/olingo2/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.examples.olingo2 olingo2 diff --git a/apache-opennlp/pom.xml b/apache-opennlp/pom.xml index 701d33c6fd..07ce14b4fd 100644 --- a/apache-opennlp/pom.xml +++ b/apache-opennlp/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-opennlp 1.0-SNAPSHOT diff --git a/apache-poi/pom.xml b/apache-poi/pom.xml index 333339ed33..eb72531787 100644 --- a/apache-poi/pom.xml +++ b/apache-poi/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-poi 0.0.1-SNAPSHOT diff --git a/apache-pulsar/pom.xml b/apache-pulsar/pom.xml index 206e1ab74d..568389f9f5 100644 --- a/apache-pulsar/pom.xml +++ b/apache-pulsar/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.pulsar apache-pulsar diff --git a/apache-rocketmq/pom.xml b/apache-rocketmq/pom.xml index f15dd0e61c..ba395ff054 100644 --- a/apache-rocketmq/pom.xml +++ b/apache-rocketmq/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 apache-rocketmq 1.0-SNAPSHOT diff --git a/apache-shiro/pom.xml b/apache-shiro/pom.xml index 0458ba783f..d519ba42af 100644 --- a/apache-shiro/pom.xml +++ b/apache-shiro/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 apache-shiro 1.0-SNAPSHOT diff --git a/apache-solrj/pom.xml b/apache-solrj/pom.xml index b25fd0fb04..165cd9571b 100644 --- a/apache-solrj/pom.xml +++ b/apache-solrj/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-solrj 0.0.1-SNAPSHOT diff --git a/apache-spark/pom.xml b/apache-spark/pom.xml index 59843adc71..27768d60fc 100644 --- a/apache-spark/pom.xml +++ b/apache-spark/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 apache-spark 1.0-SNAPSHOT diff --git a/apache-tapestry/pom.xml b/apache-tapestry/pom.xml index a4124b07df..82dc34899f 100644 --- a/apache-tapestry/pom.xml +++ b/apache-tapestry/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung apache-tapestry @@ -9,9 +11,8 @@ war - + org.apache.tapestry tapestry-core @@ -32,17 +33,10 @@ - + - + org.testng testng @@ -57,8 +51,7 @@ of testing facilities designed for use with TestNG (http://testng.org/), so it's test - + javax.servlet servlet-api @@ -108,8 +101,7 @@ of testing facilities designed for use with TestNG (http://testng.org/), so it's - + true @@ -123,7 +115,7 @@ of testing facilities designed for use with TestNG (http://testng.org/), so it's - + @@ -131,8 +123,7 @@ of testing facilities designed for use with TestNG (http://testng.org/), so it's http://repository.jboss.org/nexus/content/groups/public/ - + apache-staging https://repository.apache.org/content/groups/staging/ diff --git a/apache-thrift/pom.xml b/apache-thrift/pom.xml index 409467ccc5..6d079c8c28 100644 --- a/apache-thrift/pom.xml +++ b/apache-thrift/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-thrift 0.0.1-SNAPSHOT diff --git a/apache-tika/pom.xml b/apache-tika/pom.xml index 24c904aec3..a2c3a32820 100644 --- a/apache-tika/pom.xml +++ b/apache-tika/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-tika 0.0.1-SNAPSHOT diff --git a/apache-velocity/pom.xml b/apache-velocity/pom.xml index 61d7e74498..806b36237d 100644 --- a/apache-velocity/pom.xml +++ b/apache-velocity/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-velocity 0.1-SNAPSHOT diff --git a/apache-zookeeper/pom.xml b/apache-zookeeper/pom.xml index 0bab6cded6..f441848f70 100644 --- a/apache-zookeeper/pom.xml +++ b/apache-zookeeper/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 apache-zookeeper 0.0.1-SNAPSHOT diff --git a/asciidoctor/pom.xml b/asciidoctor/pom.xml index 5421df91be..5b34f19bbb 100644 --- a/asciidoctor/pom.xml +++ b/asciidoctor/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 asciidoctor asciidoctor diff --git a/asm/pom.xml b/asm/pom.xml index 77dbab964c..f4689de8e0 100644 --- a/asm/pom.xml +++ b/asm/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.examples asm diff --git a/atomix/pom.xml b/atomix/pom.xml index 7821ef26d7..53c7a6c0ba 100644 --- a/atomix/pom.xml +++ b/atomix/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.atomix.io atomix diff --git a/aws-lambda/pom.xml b/aws-lambda/pom.xml index 12be77baef..e1d2c7df27 100644 --- a/aws-lambda/pom.xml +++ b/aws-lambda/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 aws-lambda 0.1.0-SNAPSHOT diff --git a/aws-reactive/pom.xml b/aws-reactive/pom.xml index 046825130a..950b3f373a 100644 --- a/aws-reactive/pom.xml +++ b/aws-reactive/pom.xml @@ -1,107 +1,108 @@ - - 4.0.0 - + + 4.0.0 + com.baeldung parent-modules 1.0.0-SNAPSHOT - - aws-reactive - 0.0.1-SNAPSHOT - aws-reactive - AWS Reactive Sample - - 1.8 + aws-reactive + 0.0.1-SNAPSHOT + aws-reactive + AWS Reactive Sample + + + 1.8 2.2.1.RELEASE 2.10.27 - + - - + + - - - org.springframework.boot - spring-boot-dependencies - ${spring.version} - pom - import - + + + org.springframework.boot + spring-boot-dependencies + ${spring.version} + pom + import + - - software.amazon.awssdk - bom - ${awssdk.version} - pom - import - - - + + software.amazon.awssdk + bom + ${awssdk.version} + pom + import + + + - - - org.springframework.boot - spring-boot-starter-webflux - + + + org.springframework.boot + spring-boot-starter-webflux + - - software.amazon.awssdk - s3 - compile - + + software.amazon.awssdk + s3 + compile + - - netty-nio-client - software.amazon.awssdk - compile - + + netty-nio-client + software.amazon.awssdk + compile + - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + - - io.projectreactor - reactor-test - test - - - org.springframework.boot - spring-boot-devtools - runtime - - - org.springframework.boot - spring-boot-configuration-processor - - - org.projectlombok - lombok - - + + io.projectreactor + reactor-test + test + + + org.springframework.boot + spring-boot-devtools + runtime + + + org.springframework.boot + spring-boot-configuration-processor + + + org.projectlombok + lombok + + - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + diff --git a/aws/pom.xml b/aws/pom.xml index 19057d48e9..be0cdfdd43 100644 --- a/aws/pom.xml +++ b/aws/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 aws 0.1.0-SNAPSHOT diff --git a/axon/pom.xml b/axon/pom.xml index be74b38fa6..f6c43c7cbd 100644 --- a/axon/pom.xml +++ b/axon/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 axon axon diff --git a/azure/pom.xml b/azure/pom.xml index 7134a47cd7..dc58ffa595 100644 --- a/azure/pom.xml +++ b/azure/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 azure 0.1 diff --git a/bazel/bazelapp/pom.xml b/bazel/bazelapp/pom.xml index 6440c26cd6..54519afff8 100644 --- a/bazel/bazelapp/pom.xml +++ b/bazel/bazelapp/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 bazelapp bazelapp diff --git a/bazel/bazelgreeting/pom.xml b/bazel/bazelgreeting/pom.xml index ae8a6e4080..7742f92206 100644 --- a/bazel/bazelgreeting/pom.xml +++ b/bazel/bazelgreeting/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 bazelgreeting bazelgreeting diff --git a/bazel/pom.xml b/bazel/pom.xml index b1585cc73b..6673e09dbc 100644 --- a/bazel/pom.xml +++ b/bazel/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 bazel bazel diff --git a/blade/pom.xml b/blade/pom.xml index f463c7f077..178d1afb52 100644 --- a/blade/pom.xml +++ b/blade/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 blade blade diff --git a/bootique/pom.xml b/bootique/pom.xml index 8e40b3ec8d..2cbcd671bb 100644 --- a/bootique/pom.xml +++ b/bootique/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.bootique bootique diff --git a/cas/cas-secured-app/pom.xml b/cas/cas-secured-app/pom.xml index 63d5d43417..8e6f28e3a8 100644 --- a/cas/cas-secured-app/pom.xml +++ b/cas/cas-secured-app/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cas-secured-app cas-secured-app diff --git a/cas/cas-server/pom.xml b/cas/cas-server/pom.xml index bfd8f685ac..abcf251667 100644 --- a/cas/cas-server/pom.xml +++ b/cas/cas-server/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cas-server 1.0 diff --git a/cas/pom.xml b/cas/pom.xml index f458b23797..77fae3b50a 100644 --- a/cas/pom.xml +++ b/cas/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cas cas diff --git a/cdi/pom.xml b/cdi/pom.xml index 32b9c8a360..fec12a9b16 100644 --- a/cdi/pom.xml +++ b/cdi/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cdi 1.0-SNAPSHOT diff --git a/checker-plugin/pom.xml b/checker-plugin/pom.xml index 0140d7951a..9820d8b602 100644 --- a/checker-plugin/pom.xml +++ b/checker-plugin/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 checker-plugin 1.0-SNAPSHOT @@ -66,13 +68,10 @@ -Xbootclasspath/p:${annotatedJdk} - + - + -Awarns @@ -85,9 +84,7 @@ ${org.checkerframework:jdk8:jar} - + 2.3.1 2.3.1 2.3.1 diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml index 1429ca8b24..8706bd3b53 100644 --- a/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml +++ b/cloud-foundry-uaa/cf-uaa-oauth2-client/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.example cf-uaa-oauth2-client diff --git a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml index 6297c6f673..6bac4fe59a 100644 --- a/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml +++ b/cloud-foundry-uaa/cf-uaa-oauth2-resource-server/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.cfuaa cf-uaa-oauth2-resource-server diff --git a/cloud-foundry-uaa/pom.xml b/cloud-foundry-uaa/pom.xml index 0001e521ed..a8a46b921d 100644 --- a/cloud-foundry-uaa/pom.xml +++ b/cloud-foundry-uaa/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 cloud-foundry-uaa 0.0.1-SNAPSHOT diff --git a/code-generation/pom.xml b/code-generation/pom.xml index 7cc076c58f..c5feef2426 100644 --- a/code-generation/pom.xml +++ b/code-generation/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 code-generation 1.0 diff --git a/core-groovy-2/pom.xml b/core-groovy-2/pom.xml index 1b26182ef4..a01560781b 100644 --- a/core-groovy-2/pom.xml +++ b/core-groovy-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-groovy-2 1.0-SNAPSHOT diff --git a/core-groovy-collections/pom.xml b/core-groovy-collections/pom.xml index 4e591970b0..125dfca4c1 100644 --- a/core-groovy-collections/pom.xml +++ b/core-groovy-collections/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-groovy-collections 1.0-SNAPSHOT diff --git a/core-groovy/pom.xml b/core-groovy/pom.xml index 6407f7c0c6..69833ff74d 100644 --- a/core-groovy/pom.xml +++ b/core-groovy/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-groovy 1.0-SNAPSHOT diff --git a/core-java-modules/core-java-10/pom.xml b/core-java-modules/core-java-10/pom.xml index 49ebbfb283..a9b991852f 100644 --- a/core-java-modules/core-java-10/pom.xml +++ b/core-java-modules/core-java-10/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-10 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-11/pom.xml b/core-java-modules/core-java-11/pom.xml index 2dfc72db09..bbc4219eaa 100644 --- a/core-java-modules/core-java-11/pom.xml +++ b/core-java-modules/core-java-11/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-11 0.1.0-SNAPSHOT @@ -78,14 +79,11 @@ org.openjdk.jmh.Main - + - + *:* META-INF/*.SF diff --git a/core-java-modules/core-java-12/pom.xml b/core-java-modules/core-java-12/pom.xml index 171d3f6e73..373f23488e 100644 --- a/core-java-modules/core-java-12/pom.xml +++ b/core-java-modules/core-java-12/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-12 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-13/pom.xml b/core-java-modules/core-java-13/pom.xml index 9469f49411..4537067567 100644 --- a/core-java-modules/core-java-13/pom.xml +++ b/core-java-modules/core-java-13/pom.xml @@ -1,5 +1,7 @@ - 4.0.0 com.baeldung diff --git a/core-java-modules/core-java-14/pom.xml b/core-java-modules/core-java-14/pom.xml index 4f89e87d02..96cb6b37e7 100644 --- a/core-java-modules/core-java-14/pom.xml +++ b/core-java-modules/core-java-14/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-14 core-java-14 diff --git a/core-java-modules/core-java-8-2/pom.xml b/core-java-modules/core-java-8-2/pom.xml index 746755f7a9..00579c49b2 100644 --- a/core-java-modules/core-java-8-2/pom.xml +++ b/core-java-modules/core-java-8-2/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-8-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-8/pom.xml b/core-java-modules/core-java-8/pom.xml index 2a563333ad..a434be028d 100644 --- a/core-java-modules/core-java-8/pom.xml +++ b/core-java-modules/core-java-8/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-8 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-9-improvements/pom.xml b/core-java-modules/core-java-9-improvements/pom.xml index 9958bf9364..d1c6bac9ec 100644 --- a/core-java-modules/core-java-9-improvements/pom.xml +++ b/core-java-modules/core-java-9-improvements/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-9-improvements 0.2-SNAPSHOT diff --git a/core-java-modules/core-java-9-jigsaw/pom.xml b/core-java-modules/core-java-9-jigsaw/pom.xml index ecb36c365d..6ad4c3d510 100644 --- a/core-java-modules/core-java-9-jigsaw/pom.xml +++ b/core-java-modules/core-java-9-jigsaw/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-9-jigsaw 0.2-SNAPSHOT diff --git a/core-java-modules/core-java-9-new-features/pom.xml b/core-java-modules/core-java-9-new-features/pom.xml index 9db1112f1d..b0fb6ab7f9 100644 --- a/core-java-modules/core-java-9-new-features/pom.xml +++ b/core-java-modules/core-java-9-new-features/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-9-new-features 0.2-SNAPSHOT diff --git a/core-java-modules/core-java-9-streams/pom.xml b/core-java-modules/core-java-9-streams/pom.xml index 99be29f2b0..7865b336a7 100644 --- a/core-java-modules/core-java-9-streams/pom.xml +++ b/core-java-modules/core-java-9-streams/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-9-streams 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-9/pom.xml b/core-java-modules/core-java-9/pom.xml index a90ad0a740..b6dff0a3a4 100644 --- a/core-java-modules/core-java-9/pom.xml +++ b/core-java-modules/core-java-9/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-9 0.2-SNAPSHOT diff --git a/core-java-modules/core-java-annotations/pom.xml b/core-java-modules/core-java-annotations/pom.xml index a97686a5b5..8fc4c15cde 100644 --- a/core-java-modules/core-java-annotations/pom.xml +++ b/core-java-modules/core-java-annotations/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-annotations 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-arrays-2/pom.xml b/core-java-modules/core-java-arrays-2/pom.xml index b300de511a..1445a322d7 100644 --- a/core-java-modules/core-java-arrays-2/pom.xml +++ b/core-java-modules/core-java-arrays-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-arrays-2 0.1.0-SNAPSHOT @@ -20,7 +22,7 @@ commons-lang3 ${commons-lang3.version} - + org.openjdk.jmh jmh-core ${jmh.version} @@ -47,34 +49,33 @@ true - - - org.apache.maven.plugins - maven-shade-plugin - ${shade.plugin.version} - - - package - - shade - - - benchmarks - - - org.openjdk.jmh.Main - - - - - - - + + + org.apache.maven.plugins + maven-shade-plugin + ${shade.plugin.version} + + + package + + shade + + + benchmarks + + + org.openjdk.jmh.Main + + + + + + + - 1.19 + 1.19 3.9 diff --git a/core-java-modules/core-java-arrays-3/pom.xml b/core-java-modules/core-java-arrays-3/pom.xml index 516d9b2b37..210375b878 100644 --- a/core-java-modules/core-java-arrays-3/pom.xml +++ b/core-java-modules/core-java-arrays-3/pom.xml @@ -1,31 +1,32 @@ - - 4.0.0 - core-java-arrays-3 - 0.1.0-SNAPSHOT - core-java-arrays-3 - jar + + 4.0.0 + core-java-arrays-3 + 0.1.0-SNAPSHOT + core-java-arrays-3 + jar - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../../parent-java - + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + - - - org.assertj - assertj-core - ${assertj.version} - test - - + + + org.assertj + assertj-core + ${assertj.version} + test + + - - 3.14.0 - + + 3.14.0 + \ No newline at end of file diff --git a/core-java-modules/core-java-arrays/pom.xml b/core-java-modules/core-java-arrays/pom.xml index 145b711135..ea28eb25eb 100644 --- a/core-java-modules/core-java-arrays/pom.xml +++ b/core-java-modules/core-java-arrays/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-arrays 0.1.0-SNAPSHOT @@ -66,7 +68,7 @@ - + org.codehaus.mojo exec-maven-plugin @@ -78,7 +80,7 @@ -Xmx300m -XX:+UseParallelGC -classpath - + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -144,7 +146,7 @@ java -classpath - + org.openjdk.jmh.Main .* diff --git a/core-java-modules/core-java-collections-2/pom.xml b/core-java-modules/core-java-collections-2/pom.xml index e0e7dd5c82..3a7c70b1a2 100644 --- a/core-java-modules/core-java-collections-2/pom.xml +++ b/core-java-modules/core-java-collections-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections-2 core-java-collections-2 diff --git a/core-java-modules/core-java-collections-3/pom.xml b/core-java-modules/core-java-collections-3/pom.xml index f94ff6f71f..1e1695c8bc 100644 --- a/core-java-modules/core-java-collections-3/pom.xml +++ b/core-java-modules/core-java-collections-3/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections-3 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-collections-array-list/pom.xml b/core-java-modules/core-java-collections-array-list/pom.xml index cf7889fa58..74a6513cac 100644 --- a/core-java-modules/core-java-collections-array-list/pom.xml +++ b/core-java-modules/core-java-collections-array-list/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections-array-list 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-collections-list-2/pom.xml b/core-java-modules/core-java-collections-list-2/pom.xml index 05b82a179b..3184da1294 100644 --- a/core-java-modules/core-java-collections-list-2/pom.xml +++ b/core-java-modules/core-java-collections-list-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections-list-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-collections-list-3/pom.xml b/core-java-modules/core-java-collections-list-3/pom.xml index ced8a732c1..090e756ac6 100644 --- a/core-java-modules/core-java-collections-list-3/pom.xml +++ b/core-java-modules/core-java-collections-list-3/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections-list-3 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-collections-list/pom.xml b/core-java-modules/core-java-collections-list/pom.xml index 3227c94e78..e6dce5a0db 100644 --- a/core-java-modules/core-java-collections-list/pom.xml +++ b/core-java-modules/core-java-collections-list/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections-list 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-collections-set/pom.xml b/core-java-modules/core-java-collections-set/pom.xml index d21bbeef77..8ba1b2400d 100644 --- a/core-java-modules/core-java-collections-set/pom.xml +++ b/core-java-modules/core-java-collections-set/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections-set 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-collections/pom.xml b/core-java-modules/core-java-collections/pom.xml index c9cbe94a4f..515d19d7fb 100644 --- a/core-java-modules/core-java-collections/pom.xml +++ b/core-java-modules/core-java-collections/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-collections 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-concurrency-2/pom.xml b/core-java-modules/core-java-concurrency-2/pom.xml index 690fe97ae6..a9a01b70f3 100644 --- a/core-java-modules/core-java-concurrency-2/pom.xml +++ b/core-java-modules/core-java-concurrency-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-concurrency-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-concurrency-advanced-2/pom.xml b/core-java-modules/core-java-concurrency-advanced-2/pom.xml index 7e76219c4e..8752e7b7db 100644 --- a/core-java-modules/core-java-concurrency-advanced-2/pom.xml +++ b/core-java-modules/core-java-concurrency-advanced-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-concurrency-advanced-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-concurrency-advanced-3/pom.xml b/core-java-modules/core-java-concurrency-advanced-3/pom.xml index 8f275f4043..cf81214125 100644 --- a/core-java-modules/core-java-concurrency-advanced-3/pom.xml +++ b/core-java-modules/core-java-concurrency-advanced-3/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-concurrency-advanced-3 @@ -23,26 +24,26 @@ ${assertj.version} test - + com.jcabi jcabi-aspects ${jcabi-aspects.version} - + org.aspectj aspectjrt ${aspectjrt.version} runtime - + com.google.guava guava ${guava.version} - + org.cactoos cactoos diff --git a/core-java-modules/core-java-concurrency-advanced/pom.xml b/core-java-modules/core-java-concurrency-advanced/pom.xml index 65ca811737..d39712468f 100644 --- a/core-java-modules/core-java-concurrency-advanced/pom.xml +++ b/core-java-modules/core-java-concurrency-advanced/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-concurrency-advanced 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-concurrency-basic-2/pom.xml b/core-java-modules/core-java-concurrency-basic-2/pom.xml index 0fee2c04ff..8c9bbef54c 100644 --- a/core-java-modules/core-java-concurrency-basic-2/pom.xml +++ b/core-java-modules/core-java-concurrency-basic-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-concurrency-basic-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-concurrency-basic/pom.xml b/core-java-modules/core-java-concurrency-basic/pom.xml index 9d9d2cb663..c15200da1f 100644 --- a/core-java-modules/core-java-concurrency-basic/pom.xml +++ b/core-java-modules/core-java-concurrency-basic/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-concurrency-basic 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-concurrency-collections/pom.xml b/core-java-modules/core-java-concurrency-collections/pom.xml index f731b1acd1..5c038639a7 100644 --- a/core-java-modules/core-java-concurrency-collections/pom.xml +++ b/core-java-modules/core-java-concurrency-collections/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-concurrency-collections 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-date-operations-1/pom.xml b/core-java-modules/core-java-date-operations-1/pom.xml index 83216f1ad8..54cbc79678 100644 --- a/core-java-modules/core-java-date-operations-1/pom.xml +++ b/core-java-modules/core-java-date-operations-1/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-date-operations-1 ${project.parent.version} diff --git a/core-java-modules/core-java-date-operations-2/pom.xml b/core-java-modules/core-java-date-operations-2/pom.xml index 155b8ad0b7..ea5f852b0d 100644 --- a/core-java-modules/core-java-date-operations-2/pom.xml +++ b/core-java-modules/core-java-date-operations-2/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 diff --git a/core-java-modules/core-java-datetime-conversion/pom.xml b/core-java-modules/core-java-datetime-conversion/pom.xml index e2b143aa88..e2dd579335 100644 --- a/core-java-modules/core-java-datetime-conversion/pom.xml +++ b/core-java-modules/core-java-datetime-conversion/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-datetime-conversion ${project.parent.version} diff --git a/core-java-modules/core-java-datetime-java8-2/pom.xml b/core-java-modules/core-java-datetime-java8-2/pom.xml index 34323fe76c..a15113bddc 100644 --- a/core-java-modules/core-java-datetime-java8-2/pom.xml +++ b/core-java-modules/core-java-datetime-java8-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-datetime-java8 ${project.parent.version} diff --git a/core-java-modules/core-java-datetime-java8/pom.xml b/core-java-modules/core-java-datetime-java8/pom.xml index 34323fe76c..a15113bddc 100644 --- a/core-java-modules/core-java-datetime-java8/pom.xml +++ b/core-java-modules/core-java-datetime-java8/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-datetime-java8 ${project.parent.version} diff --git a/core-java-modules/core-java-datetime-string/pom.xml b/core-java-modules/core-java-datetime-string/pom.xml index dd793f7fe8..ceb7641320 100644 --- a/core-java-modules/core-java-datetime-string/pom.xml +++ b/core-java-modules/core-java-datetime-string/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-datetime-string ${project.parent.version} diff --git a/core-java-modules/core-java-exceptions-2/pom.xml b/core-java-modules/core-java-exceptions-2/pom.xml index 955d7153fa..cf8de3d5b6 100644 --- a/core-java-modules/core-java-exceptions-2/pom.xml +++ b/core-java-modules/core-java-exceptions-2/pom.xml @@ -1,36 +1,37 @@ - - 4.0.0 + + 4.0.0 - core-java-exceptions-2 - core-java-exceptions-2 - jar + core-java-exceptions-2 + core-java-exceptions-2 + jar - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../../parent-java - - - - - + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + org.assertj assertj-core ${assertj-core.version} test - + - - http://maven.apache.org + + http://maven.apache.org - - UTF-8 - - 3.10.0 - + + UTF-8 + + 3.10.0 + diff --git a/core-java-modules/core-java-exceptions/pom.xml b/core-java-modules/core-java-exceptions/pom.xml index 303a09d5b7..60c5e2650a 100644 --- a/core-java-modules/core-java-exceptions/pom.xml +++ b/core-java-modules/core-java-exceptions/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.exceptions core-java-exceptions diff --git a/core-java-modules/core-java-function/pom.xml b/core-java-modules/core-java-function/pom.xml index 0e61f73c84..1a853d5580 100644 --- a/core-java-modules/core-java-function/pom.xml +++ b/core-java-modules/core-java-function/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-function 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-io-2/pom.xml b/core-java-modules/core-java-io-2/pom.xml index 0c271737d9..ee7d82b610 100644 --- a/core-java-modules/core-java-io-2/pom.xml +++ b/core-java-modules/core-java-io-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-io-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-io-apis/pom.xml b/core-java-modules/core-java-io-apis/pom.xml index 6eb869c537..9628027309 100644 --- a/core-java-modules/core-java-io-apis/pom.xml +++ b/core-java-modules/core-java-io-apis/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-io-apis 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-io-conversions/pom.xml b/core-java-modules/core-java-io-conversions/pom.xml index c3a1b2fe2d..f5ccaa45a3 100644 --- a/core-java-modules/core-java-io-conversions/pom.xml +++ b/core-java-modules/core-java-io-conversions/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-io-conversions 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index 1c568a610d..103a809f90 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-io 0.1.0-SNAPSHOT @@ -73,7 +75,7 @@ -Xmx300m -XX:+UseParallelGC -classpath - + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -127,7 +129,7 @@ java -classpath - + org.openjdk.jmh.Main .* diff --git a/core-java-modules/core-java-jar/pom.xml b/core-java-modules/core-java-jar/pom.xml index d035ee33e2..1d87bcda5f 100644 --- a/core-java-modules/core-java-jar/pom.xml +++ b/core-java-modules/core-java-jar/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-jar 0.1.0-SNAPSHOT @@ -196,7 +198,7 @@ -Xmx300m -XX:+UseParallelGC -classpath - + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -262,7 +264,7 @@ java -classpath - + org.openjdk.jmh.Main .* diff --git a/core-java-modules/core-java-jndi/pom.xml b/core-java-modules/core-java-jndi/pom.xml index 482d07a999..4a491a1a47 100644 --- a/core-java-modules/core-java-jndi/pom.xml +++ b/core-java-modules/core-java-jndi/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.jndi core-java-jndi @@ -72,7 +73,7 @@ - + 5.0.9.RELEASE 1.4.199 diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml index e708502dee..fe6689dcc3 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern1/consumermodule/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 consumermodule 1.0 diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml index 3c03643a2c..fd59c151e6 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern1/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.decoupling-pattern1 decoupling-pattern1 diff --git a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml index 3fe6f735eb..c2da228ce6 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern1/servicemodule/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 servicemodule jar diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml index a042ee4562..e6b351b1b9 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/consumermodule/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.consumermodule consumermodule @@ -34,7 +35,7 @@ - + 1.0 1.0 diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml index f6b4e5b0df..17bca54edb 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.decoupling-pattern2 decoupling-pattern2 @@ -29,7 +30,7 @@ - + 3.8.0 11 diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml index 20e97fca0f..3e8d5c0c39 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/providermodule/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.providermodule providermodule @@ -32,7 +33,7 @@ 1.0 - + \ No newline at end of file diff --git a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml index f65ebb0b55..51d64998df 100644 --- a/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml +++ b/core-java-modules/core-java-jpms/decoupling-pattern2/servicemodule/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 servicemodule 1.0 diff --git a/core-java-modules/core-java-jpms/pom.xml b/core-java-modules/core-java-jpms/pom.xml index dfb3c71229..4610baab49 100644 --- a/core-java-modules/core-java-jpms/pom.xml +++ b/core-java-modules/core-java-jpms/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-jpms 0.0.1-SNAPSHOT diff --git a/core-java-modules/core-java-jvm/pom.xml b/core-java-modules/core-java-jvm/pom.xml index 61c31ce82f..edf7a4f3c5 100644 --- a/core-java-modules/core-java-jvm/pom.xml +++ b/core-java-modules/core-java-jvm/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-jvm 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lambdas/pom.xml b/core-java-modules/core-java-lambdas/pom.xml index fbcd9d5870..421ca2f394 100644 --- a/core-java-modules/core-java-lambdas/pom.xml +++ b/core-java-modules/core-java-lambdas/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-lambdas 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-2/pom.xml b/core-java-modules/core-java-lang-2/pom.xml index a5fb5ca859..5aa80ce3df 100644 --- a/core-java-modules/core-java-lang-2/pom.xml +++ b/core-java-modules/core-java-lang-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-math/pom.xml b/core-java-modules/core-java-lang-math/pom.xml index 671d5630d2..bcb5cf39d2 100644 --- a/core-java-modules/core-java-lang-math/pom.xml +++ b/core-java-modules/core-java-lang-math/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-math 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-oop-2/pom.xml b/core-java-modules/core-java-lang-oop-2/pom.xml index 01bacab0b9..ccacaf7116 100644 --- a/core-java-modules/core-java-lang-oop-2/pom.xml +++ b/core-java-modules/core-java-lang-oop-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-oop-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-oop-3/pom.xml b/core-java-modules/core-java-lang-oop-3/pom.xml index 70939c32c9..cc9b473d03 100644 --- a/core-java-modules/core-java-lang-oop-3/pom.xml +++ b/core-java-modules/core-java-lang-oop-3/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-oop-3 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-oop-4/pom.xml b/core-java-modules/core-java-lang-oop-4/pom.xml index 9e138afddf..3c7e4f446d 100644 --- a/core-java-modules/core-java-lang-oop-4/pom.xml +++ b/core-java-modules/core-java-lang-oop-4/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-oop-4 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-oop/pom.xml b/core-java-modules/core-java-lang-oop/pom.xml index a628a4d6c2..4415784f85 100644 --- a/core-java-modules/core-java-lang-oop/pom.xml +++ b/core-java-modules/core-java-lang-oop/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-oop 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-operators/pom.xml b/core-java-modules/core-java-lang-operators/pom.xml index 03720122cb..b95caa81b8 100644 --- a/core-java-modules/core-java-lang-operators/pom.xml +++ b/core-java-modules/core-java-lang-operators/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-lang-operators 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-syntax-2/pom.xml b/core-java-modules/core-java-lang-syntax-2/pom.xml index 961cf022cb..b6da37b736 100644 --- a/core-java-modules/core-java-lang-syntax-2/pom.xml +++ b/core-java-modules/core-java-lang-syntax-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-syntax-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang-syntax/pom.xml b/core-java-modules/core-java-lang-syntax/pom.xml index c47a1011b7..106074bba6 100644 --- a/core-java-modules/core-java-lang-syntax/pom.xml +++ b/core-java-modules/core-java-lang-syntax/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang-syntax 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-lang/pom.xml b/core-java-modules/core-java-lang/pom.xml index 5b8fe4133b..44d7812c15 100644 --- a/core-java-modules/core-java-lang/pom.xml +++ b/core-java-modules/core-java-lang/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-lang 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-networking-2/pom.xml b/core-java-modules/core-java-networking-2/pom.xml index 2e2eb51809..938635b8d4 100644 --- a/core-java-modules/core-java-networking-2/pom.xml +++ b/core-java-modules/core-java-networking-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-networking-2 core-java-networking-2 diff --git a/core-java-modules/core-java-networking/pom.xml b/core-java-modules/core-java-networking/pom.xml index f5b39625f0..c22b62118d 100644 --- a/core-java-modules/core-java-networking/pom.xml +++ b/core-java-modules/core-java-networking/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-networking 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-nio-2/pom.xml b/core-java-modules/core-java-nio-2/pom.xml index cd5c87d44e..2e67bff30a 100644 --- a/core-java-modules/core-java-nio-2/pom.xml +++ b/core-java-modules/core-java-nio-2/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-nio-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-nio/pom.xml b/core-java-modules/core-java-nio/pom.xml index bc7801c398..e7605763bb 100644 --- a/core-java-modules/core-java-nio/pom.xml +++ b/core-java-modules/core-java-nio/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-nio 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-optional/pom.xml b/core-java-modules/core-java-optional/pom.xml index 9ab41d5a82..57e85109e6 100644 --- a/core-java-modules/core-java-optional/pom.xml +++ b/core-java-modules/core-java-optional/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-optional 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-os/pom.xml b/core-java-modules/core-java-os/pom.xml index b934701067..d8941cb494 100644 --- a/core-java-modules/core-java-os/pom.xml +++ b/core-java-modules/core-java-os/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-os 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-perf/pom.xml b/core-java-modules/core-java-perf/pom.xml index 18e05c9741..c1970346b5 100644 --- a/core-java-modules/core-java-perf/pom.xml +++ b/core-java-modules/core-java-perf/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-perf 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-reflection/pom.xml b/core-java-modules/core-java-reflection/pom.xml index 64086ef5b8..dca446b268 100644 --- a/core-java-modules/core-java-reflection/pom.xml +++ b/core-java-modules/core-java-reflection/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 core-java-reflection 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-regex/pom.xml b/core-java-modules/core-java-regex/pom.xml index 1c55177d70..df2382a732 100644 --- a/core-java-modules/core-java-regex/pom.xml +++ b/core-java-modules/core-java-regex/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-regex 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-security-2/pom.xml b/core-java-modules/core-java-security-2/pom.xml index 43a55e3e0d..23f0c5aab9 100644 --- a/core-java-modules/core-java-security-2/pom.xml +++ b/core-java-modules/core-java-security-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-security-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-security/pom.xml b/core-java-modules/core-java-security/pom.xml index cefbd3a8a7..a46c2e2d40 100644 --- a/core-java-modules/core-java-security/pom.xml +++ b/core-java-modules/core-java-security/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-security 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-streams-2/pom.xml b/core-java-modules/core-java-streams-2/pom.xml index 58f13d658c..1f47df63a0 100644 --- a/core-java-modules/core-java-streams-2/pom.xml +++ b/core-java-modules/core-java-streams-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-streams-2 1.0 diff --git a/core-java-modules/core-java-streams-3/pom.xml b/core-java-modules/core-java-streams-3/pom.xml index 02503d3cab..ae27e28918 100644 --- a/core-java-modules/core-java-streams-3/pom.xml +++ b/core-java-modules/core-java-streams-3/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-streams-3 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-streams/pom.xml b/core-java-modules/core-java-streams/pom.xml index 56fdd523fe..272a2be540 100644 --- a/core-java-modules/core-java-streams/pom.xml +++ b/core-java-modules/core-java-streams/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-streams 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-string-algorithms-2/pom.xml b/core-java-modules/core-java-string-algorithms-2/pom.xml index a67f1df6d2..f05674034a 100644 --- a/core-java-modules/core-java-string-algorithms-2/pom.xml +++ b/core-java-modules/core-java-string-algorithms-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-string-algorithms-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-string-algorithms-3/pom.xml b/core-java-modules/core-java-string-algorithms-3/pom.xml index 43dc040591..583fa99afd 100644 --- a/core-java-modules/core-java-string-algorithms-3/pom.xml +++ b/core-java-modules/core-java-string-algorithms-3/pom.xml @@ -1,50 +1,51 @@ - - 4.0.0 - core-java-string-algorithms-3 - 0.1.0-SNAPSHOT - jar - core-java-string-algorithms-3 + + 4.0.0 + core-java-string-algorithms-3 + 0.1.0-SNAPSHOT + jar + core-java-string-algorithms-3 - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../../parent-java - + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + - - - - org.assertj - assertj-core - ${assertj.version} - test - - - com.google.guava - guava - ${guava.version} - + + + + org.assertj + assertj-core + ${assertj.version} + test + + + com.google.guava + guava + ${guava.version} + - - org.junit.jupiter - junit-jupiter-api - ${junit-jupiter-api.version} - test - - + + org.junit.jupiter + junit-jupiter-api + ${junit-jupiter-api.version} + test + + + + + core-java-string-algorithms-3 + + + src/main/resources + true + + - - core-java-string-algorithms-3 - - - src/main/resources - true - - - org.apache.maven.plugins @@ -57,13 +58,13 @@ - + - - 3.8.1 - 3.6.1 - 28.1-jre - 5.3.1 - + + 3.8.1 + 3.6.1 + 28.1-jre + 5.3.1 + diff --git a/core-java-modules/core-java-string-algorithms/pom.xml b/core-java-modules/core-java-string-algorithms/pom.xml index 6cae320f1d..cb1a25c11b 100644 --- a/core-java-modules/core-java-string-algorithms/pom.xml +++ b/core-java-modules/core-java-string-algorithms/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-string-algorithms 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-string-apis/pom.xml b/core-java-modules/core-java-string-apis/pom.xml index 6d0fd4c6fd..c1cd439386 100644 --- a/core-java-modules/core-java-string-apis/pom.xml +++ b/core-java-modules/core-java-string-apis/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-string-apis 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-string-conversions-2/pom.xml b/core-java-modules/core-java-string-conversions-2/pom.xml index 9f2276b212..53680e4fce 100644 --- a/core-java-modules/core-java-string-conversions-2/pom.xml +++ b/core-java-modules/core-java-string-conversions-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-string-conversions-2 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-string-conversions/pom.xml b/core-java-modules/core-java-string-conversions/pom.xml index 7f8fe6468f..302e73e691 100644 --- a/core-java-modules/core-java-string-conversions/pom.xml +++ b/core-java-modules/core-java-string-conversions/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-string-conversions 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-string-operations-2/pom.xml b/core-java-modules/core-java-string-operations-2/pom.xml index b882e499b2..f36f8b0ff6 100644 --- a/core-java-modules/core-java-string-operations-2/pom.xml +++ b/core-java-modules/core-java-string-operations-2/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 @@ -87,8 +88,7 @@ - + org.openjdk.jmh.Main diff --git a/core-java-modules/core-java-string-operations/pom.xml b/core-java-modules/core-java-string-operations/pom.xml index a1921c029f..a46b8ac129 100644 --- a/core-java-modules/core-java-string-operations/pom.xml +++ b/core-java-modules/core-java-string-operations/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-string-operations 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-strings/pom.xml b/core-java-modules/core-java-strings/pom.xml index 9dfe48527f..9e9bf0748b 100644 --- a/core-java-modules/core-java-strings/pom.xml +++ b/core-java-modules/core-java-strings/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-strings 0.1.0-SNAPSHOT diff --git a/core-java-modules/core-java-sun/pom.xml b/core-java-modules/core-java-sun/pom.xml index 4721eed278..d60ab71db0 100644 --- a/core-java-modules/core-java-sun/pom.xml +++ b/core-java-modules/core-java-sun/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java-sun 0.1.0-SNAPSHOT @@ -51,7 +53,7 @@ -Xmx300m -XX:+UseParallelGC -classpath - + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -81,7 +83,7 @@ java -classpath - + org.openjdk.jmh.Main .* diff --git a/core-java-modules/core-java-time-measurements/pom.xml b/core-java-modules/core-java-time-measurements/pom.xml index 9377b04690..71a012ca2b 100644 --- a/core-java-modules/core-java-time-measurements/pom.xml +++ b/core-java-modules/core-java-time-measurements/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 com.baeldung.exception.numberformat core-java-time-measurements diff --git a/core-java-modules/core-java/pom.xml b/core-java-modules/core-java/pom.xml index 06d0d85b50..9b89fffd40 100644 --- a/core-java-modules/core-java/pom.xml +++ b/core-java-modules/core-java/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-java 0.1.0-SNAPSHOT @@ -101,7 +103,7 @@ -Xmx300m -XX:+UseParallelGC -classpath - + com.baeldung.outofmemoryerror.OutOfMemoryGCLimitExceed @@ -167,7 +169,7 @@ java -classpath - + org.openjdk.jmh.Main .* diff --git a/core-java-modules/multimodulemavenproject/daomodule/pom.xml b/core-java-modules/multimodulemavenproject/daomodule/pom.xml index 79c2628ea4..15f1215d89 100644 --- a/core-java-modules/multimodulemavenproject/daomodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/daomodule/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.daomodule daomodule diff --git a/core-java-modules/multimodulemavenproject/entitymodule/pom.xml b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml index 2cc789ffbb..3e5a478299 100644 --- a/core-java-modules/multimodulemavenproject/entitymodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/entitymodule/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.entitymodule entitymodule diff --git a/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml index e8a8203f33..196e58a419 100644 --- a/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/mainappmodule/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.mainappmodule mainappmodule diff --git a/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml index 8f4cc3d945..f4a7e5c8f8 100644 --- a/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml +++ b/core-java-modules/multimodulemavenproject/userdaomodule/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.userdaomodule userdaomodule diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index da700c383e..326d4bb1c5 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.core-java-modules core-java-modules @@ -52,13 +54,8 @@ core-java-date-operations-2 - - + + core-java-exceptions core-java-exceptions-2 @@ -73,7 +70,7 @@ core-java-jar core-java-jndi - core-java-jvm + core-java-jvm core-java-lambdas core-java-lang @@ -93,7 +90,7 @@ core-java-nio-2 core-java-optional - + core-java-perf diff --git a/core-java-modules/pre-jpms/pom.xml b/core-java-modules/pre-jpms/pom.xml index 9833dc2ff7..18a2566e92 100644 --- a/core-java-modules/pre-jpms/pom.xml +++ b/core-java-modules/pre-jpms/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 pre-jpms 0.0.1-SNAPSHOT @@ -69,7 +70,7 @@ - + 3.1.1 3.8.0 diff --git a/parent-boot-1/pom.xml b/parent-boot-1/pom.xml index df2a7f8400..2e9c767aa2 100644 --- a/parent-boot-1/pom.xml +++ b/parent-boot-1/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 parent-boot-1 0.0.1-SNAPSHOT diff --git a/parent-boot-2/pom.xml b/parent-boot-2/pom.xml index 43911a26ad..6e9e90a6d3 100644 --- a/parent-boot-2/pom.xml +++ b/parent-boot-2/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 parent-boot-2 0.0.1-SNAPSHOT diff --git a/parent-java/pom.xml b/parent-java/pom.xml index e4ec2255c6..4828bc2abb 100644 --- a/parent-java/pom.xml +++ b/parent-java/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 parent-java 0.0.1-SNAPSHOT diff --git a/parent-kotlin/pom.xml b/parent-kotlin/pom.xml index abc871ca91..e3d67eaaf2 100644 --- a/parent-kotlin/pom.xml +++ b/parent-kotlin/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 parent-kotlin parent-kotlin diff --git a/parent-spring-4/pom.xml b/parent-spring-4/pom.xml index 3749c5016e..3f9a22fb03 100644 --- a/parent-spring-4/pom.xml +++ b/parent-spring-4/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 parent-spring-4 0.0.1-SNAPSHOT diff --git a/parent-spring-5/pom.xml b/parent-spring-5/pom.xml index 85a4645aa7..27f355bfad 100644 --- a/parent-spring-5/pom.xml +++ b/parent-spring-5/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 parent-spring-5 0.0.1-SNAPSHOT diff --git a/spring-5-reactive-client/pom.xml b/spring-5-reactive-client/pom.xml index 2981fc4f77..e3c41f8b84 100644 --- a/spring-5-reactive-client/pom.xml +++ b/spring-5-reactive-client/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 spring-5-reactive-client spring-5-reactive-client diff --git a/webrtc/pom.xml b/webrtc/pom.xml index 2a3b48b2ed..6dc98afb1c 100644 --- a/webrtc/pom.xml +++ b/webrtc/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 diff --git a/wicket/pom.xml b/wicket/pom.xml index 5175eca59c..68bc2f3e6b 100644 --- a/wicket/pom.xml +++ b/wicket/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.wicket.examples wicket diff --git a/wildfly/pom.xml b/wildfly/pom.xml index cdffe8b996..7b2a474c8d 100644 --- a/wildfly/pom.xml +++ b/wildfly/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 org.springframework wildfly diff --git a/xml/pom.xml b/xml/pom.xml index eb2d567957..8b2df41af6 100644 --- a/xml/pom.xml +++ b/xml/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 xml 0.1-SNAPSHOT @@ -326,8 +327,7 @@ - + maven-assembly-plugin ${project.basedir} @@ -346,10 +346,8 @@ - make-assembly - package + make-assembly + package attached diff --git a/xstream/pom.xml b/xstream/pom.xml index a703aa3774..618df1a7c2 100644 --- a/xstream/pom.xml +++ b/xstream/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 org.baeldung xstream From fff4be33f081c7ab50f6688f6e64ffef20d06235 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 16:24:26 +0100 Subject: [PATCH 059/278] JAVA-86: spring-boot-failure-analyzer --- .../spring-boot-basic-customization/pom.xml | 6 ++++- .../FailureAnalyzerApplication.java | 14 ++++++++++++ ...yBeanNotOfRequiredTypeFailureAnalyzer.java | 22 +++++++++++++++++++ .../com/baeldung/failureanalyzer/MyDAO.java | 5 +++++ .../baeldung/failureanalyzer/MySecondDAO.java | 8 +++++++ .../baeldung/failureanalyzer/MyService.java | 13 +++++++++++ .../main/resources/META-INF/spring.factories | 2 ++ 7 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyDAO.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyService.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/META-INF/spring.factories diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml index 828ee42b95..ef56623775 100644 --- a/spring-boot-modules/spring-boot-basic-customization/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -16,6 +16,11 @@ + + org.springframework.boot + spring-boot-starter + + org.springframework.boot spring-boot-starter-web @@ -27,5 +32,4 @@ test - diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java new file mode 100644 index 0000000000..d08fa05c6e --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.failureanalyzer; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import javax.annotation.security.RolesAllowed; + +@SpringBootApplication +public class FailureAnalyzerApplication { + @RolesAllowed("*") + public static void main(String[] args) { + SpringApplication.run(FailureAnalyzerApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java new file mode 100644 index 0000000000..3949908083 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java @@ -0,0 +1,22 @@ +package com.baeldung.failureanalyzer; + +import org.springframework.beans.factory.BeanNotOfRequiredTypeException; +import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; +import org.springframework.boot.diagnostics.FailureAnalysis; + +public class MyBeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnalyzer { + + @Override + protected FailureAnalysis analyze(Throwable rootFailure, BeanNotOfRequiredTypeException cause) { + return new FailureAnalysis(getDescription(cause), getAction(cause), cause); + } + + private String getDescription(BeanNotOfRequiredTypeException ex) { + return String.format("The bean %s could not be injected as %s because it is of type %s", ex.getBeanName(), ex.getRequiredType().getName(), ex.getActualType().getName()); + } + + private String getAction(BeanNotOfRequiredTypeException ex) { + return String.format("Consider creating a bean with name %s of type %s", ex.getBeanName(), ex.getRequiredType().getName()); + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyDAO.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyDAO.java new file mode 100644 index 0000000000..ddaeb28574 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyDAO.java @@ -0,0 +1,5 @@ +package com.baeldung.failureanalyzer; + +public class MyDAO { + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java new file mode 100644 index 0000000000..12dd73a05b --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java @@ -0,0 +1,8 @@ +package com.baeldung.failureanalyzer; + +import org.springframework.stereotype.Repository; + +@Repository("myDAO") +public class MySecondDAO { + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyService.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyService.java new file mode 100644 index 0000000000..f31b67615f --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/failureanalyzer/MyService.java @@ -0,0 +1,13 @@ +package com.baeldung.failureanalyzer; + +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +@Service +public class MyService { + + @Resource(name = "myDAO") + private MyDAO myDAO; + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/META-INF/spring.factories b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000000..336477df96 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer + From ab71c5eb09b079f0ede80c0ad0d9b3ed01018223 Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 15 Mar 2020 16:37:38 +0100 Subject: [PATCH 060/278] JAVA-841 Standardize packages in spring-security-mvc-boot --- .../spring-security-mvc-boot-1/pom.xml | 4 ++-- .../baeldung/{ => relationships}/AppConfig.java | 6 +++--- .../{ => relationships}/SpringSecurityConfig.java | 6 +++--- .../{ => relationships}/models/AppUser.java | 2 +- .../baeldung/{ => relationships}/models/Tweet.java | 2 +- .../repositories/TweetRepository.java | 4 ++-- .../repositories/UserRepository.java | 7 ++----- .../security/AppUserPrincipal.java | 4 ++-- .../security/AuthenticationSuccessHandlerImpl.java | 4 ++-- .../security/CustomUserDetailsService.java | 6 +++--- .../{ => relationships}/util/DummyContentUtil.java | 6 +++--- .../baeldung/roles}/custom/Application.java | 4 ++-- .../roles}/custom/config/MethodSecurityConfig.java | 6 +++--- .../baeldung/roles}/custom/config/MvcConfig.java | 2 +- .../roles}/custom/config/SecurityConfig.java | 2 +- .../roles}/custom/persistence/SetupData.java | 14 +++++++------- .../persistence/dao/OrganizationRepository.java | 4 ++-- .../persistence/dao/PrivilegeRepository.java | 4 ++-- .../custom/persistence/dao/UserRepository.java | 4 ++-- .../roles}/custom/persistence/model/Foo.java | 2 +- .../custom/persistence/model/Organization.java | 2 +- .../roles}/custom/persistence/model/Privilege.java | 2 +- .../roles}/custom/persistence/model/User.java | 2 +- .../CustomMethodSecurityExpressionHandler.java | 2 +- .../CustomMethodSecurityExpressionRoot.java | 4 ++-- .../custom/security/CustomPermissionEvaluator.java | 2 +- .../custom/security/MySecurityExpressionRoot.java | 4 ++-- .../custom/security/MyUserDetailsService.java | 6 +++--- .../roles}/custom/security/MyUserPrincipal.java | 6 +++--- .../baeldung/roles}/custom/web/MainController.java | 10 +++++----- .../baeldung/roles}/ip/IpApplication.java | 4 ++-- .../ip/config/CustomIpAuthenticationProvider.java | 2 +- .../baeldung/roles}/ip/config/SecurityConfig.java | 2 +- .../roles}/ip/config/SecurityXmlConfig.java | 2 +- .../baeldung/roles}/ip/web/MainController.java | 4 ++-- .../CustomAuthenticationProvider.java | 6 +++--- .../rolesauthorities/MyLogoutSuccessHandler.java | 2 +- .../rolesauthorities/MyUserDetailsService.java | 8 ++++---- .../RolesAuthoritiesApplication.java | 4 ++-- .../roles}/rolesauthorities/config/MvcConfig.java | 2 +- .../rolesauthorities/config/SecurityConfig.java | 10 +++++----- .../roles}/rolesauthorities/model/Privilege.java | 2 +- .../roles}/rolesauthorities/model/Role.java | 2 +- .../roles}/rolesauthorities/model/User.java | 2 +- .../rolesauthorities/persistence/IUserService.java | 9 +++++++++ .../persistence/PrivilegeRepository.java | 4 ++-- .../persistence/RoleRepository.java | 4 ++-- .../persistence/SetupDataLoader.java | 8 ++++---- .../persistence/UserRepository.java | 4 ++-- .../rolesauthorities/persistence/UserService.java | 4 ++-- .../baeldung/roles}/voter/MinuteBasedVoter.java | 2 +- .../baeldung/roles}/voter/VoterApplication.java | 4 ++-- .../baeldung/roles}/voter/VoterMvcConfig.java | 4 +--- .../baeldung/roles}/voter/WebSecurityConfig.java | 3 +-- .../baeldung/roles}/voter/XmlSecurityConfig.java | 5 +---- .../rolesauthorities/persistence/IUserService.java | 9 --------- .../resources/spring-security-custom-voter.xml | 4 ++-- .../SpringDataWithSecurityIntegrationTest.java | 13 ++++++------- .../baeldung/roles}/SpringContextTest.java | 4 ++-- .../baeldung/roles}/web/ApplicationLiveTest.java | 6 +++--- .../CustomUserDetailsServiceIntegrationTest.java | 8 ++++---- .../baeldung/roles}/web/IpLiveTest.java | 4 ++-- 62 files changed, 137 insertions(+), 147 deletions(-) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/AppConfig.java (92%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/SpringSecurityConfig.java (94%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/models/AppUser.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/models/Tweet.java (96%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{data => relationships}/repositories/TweetRepository.java (84%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{data => relationships}/repositories/UserRepository.java (76%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/security/AppUserPrincipal.java (93%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/security/AuthenticationSuccessHandlerImpl.java (88%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/security/CustomUserDetailsService.java (87%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/{ => relationships}/util/DummyContentUtil.java (95%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/Application.java (88%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/config/MethodSecurityConfig.java (83%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/config/MvcConfig.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/config/SecurityConfig.java (96%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/SetupData.java (83%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/dao/OrganizationRepository.java (63%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/dao/PrivilegeRepository.java (62%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/dao/UserRepository.java (74%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/model/Foo.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/model/Organization.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/model/Privilege.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/persistence/model/User.java (98%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/security/CustomMethodSecurityExpressionHandler.java (96%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/security/CustomMethodSecurityExpressionRoot.java (92%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/security/CustomPermissionEvaluator.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/security/MySecurityExpressionRoot.java (98%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/security/MyUserDetailsService.java (83%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/security/MyUserPrincipal.java (89%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/custom/web/MainController.java (87%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/ip/IpApplication.java (90%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/ip/config/CustomIpAuthenticationProvider.java (98%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/ip/config/SecurityConfig.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/ip/config/SecurityXmlConfig.java (78%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/ip/web/MainController.java (94%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/CustomAuthenticationProvider.java (89%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/MyLogoutSuccessHandler.java (95%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/MyUserDetailsService.java (90%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/RolesAuthoritiesApplication.java (87%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/config/MvcConfig.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/config/SecurityConfig.java (90%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/model/Privilege.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/model/Role.java (97%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/model/User.java (98%) create mode 100644 spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/persistence/PrivilegeRepository.java (65%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/persistence/RoleRepository.java (63%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/persistence/SetupDataLoader.java (93%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/persistence/UserRepository.java (64%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/rolesauthorities/persistence/UserService.java (77%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/voter/MinuteBasedVoter.java (96%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/voter/VoterApplication.java (83%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/voter/VoterMvcConfig.java (71%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/voter/WebSecurityConfig.java (96%) rename spring-security-modules/spring-security-mvc-boot-1/src/main/java/{org/baeldung => com/baeldung/roles}/voter/XmlSecurityConfig.java (60%) delete mode 100644 spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/IUserService.java rename spring-security-modules/spring-security-mvc-boot-1/src/test/java/{org/baeldung => com/baeldung/roles}/SpringContextTest.java (83%) rename spring-security-modules/spring-security-mvc-boot-1/src/test/java/{org/baeldung => com/baeldung/roles}/web/ApplicationLiveTest.java (94%) rename spring-security-modules/spring-security-mvc-boot-1/src/test/java/{org/baeldung => com/baeldung/roles}/web/CustomUserDetailsServiceIntegrationTest.java (95%) rename spring-security-modules/spring-security-mvc-boot-1/src/test/java/{org/baeldung => com/baeldung/roles}/web/IpLiveTest.java (90%) diff --git a/spring-security-modules/spring-security-mvc-boot-1/pom.xml b/spring-security-modules/spring-security-mvc-boot-1/pom.xml index 7dfee200d4..476159f306 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/pom.xml +++ b/spring-security-modules/spring-security-mvc-boot-1/pom.xml @@ -222,10 +222,10 @@ - org.baeldung.custom.Application + com.baeldung.roles.custom.Application - + 1.1.2 1.6.1 diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/AppConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/AppConfig.java similarity index 92% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/AppConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/AppConfig.java index 8719e39a20..ab2cc71fec 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/AppConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/AppConfig.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.relationships; import java.util.Properties; @@ -19,7 +19,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter @SpringBootApplication @PropertySource({"classpath:persistence-h2.properties", "classpath:application-defaults.properties"}) -@EnableJpaRepositories(basePackages = { "com.baeldung.data.repositories" }) +@EnableJpaRepositories(basePackages = {"com.baeldung.relationships.repositories"}) @EnableWebMvc @Import(SpringSecurityConfig.class) public class AppConfig extends WebMvcConfigurerAdapter { @@ -41,7 +41,7 @@ public class AppConfig extends WebMvcConfigurerAdapter { public LocalContainerEntityManagerFactoryBean entityManagerFactory() { final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); em.setDataSource(dataSource()); - em.setPackagesToScan(new String[] { "com.baeldung.models" }); + em.setPackagesToScan(new String[] { "com.baeldung.relationships.models" }); em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); em.setJpaProperties(additionalProperties()); return em; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/SpringSecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java similarity index 94% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/SpringSecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java index ee13678a24..88814038a8 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/SpringSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/SpringSecurityConfig.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.relationships; import javax.annotation.PostConstruct; import javax.sql.DataSource; @@ -18,8 +18,8 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension; import org.springframework.web.context.WebApplicationContext; -import com.baeldung.security.AuthenticationSuccessHandlerImpl; -import com.baeldung.security.CustomUserDetailsService; +import com.baeldung.relationships.security.AuthenticationSuccessHandlerImpl; +import com.baeldung.relationships.security.CustomUserDetailsService; @Configuration @EnableWebSecurity diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/models/AppUser.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/AppUser.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/models/AppUser.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/AppUser.java index e48233f90a..2efd24e879 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/models/AppUser.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/AppUser.java @@ -1,4 +1,4 @@ -package com.baeldung.models; +package com.baeldung.relationships.models; import java.util.Date; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/models/Tweet.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/Tweet.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/models/Tweet.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/Tweet.java index 54a96deaf3..d8496f89be 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/models/Tweet.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/models/Tweet.java @@ -1,4 +1,4 @@ -package com.baeldung.models; +package com.baeldung.relationships.models; import java.util.HashSet; import java.util.Set; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/data/repositories/TweetRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java similarity index 84% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/data/repositories/TweetRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java index 7d6446ed0d..4e4b16a151 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/data/repositories/TweetRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/TweetRepository.java @@ -1,11 +1,11 @@ -package com.baeldung.data.repositories; +package com.baeldung.relationships.repositories; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.PagingAndSortingRepository; -import com.baeldung.models.Tweet; +import com.baeldung.relationships.models.Tweet; public interface TweetRepository extends PagingAndSortingRepository { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/data/repositories/UserRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/UserRepository.java similarity index 76% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/data/repositories/UserRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/UserRepository.java index 5240c683e0..883ea332f8 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/data/repositories/UserRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/repositories/UserRepository.java @@ -1,18 +1,15 @@ -package com.baeldung.data.repositories; +package com.baeldung.relationships.repositories; import java.util.Date; import java.util.List; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Transactional; -import com.baeldung.models.AppUser; +import com.baeldung.relationships.models.AppUser; public interface UserRepository extends CrudRepository { AppUser findByUsername(String username); diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/AppUserPrincipal.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java similarity index 93% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/AppUserPrincipal.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java index 195f9f7bf6..1ae7d95e41 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/AppUserPrincipal.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AppUserPrincipal.java @@ -1,4 +1,4 @@ -package com.baeldung.security; +package com.baeldung.relationships.security; import java.util.Collection; import java.util.Collections; @@ -8,7 +8,7 @@ import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; -import com.baeldung.models.AppUser; +import com.baeldung.relationships.models.AppUser; public class AppUserPrincipal implements UserDetails { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/AuthenticationSuccessHandlerImpl.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java similarity index 88% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/AuthenticationSuccessHandlerImpl.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java index 3fc2bc6559..1b85294467 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/AuthenticationSuccessHandlerImpl.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/AuthenticationSuccessHandlerImpl.java @@ -1,4 +1,4 @@ -package com.baeldung.security; +package com.baeldung.relationships.security; import java.io.IOException; import java.util.Date; @@ -12,7 +12,7 @@ import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.stereotype.Component; -import com.baeldung.data.repositories.UserRepository; +import com.baeldung.relationships.repositories.UserRepository; @Component public class AuthenticationSuccessHandlerImpl implements AuthenticationSuccessHandler { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/CustomUserDetailsService.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java similarity index 87% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/CustomUserDetailsService.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java index 016f4f7fa9..10c266bb74 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/security/CustomUserDetailsService.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/security/CustomUserDetailsService.java @@ -1,4 +1,4 @@ -package com.baeldung.security; +package com.baeldung.relationships.security; import javax.annotation.PostConstruct; @@ -9,8 +9,8 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.stereotype.Service; import org.springframework.web.context.WebApplicationContext; -import com.baeldung.data.repositories.UserRepository; -import com.baeldung.models.AppUser; +import com.baeldung.relationships.repositories.UserRepository; +import com.baeldung.relationships.models.AppUser; @Service public class CustomUserDetailsService implements UserDetailsService { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/util/DummyContentUtil.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/util/DummyContentUtil.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java index f1640264d2..b8e5192b48 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/util/DummyContentUtil.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/relationships/util/DummyContentUtil.java @@ -1,4 +1,4 @@ -package com.baeldung.util; +package com.baeldung.relationships.util; import java.util.ArrayList; import java.util.Collection; @@ -10,8 +10,8 @@ import java.util.stream.IntStream; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import com.baeldung.models.AppUser; -import com.baeldung.models.Tweet; +import com.baeldung.relationships.models.AppUser; +import com.baeldung.relationships.models.Tweet; public class DummyContentUtil { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/Application.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/Application.java similarity index 88% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/Application.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/Application.java index e051e5a853..e7ace1f962 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/Application.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/Application.java @@ -1,4 +1,4 @@ -package org.baeldung.custom; +package com.baeldung.roles.custom; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -7,7 +7,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.PropertySource; @SpringBootApplication -@ComponentScan("org.baeldung.custom") +@ComponentScan("com.baeldung.roles.custom") @PropertySource("classpath:application-defaults.properties") public class Application extends SpringBootServletInitializer { public static void main(String[] args) { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/MethodSecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java similarity index 83% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/MethodSecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java index 6a005153dc..57ab8b120f 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/MethodSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MethodSecurityConfig.java @@ -1,7 +1,7 @@ -package org.baeldung.custom.config; +package com.baeldung.roles.custom.config; -import org.baeldung.custom.security.CustomMethodSecurityExpressionHandler; -import org.baeldung.custom.security.CustomPermissionEvaluator; +import com.baeldung.roles.custom.security.CustomMethodSecurityExpressionHandler; +import com.baeldung.roles.custom.security.CustomPermissionEvaluator; import org.springframework.context.annotation.Configuration; import org.springframework.security.access.expression.method.MethodSecurityExpressionHandler; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/MvcConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/MvcConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java index 58d11ea9ae..c99d1e38a5 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/MvcConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/MvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.config; +package com.baeldung.roles.custom.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/SecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/SecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java index 06357650dc..6bf04120ab 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/config/SecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/config/SecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.config; +package com.baeldung.roles.custom.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/SetupData.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java similarity index 83% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/SetupData.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java index f0fcce3908..ab57e7436c 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/SetupData.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/SetupData.java @@ -1,16 +1,16 @@ -package org.baeldung.custom.persistence; +package com.baeldung.roles.custom.persistence; import java.util.Arrays; import java.util.HashSet; import javax.annotation.PostConstruct; -import org.baeldung.custom.persistence.dao.OrganizationRepository; -import org.baeldung.custom.persistence.dao.PrivilegeRepository; -import org.baeldung.custom.persistence.dao.UserRepository; -import org.baeldung.custom.persistence.model.Organization; -import org.baeldung.custom.persistence.model.Privilege; -import org.baeldung.custom.persistence.model.User; +import com.baeldung.roles.custom.persistence.dao.OrganizationRepository; +import com.baeldung.roles.custom.persistence.dao.PrivilegeRepository; +import com.baeldung.roles.custom.persistence.dao.UserRepository; +import com.baeldung.roles.custom.persistence.model.Organization; +import com.baeldung.roles.custom.persistence.model.Privilege; +import com.baeldung.roles.custom.persistence.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Component; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/OrganizationRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java similarity index 63% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/OrganizationRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java index 1319a7b9f8..2f585f3527 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/OrganizationRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/OrganizationRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.custom.persistence.dao; +package com.baeldung.roles.custom.persistence.dao; -import org.baeldung.custom.persistence.model.Organization; +import com.baeldung.roles.custom.persistence.model.Organization; import org.springframework.data.jpa.repository.JpaRepository; public interface OrganizationRepository extends JpaRepository { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/PrivilegeRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java similarity index 62% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/PrivilegeRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java index c232bb986c..c83e0f505e 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/PrivilegeRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/PrivilegeRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.custom.persistence.dao; +package com.baeldung.roles.custom.persistence.dao; -import org.baeldung.custom.persistence.model.Privilege; +import com.baeldung.roles.custom.persistence.model.Privilege; import org.springframework.data.jpa.repository.JpaRepository; public interface PrivilegeRepository extends JpaRepository { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/UserRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java similarity index 74% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/UserRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java index 68dd1d756c..884a998219 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/dao/UserRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/dao/UserRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.custom.persistence.dao; +package com.baeldung.roles.custom.persistence.dao; -import org.baeldung.custom.persistence.model.User; +import com.baeldung.roles.custom.persistence.model.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.transaction.annotation.Transactional; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Foo.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Foo.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java index f139382eea..3dbf48f7ce 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Foo.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Foo.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.persistence.model; +package com.baeldung.roles.custom.persistence.model; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Organization.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Organization.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java index 1fdb88e320..0d0220b6b2 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Organization.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Organization.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.persistence.model; +package com.baeldung.roles.custom.persistence.model; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Privilege.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Privilege.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java index ed3edd5085..60e0506641 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/Privilege.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/Privilege.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.persistence.model; +package com.baeldung.roles.custom.persistence.model; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/User.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/User.java similarity index 98% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/User.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/User.java index c14ef034b4..219f40a3df 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/persistence/model/User.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/persistence/model/User.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.persistence.model; +package com.baeldung.roles.custom.persistence.model; import java.util.Set; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomMethodSecurityExpressionHandler.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomMethodSecurityExpressionHandler.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java index 646f5a387f..76e94a9dd4 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomMethodSecurityExpressionHandler.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.security; +package com.baeldung.roles.custom.security; import org.aopalliance.intercept.MethodInvocation; import org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomMethodSecurityExpressionRoot.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java similarity index 92% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomMethodSecurityExpressionRoot.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java index b2f2be8cf5..dd9f6a5786 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomMethodSecurityExpressionRoot.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomMethodSecurityExpressionRoot.java @@ -1,6 +1,6 @@ -package org.baeldung.custom.security; +package com.baeldung.roles.custom.security; -import org.baeldung.custom.persistence.model.User; +import com.baeldung.roles.custom.persistence.model.User; import org.springframework.security.access.expression.SecurityExpressionRoot; import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; import org.springframework.security.core.Authentication; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomPermissionEvaluator.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomPermissionEvaluator.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java index f436b4488b..d69e405b28 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/CustomPermissionEvaluator.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/CustomPermissionEvaluator.java @@ -1,4 +1,4 @@ -package org.baeldung.custom.security; +package com.baeldung.roles.custom.security; import java.io.Serializable; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MySecurityExpressionRoot.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java similarity index 98% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MySecurityExpressionRoot.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java index 03d18cb755..8448ad9075 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MySecurityExpressionRoot.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MySecurityExpressionRoot.java @@ -1,11 +1,11 @@ -package org.baeldung.custom.security; +package com.baeldung.roles.custom.security; import java.io.Serializable; import java.util.Collection; import java.util.HashSet; import java.util.Set; -import org.baeldung.custom.persistence.model.User; +import com.baeldung.roles.custom.persistence.model.User; import org.springframework.security.access.PermissionEvaluator; import org.springframework.security.access.expression.method.MethodSecurityExpressionOperations; import org.springframework.security.access.hierarchicalroles.RoleHierarchy; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MyUserDetailsService.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java similarity index 83% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MyUserDetailsService.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java index b9b40fbcb9..c6514d6c05 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MyUserDetailsService.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserDetailsService.java @@ -1,7 +1,7 @@ -package org.baeldung.custom.security; +package com.baeldung.roles.custom.security; -import org.baeldung.custom.persistence.dao.UserRepository; -import org.baeldung.custom.persistence.model.User; +import com.baeldung.roles.custom.persistence.dao.UserRepository; +import com.baeldung.roles.custom.persistence.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MyUserPrincipal.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java similarity index 89% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MyUserPrincipal.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java index 7d57227316..41741c64f4 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/security/MyUserPrincipal.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/security/MyUserPrincipal.java @@ -1,11 +1,11 @@ -package org.baeldung.custom.security; +package com.baeldung.roles.custom.security; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import org.baeldung.custom.persistence.model.Privilege; -import org.baeldung.custom.persistence.model.User; +import com.baeldung.roles.custom.persistence.model.Privilege; +import com.baeldung.roles.custom.persistence.model.User; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/web/MainController.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/web/MainController.java similarity index 87% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/web/MainController.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/web/MainController.java index 74de45d1a8..beb12f7749 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/custom/web/MainController.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/custom/web/MainController.java @@ -1,9 +1,9 @@ -package org.baeldung.custom.web; +package com.baeldung.roles.custom.web; -import org.baeldung.custom.persistence.dao.OrganizationRepository; -import org.baeldung.custom.persistence.model.Foo; -import org.baeldung.custom.persistence.model.Organization; -import org.baeldung.custom.security.MyUserPrincipal; +import com.baeldung.roles.custom.persistence.dao.OrganizationRepository; +import com.baeldung.roles.custom.persistence.model.Foo; +import com.baeldung.roles.custom.persistence.model.Organization; +import com.baeldung.roles.custom.security.MyUserPrincipal; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/IpApplication.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/IpApplication.java similarity index 90% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/IpApplication.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/IpApplication.java index d77414c54e..b9a86fee3e 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/IpApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/IpApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.ip; +package com.baeldung.roles.ip; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -7,7 +7,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.PropertySource; @SpringBootApplication -@ComponentScan("org.baeldung.ip") +@ComponentScan("com.baeldung.ip") @PropertySource("classpath:application-defaults.properties") public class IpApplication extends SpringBootServletInitializer { public static void main(String[] args) { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/CustomIpAuthenticationProvider.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java similarity index 98% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/CustomIpAuthenticationProvider.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java index 078dd81259..adcadb65e8 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/CustomIpAuthenticationProvider.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/CustomIpAuthenticationProvider.java @@ -1,4 +1,4 @@ -package org.baeldung.ip.config; +package com.baeldung.roles.ip.config; import java.util.ArrayList; import java.util.HashSet; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/SecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/SecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java index 3a8032a734..46ba62afb3 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/SecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.ip.config; +package com.baeldung.roles.ip.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/SecurityXmlConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java similarity index 78% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/SecurityXmlConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java index 1d22ca4c67..4b2cf43f6a 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/config/SecurityXmlConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/config/SecurityXmlConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.ip.config; +package com.baeldung.roles.ip.config; //@Configuration diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/web/MainController.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/web/MainController.java similarity index 94% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/web/MainController.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/web/MainController.java index 940194c421..438b668c5f 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/ip/web/MainController.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/ip/web/MainController.java @@ -1,11 +1,11 @@ -package org.baeldung.ip.web; +package com.baeldung.roles.ip.web; import java.util.List; import javax.servlet.Filter; import javax.servlet.http.HttpServletRequest; -import org.baeldung.custom.persistence.model.Foo; +import com.baeldung.roles.custom.persistence.model.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.security.web.FilterChainProxy; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/CustomAuthenticationProvider.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java similarity index 89% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/CustomAuthenticationProvider.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java index d7195ac358..5168e64b4a 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/CustomAuthenticationProvider.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/CustomAuthenticationProvider.java @@ -1,7 +1,7 @@ -package org.baeldung.rolesauthorities; +package com.baeldung.roles.rolesauthorities; -import org.baeldung.rolesauthorities.model.User; -import org.baeldung.rolesauthorities.persistence.UserRepository; +import com.baeldung.roles.rolesauthorities.model.User; +import com.baeldung.roles.rolesauthorities.persistence.UserRepository; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/MyLogoutSuccessHandler.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/MyLogoutSuccessHandler.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java index b0dc0b7537..23104e5292 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/MyLogoutSuccessHandler.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyLogoutSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.rolesauthorities; +package com.baeldung.roles.rolesauthorities; import java.io.IOException; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/MyUserDetailsService.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java similarity index 90% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/MyUserDetailsService.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java index f38b867a75..18230ba794 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/MyUserDetailsService.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/MyUserDetailsService.java @@ -1,13 +1,13 @@ -package org.baeldung.rolesauthorities; +package com.baeldung.roles.rolesauthorities; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; -import org.baeldung.rolesauthorities.model.Role; -import org.baeldung.rolesauthorities.model.User; -import org.baeldung.rolesauthorities.persistence.UserRepository; +import com.baeldung.roles.rolesauthorities.model.Role; +import com.baeldung.roles.rolesauthorities.model.User; +import com.baeldung.roles.rolesauthorities.persistence.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/RolesAuthoritiesApplication.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java similarity index 87% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/RolesAuthoritiesApplication.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java index 3c4e6f7b5a..d3e54b4303 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/RolesAuthoritiesApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/RolesAuthoritiesApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.rolesauthorities; +package com.baeldung.roles.rolesauthorities; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -8,7 +8,7 @@ import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration -@ComponentScan("org.baeldung.rolesauthorities") +@ComponentScan("com.baeldung.rolesauthorities") public class RolesAuthoritiesApplication extends SpringBootServletInitializer { public static void main(String[] args) { System.setProperty("spring.profiles.default", "rolesauthorities"); diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/config/MvcConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/config/MvcConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java index c42958457e..61394b6178 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/config/MvcConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/MvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.rolesauthorities.config; +package com.baeldung.roles.rolesauthorities.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/config/SecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java similarity index 90% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/config/SecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java index 7624dd7d39..cb8476fcc7 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/config/SecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/config/SecurityConfig.java @@ -1,7 +1,7 @@ -package org.baeldung.rolesauthorities.config; +package com.baeldung.roles.rolesauthorities.config; -import org.baeldung.rolesauthorities.CustomAuthenticationProvider; -import org.baeldung.rolesauthorities.persistence.UserRepository; +import com.baeldung.roles.rolesauthorities.CustomAuthenticationProvider; +import com.baeldung.roles.rolesauthorities.persistence.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -18,7 +18,7 @@ import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; @Configuration -@ComponentScan(basePackages = { "org.baeldung.rolesauthorities" }) +@ComponentScan(basePackages = {"com.baeldung.rolesauthorities"}) @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @@ -76,7 +76,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public DaoAuthenticationProvider authProvider() { - final CustomAuthenticationProvider authProvider + final CustomAuthenticationProvider authProvider = new CustomAuthenticationProvider(userRepository, userDetailsService); authProvider.setPasswordEncoder(encoder()); return authProvider; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/Privilege.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/Privilege.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java index ab2cd08610..507beaffa8 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/Privilege.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Privilege.java @@ -1,4 +1,4 @@ -package org.baeldung.rolesauthorities.model; +package com.baeldung.roles.rolesauthorities.model; import java.util.Collection; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/Role.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java similarity index 97% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/Role.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java index ac33e32fcf..a284d92090 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/Role.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/Role.java @@ -1,4 +1,4 @@ -package org.baeldung.rolesauthorities.model; +package com.baeldung.roles.rolesauthorities.model; import java.util.Collection; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/User.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java similarity index 98% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/User.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java index dc1096541d..ebf0c9b310 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/model/User.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/model/User.java @@ -1,4 +1,4 @@ -package org.baeldung.rolesauthorities.model; +package com.baeldung.roles.rolesauthorities.model; import java.util.Collection; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java new file mode 100644 index 0000000000..be9cb911d7 --- /dev/null +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/IUserService.java @@ -0,0 +1,9 @@ +package com.baeldung.roles.rolesauthorities.persistence; + +import com.baeldung.roles.rolesauthorities.model.User; + +public interface IUserService { + + User findUserByEmail(String email); + +} diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/PrivilegeRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java similarity index 65% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/PrivilegeRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java index 05d5f2b870..f8ba7def49 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/PrivilegeRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/PrivilegeRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.rolesauthorities.persistence; +package com.baeldung.roles.rolesauthorities.persistence; -import org.baeldung.rolesauthorities.model.Privilege; +import com.baeldung.roles.rolesauthorities.model.Privilege; import org.springframework.data.jpa.repository.JpaRepository; public interface PrivilegeRepository extends JpaRepository { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/RoleRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java similarity index 63% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/RoleRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java index 25e3b3a1f6..e5833712fe 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/RoleRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/RoleRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.rolesauthorities.persistence; +package com.baeldung.roles.rolesauthorities.persistence; -import org.baeldung.rolesauthorities.model.Role; +import com.baeldung.roles.rolesauthorities.model.Role; import org.springframework.data.jpa.repository.JpaRepository; public interface RoleRepository extends JpaRepository { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/SetupDataLoader.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java similarity index 93% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/SetupDataLoader.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java index 46dad4f06d..140fc56e53 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/SetupDataLoader.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/SetupDataLoader.java @@ -1,13 +1,13 @@ -package org.baeldung.rolesauthorities.persistence; +package com.baeldung.roles.rolesauthorities.persistence; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.baeldung.rolesauthorities.model.Privilege; -import org.baeldung.rolesauthorities.model.Role; -import org.baeldung.rolesauthorities.model.User; +import com.baeldung.roles.rolesauthorities.model.Privilege; +import com.baeldung.roles.rolesauthorities.model.Role; +import com.baeldung.roles.rolesauthorities.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/UserRepository.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java similarity index 64% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/UserRepository.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java index bca2953153..6801eec01d 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/UserRepository.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.rolesauthorities.persistence; +package com.baeldung.roles.rolesauthorities.persistence; -import org.baeldung.rolesauthorities.model.User; +import com.baeldung.roles.rolesauthorities.model.User; import org.springframework.data.jpa.repository.JpaRepository; public interface UserRepository extends JpaRepository { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/UserService.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java similarity index 77% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/UserService.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java index 3b16c78898..17770e5cd0 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/UserService.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/rolesauthorities/persistence/UserService.java @@ -1,8 +1,8 @@ -package org.baeldung.rolesauthorities.persistence; +package com.baeldung.roles.rolesauthorities.persistence; import javax.transaction.Transactional; -import org.baeldung.rolesauthorities.model.User; +import com.baeldung.roles.rolesauthorities.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/MinuteBasedVoter.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/MinuteBasedVoter.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java index 2beda1e557..6970441a4e 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/MinuteBasedVoter.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/MinuteBasedVoter.java @@ -1,4 +1,4 @@ -package org.baeldung.voter; +package com.baeldung.roles.voter; import java.time.LocalDateTime; import java.util.Collection; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/VoterApplication.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterApplication.java similarity index 83% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/VoterApplication.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterApplication.java index d2078e6115..d3e0652ae9 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/VoterApplication.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.voter; +package com.baeldung.roles.voter; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -7,7 +7,7 @@ import org.springframework.context.annotation.Configuration; @Configuration @EnableAutoConfiguration -@ComponentScan(basePackages = { "org.baeldung.voter" }) +@ComponentScan(basePackages = {"com.baeldung.voter"}) public class VoterApplication { public static void main(String[] args) { diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/VoterMvcConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java similarity index 71% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/VoterMvcConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java index 8f41153f06..f11a4ae06c 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/VoterMvcConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/VoterMvcConfig.java @@ -1,10 +1,8 @@ -package org.baeldung.voter; +package com.baeldung.roles.voter; import org.springframework.context.annotation.Configuration; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; /** * Created by ambrusadrianz on 30/09/2016. diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/WebSecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java similarity index 96% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/WebSecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java index 84ed070e8e..8a0f438b49 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/WebSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/WebSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.voter; +package com.baeldung.roles.voter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; @@ -15,7 +15,6 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.access.expression.WebExpressionVoter; -import org.springframework.security.web.util.matcher.AntPathRequestMatcher; import java.util.Arrays; import java.util.List; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/XmlSecurityConfig.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java similarity index 60% rename from spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/XmlSecurityConfig.java rename to spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java index 8041585f42..0ef2ef51c7 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/voter/XmlSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/com/baeldung/roles/voter/XmlSecurityConfig.java @@ -1,7 +1,4 @@ -package org.baeldung.voter; - -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; +package com.baeldung.roles.voter; /** * Created by ambrusadrianz on 09/10/2016. diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/IUserService.java b/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/IUserService.java deleted file mode 100644 index 2c508cbd20..0000000000 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/java/org/baeldung/rolesauthorities/persistence/IUserService.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.baeldung.rolesauthorities.persistence; - -import org.baeldung.rolesauthorities.model.User; - -public interface IUserService { - - User findUserByEmail(String email); - -} diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-custom-voter.xml b/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-custom-voter.xml index 0b334a3694..9f510280a1 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-custom-voter.xml +++ b/spring-security-modules/spring-security-mvc-boot-1/src/main/resources/spring-security-custom-voter.xml @@ -22,12 +22,12 @@ - + - + diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java index b2def82c51..54120650d9 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/relationships/SpringDataWithSecurityIntegrationTest.java @@ -1,12 +1,11 @@ package com.baeldung.relationships; -import com.baeldung.AppConfig; -import com.baeldung.data.repositories.TweetRepository; -import com.baeldung.data.repositories.UserRepository; -import com.baeldung.models.AppUser; -import com.baeldung.models.Tweet; -import com.baeldung.security.AppUserPrincipal; -import com.baeldung.util.DummyContentUtil; +import com.baeldung.relationships.repositories.TweetRepository; +import com.baeldung.relationships.repositories.UserRepository; +import com.baeldung.relationships.models.AppUser; +import com.baeldung.relationships.models.Tweet; +import com.baeldung.relationships.security.AppUserPrincipal; +import com.baeldung.relationships.util.DummyContentUtil; import org.junit.After; import org.junit.Before; import org.junit.Test; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/SpringContextTest.java similarity index 83% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/SpringContextTest.java index 2041249b71..7b23b878c8 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/SpringContextTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package com.baeldung.roles; -import org.baeldung.custom.Application; +import com.baeldung.roles.custom.Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/ApplicationLiveTest.java b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java similarity index 94% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/ApplicationLiveTest.java rename to spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java index e199411e58..5a040b8dea 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/ApplicationLiveTest.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/ApplicationLiveTest.java @@ -1,9 +1,9 @@ -package org.baeldung.web; +package com.baeldung.roles.web; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.baeldung.custom.persistence.model.Foo; +import com.baeldung.roles.custom.persistence.model.Foo; import io.restassured.RestAssured; import io.restassured.authentication.FormAuthConfig; @@ -13,7 +13,7 @@ import io.restassured.specification.RequestSpecification; import org.junit.Test; import org.springframework.http.MediaType; -// In order to execute these tests, org.baeldung.custom.Application needs to be running. +// In order to execute these tests, com.baeldung.custom.Application needs to be running. public class ApplicationLiveTest { @Test diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/CustomUserDetailsServiceIntegrationTest.java b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java similarity index 95% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/CustomUserDetailsServiceIntegrationTest.java rename to spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java index d16acc729a..df7645150f 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/CustomUserDetailsServiceIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/CustomUserDetailsServiceIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung.web; +package com.baeldung.roles.web; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -7,8 +7,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.apache.http.HttpHeaders; -import org.baeldung.custom.Application; -import org.baeldung.custom.persistence.model.Foo; +import com.baeldung.roles.custom.Application; +import com.baeldung.roles.custom.persistence.model.Foo; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; @@ -59,7 +59,7 @@ public class CustomUserDetailsServiceIntegrationTest { @WithAnonymousUser public void givenAnonymous_whenRequestFoo_thenRetrieveUnauthorized() throws Exception { this.mvc.perform(get("/foos/1").with(csrf())) - .andExpect(status().isUnauthorized()); + .andExpect(status().isFound()); } @Test diff --git a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/IpLiveTest.java b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/IpLiveTest.java similarity index 90% rename from spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/IpLiveTest.java rename to spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/IpLiveTest.java index 761f5450f7..2d0e2e5402 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/src/test/java/org/baeldung/web/IpLiveTest.java +++ b/spring-security-modules/spring-security-mvc-boot-1/src/test/java/com/baeldung/roles/web/IpLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.web; +package com.baeldung.roles.web; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -8,7 +8,7 @@ import io.restassured.response.Response; import org.junit.Test; -// In order to execute these tests, org.baeldung.ip.IpApplication needs to be running. +// In order to execute these tests, com.baeldung.ip.IpApplication needs to be running. public class IpLiveTest { @Test From 9a4f4e47dc1a6a282bf676183150e5890cc5591f Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 16:55:18 +0100 Subject: [PATCH 061/278] JAVA-86: spring-boot-custom-error-page --- .../spring-boot-basic-customization/README.md | 3 ++ .../spring-boot-basic-customization/pom.xml | 5 +++ .../ErrorHandlingApplication.java | 15 +++++++ .../controllers/IndexController.java | 26 ++++++++++++ .../controllers/MyErrorController.java | 40 +++++++++++++++++++ .../application-errorhandling.properties | 10 +++++ .../main/resources/templates/error-404.html | 7 ++++ .../main/resources/templates/error-500.html | 9 +++++ .../src/main/resources/templates/error.html | 8 ++++ .../main/resources/templates/error/404.html | 8 ++++ .../src/main/resources/templates/index.html | 6 +++ 11 files changed, 137 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-404.html create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-500.html create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error.html create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error/404.html create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/index.html diff --git a/spring-boot-modules/spring-boot-basic-customization/README.md b/spring-boot-modules/spring-boot-basic-customization/README.md index 1a899fd13a..98d1402631 100644 --- a/spring-boot-modules/spring-boot-basic-customization/README.md +++ b/spring-boot-modules/spring-boot-basic-customization/README.md @@ -6,3 +6,6 @@ This module contains articles about Spring Boot customization - [How to Change the Default Port in Spring Boot](https://www.baeldung.com/spring-boot-change-port) - [Using Custom Banners in Spring Boot](https://www.baeldung.com/spring-boot-custom-banners) + - [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer) + - [Spring Boot: Customize Whitelabel Error Page](https://www.baeldung.com/spring-boot-custom-error-page) + diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml index ef56623775..4a45c548dd 100644 --- a/spring-boot-modules/spring-boot-basic-customization/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -26,6 +26,11 @@ spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-thymeleaf + + org.springframework.boot spring-boot-starter-test diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java new file mode 100644 index 0000000000..5dd55ef077 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java @@ -0,0 +1,15 @@ +package com.baeldung.errorhandling; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(basePackages = "com.baeldung.errorhandling") +public class ErrorHandlingApplication { + + public static void main(String [] args) { + System.setProperty("spring.profiles.active", "errorhandling"); + SpringApplication.run(ErrorHandlingApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java new file mode 100644 index 0000000000..1a8761e96b --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java @@ -0,0 +1,26 @@ +package com.baeldung.errorhandling.controllers; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; + +@Controller +public class IndexController { + + @GetMapping(value = {"/", ""}) + public String index() { + return "index"; + } + + @GetMapping(value = {"/server_error"}) + public String triggerServerError() { + "ser".charAt(30); + return "index"; + } + + @PostMapping(value = {"/general_error"}) + public String triggerGeneralError() { + return "index"; + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java new file mode 100644 index 0000000000..e002ac045d --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java @@ -0,0 +1,40 @@ +package com.baeldung.errorhandling.controllers; + +import org.springframework.boot.web.servlet.error.ErrorController; +import org.springframework.http.HttpStatus; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +import javax.servlet.RequestDispatcher; +import javax.servlet.http.HttpServletRequest; + +@Controller +public class MyErrorController implements ErrorController { + + public MyErrorController() {} + + @GetMapping(value = "/error") + public String handleError(HttpServletRequest request) { + + Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + + if (status != null) { + + Integer statusCode = Integer.valueOf(status.toString()); + + if(statusCode == HttpStatus.NOT_FOUND.value()) { + return "error-404"; + } + else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) { + return "error-500"; + } + } + return "error"; + } + + @Override + public String getErrorPath() { + return "/error"; + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties new file mode 100644 index 0000000000..fba5c21cd4 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties @@ -0,0 +1,10 @@ +#server +server.port=9000 +server.servlet-path=/ +server.context-path=/ +server.error.whitelabel.enabled=false + +#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration + +#for Spring Boot 2.0+ +#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-404.html b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-404.html new file mode 100644 index 0000000000..555cf52de4 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-404.html @@ -0,0 +1,7 @@ + + + +

Sorry, we couldn't find the page you were looking for.

+

Go Home

+ + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-500.html b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-500.html new file mode 100644 index 0000000000..fc64c7e180 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error-500.html @@ -0,0 +1,9 @@ + + + +

Sorry, something went wrong!

+ +

We're fixing it.

+

Go Home

+ + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error.html b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error.html new file mode 100644 index 0000000000..4e953059e2 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error.html @@ -0,0 +1,8 @@ + + + +

Something went wrong!

+

Our Engineers are on it.

+

Go Home

+ + diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error/404.html b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error/404.html new file mode 100644 index 0000000000..df83ce219b --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/error/404.html @@ -0,0 +1,8 @@ + + + RESOURCE NOT FOUND + + +

404 RESOURCE NOT FOUND

+ + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/index.html b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/index.html new file mode 100644 index 0000000000..95c68c8600 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/templates/index.html @@ -0,0 +1,6 @@ + + +

Welcome Home

+

Success! It is working as we expected.

+ + From e2b2efa72dd36091e8b238923b9571f496dd739e Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 20:10:28 +0100 Subject: [PATCH 062/278] JAVA-86: Refactor spring-boot-custom-error-page --- .../com/baeldung/errorhandling/ErrorHandlingApplication.java | 4 +--- .../src/main/resources/application-errorhandling.properties | 4 ++-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java index 5dd55ef077..9f6c209deb 100644 --- a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java @@ -2,10 +2,8 @@ package com.baeldung.errorhandling; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; -@SpringBootApplication -@ComponentScan(basePackages = "com.baeldung.errorhandling") +@SpringBootApplication(scanBasePackages = "com.baeldung.errorhandling") public class ErrorHandlingApplication { public static void main(String [] args) { diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties index fba5c21cd4..0a6d68763c 100644 --- a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application-errorhandling.properties @@ -1,7 +1,7 @@ #server server.port=9000 -server.servlet-path=/ -server.context-path=/ +spring.mvc.servlet.path=/ +server.servlet.context-path=/ server.error.whitelabel.enabled=false #spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration From c79e927ddde6f50f91424e64beb57fe3f1aae4bd Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 20:19:33 +0100 Subject: [PATCH 063/278] JAVA-86: Add tests for spring-boot-failure-analyzer --- .../FailureAnalyzerAppIntegrationTest.java | 45 +++++++++++++++++++ .../failureanalyzer/utils/ListAppender.java | 25 +++++++++++ .../src/test/resources/logback-test.xml | 15 +++++++ 3 files changed, 85 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/test/resources/logback-test.xml diff --git a/spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java b/spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java new file mode 100644 index 0000000000..2d9fb56217 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java @@ -0,0 +1,45 @@ +package com.baeldung.failureanalyzer; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import com.baeldung.failureanalyzer.utils.ListAppender; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.BeanCreationException; +import org.springframework.boot.SpringApplication; + +import java.util.Collection; +import java.util.stream.Collectors; + +import static org.assertj.core.api.Assertions.assertThat; + +public class FailureAnalyzerAppIntegrationTest { + + private static final String EXPECTED_ANALYSIS_DESCRIPTION_TITLE = "Description:"; + private static final String EXPECTED_ANALYSIS_DESCRIPTION_CONTENT = "The bean myDAO could not be injected as com.baeldung.failureanalyzer.MyDAO because it is of type com.baeldung.failureanalyzer.MySecondDAO"; + private static final String EXPECTED_ANALYSIS_ACTION_TITLE = "Action:"; + private static final String EXPECTED_ANALYSIS_ACTION_CONTENT = "Consider creating a bean with name myDAO of type com.baeldung.failureanalyzer.MyDAO"; + + @BeforeEach + public void clearLogList() { + ListAppender.clearEventList(); + } + + @Test + public void givenBeanCreationErrorInContext_whenContextLoaded_thenFailureAnalyzerLogsReport() { + try { + SpringApplication.run(FailureAnalyzerApplication.class); + } catch (BeanCreationException e) { + Collection allLoggedEntries = ListAppender.getEvents() + .stream() + .map(ILoggingEvent::getFormattedMessage) + .collect(Collectors.toList()); + assertThat(allLoggedEntries).anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_TITLE)) + .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_CONTENT)) + .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_TITLE)) + .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_CONTENT)); + return; + } + throw new IllegalStateException("Context load should be failing due to a BeanCreationException!"); + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java b/spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java new file mode 100644 index 0000000000..091cd687f1 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java @@ -0,0 +1,25 @@ +package com.baeldung.failureanalyzer.utils; + +import ch.qos.logback.classic.spi.ILoggingEvent; +import ch.qos.logback.core.AppenderBase; + +import java.util.ArrayList; +import java.util.List; + +public class ListAppender extends AppenderBase { + + static private List events = new ArrayList<>(); + + @Override + protected void append(ILoggingEvent eventObject) { + events.add(eventObject); + } + + public static List getEvents() { + return events; + } + + public static void clearEventList() { + events.clear(); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-basic-customization/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot-basic-customization/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..6919a457cb --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/test/resources/logback-test.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + \ No newline at end of file From 7b7f988f88175e7d7bc657fce32c6406a9d08664 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 20:30:42 +0100 Subject: [PATCH 064/278] JAVA-86: spring-boot-main-class --- .../spring-boot-basic-customization/README.md | 2 +- spring-boot-modules/spring-boot-basic-customization/pom.xml | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-basic-customization/README.md b/spring-boot-modules/spring-boot-basic-customization/README.md index 98d1402631..1bfe539a36 100644 --- a/spring-boot-modules/spring-boot-basic-customization/README.md +++ b/spring-boot-modules/spring-boot-basic-customization/README.md @@ -8,4 +8,4 @@ This module contains articles about Spring Boot customization - [Using Custom Banners in Spring Boot](https://www.baeldung.com/spring-boot-custom-banners) - [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer) - [Spring Boot: Customize Whitelabel Error Page](https://www.baeldung.com/spring-boot-custom-error-page) - + - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) diff --git a/spring-boot-modules/spring-boot-basic-customization/pom.xml b/spring-boot-modules/spring-boot-basic-customization/pom.xml index 4a45c548dd..7c2c89def4 100644 --- a/spring-boot-modules/spring-boot-basic-customization/pom.xml +++ b/spring-boot-modules/spring-boot-basic-customization/pom.xml @@ -37,4 +37,9 @@ test
+ + + + com.baeldung.changeport.CustomApplication + From b19dbb9c20f19f318cf0f71bbb147434afd40158 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 20:36:28 +0100 Subject: [PATCH 065/278] JAVA-86: spring-boot-add-filter --- .../spring-boot-basic-customization/README.md | 1 + .../bootcustomfilters/FilterConfig.java | 23 ++++++++++ .../SpringBootFiltersApplication.java | 17 +++++++ .../controller/UserController.java | 34 ++++++++++++++ .../filters/RequestResponseLoggingFilter.java | 44 ++++++++++++++++++ .../filters/TransactionFilter.java | 41 +++++++++++++++++ .../bootcustomfilters/model/User.java | 45 +++++++++++++++++++ 7 files changed, 205 insertions(+) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/model/User.java diff --git a/spring-boot-modules/spring-boot-basic-customization/README.md b/spring-boot-modules/spring-boot-basic-customization/README.md index 1bfe539a36..ce4e29001c 100644 --- a/spring-boot-modules/spring-boot-basic-customization/README.md +++ b/spring-boot-modules/spring-boot-basic-customization/README.md @@ -9,3 +9,4 @@ This module contains articles about Spring Boot customization - [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer) - [Spring Boot: Customize Whitelabel Error Page](https://www.baeldung.com/spring-boot-custom-error-page) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) + - [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter) diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java new file mode 100644 index 0000000000..42da61fe14 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java @@ -0,0 +1,23 @@ +package com.baeldung.bootcustomfilters; + +import com.baeldung.bootcustomfilters.filters.RequestResponseLoggingFilter; +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class FilterConfig { + + // uncomment this and comment the @Component in the filter class definition to register only for a url pattern + // @Bean + public FilterRegistrationBean loggingFilter() { + FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); + + registrationBean.setFilter(new RequestResponseLoggingFilter()); + + registrationBean.addUrlPatterns("/users/*"); + + return registrationBean; + + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java new file mode 100644 index 0000000000..c4653932c0 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java @@ -0,0 +1,17 @@ +package com.baeldung.bootcustomfilters; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + * Boot application + * @author hemant + * + */ +@SpringBootApplication +public class SpringBootFiltersApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootFiltersApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java new file mode 100644 index 0000000000..50d5f4ea71 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java @@ -0,0 +1,34 @@ +package com.baeldung.bootcustomfilters.controller; + +import com.baeldung.bootcustomfilters.model.User; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.List; +import java.util.UUID; + +/** + * Rest controller for User + * @author hemant + * + */ +@RestController +@RequestMapping("/users") +public class UserController { + + private static final Logger LOG = LoggerFactory.getLogger(UserController.class); + + @GetMapping("") + public List getAllUsers() { + LOG.info("Fetching all the users"); + return Arrays.asList( + new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), + new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), + new User(UUID.randomUUID().toString(), "User1", "user1@test.com")); + } + +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java new file mode 100644 index 0000000000..3924354932 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java @@ -0,0 +1,44 @@ +package com.baeldung.bootcustomfilters.filters; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +/** + * A servlet filter to log request and response + * The logging implementation is pretty native and for demonstration only + * @author hemant + * + */ +@Component +@Order(2) +public class RequestResponseLoggingFilter implements Filter { + + private final static Logger LOG = LoggerFactory.getLogger(RequestResponseLoggingFilter.class); + + @Override + public void init(final FilterConfig filterConfig) throws ServletException { + LOG.info("Initializing filter :{}", this); + } + + @Override + public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) + throws IOException, ServletException { + HttpServletRequest req = (HttpServletRequest) request; + HttpServletResponse res = (HttpServletResponse) response; + LOG.info("Logging Request {} : {}", req.getMethod(), req.getRequestURI()); + chain.doFilter(request, response); + LOG.info("Logging Response :{}", res.getContentType()); + } + + @Override + public void destroy() { + LOG.warn("Destructing filter :{}", this); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java new file mode 100644 index 0000000000..604829c3d3 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java @@ -0,0 +1,41 @@ +package com.baeldung.bootcustomfilters.filters; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +import javax.servlet.*; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * A filter to create transaction before and commit it once request completes + * The current implemenatation is just for demo + * @author hemant + * + */ +@Component +@Order(1) +public class TransactionFilter implements Filter { + + private final static Logger LOG = LoggerFactory.getLogger(TransactionFilter.class); + + @Override + public void init(final FilterConfig filterConfig) throws ServletException { + LOG.info("Initializing filter :{}", this); + } + + @Override + public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { + HttpServletRequest req = (HttpServletRequest) request; + LOG.info("Starting Transaction for req :{}", req.getRequestURI()); + chain.doFilter(request, response); + LOG.info("Committing Transaction for req :{}", req.getRequestURI()); + } + + @Override + public void destroy() { + LOG.warn("Destructing filter :{}", this); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/model/User.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/model/User.java new file mode 100644 index 0000000000..ab8e6c8206 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/bootcustomfilters/model/User.java @@ -0,0 +1,45 @@ +package com.baeldung.bootcustomfilters.model; + +/** + * User model + * @author hemant + * + */ +public class User { + + private String id; + private String name; + private String email; + + public User(String id, String name, String email) { + super(); + this.id = id; + this.name = name; + this.email = email; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + +} From 5c83dddb9182c0d74ba3685d6f5c7f09f7417681 Mon Sep 17 00:00:00 2001 From: Roger Yates <587230+rojyates@users.noreply.github.com> Date: Mon, 16 Mar 2020 06:23:33 +1000 Subject: [PATCH 066/278] BAEL-3603 Update method names and variable name for PR --- .../blockingnonblocking/BlockingClientUnitTest.java | 2 +- .../NonBlockingClientUnitTest.java | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java index 3fc968ded0..cd3d688763 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/BlockingClientUnitTest.java @@ -25,7 +25,7 @@ public class BlockingClientUnitTest { } @Test - public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenReadSuccessfully() throws IOException { + public void givenJavaIOSocket_whenReadingAndWritingWithStreams_thenSuccess() throws IOException { // given an IO socket and somewhere to store our result Socket socket = new Socket("localhost", wireMockRule.port()); StringBuilder ourStore = new StringBuilder(); diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java index 47115887ab..90edee0306 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java @@ -31,7 +31,7 @@ public class NonBlockingClientUnitTest { } @Test - public void givenJavaNIOSocketChannel_whenReadingAndWriting_thenUseBuffers() throws IOException { + public void givenJavaNIOSocketChannel_whenReadingAndWritingWithBuffers_thenSuccess() throws IOException { // given a NIO SocketChannel and a charset InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); SocketChannel socketChannel = SocketChannel.open(address); @@ -58,25 +58,25 @@ public class NonBlockingClientUnitTest { } @Test - public void givenJavaNIO_whenReadingAndWriting_thenSmallBuffers() throws IOException { + public void givenJavaNIOSocketChannel_whenReadingAndWritingWithSmallBuffers_thenSuccess() throws IOException { // given a NIO SocketChannel and a charset InetSocketAddress address = new InetSocketAddress("localhost", wireMockRule.port()); - SocketChannel socket = SocketChannel.open(address); + SocketChannel socketChannel = SocketChannel.open(address); Charset charset = StandardCharsets.UTF_8; // when we write and read using buffers that are too small for our message - socket.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); + socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access CharBuffer charBuffer = CharBuffer.allocate(8); CharsetDecoder decoder = charset.newDecoder(); StringBuilder ourStore = new StringBuilder(); - while (socket.read(buffer) != -1 || buffer.position() > 0) { + while (socketChannel.read(buffer) != -1 || buffer.position() > 0) { buffer.flip(); storeBufferContents(buffer, charBuffer, decoder, ourStore); buffer.compact(); } - socket.close(); + socketChannel.close(); // then we read and saved our data assertTrue(ourStore From e8eba5fe3d2c121cabd771c81419e9b8944d32e6 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Mar 2020 21:46:59 +0100 Subject: [PATCH 067/278] JAVA-86: spring-boot-favicon --- .../spring-boot-basic-customization/README.md | 1 + .../baeldung/favicon/FaviconApplication.java | 12 +++++ .../favicon/config/FaviconConfiguration.java | 45 ++++++++++++++++++ .../src/main/resources/application.properties | 2 +- .../resources/com/baeldung/images/favicon.ico | Bin 0 -> 15086 bytes .../src/main/resources/favicon.ico | Bin 0 -> 15086 bytes .../src/main/resources/static/favicon.ico | Bin 0 -> 15086 bytes 7 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/FaviconApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/config/FaviconConfiguration.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/com/baeldung/images/favicon.ico create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/favicon.ico create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/resources/static/favicon.ico diff --git a/spring-boot-modules/spring-boot-basic-customization/README.md b/spring-boot-modules/spring-boot-basic-customization/README.md index ce4e29001c..a3d9f1b1fc 100644 --- a/spring-boot-modules/spring-boot-basic-customization/README.md +++ b/spring-boot-modules/spring-boot-basic-customization/README.md @@ -10,3 +10,4 @@ This module contains articles about Spring Boot customization - [Spring Boot: Customize Whitelabel Error Page](https://www.baeldung.com/spring-boot-custom-error-page) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) - [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter) + - [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon) diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/FaviconApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/FaviconApplication.java new file mode 100644 index 0000000000..f94549b988 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/FaviconApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.favicon; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class FaviconApplication { + + public static void main(String[] args) { + SpringApplication.run(FaviconApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/config/FaviconConfiguration.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/config/FaviconConfiguration.java new file mode 100644 index 0000000000..d1809199d6 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/favicon/config/FaviconConfiguration.java @@ -0,0 +1,45 @@ +package com.baeldung.favicon.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; +import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +@Configuration +public class FaviconConfiguration { + + @Bean + public SimpleUrlHandlerMapping myFaviconHandlerMapping() { + SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); + mapping.setOrder(Integer.MIN_VALUE); + mapping.setUrlMap(Collections.singletonMap("/favicon.ico", faviconRequestHandler())); + return mapping; + } + + @Bean + protected ResourceHttpRequestHandler faviconRequestHandler() { + ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler(); + ClassPathResource classPathResource = new ClassPathResource("com/baeldung/images"); + List locations = Arrays.asList(classPathResource); + requestHandler.setLocations(locations); + return requestHandler; + } + + // @Controller + static class FaviconController { + + @RequestMapping(value = "favicon.ico", method = RequestMethod.GET) + @ResponseBody + void favicon() { + } + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties index 2063d36b46..4d4a6ec7bd 100644 --- a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/application.properties @@ -4,4 +4,4 @@ #spring.banner.image.width= //TODO #spring.banner.image.height= //TODO #spring.banner.image.margin= //TODO -#spring.banner.image.invert= //TODO \ No newline at end of file +#spring.banner.image.invert= //TODO diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/com/baeldung/images/favicon.ico b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/com/baeldung/images/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..64105ac11c6186e380a724416ceb77ab5c263fef GIT binary patch literal 15086 zcmeI33yf6N8OP5s)D;AFL7}u+*#$K|S}oXWX{A6BF!-qLwvyDOsBLZ4#$rp2QmZaB zDMc+H+EzuWwblBlHY$b~O&EM6N;Jr;Vo@0)La}NWK^bJ(>Fs!o&?#+$PV&lcoe<}Q{V*nJA~=Gv^RNwrqwUlyiXv{0{QS2SOqSBm|V^K zQLxvS?=`|#!l^JBRzeqq>8p;)yEgECA92~92j{^Ocmu-PBuDxspmqtCp>qEVFM;g6 z3&A`)Nb3(OYfs4gVE$lypKZf~(VYR$L6|Q=Js00EefOZN@uR+-2@ByKP=BkBcZ1V& za;MV`ljQFM^6k?gyLZAaaQZKV=~YTY?;z0l>;SdzoJx5srK6LD`LGc*O%p%p9R+QP z6|Dlgn&*8KEf$U0H~|`r8OzLXW>yUXO|EuJ9@z;+0>uLCE$K;D6=;Qtp!LanwD8pF zL%lx*!{PIA@PT%dGLMJnL2J+?m5&?%=R+Heh0&mOOj7IG$)NNv!-;S-s1E&-`j3w4 ze*;$_%n#DP4jaI&`|AJo@DvQQK3qds^Eye{{=D+zeqa~w{*b0M zR(W3qW}MgW;|R}%kv6VAT?u}hX~JrYFZewm{*2G=D}>$H)B1k}oNImf8sV*wrd+?y z)7Ti{d?5T*z~&a>=YZD3X`uXPTOYnp*uPHu?IsD|j2-XPgVeqn)YVx26$}E6htuI$ z=m)c54+M3R#I@(TzV57GOMWc_&GAFvV)zbdzFY;nAxW9RytksSIj1=teCLnv;Qe)= zb~qBILNjQ;t7bg>3;iR&KmPpX2E$qd7QkdsUwjrOfz}JnuVDV3;_5@4Pt~85`XJ1P z#>Nw%K9~Y(mmfe5lJ?1BbkwHnA*`&ZG_6NkC)dDVKz($ljemfQ(sl1v*mvbDZk2$~y7?4-@x zRW95YplprFUxW6=G;=GiKOg#v?G~im3}}vj6Lbc79A1XE;C)CkXDj*hPPalMB9y1k z3)+Wu9+?PQi?t@tf!jfA!mAK>?#ZVO5kX$cp1^G4tk~}hZLk@FK5QjzOk$%c6ewpJYzz2sH}Qi~m`kNXS(kuY zm$grwk;+g?CCbwo<{?l&`~&)@G?iM7GS39v#f(dBqzXmK)%tNZB)&_lqS&%3^N>f>U?kt99_50 zhB$`5I&0nnn?UCU-Dj5f0>T4eGH4GS47y*`p6bnANsH35pnXpFH$q{h_3Avw{!hT| zCpweq>j&>4EIgEVC&504U$@;BuG_UxHy!leH5& z{a^{WbHN||wh5mKJALn6zBE#29i4;Lf!bgOe8#m`T#3#QIMn4QJOZ8t`Sc$c?|Y~7 zpxQT$zdh;f!|qy`1;bsLJxTKZ4AkZWTwcPbz!p%MkH8?`yNSemx}WID*QodUytxYW z8N<8pbY%x6?;BwS=uABq{PXp@#MQs*=UGmdu;$`oi1MKp?=((-0~K%BdG}S&7*Top z{G`5fcVJpCE`{e|K9uiD36Fv`Pzyh!Y^d$DE_ipYt___eUF(4Ve&9XgKLu9@tvLfh zYp2dx{yMY~?|`WCYw=EFLv{FAKal3mzW#DlhhG5SvXmaer-RyC>)&9dBGo?{b7~{M zes6@;#u`gryIQy8gFbtQm8bn{9(eN>sde>g*abI%H`kHc^X`Q(8?{c;eDLm!ef~%F zzt*$ALW^y0?Y9?!>ii?0jTYi7q1OI}+0(jSo(qKKV^}_an&z+etv;YJqy0f=h;iV3 z4};Wwy5C+>czgc^UvL=@^ogn2KcptH};1TUIh2RaW-u_TjMp&81nn?!d=+XJYNo1z!Vq>{a`FCfo-6C zPA9GW5E~bO*2G0Muovcs_VIP_H<$&Q_c{|UhL=F|sG7Pguyf#e>}-ZGA8MJlmonaj z7eVXTde{wV%Xm!w>%qpQAp2=;rPZsZ{nwVf_x#tor+HS5y|i^mtGCVhZ~H*&#oeEv zI_&oQZ|iU<{{J4_9Yor;IS_i?zUOmw!FR29I%jT%1K~&7GD5#6wEd95cdbje!@G4_ zk8ZywbnWk#_^mVlIJgDWAJy*FY1=wX?*qTDQDOYnxqlSQfTge+-iA1zAHvG6McTik ze6I8kpS5QX0iAW);BvSb9s-?%Ho#WU`A+LVZ>`DeEBTlv9Y6bm&eFQiJOWOHsqj7c zCFuOK0=7Uc_R3{x{7kEZ&sr1u!${CsNavu9kakYZPwPu9^zd8tIUIC`UjzFg?!3@v zqv^HqqZT&sr5Wae&fjtBpfmr+ez#Z)U((vZAFT`e%%HyLsSY}mN8atG^`lxn{5k^ef&EKUa3$A^-tpOIeN?2N_O$_+t3kGhpQ{;)KfZsYtO$v;QuD# zbv19J+6-S?V4bal_VL+K`Rnl=KI<++>ygeTvA-9qm%8Ay?vVZo-ko8+_!ZX={BDA2 z(Cxd6xcc>w58r$Bd;5B*<0sLF(hr98+af(5$qpMYbeOEt3s)M`g6u>#AYbQ~W*Ou{ z{o?Fec zlG%Jonz7_IIsM_udw)NY9X5_N?{OdO<&K_W&J*7Mb9r%_KsEEFc+pc)wR4m&nYXfF dWheeBz01lX^-;Vm7uxu0D>qw-6JEX$`9Ha#9tHpa literal 0 HcmV?d00001 diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/favicon.ico b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..64105ac11c6186e380a724416ceb77ab5c263fef GIT binary patch literal 15086 zcmeI33yf6N8OP5s)D;AFL7}u+*#$K|S}oXWX{A6BF!-qLwvyDOsBLZ4#$rp2QmZaB zDMc+H+EzuWwblBlHY$b~O&EM6N;Jr;Vo@0)La}NWK^bJ(>Fs!o&?#+$PV&lcoe<}Q{V*nJA~=Gv^RNwrqwUlyiXv{0{QS2SOqSBm|V^K zQLxvS?=`|#!l^JBRzeqq>8p;)yEgECA92~92j{^Ocmu-PBuDxspmqtCp>qEVFM;g6 z3&A`)Nb3(OYfs4gVE$lypKZf~(VYR$L6|Q=Js00EefOZN@uR+-2@ByKP=BkBcZ1V& za;MV`ljQFM^6k?gyLZAaaQZKV=~YTY?;z0l>;SdzoJx5srK6LD`LGc*O%p%p9R+QP z6|Dlgn&*8KEf$U0H~|`r8OzLXW>yUXO|EuJ9@z;+0>uLCE$K;D6=;Qtp!LanwD8pF zL%lx*!{PIA@PT%dGLMJnL2J+?m5&?%=R+Heh0&mOOj7IG$)NNv!-;S-s1E&-`j3w4 ze*;$_%n#DP4jaI&`|AJo@DvQQK3qds^Eye{{=D+zeqa~w{*b0M zR(W3qW}MgW;|R}%kv6VAT?u}hX~JrYFZewm{*2G=D}>$H)B1k}oNImf8sV*wrd+?y z)7Ti{d?5T*z~&a>=YZD3X`uXPTOYnp*uPHu?IsD|j2-XPgVeqn)YVx26$}E6htuI$ z=m)c54+M3R#I@(TzV57GOMWc_&GAFvV)zbdzFY;nAxW9RytksSIj1=teCLnv;Qe)= zb~qBILNjQ;t7bg>3;iR&KmPpX2E$qd7QkdsUwjrOfz}JnuVDV3;_5@4Pt~85`XJ1P z#>Nw%K9~Y(mmfe5lJ?1BbkwHnA*`&ZG_6NkC)dDVKz($ljemfQ(sl1v*mvbDZk2$~y7?4-@x zRW95YplprFUxW6=G;=GiKOg#v?G~im3}}vj6Lbc79A1XE;C)CkXDj*hPPalMB9y1k z3)+Wu9+?PQi?t@tf!jfA!mAK>?#ZVO5kX$cp1^G4tk~}hZLk@FK5QjzOk$%c6ewpJYzz2sH}Qi~m`kNXS(kuY zm$grwk;+g?CCbwo<{?l&`~&)@G?iM7GS39v#f(dBqzXmK)%tNZB)&_lqS&%3^N>f>U?kt99_50 zhB$`5I&0nnn?UCU-Dj5f0>T4eGH4GS47y*`p6bnANsH35pnXpFH$q{h_3Avw{!hT| zCpweq>j&>4EIgEVC&504U$@;BuG_UxHy!leH5& z{a^{WbHN||wh5mKJALn6zBE#29i4;Lf!bgOe8#m`T#3#QIMn4QJOZ8t`Sc$c?|Y~7 zpxQT$zdh;f!|qy`1;bsLJxTKZ4AkZWTwcPbz!p%MkH8?`yNSemx}WID*QodUytxYW z8N<8pbY%x6?;BwS=uABq{PXp@#MQs*=UGmdu;$`oi1MKp?=((-0~K%BdG}S&7*Top z{G`5fcVJpCE`{e|K9uiD36Fv`Pzyh!Y^d$DE_ipYt___eUF(4Ve&9XgKLu9@tvLfh zYp2dx{yMY~?|`WCYw=EFLv{FAKal3mzW#DlhhG5SvXmaer-RyC>)&9dBGo?{b7~{M zes6@;#u`gryIQy8gFbtQm8bn{9(eN>sde>g*abI%H`kHc^X`Q(8?{c;eDLm!ef~%F zzt*$ALW^y0?Y9?!>ii?0jTYi7q1OI}+0(jSo(qKKV^}_an&z+etv;YJqy0f=h;iV3 z4};Wwy5C+>czgc^UvL=@^ogn2KcptH};1TUIh2RaW-u_TjMp&81nn?!d=+XJYNo1z!Vq>{a`FCfo-6C zPA9GW5E~bO*2G0Muovcs_VIP_H<$&Q_c{|UhL=F|sG7Pguyf#e>}-ZGA8MJlmonaj z7eVXTde{wV%Xm!w>%qpQAp2=;rPZsZ{nwVf_x#tor+HS5y|i^mtGCVhZ~H*&#oeEv zI_&oQZ|iU<{{J4_9Yor;IS_i?zUOmw!FR29I%jT%1K~&7GD5#6wEd95cdbje!@G4_ zk8ZywbnWk#_^mVlIJgDWAJy*FY1=wX?*qTDQDOYnxqlSQfTge+-iA1zAHvG6McTik ze6I8kpS5QX0iAW);BvSb9s-?%Ho#WU`A+LVZ>`DeEBTlv9Y6bm&eFQiJOWOHsqj7c zCFuOK0=7Uc_R3{x{7kEZ&sr1u!${CsNavu9kakYZPwPu9^zd8tIUIC`UjzFg?!3@v zqv^HqqZT&sr5Wae&fjtBpfmr+ez#Z)U((vZAFT`e%%HyLsSY}mN8atG^`lxn{5k^ef&EKUa3$A^-tpOIeN?2N_O$_+t3kGhpQ{;)KfZsYtO$v;QuD# zbv19J+6-S?V4bal_VL+K`Rnl=KI<++>ygeTvA-9qm%8Ay?vVZo-ko8+_!ZX={BDA2 z(Cxd6xcc>w58r$Bd;5B*<0sLF(hr98+af(5$qpMYbeOEt3s)M`g6u>#AYbQ~W*Ou{ z{o?Fec zlG%Jonz7_IIsM_udw)NY9X5_N?{OdO<&K_W&J*7Mb9r%_KsEEFc+pc)wR4m&nYXfF dWheeBz01lX^-;Vm7uxu0D>qw-6JEX$`9Ha#9tHpa literal 0 HcmV?d00001 diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/resources/static/favicon.ico b/spring-boot-modules/spring-boot-basic-customization/src/main/resources/static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..64105ac11c6186e380a724416ceb77ab5c263fef GIT binary patch literal 15086 zcmeI33yf6N8OP5s)D;AFL7}u+*#$K|S}oXWX{A6BF!-qLwvyDOsBLZ4#$rp2QmZaB zDMc+H+EzuWwblBlHY$b~O&EM6N;Jr;Vo@0)La}NWK^bJ(>Fs!o&?#+$PV&lcoe<}Q{V*nJA~=Gv^RNwrqwUlyiXv{0{QS2SOqSBm|V^K zQLxvS?=`|#!l^JBRzeqq>8p;)yEgECA92~92j{^Ocmu-PBuDxspmqtCp>qEVFM;g6 z3&A`)Nb3(OYfs4gVE$lypKZf~(VYR$L6|Q=Js00EefOZN@uR+-2@ByKP=BkBcZ1V& za;MV`ljQFM^6k?gyLZAaaQZKV=~YTY?;z0l>;SdzoJx5srK6LD`LGc*O%p%p9R+QP z6|Dlgn&*8KEf$U0H~|`r8OzLXW>yUXO|EuJ9@z;+0>uLCE$K;D6=;Qtp!LanwD8pF zL%lx*!{PIA@PT%dGLMJnL2J+?m5&?%=R+Heh0&mOOj7IG$)NNv!-;S-s1E&-`j3w4 ze*;$_%n#DP4jaI&`|AJo@DvQQK3qds^Eye{{=D+zeqa~w{*b0M zR(W3qW}MgW;|R}%kv6VAT?u}hX~JrYFZewm{*2G=D}>$H)B1k}oNImf8sV*wrd+?y z)7Ti{d?5T*z~&a>=YZD3X`uXPTOYnp*uPHu?IsD|j2-XPgVeqn)YVx26$}E6htuI$ z=m)c54+M3R#I@(TzV57GOMWc_&GAFvV)zbdzFY;nAxW9RytksSIj1=teCLnv;Qe)= zb~qBILNjQ;t7bg>3;iR&KmPpX2E$qd7QkdsUwjrOfz}JnuVDV3;_5@4Pt~85`XJ1P z#>Nw%K9~Y(mmfe5lJ?1BbkwHnA*`&ZG_6NkC)dDVKz($ljemfQ(sl1v*mvbDZk2$~y7?4-@x zRW95YplprFUxW6=G;=GiKOg#v?G~im3}}vj6Lbc79A1XE;C)CkXDj*hPPalMB9y1k z3)+Wu9+?PQi?t@tf!jfA!mAK>?#ZVO5kX$cp1^G4tk~}hZLk@FK5QjzOk$%c6ewpJYzz2sH}Qi~m`kNXS(kuY zm$grwk;+g?CCbwo<{?l&`~&)@G?iM7GS39v#f(dBqzXmK)%tNZB)&_lqS&%3^N>f>U?kt99_50 zhB$`5I&0nnn?UCU-Dj5f0>T4eGH4GS47y*`p6bnANsH35pnXpFH$q{h_3Avw{!hT| zCpweq>j&>4EIgEVC&504U$@;BuG_UxHy!leH5& z{a^{WbHN||wh5mKJALn6zBE#29i4;Lf!bgOe8#m`T#3#QIMn4QJOZ8t`Sc$c?|Y~7 zpxQT$zdh;f!|qy`1;bsLJxTKZ4AkZWTwcPbz!p%MkH8?`yNSemx}WID*QodUytxYW z8N<8pbY%x6?;BwS=uABq{PXp@#MQs*=UGmdu;$`oi1MKp?=((-0~K%BdG}S&7*Top z{G`5fcVJpCE`{e|K9uiD36Fv`Pzyh!Y^d$DE_ipYt___eUF(4Ve&9XgKLu9@tvLfh zYp2dx{yMY~?|`WCYw=EFLv{FAKal3mzW#DlhhG5SvXmaer-RyC>)&9dBGo?{b7~{M zes6@;#u`gryIQy8gFbtQm8bn{9(eN>sde>g*abI%H`kHc^X`Q(8?{c;eDLm!ef~%F zzt*$ALW^y0?Y9?!>ii?0jTYi7q1OI}+0(jSo(qKKV^}_an&z+etv;YJqy0f=h;iV3 z4};Wwy5C+>czgc^UvL=@^ogn2KcptH};1TUIh2RaW-u_TjMp&81nn?!d=+XJYNo1z!Vq>{a`FCfo-6C zPA9GW5E~bO*2G0Muovcs_VIP_H<$&Q_c{|UhL=F|sG7Pguyf#e>}-ZGA8MJlmonaj z7eVXTde{wV%Xm!w>%qpQAp2=;rPZsZ{nwVf_x#tor+HS5y|i^mtGCVhZ~H*&#oeEv zI_&oQZ|iU<{{J4_9Yor;IS_i?zUOmw!FR29I%jT%1K~&7GD5#6wEd95cdbje!@G4_ zk8ZywbnWk#_^mVlIJgDWAJy*FY1=wX?*qTDQDOYnxqlSQfTge+-iA1zAHvG6McTik ze6I8kpS5QX0iAW);BvSb9s-?%Ho#WU`A+LVZ>`DeEBTlv9Y6bm&eFQiJOWOHsqj7c zCFuOK0=7Uc_R3{x{7kEZ&sr1u!${CsNavu9kakYZPwPu9^zd8tIUIC`UjzFg?!3@v zqv^HqqZT&sr5Wae&fjtBpfmr+ez#Z)U((vZAFT`e%%HyLsSY}mN8atG^`lxn{5k^ef&EKUa3$A^-tpOIeN?2N_O$_+t3kGhpQ{;)KfZsYtO$v;QuD# zbv19J+6-S?V4bal_VL+K`Rnl=KI<++>ygeTvA-9qm%8Ay?vVZo-ko8+_!ZX={BDA2 z(Cxd6xcc>w58r$Bd;5B*<0sLF(hr98+af(5$qpMYbeOEt3s)M`g6u>#AYbQ~W*Ou{ z{o?Fec zlG%Jonz7_IIsM_udw)NY9X5_N?{OdO<&K_W&J*7Mb9r%_KsEEFc+pc)wR4m&nYXfF dWheeBz01lX^-;Vm7uxu0D>qw-6JEX$`9Ha#9tHpa literal 0 HcmV?d00001 From 02ce642cbdf71e4fdf5fcb047f8c50f0cd2bed74 Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 15 Mar 2020 23:00:55 +0100 Subject: [PATCH 068/278] JAVA-877 Update "Redirect after login" article --- ...SimpleUrlAuthenticationSuccessHandler.java | 35 +++++++------------ 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java index 19f49ea59d..73c186cae3 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java @@ -2,6 +2,8 @@ package org.baeldung.security; import java.io.IOException; import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -47,26 +49,21 @@ public class MySimpleUrlAuthenticationSuccessHandler implements AuthenticationSu } protected String determineTargetUrl(final Authentication authentication) { - boolean isUser = false; - boolean isAdmin = false; + + Map roleTargetUrlMap = new HashMap<>(); + roleTargetUrlMap.put("ROLE_USER", "/homepage.html"); + roleTargetUrlMap.put("ROLE_ADMIN", "/console.html"); + final Collection authorities = authentication.getAuthorities(); for (final GrantedAuthority grantedAuthority : authorities) { - if (grantedAuthority.getAuthority().equals("ROLE_USER")) { - isUser = true; - break; - } else if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) { - isAdmin = true; - break; + + String authorityName = grantedAuthority.getAuthority(); + if(roleTargetUrlMap.containsKey(authorityName)) { + return roleTargetUrlMap.get(authorityName); } } - if (isUser) { - return "/homepage.html"; - } else if (isAdmin) { - return "/console.html"; - } else { - throw new IllegalStateException(); - } + throw new IllegalStateException(); } /** @@ -83,12 +80,4 @@ public class MySimpleUrlAuthenticationSuccessHandler implements AuthenticationSu session.removeAttribute(WebAttributes.AUTHENTICATION_EXCEPTION); } - public void setRedirectStrategy(final RedirectStrategy redirectStrategy) { - this.redirectStrategy = redirectStrategy; - } - - protected RedirectStrategy getRedirectStrategy() { - return redirectStrategy; - } - } From 3aa7a8f8a2bcf9d17f3c2b503b780fc06d3bed1b Mon Sep 17 00:00:00 2001 From: Florin Hriscu Date: Mon, 16 Mar 2020 01:42:29 +0200 Subject: [PATCH 069/278] BAEL-3859 Changes after review. --- .../AtomicMarkableReferenceUnitTest.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java index d83146c6e8..5f526344be 100644 --- a/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java +++ b/core-java-modules/core-java-concurrency-basic-2/src/test/java/com/baeldung/concurrent/atomic/AtomicMarkableReferenceUnitTest.java @@ -34,14 +34,16 @@ public class AtomicMarkableReferenceUnitTest { @Test void givenMarkValueAsTrue_whenUsingIsMarkedMethod_thenMarkValueShouldBeTrue() { - AtomicMarkableReference employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), true); + Employee employee = new Employee(123, "Mike"); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenMarkValueAsFalse_whenUsingIsMarkedMethod_thenMarkValueShouldBeFalse() { - AtomicMarkableReference employeeNode = new AtomicMarkableReference(new Employee(123, "Mike"), false); + Employee employee = new Employee(123, "Mike"); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, false); Assertions.assertFalse(employeeNode.isMarked()); } @@ -49,7 +51,7 @@ public class AtomicMarkableReferenceUnitTest { @Test void whenUsingGetReferenceMethod_thenCurrentReferenceShouldBeReturned() { Employee employee = new Employee(123, "Mike"); - AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, false); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Assertions.assertEquals(employee, employeeNode.getReference()); } @@ -90,8 +92,8 @@ public class AtomicMarkableReferenceUnitTest { @Test void givenDifferentObjectReference_whenUsingAttemptMarkMethod_thenMarkShouldNotBeUpdated() { Employee employee = new Employee(123, "Mike"); - Employee expectedEmployee = new Employee(123, "Mike"); AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); + Employee expectedEmployee = new Employee(123, "Mike"); Assertions.assertFalse(employeeNode.attemptMark(expectedEmployee, false)); Assertions.assertTrue(employeeNode.isMarked()); @@ -154,23 +156,23 @@ public class AtomicMarkableReferenceUnitTest { @Test void givenNotCurrentReferenceAndCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { - Employee expectedEmployee = new Employee(123, "Mike"); - AtomicMarkableReference employeeNode = new AtomicMarkableReference(expectedEmployee, true); + Employee employee = new Employee(123, "Mike"); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); Assertions.assertFalse(employeeNode.weakCompareAndSet(new Employee(1234, "Steve"), newEmployee, true, false)); - Assertions.assertEquals(expectedEmployee, employeeNode.getReference()); + Assertions.assertEquals(employee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } @Test void givenCurrentReferenceAndNotCurrentMark_whenUsingWeakCompareAndSet_thenReferenceAndMarkShouldNotBeUpdated() { - Employee expectedEmployee = new Employee(123, "Mike"); - AtomicMarkableReference employeeNode = new AtomicMarkableReference(expectedEmployee, true); + Employee employee = new Employee(123, "Mike"); + AtomicMarkableReference employeeNode = new AtomicMarkableReference(employee, true); Employee newEmployee = new Employee(124, "John"); - Assertions.assertFalse(employeeNode.weakCompareAndSet(expectedEmployee, newEmployee, false, true)); - Assertions.assertEquals(expectedEmployee, employeeNode.getReference()); + Assertions.assertFalse(employeeNode.weakCompareAndSet(employee, newEmployee, false, true)); + Assertions.assertEquals(employee, employeeNode.getReference()); Assertions.assertTrue(employeeNode.isMarked()); } From d4a928cdfac363353c293a7f0b0abcd936a77919 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Mon, 16 Mar 2020 01:01:01 -0600 Subject: [PATCH 070/278] BAEL-3069 Spring jdbcTemplate Unit Testing --- .../spring-persistence-simple/pom.xml | 7 +++ .../baeldung/jdbc/EmployeeDAOUnitTest.java | 49 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java diff --git a/persistence-modules/spring-persistence-simple/pom.xml b/persistence-modules/spring-persistence-simple/pom.xml index 8a03310048..45605c853e 100644 --- a/persistence-modules/spring-persistence-simple/pom.xml +++ b/persistence-modules/spring-persistence-simple/pom.xml @@ -92,6 +92,12 @@ ${org.springframework.version} test + + org.mockito + mockito-core + ${mockito.version} + test + com.querydsl querydsl-jpa @@ -137,6 +143,7 @@ 9.0.0.M26 1.1 4.2.1 + 3.3.3 21.0 diff --git a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java new file mode 100644 index 0000000000..9894801a53 --- /dev/null +++ b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.jdbc; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import javax.sql.DataSource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; +import org.springframework.test.util.ReflectionTestUtils; + + +@RunWith(MockitoJUnitRunner.class) + +public class EmployeeDAOUnitTest { + + @Mock + JdbcTemplate jdbcTemplate; + + @Test + public void whenMockJdbcTemplate_thenReturnCorrectEmployeeCount() { + EmployeeDAO employeeDAO = new EmployeeDAO(); + ReflectionTestUtils.setField(employeeDAO, "jdbcTemplate", jdbcTemplate); + Mockito.when(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class)) + .thenReturn(4); + assertEquals(4, employeeDAO.getCountOfEmployees()); + + Mockito.when(jdbcTemplate.queryForObject(Mockito.anyString(), Mockito.eq(Integer.class))) + .thenReturn(3); + assertEquals(3, employeeDAO.getCountOfEmployees()); + } + + @Test + public void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() { + DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2) + .addScript("classpath:jdbc/schema.sql") + .addScript("classpath:jdbc/test-data.sql") + .build(); + EmployeeDAO employeeDAO = new EmployeeDAO(); + employeeDAO.setDataSource(dataSource); + assertEquals(4, employeeDAO.getCountOfEmployees()); + } + +} From 0b8b9715c6e1b3c6349db051f63688bf315542c0 Mon Sep 17 00:00:00 2001 From: Antonio Moreno Date: Thu, 6 Feb 2020 22:55:09 +0000 Subject: [PATCH 071/278] BAEL-3635 Intro to Alibaba Arthas Adding a case study to show Arthas. --- .../baeldung/arthas/FibonacciGenerator.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 libraries-3/src/main/java/com/baeldung/arthas/FibonacciGenerator.java diff --git a/libraries-3/src/main/java/com/baeldung/arthas/FibonacciGenerator.java b/libraries-3/src/main/java/com/baeldung/arthas/FibonacciGenerator.java new file mode 100644 index 0000000000..27cf0dacf6 --- /dev/null +++ b/libraries-3/src/main/java/com/baeldung/arthas/FibonacciGenerator.java @@ -0,0 +1,25 @@ +package com.baeldung.arthas; + +import java.io.IOException; + +import static java.lang.String.format; + +public class FibonacciGenerator { + + public static void main(String[] args) throws IOException { + System.out.println("Press a key to continue"); + System.in.read(); + for (int i = 0; i < 100; i++) { + long result = fibonacci(i); + System.out.println(format("fib(%d): %d", i, result)); + } + } + + public static long fibonacci(int n) { + if (n == 0 || n == 1) { + return 1L; + } else { + return fibonacci(n - 1) + fibonacci(n - 2); + } + } +} From 38843e814bfcee140d766957f63514e984210230 Mon Sep 17 00:00:00 2001 From: Roger Yates <587230+rojyates@users.noreply.github.com> Date: Tue, 17 Mar 2020 06:32:39 +1000 Subject: [PATCH 072/278] BAEL-3603 Update variable names --- .../NonBlockingClientUnitTest.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java index 90edee0306..838d456f03 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java @@ -40,14 +40,14 @@ public class NonBlockingClientUnitTest { // when we write and read using buffers socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); - ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access + ByteBuffer byteBuffer = ByteBuffer.allocate(8192); // or allocateDirect if we need direct memory access CharBuffer charBuffer = CharBuffer.allocate(8192); - CharsetDecoder decoder = charset.newDecoder(); + CharsetDecoder charsetDecoder = charset.newDecoder(); StringBuilder ourStore = new StringBuilder(); - while (socketChannel.read(buffer) != -1 || buffer.position() > 0) { - buffer.flip(); - storeBufferContents(buffer, charBuffer, decoder, ourStore); - buffer.compact(); + while (socketChannel.read(byteBuffer) != -1 || byteBuffer.position() > 0) { + byteBuffer.flip(); + storeBufferContents(byteBuffer, charBuffer, charsetDecoder, ourStore); + byteBuffer.compact(); } socketChannel.close(); @@ -67,14 +67,14 @@ public class NonBlockingClientUnitTest { // when we write and read using buffers that are too small for our message socketChannel.write(charset.encode(CharBuffer.wrap("GET " + REQUESTED_RESOURCE + " HTTP/1.0\r\n\r\n"))); - ByteBuffer buffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access + ByteBuffer byteBuffer = ByteBuffer.allocate(8); // or allocateDirect if we need direct memory access CharBuffer charBuffer = CharBuffer.allocate(8); - CharsetDecoder decoder = charset.newDecoder(); + CharsetDecoder charsetDecoder = charset.newDecoder(); StringBuilder ourStore = new StringBuilder(); - while (socketChannel.read(buffer) != -1 || buffer.position() > 0) { - buffer.flip(); - storeBufferContents(buffer, charBuffer, decoder, ourStore); - buffer.compact(); + while (socketChannel.read(byteBuffer) != -1 || byteBuffer.position() > 0) { + byteBuffer.flip(); + storeBufferContents(byteBuffer, charBuffer, charsetDecoder, ourStore); + byteBuffer.compact(); } socketChannel.close(); From 0f5889567e3dc1cb1d7fff20e855a30f81842a14 Mon Sep 17 00:00:00 2001 From: Roger Yates <587230+rojyates@users.noreply.github.com> Date: Tue, 17 Mar 2020 06:35:29 +1000 Subject: [PATCH 073/278] BAEL-3603 Update variable names --- .../blockingnonblocking/NonBlockingClientUnitTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java index 838d456f03..3e606476e6 100644 --- a/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java +++ b/core-java-modules/core-java-io-2/src/test/java/com/baeldung/blockingnonblocking/NonBlockingClientUnitTest.java @@ -84,8 +84,8 @@ public class NonBlockingClientUnitTest { .contains("It worked!")); } - void storeBufferContents(ByteBuffer buffer, CharBuffer charBuffer, CharsetDecoder decoder, StringBuilder ourStore) { - decoder.decode(buffer, charBuffer, true); + void storeBufferContents(ByteBuffer byteBuffer, CharBuffer charBuffer, CharsetDecoder charsetDecoder, StringBuilder ourStore) { + charsetDecoder.decode(byteBuffer, charBuffer, true); charBuffer.flip(); ourStore.append(charBuffer); charBuffer.clear(); From a1973baca1eac87a03cc5eea5881097d2c203625 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:04:55 +0800 Subject: [PATCH 074/278] Update README.md --- custom-pmd/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/custom-pmd/README.md b/custom-pmd/README.md index 0c42106fe8..d49047f180 100644 --- a/custom-pmd/README.md +++ b/custom-pmd/README.md @@ -1,7 +1,3 @@ ## Custom PMD Rules This module contains articles about PMD - -### Relevant Articles: - -- [Introduction To PMD](https://www.baeldung.com/pmd) \ No newline at end of file From 148ca99aef2ae569f4bf73b33d4ba0f9bf9db4fe Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:05:32 +0800 Subject: [PATCH 075/278] Delete README.md --- .../README.md | 159 ------------------ 1 file changed, 159 deletions(-) delete mode 100644 spring-swagger-codegen/spring-swagger-codegen-api-client/README.md diff --git a/spring-swagger-codegen/spring-swagger-codegen-api-client/README.md b/spring-swagger-codegen/spring-swagger-codegen-api-client/README.md deleted file mode 100644 index cffab6b9c7..0000000000 --- a/spring-swagger-codegen/spring-swagger-codegen-api-client/README.md +++ /dev/null @@ -1,159 +0,0 @@ -## Spring Swagger Codegen API Client - -This module contains the code for [Generate Spring Boot REST Client with Swagger](http://www.baeldung.com/spring-boot-rest-client-swagger-codegen). - -## Requirements - -Building the API client library requires [Maven](https://maven.apache.org/) to be installed. - -## Installation - -To install the API client library to your local Maven repository, simply execute: - -```shell -mvn install -``` - -To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: - -```shell -mvn deploy -``` - -Refer to the [official documentation](https://maven.apache.org/plugins/maven-deploy-plugin/usage.html) for more information. - -### Maven users - -Add this dependency to your project's POM: - -```xml - - com.baeldung - spring-swagger-codegen-api-client - 0.0.1-SNAPSHOT - compile - -``` - -### Gradle users - -Add this dependency to your project's build file: - -```groovy -compile "com.baeldung:spring-swagger-codegen-api-client:0.0.1-SNAPSHOT" -``` - -### Others - -At first generate the JAR by executing: - - mvn package - -Then manually install the following JARs: - -* target/spring-swagger-codegen-api-client-0.0.1-SNAPSHOT.jar -* target/lib/*.jar - -## Getting Started - -Please follow the [installation](#installation) instruction and execute the following Java code: - -```java - -import com.baeldung.petstore.client.invoker.*; -import com.baeldung.petstore.client.invoker.auth.*; -import com.baeldung.petstore.client.model.*; -import com.baeldung.petstore.client.api.PetApi; - -import java.io.File; -import java.util.*; - -public class PetApiExample { - - public static void main(String[] args) { - ApiClient defaultClient = Configuration.getDefaultApiClient(); - - // Configure OAuth2 access token for authorization: petstore_auth - OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); - petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); - - PetApi apiInstance = new PetApi(); - Pet body = new Pet(); // Pet | Pet object that needs to be added to the store - try { - apiInstance.addPet(body); - } catch (ApiException e) { - System.err.println("Exception when calling PetApi#addPet"); - e.printStackTrace(); - } - } -} - -``` - -## Documentation for API Endpoints - -All URIs are relative to *http://petstore.swagger.io/v2* - -Class | Method | HTTP request | Description ------------- | ------------- | ------------- | ------------- -*PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store -*PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet -*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status -*PetApi* | [**findPetsByTags**](docs/PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags -*PetApi* | [**getPetById**](docs/PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID -*PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet -*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data -*PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image -*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID -*StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status -*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID -*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet -*UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create user -*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array -*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array -*UserApi* | [**deleteUser**](docs/UserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user -*UserApi* | [**getUserByName**](docs/UserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name -*UserApi* | [**loginUser**](docs/UserApi.md#loginUser) | **GET** /user/login | Logs user into the system -*UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session -*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user - - -## Documentation for Models - - - [Category](docs/Category.md) - - [ModelApiResponse](docs/ModelApiResponse.md) - - [Order](docs/Order.md) - - [Pet](docs/Pet.md) - - [Tag](docs/Tag.md) - - [User](docs/User.md) - - -## Documentation for Authorization - -Authentication schemes defined for the API: -### api_key - -- **Type**: API key -- **API key parameter name**: api_key -- **Location**: HTTP header - -### petstore_auth - -- **Type**: OAuth -- **Flow**: implicit -- **Authorization URL**: http://petstore.swagger.io/oauth/dialog -- **Scopes**: - - write:pets: modify pets in your account - - read:pets: read your pets - - -## Recommendation - -It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. - -## Author - -apiteam@swagger.io - - - From ca6c9c018827d0abbeee966cdbf62aa958f6ce91 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:06:38 +0800 Subject: [PATCH 076/278] Update README.md --- ddd/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/ddd/README.md b/ddd/README.md index cd7cf90d61..ad84dc40b2 100644 --- a/ddd/README.md +++ b/ddd/README.md @@ -6,5 +6,4 @@ This module contains articles about Domain-driven Design (DDD) - [Persisting DDD Aggregates](https://www.baeldung.com/spring-persisting-ddd-aggregates) - [Double Dispatch in DDD](https://www.baeldung.com/ddd-double-dispatch) -- [DDD Aggregates and @DomainEvents](https://www.baeldung.com/spring-data-ddd) - [Organizing Layers Using Hexagonal Architecture, DDD, and Spring](https://www.baeldung.com/hexagonal-architecture-ddd-spring) From 994a5531c2518826c5610cf85b5d6d440fbb0234 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:08:26 +0800 Subject: [PATCH 077/278] Update README.md --- rxjava-core/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/rxjava-core/README.md b/rxjava-core/README.md index 95a374668d..2773bd9423 100644 --- a/rxjava-core/README.md +++ b/rxjava-core/README.md @@ -13,5 +13,4 @@ This module contains articles about RxJava. - [RxJava Maybe](https://www.baeldung.com/rxjava-maybe) - [Combining RxJava Completables](https://www.baeldung.com/rxjava-completable) - [RxJava Hooks](https://www.baeldung.com/rxjava-hooks) -- [Introduction to rxjava-jdbc](https://www.baeldung.com/rxjava-jdbc) - More articles: [[next -->]](/rxjava-2) From 369cfe24ab46db81083898b2aa51e0d4f8a375b3 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:09:27 +0800 Subject: [PATCH 078/278] Update README.md --- core-java-modules/core-java-9-improvements/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/core-java-modules/core-java-9-improvements/README.md b/core-java-modules/core-java-9-improvements/README.md index 5864170e85..c89d0e3c09 100644 --- a/core-java-modules/core-java-9-improvements/README.md +++ b/core-java-modules/core-java-9-improvements/README.md @@ -9,8 +9,3 @@ This module contains articles about the improvements to core Java features intro - [Java 9 Stream API Improvements](https://www.baeldung.com/java-9-stream-api) - [Java 9 java.util.Objects Additions](https://www.baeldung.com/java-9-objects-new) - [Java 9 CompletableFuture API Improvements](https://www.baeldung.com/java-9-completablefuture) - -#### Relevant articles not in this module: - -- [Java 9 Process API Improvements](https://www.baeldung.com/java-9-process-api) (see the [core-java-os](/core-java-os) module) - From e478767d6af17869672ac40cd906764dfa3db8ac Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:10:07 +0800 Subject: [PATCH 079/278] Update README.md --- spring-boot-modules/spring-boot-mvc-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-mvc-2/README.md b/spring-boot-modules/spring-boot-mvc-2/README.md index cb0eea4c2a..dc6a136131 100644 --- a/spring-boot-modules/spring-boot-mvc-2/README.md +++ b/spring-boot-modules/spring-boot-mvc-2/README.md @@ -6,4 +6,4 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [Functional Controllers in Spring MVC](https://www.baeldung.com/spring-mvc-functional-controllers) - [Specify an Array of Strings as Body Parameters in Swagger](https://www.baeldung.com/swagger-body-array-of-strings) -- More articles: [[prev -->]](/spring-boot-mvc) +- More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc) From 71b2a9308f8423ea3b38fc4a2fc19e38468af900 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 17 Mar 2020 19:10:55 +0800 Subject: [PATCH 080/278] Update README.md --- spring-boot-modules/spring-boot-mvc/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-mvc/README.md b/spring-boot-modules/spring-boot-mvc/README.md index b4f87d1d40..2e67c42ede 100644 --- a/spring-boot-modules/spring-boot-mvc/README.md +++ b/spring-boot-modules/spring-boot-mvc/README.md @@ -10,4 +10,4 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [A Controller, Service and DAO Example with Spring Boot and JSF](https://www.baeldung.com/jsf-spring-boot-controller-service-dao) - [Setting Up Swagger 2 with a Spring REST API](https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) - [Using Spring ResponseEntity to Manipulate the HTTP Response](https://www.baeldung.com/spring-response-entity) -- More articles: [[next -->]](/spring-boot-mvc-2) +- More articles: [[next -->]](/spring-boot-modules/spring-boot-mvc-2) From 4131d1ebbd6974b494a70471be3696b186c4626e Mon Sep 17 00:00:00 2001 From: Graham Cox Date: Tue, 17 Mar 2020 14:30:46 +0000 Subject: [PATCH 081/278] Moved the Moshi examples to json-2 (#8898) --- json-2/pom.xml | 17 +++++++++++++++++ .../moshi/AlternativeAdapterUnitTest.java | 0 .../java/com/baeldung/moshi/ArrayUnitTest.java | 0 .../baeldung/moshi/ComplexAdapterUnitTest.java | 0 .../com/baeldung/moshi/DefaultUnitTest.java | 0 .../com/baeldung/moshi/PrimitiveUnitTest.java | 0 .../java/com/baeldung/moshi/RenameUnitTest.java | 0 .../baeldung/moshi/SimpleAdapterUnitTest.java | 0 .../com/baeldung/moshi/TransientUnitTest.java | 0 libraries-3/pom.xml | 11 ----------- 10 files changed, 17 insertions(+), 11 deletions(-) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/AlternativeAdapterUnitTest.java (100%) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/ArrayUnitTest.java (100%) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/ComplexAdapterUnitTest.java (100%) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/DefaultUnitTest.java (100%) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/PrimitiveUnitTest.java (100%) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/RenameUnitTest.java (100%) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/SimpleAdapterUnitTest.java (100%) rename {libraries-3 => json-2}/src/test/java/com/baeldung/moshi/TransientUnitTest.java (100%) diff --git a/json-2/pom.xml b/json-2/pom.xml index 72b3295b2b..e0295af59b 100644 --- a/json-2/pom.xml +++ b/json-2/pom.xml @@ -33,9 +33,26 @@ ${assertj-core.version} test + + + com.squareup.moshi + moshi + ${moshi.version} + + + com.squareup.moshi + moshi-adapters + ${moshi.version} + + + org.apache.commons + commons-lang3 + 3.9 + 0.9.23 3.11.1 + 1.9.2 diff --git a/libraries-3/src/test/java/com/baeldung/moshi/AlternativeAdapterUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/AlternativeAdapterUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/AlternativeAdapterUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/AlternativeAdapterUnitTest.java diff --git a/libraries-3/src/test/java/com/baeldung/moshi/ArrayUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/ArrayUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/ArrayUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/ArrayUnitTest.java diff --git a/libraries-3/src/test/java/com/baeldung/moshi/ComplexAdapterUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/ComplexAdapterUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/ComplexAdapterUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/ComplexAdapterUnitTest.java diff --git a/libraries-3/src/test/java/com/baeldung/moshi/DefaultUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/DefaultUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/DefaultUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/DefaultUnitTest.java diff --git a/libraries-3/src/test/java/com/baeldung/moshi/PrimitiveUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/PrimitiveUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/PrimitiveUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/PrimitiveUnitTest.java diff --git a/libraries-3/src/test/java/com/baeldung/moshi/RenameUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/RenameUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/RenameUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/RenameUnitTest.java diff --git a/libraries-3/src/test/java/com/baeldung/moshi/SimpleAdapterUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/SimpleAdapterUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/SimpleAdapterUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/SimpleAdapterUnitTest.java diff --git a/libraries-3/src/test/java/com/baeldung/moshi/TransientUnitTest.java b/json-2/src/test/java/com/baeldung/moshi/TransientUnitTest.java similarity index 100% rename from libraries-3/src/test/java/com/baeldung/moshi/TransientUnitTest.java rename to json-2/src/test/java/com/baeldung/moshi/TransientUnitTest.java diff --git a/libraries-3/pom.xml b/libraries-3/pom.xml index a438d423e2..68b5f2aa21 100644 --- a/libraries-3/pom.xml +++ b/libraries-3/pom.xml @@ -73,16 +73,6 @@ ${cache2k.version} pom - - com.squareup.moshi - moshi - ${moshi.version} - - - com.squareup.moshi - moshi-adapters - ${moshi.version} - com.jcabi jcabi-aspects @@ -201,7 +191,6 @@ 0.43 2.7.2 1.2.3.Final - 1.9.2 0.22.6 1.9.2 0.14.1 From 8c56c4ef43c7f9d6edbddececf6f2d0ae0833579 Mon Sep 17 00:00:00 2001 From: George Haris <40850523+gecharita@users.noreply.github.com> Date: Tue, 17 Mar 2020 22:31:11 +0200 Subject: [PATCH 082/278] BAEL-3835 (#8901) * BAEL-3835: Inject a value to a static field * BAEL-3835: integration of code into the src directory Co-authored-by: Georgios Charitakis --- .../staticvalue/injection/Application.java | 16 ++++++++++ .../injection/PropertyController.java | 30 +++++++++++++++++++ .../src/main/resources/application.properties | 1 + 3 files changed, 47 insertions(+) create mode 100644 spring-core-3/src/main/java/com/baeldung/staticvalue/injection/Application.java create mode 100644 spring-core-3/src/main/java/com/baeldung/staticvalue/injection/PropertyController.java create mode 100644 spring-core-3/src/main/resources/application.properties diff --git a/spring-core-3/src/main/java/com/baeldung/staticvalue/injection/Application.java b/spring-core-3/src/main/java/com/baeldung/staticvalue/injection/Application.java new file mode 100644 index 0000000000..45c47c955f --- /dev/null +++ b/spring-core-3/src/main/java/com/baeldung/staticvalue/injection/Application.java @@ -0,0 +1,16 @@ +package com.baeldung.staticvalue.injection; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("/application.properties") + +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/spring-core-3/src/main/java/com/baeldung/staticvalue/injection/PropertyController.java b/spring-core-3/src/main/java/com/baeldung/staticvalue/injection/PropertyController.java new file mode 100644 index 0000000000..f5910ea4f8 --- /dev/null +++ b/spring-core-3/src/main/java/com/baeldung/staticvalue/injection/PropertyController.java @@ -0,0 +1,30 @@ +package com.baeldung.staticvalue.injection; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.List; + +@RestController +public class PropertyController { + + @Value("${name}") + private String name; + + @Value("${name}") + private static String NAME_NULL; + + private static String NAME_STATIC; + + @Value("${name}") + public void setNameStatic(String name){ + PropertyController.NAME_STATIC = name; + } + + @GetMapping("/properties") + public List getProperties(){ + return Arrays.asList(this.name, NAME_STATIC, NAME_NULL) ; + } +} diff --git a/spring-core-3/src/main/resources/application.properties b/spring-core-3/src/main/resources/application.properties new file mode 100644 index 0000000000..828fa9cd2a --- /dev/null +++ b/spring-core-3/src/main/resources/application.properties @@ -0,0 +1 @@ +name = Inject a value to a static field From 5b154ca3325c63472acc0b3b1f11abb74cce066a Mon Sep 17 00:00:00 2001 From: Sam Millington Date: Tue, 17 Mar 2020 20:42:04 +0000 Subject: [PATCH 083/278] Delete static-value-injection folder (#8902) Co-authored-by: SBLUKcic --- .../static-value-injection/README.md | 22 -------- spring-core-3/static-value-injection/pom.xml | 52 ------------------- .../main/java/com/baeldung/Application.java | 13 ----- .../controller/PropertyController.java | 31 ----------- .../src/main/resources/application.properties | 1 - .../java/com/baeldung/ApplicationTests.java | 13 ----- 6 files changed, 132 deletions(-) delete mode 100644 spring-core-3/static-value-injection/README.md delete mode 100644 spring-core-3/static-value-injection/pom.xml delete mode 100644 spring-core-3/static-value-injection/src/main/java/com/baeldung/Application.java delete mode 100644 spring-core-3/static-value-injection/src/main/java/com/baeldung/controller/PropertyController.java delete mode 100644 spring-core-3/static-value-injection/src/main/resources/application.properties delete mode 100644 spring-core-3/static-value-injection/src/test/java/com/baeldung/ApplicationTests.java diff --git a/spring-core-3/static-value-injection/README.md b/spring-core-3/static-value-injection/README.md deleted file mode 100644 index 06dfa29f80..0000000000 --- a/spring-core-3/static-value-injection/README.md +++ /dev/null @@ -1,22 +0,0 @@ -# Inject a value to a static field - -## How to run -```sh -mvn clean install -mvn spring-boot:run -``` - -## Request - -**GET** -http://localhost:8080/properties - - -## Response -```json -[ - "Inject a value to a static field", - "Inject a value to a static field", - null -] -``` diff --git a/spring-core-3/static-value-injection/pom.xml b/spring-core-3/static-value-injection/pom.xml deleted file mode 100644 index aa45fde886..0000000000 --- a/spring-core-3/static-value-injection/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.4.RELEASE - - - com.baeldung - static.value.injection - 0.0.1-SNAPSHOT - static.value.injection - Demo project for Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/spring-core-3/static-value-injection/src/main/java/com/baeldung/Application.java b/spring-core-3/static-value-injection/src/main/java/com/baeldung/Application.java deleted file mode 100644 index c1875216b5..0000000000 --- a/spring-core-3/static-value-injection/src/main/java/com/baeldung/Application.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class Application { - - public static void main(String[] args) { - SpringApplication.run(Application.class, args); - } - -} diff --git a/spring-core-3/static-value-injection/src/main/java/com/baeldung/controller/PropertyController.java b/spring-core-3/static-value-injection/src/main/java/com/baeldung/controller/PropertyController.java deleted file mode 100644 index 03a2518117..0000000000 --- a/spring-core-3/static-value-injection/src/main/java/com/baeldung/controller/PropertyController.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.controller; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.util.Arrays; -import java.util.List; - -@RestController -public class PropertyController { - - @Value("${name}") - private String name; - - @Value("${name}") - private static String NAME_NULL; - - private static String NAME_STATIC; - - @Value("${name}") - public void setNameStatic(String name){ - PropertyController.NAME_STATIC = name; - } - - @GetMapping("/properties") - public List getProperties(){ - return Arrays.asList(this.name, NAME_STATIC, NAME_NULL) ; - } -} diff --git a/spring-core-3/static-value-injection/src/main/resources/application.properties b/spring-core-3/static-value-injection/src/main/resources/application.properties deleted file mode 100644 index 828fa9cd2a..0000000000 --- a/spring-core-3/static-value-injection/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ -name = Inject a value to a static field diff --git a/spring-core-3/static-value-injection/src/test/java/com/baeldung/ApplicationTests.java b/spring-core-3/static-value-injection/src/test/java/com/baeldung/ApplicationTests.java deleted file mode 100644 index 4ad83bc539..0000000000 --- a/spring-core-3/static-value-injection/src/test/java/com/baeldung/ApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ApplicationTests { - - @Test - void contextLoads() { - } - -} From cb3898127475c377a4e573d53b8381ca36776d97 Mon Sep 17 00:00:00 2001 From: Mathieu Fortin Date: Tue, 17 Mar 2020 19:20:11 -0400 Subject: [PATCH 084/278] added directive to run live test --- .../debugging/consumer/ConsumerFooServiceLiveTest.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java b/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java index af9bdfbc9b..e61ea9e155 100644 --- a/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java +++ b/spring-5-reactive-2/src/test/java/com/baeldung/debugging/consumer/ConsumerFooServiceLiveTest.java @@ -7,6 +7,11 @@ import org.springframework.test.web.reactive.server.WebTestClient.ResponseSpec; import com.baeldung.debugging.consumer.service.FooService; +/** + * In order to run this live test, start the following classes: + * - com.baeldung.debugging.server.ServerDebuggingApplication + * - com.baeldung.debugging.consumer.ConsumerDebuggingApplication + */ public class ConsumerFooServiceLiveTest { FooService service = new FooService(); From 54c1d28b2ee66077f42f16eadd8a17304e0f3cd1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:08:48 +0800 Subject: [PATCH 085/278] Create README.md --- spring-threads/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-threads/README.md diff --git a/spring-threads/README.md b/spring-threads/README.md new file mode 100644 index 0000000000..c3762cd86f --- /dev/null +++ b/spring-threads/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [ThreadPoolTaskExecutor corePoolSize vs. maxPoolSize](https://www.baeldung.com/java-threadpooltaskexecutor-core-vs-max-poolsize) From fbb59ff98b2b4e26c99aac6186da132411dc3599 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:13:12 +0800 Subject: [PATCH 086/278] Create README.md --- gradle/gradle-to-maven/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 gradle/gradle-to-maven/README.md diff --git a/gradle/gradle-to-maven/README.md b/gradle/gradle-to-maven/README.md new file mode 100644 index 0000000000..9acbfb1647 --- /dev/null +++ b/gradle/gradle-to-maven/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Converting Gradle Build File to Maven POM](https://www.baeldung.com/gradle-build-to-maven-pom) From 57c66c0906c43f5dcf8df09bc47fbfbd4892b3cb Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:15:40 +0800 Subject: [PATCH 087/278] Update README.md --- persistence-modules/spring-data-jpa-4/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-data-jpa-4/README.md b/persistence-modules/spring-data-jpa-4/README.md index 42e4619a59..3884435f75 100644 --- a/persistence-modules/spring-data-jpa-4/README.md +++ b/persistence-modules/spring-data-jpa-4/README.md @@ -5,6 +5,7 @@ - [Programmatic Transaction Management in Spring](https://www.baeldung.com/spring-programmatic-transaction-management) - [JPA Entity Lifecycle Events](https://www.baeldung.com/jpa-entity-lifecycle-events) - [Working with Lazy Element Collections in JPA](https://www.baeldung.com/java-jpa-lazy-collections) +- [Calling Stored Procedures from Spring Data JPA Repositories](https://www.baeldung.com/spring-data-jpa-stored-procedures) ### Eclipse Config After importing the project into Eclipse, you may see the following error: From 7a445ff86c815cbc87c9f86164ad400c1b3b4f4c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:18:27 +0800 Subject: [PATCH 088/278] Update README.md --- spring-amqp/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-amqp/README.md b/spring-amqp/README.md index 6b09aec10a..7d202f49f8 100644 --- a/spring-amqp/README.md +++ b/spring-amqp/README.md @@ -7,3 +7,4 @@ This module contains articles about Spring with the AMQP messaging system - [Messaging With Spring AMQP](https://www.baeldung.com/spring-amqp) - [RabbitMQ Message Dispatching with Spring AMQP](https://www.baeldung.com/rabbitmq-spring-amqp) - [Error Handling with Spring AMQP](https://www.baeldung.com/spring-amqp-error-handling) +- [Exponential Backoff With Spring AMQP](https://www.baeldung.com/spring-amqp-exponential-backoff) From d46ed5c784426fd9bf454451f00f3411737438f5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:20:03 +0800 Subject: [PATCH 089/278] Update README.md --- json-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/json-2/README.md b/json-2/README.md index b0f49f0e48..c2b6b36a11 100644 --- a/json-2/README.md +++ b/json-2/README.md @@ -4,3 +4,4 @@ This module contains articles about JSON. ### Relevant Articles: - [Introduction to Jsoniter](https://www.baeldung.com/java-jsoniter) +- [Introduction to Moshi Json](https://www.baeldung.com/java-json-moshi) From e11224d89aae2d91549635c72f59c9ade3063201 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:22:52 +0800 Subject: [PATCH 090/278] Update README.md --- java-numbers-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index 08e8dae8ef..835b8b0b54 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -2,3 +2,4 @@ - [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers) - [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long) +- [Check for null Before Calling Parse in Double.parseDouble](https://www.baeldung.com/java-check-null-parse-double) From 98c4810ae4f22f62628f4f310d9ad2eaa93eb2da Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:26:04 +0800 Subject: [PATCH 091/278] Update README.md --- core-java-modules/core-java-nio-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core-java-modules/core-java-nio-2/README.md b/core-java-modules/core-java-nio-2/README.md index 8b29c97385..ef73159f66 100644 --- a/core-java-modules/core-java-nio-2/README.md +++ b/core-java-modules/core-java-nio-2/README.md @@ -8,4 +8,5 @@ This module contains articles about core Java non-blocking input and output (IO) - [Create a Symbolic Link with Java](https://www.baeldung.com/java-symlink) - [Introduction to the Java NIO Selector](https://www.baeldung.com/java-nio-selector) - [Using Java MappedByteBuffer](https://www.baeldung.com/java-mapped-byte-buffer) -- [[<-- Prev]](/core-java-modules/core-java-nio) \ No newline at end of file +- [How to Lock a File in Java](https://www.baeldung.com/java-lock-files) +- [[<-- Prev]](/core-java-modules/core-java-nio) From 2c04d869770746c2a971221f441dc25e8d6a4e87 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:28:35 +0800 Subject: [PATCH 092/278] Update README.md --- spring-boot-modules/spring-boot-mvc-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-mvc-2/README.md b/spring-boot-modules/spring-boot-mvc-2/README.md index dc6a136131..4200f58024 100644 --- a/spring-boot-modules/spring-boot-mvc-2/README.md +++ b/spring-boot-modules/spring-boot-mvc-2/README.md @@ -6,4 +6,5 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [Functional Controllers in Spring MVC](https://www.baeldung.com/spring-mvc-functional-controllers) - [Specify an Array of Strings as Body Parameters in Swagger](https://www.baeldung.com/swagger-body-array-of-strings) +- [Swagger @ApiParam vs @ApiModelProperty](https://www.baeldung.com/swagger-apiparam-vs-apimodelproperty) - More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc) From 020a62b92cd3bae37f2b11afba3158267d078723 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:32:33 +0800 Subject: [PATCH 093/278] Create README.md --- play-framework/async-http/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 play-framework/async-http/README.md diff --git a/play-framework/async-http/README.md b/play-framework/async-http/README.md new file mode 100644 index 0000000000..c42b86ad4e --- /dev/null +++ b/play-framework/async-http/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Asynchronous HTTP Programming with Play Framework](https://www.baeldung.com/java-play-asynchronous-http-programming) From 08e438fce277e9eae280d23f5862978093153058 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:39:29 +0800 Subject: [PATCH 094/278] Update README.md --- spring-rest-http/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-rest-http/README.md b/spring-rest-http/README.md index 54b31e80c4..35793cb281 100644 --- a/spring-rest-http/README.md +++ b/spring-rest-http/README.md @@ -12,3 +12,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Returning Custom Status Codes from Spring Controllers](https://www.baeldung.com/spring-mvc-controller-custom-http-status-code) - [Spring RequestMapping](https://www.baeldung.com/spring-requestmapping) - [Guide to DeferredResult in Spring](https://www.baeldung.com/spring-deferred-result) +- [Using JSON Patch in Spring REST APIs](https://www.baeldung.com/spring-rest-json-patch) From 96c2e93de5b7c5b9f827b299acbee2c122221fd0 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:42:31 +0800 Subject: [PATCH 095/278] Update README.md --- spring-batch/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-batch/README.md b/spring-batch/README.md index 99ac9826bc..d637de269c 100644 --- a/spring-batch/README.md +++ b/spring-batch/README.md @@ -9,3 +9,4 @@ This module contains articles about Spring Batch - [How to Trigger and Stop a Scheduled Spring Batch Job](https://www.baeldung.com/spring-batch-start-stop-job) - [Configuring Skip Logic in Spring Batch](https://www.baeldung.com/spring-batch-skip-logic) - [Testing a Spring Batch Job](https://www.baeldung.com/spring-batch-testing-job) +- [Configuring Retry Logic in Spring Batch](https://www.baeldung.com/spring-batch-retry-logic) From fd4fce26775b4445b66e62b2b7412cf425187461 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:46:41 +0800 Subject: [PATCH 096/278] Update README.md --- libraries-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-3/README.md b/libraries-3/README.md index 404045e6b1..a5be14a349 100644 --- a/libraries-3/README.md +++ b/libraries-3/README.md @@ -12,3 +12,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Guide to the Cactoos Library](https://www.baeldung.com/java-cactoos) - [Parsing Command-Line Parameters with Airline](https://www.baeldung.com/java-airline) - [Introduction to cache2k](https://www.baeldung.com/java-cache2k) +- [Introduction to the jcabi-aspects AOP Annotations Library](https://www.baeldung.com/java-jcabi-aspects) From 89e0499ea650bc043b284a6d57dc764e598a32a4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:49:21 +0800 Subject: [PATCH 097/278] Update README.md --- spring-cloud/spring-cloud-zuul/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-zuul/README.md b/spring-cloud/spring-cloud-zuul/README.md index b8e1773930..acd56a213c 100644 --- a/spring-cloud/spring-cloud-zuul/README.md +++ b/spring-cloud/spring-cloud-zuul/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring with Netflix Zuul ### Relevant Articles: - [Rate Limiting in Spring Cloud Netflix Zuul](https://www.baeldung.com/spring-cloud-zuul-rate-limit) - [Spring REST with a Zuul Proxy](https://www.baeldung.com/spring-rest-with-zuul-proxy) +- [Modifying the Response Body in a Zuul Filter](https://www.baeldung.com/zuul-filter-modifying-response-body) From 7d7caec5bd212289533aa3b39f44727d7c3848dd Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:51:41 +0800 Subject: [PATCH 098/278] Update README.md --- spring-mvc-xml/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md index 0adf127aaa..685e7686b1 100644 --- a/spring-mvc-xml/README.md +++ b/spring-mvc-xml/README.md @@ -17,6 +17,7 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [A Java Web Application Without a web.xml](https://www.baeldung.com/java-web-app-without-web-xml) - [Validating RequestParams and PathVariables in Spring](https://www.baeldung.com/spring-validate-requestparam-pathvariable) - [Debugging the Spring MVC 404 “No mapping found for HTTP request” Error](https://www.baeldung.com/spring-mvc-404-error) +- [Getting Started with CRaSH](https://www.baeldung.com/jvm-crash-shell) ## Spring MVC with XML Configuration Example Project From 378c353c90a9420c564f1faa828e9e03fc531618 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:55:20 +0800 Subject: [PATCH 099/278] Create README.md --- core-java-modules/core-java-arrays-3/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 core-java-modules/core-java-arrays-3/README.md diff --git a/core-java-modules/core-java-arrays-3/README.md b/core-java-modules/core-java-arrays-3/README.md new file mode 100644 index 0000000000..255d3d097d --- /dev/null +++ b/core-java-modules/core-java-arrays-3/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Arrays.deepEquals](https://www.baeldung.com/java-arrays-deepequals) From e052b9e735f82300f41f217932351dcfc17ace8f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 12:57:21 +0800 Subject: [PATCH 100/278] Update README.md --- core-java-modules/core-java-exceptions-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-exceptions-2/README.md b/core-java-modules/core-java-exceptions-2/README.md index 49ce897e60..7ad951f1de 100644 --- a/core-java-modules/core-java-exceptions-2/README.md +++ b/core-java-modules/core-java-exceptions-2/README.md @@ -7,3 +7,4 @@ This module contains articles about core java exceptions - [Is It a Bad Practice to Catch Throwable?](https://www.baeldung.com/java-catch-throwable-bad-practice) - [Wrapping vs Rethrowing Exceptions in Java](https://www.baeldung.com/java-wrapping-vs-rethrowing-exceptions) - [java.net.UnknownHostException: Invalid Hostname for Server](https://www.baeldung.com/java-unknownhostexception) +- [How to Handle Java SocketException](https://www.baeldung.com/java-socketexception) From dc7cf4dfe719e32a05ba4782c4b96cfcefa51410 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:00:00 +0800 Subject: [PATCH 101/278] Create README.md --- spring-mvc-java-2/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-mvc-java-2/README.md diff --git a/spring-mvc-java-2/README.md b/spring-mvc-java-2/README.md new file mode 100644 index 0000000000..b5d5df3cd4 --- /dev/null +++ b/spring-mvc-java-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Cache Headers in Spring MVC](https://www.baeldung.com/spring-mvc-cache-headers) From 72c79a278d22b8cfbd5d625f1427e1078b93419a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:03:55 +0800 Subject: [PATCH 102/278] Update README.md --- spring-core-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-core-3/README.md b/spring-core-3/README.md index ae2d33c196..b064dc74d9 100644 --- a/spring-core-3/README.md +++ b/spring-core-3/README.md @@ -8,4 +8,5 @@ This module contains articles about core Spring functionality - [Guide to the Spring BeanFactory](https://www.baeldung.com/spring-beanfactory) - [How to use the Spring FactoryBean?](https://www.baeldung.com/spring-factorybean) - [Spring – Injecting Collections](https://www.baeldung.com/spring-injecting-collections) +- [Design Patterns in the Spring Framework](https://www.baeldung.com/spring-framework-design-patterns) - More articles: [[<-- prev]](/spring-core-2) From 5f7e961af1af2a9f266c39aec6b3ecfd631f3f27 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:10:33 +0800 Subject: [PATCH 103/278] Update README.md --- persistence-modules/java-mongodb/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/java-mongodb/README.md b/persistence-modules/java-mongodb/README.md index 41d0ad63f8..a8539e644f 100644 --- a/persistence-modules/java-mongodb/README.md +++ b/persistence-modules/java-mongodb/README.md @@ -9,3 +9,4 @@ This module contains articles about MongoDB in Java. - [MongoDB BSON Guide](https://www.baeldung.com/mongodb-bson) - [Geospatial Support in MongoDB](https://www.baeldung.com/mongodb-geospatial-support) - [Introduction to Morphia – Java ODM for MongoDB](https://www.baeldung.com/mongodb-morphia) +- [MongoDB Aggregations Using Java](https://www.baeldung.com/java-mongodb-aggregations) From a5ea8c9d12a251c73fb77b3c3f5b51a2d99354c4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:12:25 +0800 Subject: [PATCH 104/278] Update README.md --- core-java-modules/core-java-lang-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-lang-2/README.md b/core-java-modules/core-java-lang-2/README.md index a9604d1032..65d40c6a26 100644 --- a/core-java-modules/core-java-lang-2/README.md +++ b/core-java-modules/core-java-lang-2/README.md @@ -9,4 +9,5 @@ This module contains articles about core features in the Java language - [Java Default Parameters Using Method Overloading](https://www.baeldung.com/java-default-parameters-method-overloading) - [How to Return Multiple Values From a Java Method](https://www.baeldung.com/java-method-return-multiple-values) - [Guide to the Java finally Keyword](https://www.baeldung.com/java-finally-keyword) +- [The Java Headless Mode](https://www.baeldung.com/java-headless-mode) - [[<-- Prev]](/core-java-modules/core-java-lang) From 18fdd2b6aae8c0776ae54ea9558e5c14d9a13b9a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:14:22 +0800 Subject: [PATCH 105/278] Update README.md --- spring-boot-modules/spring-boot-properties/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-properties/README.md b/spring-boot-modules/spring-boot-properties/README.md index daf7c55ab3..d8d9d0df48 100644 --- a/spring-boot-modules/spring-boot-properties/README.md +++ b/spring-boot-modules/spring-boot-properties/README.md @@ -12,3 +12,4 @@ This module contains articles about Properties in Spring Boot. - [Spring YAML Configuration](https://www.baeldung.com/spring-yaml) - [Using Spring @Value with Defaults](https://www.baeldung.com/spring-value-defaults) - [How to Inject a Property Value Into a Class Not Managed by Spring?](https://www.baeldung.com/inject-properties-value-non-spring-class) +- [Add Build Properties to a Spring Boot Application](https://www.baeldung.com/spring-boot-build-properties) From a3f198079de42bff1b4207250f23e4ef85d67939 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:16:03 +0800 Subject: [PATCH 106/278] Update README.md --- libraries-data-io/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-data-io/README.md b/libraries-data-io/README.md index 550f353c97..3e68334ec9 100644 --- a/libraries-data-io/README.md +++ b/libraries-data-io/README.md @@ -9,3 +9,4 @@ This module contains articles about IO data processing libraries. - [Introduction To OpenCSV](https://www.baeldung.com/opencsv) - [Interact with Google Sheets from Java](https://www.baeldung.com/google-sheets-java-client) - [Introduction To Docx4J](https://www.baeldung.com/docx4j) +- [Breaking YAML Strings Over Multiple Lines](https://www.baeldung.com/yaml-multi-line) From 6fde5e9515f5fde06a599ed697c89e0ee3760550 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:18:19 +0800 Subject: [PATCH 107/278] Update README.md --- image-processing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/image-processing/README.md b/image-processing/README.md index adb35c2318..4417f312d8 100644 --- a/image-processing/README.md +++ b/image-processing/README.md @@ -4,3 +4,4 @@ This module contains articles about image processing. ### Relevant Articles: - [Working with Images in Java](https://www.baeldung.com/java-images) +- [Intro to OpenCV with Java](https://www.baeldung.com/java-opencv) From c100729cda01a0defb17a0f0ce905d997c9d1ef1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:19:55 +0800 Subject: [PATCH 108/278] Update README.md --- data-structures/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/data-structures/README.md b/data-structures/README.md index e8fb374f6c..f9ca78679a 100644 --- a/data-structures/README.md +++ b/data-structures/README.md @@ -9,3 +9,4 @@ This module contains articles about data structures in Java - [Circular Linked List Java Implementation](https://www.baeldung.com/java-circular-linked-list) - [How to Print a Binary Tree Diagram](https://www.baeldung.com/java-print-binary-tree-diagram) - [Introduction to Big Queue](https://www.baeldung.com/java-big-queue) +- [Guide to AVL Trees in Java](https://www.baeldung.com/java-avl-trees) From b46622d258a291acbc874e758f7e7092afd6cfe4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:23:13 +0800 Subject: [PATCH 109/278] Update README.md --- core-java-modules/core-java-14/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-14/README.md b/core-java-modules/core-java-14/README.md index 0648d087be..9ec20cd223 100644 --- a/core-java-modules/core-java-14/README.md +++ b/core-java-modules/core-java-14/README.md @@ -5,3 +5,4 @@ This module contains articles about Java 14. ### Relevant articles - [Guide to the @Serial Annotation in Java 14](https://www.baeldung.com/java-14-serial-annotation) +- [Java Text Blocks](https://www.baeldung.com/java-text-blocks) From c72530f3ffba5e03ac7f0bc376ceec0981d8aa3d Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:24:46 +0800 Subject: [PATCH 110/278] Create README.md --- gradle-6/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 gradle-6/README.md diff --git a/gradle-6/README.md b/gradle-6/README.md new file mode 100644 index 0000000000..a1ea96ad83 --- /dev/null +++ b/gradle-6/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [What’s New in Gradle 6.0](https://www.baeldung.com/gradle-6-features) From 37e2cdbbc230e8f835c0364faee081079fe63da1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:26:35 +0800 Subject: [PATCH 111/278] Create README.md --- open-liberty/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 open-liberty/README.md diff --git a/open-liberty/README.md b/open-liberty/README.md new file mode 100644 index 0000000000..6a51d2c486 --- /dev/null +++ b/open-liberty/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Introduction to Open Liberty](https://www.baeldung.com/java-open-liberty) From 4616c3d389cae7e82ae5a4a36dbf85fe99f1099e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:28:15 +0800 Subject: [PATCH 112/278] Update README.md --- spring-boot-modules/spring-boot-bootstrap/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-bootstrap/README.md b/spring-boot-modules/spring-boot-bootstrap/README.md index 5fb8fd4a84..146cd04551 100644 --- a/spring-boot-modules/spring-boot-bootstrap/README.md +++ b/spring-boot-modules/spring-boot-bootstrap/README.md @@ -10,3 +10,4 @@ This module contains articles about bootstrapping Spring Boot applications. - [Deploy a Spring Boot Application to OpenShift](https://www.baeldung.com/spring-boot-deploy-openshift) - [Deploy a Spring Boot Application to AWS Beanstalk](https://www.baeldung.com/spring-boot-deploy-aws-beanstalk) - [Guide to @SpringBootConfiguration in Spring Boot](https://www.baeldung.com/springbootconfiguration-annotation) +- [Implement Health Checks in OpenShift](https://www.baeldung.com/openshift-health-checks) From c6ada1f61c4ca0df8a0ad9ef35c0dcec258d187f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:30:31 +0800 Subject: [PATCH 113/278] Update README.md --- spring-cloud/spring-cloud-gateway/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud/spring-cloud-gateway/README.md b/spring-cloud/spring-cloud-gateway/README.md index d3323947e8..9c8e0d443a 100644 --- a/spring-cloud/spring-cloud-gateway/README.md +++ b/spring-cloud/spring-cloud-gateway/README.md @@ -5,3 +5,4 @@ This module contains articles about Spring Cloud Gateway ### Relevant Articles: - [Exploring the new Spring Cloud Gateway](http://www.baeldung.com/spring-cloud-gateway) - [Writing Custom Spring Cloud Gateway Filters](https://www.baeldung.com/spring-cloud-custom-gateway-filters) +- [Spring Cloud Gateway Routing Predicate Factories](https://www.baeldung.com/spring-cloud-gateway-routing-predicate-factories) From 36c745ceb54d09828edbe6d289cb27e8403c41cd Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:34:56 +0800 Subject: [PATCH 114/278] Update README.md --- core-java-modules/core-java-string-operations-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-string-operations-2/README.md b/core-java-modules/core-java-string-operations-2/README.md index 8687ac19ba..5e92738f5c 100644 --- a/core-java-modules/core-java-string-operations-2/README.md +++ b/core-java-modules/core-java-string-operations-2/README.md @@ -10,4 +10,5 @@ This module contains articles about string operations. - [Java String equalsIgnoreCase()](https://www.baeldung.com/java-string-equalsignorecase) - [Case-Insensitive String Matching in Java](https://www.baeldung.com/java-case-insensitive-string-matching) - [L-Trim and R-Trim in Java](https://www.baeldung.com/l-trim-and-r-trim-in-java) +- [L-Trim and R-Trim Alternatives in Java](https://www.baeldung.com/java-trim-alternatives) - More articles: [[<-- prev]](../core-java-string-operations) From 0af09bf2c113b9e3321a51a72db3137c36b42380 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:36:41 +0800 Subject: [PATCH 115/278] Update README.md --- spring-boot-modules/spring-boot-properties/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-properties/README.md b/spring-boot-modules/spring-boot-properties/README.md index d8d9d0df48..f861a01d10 100644 --- a/spring-boot-modules/spring-boot-properties/README.md +++ b/spring-boot-modules/spring-boot-properties/README.md @@ -13,3 +13,4 @@ This module contains articles about Properties in Spring Boot. - [Using Spring @Value with Defaults](https://www.baeldung.com/spring-value-defaults) - [How to Inject a Property Value Into a Class Not Managed by Spring?](https://www.baeldung.com/inject-properties-value-non-spring-class) - [Add Build Properties to a Spring Boot Application](https://www.baeldung.com/spring-boot-build-properties) +- [IntelliJ – Cannot Resolve Spring Boot Configuration Properties Error](https://www.baeldung.com/intellij-resolve-spring-boot-configuration-properties) From 5c6c706a17b8b8f77c24eafc20deb04531dbc245 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:38:24 +0800 Subject: [PATCH 116/278] Update README.md --- gson/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gson/README.md b/gson/README.md index df6ba0f516..4255e2ead9 100644 --- a/gson/README.md +++ b/gson/README.md @@ -13,4 +13,4 @@ This module contains articles about Gson - [Convert String to JsonObject with Gson](https://www.baeldung.com/gson-string-to-jsonobject) - [Mapping Multiple JSON Fields to a Single Java Field](https://www.baeldung.com/json-multiple-fields-single-java-field) - [Serializing and Deserializing a List with Gson](https://www.baeldung.com/gson-list) - +- [Compare Two JSON Objects with Gson](https://www.baeldung.com/gson-compare-json-objects) From 4051cdcf173a812fb732a9552aa5b44268e1a661 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 13:39:59 +0800 Subject: [PATCH 117/278] Update README.md --- image-processing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/image-processing/README.md b/image-processing/README.md index 4417f312d8..50129bb994 100644 --- a/image-processing/README.md +++ b/image-processing/README.md @@ -5,3 +5,4 @@ This module contains articles about image processing. ### Relevant Articles: - [Working with Images in Java](https://www.baeldung.com/java-images) - [Intro to OpenCV with Java](https://www.baeldung.com/java-opencv) +- [Optical Character Recognition with Tesseract](https://www.baeldung.com/java-ocr-tesseract) From 53c9accfd679d26a59d56037b7090cbca35da2df Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:09:32 +0800 Subject: [PATCH 118/278] Create README.md --- core-java-modules/core-java-security-2/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 core-java-modules/core-java-security-2/README.md diff --git a/core-java-modules/core-java-security-2/README.md b/core-java-modules/core-java-security-2/README.md new file mode 100644 index 0000000000..c250e24078 --- /dev/null +++ b/core-java-modules/core-java-security-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Guide To The Java Authentication And Authorization Service (JAAS)](https://www.baeldung.com/java-authentication-authorization-service) From 087248c5e3c8922c54aa507072966ebde3367ceb Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:11:14 +0800 Subject: [PATCH 119/278] Update README.md --- persistence-modules/spring-data-redis/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/persistence-modules/spring-data-redis/README.md b/persistence-modules/spring-data-redis/README.md index e4a528ae91..175634376b 100644 --- a/persistence-modules/spring-data-redis/README.md +++ b/persistence-modules/spring-data-redis/README.md @@ -4,6 +4,7 @@ - [Introduction to Spring Data Redis](https://www.baeldung.com/spring-data-redis-tutorial) - [PubSub Messaging with Spring Data Redis](https://www.baeldung.com/spring-data-redis-pub-sub) - [An Introduction to Spring Data Redis Reactive](https://www.baeldung.com/spring-data-redis-reactive) +- [Delete Everything in Redis](https://www.baeldung.com/redis-delete-data) ### Build the Project with Tests Running ``` From ff4ac52b2ee71b2f9094428371d6bda192e26f6f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:12:43 +0800 Subject: [PATCH 120/278] Update README.md --- libraries/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries/README.md b/libraries/README.md index 79ba8fe55d..f439033730 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -45,4 +45,5 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client) - [Introduction to Functional Java](https://www.baeldung.com/java-functional-library) - [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) +- [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway) - More articles [[next -->]](/libraries-2) From f70e4a0563e6f766caa2978641b7ca00fa4e2681 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:14:13 +0800 Subject: [PATCH 121/278] Update README.md --- core-java-modules/core-java-regex/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-regex/README.md b/core-java-modules/core-java-regex/README.md index 7a8f6d9293..21cd7a95a3 100644 --- a/core-java-modules/core-java-regex/README.md +++ b/core-java-modules/core-java-regex/README.md @@ -8,3 +8,4 @@ - [Guide to Escaping Characters in Java RegExps](http://www.baeldung.com/java-regexp-escape-char) - [Pre-compile Regex Patterns Into Pattern Objects](https://www.baeldung.com/java-regex-pre-compile) - [Difference Between Java Matcher find() and matches()](https://www.baeldung.com/java-matcher-find-vs-matches) +- [How to Use Regular Expressions to Replace Tokens in Strings](https://www.baeldung.com/java-regex-token-replacement) From 6c32698f62e9f3042b0c2217643a608ad0a129d3 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:16:14 +0800 Subject: [PATCH 122/278] Update README.md --- spring-core-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-core-3/README.md b/spring-core-3/README.md index b064dc74d9..b2c4f694a8 100644 --- a/spring-core-3/README.md +++ b/spring-core-3/README.md @@ -9,4 +9,5 @@ This module contains articles about core Spring functionality - [How to use the Spring FactoryBean?](https://www.baeldung.com/spring-factorybean) - [Spring – Injecting Collections](https://www.baeldung.com/spring-injecting-collections) - [Design Patterns in the Spring Framework](https://www.baeldung.com/spring-framework-design-patterns) +- [Injecting a Value in a Static Field in Spring](https://www.baeldung.com/spring-inject-static-field) - More articles: [[<-- prev]](/spring-core-2) From eb8b2bb8b4fae22f1306e73454200f9b17f74781 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:17:32 +0800 Subject: [PATCH 123/278] Create README.md --- apache-beam/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 apache-beam/README.md diff --git a/apache-beam/README.md b/apache-beam/README.md new file mode 100644 index 0000000000..a71e5256a8 --- /dev/null +++ b/apache-beam/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Introduction to Apache Beam](https://www.baeldung.com/apache-beam) From 5b83d05a1fdfea16b9a333fc8f65a577c3c62cfa Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:19:41 +0800 Subject: [PATCH 124/278] Update README.md --- spring-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-5/README.md b/spring-5/README.md index 857b199562..d50f9c7544 100644 --- a/spring-5/README.md +++ b/spring-5/README.md @@ -16,3 +16,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Assert Statements](https://www.baeldung.com/spring-assert) - [Configuring a Hikari Connection Pool with Spring Boot](https://www.baeldung.com/spring-boot-hikari) - [Difference between \ vs \](https://www.baeldung.com/spring-contextannotation-contextcomponentscan) +- [Finding the Spring Version](https://www.baeldung.com/spring-find-version) From 0ea9f1644876d54d8436da5d626e070dcec282c8 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:21:53 +0800 Subject: [PATCH 125/278] Update README.md --- core-java-modules/core-java-perf/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-perf/README.md b/core-java-modules/core-java-perf/README.md index 4204c2b012..d52fd2d733 100644 --- a/core-java-modules/core-java-perf/README.md +++ b/core-java-modules/core-java-perf/README.md @@ -10,3 +10,4 @@ This module contains articles about performance of Java applications - [Basic Introduction to JMX](http://www.baeldung.com/java-management-extensions) - [Monitoring Java Applications with Flight Recorder](https://www.baeldung.com/java-flight-recorder-monitoring) - [Branch Prediction in Java](https://www.baeldung.com/java-branch-prediction) +- [Capturing a Java Thread Dump](https://www.baeldung.com/java-thread-dump) From 7494225aa8f284d1724a68943dbbf35b96495a95 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:23:00 +0800 Subject: [PATCH 126/278] Update README.md --- core-java-modules/core-java-14/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-14/README.md b/core-java-modules/core-java-14/README.md index 9ec20cd223..0e8278c4f6 100644 --- a/core-java-modules/core-java-14/README.md +++ b/core-java-modules/core-java-14/README.md @@ -6,3 +6,4 @@ This module contains articles about Java 14. - [Guide to the @Serial Annotation in Java 14](https://www.baeldung.com/java-14-serial-annotation) - [Java Text Blocks](https://www.baeldung.com/java-text-blocks) +- [Pattern Matching for instanceof in Java 14](https://www.baeldung.com/java-pattern-matching-instanceof) From 231a181804cf01ce979efd78b403aef7d3e428e5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:24:22 +0800 Subject: [PATCH 127/278] Update README.md --- spring-boot-modules/spring-boot-testing/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot-testing/README.md b/spring-boot-modules/spring-boot-testing/README.md index 0b2533e6bc..882e2be766 100644 --- a/spring-boot-modules/spring-boot-testing/README.md +++ b/spring-boot-modules/spring-boot-testing/README.md @@ -12,3 +12,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Exclude Auto-Configuration Classes in Spring Boot Tests](https://www.baeldung.com/spring-boot-exclude-auto-configuration-test) - [Setting the Log Level in Spring Boot when Testing](https://www.baeldung.com/spring-boot-testing-log-level) - [Embedded Redis Server with Spring Boot Test](https://www.baeldung.com/spring-embedded-redis) +- [Testing Spring Boot @ConfigurationProperties](https://www.baeldung.com/spring-boot-testing-configurationproperties) From 9cda688213788e7caf4bdc603d5bbb30fc6b950e Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:25:35 +0800 Subject: [PATCH 128/278] Update README.md --- algorithms-searching/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms-searching/README.md b/algorithms-searching/README.md index 9b85995235..aed3c7d21f 100644 --- a/algorithms-searching/README.md +++ b/algorithms-searching/README.md @@ -10,3 +10,4 @@ This module contains articles about searching algorithms. - [String Search Algorithms for Large Texts](https://www.baeldung.com/java-full-text-search-algorithms) - [Monte Carlo Tree Search for Tic-Tac-Toe Game](https://www.baeldung.com/java-monte-carlo-tree-search) - [Range Search Algorithm in Java](https://www.baeldung.com/java-range-search) +- [Fast Pattern Matching of Strings Using Suffix Tree](https://www.baeldung.com/java-pattern-matching-suffix-tree) From 803c8ddc990105649c306a4d6995160a484a2875 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:27:33 +0800 Subject: [PATCH 129/278] Update README.md --- core-java-modules/core-java-exceptions-2/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/core-java-exceptions-2/README.md b/core-java-modules/core-java-exceptions-2/README.md index 7ad951f1de..1b8457acc4 100644 --- a/core-java-modules/core-java-exceptions-2/README.md +++ b/core-java-modules/core-java-exceptions-2/README.md @@ -8,3 +8,4 @@ This module contains articles about core java exceptions - [Wrapping vs Rethrowing Exceptions in Java](https://www.baeldung.com/java-wrapping-vs-rethrowing-exceptions) - [java.net.UnknownHostException: Invalid Hostname for Server](https://www.baeldung.com/java-unknownhostexception) - [How to Handle Java SocketException](https://www.baeldung.com/java-socketexception) +- [Java Suppressed Exceptions](https://www.baeldung.com/java-suppressed-exceptions) From a494d8b0e5863c2005692a77cc9b57d74233a128 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:29:11 +0800 Subject: [PATCH 130/278] Update README.md --- libraries-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-3/README.md b/libraries-3/README.md index a5be14a349..0a76c7ff6e 100644 --- a/libraries-3/README.md +++ b/libraries-3/README.md @@ -13,3 +13,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Parsing Command-Line Parameters with Airline](https://www.baeldung.com/java-airline) - [Introduction to cache2k](https://www.baeldung.com/java-cache2k) - [Introduction to the jcabi-aspects AOP Annotations Library](https://www.baeldung.com/java-jcabi-aspects) +- [Introduction to Takes](https://www.baeldung.com/java-takes) From 3f1881176169f758c38cab8018bf2d6173a47139 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:31:33 +0800 Subject: [PATCH 131/278] Create README.md --- spring-ejb/ejb-beans/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 spring-ejb/ejb-beans/README.md diff --git a/spring-ejb/ejb-beans/README.md b/spring-ejb/ejb-beans/README.md new file mode 100644 index 0000000000..f1af5a3a87 --- /dev/null +++ b/spring-ejb/ejb-beans/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: + +- [Spring Bean vs. EJB – A Feature Comparison](https://www.baeldung.com/spring-bean-vs-ejb) From fa7b7266e6aadf8d2e43bca5e2b1470ee284db8b Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 18 Mar 2020 14:33:15 +0800 Subject: [PATCH 132/278] Update README.md --- ddd-modules/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ddd-modules/README.md b/ddd-modules/README.md index 5616cce48b..ba6b8d5016 100644 --- a/ddd-modules/README.md +++ b/ddd-modules/README.md @@ -1 +1,3 @@ -## Relevant Articles +### Relevant Articles: + +- [DDD Bounded Contexts and Java Modules](https://www.baeldung.com/java-modules-ddd-bounded-contexts) From 932eba6929119547d1843ebf9a88702338d67f44 Mon Sep 17 00:00:00 2001 From: kwoyke Date: Wed, 18 Mar 2020 07:44:23 +0100 Subject: [PATCH 133/278] BAEL-3921: Remove adding a redundant log handler (#8881) --- .../constructorsstaticfactorymethods/entities/User.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/patterns/design-patterns-creational/src/main/java/com/baeldung/constructorsstaticfactorymethods/entities/User.java b/patterns/design-patterns-creational/src/main/java/com/baeldung/constructorsstaticfactorymethods/entities/User.java index f05a3baaa3..a602d1c55d 100644 --- a/patterns/design-patterns-creational/src/main/java/com/baeldung/constructorsstaticfactorymethods/entities/User.java +++ b/patterns/design-patterns-creational/src/main/java/com/baeldung/constructorsstaticfactorymethods/entities/User.java @@ -19,8 +19,8 @@ public class User { } public static User createWithLoggedInstantiationTime(String name, String email, String country) { - setLoggerProperties(); LOGGER.log(Level.INFO, "Creating User instance at : {0}", LocalTime.now()); + return new User(name, email, country); } @@ -53,11 +53,4 @@ public class User { public String getCountry() { return country; } - - private static void setLoggerProperties() { - ConsoleHandler handler = new ConsoleHandler(); - handler.setLevel(Level.INFO); - handler.setFormatter(new SimpleFormatter()); - LOGGER.addHandler(handler); - } } From 0692bac979c756b7e8a6e9fd95f37a58233e3f05 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 18 Mar 2020 10:18:58 +0100 Subject: [PATCH 134/278] BAEL-3855 --- .../main/java/com/baeldung/concurrent/lock/SingleLock.java | 4 ++-- .../main/java/com/baeldung/concurrent/lock/StripedLock.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java index 19b3ba4510..4dff459df6 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/SingleLock.java @@ -14,8 +14,8 @@ public class SingleLock extends ConcurrentAccessExperiment { protected Supplier putSupplier(Map map, int key) { return (()-> { + lock.lock(); try { - lock.lock(); return map.put("key" + key, "value" + key); } finally { lock.unlock(); @@ -25,8 +25,8 @@ public class SingleLock extends ConcurrentAccessExperiment { protected Supplier getSupplier(Map map, int key) { return (()-> { + lock.lock(); try { - lock.lock(); return map.get("key" + key); } finally { lock.unlock(); diff --git a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java index 7adca428ba..47c47d8813 100644 --- a/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java +++ b/core-java-modules/core-java-concurrency-collections-2/src/main/java/com/baeldung/concurrent/lock/StripedLock.java @@ -17,8 +17,8 @@ public class StripedLock extends ConcurrentAccessExperiment { return (()-> { int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); + lock.lock(); try { - lock.lock(); return map.put("key" + key, "value" + key); } finally { lock.unlock(); @@ -30,8 +30,8 @@ public class StripedLock extends ConcurrentAccessExperiment { return (()-> { int bucket = key % stripedLock.size(); Lock lock = stripedLock.get(bucket); + lock.lock(); try { - lock.lock(); return map.get("key" + key); } finally { lock.unlock(); From dc03fa58712d786cb4d8a5ebc54569f6ec8524d9 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 18 Mar 2020 17:12:36 +0530 Subject: [PATCH 135/278] JAVA-626 : Moved extra articles to java-math-2 module --- java-math/README.md | 2 - .../algorithms/gcd/GCDImplementation.java | 55 ------------------- .../gcd/GCDImplementationUnitTest.java | 32 ----------- .../logarithm/LogarithmUnitTest.java | 31 ----------- 4 files changed, 120 deletions(-) delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java diff --git a/java-math/README.md b/java-math/README.md index d80a07258a..49ff5afde1 100644 --- a/java-math/README.md +++ b/java-math/README.md @@ -14,5 +14,3 @@ This module contains articles about math in Java. - [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) - [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging) - [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication) -- [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms) -- [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor) diff --git a/java-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java b/java-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java deleted file mode 100644 index d4844abd9c..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.baeldung.algorithms.gcd; - -public class GCDImplementation { - - public static int gcdByBruteForce(int n1, int n2) { - int gcd = 1; - for (int i = 1; i <= n1 && i <= n2; i++) { - if (n1 % i == 0 && n2 % i == 0) { - gcd = i; - } - } - return gcd; - } - - public static int gcdByEuclidsAlgorithm(int n1, int n2) { - if (n2 == 0) { - return n1; - } - return gcdByEuclidsAlgorithm(n2, n1 % n2); - } - - public static int gcdBySteinsAlgorithm(int n1, int n2) { - if (n1 == 0) { - return n2; - } - - if (n2 == 0) { - return n1; - } - - int n; - for (n = 0; ((n1 | n2) & 1) == 0; n++) { - n1 >>= 1; - n2 >>= 1; - } - - while ((n1 & 1) == 0) { - n1 >>= 1; - } - - do { - while ((n2 & 1) == 0) { - n2 >>= 1; - } - - if (n1 > n2) { - int temp = n1; - n1 = n2; - n2 = temp; - } - n2 = (n2 - n1); - } while (n2 != 0); - return n1 << n; - } -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java deleted file mode 100644 index d2c91a2eb8..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.algorithms.gcd; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GCDImplementationUnitTest { - - @Test - public void whenCalculatingGCDByBruteForceMethod_thenCorrect() { - int n1 = 60; - int n2 = 90; - int gcd = GCDImplementation.gcdByBruteForce(n1, n2); - assertThat(gcd).isEqualTo(30); - } - - @Test - public void whenCalculatingGCDByEuclidsAlgorithm_thenCorrect() { - int n1 = 60; - int n2 = 90; - int gcd = GCDImplementation.gcdByEuclidsAlgorithm(n1, n2); - assertThat(gcd).isEqualTo(30); - } - - @Test - public void whenCalculatingGCDBySteinsAlgorithm_thenCorrect() { - int n1 = 60; - int n2 = 90; - int gcd = GCDImplementation.gcdBySteinsAlgorithm(n1, n2); - assertThat(gcd).isEqualTo(30); - } -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java deleted file mode 100644 index facad1edc4..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.algorithms.logarithm; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.Test; - -public class LogarithmUnitTest { - - @Test - public void givenLog10_shouldReturnValidResults() { - assertEquals(Math.log10(100), 2); - assertEquals(Math.log10(1000), 3); - } - - @Test - public void givenLogE_shouldReturnValidResults() { - assertEquals(Math.log(Math.E), 1); - assertEquals(Math.log(10), 2.30258, 0.00001); - } - - @Test - public void givenCustomLog_shouldReturnValidResults() { - assertEquals(customLog(2, 256), 8); - assertEquals(customLog(10, 100), 2); - } - - private static double customLog(double base, double logNumber) { - return Math.log(logNumber) / Math.log(base); - } - -} From 3ff81a894315d4553354d40c7c6589aeb3bdc817 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 18 Mar 2020 17:13:37 +0530 Subject: [PATCH 136/278] JAVA-626 : Moved extra articles from java-math module --- java-math-2/README.md | 3 +- java-math-2/pom.xml | 14 +++++ .../algorithms/gcd/GCDImplementation.java | 55 +++++++++++++++++++ .../gcd/GCDImplementationUnitTest.java | 32 +++++++++++ .../logarithm/LogarithmUnitTest.java | 31 +++++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java create mode 100644 java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java create mode 100644 java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java diff --git a/java-math-2/README.md b/java-math-2/README.md index ca809e8623..5345564d5d 100644 --- a/java-math-2/README.md +++ b/java-math-2/README.md @@ -4,5 +4,6 @@ This module contains articles about math in Java. ### Relevant articles: -- [Basic Calculator in Java](https://www.baeldung.com/basic-calculator-in-java) +- [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms) +- [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor) - More articles: [[<-- prev]](/../java-math) diff --git a/java-math-2/pom.xml b/java-math-2/pom.xml index e22dcc2b31..7bc05a3a86 100644 --- a/java-math-2/pom.xml +++ b/java-math-2/pom.xml @@ -12,4 +12,18 @@ 1.0.0-SNAPSHOT + + + org.assertj + assertj-core + ${org.assertj.core.version} + test + + + + + + 3.9.0 + + \ No newline at end of file diff --git a/java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java b/java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java new file mode 100644 index 0000000000..d4844abd9c --- /dev/null +++ b/java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java @@ -0,0 +1,55 @@ +package com.baeldung.algorithms.gcd; + +public class GCDImplementation { + + public static int gcdByBruteForce(int n1, int n2) { + int gcd = 1; + for (int i = 1; i <= n1 && i <= n2; i++) { + if (n1 % i == 0 && n2 % i == 0) { + gcd = i; + } + } + return gcd; + } + + public static int gcdByEuclidsAlgorithm(int n1, int n2) { + if (n2 == 0) { + return n1; + } + return gcdByEuclidsAlgorithm(n2, n1 % n2); + } + + public static int gcdBySteinsAlgorithm(int n1, int n2) { + if (n1 == 0) { + return n2; + } + + if (n2 == 0) { + return n1; + } + + int n; + for (n = 0; ((n1 | n2) & 1) == 0; n++) { + n1 >>= 1; + n2 >>= 1; + } + + while ((n1 & 1) == 0) { + n1 >>= 1; + } + + do { + while ((n2 & 1) == 0) { + n2 >>= 1; + } + + if (n1 > n2) { + int temp = n1; + n1 = n2; + n2 = temp; + } + n2 = (n2 - n1); + } while (n2 != 0); + return n1 << n; + } +} diff --git a/java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java b/java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java new file mode 100644 index 0000000000..d2c91a2eb8 --- /dev/null +++ b/java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.algorithms.gcd; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GCDImplementationUnitTest { + + @Test + public void whenCalculatingGCDByBruteForceMethod_thenCorrect() { + int n1 = 60; + int n2 = 90; + int gcd = GCDImplementation.gcdByBruteForce(n1, n2); + assertThat(gcd).isEqualTo(30); + } + + @Test + public void whenCalculatingGCDByEuclidsAlgorithm_thenCorrect() { + int n1 = 60; + int n2 = 90; + int gcd = GCDImplementation.gcdByEuclidsAlgorithm(n1, n2); + assertThat(gcd).isEqualTo(30); + } + + @Test + public void whenCalculatingGCDBySteinsAlgorithm_thenCorrect() { + int n1 = 60; + int n2 = 90; + int gcd = GCDImplementation.gcdBySteinsAlgorithm(n1, n2); + assertThat(gcd).isEqualTo(30); + } +} diff --git a/java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java b/java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java new file mode 100644 index 0000000000..facad1edc4 --- /dev/null +++ b/java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.algorithms.logarithm; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + +public class LogarithmUnitTest { + + @Test + public void givenLog10_shouldReturnValidResults() { + assertEquals(Math.log10(100), 2); + assertEquals(Math.log10(1000), 3); + } + + @Test + public void givenLogE_shouldReturnValidResults() { + assertEquals(Math.log(Math.E), 1); + assertEquals(Math.log(10), 2.30258, 0.00001); + } + + @Test + public void givenCustomLog_shouldReturnValidResults() { + assertEquals(customLog(2, 256), 8); + assertEquals(customLog(10, 100), 2); + } + + private static double customLog(double base, double logNumber) { + return Math.log(logNumber) / Math.log(base); + } + +} From 52822b7c226f215b8790eae6776281f6a01a71be Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Wed, 18 Mar 2020 11:41:11 +0100 Subject: [PATCH 137/278] [JAVA-963] Added parent pom to jhipster-5/bookstore-monolith and renamed tests according to conventions (*Test -> *UnitTest, *IntTest -> *IntegrationTest) --- jhipster-5/bookstore-monolith/pom.xml | 6 ++++++ ...bConfigurerTest.java => WebConfigurerUnitTest.java} | 10 +++++----- ...oller.java => WebConfigurerUnitTestController.java} | 2 +- ... => CustomAuditEventRepositoryIntegrationTest.java} | 2 +- ...va => DomainUserDetailsServiceIntegrationTest.java} | 2 +- .../jwt/{JWTFilterTest.java => JWTFilterUnitTest.java} | 2 +- ...kenProviderTest.java => TokenProviderUnitTest.java} | 2 +- ...iceIntTest.java => MailServiceIntegrationTest.java} | 2 +- ...iceIntTest.java => UserServiceIntegrationTest.java} | 2 +- .../{UserMapperTest.java => UserMapperUnitTest.java} | 2 +- ...ntTest.java => AccountResourceIntegrationTest.java} | 2 +- ...eIntTest.java => AuditResourceIntegrationTest.java} | 2 +- ...ceIntTest.java => BookResourceIntegrationTest.java} | 2 +- ...ceIntTest.java => LogsResourceIntegrationTest.java} | 2 +- ...Test.java => UserJWTControllerIntegrationTest.java} | 2 +- ...ceIntTest.java => UserResourceIntegrationTest.java} | 2 +- ...st.java => ExceptionTranslatorIntegrationTest.java} | 2 +- 17 files changed, 26 insertions(+), 20 deletions(-) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/{WebConfigurerTest.java => WebConfigurerUnitTest.java} (97%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/{WebConfigurerTestController.java => WebConfigurerUnitTestController.java} (87%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/repository/{CustomAuditEventRepositoryIntTest.java => CustomAuditEventRepositoryIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/{DomainUserDetailsServiceIntTest.java => DomainUserDetailsServiceIntegrationTest.java} (98%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/{JWTFilterTest.java => JWTFilterUnitTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/{TokenProviderTest.java => TokenProviderUnitTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/{MailServiceIntTest.java => MailServiceIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/{UserServiceIntTest.java => UserServiceIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/mapper/{UserMapperTest.java => UserMapperUnitTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/{AccountResourceIntTest.java => AccountResourceIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/{AuditResourceIntTest.java => AuditResourceIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/{BookResourceIntTest.java => BookResourceIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/{LogsResourceIntTest.java => LogsResourceIntegrationTest.java} (98%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/{UserJWTControllerIntTest.java => UserJWTControllerIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/{UserResourceIntTest.java => UserResourceIntegrationTest.java} (99%) rename jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/errors/{ExceptionTranslatorIntTest.java => ExceptionTranslatorIntegrationTest.java} (99%) diff --git a/jhipster-5/bookstore-monolith/pom.xml b/jhipster-5/bookstore-monolith/pom.xml index 60fc1acf92..5eaf761921 100644 --- a/jhipster-5/bookstore-monolith/pom.xml +++ b/jhipster-5/bookstore-monolith/pom.xml @@ -7,6 +7,12 @@ 0.0.1-SNAPSHOT war Bookstore + + + jhipster-5 + com.baeldung.jhipster + 1.0.0-SNAPSHOT + diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerUnitTest.java similarity index 97% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerUnitTest.java index 670042d2df..764d6b3587 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerUnitTest.java @@ -37,7 +37,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. * * @see WebConfigurer */ -public class WebConfigurerTest { +public class WebConfigurerUnitTest { private WebConfigurer webConfigurer; @@ -116,7 +116,7 @@ public class WebConfigurerTest { props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); - MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) + MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController()) .addFilters(webConfigurer.corsFilter()) .build(); @@ -146,7 +146,7 @@ public class WebConfigurerTest { props.getCors().setMaxAge(1800L); props.getCors().setAllowCredentials(true); - MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) + MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController()) .addFilters(webConfigurer.corsFilter()) .build(); @@ -161,7 +161,7 @@ public class WebConfigurerTest { public void testCorsFilterDeactivated() throws Exception { props.getCors().setAllowedOrigins(null); - MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) + MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController()) .addFilters(webConfigurer.corsFilter()) .build(); @@ -176,7 +176,7 @@ public class WebConfigurerTest { public void testCorsFilterDeactivated2() throws Exception { props.getCors().setAllowedOrigins(new ArrayList<>()); - MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()) + MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerUnitTestController()) .addFilters(webConfigurer.corsFilter()) .build(); diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerTestController.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerUnitTestController.java similarity index 87% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerTestController.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerUnitTestController.java index c19b28ea16..ee72e1c80e 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerTestController.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/config/WebConfigurerUnitTestController.java @@ -4,7 +4,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController -public class WebConfigurerTestController { +public class WebConfigurerUnitTestController { @GetMapping("/api/test-cors") public void testCorsOnApiPath() { diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/repository/CustomAuditEventRepositoryIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/repository/CustomAuditEventRepositoryIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/repository/CustomAuditEventRepositoryIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/repository/CustomAuditEventRepositoryIntegrationTest.java index eaf5c07504..948bf43f87 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/repository/CustomAuditEventRepositoryIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/repository/CustomAuditEventRepositoryIntegrationTest.java @@ -33,7 +33,7 @@ import static com.baeldung.jhipster5.repository.CustomAuditEventRepository.EVENT @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) @Transactional -public class CustomAuditEventRepositoryIntTest { +public class CustomAuditEventRepositoryIntegrationTest { @Autowired private PersistenceAuditEventRepository persistenceAuditEventRepository; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/DomainUserDetailsServiceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/DomainUserDetailsServiceIntegrationTest.java similarity index 98% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/DomainUserDetailsServiceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/DomainUserDetailsServiceIntegrationTest.java index f11252de2b..11757f6516 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/DomainUserDetailsServiceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/DomainUserDetailsServiceIntegrationTest.java @@ -28,7 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) @Transactional -public class DomainUserDetailsServiceIntTest { +public class DomainUserDetailsServiceIntegrationTest { private static final String USER_ONE_LOGIN = "test-user-one"; private static final String USER_ONE_EMAIL = "test-user-one@localhost"; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/JWTFilterTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/JWTFilterUnitTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/JWTFilterTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/JWTFilterUnitTest.java index b3de21819b..2be8e6809a 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/JWTFilterTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/JWTFilterUnitTest.java @@ -20,7 +20,7 @@ import java.util.Collections; import static org.assertj.core.api.Assertions.assertThat; -public class JWTFilterTest { +public class JWTFilterUnitTest { private TokenProvider tokenProvider; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/TokenProviderTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/TokenProviderUnitTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/TokenProviderTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/TokenProviderUnitTest.java index 11fcfddbf9..18da2eb875 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/TokenProviderTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/security/jwt/TokenProviderUnitTest.java @@ -22,7 +22,7 @@ import io.jsonwebtoken.security.Keys; import static org.assertj.core.api.Assertions.assertThat; -public class TokenProviderTest { +public class TokenProviderUnitTest { private final long ONE_MINUTE = 60000; private Key key; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/MailServiceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/MailServiceIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/MailServiceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/MailServiceIntegrationTest.java index 4bde3276f5..72592e1239 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/MailServiceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/MailServiceIntegrationTest.java @@ -31,7 +31,7 @@ import static org.mockito.Mockito.*; @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class MailServiceIntTest { +public class MailServiceIntegrationTest { @Autowired private JHipsterProperties jHipsterProperties; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/UserServiceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/UserServiceIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/UserServiceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/UserServiceIntegrationTest.java index 81034c2793..ca3608462d 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/UserServiceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/UserServiceIntegrationTest.java @@ -38,7 +38,7 @@ import static org.mockito.Mockito.when; @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) @Transactional -public class UserServiceIntTest { +public class UserServiceIntegrationTest { @Autowired private UserRepository userRepository; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/mapper/UserMapperTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/mapper/UserMapperUnitTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/mapper/UserMapperTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/mapper/UserMapperUnitTest.java index 3d66fa5813..cd6a326c06 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/mapper/UserMapperTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/service/mapper/UserMapperUnitTest.java @@ -26,7 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat; */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class UserMapperTest { +public class UserMapperUnitTest { private static final String DEFAULT_LOGIN = "johndoe"; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AccountResourceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AccountResourceIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AccountResourceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AccountResourceIntegrationTest.java index 6db284a87f..f591b7ecbf 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AccountResourceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AccountResourceIntegrationTest.java @@ -49,7 +49,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class AccountResourceIntTest { +public class AccountResourceIntegrationTest { @Autowired private UserRepository userRepository; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AuditResourceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AuditResourceIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AuditResourceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AuditResourceIntegrationTest.java index c3b91ab390..05d8f9d503 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AuditResourceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/AuditResourceIntegrationTest.java @@ -35,7 +35,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) @Transactional -public class AuditResourceIntTest { +public class AuditResourceIntegrationTest { private static final String SAMPLE_PRINCIPAL = "SAMPLE_PRINCIPAL"; private static final String SAMPLE_TYPE = "SAMPLE_TYPE"; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/BookResourceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/BookResourceIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/BookResourceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/BookResourceIntegrationTest.java index ef8f27ceea..4f5cb25cdb 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/BookResourceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/BookResourceIntegrationTest.java @@ -43,7 +43,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class BookResourceIntTest { +public class BookResourceIntegrationTest { private static final String DEFAULT_TITLE = "AAAAAAAAAA"; private static final String UPDATED_TITLE = "BBBBBBBBBB"; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/LogsResourceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/LogsResourceIntegrationTest.java similarity index 98% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/LogsResourceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/LogsResourceIntegrationTest.java index 62f7f3f17c..b045f52f87 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/LogsResourceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/LogsResourceIntegrationTest.java @@ -27,7 +27,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class LogsResourceIntTest { +public class LogsResourceIntegrationTest { private MockMvc restLogsMockMvc; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserJWTControllerIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserJWTControllerIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserJWTControllerIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserJWTControllerIntegrationTest.java index 3886710438..7cfc0e19fc 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserJWTControllerIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserJWTControllerIntegrationTest.java @@ -33,7 +33,7 @@ import static org.hamcrest.Matchers.not; */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class UserJWTControllerIntTest { +public class UserJWTControllerIntegrationTest { @Autowired private TokenProvider tokenProvider; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserResourceIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserResourceIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserResourceIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserResourceIntegrationTest.java index d31df3b15c..c0abc042fb 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserResourceIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/UserResourceIntegrationTest.java @@ -42,7 +42,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class UserResourceIntTest { +public class UserResourceIntegrationTest { private static final String DEFAULT_LOGIN = "johndoe"; private static final String UPDATED_LOGIN = "jhipster"; diff --git a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/errors/ExceptionTranslatorIntTest.java b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/errors/ExceptionTranslatorIntegrationTest.java similarity index 99% rename from jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/errors/ExceptionTranslatorIntTest.java rename to jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/errors/ExceptionTranslatorIntegrationTest.java index a94d54063b..e5ef08ee9c 100644 --- a/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/errors/ExceptionTranslatorIntTest.java +++ b/jhipster-5/bookstore-monolith/src/test/java/com/baeldung/jhipster5/web/rest/errors/ExceptionTranslatorIntegrationTest.java @@ -25,7 +25,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers. */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookstoreApp.class) -public class ExceptionTranslatorIntTest { +public class ExceptionTranslatorIntegrationTest { @Autowired private ExceptionTranslatorTestController controller; From 89e04a58fdc4238d49342ca7284a7a34f6284d1c Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 18 Mar 2020 15:05:59 +0100 Subject: [PATCH 138/278] BAEL-3931: Use httpS://repo.spring.io --- parent-kotlin/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parent-kotlin/pom.xml b/parent-kotlin/pom.xml index e3d67eaaf2..52a753439c 100644 --- a/parent-kotlin/pom.xml +++ b/parent-kotlin/pom.xml @@ -31,7 +31,7 @@ spring-milestone Spring Milestone Repository - http://repo.spring.io/milestone + https://repo.spring.io/milestone From 9d2472839fc9a9e6e9f010eac0dc07a3dacd4008 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Wed, 18 Mar 2020 15:11:59 +0100 Subject: [PATCH 139/278] BAEL-3931: Migrate FuelHttpUnitTest to FuelHttpLiveTest --- .../fuel/{FuelHttpUnitTest.kt => FuelHttpLiveTest.kt} | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) rename kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/{FuelHttpUnitTest.kt => FuelHttpLiveTest.kt} (97%) diff --git a/kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpUnitTest.kt b/kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpLiveTest.kt similarity index 97% rename from kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpUnitTest.kt rename to kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpLiveTest.kt index b7993c5f43..69b6ae88c6 100644 --- a/kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpUnitTest.kt +++ b/kotlin-libraries-2/src/test/kotlin/com/baeldung/fuel/FuelHttpLiveTest.kt @@ -12,7 +12,11 @@ import org.junit.jupiter.api.Test import java.io.File import java.util.concurrent.CountDownLatch -internal class FuelHttpUnitTest { +/** + * These live tests make connections to the external systems: http://httpbin.org, https://jsonplaceholder.typicode.com + * Make sure these hosts are up and your internet connection is on before running the tests. + */ +internal class FuelHttpLiveTest { @Test fun whenMakingAsyncHttpGetRequest_thenResponseNotNullAndErrorNullAndStatusCode200() { From 42b945ce7353eb38007663e30b477ae5925f816a Mon Sep 17 00:00:00 2001 From: chirag d Date: Wed, 18 Mar 2020 22:41:58 +0530 Subject: [PATCH 140/278] BAEL3901 Changed the module --- .../spring-security-clear-site-data/pom.xml | 54 ------------------- .../spring-security-mvc/pom.xml | 27 ++++++++++ .../LogoutClearSiteDataController.java | 2 +- .../clearsitedata}/SpringSecurityConfig.java | 2 +- .../baeldung/clearsitedata}/WebConfig.java | 4 +- ...LogoutClearSiteDataControllerUnitTest.java | 2 +- 6 files changed, 32 insertions(+), 59 deletions(-) delete mode 100644 spring-security-modules/spring-security-clear-site-data/pom.xml rename spring-security-modules/{spring-security-clear-site-data/src/main/java/com/baeldung => spring-security-mvc/src/main/java/com/baeldung/clearsitedata}/LogoutClearSiteDataController.java (92%) rename spring-security-modules/{spring-security-clear-site-data/src/main/java/com/baeldung => spring-security-mvc/src/main/java/com/baeldung/clearsitedata}/SpringSecurityConfig.java (97%) rename spring-security-modules/{spring-security-clear-site-data/src/main/java/com/baeldung => spring-security-mvc/src/main/java/com/baeldung/clearsitedata}/WebConfig.java (88%) rename spring-security-modules/{spring-security-clear-site-data/src/test/java/com/baeldung => spring-security-mvc/src/test/java/com/baeldung/clearsitedata}/LogoutClearSiteDataControllerUnitTest.java (98%) diff --git a/spring-security-modules/spring-security-clear-site-data/pom.xml b/spring-security-modules/spring-security-clear-site-data/pom.xml deleted file mode 100644 index e58debc0aa..0000000000 --- a/spring-security-modules/spring-security-clear-site-data/pom.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - 4.0.0 - - com.baeldung - spring-security-clear-site-data - 1.0-SNAPSHOT - spring-security-clear-site-data - - - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 - - - - - org.springframework.security - spring-security-web - ${spring.mvc.version} - - - org.springframework.security - spring-security-config - ${spring.mvc.version} - - - org.springframework.security - spring-security-test - ${spring.mvc.version} - test - - - org.springframework - spring-webmvc - ${spring.mvc.version} - - - javax.servlet - javax.servlet-api - ${javax.version} - - - - - - 5.2.2.RELEASE - 4.0.1 - - - diff --git a/spring-security-modules/spring-security-mvc/pom.xml b/spring-security-modules/spring-security-mvc/pom.xml index 7da047707a..517aa83270 100644 --- a/spring-security-modules/spring-security-mvc/pom.xml +++ b/spring-security-modules/spring-security-mvc/pom.xml @@ -64,9 +64,36 @@ org.springframework.security spring-security-test + ${spring.mvc.version} test + + org.springframework.security + spring-security-web + ${spring.mvc.version} + + + org.springframework.security + spring-security-config + ${spring.mvc.version} + + + org.springframework + spring-webmvc + ${spring.mvc.version} + + + javax.servlet + javax.servlet-api + ${javax.version} + + + + 5.2.2.RELEASE + 4.0.1 + + diff --git a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/LogoutClearSiteDataController.java b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java similarity index 92% rename from spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/LogoutClearSiteDataController.java rename to spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java index d27fa18116..fcf78ac82f 100644 --- a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/LogoutClearSiteDataController.java +++ b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/LogoutClearSiteDataController.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.clearsitedata; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; diff --git a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/SpringSecurityConfig.java b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java similarity index 97% rename from spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/SpringSecurityConfig.java rename to spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java index fd43fb2c9e..13011da9e4 100644 --- a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/SpringSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/SpringSecurityConfig.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.clearsitedata; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/WebConfig.java b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/WebConfig.java similarity index 88% rename from spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/WebConfig.java rename to spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/WebConfig.java index 16826e28b8..a523efa554 100644 --- a/spring-security-modules/spring-security-clear-site-data/src/main/java/com/baeldung/WebConfig.java +++ b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/clearsitedata/WebConfig.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.clearsitedata; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -14,6 +14,6 @@ import java.util.concurrent.TimeUnit; @EnableWebMvc @Configuration -@ComponentScan(basePackages = {"com.baeldung"}) +@ComponentScan(basePackages = {"com.baeldung.clearsitedata"}) public class WebConfig implements WebMvcConfigurer { } \ No newline at end of file diff --git a/spring-security-modules/spring-security-clear-site-data/src/test/java/com/baeldung/LogoutClearSiteDataControllerUnitTest.java b/spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java similarity index 98% rename from spring-security-modules/spring-security-clear-site-data/src/test/java/com/baeldung/LogoutClearSiteDataControllerUnitTest.java rename to spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java index 905a866413..30036eea89 100644 --- a/spring-security-modules/spring-security-clear-site-data/src/test/java/com/baeldung/LogoutClearSiteDataControllerUnitTest.java +++ b/spring-security-modules/spring-security-mvc/src/test/java/com/baeldung/clearsitedata/LogoutClearSiteDataControllerUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung; +package com.baeldung.clearsitedata; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; From 108cca4b4ba5b34c03d7ac41e841609b87f42089 Mon Sep 17 00:00:00 2001 From: chirag d Date: Wed, 18 Mar 2020 22:46:35 +0530 Subject: [PATCH 141/278] BAEL3901 updated pom to remove module --- spring-security-modules/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-security-modules/pom.xml b/spring-security-modules/pom.xml index 07c326c10e..49a0db03ed 100644 --- a/spring-security-modules/pom.xml +++ b/spring-security-modules/pom.xml @@ -17,7 +17,6 @@ spring-security-acl spring-security-angular/server spring-security-cache-control - spring-security-clear-site-data spring-security-core spring-security-cors spring-security-kerberos From 89a3f70befcc878f747f62c8e9ca0a5db8c937cd Mon Sep 17 00:00:00 2001 From: Loredana Date: Wed, 18 Mar 2020 20:22:39 +0200 Subject: [PATCH 142/278] disable jee tests - fixing in BAEL-3812 --- .../baeldung/batch/understanding/CustomCheckPointUnitTest.java | 2 ++ .../com/baeldung/batch/understanding/JobSequenceUnitTest.java | 2 ++ .../com/baeldung/batch/understanding/SimpleChunkUnitTest.java | 2 ++ 3 files changed, 6 insertions(+) diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java index dfea878a75..744bdfc8f5 100644 --- a/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/CustomCheckPointUnitTest.java @@ -12,7 +12,9 @@ import javax.batch.runtime.StepExecution; import com.baeldung.batch.understanding.BatchTestHelper; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Disabled; +@Disabled("Should be fixed in BAEL-3812") class CustomCheckPointUnitTest { @Test public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception { diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java index 7c5e8d0b78..88b981df92 100644 --- a/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/JobSequenceUnitTest.java @@ -13,7 +13,9 @@ import javax.batch.runtime.JobExecution; import javax.batch.runtime.StepExecution; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Disabled; +@Disabled("Should be fixed in BAEL-3812") class JobSequenceUnitTest { @Test public void givenTwoSteps_thenBatch_CompleteWithSuccess() throws Exception { diff --git a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java index 57c794ba00..5871143fa3 100644 --- a/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java +++ b/jee-7/src/test/java/com/baeldung/batch/understanding/SimpleChunkUnitTest.java @@ -14,7 +14,9 @@ import javax.batch.runtime.Metric; import javax.batch.runtime.StepExecution; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Disabled; +@Disabled("Should be fixed in BAEL-3812") class SimpleChunkUnitTest { @Test public void givenChunk_thenBatch_CompletesWithSucess() throws Exception { From cccec36753a22739b4af34d48da41d6c1f0a94a6 Mon Sep 17 00:00:00 2001 From: mikr Date: Wed, 18 Mar 2020 20:05:41 +0100 Subject: [PATCH 143/278] JAVA-841 Update commented section in pom file --- spring-security-modules/spring-security-mvc-boot-1/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-modules/spring-security-mvc-boot-1/pom.xml b/spring-security-modules/spring-security-mvc-boot-1/pom.xml index 476159f306..7ad18376ec 100644 --- a/spring-security-modules/spring-security-mvc-boot-1/pom.xml +++ b/spring-security-modules/spring-security-mvc-boot-1/pom.xml @@ -225,7 +225,7 @@ com.baeldung.roles.custom.Application - + 1.1.2 1.6.1 From a7e146e5d17c7602849e68a5636e3c83c67b2e1f Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Wed, 18 Mar 2020 21:04:46 +0100 Subject: [PATCH 144/278] JAVA-86: Add spring-boot-basic-customization to the pom.xml --- spring-boot-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index c8d153d4bb..228e7ce481 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -20,6 +20,7 @@ spring-boot-annotations spring-boot-artifacts spring-boot-autoconfiguration + spring-boot-basic-customization spring-boot-bootstrap spring-boot-client spring-boot-config-jpa-error From a94b56c74eaac631cff61b372da9cf2ace69493b Mon Sep 17 00:00:00 2001 From: petershatunov Date: Thu, 19 Mar 2020 00:00:37 +0300 Subject: [PATCH 145/278] lazy_load_no_trans init commit (#8736) * lazy_load_no_trans init commit * refactoring * methods naming * Update persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java Co-Authored-By: KevinGilmore * Update persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java Co-Authored-By: KevinGilmore * Update persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOffIntegrationTest.java Co-Authored-By: KevinGilmore * naming * code readability Co-authored-by: admin Co-authored-by: KevinGilmore --- .../spring-boot-persistence-h2/pom.xml | 18 +++++ .../LazyLoadNoTransSpringBootApplication.java | 13 ++++ .../DatasourceProxyBeanPostProcessor.java | 67 +++++++++++++++++++ .../lazy_load_no_trans/entity/Document.java | 26 +++++++ .../h2db/lazy_load_no_trans/entity/User.java | 37 ++++++++++ .../repository/UserRepository.java | 9 +++ .../service/ServiceLayer.java | 34 ++++++++++ ...lication-lazy-load-no-trans-off.properties | 13 ++++ ...plication-lazy-load-no-trans-on.properties | 13 ++++ .../src/main/resources/data.sql | 15 ++++- ...LoadNoTransPropertyOffIntegrationTest.java | 41 ++++++++++++ ...yLoadNoTransPropertyOnIntegrationTest.java | 47 +++++++++++++ 12 files changed, 332 insertions(+), 1 deletion(-) create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/LazyLoadNoTransSpringBootApplication.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/config/DatasourceProxyBeanPostProcessor.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/Document.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/User.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/repository/UserRepository.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/service/ServiceLayer.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties create mode 100644 persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties create mode 100644 persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOffIntegrationTest.java create mode 100644 persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java diff --git a/persistence-modules/spring-boot-persistence-h2/pom.xml b/persistence-modules/spring-boot-persistence-h2/pom.xml index 5b5e255211..777bc6cb2d 100644 --- a/persistence-modules/spring-boot-persistence-h2/pom.xml +++ b/persistence-modules/spring-boot-persistence-h2/pom.xml @@ -29,12 +29,30 @@ com.h2database h2 + + org.projectlombok + lombok + ${lombok.version} + compile + + + org.hibernate + hibernate-core + ${hibernate.version} + + + com.vladmihalcea + db-util + ${db-util.version} + com.baeldung.h2db.demo.server.SpringBootApp 2.0.4.RELEASE + 5.3.11.Final + 1.0.4 diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/LazyLoadNoTransSpringBootApplication.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/LazyLoadNoTransSpringBootApplication.java new file mode 100644 index 0000000000..a52d9fc2f9 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/LazyLoadNoTransSpringBootApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.h2db.lazy_load_no_trans; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@SpringBootApplication +@EnableTransactionManagement +public class LazyLoadNoTransSpringBootApplication { + public static void main(String[] args) { + SpringApplication.run(LazyLoadNoTransSpringBootApplication.class, args); + } +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/config/DatasourceProxyBeanPostProcessor.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/config/DatasourceProxyBeanPostProcessor.java new file mode 100644 index 0000000000..c087427b65 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/config/DatasourceProxyBeanPostProcessor.java @@ -0,0 +1,67 @@ +package com.baeldung.h2db.lazy_load_no_trans.config; + +import net.ttddyy.dsproxy.listener.DataSourceQueryCountListener; +import net.ttddyy.dsproxy.listener.logging.CommonsQueryLoggingListener; +import net.ttddyy.dsproxy.listener.logging.DefaultQueryLogEntryCreator; +import net.ttddyy.dsproxy.listener.logging.SLF4JLogLevel; +import net.ttddyy.dsproxy.listener.logging.SLF4JQueryLoggingListener; +import net.ttddyy.dsproxy.support.ProxyDataSource; +import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.stereotype.Component; +import org.springframework.util.ReflectionUtils; + +import javax.sql.DataSource; +import java.lang.reflect.Method; + +@Component +public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) { + if (bean instanceof DataSource && !(bean instanceof ProxyDataSource)) { + // Instead of directly returning a less specific datasource bean + // (e.g.: HikariDataSource -> DataSource), return a proxy object. + // See following links for why: + // https://stackoverflow.com/questions/44237787/how-to-use-user-defined-database-proxy-in-datajpatest + // https://gitter.im/spring-projects/spring-boot?at=5983602d2723db8d5e70a904 + // http://blog.arnoldgalovics.com/2017/06/26/configuring-a-datasource-proxy-in-spring-boot/ + final ProxyFactory factory = new ProxyFactory(bean); + factory.setProxyTargetClass(true); + factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean)); + return factory.getProxy(); + } + return bean; + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) { + return bean; + } + + private static class ProxyDataSourceInterceptor implements MethodInterceptor { + private final DataSource dataSource; + + public ProxyDataSourceInterceptor(final DataSource dataSource) { + this.dataSource = ProxyDataSourceBuilder.create(dataSource) + .name("MyDS") + .multiline() + .logQueryBySlf4j(SLF4JLogLevel.INFO) + .listener(new DataSourceQueryCountListener()) + .build(); + } + + @Override + public Object invoke(final MethodInvocation invocation) throws Throwable { + final Method proxyMethod = ReflectionUtils.findMethod(this.dataSource.getClass(), + invocation.getMethod().getName()); + if (proxyMethod != null) { + return proxyMethod.invoke(this.dataSource, invocation.getArguments()); + } + return invocation.proceed(); + } + } +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/Document.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/Document.java new file mode 100644 index 0000000000..9d69e7eb58 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/Document.java @@ -0,0 +1,26 @@ +package com.baeldung.h2db.lazy_load_no_trans.entity; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.Immutable; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Immutable +public class Document { + + @Id + private Long id; + + private String title; + + private Long userId; +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/User.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/User.java new file mode 100644 index 0000000000..ae9cb9e4e8 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/entity/User.java @@ -0,0 +1,37 @@ +package com.baeldung.h2db.lazy_load_no_trans.entity; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import org.hibernate.annotations.Fetch; +import org.hibernate.annotations.FetchMode; +import org.hibernate.annotations.Immutable; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import javax.persistence.OneToMany; +import java.util.ArrayList; +import java.util.List; + +@Entity +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Immutable +public class User { + + @Id + @GeneratedValue + private Long id; + + private String name; + + private String comment; + + @OneToMany(mappedBy = "userId") + @Fetch(FetchMode.SUBSELECT) + private List docs = new ArrayList<>(); +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/repository/UserRepository.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/repository/UserRepository.java new file mode 100644 index 0000000000..bafe484163 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/repository/UserRepository.java @@ -0,0 +1,9 @@ +package com.baeldung.h2db.lazy_load_no_trans.repository; + +import com.baeldung.h2db.lazy_load_no_trans.entity.User; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface UserRepository extends JpaRepository { +} \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/service/ServiceLayer.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/service/ServiceLayer.java new file mode 100644 index 0000000000..ff3783fd9d --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/lazy_load_no_trans/service/ServiceLayer.java @@ -0,0 +1,34 @@ +package com.baeldung.h2db.lazy_load_no_trans.service; + +import com.baeldung.h2db.lazy_load_no_trans.entity.User; +import com.baeldung.h2db.lazy_load_no_trans.repository.UserRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.Collection; + +@Service +public class ServiceLayer { + + @Autowired + private UserRepository userRepository; + + @Transactional(readOnly = true) + public long countAllDocsTransactional() { + return countAllDocs(); + } + + public long countAllDocsNonTransactional() { + return countAllDocs(); + } + + private long countAllDocs() { + return userRepository.findAll() + .stream() + .map(User::getDocs) + .mapToLong(Collection::size) + .sum(); + } + +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties new file mode 100644 index 0000000000..b5fb841685 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-off.properties @@ -0,0 +1,13 @@ +spring.datasource.url=jdbc:h2:mem:mydb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= +spring.jpa.hibernate.ddl-auto=create-drop +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + +logging.level.org.hibernate.SQL=INFO +logging.level.org.hibernate.type=TRACE +spring.jpa.properties.hibernate.validator.apply_to_ddl=false +spring.jpa.properties.hibernate.enable_lazy_load_no_trans=false +spring.jpa.open-in-view=false \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties new file mode 100644 index 0000000000..04579e1dae --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application-lazy-load-no-trans-on.properties @@ -0,0 +1,13 @@ +spring.datasource.url=jdbc:h2:mem:mydb +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= +spring.jpa.hibernate.ddl-auto=create-drop +spring.h2.console.enabled=true +spring.h2.console.path=/h2-console + +logging.level.org.hibernate.SQL=INFO +logging.level.org.hibernate.type=TRACE +spring.jpa.properties.hibernate.validator.apply_to_ddl=false +spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true +spring.jpa.open-in-view=false \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql index 2d7b446005..b8835e70cb 100644 --- a/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql +++ b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql @@ -10,4 +10,17 @@ CREATE TABLE billionaires ( INSERT INTO billionaires (first_name, last_name, career) VALUES ('Aliko', 'Dangote', 'Billionaire Industrialist'), ('Bill', 'Gates', 'Billionaire Tech Entrepreneur'), -('Folrunsho', 'Alakija', 'Billionaire Oil Magnate'); \ No newline at end of file +('Folrunsho', 'Alakija', 'Billionaire Oil Magnate'); + +insert into USER values (101, 'user1', 'comment1'); +insert into USER values (102, 'user2', 'comment2'); +insert into USER values (103, 'user3', 'comment3'); +insert into USER values (104, 'user4', 'comment4'); +insert into USER values (105, 'user5', 'comment5'); + +insert into DOCUMENT values (1, 'doc1', 101); +insert into DOCUMENT values (2, 'doc2', 101); +insert into DOCUMENT values (3, 'doc3', 101); +insert into DOCUMENT values (4, 'doc4', 101); +insert into DOCUMENT values (5, 'doc5', 102); +insert into DOCUMENT values (6, 'doc6', 102); \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOffIntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOffIntegrationTest.java new file mode 100644 index 0000000000..cb5063d8a4 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOffIntegrationTest.java @@ -0,0 +1,41 @@ +package com.baeldung.lazy_load_no_trans; + +import com.baeldung.h2db.lazy_load_no_trans.LazyLoadNoTransSpringBootApplication; +import com.baeldung.h2db.lazy_load_no_trans.service.ServiceLayer; +import com.vladmihalcea.sql.SQLStatementCountValidator; +import org.hibernate.LazyInitializationException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = LazyLoadNoTransSpringBootApplication.class) +@ActiveProfiles("lazy-load-no-trans-off") +public class LazyLoadNoTransPropertyOffIntegrationTest { + + @Autowired + private ServiceLayer serviceLayer; + + private static final long EXPECTED_DOCS_COLLECTION_SIZE = 6; + + @Test(expected = LazyInitializationException.class) + public void whenCallNonTransactionalMethodWithPropertyOff_thenThrowException() { + serviceLayer.countAllDocsNonTransactional(); + } + + @Test + public void whenCallTransactionalMethodWithPropertyOff_thenTestPass() { + SQLStatementCountValidator.reset(); + + long docsCount = serviceLayer.countAllDocsTransactional(); + + assertEquals(EXPECTED_DOCS_COLLECTION_SIZE, docsCount); + + SQLStatementCountValidator.assertSelectCount(2); + } +} diff --git a/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java new file mode 100644 index 0000000000..5968fde7b7 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/lazy_load_no_trans/LazyLoadNoTransPropertyOnIntegrationTest.java @@ -0,0 +1,47 @@ +package com.baeldung.lazy_load_no_trans; + +import com.baeldung.h2db.lazy_load_no_trans.LazyLoadNoTransSpringBootApplication; +import com.baeldung.h2db.lazy_load_no_trans.service.ServiceLayer; +import com.vladmihalcea.sql.SQLStatementCountValidator; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertEquals; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = LazyLoadNoTransSpringBootApplication.class) +@ActiveProfiles("lazy-load-no-trans-on") +public class LazyLoadNoTransPropertyOnIntegrationTest { + + @Autowired + private ServiceLayer serviceLayer; + + private static final long EXPECTED_DOCS_COLLECTION_SIZE = 6; + private static final long EXPECTED_USERS_COUNT = 5; + + @Test + public void whenCallNonTransactionalMethodWithPropertyOn_thenGetNplusOne() { + SQLStatementCountValidator.reset(); + + long docsCount = serviceLayer.countAllDocsNonTransactional(); + + assertEquals(EXPECTED_DOCS_COLLECTION_SIZE, docsCount); + + SQLStatementCountValidator.assertSelectCount(EXPECTED_USERS_COUNT + 1); + } + + @Test + public void whenCallTransactionalMethodWithPropertyOn_thenTestPass() { + SQLStatementCountValidator.reset(); + + long docsCount = serviceLayer.countAllDocsTransactional(); + + assertEquals(EXPECTED_DOCS_COLLECTION_SIZE, docsCount); + + SQLStatementCountValidator.assertSelectCount(2); + } +} From 5b8ac156ff7d3d51cdd5afc7c5f22e8a7902e93c Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 12 Mar 2020 19:42:41 +0100 Subject: [PATCH 146/278] [JAVA-962] Standardized packages from org.baeldung to com.baeldung --- lagom/build.sbt | 2 +- .../lagom/helloworld/greeting/api/GreetingService.java | 2 +- .../helloworld/greeting/impl/GreetingCommand.java | 2 +- .../lagom/helloworld/greeting/impl/GreetingEntity.java | 6 +++--- .../lagom/helloworld/greeting/impl/GreetingEvent.java | 2 +- .../helloworld/greeting/impl/GreetingServiceImpl.java | 10 +++++----- .../greeting/impl/GreetingServiceModule.java | 6 +++--- .../lagom/helloworld/greeting/impl/GreetingState.java | 2 +- lagom/greeting-impl/bin/application.conf | 2 +- lagom/greeting-impl/bin/classes/application.conf | 2 +- .../greeting-impl/src/main/resources/application.conf | 2 +- .../lagom/helloworld/weather/api/WeatherService.java | 2 +- .../lagom/helloworld/weather/api/WeatherStats.java | 2 +- lagom/weather-impl/bin/application.conf | 2 +- .../helloworld/weather/impl/WeatherServiceImpl.java | 6 +++--- .../helloworld/weather/impl/WeatherServiceModule.java | 4 ++-- lagom/weather-impl/src/main/resources/application.conf | 2 +- 17 files changed, 28 insertions(+), 28 deletions(-) rename lagom/greeting-api/src/main/java/{org => com}/baeldung/lagom/helloworld/greeting/api/GreetingService.java (93%) rename lagom/{greeting-impl/src/main/java/org => greeting-api/src/main/java/com}/baeldung/lagom/helloworld/greeting/impl/GreetingCommand.java (94%) rename lagom/{greeting-impl/src/main/java/org => greeting-api/src/main/java/com}/baeldung/lagom/helloworld/greeting/impl/GreetingEntity.java (85%) rename lagom/{greeting-impl/src/main/java/org => greeting-api/src/main/java/com}/baeldung/lagom/helloworld/greeting/impl/GreetingEvent.java (90%) rename lagom/{greeting-impl/src/main/java/org => greeting-api/src/main/java/com}/baeldung/lagom/helloworld/greeting/impl/GreetingServiceImpl.java (85%) rename lagom/{greeting-impl/src/main/java/org => greeting-api/src/main/java/com}/baeldung/lagom/helloworld/greeting/impl/GreetingServiceModule.java (72%) rename lagom/{greeting-impl/src/main/java/org => greeting-api/src/main/java/com}/baeldung/lagom/helloworld/greeting/impl/GreetingState.java (89%) rename lagom/weather-api/src/main/java/{org => com}/baeldung/lagom/helloworld/weather/api/WeatherService.java (93%) rename lagom/weather-api/src/main/java/{org => com}/baeldung/lagom/helloworld/weather/api/WeatherStats.java (93%) rename lagom/weather-impl/src/main/java/{org => com}/baeldung/lagom/helloworld/weather/impl/WeatherServiceImpl.java (67%) rename lagom/weather-impl/src/main/java/{org => com}/baeldung/lagom/helloworld/weather/impl/WeatherServiceModule.java (78%) diff --git a/lagom/build.sbt b/lagom/build.sbt index 06927e3301..19aeccbd07 100644 --- a/lagom/build.sbt +++ b/lagom/build.sbt @@ -1,4 +1,4 @@ -organization in ThisBuild := "org.baeldung" +organization in ThisBuild := "com.baeldung" // the Scala version that will be used for cross-compiled libraries scalaVersion in ThisBuild := "2.11.8" diff --git a/lagom/greeting-api/src/main/java/org/baeldung/lagom/helloworld/greeting/api/GreetingService.java b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/api/GreetingService.java similarity index 93% rename from lagom/greeting-api/src/main/java/org/baeldung/lagom/helloworld/greeting/api/GreetingService.java rename to lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/api/GreetingService.java index 93567f0185..e212c45437 100644 --- a/lagom/greeting-api/src/main/java/org/baeldung/lagom/helloworld/greeting/api/GreetingService.java +++ b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/api/GreetingService.java @@ -1,4 +1,4 @@ -package org.baeldung.lagom.helloworld.greeting.api; +package com.baeldung.lagom.helloworld.greeting.api; import static com.lightbend.lagom.javadsl.api.Service.named; import static com.lightbend.lagom.javadsl.api.Service.restCall; diff --git a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingCommand.java b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingCommand.java similarity index 94% rename from lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingCommand.java rename to lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingCommand.java index be9e713ec9..30d3930b75 100644 --- a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingCommand.java +++ b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingCommand.java @@ -1,4 +1,4 @@ -package org.baeldung.lagom.helloworld.greeting.impl; +package com.baeldung.lagom.helloworld.greeting.impl; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingEntity.java b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingEntity.java similarity index 85% rename from lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingEntity.java rename to lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingEntity.java index 91fc74039d..125cf4bf38 100644 --- a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingEntity.java +++ b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingEntity.java @@ -1,9 +1,9 @@ -package org.baeldung.lagom.helloworld.greeting.impl; +package com.baeldung.lagom.helloworld.greeting.impl; import java.util.Optional; -import org.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand; -import org.baeldung.lagom.helloworld.greeting.impl.GreetingEvent.ReceivedGreetingEvent; +import com.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand; +import com.baeldung.lagom.helloworld.greeting.impl.GreetingEvent.ReceivedGreetingEvent; import com.lightbend.lagom.javadsl.persistence.PersistentEntity; diff --git a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingEvent.java b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingEvent.java similarity index 90% rename from lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingEvent.java rename to lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingEvent.java index e454f6cd1b..8800177add 100644 --- a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingEvent.java +++ b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingEvent.java @@ -1,4 +1,4 @@ -package org.baeldung.lagom.helloworld.greeting.impl; +package com.baeldung.lagom.helloworld.greeting.impl; import com.fasterxml.jackson.annotation.JsonCreator; import com.lightbend.lagom.serialization.Jsonable; diff --git a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingServiceImpl.java b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingServiceImpl.java similarity index 85% rename from lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingServiceImpl.java rename to lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingServiceImpl.java index c28687291e..0c79b0d468 100644 --- a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingServiceImpl.java +++ b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingServiceImpl.java @@ -1,12 +1,12 @@ -package org.baeldung.lagom.helloworld.greeting.impl; +package com.baeldung.lagom.helloworld.greeting.impl; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; -import org.baeldung.lagom.helloworld.greeting.api.GreetingService; -import org.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand; -import org.baeldung.lagom.helloworld.weather.api.WeatherService; -import org.baeldung.lagom.helloworld.weather.api.WeatherStats; +import com.baeldung.lagom.helloworld.greeting.api.GreetingService; +import com.baeldung.lagom.helloworld.greeting.impl.GreetingCommand.ReceivedGreetingCommand; +import com.baeldung.lagom.helloworld.weather.api.WeatherService; +import com.baeldung.lagom.helloworld.weather.api.WeatherStats; import com.google.inject.Inject; import com.lightbend.lagom.javadsl.api.ServiceCall; diff --git a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingServiceModule.java b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingServiceModule.java similarity index 72% rename from lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingServiceModule.java rename to lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingServiceModule.java index 4813e91a7c..ba5142a5e6 100644 --- a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingServiceModule.java +++ b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingServiceModule.java @@ -1,7 +1,7 @@ -package org.baeldung.lagom.helloworld.greeting.impl; +package com.baeldung.lagom.helloworld.greeting.impl; -import org.baeldung.lagom.helloworld.greeting.api.GreetingService; -import org.baeldung.lagom.helloworld.weather.api.WeatherService; +import com.baeldung.lagom.helloworld.greeting.api.GreetingService; +import com.baeldung.lagom.helloworld.weather.api.WeatherService; import com.google.inject.AbstractModule; import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport; diff --git a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingState.java b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingState.java similarity index 89% rename from lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingState.java rename to lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingState.java index 125795601e..023c0510ae 100644 --- a/lagom/greeting-impl/src/main/java/org/baeldung/lagom/helloworld/greeting/impl/GreetingState.java +++ b/lagom/greeting-api/src/main/java/com/baeldung/lagom/helloworld/greeting/impl/GreetingState.java @@ -1,4 +1,4 @@ -package org.baeldung.lagom.helloworld.greeting.impl; +package com.baeldung.lagom.helloworld.greeting.impl; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; diff --git a/lagom/greeting-impl/bin/application.conf b/lagom/greeting-impl/bin/application.conf index 1e78ce4a79..3fd21ae72b 100644 --- a/lagom/greeting-impl/bin/application.conf +++ b/lagom/greeting-impl/bin/application.conf @@ -1 +1 @@ -play.modules.enabled += org.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule \ No newline at end of file +play.modules.enabled += com.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule \ No newline at end of file diff --git a/lagom/greeting-impl/bin/classes/application.conf b/lagom/greeting-impl/bin/classes/application.conf index 1e78ce4a79..3fd21ae72b 100644 --- a/lagom/greeting-impl/bin/classes/application.conf +++ b/lagom/greeting-impl/bin/classes/application.conf @@ -1 +1 @@ -play.modules.enabled += org.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule \ No newline at end of file +play.modules.enabled += com.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule \ No newline at end of file diff --git a/lagom/greeting-impl/src/main/resources/application.conf b/lagom/greeting-impl/src/main/resources/application.conf index 1e78ce4a79..3fd21ae72b 100644 --- a/lagom/greeting-impl/src/main/resources/application.conf +++ b/lagom/greeting-impl/src/main/resources/application.conf @@ -1 +1 @@ -play.modules.enabled += org.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule \ No newline at end of file +play.modules.enabled += com.baeldung.lagom.helloworld.greeting.impl.GreetingServiceModule \ No newline at end of file diff --git a/lagom/weather-api/src/main/java/org/baeldung/lagom/helloworld/weather/api/WeatherService.java b/lagom/weather-api/src/main/java/com/baeldung/lagom/helloworld/weather/api/WeatherService.java similarity index 93% rename from lagom/weather-api/src/main/java/org/baeldung/lagom/helloworld/weather/api/WeatherService.java rename to lagom/weather-api/src/main/java/com/baeldung/lagom/helloworld/weather/api/WeatherService.java index 888109322b..a0749222eb 100644 --- a/lagom/weather-api/src/main/java/org/baeldung/lagom/helloworld/weather/api/WeatherService.java +++ b/lagom/weather-api/src/main/java/com/baeldung/lagom/helloworld/weather/api/WeatherService.java @@ -1,4 +1,4 @@ -package org.baeldung.lagom.helloworld.weather.api; +package com.baeldung.lagom.helloworld.weather.api; import static com.lightbend.lagom.javadsl.api.Service.named; import static com.lightbend.lagom.javadsl.api.Service.*; diff --git a/lagom/weather-api/src/main/java/org/baeldung/lagom/helloworld/weather/api/WeatherStats.java b/lagom/weather-api/src/main/java/com/baeldung/lagom/helloworld/weather/api/WeatherStats.java similarity index 93% rename from lagom/weather-api/src/main/java/org/baeldung/lagom/helloworld/weather/api/WeatherStats.java rename to lagom/weather-api/src/main/java/com/baeldung/lagom/helloworld/weather/api/WeatherStats.java index 23530a297d..aa04c5ad86 100644 --- a/lagom/weather-api/src/main/java/org/baeldung/lagom/helloworld/weather/api/WeatherStats.java +++ b/lagom/weather-api/src/main/java/com/baeldung/lagom/helloworld/weather/api/WeatherStats.java @@ -1,4 +1,4 @@ -package org.baeldung.lagom.helloworld.weather.api; +package com.baeldung.lagom.helloworld.weather.api; import java.util.Arrays; import java.util.Collections; diff --git a/lagom/weather-impl/bin/application.conf b/lagom/weather-impl/bin/application.conf index cf6cec2115..53d2dff8f2 100644 --- a/lagom/weather-impl/bin/application.conf +++ b/lagom/weather-impl/bin/application.conf @@ -1 +1 @@ -play.modules.enabled += org.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule \ No newline at end of file +play.modules.enabled += com.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule \ No newline at end of file diff --git a/lagom/weather-impl/src/main/java/org/baeldung/lagom/helloworld/weather/impl/WeatherServiceImpl.java b/lagom/weather-impl/src/main/java/com/baeldung/lagom/helloworld/weather/impl/WeatherServiceImpl.java similarity index 67% rename from lagom/weather-impl/src/main/java/org/baeldung/lagom/helloworld/weather/impl/WeatherServiceImpl.java rename to lagom/weather-impl/src/main/java/com/baeldung/lagom/helloworld/weather/impl/WeatherServiceImpl.java index d7f97f9105..38e4b4d28f 100644 --- a/lagom/weather-impl/src/main/java/org/baeldung/lagom/helloworld/weather/impl/WeatherServiceImpl.java +++ b/lagom/weather-impl/src/main/java/com/baeldung/lagom/helloworld/weather/impl/WeatherServiceImpl.java @@ -1,9 +1,9 @@ -package org.baeldung.lagom.helloworld.weather.impl; +package com.baeldung.lagom.helloworld.weather.impl; import java.util.concurrent.CompletableFuture; -import org.baeldung.lagom.helloworld.weather.api.WeatherService; -import org.baeldung.lagom.helloworld.weather.api.WeatherStats; +import com.baeldung.lagom.helloworld.weather.api.WeatherService; +import com.baeldung.lagom.helloworld.weather.api.WeatherStats; import com.lightbend.lagom.javadsl.api.ServiceCall; diff --git a/lagom/weather-impl/src/main/java/org/baeldung/lagom/helloworld/weather/impl/WeatherServiceModule.java b/lagom/weather-impl/src/main/java/com/baeldung/lagom/helloworld/weather/impl/WeatherServiceModule.java similarity index 78% rename from lagom/weather-impl/src/main/java/org/baeldung/lagom/helloworld/weather/impl/WeatherServiceModule.java rename to lagom/weather-impl/src/main/java/com/baeldung/lagom/helloworld/weather/impl/WeatherServiceModule.java index ac2834ff5c..85257ffa47 100644 --- a/lagom/weather-impl/src/main/java/org/baeldung/lagom/helloworld/weather/impl/WeatherServiceModule.java +++ b/lagom/weather-impl/src/main/java/com/baeldung/lagom/helloworld/weather/impl/WeatherServiceModule.java @@ -1,6 +1,6 @@ -package org.baeldung.lagom.helloworld.weather.impl; +package com.baeldung.lagom.helloworld.weather.impl; -import org.baeldung.lagom.helloworld.weather.api.WeatherService; +import com.baeldung.lagom.helloworld.weather.api.WeatherService; import com.google.inject.AbstractModule; import com.lightbend.lagom.javadsl.server.ServiceGuiceSupport; diff --git a/lagom/weather-impl/src/main/resources/application.conf b/lagom/weather-impl/src/main/resources/application.conf index cf6cec2115..53d2dff8f2 100644 --- a/lagom/weather-impl/src/main/resources/application.conf +++ b/lagom/weather-impl/src/main/resources/application.conf @@ -1 +1 @@ -play.modules.enabled += org.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule \ No newline at end of file +play.modules.enabled += com.baeldung.lagom.helloworld.weather.impl.WeatherServiceModule \ No newline at end of file From b1cc7f4337abc0401255721baf22afed5d31a8bc Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 14:56:31 +0100 Subject: [PATCH 147/278] JAVA-960: Migrate spring-social-login to com.baeldung --- .../java/{org => com}/baeldung/config/Application.java | 6 +++--- .../java/{org => com}/baeldung/config/SecurityConfig.java | 8 ++++---- .../main/java/{org => com}/baeldung/config/WebConfig.java | 2 +- .../baeldung/persistence/dao/UserRepository.java | 4 ++-- .../{org => com}/baeldung/persistence/model/User.java | 2 +- .../baeldung/security/FacebookConnectionSignup.java | 6 +++--- .../baeldung/security/FacebookSignInAdapter.java | 2 +- .../baeldung/security/MyUserDetailsService.java | 6 +++--- .../java/{org => com}/baeldung/SpringContextTest.java | 4 ++-- 9 files changed, 20 insertions(+), 20 deletions(-) rename spring-social-login/src/main/java/{org => com}/baeldung/config/Application.java (80%) rename spring-social-login/src/main/java/{org => com}/baeldung/config/SecurityConfig.java (92%) rename spring-social-login/src/main/java/{org => com}/baeldung/config/WebConfig.java (98%) rename spring-social-login/src/main/java/{org => com}/baeldung/persistence/dao/UserRepository.java (69%) rename spring-social-login/src/main/java/{org => com}/baeldung/persistence/model/User.java (96%) rename spring-social-login/src/main/java/{org => com}/baeldung/security/FacebookConnectionSignup.java (85%) rename spring-social-login/src/main/java/{org => com}/baeldung/security/FacebookSignInAdapter.java (96%) rename spring-social-login/src/main/java/{org => com}/baeldung/security/MyUserDetailsService.java (89%) rename spring-social-login/src/test/java/{org => com}/baeldung/SpringContextTest.java (88%) diff --git a/spring-social-login/src/main/java/org/baeldung/config/Application.java b/spring-social-login/src/main/java/com/baeldung/config/Application.java similarity index 80% rename from spring-social-login/src/main/java/org/baeldung/config/Application.java rename to spring-social-login/src/main/java/com/baeldung/config/Application.java index cf6251a51e..5d083d2d47 100644 --- a/spring-social-login/src/main/java/org/baeldung/config/Application.java +++ b/spring-social-login/src/main/java/com/baeldung/config/Application.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -7,8 +7,8 @@ import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @SpringBootApplication -@EnableJpaRepositories("org.baeldung.persistence.dao") -@EntityScan("org.baeldung.persistence.model") +@EnableJpaRepositories("com.baeldung.persistence.dao") +@EntityScan("com.baeldung.persistence.model") public class Application extends SpringBootServletInitializer { public static void main(String[] args) { diff --git a/spring-social-login/src/main/java/org/baeldung/config/SecurityConfig.java b/spring-social-login/src/main/java/com/baeldung/config/SecurityConfig.java similarity index 92% rename from spring-social-login/src/main/java/org/baeldung/config/SecurityConfig.java rename to spring-social-login/src/main/java/com/baeldung/config/SecurityConfig.java index 8e439653a9..3d3081fef9 100644 --- a/spring-social-login/src/main/java/org/baeldung/config/SecurityConfig.java +++ b/spring-social-login/src/main/java/com/baeldung/config/SecurityConfig.java @@ -1,7 +1,7 @@ -package org.baeldung.config; +package com.baeldung.config; -import org.baeldung.security.FacebookSignInAdapter; -import org.baeldung.security.FacebookConnectionSignup; +import com.baeldung.security.FacebookSignInAdapter; +import com.baeldung.security.FacebookConnectionSignup; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -18,7 +18,7 @@ import org.springframework.social.connect.web.ProviderSignInController; @Configuration @EnableWebSecurity -@ComponentScan(basePackages = { "org.baeldung.security" }) +@ComponentScan(basePackages = { "com.baeldung.security" }) public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired diff --git a/spring-social-login/src/main/java/org/baeldung/config/WebConfig.java b/spring-social-login/src/main/java/com/baeldung/config/WebConfig.java similarity index 98% rename from spring-social-login/src/main/java/org/baeldung/config/WebConfig.java rename to spring-social-login/src/main/java/com/baeldung/config/WebConfig.java index 8cfcd6cb41..d178cc28a6 100644 --- a/spring-social-login/src/main/java/org/baeldung/config/WebConfig.java +++ b/spring-social-login/src/main/java/com/baeldung/config/WebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-social-login/src/main/java/org/baeldung/persistence/dao/UserRepository.java b/spring-social-login/src/main/java/com/baeldung/persistence/dao/UserRepository.java similarity index 69% rename from spring-social-login/src/main/java/org/baeldung/persistence/dao/UserRepository.java rename to spring-social-login/src/main/java/com/baeldung/persistence/dao/UserRepository.java index 679dd6c363..aeb443dd06 100644 --- a/spring-social-login/src/main/java/org/baeldung/persistence/dao/UserRepository.java +++ b/spring-social-login/src/main/java/com/baeldung/persistence/dao/UserRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.persistence.dao; +package com.baeldung.persistence.dao; -import org.baeldung.persistence.model.User; +import com.baeldung.persistence.model.User; import org.springframework.data.jpa.repository.JpaRepository; public interface UserRepository extends JpaRepository { diff --git a/spring-social-login/src/main/java/org/baeldung/persistence/model/User.java b/spring-social-login/src/main/java/com/baeldung/persistence/model/User.java similarity index 96% rename from spring-social-login/src/main/java/org/baeldung/persistence/model/User.java rename to spring-social-login/src/main/java/com/baeldung/persistence/model/User.java index a4cffc27d0..ce1774ca2c 100644 --- a/spring-social-login/src/main/java/org/baeldung/persistence/model/User.java +++ b/spring-social-login/src/main/java/com/baeldung/persistence/model/User.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.model; +package com.baeldung.persistence.model; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/spring-social-login/src/main/java/org/baeldung/security/FacebookConnectionSignup.java b/spring-social-login/src/main/java/com/baeldung/security/FacebookConnectionSignup.java similarity index 85% rename from spring-social-login/src/main/java/org/baeldung/security/FacebookConnectionSignup.java rename to spring-social-login/src/main/java/com/baeldung/security/FacebookConnectionSignup.java index 6a9e30d7d8..e0a9fdc2e7 100644 --- a/spring-social-login/src/main/java/org/baeldung/security/FacebookConnectionSignup.java +++ b/spring-social-login/src/main/java/com/baeldung/security/FacebookConnectionSignup.java @@ -1,9 +1,9 @@ -package org.baeldung.security; +package com.baeldung.security; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; -import org.baeldung.persistence.dao.UserRepository; -import org.baeldung.persistence.model.User; +import com.baeldung.persistence.dao.UserRepository; +import com.baeldung.persistence.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.social.connect.Connection; import org.springframework.social.connect.ConnectionSignUp; diff --git a/spring-social-login/src/main/java/org/baeldung/security/FacebookSignInAdapter.java b/spring-social-login/src/main/java/com/baeldung/security/FacebookSignInAdapter.java similarity index 96% rename from spring-social-login/src/main/java/org/baeldung/security/FacebookSignInAdapter.java rename to spring-social-login/src/main/java/com/baeldung/security/FacebookSignInAdapter.java index b861609a01..3050941ffa 100644 --- a/spring-social-login/src/main/java/org/baeldung/security/FacebookSignInAdapter.java +++ b/spring-social-login/src/main/java/com/baeldung/security/FacebookSignInAdapter.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.util.Arrays; diff --git a/spring-social-login/src/main/java/org/baeldung/security/MyUserDetailsService.java b/spring-social-login/src/main/java/com/baeldung/security/MyUserDetailsService.java similarity index 89% rename from spring-social-login/src/main/java/org/baeldung/security/MyUserDetailsService.java rename to spring-social-login/src/main/java/com/baeldung/security/MyUserDetailsService.java index 5d0d5d793a..126f02e74a 100644 --- a/spring-social-login/src/main/java/org/baeldung/security/MyUserDetailsService.java +++ b/spring-social-login/src/main/java/com/baeldung/security/MyUserDetailsService.java @@ -1,9 +1,9 @@ -package org.baeldung.security; +package com.baeldung.security; import java.util.Arrays; -import org.baeldung.persistence.dao.UserRepository; -import org.baeldung.persistence.model.User; +import com.baeldung.persistence.dao.UserRepository; +import com.baeldung.persistence.model.User; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; diff --git a/spring-social-login/src/test/java/org/baeldung/SpringContextTest.java b/spring-social-login/src/test/java/com/baeldung/SpringContextTest.java similarity index 88% rename from spring-social-login/src/test/java/org/baeldung/SpringContextTest.java rename to spring-social-login/src/test/java/com/baeldung/SpringContextTest.java index cfd8759c52..1d9711b5a4 100644 --- a/spring-social-login/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-social-login/src/test/java/com/baeldung/SpringContextTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.config.Application; +import com.baeldung.config.Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; From aa251bb22b90a97128858317cc8ad9240cc897ca Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:02:32 +0100 Subject: [PATCH 148/278] JAVA-960: Migrate spring-static-resources to com.baeldung --- .../security/MySimpleUrlAuthenticationSuccessHandler.java | 2 +- .../src/main/java/{org => com}/baeldung/spring/AppConfig.java | 4 ++-- .../src/main/java/{org => com}/baeldung/spring/MvcConfig.java | 4 ++-- .../java/{org => com}/baeldung/spring/SecSecurityConfig.java | 2 +- .../{org => com}/baeldung/web/controller/HomeController.java | 2 +- .../src/main/resources/webSecurityConfig.xml | 2 +- .../src/test/java/com/baeldung/SpringContextTest.java | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) rename spring-static-resources/src/main/java/{org => com}/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java (98%) rename spring-static-resources/src/main/java/{org => com}/baeldung/spring/AppConfig.java (83%) rename spring-static-resources/src/main/java/{org => com}/baeldung/spring/MvcConfig.java (96%) rename spring-static-resources/src/main/java/{org => com}/baeldung/spring/SecSecurityConfig.java (90%) rename spring-static-resources/src/main/java/{org => com}/baeldung/web/controller/HomeController.java (96%) diff --git a/spring-static-resources/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-static-resources/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java similarity index 98% rename from spring-static-resources/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java rename to spring-static-resources/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java index 316642ab6f..d6c54f8099 100644 --- a/spring-static-resources/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java +++ b/spring-static-resources/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; import javax.servlet.http.HttpServletRequest; diff --git a/spring-static-resources/src/main/java/org/baeldung/spring/AppConfig.java b/spring-static-resources/src/main/java/com/baeldung/spring/AppConfig.java similarity index 83% rename from spring-static-resources/src/main/java/org/baeldung/spring/AppConfig.java rename to spring-static-resources/src/main/java/com/baeldung/spring/AppConfig.java index c379d20047..97e7cf96fc 100644 --- a/spring-static-resources/src/main/java/org/baeldung/spring/AppConfig.java +++ b/spring-static-resources/src/main/java/com/baeldung/spring/AppConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -8,7 +8,7 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @Configuration -@ComponentScan(basePackages = { "org.baeldung.persistence.service", "org.baeldung.persistence.dao" }) +@ComponentScan(basePackages = { "com.baeldung.persistence.service", "com.baeldung.persistence.dao" }) @Import({ MvcConfig.class, SecSecurityConfig.class }) @PropertySource("classpath:application.properties") public class AppConfig { diff --git a/spring-static-resources/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-static-resources/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 96% rename from spring-static-resources/src/main/java/org/baeldung/spring/MvcConfig.java rename to spring-static-resources/src/main/java/com/baeldung/spring/MvcConfig.java index 7bd03617be..f23fe14fb8 100644 --- a/spring-static-resources/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-static-resources/src/main/java/com/baeldung/spring/MvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import java.util.Locale; @@ -25,7 +25,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; @Configuration -@ComponentScan(basePackages = { "org.baeldung.web.controller", "org.baeldung.persistence.service", "org.baeldung.persistence.dao" }) +@ComponentScan(basePackages = { "com.baeldung.web.controller", "com.baeldung.persistence.service", "com.baeldung.persistence.dao" }) @EnableWebMvc public class MvcConfig implements WebMvcConfigurer { @Autowired diff --git a/spring-static-resources/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-static-resources/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 90% rename from spring-static-resources/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-static-resources/src/main/java/com/baeldung/spring/SecSecurityConfig.java index 4da114c78b..3e630b8729 100644 --- a/spring-static-resources/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-static-resources/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; diff --git a/spring-static-resources/src/main/java/org/baeldung/web/controller/HomeController.java b/spring-static-resources/src/main/java/com/baeldung/web/controller/HomeController.java similarity index 96% rename from spring-static-resources/src/main/java/org/baeldung/web/controller/HomeController.java rename to spring-static-resources/src/main/java/com/baeldung/web/controller/HomeController.java index 44645a1471..dd58c7c2b6 100644 --- a/spring-static-resources/src/main/java/org/baeldung/web/controller/HomeController.java +++ b/spring-static-resources/src/main/java/com/baeldung/web/controller/HomeController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import java.io.IOException; import java.text.DateFormat; diff --git a/spring-static-resources/src/main/resources/webSecurityConfig.xml b/spring-static-resources/src/main/resources/webSecurityConfig.xml index ea64ad5aea..2278cb6138 100644 --- a/spring-static-resources/src/main/resources/webSecurityConfig.xml +++ b/spring-static-resources/src/main/resources/webSecurityConfig.xml @@ -23,7 +23,7 @@ - + diff --git a/spring-static-resources/src/test/java/com/baeldung/SpringContextTest.java b/spring-static-resources/src/test/java/com/baeldung/SpringContextTest.java index 0dcbba3221..153b290de7 100644 --- a/spring-static-resources/src/test/java/com/baeldung/SpringContextTest.java +++ b/spring-static-resources/src/test/java/com/baeldung/SpringContextTest.java @@ -1,6 +1,6 @@ package com.baeldung; -import org.baeldung.spring.SecSecurityConfig; +import com.baeldung.spring.SecSecurityConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; From 20e1eb49123cbbf7fa2dcb0b38140b66b1e1f1d7 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:07:48 +0100 Subject: [PATCH 149/278] JAVA-960: Migrate spring-session to com.baeldung --- spring-session/pom.xml | 2 +- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- .../test/java/{org => com}/baeldung/SpringContextLiveTest.java | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) rename spring-session/spring-session-jdbc/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) rename spring-session/spring-session-mongodb/src/test/java/{org => com}/baeldung/SpringContextTest.java (96%) rename spring-session/spring-session-redis/src/test/java/{org => com}/baeldung/SpringContextLiveTest.java (96%) diff --git a/spring-session/pom.xml b/spring-session/pom.xml index 579d2327e8..42a414afdc 100644 --- a/spring-session/pom.xml +++ b/spring-session/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - org.baeldung + com.baeldung spring-session 1.0.0-SNAPSHOT spring-session diff --git a/spring-session/spring-session-jdbc/src/test/java/org/baeldung/SpringContextTest.java b/spring-session/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-session/spring-session-jdbc/src/test/java/org/baeldung/SpringContextTest.java rename to spring-session/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java index b69855ba38..8f6c2f2889 100644 --- a/spring-session/spring-session-jdbc/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-session/spring-session-jdbc/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-session/spring-session-mongodb/src/test/java/org/baeldung/SpringContextTest.java b/spring-session/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java similarity index 96% rename from spring-session/spring-session-mongodb/src/test/java/org/baeldung/SpringContextTest.java rename to spring-session/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java index cc935b8cfb..babcdb2ccf 100644 --- a/spring-session/spring-session-mongodb/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-session/spring-session-mongodb/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import com.baeldung.springsessionmongodb.SpringSessionMongoDBApplication; import org.junit.Test; diff --git a/spring-session/spring-session-redis/src/test/java/org/baeldung/SpringContextLiveTest.java b/spring-session/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java similarity index 96% rename from spring-session/spring-session-redis/src/test/java/org/baeldung/SpringContextLiveTest.java rename to spring-session/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java index 3a4f14e9e6..2e33255e01 100644 --- a/spring-session/spring-session-redis/src/test/java/org/baeldung/SpringContextLiveTest.java +++ b/spring-session/spring-session-redis/src/test/java/com/baeldung/SpringContextLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From b4ee35c52573948839a86414cc16f0ce568ba6b7 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:09:47 +0100 Subject: [PATCH 150/278] JAVA-960: Migrate spring-sleuth to com.baeldung --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-sleuth/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-sleuth/src/test/java/org/baeldung/SpringContextTest.java b/spring-sleuth/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-sleuth/src/test/java/org/baeldung/SpringContextTest.java rename to spring-sleuth/src/test/java/com/baeldung/SpringContextTest.java index ff22398ca4..8dc2455e63 100644 --- a/spring-sleuth/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-sleuth/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From fd68ce46363068b00da1ef7a3914d46b51b09be0 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:13:49 +0100 Subject: [PATCH 151/278] JAVA-960: Migrate spring-spel to com.baeldung --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-spel/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-spel/src/test/java/org/baeldung/SpringContextTest.java b/spring-spel/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-spel/src/test/java/org/baeldung/SpringContextTest.java rename to spring-spel/src/test/java/com/baeldung/SpringContextTest.java index e25c1bf8e4..338b8b1e68 100644 --- a/spring-spel/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-spel/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From b205233679e3b27d284a4b88baed36fffc66ce4c Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:15:41 +0100 Subject: [PATCH 152/278] JAVA-960: Migrate spring-state-machine to com.baeldung --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-state-machine/src/test/java/{org => com}/baeldung/SpringContextTest.java (97%) diff --git a/spring-state-machine/src/test/java/org/baeldung/SpringContextTest.java b/spring-state-machine/src/test/java/com/baeldung/SpringContextTest.java similarity index 97% rename from spring-state-machine/src/test/java/org/baeldung/SpringContextTest.java rename to spring-state-machine/src/test/java/com/baeldung/SpringContextTest.java index 1e847c0d65..407cd8ebb0 100644 --- a/spring-state-machine/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-state-machine/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From bcc15ba72ec1807f727c913b23637051e4107724 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:17:48 +0100 Subject: [PATCH 153/278] JAVA-960: Migrate spring-swagger-codegen to com.baeldung --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-swagger-codegen/spring-swagger-codegen-app/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-swagger-codegen/spring-swagger-codegen-app/src/test/java/org/baeldung/SpringContextTest.java b/spring-swagger-codegen/spring-swagger-codegen-app/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-swagger-codegen/spring-swagger-codegen-app/src/test/java/org/baeldung/SpringContextTest.java rename to spring-swagger-codegen/spring-swagger-codegen-app/src/test/java/com/baeldung/SpringContextTest.java index 79b2b7fa88..54949598aa 100644 --- a/spring-swagger-codegen/spring-swagger-codegen-app/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-swagger-codegen/spring-swagger-codegen-app/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 137ff8d5eaff8dd636436f09ee9053b5698852b6 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:19:30 +0100 Subject: [PATCH 154/278] JAVA-960: Migrate spring-vertx to com.baeldung --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-vertx/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-vertx/src/test/java/org/baeldung/SpringContextTest.java b/spring-vertx/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-vertx/src/test/java/org/baeldung/SpringContextTest.java rename to spring-vertx/src/test/java/com/baeldung/SpringContextTest.java index 4ce94ec16a..386d83b47b 100644 --- a/spring-vertx/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-vertx/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 25e76cdb8848f88569a9cfc82d1f9c263de5121c Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 19 Mar 2020 15:40:01 +0100 Subject: [PATCH 155/278] JAVA-960: Migrate spring-resttemplate to com.baeldung --- .../RestTemplateConfigurationApplication.java | 2 +- .../CustomClientHttpRequestInterceptor.java | 2 +- .../CustomRestTemplateCustomizer.java | 2 +- .../configuration/FooController.java | 4 ++-- .../configuration/HelloController.java | 2 +- .../resttemplate/configuration/SpringConfig.java | 4 ++-- .../resttemplate/web/controller/PersonAPI.java | 6 +++--- .../baeldung/resttemplate/web/dto/Foo.java | 2 +- .../baeldung/resttemplate/web/dto/Person.java | 2 +- .../web/exception/NotFoundException.java | 2 +- .../RestTemplateResponseErrorHandler.java | 4 ++-- .../baeldung/resttemplate/web/model/Bar.java | 2 +- .../resttemplate/web/model/Employee.java | 3 +-- .../web/service/BarConsumerService.java | 6 +++--- .../web/service/EmployeeService.java | 4 ++-- .../resttemplate/web/service/PersonService.java | 4 ++-- .../web/service/PersonServiceImpl.java | 4 ++-- .../java/com/baeldung/SpringContextTest.java | 0 .../{org => com}/baeldung/SpringTestConfig.java | 4 ++-- .../{org => com}/baeldung/client/Consts.java | 2 +- .../client/TestRestTemplateBasicLiveTest.java | 4 ++-- .../LargeFileDownloadIntegrationTest.java | 2 +- .../resttemplate/RestTemplateBasicLiveTest.java | 8 ++++---- .../resttemplate/postjson/PersonAPILiveTest.java | 6 +++--- ...plateResponseErrorHandlerIntegrationTest.java | 8 ++++---- ...oyeeServiceMockRestServiceServerUnitTest.java | 8 ++++---- .../web/service/EmployeeServiceUnitTest.java | 8 +++----- .../java/org/baeldung/SpringContextTest.java | 16 ---------------- 28 files changed, 51 insertions(+), 70 deletions(-) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/RestTemplateConfigurationApplication.java (92%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java (95%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java (89%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/configuration/FooController.java (97%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/configuration/HelloController.java (95%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/configuration/SpringConfig.java (90%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/controller/PersonAPI.java (88%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/dto/Foo.java (93%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/dto/Person.java (91%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/exception/NotFoundException.java (55%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java (92%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/model/Bar.java (87%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/model/Employee.java (93%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/service/BarConsumerService.java (80%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/service/EmployeeService.java (89%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/service/PersonService.java (58%) rename spring-resttemplate/src/main/java/{org => com}/baeldung/resttemplate/web/service/PersonServiceImpl.java (77%) rename spring-resttemplate/src/{main => test}/java/com/baeldung/SpringContextTest.java (100%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/SpringTestConfig.java (89%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/client/Consts.java (68%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/client/TestRestTemplateBasicLiveTest.java (98%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java (99%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/resttemplate/RestTemplateBasicLiveTest.java (98%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/resttemplate/postjson/PersonAPILiveTest.java (95%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java (90%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java (92%) rename spring-resttemplate/src/test/java/{org => com}/baeldung/web/service/EmployeeServiceUnitTest.java (84%) delete mode 100644 spring-resttemplate/src/test/java/org/baeldung/SpringContextTest.java diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/RestTemplateConfigurationApplication.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java similarity index 92% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/RestTemplateConfigurationApplication.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java index 9a361e92c9..3e4d1ffa00 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/RestTemplateConfigurationApplication.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/RestTemplateConfigurationApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate; +package com.baeldung.resttemplate; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java similarity index 95% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java index a39994ae67..bef8af3725 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomClientHttpRequestInterceptor.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.configuration; +package com.baeldung.resttemplate.configuration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java similarity index 89% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java index 5e8220d064..75ce02ea04 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/CustomRestTemplateCustomizer.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.configuration; +package com.baeldung.resttemplate.configuration; import org.springframework.boot.web.client.RestTemplateCustomizer; import org.springframework.web.client.RestTemplate; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/FooController.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java similarity index 97% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/FooController.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java index a9d400b199..dbef16b592 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/FooController.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/FooController.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.configuration; +package com.baeldung.resttemplate.configuration; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; @@ -6,7 +6,7 @@ import java.net.URI; import java.util.Collection; import java.util.Map; -import org.baeldung.resttemplate.web.dto.Foo; +import com.baeldung.resttemplate.web.dto.Foo; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/HelloController.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java similarity index 95% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/HelloController.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java index ee404db4f8..854ca1a1c1 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/HelloController.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/HelloController.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.configuration; +package com.baeldung.resttemplate.configuration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/SpringConfig.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java similarity index 90% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/SpringConfig.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java index 966d5bcaa1..a97ac7d5a5 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/configuration/SpringConfig.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.configuration; +package com.baeldung.resttemplate.configuration; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; @@ -11,7 +11,7 @@ import org.springframework.web.client.RestTemplate; @Configuration @EnableAutoConfiguration -@ComponentScan("org.baeldung.resttemplate.configuration") +@ComponentScan("com.baeldung.resttemplate.configuration") public class SpringConfig { @Bean diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java similarity index 88% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java index b1b56ec2f3..b3131cc00c 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/controller/PersonAPI.java @@ -1,9 +1,9 @@ -package org.baeldung.resttemplate.web.controller; +package com.baeldung.resttemplate.web.controller; import javax.servlet.http.HttpServletResponse; -import org.baeldung.resttemplate.web.dto.Person; -import org.baeldung.resttemplate.web.service.PersonService; +import com.baeldung.resttemplate.web.service.PersonService; +import com.baeldung.resttemplate.web.dto.Person; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Foo.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java similarity index 93% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Foo.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java index ed0a42c429..ede91dab1a 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Foo.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Foo.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.web.dto; +package com.baeldung.resttemplate.web.dto; import com.thoughtworks.xstream.annotations.XStreamAlias; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Person.java similarity index 91% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Person.java index 4b7679638f..11e56fc6e2 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/dto/Person.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.web.dto; +package com.baeldung.resttemplate.web.dto; public class Person { private Integer id; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/exception/NotFoundException.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java similarity index 55% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/exception/NotFoundException.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java index 3e606e9314..8eb217978c 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/exception/NotFoundException.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/exception/NotFoundException.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.web.exception; +package com.baeldung.resttemplate.web.exception; public class NotFoundException extends RuntimeException { } diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java similarity index 92% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java index 214de38746..02260438c7 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/handler/RestTemplateResponseErrorHandler.java @@ -1,8 +1,8 @@ -package org.baeldung.resttemplate.web.handler; +package com.baeldung.resttemplate.web.handler; import java.io.IOException; -import org.baeldung.resttemplate.web.exception.NotFoundException; +import com.baeldung.resttemplate.web.exception.NotFoundException; import org.springframework.http.HttpStatus; import org.springframework.http.client.ClientHttpResponse; import org.springframework.stereotype.Component; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/model/Bar.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java similarity index 87% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/model/Bar.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java index cf5279697f..7f8902e2fc 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/model/Bar.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Bar.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate.web.model; +package com.baeldung.resttemplate.web.model; public class Bar { private String id; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/model/Employee.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java similarity index 93% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/model/Employee.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java index a9b84a77b4..bb1ad8cbfa 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/model/Employee.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/model/Employee.java @@ -1,6 +1,5 @@ -package org.baeldung.resttemplate.web.model; +package com.baeldung.resttemplate.web.model; -import java.util.Date; import java.util.Objects; public class Employee { diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/BarConsumerService.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java similarity index 80% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/BarConsumerService.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java index 54a66ea591..485143b0a1 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/BarConsumerService.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/BarConsumerService.java @@ -1,7 +1,7 @@ -package org.baeldung.resttemplate.web.service; +package com.baeldung.resttemplate.web.service; -import org.baeldung.resttemplate.web.handler.RestTemplateResponseErrorHandler; -import org.baeldung.resttemplate.web.model.Bar; +import com.baeldung.resttemplate.web.handler.RestTemplateResponseErrorHandler; +import com.baeldung.resttemplate.web.model.Bar; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateBuilder; import org.springframework.stereotype.Service; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/EmployeeService.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java similarity index 89% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/EmployeeService.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java index c6562fbc94..18dff3db1b 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/EmployeeService.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/EmployeeService.java @@ -1,6 +1,6 @@ -package org.baeldung.resttemplate.web.service; +package com.baeldung.resttemplate.web.service; -import org.baeldung.resttemplate.web.model.Employee; +import com.baeldung.resttemplate.web.model.Employee; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java similarity index 58% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java index c5ad39e101..e91d2adc5c 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonService.java @@ -1,6 +1,6 @@ -package org.baeldung.resttemplate.web.service; +package com.baeldung.resttemplate.web.service; -import org.baeldung.resttemplate.web.dto.Person; +import com.baeldung.resttemplate.web.dto.Person; public interface PersonService { diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java similarity index 77% rename from spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java rename to spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java index 658e0fade0..d7a1bfc2db 100644 --- a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/web/service/PersonServiceImpl.java @@ -1,6 +1,6 @@ -package org.baeldung.resttemplate.web.service; +package com.baeldung.resttemplate.web.service; -import org.baeldung.resttemplate.web.dto.Person; +import com.baeldung.resttemplate.web.dto.Person; import org.springframework.stereotype.Component; @Component diff --git a/spring-resttemplate/src/main/java/com/baeldung/SpringContextTest.java b/spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-resttemplate/src/main/java/com/baeldung/SpringContextTest.java rename to spring-resttemplate/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-resttemplate/src/test/java/org/baeldung/SpringTestConfig.java b/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java similarity index 89% rename from spring-resttemplate/src/test/java/org/baeldung/SpringTestConfig.java rename to spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java index 7c4bbb4e5e..9a32d1ee98 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/SpringTestConfig.java +++ b/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.context.annotation.Bean; @@ -8,7 +8,7 @@ import org.springframework.web.client.RestTemplate; @Configuration @EnableAutoConfiguration -@ComponentScan("org.baeldung") +@ComponentScan("com.baeldung") public class SpringTestConfig { @Bean diff --git a/spring-resttemplate/src/test/java/org/baeldung/client/Consts.java b/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java similarity index 68% rename from spring-resttemplate/src/test/java/org/baeldung/client/Consts.java rename to spring-resttemplate/src/test/java/com/baeldung/client/Consts.java index b40561d9c3..b392c4d199 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/client/Consts.java +++ b/spring-resttemplate/src/test/java/com/baeldung/client/Consts.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package com.baeldung.client; public interface Consts { int APPLICATION_PORT = 8082; diff --git a/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java similarity index 98% rename from spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java rename to spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java index 967c4a6188..9f4b3c9b35 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/client/TestRestTemplateBasicLiveTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/client/TestRestTemplateBasicLiveTest.java @@ -1,10 +1,10 @@ -package org.baeldung.client; +package com.baeldung.client; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; -import org.baeldung.resttemplate.web.dto.Foo; +import com.baeldung.resttemplate.web.dto.Foo; import org.junit.Before; import org.junit.Test; import org.springframework.boot.test.web.client.TestRestTemplate; diff --git a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java similarity index 99% rename from spring-resttemplate/src/test/java/org/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java rename to spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java index 21639818db..eb5d01d06f 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/LargeFileDownloadIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung.resttemplate; +package com.baeldung.resttemplate; import org.assertj.core.api.Assertions; import org.junit.Assert; diff --git a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/RestTemplateBasicLiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java similarity index 98% rename from spring-resttemplate/src/test/java/org/baeldung/resttemplate/RestTemplateBasicLiveTest.java rename to spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java index 54e416d008..0dab124316 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/RestTemplateBasicLiveTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/RestTemplateBasicLiveTest.java @@ -1,7 +1,7 @@ -package org.baeldung.resttemplate; +package com.baeldung.resttemplate; import static org.apache.commons.codec.binary.Base64.encodeBase64; -import static org.baeldung.client.Consts.APPLICATION_PORT; +import static com.baeldung.client.Consts.APPLICATION_PORT; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.CoreMatchers.notNullValue; @@ -14,8 +14,8 @@ import java.net.URI; import java.util.Arrays; import java.util.Set; -import org.baeldung.resttemplate.web.dto.Foo; -import org.baeldung.resttemplate.web.handler.RestTemplateResponseErrorHandler; +import com.baeldung.resttemplate.web.handler.RestTemplateResponseErrorHandler; +import com.baeldung.resttemplate.web.dto.Foo; import org.junit.Before; import org.junit.Test; import org.springframework.http.HttpEntity; diff --git a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/postjson/PersonAPILiveTest.java b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java similarity index 95% rename from spring-resttemplate/src/test/java/org/baeldung/resttemplate/postjson/PersonAPILiveTest.java rename to spring-resttemplate/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java index 1347cb0c7a..f1861ede92 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/postjson/PersonAPILiveTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/resttemplate/postjson/PersonAPILiveTest.java @@ -1,12 +1,12 @@ -package org.baeldung.resttemplate.postjson; +package com.baeldung.resttemplate.postjson; import static org.junit.Assert.assertNotNull; import java.io.IOException; import java.net.URI; -import org.baeldung.resttemplate.RestTemplateConfigurationApplication; -import org.baeldung.resttemplate.web.dto.Person; +import com.baeldung.resttemplate.RestTemplateConfigurationApplication; +import com.baeldung.resttemplate.web.dto.Person; import org.json.JSONException; import org.json.JSONObject; import org.junit.BeforeClass; diff --git a/spring-resttemplate/src/test/java/org/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java b/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java similarity index 90% rename from spring-resttemplate/src/test/java/org/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java rename to spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java index 60069cea71..688b6e9d56 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/web/handler/RestTemplateResponseErrorHandlerIntegrationTest.java @@ -1,8 +1,8 @@ -package org.baeldung.web.handler; +package com.baeldung.web.handler; -import org.baeldung.resttemplate.web.exception.NotFoundException; -import org.baeldung.resttemplate.web.handler.RestTemplateResponseErrorHandler; -import org.baeldung.resttemplate.web.model.Bar; +import com.baeldung.resttemplate.web.exception.NotFoundException; +import com.baeldung.resttemplate.web.handler.RestTemplateResponseErrorHandler; +import com.baeldung.resttemplate.web.model.Bar; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-resttemplate/src/test/java/org/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java b/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java similarity index 92% rename from spring-resttemplate/src/test/java/org/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java rename to spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java index f93ba71666..9fe1232231 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java @@ -1,4 +1,4 @@ -package org.baeldung.web.service; +package com.baeldung.web.service; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; @@ -6,9 +6,9 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat import java.net.URI; -import org.baeldung.SpringTestConfig; -import org.baeldung.resttemplate.web.model.Employee; -import org.baeldung.resttemplate.web.service.EmployeeService; +import com.baeldung.SpringTestConfig; +import com.baeldung.resttemplate.web.model.Employee; +import com.baeldung.resttemplate.web.service.EmployeeService; import org.junit.Assert; import org.junit.Before; import org.junit.Test; diff --git a/spring-resttemplate/src/test/java/org/baeldung/web/service/EmployeeServiceUnitTest.java b/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java similarity index 84% rename from spring-resttemplate/src/test/java/org/baeldung/web/service/EmployeeServiceUnitTest.java rename to spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java index f4b391573a..6eb040414b 100644 --- a/spring-resttemplate/src/test/java/org/baeldung/web/service/EmployeeServiceUnitTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceUnitTest.java @@ -1,15 +1,13 @@ -package org.baeldung.web.service; +package com.baeldung.web.service; -import org.baeldung.resttemplate.web.model.Employee; -import org.baeldung.resttemplate.web.service.EmployeeService; +import com.baeldung.resttemplate.web.model.Employee; +import com.baeldung.resttemplate.web.service.EmployeeService; import org.junit.Assert; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; import org.mockito.runners.MockitoJUnitRunner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-resttemplate/src/test/java/org/baeldung/SpringContextTest.java b/spring-resttemplate/src/test/java/org/baeldung/SpringContextTest.java deleted file mode 100644 index e52d249f0b..0000000000 --- a/spring-resttemplate/src/test/java/org/baeldung/SpringContextTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.baeldung; - -import org.baeldung.resttemplate.RestTemplateConfigurationApplication; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestTemplateConfigurationApplication.class) -public class SpringContextTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} From 413b9d682ef07053245ed2ae340c0c1917de979f Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Thu, 19 Mar 2020 22:30:53 +0530 Subject: [PATCH 156/278] JAVA-60 Mvn Clean Install Profile Issue - Github 8189 - Updated README.md as per the latest profile based segregation that we follow in this repository --- README.md | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 5307efa008..47b9709465 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,38 @@ This project is **a collection of small and focused tutorials** - each covering A strong focus of these is, of course, the Spring Framework - Spring, Spring Boot and Spring Security. In additional to Spring, the modules here are covering a number of aspects in Java. +Profile based segregation +==================== + +We are using maven build profiles to segregate the huge list of individual projects we have in our repository. + +The projects are broadly divided into 3 list: first, second and heavy. + +Next, they are segregated further on the basis of tests that we want to execute. + +Therefore, we have a total of 6 profiles: + +| Profile | Includes | Type of test enabled | +| ---------------------- | --------------------------- | -------------------- | +| default-first | First set of projects | *UnitTest | +| integration-lite-first | First set of projects | *IntegrationTest | +| default-second | Second set of projects | *UnitTest | +| integration-lite-first | Second set of projects | *IntegrationTest | +| default-heavy | Heavy/long running projects | *UnitTest | +| integration-heavy | Heavy/long running projects | *IntegrationTest | Building the project ==================== -To do the full build, do: `mvn clean install` + +Though it should not be needed often to build the entire repository at once because we are usually concerned with a specific module. + +But if we want to, we can invoke the below command from the root of the repository if we want to build the entire repository with only Unit Tests enabled: + +`mvn clean install -Pdefault-first,default-second,default-heavy` + +or if we want to build the entire repository with Integration Tests enabled, we can do: + +`mvn clean install -Pintegration-lite-first,integration-lite-second,integration-heavy` Building a single module @@ -46,8 +74,16 @@ When you're working with an individual module, there's no need to import all of Running Tests ============= -The command `mvn clean install` will run the unit tests in a module. -To run the integration tests, use the command `mvn clean install -Pintegration-lite-first` +The command `mvn clean install` from within a module will run the unit tests in that module. +To run the integration tests, use the command: + +`mvn clean install -Pintegration-lite-first` or + +`mvn clean install -Pintegration-lite-second` or + +`mvn clean install -Pintegration-heavy` + +depending on the list where our module exists From 2261dd80d44ccea40fefc212930c5eb133a5fc49 Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Wed, 18 Mar 2020 10:34:00 +0100 Subject: [PATCH 157/278] [JAVA-22] Moved articles not in ebook from spring-boot-rest to spring-boot-mvc-2 --- .../spring-boot-mvc-2/README.md | 4 + spring-boot-modules/spring-boot-mvc-2/pom.xml | 22 +++ .../src/main/java/com/baeldung/etag/Foo.java | 95 +++++++++ .../java/com/baeldung/etag/FooController.java | 58 ++++++ .../main/java/com/baeldung/etag/FooDao.java | 8 + .../etag/SpringBootEtagApplication.java | 13 ++ .../java/com/baeldung/etag/WebConfig.java | 28 +++ .../SpringBootStudentsApplication.java | 13 ++ .../java/com/baeldung/students/Student.java | 53 ++++++ .../baeldung/students/StudentController.java | 74 +++++++ .../com/baeldung/students/StudentService.java | 51 +++++ .../src/main/resources/WEB-INF/web.xml | 18 ++ .../foo_API_test.postman_collection.json | 180 ++++++++++++++++++ .../baeldung/etag/EtagIntegrationTest.java | 123 ++++++++++++ .../java/com/baeldung/mime/FooLiveTest.java | 82 ++++++++ .../java/com/baeldung/mime/IMarshaller.java | 15 ++ .../com/baeldung/mime/JacksonMarshaller.java | 75 ++++++++ .../baeldung/mime/TestMarshallerFactory.java | 48 +++++ .../com/baeldung/mime/XStreamMarshaller.java | 46 +++++ .../StudentControllerIntegrationTest.java | 73 +++++++ spring-boot-rest/README.md | 6 +- 21 files changed, 1080 insertions(+), 5 deletions(-) create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/Foo.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooController.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooDao.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/SpringBootEtagApplication.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/WebConfig.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/SpringBootStudentsApplication.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/Student.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentController.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentService.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/resources/WEB-INF/web.xml create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/main/resources/foo_API_test.postman_collection.json create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/etag/EtagIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/FooLiveTest.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/IMarshaller.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/JacksonMarshaller.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/TestMarshallerFactory.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/XStreamMarshaller.java create mode 100644 spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/students/StudentControllerIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-mvc-2/README.md b/spring-boot-modules/spring-boot-mvc-2/README.md index dc6a136131..d7341cca35 100644 --- a/spring-boot-modules/spring-boot-mvc-2/README.md +++ b/spring-boot-modules/spring-boot-mvc-2/README.md @@ -6,4 +6,8 @@ This module contains articles about Spring Web MVC in Spring Boot projects. - [Functional Controllers in Spring MVC](https://www.baeldung.com/spring-mvc-functional-controllers) - [Specify an Array of Strings as Body Parameters in Swagger](https://www.baeldung.com/swagger-body-array-of-strings) +- [ETags for REST with Spring](https://www.baeldung.com/etags-for-rest-with-spring) +- [Testing REST with multiple MIME types](https://www.baeldung.com/testing-rest-api-with-multiple-media-types) +- [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) +- [Spring Boot Consuming and Producing JSON](https://www.baeldung.com/spring-boot-json) - More articles: [[prev -->]](/spring-boot-modules/spring-boot-mvc) diff --git a/spring-boot-modules/spring-boot-mvc-2/pom.xml b/spring-boot-modules/spring-boot-mvc-2/pom.xml index edebd41986..f527fd78f6 100644 --- a/spring-boot-modules/spring-boot-mvc-2/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-2/pom.xml @@ -49,6 +49,27 @@ org.apache.commons commons-lang3 + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + com.fasterxml.jackson.core + jackson-databind + + + + com.h2database + h2 + + + + com.thoughtworks.xstream + xstream + ${xstream.version} @@ -103,6 +124,7 @@ com.baeldung.swagger2boot.SpringBootSwaggerApplication 2.2.0.BUILD-SNAPSHOT + 1.4.11.1 \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/Foo.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/Foo.java new file mode 100644 index 0000000000..e553ca1b72 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/Foo.java @@ -0,0 +1,95 @@ +package com.baeldung.etag; + +import java.io.Serializable; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.Version; + +@Entity +public class Foo implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + private long id; + + @Column(nullable = false) + private String name; + + @Version + private long version; + + public Foo() { + super(); + } + + public Foo(final String name) { + super(); + + this.name = name; + } + + // API + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + public long getVersion() { + return version; + } + + public void setVersion(long version) { + this.version = version; + } + + // + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final Foo other = (Foo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Foo [name=").append(name).append("]"); + return builder.toString(); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooController.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooController.java new file mode 100644 index 0000000000..58f366501d --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooController.java @@ -0,0 +1,58 @@ +package com.baeldung.etag; + +import javax.servlet.http.HttpServletResponse; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.server.ResponseStatusException; + +@RestController +@RequestMapping(value = "/foos") +public class FooController { + + @Autowired + private FooDao fooDao; + + @GetMapping(value = "/{id}") + public Foo findById(@PathVariable("id") final Long id, final HttpServletResponse response) { + return fooDao.findById(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); + } + + // Note: the global filter overrides the ETag value we set here. We can still + // analyze its behaviour in the Integration Test. + @GetMapping(value = "/{id}/custom-etag") + public ResponseEntity findByIdWithCustomEtag(@PathVariable("id") final Long id, + final HttpServletResponse response) { + final Foo foo = fooDao.findById(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); + return ResponseEntity.ok().eTag(Long.toString(foo.getVersion())).body(foo); + } + + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + public Foo create(@RequestBody final Foo resource, final HttpServletResponse response) { + return fooDao.save(resource); + } + + @PutMapping(value = "/{id}") + @ResponseStatus(HttpStatus.OK) + public void update(@PathVariable("id") final Long id, @RequestBody final Foo resource) { + fooDao.save(resource); + } + + @DeleteMapping(value = "/{id}") + @ResponseStatus(HttpStatus.OK) + public void delete(@PathVariable("id") final Long id) { + fooDao.deleteById(id); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooDao.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooDao.java new file mode 100644 index 0000000000..aff011af4a --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/FooDao.java @@ -0,0 +1,8 @@ +package com.baeldung.etag; + +import org.springframework.data.repository.CrudRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface FooDao extends CrudRepository{ +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/SpringBootEtagApplication.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/SpringBootEtagApplication.java new file mode 100644 index 0000000000..9e58a1550c --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/SpringBootEtagApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.etag; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootEtagApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootEtagApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/WebConfig.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/WebConfig.java new file mode 100644 index 0000000000..bef468452a --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/etag/WebConfig.java @@ -0,0 +1,28 @@ +package com.baeldung.etag; + +import org.springframework.boot.web.servlet.FilterRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.filter.ShallowEtagHeaderFilter; + +@Configuration +public class WebConfig { + + // Etags + + // If we're not using Spring Boot we can make use of + // AbstractAnnotationConfigDispatcherServletInitializer#getServletFilters + @Bean + public FilterRegistrationBean shallowEtagHeaderFilter() { + FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean<>( new ShallowEtagHeaderFilter()); + filterRegistrationBean.addUrlPatterns("/foos/*"); + filterRegistrationBean.setName("etagFilter"); + return filterRegistrationBean; + } + + // We can also just declare the filter directly + // @Bean + // public ShallowEtagHeaderFilter shallowEtagHeaderFilter() { + // return new ShallowEtagHeaderFilter(); + // } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/SpringBootStudentsApplication.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/SpringBootStudentsApplication.java new file mode 100644 index 0000000000..9c499e6103 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/SpringBootStudentsApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.students; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringBootStudentsApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootStudentsApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/Student.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/Student.java new file mode 100644 index 0000000000..16d02fe14a --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/Student.java @@ -0,0 +1,53 @@ +package com.baeldung.students; + +public class Student { + + private long id; + private String firstName; + private String lastName; + + public Student() {} + + public Student(String firstName, String lastName) { + super(); + this.firstName = firstName; + this.lastName = lastName; + } + + public Student(long id, String firstName, String lastName) { + super(); + this.id = id; + this.firstName = firstName; + this.lastName = lastName; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + @Override + public String toString() { + return "Student [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + "]"; + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentController.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentController.java new file mode 100644 index 0000000000..c71bb6c6e6 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentController.java @@ -0,0 +1,74 @@ +package com.baeldung.students; + +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +import com.baeldung.students.StudentService; + +@RestController +@RequestMapping("/students") +public class StudentController { + + @Autowired + private StudentService service; + + @GetMapping("/") + public List read() { + return service.readAll(); + } + + @GetMapping("/{id}") + public ResponseEntity read(@PathVariable("id") Long id) { + Student foundStudent = service.read(id); + if (foundStudent == null) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(foundStudent); + } + } + + @PostMapping("/") + public ResponseEntity create(@RequestBody Student student) throws URISyntaxException { + Student createdStudent = service.create(student); + + URI uri = ServletUriComponentsBuilder.fromCurrentRequest() + .path("/{id}") + .buildAndExpand(createdStudent.getId()) + .toUri(); + + return ResponseEntity.created(uri) + .body(createdStudent); + + } + + @PutMapping("/{id}") + public ResponseEntity update(@RequestBody Student student, @PathVariable Long id) { + Student updatedStudent = service.update(id, student); + if (updatedStudent == null) { + return ResponseEntity.notFound().build(); + } else { + return ResponseEntity.ok(updatedStudent); + } + } + + @DeleteMapping("/{id}") + public ResponseEntity deleteStudent(@PathVariable Long id) { + service.delete(id); + + return ResponseEntity.noContent().build(); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentService.java b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentService.java new file mode 100644 index 0000000000..80f6dfd514 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/java/com/baeldung/students/StudentService.java @@ -0,0 +1,51 @@ +package com.baeldung.students; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicLong; +import java.util.function.Function; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Service; + +@Service +public class StudentService { + + // DB repository mock + private Map repository = Arrays.asList( + new Student[]{ + new Student(1, "Alan","Turing"), + new Student(2, "Sebastian","Bach"), + new Student(3, "Pablo","Picasso"), + }).stream() + .collect(Collectors.toConcurrentMap(s -> s.getId(), Function.identity())); + + // DB id sequence mock + private AtomicLong sequence = new AtomicLong(3); + + public List readAll() { + return repository.values().stream().collect(Collectors.toList()); + } + + public Student read(Long id) { + return repository.get(id); + } + + public Student create(Student student) { + long key = sequence.incrementAndGet(); + student.setId(key); + repository.put(key, student); + return student; + } + + public Student update(Long id, Student student) { + student.setId(id); + Student oldStudent = repository.replace(id, student); + return oldStudent == null ? null : student; + } + + public void delete(Long id) { + repository.remove(id); + } +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/resources/WEB-INF/web.xml b/spring-boot-modules/spring-boot-mvc-2/src/main/resources/WEB-INF/web.xml new file mode 100644 index 0000000000..7f36b33b38 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/resources/WEB-INF/web.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/main/resources/foo_API_test.postman_collection.json b/spring-boot-modules/spring-boot-mvc-2/src/main/resources/foo_API_test.postman_collection.json new file mode 100644 index 0000000000..dc4acafab3 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/main/resources/foo_API_test.postman_collection.json @@ -0,0 +1,180 @@ +{ + "info": { + "_postman_id": "9989b5be-13ba-4d22-8e43-d05dbf628e58", + "name": "foo API test", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" + }, + "item": [ + { + "name": "add a foo", + "event": [ + { + "listen": "test", + "script": { + "id": "a01534dc-6fc7-4c54-ba1d-6bcf311e5836", + "exec": [ + "pm.test(\"success status\", () => pm.response.to.be.success );", + "", + "pm.test(\"name is correct\", () => ", + " pm.expect(pm.response.json().name).to.equal(\"Transformers\"));", + "", + "pm.test(\"id was assigned\", () => ", + " pm.expect(pm.response.json().id).to.be.not.null );", + "", + "pm.variables.set(\"id\", pm.response.json().id);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "name": "Content-Type", + "value": "application/json", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Transformers\"\n}" + }, + "url": { + "raw": "http://localhost:8080/spring-boot-rest/foos", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "spring-boot-rest", + "foos" + ] + } + }, + "response": [] + }, + { + "name": "get a foo", + "event": [ + { + "listen": "test", + "script": { + "id": "03de440c-b483-4ab8-a11a-d0c99b349963", + "exec": [ + "pm.test(\"success status\", () => pm.response.to.be.success );", + "", + "pm.test(\"name is correct\", () => ", + " pm.expect(pm.response.json().name).to.equal(\"Transformers\"));", + "", + "pm.test(\"id is correct\", () => ", + " pm.expect(pm.response.json().id).to.equal(pm.variables.get(\"id\")) );" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8080/spring-boot-rest/foos/{{id}}", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "spring-boot-rest", + "foos", + "{{id}}" + ] + } + }, + "response": [] + }, + { + "name": "delete a foo", + "event": [ + { + "listen": "test", + "script": { + "id": "74c1bb0f-c06c-48b1-a545-459233541b14", + "exec": [ + "pm.test(\"success status\", () => pm.response.to.be.success );" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "DELETE", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8080/spring-boot-rest/foos/{{id}}", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "spring-boot-rest", + "foos", + "{{id}}" + ] + } + }, + "response": [] + }, + { + "name": "verify delete", + "event": [ + { + "listen": "test", + "script": { + "id": "03de440c-b483-4ab8-a11a-d0c99b349963", + "exec": [ + "pm.test(\"status is 500\", () => pm.response.to.have.status(500) );", + "", + "pm.test(\"no value present\", () => ", + " pm.expect(pm.response.json().cause).to.equal(\"No value present\"));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [], + "body": { + "mode": "raw", + "raw": "" + }, + "url": { + "raw": "http://localhost:8080/spring-boot-rest/foos/{{id}}", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8080", + "path": [ + "spring-boot-rest", + "foos", + "{{id}}" + ] + } + }, + "response": [] + } + ] +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/etag/EtagIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/etag/EtagIntegrationTest.java new file mode 100644 index 0000000000..88c5ae1686 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/etag/EtagIntegrationTest.java @@ -0,0 +1,123 @@ +package com.baeldung.etag; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import org.assertj.core.util.Preconditions; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import io.restassured.RestAssured; +import io.restassured.http.ContentType; +import io.restassured.response.Response; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@ComponentScan(basePackageClasses = WebConfig.class) +@EnableAutoConfiguration +public class EtagIntegrationTest { + + @LocalServerPort + private int port; + + @Test + public void givenResourceExists_whenRetrievingResource_thenEtagIsAlsoReturned() { + // Given + final String uriOfResource = createAsUri(); + + // When + final Response findOneResponse = RestAssured.given().header("Accept", "application/json").get(uriOfResource); + + // Then + assertNotNull(findOneResponse.getHeader(HttpHeaders.ETAG)); + } + + @Test + public void givenResourceWasRetrieved_whenRetrievingAgainWithEtag_thenNotModifiedReturned() { + // Given + final String uriOfResource = createAsUri(); + final Response findOneResponse = RestAssured.given().header("Accept", "application/json").get(uriOfResource); + final String etagValue = findOneResponse.getHeader(HttpHeaders.ETAG); + + // When + final Response secondFindOneResponse = RestAssured.given().header("Accept", "application/json") + .headers("If-None-Match", etagValue).get(uriOfResource); + + // Then + assertTrue(secondFindOneResponse.getStatusCode() == 304); + } + + @Test + public void givenResourceWasRetrievedThenModified_whenRetrievingAgainWithEtag_thenResourceIsReturned() { + // Given + final String uriOfResource = createAsUri(); + final Response firstFindOneResponse = RestAssured.given().header("Accept", "application/json") + .get(uriOfResource); + final String etagValue = firstFindOneResponse.getHeader(HttpHeaders.ETAG); + final long createdId = firstFindOneResponse.jsonPath().getLong("id"); + + Foo updatedFoo = new Foo("updated value"); + updatedFoo.setId(createdId); + Response updatedResponse = RestAssured.given().contentType(ContentType.JSON).body(updatedFoo) + .put(uriOfResource); + assertThat(updatedResponse.getStatusCode() == 200); + + // When + final Response secondFindOneResponse = RestAssured.given().header("Accept", "application/json") + .headers("If-None-Match", etagValue).get(uriOfResource); + + // Then + assertTrue(secondFindOneResponse.getStatusCode() == 200); + } + + @Test + @Ignore("Not Yet Implemented By Spring - https://jira.springsource.org/browse/SPR-10164") + public void givenResourceExists_whenRetrievedWithIfMatchIncorrectEtag_then412IsReceived() { + // Given + final String uriOfResource = createAsUri(); + + // When + final Response findOneResponse = RestAssured.given().header("Accept", "application/json") + .headers("If-Match", randomAlphabetic(8)).get(uriOfResource); + + // Then + assertTrue(findOneResponse.getStatusCode() == 412); + } + + private final String createAsUri() { + final Response response = createAsResponse(new Foo(randomAlphabetic(6))); + Preconditions.checkState(response.getStatusCode() == 201, "create operation: " + response.getStatusCode()); + + return getURL() + "/" + response.getBody().as(Foo.class).getId(); + } + + private Response createAsResponse(final Foo resource) { + String resourceAsString; + try { + resourceAsString = new ObjectMapper().writeValueAsString(resource); + } catch (JsonProcessingException e) { + throw new AssertionError("Error during serialization"); + } + return RestAssured.given().contentType(MediaType.APPLICATION_JSON.toString()).body(resourceAsString) + .post(getURL()); + } + + private String getURL() { + return "http://localhost:" + port + "/foos"; + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/FooLiveTest.java b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/FooLiveTest.java new file mode 100644 index 0000000000..e65b106ead --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/FooLiveTest.java @@ -0,0 +1,82 @@ +package com.baeldung.mime; + +import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.etag.Foo; +import com.baeldung.etag.WebConfig; + +import io.restassured.RestAssured; +import io.restassured.response.Response; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes= WebConfig.class, webEnvironment = WebEnvironment.RANDOM_PORT) +@ComponentScan({"com.baeldung.mime", "com.baeldung.etag"}) +@EnableAutoConfiguration +@ActiveProfiles("test") +public class FooLiveTest { + + @LocalServerPort + private int port; + + @Autowired + protected IMarshaller marshaller; + + // API + + public final void create() { + create(new Foo(randomAlphabetic(6))); + } + + public final String createAsUri() { + return createAsUri(new Foo(randomAlphabetic(6))); + } + + protected final void create(final Foo resource) { + createAsUri(resource); + } + + private final String createAsUri(final Foo resource) { + final Response response = createAsResponse(resource); + return getURL() + "/" + response.getBody().as(Foo.class).getId(); + } + + private final Response createAsResponse(final Foo resource) { + + final String resourceAsString = marshaller.encode(resource); + return RestAssured.given() + .contentType(marshaller.getMime()) + .body(resourceAsString) + .post(getURL()); + } + + // + + protected String getURL() { + return "http://localhost:" + port + "/foos"; + } + + @Test + public void givenResourceExists_whenRetrievingResource_thenEtagIsAlsoReturned() { + // Given + final String uriOfResource = createAsUri(); + + // When + final Response findOneResponse = RestAssured.given().header("Accept", "application/json").get(uriOfResource); + + // Then + assertEquals(findOneResponse.getStatusCode(), 200); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/IMarshaller.java b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/IMarshaller.java new file mode 100644 index 0000000000..79c0616043 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/IMarshaller.java @@ -0,0 +1,15 @@ +package com.baeldung.mime; + +import java.util.List; + +public interface IMarshaller { + + String encode(final T entity); + + T decode(final String entityAsString, final Class clazz); + + List decodeList(final String entitiesAsString, final Class clazz); + + String getMime(); + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/JacksonMarshaller.java b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/JacksonMarshaller.java new file mode 100644 index 0000000000..9dee0ef2cd --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/JacksonMarshaller.java @@ -0,0 +1,75 @@ +package com.baeldung.mime; + +import java.io.IOException; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.MediaType; + +import com.baeldung.etag.Foo; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; + +public final class JacksonMarshaller implements IMarshaller { + private final Logger logger = LoggerFactory.getLogger(JacksonMarshaller.class); + + private final ObjectMapper objectMapper; + + public JacksonMarshaller() { + super(); + + objectMapper = new ObjectMapper(); + } + + // API + + @Override + public final String encode(final T resource) { + String entityAsJSON = null; + try { + entityAsJSON = objectMapper.writeValueAsString(resource); + } catch (final IOException ioEx) { + logger.error("", ioEx); + } + + return entityAsJSON; + } + + @Override + public final T decode(final String resourceAsString, final Class clazz) { + T entity = null; + try { + entity = objectMapper.readValue(resourceAsString, clazz); + } catch (final IOException ioEx) { + logger.error("", ioEx); + } + + return entity; + } + + @SuppressWarnings("unchecked") + @Override + public final List decodeList(final String resourcesAsString, final Class clazz) { + List entities = null; + try { + if (clazz.equals(Foo.class)) { + entities = objectMapper.readValue(resourcesAsString, new TypeReference>() { + // ... + }); + } else { + entities = objectMapper.readValue(resourcesAsString, List.class); + } + } catch (final IOException ioEx) { + logger.error("", ioEx); + } + + return entities; + } + + @Override + public final String getMime() { + return MediaType.APPLICATION_JSON.toString(); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/TestMarshallerFactory.java b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/TestMarshallerFactory.java new file mode 100644 index 0000000000..d7cd875ae4 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/TestMarshallerFactory.java @@ -0,0 +1,48 @@ +package com.baeldung.mime; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Profile; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +@Component +@Profile("test") +public class TestMarshallerFactory implements FactoryBean { + + @Autowired + private Environment env; + + public TestMarshallerFactory() { + super(); + } + + // API + + @Override + public IMarshaller getObject() { + final String testMime = env.getProperty("test.mime"); + if (testMime != null) { + switch (testMime) { + case "json": + return new JacksonMarshaller(); + case "xml": + return new XStreamMarshaller(); + default: + throw new IllegalStateException(); + } + } + + return new JacksonMarshaller(); + } + + @Override + public Class getObjectType() { + return IMarshaller.class; + } + + @Override + public boolean isSingleton() { + return true; + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/XStreamMarshaller.java b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/XStreamMarshaller.java new file mode 100644 index 0000000000..2c67694e83 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/mime/XStreamMarshaller.java @@ -0,0 +1,46 @@ +package com.baeldung.mime; + +import java.util.List; + +import org.springframework.http.MediaType; + +import com.baeldung.etag.Foo; +import com.thoughtworks.xstream.XStream; + +public final class XStreamMarshaller implements IMarshaller { + + private XStream xstream; + + public XStreamMarshaller() { + super(); + + xstream = new XStream(); + xstream.autodetectAnnotations(true); + xstream.processAnnotations(Foo.class); + } + + // API + + @Override + public final String encode(final T resource) { + return xstream.toXML(resource); + } + + @SuppressWarnings("unchecked") + @Override + public final T decode(final String resourceAsString, final Class clazz) { + return (T) xstream.fromXML(resourceAsString); + } + + @SuppressWarnings("unchecked") + @Override + public List decodeList(final String resourcesAsString, final Class clazz) { + return this.decode(resourcesAsString, List.class); + } + + @Override + public final String getMime() { + return MediaType.APPLICATION_XML.toString(); + } + +} diff --git a/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/students/StudentControllerIntegrationTest.java b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/students/StudentControllerIntegrationTest.java new file mode 100644 index 0000000000..577dbb6eb1 --- /dev/null +++ b/spring-boot-modules/spring-boot-mvc-2/src/test/java/com/baeldung/students/StudentControllerIntegrationTest.java @@ -0,0 +1,73 @@ +package com.baeldung.students; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest +@AutoConfigureMockMvc +public class StudentControllerIntegrationTest { + + private static final String STUDENTS_PATH = "/students/"; + + @Autowired + private MockMvc mockMvc; + + @Test + public void whenReadAll_thenStatusIsOk() throws Exception { + this.mockMvc.perform(get(STUDENTS_PATH)) + .andExpect(status().isOk()); + } + + @Test + public void whenReadOne_thenStatusIsOk() throws Exception { + this.mockMvc.perform(get(STUDENTS_PATH + 1)) + .andExpect(status().isOk()); + } + + @Test + public void whenCreate_thenStatusIsCreated() throws Exception { + Student student = new Student(10, "Albert", "Einstein"); + this.mockMvc.perform(post(STUDENTS_PATH).content(asJsonString(student)) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isCreated()); + } + + @Test + public void whenUpdate_thenStatusIsOk() throws Exception { + Student student = new Student(1, "Nikola", "Tesla"); + this.mockMvc.perform(put(STUDENTS_PATH + 1) + .content(asJsonString(student)) + .contentType(MediaType.APPLICATION_JSON_VALUE)) + .andExpect(status().isOk()); + } + + @Test + public void whenDelete_thenStatusIsNoContent() throws Exception { + this.mockMvc.perform(delete(STUDENTS_PATH + 3)) + .andExpect(status().isNoContent()); + } + + private String asJsonString(final Object obj) { + try { + return new ObjectMapper().writeValueAsString(obj); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + +} diff --git a/spring-boot-rest/README.md b/spring-boot-rest/README.md index f78c88d30b..861181c53e 100644 --- a/spring-boot-rest/README.md +++ b/spring-boot-rest/README.md @@ -4,12 +4,7 @@ This module contains articles about Spring Boot RESTful APIs. ### Relevant Articles -- [HATEOAS for a Spring REST Service](https://www.baeldung.com/rest-api-discoverability-with-spring) - [Versioning a REST API](https://www.baeldung.com/rest-versioning) -- [ETags for REST with Spring](https://www.baeldung.com/etags-for-rest-with-spring) -- [Testing REST with multiple MIME types](https://www.baeldung.com/testing-rest-api-with-multiple-media-types) -- [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) -- [Spring Boot Consuming and Producing JSON](https://www.baeldung.com/spring-boot-json) ### E-book @@ -25,6 +20,7 @@ These articles are part of the Spring REST E-book: 8. [An Intro to Spring HATEOAS](https://www.baeldung.com/spring-hateoas-tutorial) 9. [REST Pagination in Spring](https://www.baeldung.com/rest-api-pagination-in-spring) 10. [Test a REST API with Java](https://www.baeldung.com/integration-testing-a-rest-api) +11. [HATEOAS for a Spring REST Service](https://www.baeldung.com/rest-api-discoverability-with-spring) NOTE: Since this is a module tied to an e-book, it should not be moved or used to store the code for any further article. From 8894f16741c383b6995e957dd2be2f33ded6e63a Mon Sep 17 00:00:00 2001 From: dupirefr Date: Sun, 1 Mar 2020 10:58:06 +0100 Subject: [PATCH 158/278] [JAVA-134] Mockito versio update --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a295439951..d320e989f7 100644 --- a/pom.xml +++ b/pom.xml @@ -1330,7 +1330,7 @@ 4.12 2.2 1.3 - 2.21.0 + 3.3.0 1.7.30 From 1c50dedb91031dfcebaaf7d0dcd9440e671b75d5 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Mon, 2 Mar 2020 23:37:40 +0100 Subject: [PATCH 159/278] [JAVA-134] Added byte-buddy dependencies with version used by mockito to avoid versions conflict --- pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d320e989f7..3e8e5f7ac7 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,12 @@ ${hamcrest-all.version} test + + net.bytebuddy + byte-buddy + ${byte-buddy.version} + test + org.mockito mockito-core @@ -1330,7 +1336,8 @@ 4.12 2.2 1.3 - 3.3.0 + 3.3.0 + 1.10.5 1.7.30 From 08e93e8da504fe7533ebab70b6a5047095c72cfd Mon Sep 17 00:00:00 2001 From: dupirefr Date: Sun, 8 Mar 2020 09:06:30 +0100 Subject: [PATCH 160/278] [JAVA-134] Created a powermockito module that uses version 2.21.0 version of Mockito --- testing-modules/mockito/pom.xml | 13 -------- testing-modules/pom.xml | 1 + testing-modules/powermockito/pom.xml | 33 +++++++++++++++++++ .../CollaboratorForPartialMocking.java | 0 .../CollaboratorWithFinalMethods.java | 0 .../CollaboratorWithStaticMethods.java | 0 .../introduction/LuckyNumberGenerator.java | 0 .../LuckyNumberGeneratorUnitTest.java | 0 .../introduction/PowerMockitoUnitTest.java | 2 +- 9 files changed, 35 insertions(+), 14 deletions(-) create mode 100644 testing-modules/powermockito/pom.xml rename testing-modules/{mockito => powermockito}/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java (100%) rename testing-modules/{mockito => powermockito}/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java (100%) rename testing-modules/{mockito => powermockito}/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java (100%) rename testing-modules/{mockito => powermockito}/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java (100%) rename testing-modules/{mockito => powermockito}/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java (100%) rename testing-modules/{mockito => powermockito}/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java (98%) diff --git a/testing-modules/mockito/pom.xml b/testing-modules/mockito/pom.xml index aae3981c66..ea5ef4c322 100644 --- a/testing-modules/mockito/pom.xml +++ b/testing-modules/mockito/pom.xml @@ -44,19 +44,6 @@ - - - org.powermock - powermock-module-junit4 - ${powermock.version} - test - - - org.powermock - powermock-api-mockito2 - ${powermock.version} - test - org.springframework.boot spring-boot-starter diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index f4a8368581..e413e02e48 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -40,6 +40,7 @@ xmlunit-2 junit-4 testing-libraries + powermockito diff --git a/testing-modules/powermockito/pom.xml b/testing-modules/powermockito/pom.xml new file mode 100644 index 0000000000..fde7bfe78c --- /dev/null +++ b/testing-modules/powermockito/pom.xml @@ -0,0 +1,33 @@ + + + + testing-modules + com.baeldung + 1.0.0-SNAPSHOT + + 4.0.0 + + powermockito + + + + org.powermock + powermock-module-junit4 + ${powermock.version} + test + + + org.powermock + powermock-api-mockito2 + ${powermock.version} + test + + + + + 2.21.0 + 2.0.2 + + \ No newline at end of file diff --git a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java b/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java similarity index 100% rename from testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java rename to testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java diff --git a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java b/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java similarity index 100% rename from testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java rename to testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java diff --git a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java b/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java similarity index 100% rename from testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java rename to testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java diff --git a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java b/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java similarity index 100% rename from testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java rename to testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java diff --git a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java b/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java similarity index 100% rename from testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java rename to testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java diff --git a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java b/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java similarity index 98% rename from testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java rename to testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java index 4943b0486a..1b2bb99896 100644 --- a/testing-modules/mockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java +++ b/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java @@ -68,7 +68,7 @@ public class PowerMockitoUnitTest { when(mock.finalMethod()).thenReturn("I am a final mock method."); returnValue = mock.finalMethod(); - verify(mock,times(3)).finalMethod(); + verify(mock).finalMethod(); assertEquals("I am a final mock method.", returnValue); when(mock, "privateMethod").thenReturn("I am a private mock method."); From 4226bdc983fcdfbd37d8a598369757290d49b58e Mon Sep 17 00:00:00 2001 From: dupirefr Date: Tue, 10 Mar 2020 08:03:40 +0100 Subject: [PATCH 161/278] [JAVA-134] Retrograding Mockito and Byte-Buddy versions for ejb-beans module as they conflict with dependencies of this module --- spring-ejb/ejb-beans/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-ejb/ejb-beans/pom.xml b/spring-ejb/ejb-beans/pom.xml index eecf8c1d23..c9edfc21f8 100644 --- a/spring-ejb/ejb-beans/pom.xml +++ b/spring-ejb/ejb-beans/pom.xml @@ -121,6 +121,8 @@ 5.2.3.RELEASE 5.10.2 5.13.1 + 2.21.0 + 1.8.5 From fb8f9f1f6237388ffc964ba4a5b06c3665d831bd Mon Sep 17 00:00:00 2001 From: dupirefr Date: Tue, 10 Mar 2020 08:09:57 +0100 Subject: [PATCH 162/278] [JAVA-134] Creating README.md in new powermockito module --- testing-modules/mockito/README.md | 2 -- testing-modules/powermockito/README.md | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 testing-modules/powermockito/README.md diff --git a/testing-modules/mockito/README.md b/testing-modules/mockito/README.md index 7cef9ee8f6..5f307c2f0b 100644 --- a/testing-modules/mockito/README.md +++ b/testing-modules/mockito/README.md @@ -8,8 +8,6 @@ - [Mockito When/Then Cookbook](https://www.baeldung.com/mockito-behavior) - [Getting Started with Mockito @Mock, @Spy, @Captor and @InjectMocks](https://www.baeldung.com/mockito-annotations) - [Mockito’s Mock Methods](https://www.baeldung.com/mockito-mock-methods) -- [Introduction to PowerMock](https://www.baeldung.com/intro-to-powermock) -- [Mocking of Private Methods Using PowerMock](https://www.baeldung.com/powermock-private-method) - [Mocking Exception Throwing using Mockito](https://www.baeldung.com/mockito-exceptions) - [Mocking Void Methods with Mockito](https://www.baeldung.com/mockito-void-methods) - [Mock Final Classes and Methods with Mockito](https://www.baeldung.com/mockito-final) diff --git a/testing-modules/powermockito/README.md b/testing-modules/powermockito/README.md new file mode 100644 index 0000000000..df9fb0088c --- /dev/null +++ b/testing-modules/powermockito/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Introduction to PowerMock](https://www.baeldung.com/intro-to-powermock) +- [Mocking of Private Methods Using PowerMock](https://www.baeldung.com/powermock-private-method) From a2c7348831e548bd880e32ac4c1824a063409c27 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Wed, 18 Mar 2020 08:17:19 +0100 Subject: [PATCH 163/278] [JAVA-134] Renamed powermockito module to powermock --- testing-modules/{powermockito => powermock}/README.md | 0 testing-modules/{powermockito => powermock}/pom.xml | 0 .../powermockito/introduction/CollaboratorForPartialMocking.java | 0 .../powermockito/introduction/CollaboratorWithFinalMethods.java | 0 .../powermockito/introduction/CollaboratorWithStaticMethods.java | 0 .../baeldung/powermockito/introduction/LuckyNumberGenerator.java | 0 .../powermockito/introduction/LuckyNumberGeneratorUnitTest.java | 0 .../baeldung/powermockito/introduction/PowerMockitoUnitTest.java | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename testing-modules/{powermockito => powermock}/README.md (100%) rename testing-modules/{powermockito => powermock}/pom.xml (100%) rename testing-modules/{powermockito => powermock}/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java (100%) rename testing-modules/{powermockito => powermock}/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java (100%) rename testing-modules/{powermockito => powermock}/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java (100%) rename testing-modules/{powermockito => powermock}/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java (100%) rename testing-modules/{powermockito => powermock}/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java (100%) rename testing-modules/{powermockito => powermock}/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java (100%) diff --git a/testing-modules/powermockito/README.md b/testing-modules/powermock/README.md similarity index 100% rename from testing-modules/powermockito/README.md rename to testing-modules/powermock/README.md diff --git a/testing-modules/powermockito/pom.xml b/testing-modules/powermock/pom.xml similarity index 100% rename from testing-modules/powermockito/pom.xml rename to testing-modules/powermock/pom.xml diff --git a/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java b/testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java similarity index 100% rename from testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java rename to testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/CollaboratorForPartialMocking.java diff --git a/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java b/testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java similarity index 100% rename from testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java rename to testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithFinalMethods.java diff --git a/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java b/testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java similarity index 100% rename from testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java rename to testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/CollaboratorWithStaticMethods.java diff --git a/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java b/testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java similarity index 100% rename from testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java rename to testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGenerator.java diff --git a/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java b/testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java similarity index 100% rename from testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java rename to testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/LuckyNumberGeneratorUnitTest.java diff --git a/testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java b/testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java similarity index 100% rename from testing-modules/powermockito/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java rename to testing-modules/powermock/src/test/java/com/baeldung/powermockito/introduction/PowerMockitoUnitTest.java From 27620bb3e7a9cc885282d53a4baf5c3f398941d8 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 08:05:23 +0100 Subject: [PATCH 164/278] [JAVA-134] Actually renamed that module since IntelliJ didn't do it right the first time --- testing-modules/pom.xml | 2 +- testing-modules/powermock/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/testing-modules/pom.xml b/testing-modules/pom.xml index e413e02e48..951909b36f 100644 --- a/testing-modules/pom.xml +++ b/testing-modules/pom.xml @@ -40,7 +40,7 @@ xmlunit-2 junit-4 testing-libraries - powermockito + powermock diff --git a/testing-modules/powermock/pom.xml b/testing-modules/powermock/pom.xml index fde7bfe78c..21b2e98af0 100644 --- a/testing-modules/powermock/pom.xml +++ b/testing-modules/powermock/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - powermockito + powermock From c6bd70983692310fc828db21210ab0d527ef7ea9 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 20:30:57 +0100 Subject: [PATCH 165/278] [JAVA-134] Fixed whitespacing in parent pom.xml --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3e8e5f7ac7..443d79a355 100644 --- a/pom.xml +++ b/pom.xml @@ -1336,8 +1336,8 @@ 4.12 2.2 1.3 - 3.3.0 - 1.10.5 + 3.3.0 + 1.10.5 1.7.30 From f3d7a9d5febfe9c5aab4f6e7558ada74bce9a4a3 Mon Sep 17 00:00:00 2001 From: Loredana Date: Thu, 19 Mar 2020 22:38:01 +0200 Subject: [PATCH 166/278] move nullaway article --- libraries-3/README.md | 2 + libraries-3/pom.xml | 56 ++++++++++++++++ .../baeldung/nullaway/NullAwayExample.java | 2 - .../java/com/baeldung/nullaway/Person.java | 65 +++++++++++++++++++ libraries/README.md | 1 - libraries/pom.xml | 57 ---------------- 6 files changed, 123 insertions(+), 60 deletions(-) rename {libraries => libraries-3}/src/main/java/com/baeldung/nullaway/NullAwayExample.java (93%) create mode 100644 libraries-3/src/main/java/com/baeldung/nullaway/Person.java diff --git a/libraries-3/README.md b/libraries-3/README.md index 0a76c7ff6e..f3c3375098 100644 --- a/libraries-3/README.md +++ b/libraries-3/README.md @@ -14,3 +14,5 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Introduction to cache2k](https://www.baeldung.com/java-cache2k) - [Introduction to the jcabi-aspects AOP Annotations Library](https://www.baeldung.com/java-jcabi-aspects) - [Introduction to Takes](https://www.baeldung.com/java-takes) +- [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway) + diff --git a/libraries-3/pom.xml b/libraries-3/pom.xml index 68b5f2aa21..4b9cac8cff 100644 --- a/libraries-3/pom.xml +++ b/libraries-3/pom.xml @@ -94,6 +94,23 @@ velocity-engine-core ${velocity-engine-core.version} + + com.uber.nullaway + nullaway + 0.3.0 + + + org.codehaus.plexus + plexus-compiler-javac-errorprone + 2.8 + + + + com.google.errorprone + error_prone_core + 2.1.3 + @@ -130,6 +147,45 @@ + + org.apache.maven.plugins + maven-compiler-plugin + 3.5 + + javac-with-errorprone + true + 1.8 + 1.8 + true + + + com.uber.nullaway + nullaway + 0.3.0 + + + + + + -XepExcludedPaths:(.*)/test/.*|(.*)/jcabi/.* + -XepOpt:NullAway:AnnotatedPackages=com.baeldung.nullaway + + + + + org.codehaus.plexus + plexus-compiler-javac-errorprone + 2.8 + + + + com.google.errorprone + error_prone_core + 2.3.4 + + + diff --git a/libraries/src/main/java/com/baeldung/nullaway/NullAwayExample.java b/libraries-3/src/main/java/com/baeldung/nullaway/NullAwayExample.java similarity index 93% rename from libraries/src/main/java/com/baeldung/nullaway/NullAwayExample.java rename to libraries-3/src/main/java/com/baeldung/nullaway/NullAwayExample.java index f3db1d2df9..1fab591cb0 100644 --- a/libraries/src/main/java/com/baeldung/nullaway/NullAwayExample.java +++ b/libraries-3/src/main/java/com/baeldung/nullaway/NullAwayExample.java @@ -1,7 +1,5 @@ package com.baeldung.nullaway; -import com.baeldung.distinct.Person; - public class NullAwayExample { /* diff --git a/libraries-3/src/main/java/com/baeldung/nullaway/Person.java b/libraries-3/src/main/java/com/baeldung/nullaway/Person.java new file mode 100644 index 0000000000..fcd88036a1 --- /dev/null +++ b/libraries-3/src/main/java/com/baeldung/nullaway/Person.java @@ -0,0 +1,65 @@ +package com.baeldung.nullaway; + +public class Person { + int age; + String name; + String email; + + public Person(int age, String name, String email) { + super(); + this.age = age; + this.name = name; + this.email = email; + } + + public int getAge() { + return age; + } + + public String getName() { + return name; + } + + public String getEmail() { + return email; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Person [age="); + builder.append(age); + builder.append(", name="); + builder.append(name); + builder.append(", email="); + builder.append(email); + builder.append("]"); + return builder.toString(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((email == null) ? 0 : email.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Person other = (Person) obj; + if (email == null) { + if (other.email != null) + return false; + } else if (!email.equals(other.email)) + return false; + return true; + } + +} diff --git a/libraries/README.md b/libraries/README.md index f439033730..79ba8fe55d 100644 --- a/libraries/README.md +++ b/libraries/README.md @@ -45,5 +45,4 @@ Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-m - [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client) - [Introduction to Functional Java](https://www.baeldung.com/java-functional-library) - [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library) -- [Using NullAway to Avoid NullPointerExceptions](https://www.baeldung.com/java-nullaway) - More articles [[next -->]](/libraries-2) diff --git a/libraries/pom.xml b/libraries/pom.xml index af300657b0..41bc2b9311 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -435,23 +435,6 @@ reflections ${reflections.version} - - com.uber.nullaway - nullaway - 0.3.0 - - - org.codehaus.plexus - plexus-compiler-javac-errorprone - 2.8 - - - - com.google.errorprone - error_prone_core - 2.1.3 - @@ -569,46 +552,6 @@ - - org.apache.maven.plugins - maven-compiler-plugin - 3.5 - - javac-with-errorprone - true - 1.8 - 1.8 - true - - - com.uber.nullaway - nullaway - 0.3.0 - - - - - - -XepExcludedPaths:(.*)/test/.*|(.*)/streamex/.* - -XepOpt:NullAway:AnnotatedPackages=com.baeldung.nullaway - - - - - org.codehaus.plexus - plexus-compiler-javac-errorprone - 2.8 - - - - com.google.errorprone - error_prone_core - 2.1.3 - - - - From 989c523308ed06ef3e799285e6d2ddeb08faacec Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Thu, 19 Mar 2020 23:06:52 +0100 Subject: [PATCH 167/278] JAVA-960: Fix conflicts --- .../baeldung/resttemplate/configuration/SpringConfig.java | 4 ---- .../baeldung/resttemplate/lists/service/EmployeeService.java | 2 +- .../baeldung/sampleapp/web/controller/MyFooController.java | 2 +- .../src/test/java/com/baeldung/SpringTestConfig.java | 5 ----- .../EmployeeServiceMockRestServiceServerUnitTest.java | 3 ++- 5 files changed, 4 insertions(+), 12 deletions(-) diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java index a97ac7d5a5..7866a4abcd 100644 --- a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/configuration/SpringConfig.java @@ -26,8 +26,4 @@ public class SpringConfig { return new RestTemplateBuilder(customRestTemplateCustomizer()); } - @Bean - public RestTemplate restTemplate() { - return new RestTemplate(); - } } diff --git a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java index 226134787f..8a1773483a 100644 --- a/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java +++ b/spring-resttemplate/src/main/java/com/baeldung/resttemplate/lists/service/EmployeeService.java @@ -7,7 +7,7 @@ import com.baeldung.resttemplate.lists.dto.Employee; import java.util.ArrayList; import java.util.List; -@Service +@Service("EmployeeListService") public class EmployeeService { public List getAllEmployees() diff --git a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java b/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java index 11ea5b70c9..5c385edb07 100644 --- a/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java +++ b/spring-resttemplate/src/main/java/com/baeldung/sampleapp/web/controller/MyFooController.java @@ -20,7 +20,7 @@ import com.baeldung.sampleapp.web.dto.Foo; import com.baeldung.sampleapp.web.exception.ResourceNotFoundException; @Controller -@RequestMapping(value = "/foos") +@RequestMapping(value = "/foo") public class MyFooController { private final Map myfoos; diff --git a/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java b/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java index 9a32d1ee98..c626d1021d 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java +++ b/spring-resttemplate/src/test/java/com/baeldung/SpringTestConfig.java @@ -11,9 +11,4 @@ import org.springframework.web.client.RestTemplate; @ComponentScan("com.baeldung") public class SpringTestConfig { - @Bean - public RestTemplate restTemplate() { - return new RestTemplate(); - } - } diff --git a/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java b/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java index 9fe1232231..ee01cb6a50 100644 --- a/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java +++ b/spring-resttemplate/src/test/java/com/baeldung/web/service/EmployeeServiceMockRestServiceServerUnitTest.java @@ -16,6 +16,7 @@ import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -28,7 +29,7 @@ import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(SpringRunner.class) -@ContextConfiguration(classes = SpringTestConfig.class) +@SpringBootTest(classes = SpringTestConfig.class) public class EmployeeServiceMockRestServiceServerUnitTest { private static final Logger logger = LoggerFactory.getLogger(EmployeeServiceMockRestServiceServerUnitTest.class); From 46d2ac9837c75732b5b5d7c1755a403659ea167b Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:06:25 +0100 Subject: [PATCH 168/278] [JAVA-958] Standardize packages in spring-batch module --- spring-batch/repository.sqlite | Bin 49152 -> 73728 bytes .../java/{org => com}/baeldung/batch/App.java | 2 +- .../baeldung/batch/SpringBatchConfig.java | 16 ++++++++-------- .../batch/SpringBatchRetryConfig.java | 8 ++++---- .../baeldung/batch/SpringConfig.java | 2 +- .../baeldung/batch/model/Transaction.java | 4 ++-- .../CustomMultiResourcePartitioner.java | 2 +- .../SpringbatchPartitionConfig.java | 6 +++--- .../SpringbatchPartitionerApp.java | 2 +- .../batch/service/CustomItemProcessor.java | 4 ++-- .../batch/service/CustomSkipPolicy.java | 2 +- .../service/MissingUsernameException.java | 2 +- .../service/NegativeAmountException.java | 2 +- .../batch/service/RecordFieldSetMapper.java | 4 ++-- .../batch/service/RetryItemProcessor.java | 4 ++-- .../batch/service/SkippingItemProcessor.java | 4 ++-- .../service/adapter/LocalDateTimeAdapter.java | 2 +- .../batchscheduler/SpringBatchScheduler.java | 4 ++-- .../baeldung/batchscheduler/model/Book.java | 2 +- .../batchtesting/SpringBatchApplication.java | 2 +- .../SpringBatchConfiguration.java | 14 +++++++------- .../baeldung/batchtesting/model/Book.java | 2 +- .../batchtesting/model/BookDetails.java | 2 +- .../batchtesting/model/BookRecord.java | 2 +- .../service/BookDetailsItemProcessor.java | 6 +++--- .../service/BookItemProcessor.java | 6 +++--- .../service/BookRecordFieldSetMapper.java | 4 ++-- .../chunks/LineProcessor.java | 4 ++-- .../taskletsvschunks/chunks/LineReader.java | 6 +++--- .../taskletsvschunks/chunks/LinesWriter.java | 6 +++--- .../taskletsvschunks/config/ChunksConfig.java | 10 +++++----- .../config/TaskletsConfig.java | 8 ++++---- .../baeldung/taskletsvschunks/model/Line.java | 2 +- .../tasklets/LinesProcessor.java | 4 ++-- .../tasklets/LinesReader.java | 6 +++--- .../tasklets/LinesWriter.java | 6 +++--- .../taskletsvschunks/utils/FileUtils.java | 4 ++-- spring-batch/src/main/resources/logback.xml | 6 +++--- .../src/main/resources/spring-batch-intro.xml | 6 +++--- .../baeldung/SpringContextTest.java | 4 ++-- .../SpringBatchRetryIntegrationTest.java | 3 ++- .../SpringBatchSchedulerIntegrationTest.java | 3 ++- .../SpringBatchIntegrationTest.java | 3 ++- .../SpringBatchStepScopeIntegrationTest.java | 7 ++++--- .../chunks/ChunksIntegrationTest.java | 4 ++-- .../tasklets/TaskletsIntegrationTest.java | 4 ++-- spring-batch/xml/retryOutput.xml | 2 +- 47 files changed, 106 insertions(+), 102 deletions(-) rename spring-batch/src/main/java/{org => com}/baeldung/batch/App.java (98%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/SpringBatchConfig.java (92%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/SpringBatchRetryConfig.java (95%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/SpringConfig.java (99%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/model/Transaction.java (94%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/partitioner/CustomMultiResourcePartitioner.java (98%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/partitioner/SpringbatchPartitionConfig.java (98%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/partitioner/SpringbatchPartitionerApp.java (96%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/CustomItemProcessor.java (77%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/CustomSkipPolicy.java (96%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/MissingUsernameException.java (65%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/NegativeAmountException.java (87%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/RecordFieldSetMapper.java (93%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/RetryItemProcessor.java (95%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/SkippingItemProcessor.java (88%) rename spring-batch/src/main/java/{org => com}/baeldung/batch/service/adapter/LocalDateTimeAdapter.java (93%) rename spring-batch/src/main/java/{org => com}/baeldung/batchscheduler/SpringBatchScheduler.java (98%) rename spring-batch/src/main/java/{org => com}/baeldung/batchscheduler/model/Book.java (92%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/SpringBatchApplication.java (97%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/SpringBatchConfiguration.java (92%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/model/Book.java (92%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/model/BookDetails.java (96%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/model/BookRecord.java (96%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/service/BookDetailsItemProcessor.java (83%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/service/BookItemProcessor.java (79%) rename spring-batch/src/main/java/{org => com}/baeldung/batchtesting/service/BookRecordFieldSetMapper.java (89%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/chunks/LineProcessor.java (92%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/chunks/LineReader.java (87%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/chunks/LinesWriter.java (87%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/config/ChunksConfig.java (91%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/config/TaskletsConfig.java (92%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/model/Line.java (96%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/tasklets/LinesProcessor.java (94%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/tasklets/LinesReader.java (91%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/tasklets/LinesWriter.java (91%) rename spring-batch/src/main/java/{org => com}/baeldung/taskletsvschunks/utils/FileUtils.java (96%) rename spring-batch/src/test/java/{org => com}/baeldung/SpringContextTest.java (73%) rename spring-batch/src/test/java/{org => com}/baeldung/batch/SpringBatchRetryIntegrationTest.java (98%) rename spring-batch/src/test/java/{org => com}/baeldung/batchscheduler/SpringBatchSchedulerIntegrationTest.java (96%) rename spring-batch/src/test/java/{org => com}/baeldung/batchtesting/SpringBatchIntegrationTest.java (98%) rename spring-batch/src/test/java/{org => com}/baeldung/batchtesting/SpringBatchStepScopeIntegrationTest.java (95%) rename spring-batch/src/test/java/{org => com}/baeldung/taskletsvschunks/chunks/ChunksIntegrationTest.java (89%) rename spring-batch/src/test/java/{org => com}/baeldung/taskletsvschunks/tasklets/TaskletsIntegrationTest.java (89%) diff --git a/spring-batch/repository.sqlite b/spring-batch/repository.sqlite index 4456ef63cc28948e07a545a72ec1b63366e9057b..2b549352ec8073708bd085fd414ed93d189c7511 100644 GIT binary patch literal 73728 zcmeI5TWllOd4Okl(PdXMW4o!k*aSO}*N}v0r<@@vQZk&BOO4j_QY4q8yp~f#9S#pA zS`>#F4p(x6Jb1H7fc7b|1N5n{dCvtwp9-`HTEI>n`=u{Uk(ZzW`jUqrFp{F^f6fet zGvtVu^|~vse=c@Jp8NUEWzK*8b1C1+HB2JZb>l=eg&6laj_0|*5Co3n>hS*=_}}~7 zfG?rm5BSTwzMuEC&WZf~V&o(4apN?r4N3{>XJ{Ie8YfbdCgs=moHR={9Z2SF2;4C{8FJ*Ik1x;ypk?uUP_l% zrLy{kC&Rq|HX!OG?vMjGmUB@2PjN4b*TEjkq*>a~*J9<<$7cG7z}yAeT~ zsH7`+HHY(*I|Wg(PrXNyBN zmU~~TVyTc(%H;!J%TghiyP3}19tu!-mE~Z2053417Qm{UzSXz0x{7rnmo8Th_KMr^ zCfV*I_3t29Mf@ash;L?RXP44x{@Y)4)n;#PD5gv4-LhY2YuU{B)NH>HChBU}h01;r z3Uk}3CL8^36{-uoNk>#*q{^-%RW!etl z1-p~IwO2~BL0ztpVPD*}GrBg^>M0*K;_7;wAVQcuV__*}dHOlWpVlK5{H1}a`J;(opBnFKr` z58KNW*495V+>3(6tEvLy=W3@?PZok-vm5_(1|l00|%g zB!C2v01`j~NB{{S0VMDlCLo8x+}z5pK}_S#o2scDy{uQ`sj5^Zsc4c&HBC)vT0D`g zCQ=*qSZy=DDbvBl1^~zxxaqF=ibJAOR$R1dsp{ zKmter2_OL^fCP|$ML-U%?DA7h0fdqvX_udV1|XOS-LU*kGXW5gAc6B!$^TUUKNC6R zB8QRRMBa`3F!E01ud%q101`j~NB{{S0VIF~kN^@u0!RP}Ac08fsb?a8w7yK5Lv)7(kN^@u0-qFt8^Hx`o)3q)t5+ApT##@7{+~Wj+4Gp~R8+S2 z^0)JayLrp(?bE;_oZk`-hp$}u!RNzVAVAH3@k{pnHFHzkNoRA)w)NDFL$T8~V2N4X zfGu~Yx^XO4>Ebp~g98J^j!D`gox2vx@W?ez8m4ll5mF;H`nPR1^wyR@?Sv+^6!f~V zBCiOhD9?q1RI1&~?=7?y=kf5wdPH4#1!a1>Xq<5P&YOp%W*&FITbxVrH)~1Zw z$xf!Jb~=rEgBbpik9NqSPe!MR9kxiGh&yVxX;$s&G#MWowW`rHT!-@~R>wyzKf+93mqmkU`aNQdk62D_j)r-PR3LEYZcA z6>`#UswNSS)K;xYn3-~Rq;{dU*H*nwEUMC|yp4*XrYmPe>zc$b*jPe($b^&g1C^yw zfetopRs+~VQE#?;5%^d!BCrB=MACg@8C8Mc%#v1z9zZogX>X>cjk(-_@+JeVs%^Ee zRbNXxk5e~e7DvHokQUUWirP7D5>xE4^tEI$C8vRD+QHhvm!XHg&VsH`h^j`rJj?;WyS#cV153ipc%c2yYrX2n7%8Vm} zoYA3Z&&*+va&pq1SJT@B-mWYhkrtmFW{I?kYI=$eUV(;63v~5-cPx*oQ5}@k91Rw{ zgVKu4p?FBlJmjlHI`ATb&Wa|*v1C!il8LbmZ*&}XNo67DMoVq_#v)4}Hx}s9fEn#@ zhw~uC$A{h@_xMx=s0fPP_YO5BIWbMol&;c~nlzIZtkXq!3>kGfIzCV~s=Jfq7dU<% z27cGB!9bA>``+(TtM`A#27m9uX*k840tdpdFEC#H96bUc0^>!x{{MuF{72-ck?+A5 z{2&1&fCP{L5#*0f{vr0ucM84Z2!4{<0#jbtjh@6!K2jr#wOSG?#O z2_OL^Fpj`iz8rj(n_q*|TCT#YfPG-rw&Q5K>8!A&>;IOm<+sn`&);IRz2AOkHt;7L z|2!!Augvk(KhINre}D!-_lwa0EY<)2G7m{h-9Hluq2AxKu3@w~-?ivqv_m#ok9z-c zOG(D9I6%EWtb2eZ3NAIBd%;3a*XdQ(TZ$so`@5Dbv3lmK+DE-Vt1hVbA6Vq(qwIyw zh_0VNy+7*xFRtD{^%eeEj$Z=B|FwDE8VbTlGT4FfpTzY3m)Y}2j`lwo?CJlXqWb?u zOaFiQIqs={UHtCCYw!g>NB{{S0VIF~kN^@u0!ZMqP2heUcF8_C=Dxmct);ew#mbv) zvb?oC$@V5TA>p?JV0nGHY^rCgWY=ZI~@*1B`B!QtCH_Are!H9;$lKgw3R82KNLk9@>MK7t3w zU55V)uD|q-z@8bqFA#p?2MHhnB!C2v01`j~NB{{S0VIF~kicUjaR14W|2HzI|D&#LXD5j##$P?%zfu{_HaihV z1c~SWb>N0^dVPFF?Ho6Wb=f$c|F0Xz zqIHmCzsC5S#E0kq!=aN~v19_z|9|q%|5qx?HoF<%$8`TcAO0N|{$2PVF7}`oQ-=hQ z01`j~l)%+`oN;z zY-n%NAnY3mX+R(Rc!CQAt*gt}2)f6T^qWe+Frm4*lgC>hpr`vAphAA>$6>`#slevj_q_%2JVlzBayA;Bz z*NG)|OQYoOQ8CnX<&0=ullTQ2OGpoyaJ-vtntFz^Daxi3_e?08HcjZP+C(*-ev);9 zD4WuG?0$znG|eL?rkOQMS39NwGe-2?FZTL#k0GNjM<)yvuC^Dgj*f=-5__{5_8X3x ztPWeU2&DKF5%kjcGDK#*JXz3gV-{#!ijH`*xu%2qsir~p;aZ8MW>z9&8n4v?J$^SSMjQW=@Rjl4x{WHeCq5XKp7vp0pFr26jK8@_!)wb1w2P z@W2leKmter34A&UynPDyx$+>_hp$}u!RNzVAiyShf61P|W*vUflH{%DB!V&1lT%fD zu5r>Zsbo!Rq~=K2TLQHcn$%Lz>%xk>!lZWUXmaVBMZzM;91-mpMEL;)ze^QA%9;Ic z#&rP3q1b5~z_D(?e8{Pv&TE`DUQ{)zg1w%IMps8nj99}8TnFGYo6{dX`b^>ATuV>G z4^l^~Q`e1?@zo610a&Vh(Ix9$XA34O6r!c?ĤRn?9`ddaq2=C}@EY@dj8EjZUg z#15SS@u>=~=>S*zvsWlRuDKRAs=Jfq7dU<%27cGBEyB2u8ou9U&!5rfFW$`*c8fWx z_IJK8^Y@tke`bc8nF;^b>!reSG`_0>@LGQ$YrTkZ!?J;}4H*Vs<(mFFq$2B{E`u{;We3W(`_5W;E z;-+e9M_!q^r#JDjVv|0y)YEHBGO0Co?gM4g$tUl8M#?CY!U7wY=?2_ zxHcWvruQ~<^d}iFj!eonR=k1we}jmW!Ufj<|J+*t{|7Go2iNEkzajx7fCP}h6HMTp zU? zZ3}iiunY<&05`uyNgMef|FvJk-UkAps+GLQ`M>>tD?7g6 delta 609 zcmZoTz|zpbJV9DepMima2Z&)ndZLaoqyEMOJ!VFZ$%d@ro0l=)U}EG1GKD8^VBz1q zkS&>$jgkKh1OJ)Lf)ft$+Zi#kGH|H-rezitmpCPsBxiW#C#9GerdTAWSX!hR7$g}P zn50@-7#LVuTBIhYS(q4^r*Z*pW8^=_z<&;C#u0uuLl$*kPLfRE1)9LdpUc4ij{iFU zZvMsmZTz{L1p^}aS;g6yO*toDU>9MPW@WYovnDsNu&|1;FdK7De#k7$D#grf4PuEK zi!w1AaymJNID5o<`8&mX`UQtL`Z>D_Ffywn2?x6df~;fYKhD5^9O&S^{PyOIJPeGS ztgNi^^1Q4JOpK}fZ}0dCB6muF$BNGEyJKqTgz7s&neNf2*bsSI!{b1n#0dZphyAT^A3xgm-buGe5 Ts1!HCD4;X=|G { diff --git a/spring-batch/src/main/java/org/baeldung/batch/service/CustomSkipPolicy.java b/spring-batch/src/main/java/com/baeldung/batch/service/CustomSkipPolicy.java similarity index 96% rename from spring-batch/src/main/java/org/baeldung/batch/service/CustomSkipPolicy.java rename to spring-batch/src/main/java/com/baeldung/batch/service/CustomSkipPolicy.java index a156a65b6e..25401de022 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/service/CustomSkipPolicy.java +++ b/spring-batch/src/main/java/com/baeldung/batch/service/CustomSkipPolicy.java @@ -1,4 +1,4 @@ -package org.baeldung.batch.service; +package com.baeldung.batch.service; import org.springframework.batch.core.step.skip.SkipLimitExceededException; import org.springframework.batch.core.step.skip.SkipPolicy; diff --git a/spring-batch/src/main/java/org/baeldung/batch/service/MissingUsernameException.java b/spring-batch/src/main/java/com/baeldung/batch/service/MissingUsernameException.java similarity index 65% rename from spring-batch/src/main/java/org/baeldung/batch/service/MissingUsernameException.java rename to spring-batch/src/main/java/com/baeldung/batch/service/MissingUsernameException.java index 2cf8f4d334..b12daa17cc 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/service/MissingUsernameException.java +++ b/spring-batch/src/main/java/com/baeldung/batch/service/MissingUsernameException.java @@ -1,4 +1,4 @@ -package org.baeldung.batch.service; +package com.baeldung.batch.service; public class MissingUsernameException extends RuntimeException { } diff --git a/spring-batch/src/main/java/org/baeldung/batch/service/NegativeAmountException.java b/spring-batch/src/main/java/com/baeldung/batch/service/NegativeAmountException.java similarity index 87% rename from spring-batch/src/main/java/org/baeldung/batch/service/NegativeAmountException.java rename to spring-batch/src/main/java/com/baeldung/batch/service/NegativeAmountException.java index c9c05be671..ee46574f87 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/service/NegativeAmountException.java +++ b/spring-batch/src/main/java/com/baeldung/batch/service/NegativeAmountException.java @@ -1,4 +1,4 @@ -package org.baeldung.batch.service; +package com.baeldung.batch.service; public class NegativeAmountException extends RuntimeException { diff --git a/spring-batch/src/main/java/org/baeldung/batch/service/RecordFieldSetMapper.java b/spring-batch/src/main/java/com/baeldung/batch/service/RecordFieldSetMapper.java similarity index 93% rename from spring-batch/src/main/java/org/baeldung/batch/service/RecordFieldSetMapper.java rename to spring-batch/src/main/java/com/baeldung/batch/service/RecordFieldSetMapper.java index e61c54193a..09478e9a30 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/service/RecordFieldSetMapper.java +++ b/spring-batch/src/main/java/com/baeldung/batch/service/RecordFieldSetMapper.java @@ -1,6 +1,6 @@ -package org.baeldung.batch.service; +package com.baeldung.batch.service; -import org.baeldung.batch.model.Transaction; +import com.baeldung.batch.model.Transaction; import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.validation.BindException; diff --git a/spring-batch/src/main/java/org/baeldung/batch/service/RetryItemProcessor.java b/spring-batch/src/main/java/com/baeldung/batch/service/RetryItemProcessor.java similarity index 95% rename from spring-batch/src/main/java/org/baeldung/batch/service/RetryItemProcessor.java rename to spring-batch/src/main/java/com/baeldung/batch/service/RetryItemProcessor.java index d4e82452a7..c380e2c0ab 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/service/RetryItemProcessor.java +++ b/spring-batch/src/main/java/com/baeldung/batch/service/RetryItemProcessor.java @@ -1,10 +1,10 @@ -package org.baeldung.batch.service; +package com.baeldung.batch.service; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.util.EntityUtils; -import org.baeldung.batch.model.Transaction; +import com.baeldung.batch.model.Transaction; import org.codehaus.jettison.json.JSONException; import org.codehaus.jettison.json.JSONObject; import org.slf4j.Logger; diff --git a/spring-batch/src/main/java/org/baeldung/batch/service/SkippingItemProcessor.java b/spring-batch/src/main/java/com/baeldung/batch/service/SkippingItemProcessor.java similarity index 88% rename from spring-batch/src/main/java/org/baeldung/batch/service/SkippingItemProcessor.java rename to spring-batch/src/main/java/com/baeldung/batch/service/SkippingItemProcessor.java index 307a8213e2..ee37eb6c1b 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/service/SkippingItemProcessor.java +++ b/spring-batch/src/main/java/com/baeldung/batch/service/SkippingItemProcessor.java @@ -1,6 +1,6 @@ -package org.baeldung.batch.service; +package com.baeldung.batch.service; -import org.baeldung.batch.model.Transaction; +import com.baeldung.batch.model.Transaction; import org.springframework.batch.item.ItemProcessor; public class SkippingItemProcessor implements ItemProcessor { diff --git a/spring-batch/src/main/java/org/baeldung/batch/service/adapter/LocalDateTimeAdapter.java b/spring-batch/src/main/java/com/baeldung/batch/service/adapter/LocalDateTimeAdapter.java similarity index 93% rename from spring-batch/src/main/java/org/baeldung/batch/service/adapter/LocalDateTimeAdapter.java rename to spring-batch/src/main/java/com/baeldung/batch/service/adapter/LocalDateTimeAdapter.java index 45c35b87f1..561a7335b3 100644 --- a/spring-batch/src/main/java/org/baeldung/batch/service/adapter/LocalDateTimeAdapter.java +++ b/spring-batch/src/main/java/com/baeldung/batch/service/adapter/LocalDateTimeAdapter.java @@ -1,4 +1,4 @@ -package org.baeldung.batch.service.adapter; +package com.baeldung.batch.service.adapter; import javax.xml.bind.annotation.adapters.XmlAdapter; import java.time.LocalDateTime; diff --git a/spring-batch/src/main/java/org/baeldung/batchscheduler/SpringBatchScheduler.java b/spring-batch/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java similarity index 98% rename from spring-batch/src/main/java/org/baeldung/batchscheduler/SpringBatchScheduler.java rename to spring-batch/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java index 1beeb6b2bf..4de3e0a4b6 100644 --- a/spring-batch/src/main/java/org/baeldung/batchscheduler/SpringBatchScheduler.java +++ b/spring-batch/src/main/java/com/baeldung/batchscheduler/SpringBatchScheduler.java @@ -1,4 +1,4 @@ -package org.baeldung.batchscheduler; +package com.baeldung.batchscheduler; import java.util.Date; import java.util.IdentityHashMap; @@ -7,7 +7,7 @@ import java.util.Map; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.baeldung.batchscheduler.model.Book; +import com.baeldung.batchscheduler.model.Book; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.Job; diff --git a/spring-batch/src/main/java/org/baeldung/batchscheduler/model/Book.java b/spring-batch/src/main/java/com/baeldung/batchscheduler/model/Book.java similarity index 92% rename from spring-batch/src/main/java/org/baeldung/batchscheduler/model/Book.java rename to spring-batch/src/main/java/com/baeldung/batchscheduler/model/Book.java index f992bde20e..8ee986c729 100644 --- a/spring-batch/src/main/java/org/baeldung/batchscheduler/model/Book.java +++ b/spring-batch/src/main/java/com/baeldung/batchscheduler/model/Book.java @@ -1,4 +1,4 @@ -package org.baeldung.batchscheduler.model; +package com.baeldung.batchscheduler.model; public class Book { private int id; diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/SpringBatchApplication.java b/spring-batch/src/main/java/com/baeldung/batchtesting/SpringBatchApplication.java similarity index 97% rename from spring-batch/src/main/java/org/baeldung/batchtesting/SpringBatchApplication.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/SpringBatchApplication.java index 39bfdfbee7..04185fb1ca 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/SpringBatchApplication.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/SpringBatchApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.batchtesting; +package com.baeldung.batchtesting; import org.springframework.batch.core.Job; import org.springframework.batch.core.JobParametersBuilder; diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/SpringBatchConfiguration.java b/spring-batch/src/main/java/com/baeldung/batchtesting/SpringBatchConfiguration.java similarity index 92% rename from spring-batch/src/main/java/org/baeldung/batchtesting/SpringBatchConfiguration.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/SpringBatchConfiguration.java index 2d891ad7da..664db3fbba 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/SpringBatchConfiguration.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/SpringBatchConfiguration.java @@ -1,13 +1,13 @@ -package org.baeldung.batchtesting; +package com.baeldung.batchtesting; import java.io.IOException; -import org.baeldung.batchtesting.model.Book; -import org.baeldung.batchtesting.model.BookDetails; -import org.baeldung.batchtesting.model.BookRecord; -import org.baeldung.batchtesting.service.BookDetailsItemProcessor; -import org.baeldung.batchtesting.service.BookItemProcessor; -import org.baeldung.batchtesting.service.BookRecordFieldSetMapper; +import com.baeldung.batchtesting.model.Book; +import com.baeldung.batchtesting.model.BookDetails; +import com.baeldung.batchtesting.model.BookRecord; +import com.baeldung.batchtesting.service.BookDetailsItemProcessor; +import com.baeldung.batchtesting.service.BookItemProcessor; +import com.baeldung.batchtesting.service.BookRecordFieldSetMapper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.Job; diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/model/Book.java b/spring-batch/src/main/java/com/baeldung/batchtesting/model/Book.java similarity index 92% rename from spring-batch/src/main/java/org/baeldung/batchtesting/model/Book.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/model/Book.java index 3ea4a29e7f..f34e6cb5f6 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/model/Book.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/model/Book.java @@ -1,4 +1,4 @@ -package org.baeldung.batchtesting.model; +package com.baeldung.batchtesting.model; public class Book { diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/model/BookDetails.java b/spring-batch/src/main/java/com/baeldung/batchtesting/model/BookDetails.java similarity index 96% rename from spring-batch/src/main/java/org/baeldung/batchtesting/model/BookDetails.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/model/BookDetails.java index d9284fbc66..3e994d2c92 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/model/BookDetails.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/model/BookDetails.java @@ -1,4 +1,4 @@ -package org.baeldung.batchtesting.model; +package com.baeldung.batchtesting.model; public class BookDetails { diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/model/BookRecord.java b/spring-batch/src/main/java/com/baeldung/batchtesting/model/BookRecord.java similarity index 96% rename from spring-batch/src/main/java/org/baeldung/batchtesting/model/BookRecord.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/model/BookRecord.java index 35fb40e878..d6a1692577 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/model/BookRecord.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/model/BookRecord.java @@ -1,4 +1,4 @@ -package org.baeldung.batchtesting.model; +package com.baeldung.batchtesting.model; public class BookRecord { diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/service/BookDetailsItemProcessor.java b/spring-batch/src/main/java/com/baeldung/batchtesting/service/BookDetailsItemProcessor.java similarity index 83% rename from spring-batch/src/main/java/org/baeldung/batchtesting/service/BookDetailsItemProcessor.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/service/BookDetailsItemProcessor.java index f3800fee51..514a383108 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/service/BookDetailsItemProcessor.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/service/BookDetailsItemProcessor.java @@ -1,7 +1,7 @@ -package org.baeldung.batchtesting.service; +package com.baeldung.batchtesting.service; -import org.baeldung.batchtesting.model.BookDetails; -import org.baeldung.batchtesting.model.BookRecord; +import com.baeldung.batchtesting.model.BookDetails; +import com.baeldung.batchtesting.model.BookRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.item.ItemProcessor; diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/service/BookItemProcessor.java b/spring-batch/src/main/java/com/baeldung/batchtesting/service/BookItemProcessor.java similarity index 79% rename from spring-batch/src/main/java/org/baeldung/batchtesting/service/BookItemProcessor.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/service/BookItemProcessor.java index 69e72ba1d3..84e850fe71 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/service/BookItemProcessor.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/service/BookItemProcessor.java @@ -1,7 +1,7 @@ -package org.baeldung.batchtesting.service; +package com.baeldung.batchtesting.service; -import org.baeldung.batchtesting.model.Book; -import org.baeldung.batchtesting.model.BookRecord; +import com.baeldung.batchtesting.model.Book; +import com.baeldung.batchtesting.model.BookRecord; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.item.ItemProcessor; diff --git a/spring-batch/src/main/java/org/baeldung/batchtesting/service/BookRecordFieldSetMapper.java b/spring-batch/src/main/java/com/baeldung/batchtesting/service/BookRecordFieldSetMapper.java similarity index 89% rename from spring-batch/src/main/java/org/baeldung/batchtesting/service/BookRecordFieldSetMapper.java rename to spring-batch/src/main/java/com/baeldung/batchtesting/service/BookRecordFieldSetMapper.java index cfc36fed7a..d9e8ee1158 100644 --- a/spring-batch/src/main/java/org/baeldung/batchtesting/service/BookRecordFieldSetMapper.java +++ b/spring-batch/src/main/java/com/baeldung/batchtesting/service/BookRecordFieldSetMapper.java @@ -1,6 +1,6 @@ -package org.baeldung.batchtesting.service; +package com.baeldung.batchtesting.service; -import org.baeldung.batchtesting.model.BookRecord; +import com.baeldung.batchtesting.model.BookRecord; import org.springframework.batch.item.file.mapping.FieldSetMapper; import org.springframework.batch.item.file.transform.FieldSet; import org.springframework.validation.BindException; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LineProcessor.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LineProcessor.java similarity index 92% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LineProcessor.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LineProcessor.java index 5b6cd9add3..87d0bdc3fb 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LineProcessor.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LineProcessor.java @@ -1,6 +1,6 @@ -package org.baeldung.taskletsvschunks.chunks; +package com.baeldung.taskletsvschunks.chunks; -import org.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.model.Line; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.ExitStatus; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LineReader.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LineReader.java similarity index 87% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LineReader.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LineReader.java index 5f6b6de218..6ffa730c19 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LineReader.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LineReader.java @@ -1,7 +1,7 @@ -package org.baeldung.taskletsvschunks.chunks; +package com.baeldung.taskletsvschunks.chunks; -import org.baeldung.taskletsvschunks.model.Line; -import org.baeldung.taskletsvschunks.utils.FileUtils; +import com.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.utils.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.ExitStatus; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LinesWriter.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LinesWriter.java similarity index 87% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LinesWriter.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LinesWriter.java index 66f9103a56..9f292b24b9 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/chunks/LinesWriter.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/chunks/LinesWriter.java @@ -1,7 +1,7 @@ -package org.baeldung.taskletsvschunks.chunks; +package com.baeldung.taskletsvschunks.chunks; -import org.baeldung.taskletsvschunks.model.Line; -import org.baeldung.taskletsvschunks.utils.FileUtils; +import com.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.utils.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.ExitStatus; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/config/ChunksConfig.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/ChunksConfig.java similarity index 91% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/config/ChunksConfig.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/ChunksConfig.java index 601ffb7f27..57288fb312 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/config/ChunksConfig.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/ChunksConfig.java @@ -1,9 +1,9 @@ -package org.baeldung.taskletsvschunks.config; +package com.baeldung.taskletsvschunks.config; -import org.baeldung.taskletsvschunks.chunks.LineProcessor; -import org.baeldung.taskletsvschunks.chunks.LineReader; -import org.baeldung.taskletsvschunks.chunks.LinesWriter; -import org.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.chunks.LineProcessor; +import com.baeldung.taskletsvschunks.chunks.LineReader; +import com.baeldung.taskletsvschunks.chunks.LinesWriter; +import com.baeldung.taskletsvschunks.model.Line; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/config/TaskletsConfig.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/TaskletsConfig.java similarity index 92% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/config/TaskletsConfig.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/TaskletsConfig.java index b9d06d2639..e7157ac520 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/config/TaskletsConfig.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/config/TaskletsConfig.java @@ -1,8 +1,8 @@ -package org.baeldung.taskletsvschunks.config; +package com.baeldung.taskletsvschunks.config; -import org.baeldung.taskletsvschunks.tasklets.LinesProcessor; -import org.baeldung.taskletsvschunks.tasklets.LinesReader; -import org.baeldung.taskletsvschunks.tasklets.LinesWriter; +import com.baeldung.taskletsvschunks.tasklets.LinesProcessor; +import com.baeldung.taskletsvschunks.tasklets.LinesReader; +import com.baeldung.taskletsvschunks.tasklets.LinesWriter; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/model/Line.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/model/Line.java similarity index 96% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/model/Line.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/model/Line.java index fee6fd31a6..2d7d3ff63f 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/model/Line.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/model/Line.java @@ -1,4 +1,4 @@ -package org.baeldung.taskletsvschunks.model; +package com.baeldung.taskletsvschunks.model; import java.io.Serializable; import java.time.LocalDate; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesProcessor.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesProcessor.java similarity index 94% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesProcessor.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesProcessor.java index ba7a3088d5..8b84c39174 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesProcessor.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesProcessor.java @@ -1,6 +1,6 @@ -package org.baeldung.taskletsvschunks.tasklets; +package com.baeldung.taskletsvschunks.tasklets; -import org.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.model.Line; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.ExitStatus; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesReader.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesReader.java similarity index 91% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesReader.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesReader.java index 9905ee8f8a..b1f58be4a4 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesReader.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesReader.java @@ -1,7 +1,7 @@ -package org.baeldung.taskletsvschunks.tasklets; +package com.baeldung.taskletsvschunks.tasklets; -import org.baeldung.taskletsvschunks.model.Line; -import org.baeldung.taskletsvschunks.utils.FileUtils; +import com.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.utils.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.ExitStatus; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesWriter.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesWriter.java similarity index 91% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesWriter.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesWriter.java index 937288a890..76128b7841 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/tasklets/LinesWriter.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/tasklets/LinesWriter.java @@ -1,7 +1,7 @@ -package org.baeldung.taskletsvschunks.tasklets; +package com.baeldung.taskletsvschunks.tasklets; -import org.baeldung.taskletsvschunks.model.Line; -import org.baeldung.taskletsvschunks.utils.FileUtils; +import com.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.utils.FileUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.batch.core.ExitStatus; diff --git a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/utils/FileUtils.java b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/utils/FileUtils.java similarity index 96% rename from spring-batch/src/main/java/org/baeldung/taskletsvschunks/utils/FileUtils.java rename to spring-batch/src/main/java/com/baeldung/taskletsvschunks/utils/FileUtils.java index df36d5c756..fde3b1fa9d 100644 --- a/spring-batch/src/main/java/org/baeldung/taskletsvschunks/utils/FileUtils.java +++ b/spring-batch/src/main/java/com/baeldung/taskletsvschunks/utils/FileUtils.java @@ -1,8 +1,8 @@ -package org.baeldung.taskletsvschunks.utils; +package com.baeldung.taskletsvschunks.utils; import com.opencsv.CSVReader; import com.opencsv.CSVWriter; -import org.baeldung.taskletsvschunks.model.Line; +import com.baeldung.taskletsvschunks.model.Line; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-batch/src/main/resources/logback.xml b/spring-batch/src/main/resources/logback.xml index 9a622ceb65..55bbeba870 100644 --- a/spring-batch/src/main/resources/logback.xml +++ b/spring-batch/src/main/resources/logback.xml @@ -8,15 +8,15 @@ - + - + - + diff --git a/spring-batch/src/main/resources/spring-batch-intro.xml b/spring-batch/src/main/resources/spring-batch-intro.xml index 908b8aa2e1..2a7c1e7c4a 100644 --- a/spring-batch/src/main/resources/spring-batch-intro.xml +++ b/spring-batch/src/main/resources/spring-batch-intro.xml @@ -22,14 +22,14 @@ + class="com.baeldung.batch.service.RecordFieldSetMapper" /> - + @@ -40,7 +40,7 @@ - org.baeldung.batch.model.Transaction + com.baeldung.batch.model.Transaction diff --git a/spring-batch/src/test/java/org/baeldung/SpringContextTest.java b/spring-batch/src/test/java/com/baeldung/SpringContextTest.java similarity index 73% rename from spring-batch/src/test/java/org/baeldung/SpringContextTest.java rename to spring-batch/src/test/java/com/baeldung/SpringContextTest.java index 1a4f923a1e..b82bb35daf 100644 --- a/spring-batch/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-batch/src/test/java/com/baeldung/SpringContextTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.batch.App; +import com.baeldung.batch.App; import org.junit.Test; public class SpringContextTest { diff --git a/spring-batch/src/test/java/org/baeldung/batch/SpringBatchRetryIntegrationTest.java b/spring-batch/src/test/java/com/baeldung/batch/SpringBatchRetryIntegrationTest.java similarity index 98% rename from spring-batch/src/test/java/org/baeldung/batch/SpringBatchRetryIntegrationTest.java rename to spring-batch/src/test/java/com/baeldung/batch/SpringBatchRetryIntegrationTest.java index 293c97ac5d..df9154a765 100644 --- a/spring-batch/src/test/java/org/baeldung/batch/SpringBatchRetryIntegrationTest.java +++ b/spring-batch/src/test/java/com/baeldung/batch/SpringBatchRetryIntegrationTest.java @@ -1,5 +1,6 @@ -package org.baeldung.batch; +package com.baeldung.batch; +import com.baeldung.batch.SpringBatchRetryConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.conn.ConnectTimeoutException; import org.apache.http.entity.StringEntity; diff --git a/spring-batch/src/test/java/org/baeldung/batchscheduler/SpringBatchSchedulerIntegrationTest.java b/spring-batch/src/test/java/com/baeldung/batchscheduler/SpringBatchSchedulerIntegrationTest.java similarity index 96% rename from spring-batch/src/test/java/org/baeldung/batchscheduler/SpringBatchSchedulerIntegrationTest.java rename to spring-batch/src/test/java/com/baeldung/batchscheduler/SpringBatchSchedulerIntegrationTest.java index 8927421ac5..81877fbc39 100644 --- a/spring-batch/src/test/java/org/baeldung/batchscheduler/SpringBatchSchedulerIntegrationTest.java +++ b/spring-batch/src/test/java/com/baeldung/batchscheduler/SpringBatchSchedulerIntegrationTest.java @@ -1,5 +1,6 @@ -package org.baeldung.batchscheduler; +package com.baeldung.batchscheduler; +import com.baeldung.batchscheduler.SpringBatchScheduler; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-batch/src/test/java/org/baeldung/batchtesting/SpringBatchIntegrationTest.java b/spring-batch/src/test/java/com/baeldung/batchtesting/SpringBatchIntegrationTest.java similarity index 98% rename from spring-batch/src/test/java/org/baeldung/batchtesting/SpringBatchIntegrationTest.java rename to spring-batch/src/test/java/com/baeldung/batchtesting/SpringBatchIntegrationTest.java index d66da89ba4..333c69684e 100644 --- a/spring-batch/src/test/java/org/baeldung/batchtesting/SpringBatchIntegrationTest.java +++ b/spring-batch/src/test/java/com/baeldung/batchtesting/SpringBatchIntegrationTest.java @@ -1,10 +1,11 @@ -package org.baeldung.batchtesting; +package com.baeldung.batchtesting; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import java.util.Collection; +import com.baeldung.batchtesting.SpringBatchConfiguration; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-batch/src/test/java/org/baeldung/batchtesting/SpringBatchStepScopeIntegrationTest.java b/spring-batch/src/test/java/com/baeldung/batchtesting/SpringBatchStepScopeIntegrationTest.java similarity index 95% rename from spring-batch/src/test/java/org/baeldung/batchtesting/SpringBatchStepScopeIntegrationTest.java rename to spring-batch/src/test/java/com/baeldung/batchtesting/SpringBatchStepScopeIntegrationTest.java index f7b888f0f9..4655117b85 100644 --- a/spring-batch/src/test/java/org/baeldung/batchtesting/SpringBatchStepScopeIntegrationTest.java +++ b/spring-batch/src/test/java/com/baeldung/batchtesting/SpringBatchStepScopeIntegrationTest.java @@ -1,12 +1,13 @@ -package org.baeldung.batchtesting; +package com.baeldung.batchtesting; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import java.util.Arrays; -import org.baeldung.batchtesting.model.Book; -import org.baeldung.batchtesting.model.BookRecord; +import com.baeldung.batchtesting.SpringBatchConfiguration; +import com.baeldung.batchtesting.model.Book; +import com.baeldung.batchtesting.model.BookRecord; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-batch/src/test/java/org/baeldung/taskletsvschunks/chunks/ChunksIntegrationTest.java b/spring-batch/src/test/java/com/baeldung/taskletsvschunks/chunks/ChunksIntegrationTest.java similarity index 89% rename from spring-batch/src/test/java/org/baeldung/taskletsvschunks/chunks/ChunksIntegrationTest.java rename to spring-batch/src/test/java/com/baeldung/taskletsvschunks/chunks/ChunksIntegrationTest.java index eaf73e4a4a..1132e4d5e2 100644 --- a/spring-batch/src/test/java/org/baeldung/taskletsvschunks/chunks/ChunksIntegrationTest.java +++ b/spring-batch/src/test/java/com/baeldung/taskletsvschunks/chunks/ChunksIntegrationTest.java @@ -1,6 +1,6 @@ -package org.baeldung.taskletsvschunks.chunks; +package com.baeldung.taskletsvschunks.chunks; -import org.baeldung.taskletsvschunks.config.ChunksConfig; +import com.baeldung.taskletsvschunks.config.ChunksConfig; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-batch/src/test/java/org/baeldung/taskletsvschunks/tasklets/TaskletsIntegrationTest.java b/spring-batch/src/test/java/com/baeldung/taskletsvschunks/tasklets/TaskletsIntegrationTest.java similarity index 89% rename from spring-batch/src/test/java/org/baeldung/taskletsvschunks/tasklets/TaskletsIntegrationTest.java rename to spring-batch/src/test/java/com/baeldung/taskletsvschunks/tasklets/TaskletsIntegrationTest.java index 322b17bd55..2e1ad031aa 100644 --- a/spring-batch/src/test/java/org/baeldung/taskletsvschunks/tasklets/TaskletsIntegrationTest.java +++ b/spring-batch/src/test/java/com/baeldung/taskletsvschunks/tasklets/TaskletsIntegrationTest.java @@ -1,6 +1,6 @@ -package org.baeldung.taskletsvschunks.tasklets; +package com.baeldung.taskletsvschunks.tasklets; -import org.baeldung.taskletsvschunks.config.TaskletsConfig; +import com.baeldung.taskletsvschunks.config.TaskletsConfig; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-batch/xml/retryOutput.xml b/spring-batch/xml/retryOutput.xml index d30f2c4a32..c5dec44f16 100644 --- a/spring-batch/xml/retryOutput.xml +++ b/spring-batch/xml/retryOutput.xml @@ -1 +1 @@ -1010000.04302222015-10-31 00:00:001234sammy1012321.04302222015-12-03 00:00:009999john \ No newline at end of file + \ No newline at end of file From 8ecb1072a6b2fd34eabd0c4ebf5c6647f20dbccf Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:09:11 +0100 Subject: [PATCH 169/278] [JAVA-958] Standardize packages in spring-5 module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-5/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-5/src/test/java/org/baeldung/SpringContextTest.java b/spring-5/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-5/src/test/java/org/baeldung/SpringContextTest.java rename to spring-5/src/test/java/com/baeldung/SpringContextTest.java index 56e8697f5c..e3f67def90 100644 --- a/spring-5/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-5/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 18c557679c3beb832dbde30a8c51f5f6823cf6fa Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:16:56 +0100 Subject: [PATCH 170/278] [JAVA-958] Standardize packages in spring-5-data-reactive module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-5-data-reactive/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-5-data-reactive/src/test/java/org/baeldung/SpringContextTest.java b/spring-5-data-reactive/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-5-data-reactive/src/test/java/org/baeldung/SpringContextTest.java rename to spring-5-data-reactive/src/test/java/com/baeldung/SpringContextTest.java index c3ea1d8435..bedb30fcaa 100644 --- a/spring-5-data-reactive/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-5-data-reactive/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 6bc9e485303dea3edb9e79678222aa74887e7ca5 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:18:56 +0100 Subject: [PATCH 171/278] [JAVA-958] Standardize packages in spring-5-reactive module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-5-reactive/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-5-reactive/src/test/java/org/baeldung/SpringContextTest.java b/spring-5-reactive/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-5-reactive/src/test/java/org/baeldung/SpringContextTest.java rename to spring-5-reactive/src/test/java/com/baeldung/SpringContextTest.java index c3ea1d8435..bedb30fcaa 100644 --- a/spring-5-reactive/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-5-reactive/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 580aa4d8b0c154640fb82fd3684a4d4308d200c5 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:21:22 +0100 Subject: [PATCH 172/278] [JAVA-958] Standardize packages in spring-5-reactive-client module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-5-reactive-client/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-5-reactive-client/src/test/java/org/baeldung/SpringContextTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-5-reactive-client/src/test/java/org/baeldung/SpringContextTest.java rename to spring-5-reactive-client/src/test/java/com/baeldung/SpringContextTest.java index 678d04897b..c0ca9b7e64 100644 --- a/spring-5-reactive-client/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From d38818530532360821b3fa40461bffc3a5058ac1 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:23:39 +0100 Subject: [PATCH 173/278] [JAVA-958] Standardize packages in spring-5-reactive-security module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-5-reactive-security/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-5-reactive-security/src/test/java/org/baeldung/SpringContextTest.java b/spring-5-reactive-security/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-5-reactive-security/src/test/java/org/baeldung/SpringContextTest.java rename to spring-5-reactive-security/src/test/java/com/baeldung/SpringContextTest.java index 479c35d986..b4f4118527 100644 --- a/spring-5-reactive-security/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-5-reactive-security/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 76ee18f79959027dcba517a9ec8d22a4ac228968 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:26:22 +0100 Subject: [PATCH 174/278] [JAVA-958] Standardize packages in spring-5-security module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-5-security/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-5-security/src/test/java/org/baeldung/SpringContextTest.java b/spring-5-security/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-5-security/src/test/java/org/baeldung/SpringContextTest.java rename to spring-5-security/src/test/java/com/baeldung/SpringContextTest.java index 729790bd14..7812a5c063 100644 --- a/spring-5-security/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-5-security/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From e30cd5677ecd5e13cf55d07fd74b871c6c78fe2f Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:29:03 +0100 Subject: [PATCH 175/278] [JAVA-958] Standardize packages in spring-apache-camel module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-apache-camel/src/test/java/{org => com}/baeldung/SpringContextTest.java (89%) diff --git a/spring-apache-camel/src/test/java/org/baeldung/SpringContextTest.java b/spring-apache-camel/src/test/java/com/baeldung/SpringContextTest.java similarity index 89% rename from spring-apache-camel/src/test/java/org/baeldung/SpringContextTest.java rename to spring-apache-camel/src/test/java/com/baeldung/SpringContextTest.java index 1c098a56ab..14e7de2095 100644 --- a/spring-apache-camel/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-apache-camel/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; From 66c4fe3216b807a0bc137e0cf78046fb596b6b0b Mon Sep 17 00:00:00 2001 From: dupirefr Date: Fri, 20 Mar 2020 08:39:48 +0100 Subject: [PATCH 176/278] [JAVA-958] Standardize packages in spring-bom module --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-bom/src/test/java/{org => com}/baeldung/SpringContextTest.java (90%) diff --git a/spring-bom/src/test/java/org/baeldung/SpringContextTest.java b/spring-bom/src/test/java/com/baeldung/SpringContextTest.java similarity index 90% rename from spring-bom/src/test/java/org/baeldung/SpringContextTest.java rename to spring-bom/src/test/java/com/baeldung/SpringContextTest.java index 783567cdfa..0c7da10dd6 100644 --- a/spring-bom/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-bom/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; From 1022c706a4267e7f05e6a289b62fa150b67e1493 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Fri, 20 Mar 2020 23:49:49 +0100 Subject: [PATCH 177/278] JAVA-1088: Move java-generating-barcodes-qr-codes into spring-boot-libraries module --- libraries-3/pom.xml | 56 +++++-------------- .../spring-boot-libraries/README.md | 1 + .../spring-boot-libraries/pom.xml | 37 ++++++++++++ .../baeldung/barcodes/BarcodesController.java | 0 .../com/baeldung/barcodes/SpringBootApp.java | 0 .../generators/BarbecueBarcodeGenerator.java | 0 .../generators/Barcode4jBarcodeGenerator.java | 0 .../generators/QRGenBarcodeGenerator.java | 0 .../generators/ZxingBarcodeGenerator.java | 0 9 files changed, 53 insertions(+), 41 deletions(-) rename {libraries-3 => spring-boot-modules/spring-boot-libraries}/src/main/java/com/baeldung/barcodes/BarcodesController.java (100%) rename {libraries-3 => spring-boot-modules/spring-boot-libraries}/src/main/java/com/baeldung/barcodes/SpringBootApp.java (100%) rename {libraries-3 => spring-boot-modules/spring-boot-libraries}/src/main/java/com/baeldung/barcodes/generators/BarbecueBarcodeGenerator.java (100%) rename {libraries-3 => spring-boot-modules/spring-boot-libraries}/src/main/java/com/baeldung/barcodes/generators/Barcode4jBarcodeGenerator.java (100%) rename {libraries-3 => spring-boot-modules/spring-boot-libraries}/src/main/java/com/baeldung/barcodes/generators/QRGenBarcodeGenerator.java (100%) rename {libraries-3 => spring-boot-modules/spring-boot-libraries}/src/main/java/com/baeldung/barcodes/generators/ZxingBarcodeGenerator.java (100%) diff --git a/libraries-3/pom.xml b/libraries-3/pom.xml index 4b9cac8cff..5334bfba70 100644 --- a/libraries-3/pom.xml +++ b/libraries-3/pom.xml @@ -8,9 +8,8 @@ com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../parent-boot-2 + parent-modules + 1.0.0-SNAPSHOT @@ -24,39 +23,6 @@ lombok ${lombok.version} - - org.springframework.boot - spring-boot-starter-web - - - - net.sourceforge.barbecue - barbecue - ${barbecue.version} - - - - net.sf.barcode4j - barcode4j - ${barcode4j.version} - - - - com.google.zxing - core - ${zxing.version} - - - com.google.zxing - javase - ${zxing.version} - - - - com.github.kenglxn.qrgen - javase - ${qrgen.version} - com.github.rvesse airline @@ -89,6 +55,16 @@ takes ${takes.version} + + org.apache.httpcomponents + httpcore + ${httpcore.version} + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + org.apache.velocity velocity-engine-core @@ -119,7 +95,7 @@ https://jitpack.io - + libraries-3 @@ -239,10 +215,6 @@ 1.78 1.18.6 - 1.5-beta1 - 2.1 - 3.3.0 - 2.6.0 0.43 2.7.2 @@ -254,6 +226,8 @@ 1.9.2 1.19 + 4.4.13 + 4.5.12 2.2 1.6.0 diff --git a/spring-boot-modules/spring-boot-libraries/README.md b/spring-boot-modules/spring-boot-libraries/README.md index f0bc3c9e89..c02fb69e5d 100644 --- a/spring-boot-modules/spring-boot-libraries/README.md +++ b/spring-boot-modules/spring-boot-libraries/README.md @@ -9,3 +9,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Guide to ShedLock with Spring](https://www.baeldung.com/shedlock-spring) - [A Guide to the Problem Spring Web Library](https://www.baeldung.com/problem-spring-web) +- [Generating Barcodes and QR Codes in Java](https://www.baeldung.com/java-generating-barcodes-qr-codes) diff --git a/spring-boot-modules/spring-boot-libraries/pom.xml b/spring-boot-modules/spring-boot-libraries/pom.xml index ba1164dd59..e9d955edc0 100644 --- a/spring-boot-modules/spring-boot-libraries/pom.xml +++ b/spring-boot-modules/spring-boot-libraries/pom.xml @@ -53,8 +53,41 @@ ${shedlock.version} + + + net.sourceforge.barbecue + barbecue + ${barbecue.version} + + + net.sf.barcode4j + barcode4j + ${barcode4j.version} + + + com.github.kenglxn.qrgen + javase + ${qrgen.version} + + + com.google.zxing + core + ${zxing.version} + + + com.google.zxing + javase + ${zxing.version} + + + + jitpack.io + https://jitpack.io + + + spring-boot-libraries @@ -153,6 +186,10 @@ 2.3.2 0.23.0 2.1.0 + 1.5-beta1 + 2.1 + 2.6.0 + 3.3.0 diff --git a/libraries-3/src/main/java/com/baeldung/barcodes/BarcodesController.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/BarcodesController.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/barcodes/BarcodesController.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/BarcodesController.java diff --git a/libraries-3/src/main/java/com/baeldung/barcodes/SpringBootApp.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/SpringBootApp.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/barcodes/SpringBootApp.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/SpringBootApp.java diff --git a/libraries-3/src/main/java/com/baeldung/barcodes/generators/BarbecueBarcodeGenerator.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/BarbecueBarcodeGenerator.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/barcodes/generators/BarbecueBarcodeGenerator.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/BarbecueBarcodeGenerator.java diff --git a/libraries-3/src/main/java/com/baeldung/barcodes/generators/Barcode4jBarcodeGenerator.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/Barcode4jBarcodeGenerator.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/barcodes/generators/Barcode4jBarcodeGenerator.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/Barcode4jBarcodeGenerator.java diff --git a/libraries-3/src/main/java/com/baeldung/barcodes/generators/QRGenBarcodeGenerator.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/QRGenBarcodeGenerator.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/barcodes/generators/QRGenBarcodeGenerator.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/QRGenBarcodeGenerator.java diff --git a/libraries-3/src/main/java/com/baeldung/barcodes/generators/ZxingBarcodeGenerator.java b/spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/ZxingBarcodeGenerator.java similarity index 100% rename from libraries-3/src/main/java/com/baeldung/barcodes/generators/ZxingBarcodeGenerator.java rename to spring-boot-modules/spring-boot-libraries/src/main/java/com/baeldung/barcodes/generators/ZxingBarcodeGenerator.java From ad94b4d4b2c60d603fc6b52ba2886690c29a24c0 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 21 Mar 2020 16:07:48 +0530 Subject: [PATCH 178/278] JAVA-60 Mvn Clean Install Profile Issue - Github 8189 - Updated README.md as per the latest profile based segregation that we follow in this repository --- README.md | 16 ++++++++-------- parent-kotlin/pom.xml | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 47b9709465..106c5f876a 100644 --- a/README.md +++ b/README.md @@ -33,14 +33,14 @@ Next, they are segregated further on the basis of tests that we want to execute. Therefore, we have a total of 6 profiles: -| Profile | Includes | Type of test enabled | -| ---------------------- | --------------------------- | -------------------- | -| default-first | First set of projects | *UnitTest | -| integration-lite-first | First set of projects | *IntegrationTest | -| default-second | Second set of projects | *UnitTest | -| integration-lite-first | Second set of projects | *IntegrationTest | -| default-heavy | Heavy/long running projects | *UnitTest | -| integration-heavy | Heavy/long running projects | *IntegrationTest | +| Profile | Includes | Type of test enabled | +| ----------------------- | --------------------------- | -------------------- | +| default-first | First set of projects | *UnitTest | +| integration-lite-first | First set of projects | *IntegrationTest | +| default-second | Second set of projects | *UnitTest | +| integration-lite-second | Second set of projects | *IntegrationTest | +| default-heavy | Heavy/long running projects | *UnitTest | +| integration-heavy | Heavy/long running projects | *IntegrationTest | Building the project ==================== diff --git a/parent-kotlin/pom.xml b/parent-kotlin/pom.xml index abc871ca91..6a7d763550 100644 --- a/parent-kotlin/pom.xml +++ b/parent-kotlin/pom.xml @@ -29,7 +29,7 @@ spring-milestone Spring Milestone Repository - http://repo.spring.io/milestone + https://repo.spring.io/milestone From 476270ce54074ca36bd4056ef3eead1ab086856f Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 21 Mar 2020 17:03:32 +0530 Subject: [PATCH 179/278] JAVA-60 Mvn Clean Install Profile Issue - Github 8189 - Updated README.md as per the latest profile based segregation that we follow in this repository --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 106c5f876a..6ed01b1ae6 100644 --- a/README.md +++ b/README.md @@ -33,21 +33,21 @@ Next, they are segregated further on the basis of tests that we want to execute. Therefore, we have a total of 6 profiles: -| Profile | Includes | Type of test enabled | -| ----------------------- | --------------------------- | -------------------- | -| default-first | First set of projects | *UnitTest | -| integration-lite-first | First set of projects | *IntegrationTest | -| default-second | Second set of projects | *UnitTest | -| integration-lite-second | Second set of projects | *IntegrationTest | -| default-heavy | Heavy/long running projects | *UnitTest | -| integration-heavy | Heavy/long running projects | *IntegrationTest | +| Profile | Includes | Type of test enabled | +| ----------------------- | --------------------------- | ---------------------------- | +| default-first | First set of projects | *UnitTest, SpringContextTest | +| integration-lite-first | First set of projects | *IntegrationTest | +| default-second | Second set of projects | *UnitTest, SpringContextTest | +| integration-lite-second | Second set of projects | *IntegrationTest | +| default-heavy | Heavy/long running projects | *UnitTest, SpringContextTest | +| integration-heavy | Heavy/long running projects | *IntegrationTest | Building the project ==================== Though it should not be needed often to build the entire repository at once because we are usually concerned with a specific module. -But if we want to, we can invoke the below command from the root of the repository if we want to build the entire repository with only Unit Tests enabled: +But if we want to, we can invoke the below command from the root of the repository if we want to build the entire repository with only Unit Tests and `SpringContextTest` enabled: `mvn clean install -Pdefault-first,default-second,default-heavy` @@ -74,7 +74,7 @@ When you're working with an individual module, there's no need to import all of Running Tests ============= -The command `mvn clean install` from within a module will run the unit tests in that module. +The command `mvn clean install` from within a module will run the unit tests in that module and additionally `SpringContextTest`. To run the integration tests, use the command: `mvn clean install -Pintegration-lite-first` or From c0e1a3df91af874a32383c005db287430c367340 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sat, 21 Mar 2020 17:09:53 +0530 Subject: [PATCH 180/278] JAVA-60 Mvn Clean Install Profile Issue - Github 8189 - Updated README.md as per the latest profile based segregation that we follow in this repository --- README.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6ed01b1ae6..b08a93f23e 100644 --- a/README.md +++ b/README.md @@ -33,21 +33,21 @@ Next, they are segregated further on the basis of tests that we want to execute. Therefore, we have a total of 6 profiles: -| Profile | Includes | Type of test enabled | -| ----------------------- | --------------------------- | ---------------------------- | -| default-first | First set of projects | *UnitTest, SpringContextTest | -| integration-lite-first | First set of projects | *IntegrationTest | -| default-second | Second set of projects | *UnitTest, SpringContextTest | -| integration-lite-second | Second set of projects | *IntegrationTest | -| default-heavy | Heavy/long running projects | *UnitTest, SpringContextTest | -| integration-heavy | Heavy/long running projects | *IntegrationTest | +| Profile | Includes | Type of test enabled | +| ----------------------- | --------------------------- | -------------------- | +| default-first | First set of projects | *UnitTest | +| integration-lite-first | First set of projects | *IntegrationTest | +| default-second | Second set of projects | *UnitTest | +| integration-lite-second | Second set of projects | *IntegrationTest | +| default-heavy | Heavy/long running projects | *UnitTest | +| integration-heavy | Heavy/long running projects | *IntegrationTest | Building the project ==================== Though it should not be needed often to build the entire repository at once because we are usually concerned with a specific module. -But if we want to, we can invoke the below command from the root of the repository if we want to build the entire repository with only Unit Tests and `SpringContextTest` enabled: +But if we want to, we can invoke the below command from the root of the repository if we want to build the entire repository with only Unit Tests enabled: `mvn clean install -Pdefault-first,default-second,default-heavy` @@ -74,7 +74,9 @@ When you're working with an individual module, there's no need to import all of Running Tests ============= -The command `mvn clean install` from within a module will run the unit tests in that module and additionally `SpringContextTest`. +The command `mvn clean install` from within a module will run the unit tests in that module. +For Spring modules this will also run the `SpringContextTest` if present. + To run the integration tests, use the command: `mvn clean install -Pintegration-lite-first` or From 2129f59ee263844dc588cdee5393db0853048a1f Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:06:29 +0100 Subject: [PATCH 181/278] JAVA-86: Remove spring-boot-change-port --- .../spring-boot-runtime/README.md | 1 - .../baeldung/changeport/CustomApplication.java | 17 ----------------- .../changeport/ServerPortCustomizer.java | 15 --------------- 3 files changed, 33 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/CustomApplication.java delete mode 100644 spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java diff --git a/spring-boot-modules/spring-boot-runtime/README.md b/spring-boot-modules/spring-boot-runtime/README.md index a544faf830..62727ecc76 100644 --- a/spring-boot-modules/spring-boot-runtime/README.md +++ b/spring-boot-modules/spring-boot-runtime/README.md @@ -8,7 +8,6 @@ This module contains articles about administering a Spring Boot runtime - [Logging HTTP Requests with Spring Boot Actuator HTTP Tracing](https://www.baeldung.com/spring-boot-actuator-http) - [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging) - [Spring Boot Embedded Tomcat Logs](https://www.baeldung.com/spring-boot-embedded-tomcat-logs) - - [How to Change the Default Port in Spring Boot](https://www.baeldung.com/spring-boot-change-port) - [Project Configuration with Spring](https://www.baeldung.com/project-configuration-with-spring) - [CORS with Spring](https://www.baeldung.com/spring-cors) - [Spring – Log Incoming Requests](https://www.baeldung.com/spring-http-logging) \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/CustomApplication.java b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/CustomApplication.java deleted file mode 100644 index 3fce0f1289..0000000000 --- a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/CustomApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.changeport; - -import java.util.Collections; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class CustomApplication { - - public static void main(String[] args) { - SpringApplication app = new SpringApplication(CustomApplication.class); - app.setDefaultProperties(Collections.singletonMap("server.port", "8083")); - app.run(args); - } - -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java b/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java deleted file mode 100644 index f3610aeac6..0000000000 --- a/spring-boot-modules/spring-boot-runtime/src/main/java/com/baeldung/changeport/ServerPortCustomizer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.changeport; - -import org.springframework.boot.web.server.ConfigurableWebServerFactory; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; -import org.springframework.stereotype.Component; - -//@Component -public class ServerPortCustomizer implements WebServerFactoryCustomizer { - - @Override - public void customize(ConfigurableWebServerFactory factory) { - factory.setPort(8086); - } - -} \ No newline at end of file From 4f8cb3cf3723c7dce708c9de68768ba339b84729 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:10:02 +0100 Subject: [PATCH 182/278] JAVA-86: Remove spring-boot-custom-banners --- spring-boot-modules/spring-boot/README.MD | 1 - .../src/main/resources/application.properties | 8 -------- .../spring-boot/src/main/resources/banner.txt | 14 -------------- 3 files changed, 23 deletions(-) delete mode 100644 spring-boot-modules/spring-boot/src/main/resources/banner.txt diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index 217d9e90b2..a59ca34fae 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -11,7 +11,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [The @ServletComponentScan Annotation in Spring Boot](https://www.baeldung.com/spring-servletcomponentscan) - [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) - [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) -- [Using Custom Banners in Spring Boot](https://www.baeldung.com/spring-boot-custom-banners) - [Guide to Internationalization in Spring Boot](https://www.baeldung.com/spring-boot-internationalization) - [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer) - [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation) diff --git a/spring-boot-modules/spring-boot/src/main/resources/application.properties b/spring-boot-modules/spring-boot/src/main/resources/application.properties index 7de79da574..44649fc1c0 100644 --- a/spring-boot-modules/spring-boot/src/main/resources/application.properties +++ b/spring-boot-modules/spring-boot/src/main/resources/application.properties @@ -33,12 +33,4 @@ logging.level.org.springframework=INFO servlet.name=dispatcherExample servlet.mapping=/dispatcherExampleURL -#spring.banner.charset=UTF-8 -#spring.banner.location=classpath:banner.txt -#spring.banner.image.location=classpath:banner.gif -#spring.banner.image.width= //TODO -#spring.banner.image.height= //TODO -#spring.banner.image.margin= //TODO -#spring.banner.image.invert= //TODO - contactInfoType=email \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/banner.txt b/spring-boot-modules/spring-boot/src/main/resources/banner.txt deleted file mode 100644 index abfa666eb6..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/banner.txt +++ /dev/null @@ -1,14 +0,0 @@ -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@########@@@@@@@@@@@@@@@@@@@@@@@@...@@@@@@@@@:..@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -@@@@@@@@@@@@@@@@@@@@@@#. @@@@@* *@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -@@@@@@@@@@@@@@@@@#o @@@@@* @@@@@* @@@:*.*@@@@@@@: *8@@@ @@@@&:.#@. @o**@@@@**:@o*o@@:.:@@@@@:.o#@&*:@@@@ -@@@@@@@@@@@@* @@@@@* 8888 8@ @@@8 #@o 8@# .@ @@* :. @* @@@@ @. : &@ ** .@@@@ -@@@@@@@@@@. @ o@@@@@* *@@@o::& .* 8@@@@. @@ 8@@@@. @* @@@@ @. @@@& * @@@@# .@@@@ -@@@@@@@@@& @ @@@@@@* @@@@@@ 8 @@@@ .. o&&&&&&& @@ #@@@@. @* @@@@ @. @@@# * @@@@@ .@@@@ -@@@@@@@@@ @@o @@@@@@@* oooo* 8 @@@& @* @@@ # 88. 88. *& o#: @. @@@# *@ &#& .@@@@ -@@@@@@@@# @@@8 @@@@@@@* .*@@@#. *@@ @@@& :#@@@o .@@: *&@8 @o o@@: @. @@@# *@@#. :8# .@@@@ -@@@@@@@@@ @@@@ &@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# o@@@@ @@@@@ -@@@@@& &@@@@ 8@@@@@@@@@8&8@@@@@#8#@@@o8@#&@@o&@@@&@@8@@&@@@@88@@8#@8&@@##@@@@@@#8@@#8@@88@@@@@ *@@@@@@@ -@@@# #@@@@#. @@@@@@@@@@@@@8@@8#o@&#@@@@o.@o*@@*.@@@.@&:8o8*@@@8&@@#@@@8@@@@8@#@@@8&@@@@@@#@@@@@@@@@@@@@@@@@@@ -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ \ No newline at end of file From 3f21f970b8749987b05a048db9e1389b08babda6 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:13:59 +0100 Subject: [PATCH 183/278] JAVA-86: Remove spring-boot-failure-analyzer --- spring-boot-modules/spring-boot/README.MD | 1 - .../FailureAnalyzerApplication.java | 14 ------ ...yBeanNotOfRequiredTypeFailureAnalyzer.java | 22 --------- .../com/baeldung/failureanalyzer/MyDAO.java | 5 -- .../baeldung/failureanalyzer/MySecondDAO.java | 8 ---- .../baeldung/failureanalyzer/MyService.java | 13 ----- .../main/resources/META-INF/spring.factories | 2 - .../FailureAnalyzerAppIntegrationTest.java | 47 ------------------- .../failureanalyzer/utils/ListAppender.java | 25 ---------- .../src/test/resources/logback-test.xml | 15 ------ 10 files changed, 152 deletions(-) delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyDAO.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyService.java delete mode 100644 spring-boot-modules/spring-boot/src/main/resources/META-INF/spring.factories delete mode 100644 spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java delete mode 100644 spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java delete mode 100644 spring-boot-modules/spring-boot/src/test/resources/logback-test.xml diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index a59ca34fae..83cc26fdec 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -12,7 +12,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [How to Register a Servlet in Java](https://www.baeldung.com/register-servlet) - [Guide to Spring WebUtils and ServletRequestUtils](https://www.baeldung.com/spring-webutils-servletrequestutils) - [Guide to Internationalization in Spring Boot](https://www.baeldung.com/spring-boot-internationalization) -- [Create a Custom FailureAnalyzer with Spring Boot](https://www.baeldung.com/spring-boot-failure-analyzer) - [Dynamic DTO Validation Config Retrieved from the Database](https://www.baeldung.com/spring-dynamic-dto-validation) - [Custom Information in Spring Boot Info Endpoint](https://www.baeldung.com/spring-boot-info-actuator-custom) - [Testing in Spring Boot](https://www.baeldung.com/spring-boot-testing) diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java deleted file mode 100644 index 7bd5c36786..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/FailureAnalyzerApplication.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.failureanalyzer; - -import javax.annotation.security.RolesAllowed; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class FailureAnalyzerApplication { - @RolesAllowed("*") - public static void main(String[] args) { - SpringApplication.run(FailureAnalyzerApplication.class, args); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java deleted file mode 100644 index 3949908083..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyBeanNotOfRequiredTypeFailureAnalyzer.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.failureanalyzer; - -import org.springframework.beans.factory.BeanNotOfRequiredTypeException; -import org.springframework.boot.diagnostics.AbstractFailureAnalyzer; -import org.springframework.boot.diagnostics.FailureAnalysis; - -public class MyBeanNotOfRequiredTypeFailureAnalyzer extends AbstractFailureAnalyzer { - - @Override - protected FailureAnalysis analyze(Throwable rootFailure, BeanNotOfRequiredTypeException cause) { - return new FailureAnalysis(getDescription(cause), getAction(cause), cause); - } - - private String getDescription(BeanNotOfRequiredTypeException ex) { - return String.format("The bean %s could not be injected as %s because it is of type %s", ex.getBeanName(), ex.getRequiredType().getName(), ex.getActualType().getName()); - } - - private String getAction(BeanNotOfRequiredTypeException ex) { - return String.format("Consider creating a bean with name %s of type %s", ex.getBeanName(), ex.getRequiredType().getName()); - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyDAO.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyDAO.java deleted file mode 100644 index ddaeb28574..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyDAO.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.failureanalyzer; - -public class MyDAO { - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java deleted file mode 100644 index 12dd73a05b..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MySecondDAO.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.failureanalyzer; - -import org.springframework.stereotype.Repository; - -@Repository("myDAO") -public class MySecondDAO { - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyService.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyService.java deleted file mode 100644 index 72334ca8fa..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/failureanalyzer/MyService.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.failureanalyzer; - -import javax.annotation.Resource; - -import org.springframework.stereotype.Service; - -@Service -public class MyService { - - @Resource(name = "myDAO") - private MyDAO myDAO; - -} diff --git a/spring-boot-modules/spring-boot/src/main/resources/META-INF/spring.factories b/spring-boot-modules/spring-boot/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 336477df96..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,2 +0,0 @@ -org.springframework.boot.diagnostics.FailureAnalyzer=com.baeldung.failureanalyzer.MyBeanNotOfRequiredTypeFailureAnalyzer - diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java deleted file mode 100644 index b3555f55da..0000000000 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/FailureAnalyzerAppIntegrationTest.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.failureanalyzer; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Collection; -import java.util.stream.Collectors; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.BeanCreationException; -import org.springframework.boot.SpringApplication; - -import com.baeldung.failureanalyzer.utils.ListAppender; - -import ch.qos.logback.classic.spi.ILoggingEvent; - -public class FailureAnalyzerAppIntegrationTest { - - private static final String EXPECTED_ANALYSIS_DESCRIPTION_TITLE = "Description:"; - private static final String EXPECTED_ANALYSIS_DESCRIPTION_CONTENT = "The bean myDAO could not be injected as com.baeldung.failureanalyzer.MyDAO because it is of type com.baeldung.failureanalyzer.MySecondDAO"; - private static final String EXPECTED_ANALYSIS_ACTION_TITLE = "Action:"; - private static final String EXPECTED_ANALYSIS_ACTION_CONTENT = "Consider creating a bean with name myDAO of type com.baeldung.failureanalyzer.MyDAO"; - - @BeforeEach - public void clearLogList() { - ListAppender.clearEventList(); - } - - @Test - public void givenBeanCreationErrorInContext_whenContextLoaded_thenFailureAnalyzerLogsReport() { - try { - SpringApplication.run(FailureAnalyzerApplication.class); - } catch (BeanCreationException e) { - Collection allLoggedEntries = ListAppender.getEvents() - .stream() - .map(ILoggingEvent::getFormattedMessage) - .collect(Collectors.toList()); - assertThat(allLoggedEntries).anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_TITLE)) - .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_DESCRIPTION_CONTENT)) - .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_TITLE)) - .anyMatch(entry -> entry.contains(EXPECTED_ANALYSIS_ACTION_CONTENT)); - return; - } - throw new IllegalStateException("Context load should be failing due to a BeanCreationException!"); - } - -} diff --git a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java b/spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java deleted file mode 100644 index a298f49ff5..0000000000 --- a/spring-boot-modules/spring-boot/src/test/java/com/baeldung/failureanalyzer/utils/ListAppender.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.failureanalyzer.utils; - -import java.util.ArrayList; -import java.util.List; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.AppenderBase; - -public class ListAppender extends AppenderBase { - - static private List events = new ArrayList<>(); - - @Override - protected void append(ILoggingEvent eventObject) { - events.add(eventObject); - } - - public static List getEvents() { - return events; - } - - public static void clearEventList() { - events.clear(); - } -} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/test/resources/logback-test.xml b/spring-boot-modules/spring-boot/src/test/resources/logback-test.xml deleted file mode 100644 index 9e0f4e221f..0000000000 --- a/spring-boot-modules/spring-boot/src/test/resources/logback-test.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file From 802d1d3b9029e0eea97afeb0c23f6aed42bba369 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:19:54 +0100 Subject: [PATCH 184/278] JAVA-86: Remove spring-boot-custom-error-page --- spring-boot-modules/spring-boot/README.MD | 1 - .../ErrorHandlingApplication.java | 15 ------- .../controllers/IndexController.java | 26 ------------ .../controllers/MyErrorController.java | 40 ------------------- .../application-errorhandling.properties | 8 +--- .../main/resources/templates/error-404.html | 14 ------- .../main/resources/templates/error-500.html | 16 -------- 7 files changed, 1 insertion(+), 119 deletions(-) delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java delete mode 100644 spring-boot-modules/spring-boot/src/main/resources/templates/error-404.html delete mode 100644 spring-boot-modules/spring-boot/src/main/resources/templates/error-500.html diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index 83cc26fdec..16f20d889c 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -20,7 +20,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Getting Started with GraphQL and Spring Boot](https://www.baeldung.com/spring-graphql) - [Guide to Spring Type Conversions](https://www.baeldung.com/spring-type-conversions) - [An Introduction to Kong](https://www.baeldung.com/kong) -- [Spring Boot: Customize Whitelabel Error Page](https://www.baeldung.com/spring-boot-custom-error-page) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) - [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer) - [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter) diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java deleted file mode 100644 index 5dd55ef077..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/ErrorHandlingApplication.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.errorhandling; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.ComponentScan; - -@SpringBootApplication -@ComponentScan(basePackages = "com.baeldung.errorhandling") -public class ErrorHandlingApplication { - - public static void main(String [] args) { - System.setProperty("spring.profiles.active", "errorhandling"); - SpringApplication.run(ErrorHandlingApplication.class, args); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java deleted file mode 100644 index 1a8761e96b..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/IndexController.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.baeldung.errorhandling.controllers; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; - -@Controller -public class IndexController { - - @GetMapping(value = {"/", ""}) - public String index() { - return "index"; - } - - @GetMapping(value = {"/server_error"}) - public String triggerServerError() { - "ser".charAt(30); - return "index"; - } - - @PostMapping(value = {"/general_error"}) - public String triggerGeneralError() { - return "index"; - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java deleted file mode 100644 index e002ac045d..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/errorhandling/controllers/MyErrorController.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.errorhandling.controllers; - -import org.springframework.boot.web.servlet.error.ErrorController; -import org.springframework.http.HttpStatus; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; - -import javax.servlet.RequestDispatcher; -import javax.servlet.http.HttpServletRequest; - -@Controller -public class MyErrorController implements ErrorController { - - public MyErrorController() {} - - @GetMapping(value = "/error") - public String handleError(HttpServletRequest request) { - - Object status = request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); - - if (status != null) { - - Integer statusCode = Integer.valueOf(status.toString()); - - if(statusCode == HttpStatus.NOT_FOUND.value()) { - return "error-404"; - } - else if(statusCode == HttpStatus.INTERNAL_SERVER_ERROR.value()) { - return "error-500"; - } - } - return "error"; - } - - @Override - public String getErrorPath() { - return "/error"; - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/resources/application-errorhandling.properties b/spring-boot-modules/spring-boot/src/main/resources/application-errorhandling.properties index 6ffcfbaf52..270e86d443 100644 --- a/spring-boot-modules/spring-boot/src/main/resources/application-errorhandling.properties +++ b/spring-boot-modules/spring-boot/src/main/resources/application-errorhandling.properties @@ -1,10 +1,4 @@ #server server.port=9000 server.servlet-path=/ -server.context-path=/ -#server.error.whitelabel.enabled=false - -#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.ErrorMvcAutoConfiguration - -#for Spring Boot 2.0+ -#spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration \ No newline at end of file +server.context-path=/ \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/error-404.html b/spring-boot-modules/spring-boot/src/main/resources/templates/error-404.html deleted file mode 100644 index cf68032596..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/error-404.html +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - -
-
-

Sorry, we couldn't find the page you were looking for.

-

Go Home

-
- - \ No newline at end of file diff --git a/spring-boot-modules/spring-boot/src/main/resources/templates/error-500.html b/spring-boot-modules/spring-boot/src/main/resources/templates/error-500.html deleted file mode 100644 index 5ddf458229..0000000000 --- a/spring-boot-modules/spring-boot/src/main/resources/templates/error-500.html +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - -
-
-

Sorry, something went wrong!

- -

We're fixing it.

-

Go Home

-
- - \ No newline at end of file From a5ee0d6b6f6a7360d04272858d003671959e88f8 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:23:58 +0100 Subject: [PATCH 185/278] JAVA-86: Remove spring-boot-add-filter --- spring-boot-modules/spring-boot/README.MD | 1 - .../bootcustomfilters/FilterConfig.java | 25 ---------- .../SpringBootFiltersApplication.java | 17 ------- .../controller/UserController.java | 35 ------------- .../filters/RequestResponseLoggingFilter.java | 50 ------------------- .../filters/TransactionFilter.java | 47 ----------------- .../bootcustomfilters/model/User.java | 45 ----------------- 7 files changed, 220 deletions(-) delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java delete mode 100644 spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index 16f20d889c..3397ad3b75 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -22,7 +22,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [An Introduction to Kong](https://www.baeldung.com/kong) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) - [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer) -- [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter) - [Spring Boot Exit Codes](https://www.baeldung.com/spring-boot-exit-codes) - [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon) - [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java deleted file mode 100644 index aa794182de..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/FilterConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.bootcustomfilters; - -import org.springframework.boot.web.servlet.FilterRegistrationBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.baeldung.bootcustomfilters.filters.RequestResponseLoggingFilter; - -@Configuration -public class FilterConfig { - - // uncomment this and comment the @Component in the filter class definition to register only for a url pattern - // @Bean - public FilterRegistrationBean loggingFilter() { - FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); - - registrationBean.setFilter(new RequestResponseLoggingFilter()); - - registrationBean.addUrlPatterns("/users/*"); - - return registrationBean; - - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java deleted file mode 100644 index c4653932c0..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/SpringBootFiltersApplication.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.bootcustomfilters; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -/** - * Boot application - * @author hemant - * - */ -@SpringBootApplication -public class SpringBootFiltersApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootFiltersApplication.class, args); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java deleted file mode 100644 index 97165f2cf3..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/controller/UserController.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.bootcustomfilters.controller; - -import java.util.Arrays; -import java.util.List; -import java.util.UUID; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.baeldung.bootcustomfilters.model.User; - -/** - * Rest controller for User - * @author hemant - * - */ -@RestController -@RequestMapping("/users") -public class UserController { - - private static final Logger LOG = LoggerFactory.getLogger(UserController.class); - - @GetMapping("") - public List getAllUsers() { - LOG.info("Fetching all the users"); - return Arrays.asList( - new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), - new User(UUID.randomUUID().toString(), "User1", "user1@test.com"), - new User(UUID.randomUUID().toString(), "User1", "user1@test.com")); - } - -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java deleted file mode 100644 index e42ea7d2dd..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/RequestResponseLoggingFilter.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.baeldung.bootcustomfilters.filters; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -/** - * A servlet filter to log request and response - * The logging implementation is pretty native and for demonstration only - * @author hemant - * - */ -@Component -@Order(2) -public class RequestResponseLoggingFilter implements Filter { - - private final static Logger LOG = LoggerFactory.getLogger(RequestResponseLoggingFilter.class); - - @Override - public void init(final FilterConfig filterConfig) throws ServletException { - LOG.info("Initializing filter :{}", this); - } - - @Override - public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) - throws IOException, ServletException { - HttpServletRequest req = (HttpServletRequest) request; - HttpServletResponse res = (HttpServletResponse) response; - LOG.info("Logging Request {} : {}", req.getMethod(), req.getRequestURI()); - chain.doFilter(request, response); - LOG.info("Logging Response :{}", res.getContentType()); - } - - @Override - public void destroy() { - LOG.warn("Destructing filter :{}", this); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java deleted file mode 100644 index d92b723e73..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/filters/TransactionFilter.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.baeldung.bootcustomfilters.filters; - -import java.io.IOException; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -/** - * A filter to create transaction before and commit it once request completes - * The current implemenatation is just for demo - * @author hemant - * - */ -@Component -@Order(1) -public class TransactionFilter implements Filter { - - private final static Logger LOG = LoggerFactory.getLogger(TransactionFilter.class); - - @Override - public void init(final FilterConfig filterConfig) throws ServletException { - LOG.info("Initializing filter :{}", this); - } - - @Override - public void doFilter(final ServletRequest request, final ServletResponse response, final FilterChain chain) throws IOException, ServletException { - HttpServletRequest req = (HttpServletRequest) request; - LOG.info("Starting Transaction for req :{}", req.getRequestURI()); - chain.doFilter(request, response); - LOG.info("Committing Transaction for req :{}", req.getRequestURI()); - } - - @Override - public void destroy() { - LOG.warn("Destructing filter :{}", this); - } -} diff --git a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java b/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java deleted file mode 100644 index ab8e6c8206..0000000000 --- a/spring-boot-modules/spring-boot/src/main/java/com/baeldung/bootcustomfilters/model/User.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.bootcustomfilters.model; - -/** - * User model - * @author hemant - * - */ -public class User { - - private String id; - private String name; - private String email; - - public User(String id, String name, String email) { - super(); - this.id = id; - this.name = name; - this.email = email; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - -} From 9c102b2b8723807d50eb9fceaae66dd7d641f923 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:27:30 +0100 Subject: [PATCH 186/278] JAVA-86: Remove spring-boot-exit-codes --- spring-boot-modules/spring-boot/README.MD | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index 3397ad3b75..b15ab7dbe5 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -22,7 +22,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [An Introduction to Kong](https://www.baeldung.com/kong) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) - [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer) -- [Spring Boot Exit Codes](https://www.baeldung.com/spring-boot-exit-codes) - [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon) - [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) - [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) From cd10d206daf8d032b313450ec56fb01c1f38d1b5 Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sat, 21 Mar 2020 16:31:39 +0100 Subject: [PATCH 187/278] JAVA-86: Remove spring-boot-favicon --- spring-boot-modules/spring-boot-mvc/README.md | 1 - .../config/FaviconConfiguration.java | 44 ------------------ .../resources/com/baeldung/images/favicon.ico | Bin 15086 -> 0 bytes .../src/main/resources/favicon.ico | Bin 15086 -> 0 bytes .../src/main/resources/static/favicon.ico | Bin 15086 -> 0 bytes 5 files changed, 45 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/config/FaviconConfiguration.java delete mode 100644 spring-boot-modules/spring-boot-mvc/src/main/resources/com/baeldung/images/favicon.ico delete mode 100644 spring-boot-modules/spring-boot-mvc/src/main/resources/favicon.ico delete mode 100644 spring-boot-modules/spring-boot-mvc/src/main/resources/static/favicon.ico diff --git a/spring-boot-modules/spring-boot-mvc/README.md b/spring-boot-modules/spring-boot-mvc/README.md index 2e67c42ede..41b98063a6 100644 --- a/spring-boot-modules/spring-boot-mvc/README.md +++ b/spring-boot-modules/spring-boot-mvc/README.md @@ -4,7 +4,6 @@ This module contains articles about Spring Web MVC in Spring Boot projects. ### Relevant Articles: -- [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon) - [Custom Validation MessageSource in Spring Boot](https://www.baeldung.com/spring-custom-validation-message-source) - [Display RSS Feed with Spring MVC](https://www.baeldung.com/spring-mvc-rss-feed) - [A Controller, Service and DAO Example with Spring Boot and JSF](https://www.baeldung.com/jsf-spring-boot-controller-service-dao) diff --git a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/config/FaviconConfiguration.java b/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/config/FaviconConfiguration.java deleted file mode 100644 index 9a1f47b5cb..0000000000 --- a/spring-boot-modules/spring-boot-mvc/src/main/java/com/baeldung/springbootmvc/config/FaviconConfiguration.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.springbootmvc.config; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.io.ClassPathResource; -import org.springframework.core.io.Resource; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; -import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; - -@Configuration -public class FaviconConfiguration { - @Bean - public SimpleUrlHandlerMapping myFaviconHandlerMapping() { - SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping(); - mapping.setOrder(Integer.MIN_VALUE); - mapping.setUrlMap(Collections.singletonMap("/favicon.ico", faviconRequestHandler())); - return mapping; - } - - @Bean - protected ResourceHttpRequestHandler faviconRequestHandler() { - ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler(); - ClassPathResource classPathResource = new ClassPathResource("com/baeldung/images"); - List locations = Arrays.asList(classPathResource); - requestHandler.setLocations(locations); - return requestHandler; - } - - // @Controller - static class FaviconController { - - @RequestMapping(value = "favicon.ico", method = RequestMethod.GET) - @ResponseBody - void favicon() { - } - } -} diff --git a/spring-boot-modules/spring-boot-mvc/src/main/resources/com/baeldung/images/favicon.ico b/spring-boot-modules/spring-boot-mvc/src/main/resources/com/baeldung/images/favicon.ico deleted file mode 100644 index 64105ac11c6186e380a724416ceb77ab5c263fef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15086 zcmeI33yf6N8OP5s)D;AFL7}u+*#$K|S}oXWX{A6BF!-qLwvyDOsBLZ4#$rp2QmZaB zDMc+H+EzuWwblBlHY$b~O&EM6N;Jr;Vo@0)La}NWK^bJ(>Fs!o&?#+$PV&lcoe<}Q{V*nJA~=Gv^RNwrqwUlyiXv{0{QS2SOqSBm|V^K zQLxvS?=`|#!l^JBRzeqq>8p;)yEgECA92~92j{^Ocmu-PBuDxspmqtCp>qEVFM;g6 z3&A`)Nb3(OYfs4gVE$lypKZf~(VYR$L6|Q=Js00EefOZN@uR+-2@ByKP=BkBcZ1V& za;MV`ljQFM^6k?gyLZAaaQZKV=~YTY?;z0l>;SdzoJx5srK6LD`LGc*O%p%p9R+QP z6|Dlgn&*8KEf$U0H~|`r8OzLXW>yUXO|EuJ9@z;+0>uLCE$K;D6=;Qtp!LanwD8pF zL%lx*!{PIA@PT%dGLMJnL2J+?m5&?%=R+Heh0&mOOj7IG$)NNv!-;S-s1E&-`j3w4 ze*;$_%n#DP4jaI&`|AJo@DvQQK3qds^Eye{{=D+zeqa~w{*b0M zR(W3qW}MgW;|R}%kv6VAT?u}hX~JrYFZewm{*2G=D}>$H)B1k}oNImf8sV*wrd+?y z)7Ti{d?5T*z~&a>=YZD3X`uXPTOYnp*uPHu?IsD|j2-XPgVeqn)YVx26$}E6htuI$ z=m)c54+M3R#I@(TzV57GOMWc_&GAFvV)zbdzFY;nAxW9RytksSIj1=teCLnv;Qe)= zb~qBILNjQ;t7bg>3;iR&KmPpX2E$qd7QkdsUwjrOfz}JnuVDV3;_5@4Pt~85`XJ1P z#>Nw%K9~Y(mmfe5lJ?1BbkwHnA*`&ZG_6NkC)dDVKz($ljemfQ(sl1v*mvbDZk2$~y7?4-@x zRW95YplprFUxW6=G;=GiKOg#v?G~im3}}vj6Lbc79A1XE;C)CkXDj*hPPalMB9y1k z3)+Wu9+?PQi?t@tf!jfA!mAK>?#ZVO5kX$cp1^G4tk~}hZLk@FK5QjzOk$%c6ewpJYzz2sH}Qi~m`kNXS(kuY zm$grwk;+g?CCbwo<{?l&`~&)@G?iM7GS39v#f(dBqzXmK)%tNZB)&_lqS&%3^N>f>U?kt99_50 zhB$`5I&0nnn?UCU-Dj5f0>T4eGH4GS47y*`p6bnANsH35pnXpFH$q{h_3Avw{!hT| zCpweq>j&>4EIgEVC&504U$@;BuG_UxHy!leH5& z{a^{WbHN||wh5mKJALn6zBE#29i4;Lf!bgOe8#m`T#3#QIMn4QJOZ8t`Sc$c?|Y~7 zpxQT$zdh;f!|qy`1;bsLJxTKZ4AkZWTwcPbz!p%MkH8?`yNSemx}WID*QodUytxYW z8N<8pbY%x6?;BwS=uABq{PXp@#MQs*=UGmdu;$`oi1MKp?=((-0~K%BdG}S&7*Top z{G`5fcVJpCE`{e|K9uiD36Fv`Pzyh!Y^d$DE_ipYt___eUF(4Ve&9XgKLu9@tvLfh zYp2dx{yMY~?|`WCYw=EFLv{FAKal3mzW#DlhhG5SvXmaer-RyC>)&9dBGo?{b7~{M zes6@;#u`gryIQy8gFbtQm8bn{9(eN>sde>g*abI%H`kHc^X`Q(8?{c;eDLm!ef~%F zzt*$ALW^y0?Y9?!>ii?0jTYi7q1OI}+0(jSo(qKKV^}_an&z+etv;YJqy0f=h;iV3 z4};Wwy5C+>czgc^UvL=@^ogn2KcptH};1TUIh2RaW-u_TjMp&81nn?!d=+XJYNo1z!Vq>{a`FCfo-6C zPA9GW5E~bO*2G0Muovcs_VIP_H<$&Q_c{|UhL=F|sG7Pguyf#e>}-ZGA8MJlmonaj z7eVXTde{wV%Xm!w>%qpQAp2=;rPZsZ{nwVf_x#tor+HS5y|i^mtGCVhZ~H*&#oeEv zI_&oQZ|iU<{{J4_9Yor;IS_i?zUOmw!FR29I%jT%1K~&7GD5#6wEd95cdbje!@G4_ zk8ZywbnWk#_^mVlIJgDWAJy*FY1=wX?*qTDQDOYnxqlSQfTge+-iA1zAHvG6McTik ze6I8kpS5QX0iAW);BvSb9s-?%Ho#WU`A+LVZ>`DeEBTlv9Y6bm&eFQiJOWOHsqj7c zCFuOK0=7Uc_R3{x{7kEZ&sr1u!${CsNavu9kakYZPwPu9^zd8tIUIC`UjzFg?!3@v zqv^HqqZT&sr5Wae&fjtBpfmr+ez#Z)U((vZAFT`e%%HyLsSY}mN8atG^`lxn{5k^ef&EKUa3$A^-tpOIeN?2N_O$_+t3kGhpQ{;)KfZsYtO$v;QuD# zbv19J+6-S?V4bal_VL+K`Rnl=KI<++>ygeTvA-9qm%8Ay?vVZo-ko8+_!ZX={BDA2 z(Cxd6xcc>w58r$Bd;5B*<0sLF(hr98+af(5$qpMYbeOEt3s)M`g6u>#AYbQ~W*Ou{ z{o?Fec zlG%Jonz7_IIsM_udw)NY9X5_N?{OdO<&K_W&J*7Mb9r%_KsEEFc+pc)wR4m&nYXfF dWheeBz01lX^-;Vm7uxu0D>qw-6JEX$`9Ha#9tHpa diff --git a/spring-boot-modules/spring-boot-mvc/src/main/resources/favicon.ico b/spring-boot-modules/spring-boot-mvc/src/main/resources/favicon.ico deleted file mode 100644 index 64105ac11c6186e380a724416ceb77ab5c263fef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15086 zcmeI33yf6N8OP5s)D;AFL7}u+*#$K|S}oXWX{A6BF!-qLwvyDOsBLZ4#$rp2QmZaB zDMc+H+EzuWwblBlHY$b~O&EM6N;Jr;Vo@0)La}NWK^bJ(>Fs!o&?#+$PV&lcoe<}Q{V*nJA~=Gv^RNwrqwUlyiXv{0{QS2SOqSBm|V^K zQLxvS?=`|#!l^JBRzeqq>8p;)yEgECA92~92j{^Ocmu-PBuDxspmqtCp>qEVFM;g6 z3&A`)Nb3(OYfs4gVE$lypKZf~(VYR$L6|Q=Js00EefOZN@uR+-2@ByKP=BkBcZ1V& za;MV`ljQFM^6k?gyLZAaaQZKV=~YTY?;z0l>;SdzoJx5srK6LD`LGc*O%p%p9R+QP z6|Dlgn&*8KEf$U0H~|`r8OzLXW>yUXO|EuJ9@z;+0>uLCE$K;D6=;Qtp!LanwD8pF zL%lx*!{PIA@PT%dGLMJnL2J+?m5&?%=R+Heh0&mOOj7IG$)NNv!-;S-s1E&-`j3w4 ze*;$_%n#DP4jaI&`|AJo@DvQQK3qds^Eye{{=D+zeqa~w{*b0M zR(W3qW}MgW;|R}%kv6VAT?u}hX~JrYFZewm{*2G=D}>$H)B1k}oNImf8sV*wrd+?y z)7Ti{d?5T*z~&a>=YZD3X`uXPTOYnp*uPHu?IsD|j2-XPgVeqn)YVx26$}E6htuI$ z=m)c54+M3R#I@(TzV57GOMWc_&GAFvV)zbdzFY;nAxW9RytksSIj1=teCLnv;Qe)= zb~qBILNjQ;t7bg>3;iR&KmPpX2E$qd7QkdsUwjrOfz}JnuVDV3;_5@4Pt~85`XJ1P z#>Nw%K9~Y(mmfe5lJ?1BbkwHnA*`&ZG_6NkC)dDVKz($ljemfQ(sl1v*mvbDZk2$~y7?4-@x zRW95YplprFUxW6=G;=GiKOg#v?G~im3}}vj6Lbc79A1XE;C)CkXDj*hPPalMB9y1k z3)+Wu9+?PQi?t@tf!jfA!mAK>?#ZVO5kX$cp1^G4tk~}hZLk@FK5QjzOk$%c6ewpJYzz2sH}Qi~m`kNXS(kuY zm$grwk;+g?CCbwo<{?l&`~&)@G?iM7GS39v#f(dBqzXmK)%tNZB)&_lqS&%3^N>f>U?kt99_50 zhB$`5I&0nnn?UCU-Dj5f0>T4eGH4GS47y*`p6bnANsH35pnXpFH$q{h_3Avw{!hT| zCpweq>j&>4EIgEVC&504U$@;BuG_UxHy!leH5& z{a^{WbHN||wh5mKJALn6zBE#29i4;Lf!bgOe8#m`T#3#QIMn4QJOZ8t`Sc$c?|Y~7 zpxQT$zdh;f!|qy`1;bsLJxTKZ4AkZWTwcPbz!p%MkH8?`yNSemx}WID*QodUytxYW z8N<8pbY%x6?;BwS=uABq{PXp@#MQs*=UGmdu;$`oi1MKp?=((-0~K%BdG}S&7*Top z{G`5fcVJpCE`{e|K9uiD36Fv`Pzyh!Y^d$DE_ipYt___eUF(4Ve&9XgKLu9@tvLfh zYp2dx{yMY~?|`WCYw=EFLv{FAKal3mzW#DlhhG5SvXmaer-RyC>)&9dBGo?{b7~{M zes6@;#u`gryIQy8gFbtQm8bn{9(eN>sde>g*abI%H`kHc^X`Q(8?{c;eDLm!ef~%F zzt*$ALW^y0?Y9?!>ii?0jTYi7q1OI}+0(jSo(qKKV^}_an&z+etv;YJqy0f=h;iV3 z4};Wwy5C+>czgc^UvL=@^ogn2KcptH};1TUIh2RaW-u_TjMp&81nn?!d=+XJYNo1z!Vq>{a`FCfo-6C zPA9GW5E~bO*2G0Muovcs_VIP_H<$&Q_c{|UhL=F|sG7Pguyf#e>}-ZGA8MJlmonaj z7eVXTde{wV%Xm!w>%qpQAp2=;rPZsZ{nwVf_x#tor+HS5y|i^mtGCVhZ~H*&#oeEv zI_&oQZ|iU<{{J4_9Yor;IS_i?zUOmw!FR29I%jT%1K~&7GD5#6wEd95cdbje!@G4_ zk8ZywbnWk#_^mVlIJgDWAJy*FY1=wX?*qTDQDOYnxqlSQfTge+-iA1zAHvG6McTik ze6I8kpS5QX0iAW);BvSb9s-?%Ho#WU`A+LVZ>`DeEBTlv9Y6bm&eFQiJOWOHsqj7c zCFuOK0=7Uc_R3{x{7kEZ&sr1u!${CsNavu9kakYZPwPu9^zd8tIUIC`UjzFg?!3@v zqv^HqqZT&sr5Wae&fjtBpfmr+ez#Z)U((vZAFT`e%%HyLsSY}mN8atG^`lxn{5k^ef&EKUa3$A^-tpOIeN?2N_O$_+t3kGhpQ{;)KfZsYtO$v;QuD# zbv19J+6-S?V4bal_VL+K`Rnl=KI<++>ygeTvA-9qm%8Ay?vVZo-ko8+_!ZX={BDA2 z(Cxd6xcc>w58r$Bd;5B*<0sLF(hr98+af(5$qpMYbeOEt3s)M`g6u>#AYbQ~W*Ou{ z{o?Fec zlG%Jonz7_IIsM_udw)NY9X5_N?{OdO<&K_W&J*7Mb9r%_KsEEFc+pc)wR4m&nYXfF dWheeBz01lX^-;Vm7uxu0D>qw-6JEX$`9Ha#9tHpa diff --git a/spring-boot-modules/spring-boot-mvc/src/main/resources/static/favicon.ico b/spring-boot-modules/spring-boot-mvc/src/main/resources/static/favicon.ico deleted file mode 100644 index 64105ac11c6186e380a724416ceb77ab5c263fef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15086 zcmeI33yf6N8OP5s)D;AFL7}u+*#$K|S}oXWX{A6BF!-qLwvyDOsBLZ4#$rp2QmZaB zDMc+H+EzuWwblBlHY$b~O&EM6N;Jr;Vo@0)La}NWK^bJ(>Fs!o&?#+$PV&lcoe<}Q{V*nJA~=Gv^RNwrqwUlyiXv{0{QS2SOqSBm|V^K zQLxvS?=`|#!l^JBRzeqq>8p;)yEgECA92~92j{^Ocmu-PBuDxspmqtCp>qEVFM;g6 z3&A`)Nb3(OYfs4gVE$lypKZf~(VYR$L6|Q=Js00EefOZN@uR+-2@ByKP=BkBcZ1V& za;MV`ljQFM^6k?gyLZAaaQZKV=~YTY?;z0l>;SdzoJx5srK6LD`LGc*O%p%p9R+QP z6|Dlgn&*8KEf$U0H~|`r8OzLXW>yUXO|EuJ9@z;+0>uLCE$K;D6=;Qtp!LanwD8pF zL%lx*!{PIA@PT%dGLMJnL2J+?m5&?%=R+Heh0&mOOj7IG$)NNv!-;S-s1E&-`j3w4 ze*;$_%n#DP4jaI&`|AJo@DvQQK3qds^Eye{{=D+zeqa~w{*b0M zR(W3qW}MgW;|R}%kv6VAT?u}hX~JrYFZewm{*2G=D}>$H)B1k}oNImf8sV*wrd+?y z)7Ti{d?5T*z~&a>=YZD3X`uXPTOYnp*uPHu?IsD|j2-XPgVeqn)YVx26$}E6htuI$ z=m)c54+M3R#I@(TzV57GOMWc_&GAFvV)zbdzFY;nAxW9RytksSIj1=teCLnv;Qe)= zb~qBILNjQ;t7bg>3;iR&KmPpX2E$qd7QkdsUwjrOfz}JnuVDV3;_5@4Pt~85`XJ1P z#>Nw%K9~Y(mmfe5lJ?1BbkwHnA*`&ZG_6NkC)dDVKz($ljemfQ(sl1v*mvbDZk2$~y7?4-@x zRW95YplprFUxW6=G;=GiKOg#v?G~im3}}vj6Lbc79A1XE;C)CkXDj*hPPalMB9y1k z3)+Wu9+?PQi?t@tf!jfA!mAK>?#ZVO5kX$cp1^G4tk~}hZLk@FK5QjzOk$%c6ewpJYzz2sH}Qi~m`kNXS(kuY zm$grwk;+g?CCbwo<{?l&`~&)@G?iM7GS39v#f(dBqzXmK)%tNZB)&_lqS&%3^N>f>U?kt99_50 zhB$`5I&0nnn?UCU-Dj5f0>T4eGH4GS47y*`p6bnANsH35pnXpFH$q{h_3Avw{!hT| zCpweq>j&>4EIgEVC&504U$@;BuG_UxHy!leH5& z{a^{WbHN||wh5mKJALn6zBE#29i4;Lf!bgOe8#m`T#3#QIMn4QJOZ8t`Sc$c?|Y~7 zpxQT$zdh;f!|qy`1;bsLJxTKZ4AkZWTwcPbz!p%MkH8?`yNSemx}WID*QodUytxYW z8N<8pbY%x6?;BwS=uABq{PXp@#MQs*=UGmdu;$`oi1MKp?=((-0~K%BdG}S&7*Top z{G`5fcVJpCE`{e|K9uiD36Fv`Pzyh!Y^d$DE_ipYt___eUF(4Ve&9XgKLu9@tvLfh zYp2dx{yMY~?|`WCYw=EFLv{FAKal3mzW#DlhhG5SvXmaer-RyC>)&9dBGo?{b7~{M zes6@;#u`gryIQy8gFbtQm8bn{9(eN>sde>g*abI%H`kHc^X`Q(8?{c;eDLm!ef~%F zzt*$ALW^y0?Y9?!>ii?0jTYi7q1OI}+0(jSo(qKKV^}_an&z+etv;YJqy0f=h;iV3 z4};Wwy5C+>czgc^UvL=@^ogn2KcptH};1TUIh2RaW-u_TjMp&81nn?!d=+XJYNo1z!Vq>{a`FCfo-6C zPA9GW5E~bO*2G0Muovcs_VIP_H<$&Q_c{|UhL=F|sG7Pguyf#e>}-ZGA8MJlmonaj z7eVXTde{wV%Xm!w>%qpQAp2=;rPZsZ{nwVf_x#tor+HS5y|i^mtGCVhZ~H*&#oeEv zI_&oQZ|iU<{{J4_9Yor;IS_i?zUOmw!FR29I%jT%1K~&7GD5#6wEd95cdbje!@G4_ zk8ZywbnWk#_^mVlIJgDWAJy*FY1=wX?*qTDQDOYnxqlSQfTge+-iA1zAHvG6McTik ze6I8kpS5QX0iAW);BvSb9s-?%Ho#WU`A+LVZ>`DeEBTlv9Y6bm&eFQiJOWOHsqj7c zCFuOK0=7Uc_R3{x{7kEZ&sr1u!${CsNavu9kakYZPwPu9^zd8tIUIC`UjzFg?!3@v zqv^HqqZT&sr5Wae&fjtBpfmr+ez#Z)U((vZAFT`e%%HyLsSY}mN8atG^`lxn{5k^ef&EKUa3$A^-tpOIeN?2N_O$_+t3kGhpQ{;)KfZsYtO$v;QuD# zbv19J+6-S?V4bal_VL+K`Rnl=KI<++>ygeTvA-9qm%8Ay?vVZo-ko8+_!ZX={BDA2 z(Cxd6xcc>w58r$Bd;5B*<0sLF(hr98+af(5$qpMYbeOEt3s)M`g6u>#AYbQ~W*Ou{ z{o?Fec zlG%Jonz7_IIsM_udw)NY9X5_N?{OdO<&K_W&J*7Mb9r%_KsEEFc+pc)wR4m&nYXfF dWheeBz01lX^-;Vm7uxu0D>qw-6JEX$`9Ha#9tHpa From 5e97741b072cf19eec9e7c7e33ae4ebae2366f53 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Sat, 21 Mar 2020 11:29:55 -0600 Subject: [PATCH 188/278] Revert "BAEL-3069 Spring jdbcTemplate Unit Testing" This reverts commit d4a928cdfac363353c293a7f0b0abcd936a77919. --- .../spring-persistence-simple/pom.xml | 7 --- .../baeldung/jdbc/EmployeeDAOUnitTest.java | 49 ------------------- 2 files changed, 56 deletions(-) delete mode 100644 persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java diff --git a/persistence-modules/spring-persistence-simple/pom.xml b/persistence-modules/spring-persistence-simple/pom.xml index 45605c853e..8a03310048 100644 --- a/persistence-modules/spring-persistence-simple/pom.xml +++ b/persistence-modules/spring-persistence-simple/pom.xml @@ -92,12 +92,6 @@ ${org.springframework.version} test - - org.mockito - mockito-core - ${mockito.version} - test - com.querydsl querydsl-jpa @@ -143,7 +137,6 @@ 9.0.0.M26 1.1 4.2.1 - 3.3.3 21.0 diff --git a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java b/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java deleted file mode 100644 index 9894801a53..0000000000 --- a/persistence-modules/spring-persistence-simple/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.jdbc; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import javax.sql.DataSource; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import org.springframework.jdbc.core.JdbcTemplate; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; -import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; -import org.springframework.test.util.ReflectionTestUtils; - - -@RunWith(MockitoJUnitRunner.class) - -public class EmployeeDAOUnitTest { - - @Mock - JdbcTemplate jdbcTemplate; - - @Test - public void whenMockJdbcTemplate_thenReturnCorrectEmployeeCount() { - EmployeeDAO employeeDAO = new EmployeeDAO(); - ReflectionTestUtils.setField(employeeDAO, "jdbcTemplate", jdbcTemplate); - Mockito.when(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class)) - .thenReturn(4); - assertEquals(4, employeeDAO.getCountOfEmployees()); - - Mockito.when(jdbcTemplate.queryForObject(Mockito.anyString(), Mockito.eq(Integer.class))) - .thenReturn(3); - assertEquals(3, employeeDAO.getCountOfEmployees()); - } - - @Test - public void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() { - DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2) - .addScript("classpath:jdbc/schema.sql") - .addScript("classpath:jdbc/test-data.sql") - .build(); - EmployeeDAO employeeDAO = new EmployeeDAO(); - employeeDAO.setDataSource(dataSource); - assertEquals(4, employeeDAO.getCountOfEmployees()); - } - -} From c986147850ef773d8bfeb6cfac18256368adf683 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Sat, 21 Mar 2020 11:50:07 -0600 Subject: [PATCH 189/278] BAEL-3069 Spring jdbcTemplate Unit Testing. Create a new module for this article. --- .../spring-persistence-simple-1/.gitignore | 13 ++++ .../spring-persistence-simple-1/pom.xml | 60 +++++++++++++++++++ .../main/java/com/baeldung/jdbc/Employee.java | 44 ++++++++++++++ .../java/com/baeldung/jdbc/EmployeeDAO.java | 21 +++++++ .../src/main/resources/jdbc/schema.sql | 7 +++ .../src/main/resources/jdbc/test-data.sql | 4 ++ .../baeldung/jdbc/EmployeeDAOUnitTest.java | 47 +++++++++++++++ 7 files changed, 196 insertions(+) create mode 100644 persistence-modules/spring-persistence-simple-1/.gitignore create mode 100644 persistence-modules/spring-persistence-simple-1/pom.xml create mode 100644 persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/Employee.java create mode 100644 persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/EmployeeDAO.java create mode 100644 persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/schema.sql create mode 100644 persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/test-data.sql create mode 100644 persistence-modules/spring-persistence-simple-1/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java diff --git a/persistence-modules/spring-persistence-simple-1/.gitignore b/persistence-modules/spring-persistence-simple-1/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/persistence-modules/spring-persistence-simple-1/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/persistence-modules/spring-persistence-simple-1/pom.xml b/persistence-modules/spring-persistence-simple-1/pom.xml new file mode 100644 index 0000000000..a60db4b9e1 --- /dev/null +++ b/persistence-modules/spring-persistence-simple-1/pom.xml @@ -0,0 +1,60 @@ + + + 4.0.0 + spring-persistence-simple-1 + 0.1-SNAPSHOT + spring-persistence-simple-1 + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework + spring-context + ${org.springframework.version} + + + + + com.h2database + h2 + ${h2.version} + test + + + + + org.springframework + spring-test + ${org.springframework.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + + + + 5.2.4.RELEASE + + 1.4.200 + + 3.3.3 + + + \ No newline at end of file diff --git a/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/Employee.java new file mode 100644 index 0000000000..a43eb265c7 --- /dev/null +++ b/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/Employee.java @@ -0,0 +1,44 @@ +package com.baeldung.jdbc; + +public class Employee { + private int id; + + private String firstName; + + private String lastName; + + private String address; + + public int getId() { + return id; + } + + public void setId(final int id) { + this.id = id; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(final String firstName) { + this.firstName = firstName; + } + + public String getLastName() { + return lastName; + } + + public void setLastName(final String lastName) { + this.lastName = lastName; + } + + public String getAddress() { + return address; + } + + public void setAddress(final String address) { + this.address = address; + } + +} diff --git a/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/EmployeeDAO.java b/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/EmployeeDAO.java new file mode 100644 index 0000000000..a7adb7933a --- /dev/null +++ b/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/EmployeeDAO.java @@ -0,0 +1,21 @@ +package com.baeldung.jdbc; + +import javax.sql.DataSource; + +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Repository; + +@Repository +public class EmployeeDAO { + private JdbcTemplate jdbcTemplate; + + public void setDataSource(final DataSource dataSource) { + jdbcTemplate = new JdbcTemplate(dataSource); + } + + public int getCountOfEmployees() { + return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class); + } + + +} diff --git a/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/schema.sql b/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/schema.sql new file mode 100644 index 0000000000..3401c5d963 --- /dev/null +++ b/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/schema.sql @@ -0,0 +1,7 @@ +CREATE TABLE EMPLOYEE +( + ID int NOT NULL PRIMARY KEY, + FIRST_NAME varchar(255), + LAST_NAME varchar(255), + ADDRESS varchar(255) +); \ No newline at end of file diff --git a/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/test-data.sql b/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/test-data.sql new file mode 100644 index 0000000000..c1669c156d --- /dev/null +++ b/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/test-data.sql @@ -0,0 +1,4 @@ +INSERT INTO EMPLOYEE VALUES (1, 'James', 'Gosling', 'Canada'); +INSERT INTO EMPLOYEE VALUES (2, 'Donald', 'Knuth', 'USA'); +INSERT INTO EMPLOYEE VALUES (3, 'Linus', 'Torvalds', 'Finland'); +INSERT INTO EMPLOYEE VALUES (4, 'Dennis', 'Ritchie', 'USA'); \ No newline at end of file diff --git a/persistence-modules/spring-persistence-simple-1/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java b/persistence-modules/spring-persistence-simple-1/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java new file mode 100644 index 0000000000..a64ba9b2f0 --- /dev/null +++ b/persistence-modules/spring-persistence-simple-1/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java @@ -0,0 +1,47 @@ +package com.baeldung.jdbc; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import javax.sql.DataSource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; +import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType; +import org.springframework.test.util.ReflectionTestUtils; + + +@RunWith(MockitoJUnitRunner.class) + +public class EmployeeDAOUnitTest { + @Mock + JdbcTemplate jdbcTemplate; + + @Test + public void whenMockJdbcTemplate_thenReturnCorrectEmployeeCount() { + EmployeeDAO employeeDAO = new EmployeeDAO(); + ReflectionTestUtils.setField(employeeDAO, "jdbcTemplate", jdbcTemplate); + Mockito.when(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class)) + .thenReturn(4); + assertEquals(4, employeeDAO.getCountOfEmployees()); + + Mockito.when(jdbcTemplate.queryForObject(Mockito.anyString(), Mockito.eq(Integer.class))) + .thenReturn(3); + assertEquals(3, employeeDAO.getCountOfEmployees()); + } + + @Test + public void whenInjectInMemoryDataSource_thenReturnCorrectEmployeeCount() { + DataSource dataSource = new EmbeddedDatabaseBuilder().setType(EmbeddedDatabaseType.H2) + .addScript("classpath:jdbc/schema.sql") + .addScript("classpath:jdbc/test-data.sql") + .build(); + EmployeeDAO employeeDAO = new EmployeeDAO(); + employeeDAO.setDataSource(dataSource); + assertEquals(4, employeeDAO.getCountOfEmployees()); + } +} From 9f3c94929a1a761146e372c73a4c8dbd7fb4b6ec Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Sat, 21 Mar 2020 11:57:30 -0600 Subject: [PATCH 190/278] BAEL-3069 Rename the folder name to spring-persistence-simple-2 --- .../.gitignore | 0 .../pom.xml | 4 ++-- .../src/main/java/com/baeldung/jdbc/Employee.java | 0 .../src/main/java/com/baeldung/jdbc/EmployeeDAO.java | 0 .../src/main/resources/jdbc/schema.sql | 0 .../src/main/resources/jdbc/test-data.sql | 0 .../src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java | 0 7 files changed, 2 insertions(+), 2 deletions(-) rename persistence-modules/{spring-persistence-simple-1 => spring-persistence-simple-2}/.gitignore (100%) rename persistence-modules/{spring-persistence-simple-1 => spring-persistence-simple-2}/pom.xml (95%) rename persistence-modules/{spring-persistence-simple-1 => spring-persistence-simple-2}/src/main/java/com/baeldung/jdbc/Employee.java (100%) rename persistence-modules/{spring-persistence-simple-1 => spring-persistence-simple-2}/src/main/java/com/baeldung/jdbc/EmployeeDAO.java (100%) rename persistence-modules/{spring-persistence-simple-1 => spring-persistence-simple-2}/src/main/resources/jdbc/schema.sql (100%) rename persistence-modules/{spring-persistence-simple-1 => spring-persistence-simple-2}/src/main/resources/jdbc/test-data.sql (100%) rename persistence-modules/{spring-persistence-simple-1 => spring-persistence-simple-2}/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java (100%) diff --git a/persistence-modules/spring-persistence-simple-1/.gitignore b/persistence-modules/spring-persistence-simple-2/.gitignore similarity index 100% rename from persistence-modules/spring-persistence-simple-1/.gitignore rename to persistence-modules/spring-persistence-simple-2/.gitignore diff --git a/persistence-modules/spring-persistence-simple-1/pom.xml b/persistence-modules/spring-persistence-simple-2/pom.xml similarity index 95% rename from persistence-modules/spring-persistence-simple-1/pom.xml rename to persistence-modules/spring-persistence-simple-2/pom.xml index a60db4b9e1..8380d635de 100644 --- a/persistence-modules/spring-persistence-simple-1/pom.xml +++ b/persistence-modules/spring-persistence-simple-2/pom.xml @@ -2,9 +2,9 @@ 4.0.0 - spring-persistence-simple-1 + spring-persistence-simple-2 0.1-SNAPSHOT - spring-persistence-simple-1 + spring-persistence-simple-2 com.baeldung diff --git a/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/Employee.java b/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/Employee.java similarity index 100% rename from persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/Employee.java rename to persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/Employee.java diff --git a/persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/EmployeeDAO.java b/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java similarity index 100% rename from persistence-modules/spring-persistence-simple-1/src/main/java/com/baeldung/jdbc/EmployeeDAO.java rename to persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java diff --git a/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/schema.sql b/persistence-modules/spring-persistence-simple-2/src/main/resources/jdbc/schema.sql similarity index 100% rename from persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/schema.sql rename to persistence-modules/spring-persistence-simple-2/src/main/resources/jdbc/schema.sql diff --git a/persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/test-data.sql b/persistence-modules/spring-persistence-simple-2/src/main/resources/jdbc/test-data.sql similarity index 100% rename from persistence-modules/spring-persistence-simple-1/src/main/resources/jdbc/test-data.sql rename to persistence-modules/spring-persistence-simple-2/src/main/resources/jdbc/test-data.sql diff --git a/persistence-modules/spring-persistence-simple-1/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java b/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java similarity index 100% rename from persistence-modules/spring-persistence-simple-1/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java rename to persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java From 5c78f8891300821584b31748a41a17c40bbfb253 Mon Sep 17 00:00:00 2001 From: mikr Date: Sat, 21 Mar 2020 21:43:32 +0100 Subject: [PATCH 191/278] JAVA-877 Update redirect after login --- .../baeldung/spring/MyUserDetailsService.java | 32 +++++++++++++ .../baeldung/spring/SecSecurityConfig.java | 47 +++++++------------ 2 files changed, 50 insertions(+), 29 deletions(-) create mode 100644 spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/MyUserDetailsService.java diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/MyUserDetailsService.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/MyUserDetailsService.java new file mode 100644 index 0000000000..43eb39e927 --- /dev/null +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/MyUserDetailsService.java @@ -0,0 +1,32 @@ +package org.baeldung.spring; + +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.authority.SimpleGrantedAuthority; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.stereotype.Service; + +import javax.annotation.PostConstruct; +import java.util.*; + +@Service +public class MyUserDetailsService implements UserDetailsService { + + private Map roles = new HashMap<>(); + + @PostConstruct + public void init() { + roles.put("admin", new User("admin", "{noop}admin1", getAuthority("ROLE_ADMIN"))); + roles.put("user", new User("user", "{noop}user1", getAuthority("ROLE_USER"))); + } + + @Override + public UserDetails loadUserByUsername(String username) { + return roles.get(username); + } + + private List getAuthority(String role) { + return Collections.singletonList(new SimpleGrantedAuthority(role)); + } +} \ No newline at end of file diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java index ebe23950a7..fe00e6943b 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java @@ -1,11 +1,9 @@ package org.baeldung.spring; import org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; @@ -15,7 +13,7 @@ import org.springframework.security.web.authentication.AuthenticationSuccessHand //@ImportResource({ "classpath:webSecurityConfig.xml" }) @EnableWebSecurity public class SecSecurityConfig extends WebSecurityConfigurerAdapter { - + public SecSecurityConfig() { super(); } @@ -26,43 +24,34 @@ public class SecSecurityConfig extends WebSecurityConfigurerAdapter { return super.authenticationManagerBean(); } - @Autowired - public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - // @formatter:off - auth.inMemoryAuthentication() - .withUser("user1").password("{noop}user1Pass").roles("USER") - .and() - .withUser("admin1").password("{noop}admin1Pass").roles("ADMIN"); - // @formatter:on - } - @Override protected void configure(final HttpSecurity http) throws Exception { // @formatter:off - http.authorizeRequests() - .antMatchers("/anonymous*").anonymous() - .antMatchers("/login*").permitAll() - .anyRequest().authenticated() - + http + .authorizeRequests() + .antMatchers("/anonymous*").anonymous() + .antMatchers("/login*").permitAll() + .anyRequest().authenticated() + .and() .formLogin() - .loginPage("/login.html") - .loginProcessingUrl("/login") - .successHandler(myAuthenticationSuccessHandler()) - .failureUrl("/login.html?error=true") - + .loginPage("/login.html") + .loginProcessingUrl("/login") + .successHandler(myAuthenticationSuccessHandler()) + .failureUrl("/login.html?error=true") + .and() - .logout().deleteCookies("JSESSIONID") - + .logout().deleteCookies("JSESSIONID") + .and() - .rememberMe().key("uniqueAndSecret").tokenValiditySeconds(86400) - + .rememberMe().key("uniqueAndSecret").tokenValiditySeconds(86400) + .and() - .csrf().disable() + .csrf().disable() ; // @formatter:on } - + @Bean public AuthenticationSuccessHandler myAuthenticationSuccessHandler(){ return new MySimpleUrlAuthenticationSuccessHandler(); From ee8d7adb8eacbaef4dcff5fda9db9208158455de Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 22 Mar 2020 07:24:38 +0530 Subject: [PATCH 192/278] formatted pom.xml file --- aws-reactive/pom.xml | 11 +-- .../pom.xml | 82 ++++++++-------- core-kotlin-modules/pom.xml | 6 +- core-scala/pom.xml | 7 +- couchbase/pom.xml | 6 +- custom-pmd/pom.xml | 6 +- dagger/pom.xml | 8 +- data-structures/pom.xml | 6 +- ddd-modules/infrastructure/pom.xml | 6 +- ddd-modules/mainapp/pom.xml | 6 +- ddd-modules/ordercontext/pom.xml | 6 +- ddd-modules/pom.xml | 6 +- ddd-modules/sharedkernel/pom.xml | 6 +- ddd-modules/shippingcontext/pom.xml | 6 +- ddd/pom.xml | 12 ++- deeplearning4j/pom.xml | 6 +- disruptor/pom.xml | 6 +- dozer/pom.xml | 6 +- drools/pom.xml | 6 +- dropwizard/pom.xml | 10 +- dubbo/pom.xml | 6 +- ethereum/pom.xml | 6 +- feign/pom.xml | 6 +- flyway-cdi-extension/pom.xml | 7 +- geotools/pom.xml | 7 +- google-cloud/pom.xml | 6 +- google-web-toolkit/pom.xml | 18 ++-- graphql/graphql-java/pom.xml | 6 +- grpc/pom.xml | 6 +- gson/pom.xml | 7 +- guava-collections/pom.xml | 6 +- guava/pom.xml | 6 +- guice/pom.xml | 6 +- hazelcast/pom.xml | 8 +- .../app-auth-form-store-ldap/pom.xml | 15 +-- machine-learning/pom.xml | 40 ++++---- .../maven-custom-plugin/usage-example/pom.xml | 17 ++-- .../resources/archetype-resources/pom.xml | 30 +++--- .../userdaomodule/pom.xml | 16 ++-- ninja/pom.xml | 96 ++++++++++--------- .../spring-boot-springdoc/pom.xml | 17 ++-- .../spring-zuul-post-filter/pom.xml | 14 +-- 42 files changed, 314 insertions(+), 246 deletions(-) diff --git a/aws-reactive/pom.xml b/aws-reactive/pom.xml index 950b3f373a..d4f0e5e231 100644 --- a/aws-reactive/pom.xml +++ b/aws-reactive/pom.xml @@ -16,12 +16,6 @@ aws-reactive AWS Reactive Sample - - 1.8 - 2.2.1.RELEASE - 2.10.27 - - @@ -105,4 +99,9 @@
+ + 1.8 + 2.2.1.RELEASE + 2.10.27 + diff --git a/core-java-modules/core-java-concurrency-collections-2/pom.xml b/core-java-modules/core-java-concurrency-collections-2/pom.xml index 0e5310b9da..65a91c9a9c 100644 --- a/core-java-modules/core-java-concurrency-collections-2/pom.xml +++ b/core-java-modules/core-java-concurrency-collections-2/pom.xml @@ -1,43 +1,47 @@ - - 4.0.0 - com.baeldung.concurrent.lock - core-java-concurrency-collections-2 - 0.0.1-SNAPSHOT + + 4.0.0 + com.baeldung.concurrent.lock + core-java-concurrency-collections-2 + 0.0.1-SNAPSHOT - - 1.21 - 28.2-jre - + + + com.google.guava + guava + ${guava.version} + + + org.openjdk.jmh + jmh-core + ${jmh.version} + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + - - - com.google.guava - guava - ${guava.version} - - - org.openjdk.jmh - jmh-core - ${jmh.version} - - - org.openjdk.jmh - jmh-generator-annprocess - ${jmh.version} - + + + src + + + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + + + + 1.21 + 28.2-jre + - - - src - - - maven-compiler-plugin - 3.8.0 - - 1.8 - 1.8 - - - - \ No newline at end of file diff --git a/core-kotlin-modules/pom.xml b/core-kotlin-modules/pom.xml index 24bdc189be..de41aecf73 100644 --- a/core-kotlin-modules/pom.xml +++ b/core-kotlin-modules/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.core-kotlin-modules core-kotlin-modules diff --git a/core-scala/pom.xml b/core-scala/pom.xml index d72727dd39..f6d61da1c3 100644 --- a/core-scala/pom.xml +++ b/core-scala/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 core-scala 1.0-SNAPSHOT @@ -52,4 +54,3 @@ 3.3.2 - diff --git a/couchbase/pom.xml b/couchbase/pom.xml index f4e98b32ba..34e2832e55 100644 --- a/couchbase/pom.xml +++ b/couchbase/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 couchbase 0.1-SNAPSHOT diff --git a/custom-pmd/pom.xml b/custom-pmd/pom.xml index a011b6a121..e0f38199ec 100644 --- a/custom-pmd/pom.xml +++ b/custom-pmd/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.pmd custom-pmd diff --git a/dagger/pom.xml b/dagger/pom.xml index 528a5383c6..e9410ceb63 100644 --- a/dagger/pom.xml +++ b/dagger/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 dagger dagger @@ -44,4 +46,4 @@ 2.16 - \ No newline at end of file + diff --git a/data-structures/pom.xml b/data-structures/pom.xml index 4468f3d21f..e2d2e23090 100644 --- a/data-structures/pom.xml +++ b/data-structures/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 data-structures 0.0.1-SNAPSHOT diff --git a/ddd-modules/infrastructure/pom.xml b/ddd-modules/infrastructure/pom.xml index 72ec263745..c301eaa92a 100644 --- a/ddd-modules/infrastructure/pom.xml +++ b/ddd-modules/infrastructure/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.dddmodules.infrastructure infrastructure diff --git a/ddd-modules/mainapp/pom.xml b/ddd-modules/mainapp/pom.xml index ae1057f307..a048263d37 100644 --- a/ddd-modules/mainapp/pom.xml +++ b/ddd-modules/mainapp/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.dddmodules.mainapp mainapp diff --git a/ddd-modules/ordercontext/pom.xml b/ddd-modules/ordercontext/pom.xml index 6a921d2408..abd166fb69 100644 --- a/ddd-modules/ordercontext/pom.xml +++ b/ddd-modules/ordercontext/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.dddmodules.ordercontext ordercontext diff --git a/ddd-modules/pom.xml b/ddd-modules/pom.xml index 65bc204988..38e48ff27d 100644 --- a/ddd-modules/pom.xml +++ b/ddd-modules/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.dddmodules dddmodules diff --git a/ddd-modules/sharedkernel/pom.xml b/ddd-modules/sharedkernel/pom.xml index 3b5d8bb71f..a61f03a494 100644 --- a/ddd-modules/sharedkernel/pom.xml +++ b/ddd-modules/sharedkernel/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.dddmodules.sharedkernel sharedkernel diff --git a/ddd-modules/shippingcontext/pom.xml b/ddd-modules/shippingcontext/pom.xml index 060f4fe5bf..2096923f90 100644 --- a/ddd-modules/shippingcontext/pom.xml +++ b/ddd-modules/shippingcontext/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.dddmodules.shippingcontext shippingcontext diff --git a/ddd/pom.xml b/ddd/pom.xml index f27f1d24a9..7f3c417b71 100644 --- a/ddd/pom.xml +++ b/ddd/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.ddd ddd @@ -21,8 +23,8 @@ spring-boot-starter-data-mongodb - org.springframework.boot - spring-boot-starter-data-cassandra + org.springframework.boot + spring-boot-starter-data-cassandra org.junit.jupiter @@ -97,4 +99,4 @@ 2.0.6.RELEASE - \ No newline at end of file + diff --git a/deeplearning4j/pom.xml b/deeplearning4j/pom.xml index c143b86ff8..c8fa18cbd4 100644 --- a/deeplearning4j/pom.xml +++ b/deeplearning4j/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.deeplearning4j deeplearning4j diff --git a/disruptor/pom.xml b/disruptor/pom.xml index 94be78fad6..31fc28986b 100644 --- a/disruptor/pom.xml +++ b/disruptor/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 disruptor 0.1.0-SNAPSHOT diff --git a/dozer/pom.xml b/dozer/pom.xml index e307354603..0fdf7f6fba 100644 --- a/dozer/pom.xml +++ b/dozer/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 dozer 1.0 diff --git a/drools/pom.xml b/drools/pom.xml index b4421ff2e3..e0a7b52938 100644 --- a/drools/pom.xml +++ b/drools/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 drools drools diff --git a/dropwizard/pom.xml b/dropwizard/pom.xml index ddc9aa1949..c3e1a4e841 100644 --- a/dropwizard/pom.xml +++ b/dropwizard/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 dropwizard 0.0.1-SNAPSHOT @@ -48,8 +49,7 @@ - + com.baeldung.dropwizard.introduction.IntroductionApplication diff --git a/dubbo/pom.xml b/dubbo/pom.xml index 9a7aceb9e5..cca1b3a3d1 100644 --- a/dubbo/pom.xml +++ b/dubbo/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 dubbo dubbo diff --git a/ethereum/pom.xml b/ethereum/pom.xml index 8c7e4c8c4c..5953195123 100644 --- a/ethereum/pom.xml +++ b/ethereum/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.ethereum ethereum diff --git a/feign/pom.xml b/feign/pom.xml index 6dc8e7bafa..4b994be1f2 100644 --- a/feign/pom.xml +++ b/feign/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.feign feign diff --git a/flyway-cdi-extension/pom.xml b/flyway-cdi-extension/pom.xml index 8f7d058db7..566eed95d8 100644 --- a/flyway-cdi-extension/pom.xml +++ b/flyway-cdi-extension/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 flyway-cdi-extension 1.0-SNAPSHOT diff --git a/geotools/pom.xml b/geotools/pom.xml index 71489bdf94..46913daa69 100644 --- a/geotools/pom.xml +++ b/geotools/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 geotools 0.0.1-SNAPSHOT diff --git a/google-cloud/pom.xml b/google-cloud/pom.xml index 15f7f5c824..1e474b5dd0 100644 --- a/google-cloud/pom.xml +++ b/google-cloud/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 google-cloud 0.1-SNAPSHOT diff --git a/google-web-toolkit/pom.xml b/google-web-toolkit/pom.xml index 37e423b3af..6fdcae4f75 100644 --- a/google-web-toolkit/pom.xml +++ b/google-web-toolkit/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 google-web-toolkit @@ -53,8 +54,7 @@ - + ${project.build.directory}/${project.build.finalName}/WEB-INF/classes @@ -76,8 +76,7 @@ com.baeldung.Google_web_toolkit Google_web_toolkit true - + ${maven.compiler.source} @@ -109,9 +108,8 @@ - + 1.8 1.8 diff --git a/graphql/graphql-java/pom.xml b/graphql/graphql-java/pom.xml index 793a02458a..30bfbf555a 100644 --- a/graphql/graphql-java/pom.xml +++ b/graphql/graphql-java/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.graphql graphql-java diff --git a/grpc/pom.xml b/grpc/pom.xml index c7ae111da3..5e1c0bb28b 100644 --- a/grpc/pom.xml +++ b/grpc/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 grpc 0.0.1-SNAPSHOT diff --git a/gson/pom.xml b/gson/pom.xml index f2ed5509fa..0de9a6a533 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 gson 0.1-SNAPSHOT diff --git a/guava-collections/pom.xml b/guava-collections/pom.xml index 9002ac2b91..c6019362c5 100644 --- a/guava-collections/pom.xml +++ b/guava-collections/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 guava-collections 0.1.0-SNAPSHOT diff --git a/guava/pom.xml b/guava/pom.xml index 3f07b77b0b..df6d57bd09 100644 --- a/guava/pom.xml +++ b/guava/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 guava 0.1.0-SNAPSHOT diff --git a/guice/pom.xml b/guice/pom.xml index d119bbf78e..6bbad6dddc 100644 --- a/guice/pom.xml +++ b/guice/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.examples.guice guice diff --git a/hazelcast/pom.xml b/hazelcast/pom.xml index 10234bb81f..287542be33 100644 --- a/hazelcast/pom.xml +++ b/hazelcast/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 hazelcast 0.0.1-SNAPSHOT @@ -32,7 +34,7 @@ - + 0.6 diff --git a/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml b/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml index a2d9443d67..f8d19b5750 100644 --- a/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml +++ b/java-ee-8-security-api/app-auth-form-store-ldap/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 app-auth-form-store-ldap app-auth-form-store-ldap @@ -12,10 +13,6 @@ java-ee-8-security-api 1.0-SNAPSHOT - - - 4.0.4 - @@ -52,4 +49,8 @@ + + 4.0.4 + + diff --git a/machine-learning/pom.xml b/machine-learning/pom.xml index 24162b7b9c..99b7e33579 100644 --- a/machine-learning/pom.xml +++ b/machine-learning/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 machine-learning 1.0-SNAPSHOT @@ -13,23 +15,6 @@ 1.0.0-SNAPSHOT - - UTF-8 - 1.7 - 1.7 - 1.3.50 - 0.9.1 - 3.1.0 - 3.0.2 - 3.0.2 - 3.8.0 - 2.22.1 - 2.5.2 - 2.8.2 - 3.7.1 - 3.0.0 - - org.jetbrains.kotlin @@ -158,4 +143,21 @@ + + UTF-8 + 1.7 + 1.7 + 1.3.50 + 0.9.1 + 3.1.0 + 3.0.2 + 3.0.2 + 3.8.0 + 2.22.1 + 2.5.2 + 2.8.2 + 3.7.1 + 3.0.0 + + diff --git a/maven-all/maven-custom-plugin/usage-example/pom.xml b/maven-all/maven-custom-plugin/usage-example/pom.xml index bd2b16475e..ef6f08a3fb 100644 --- a/maven-all/maven-custom-plugin/usage-example/pom.xml +++ b/maven-all/maven-custom-plugin/usage-example/pom.xml @@ -1,18 +1,14 @@ - + 4.0.0 com.baeldung example 0.0.1-SNAPSHOT pom - - 3.9 - 4.12 - - org.apache.commons @@ -47,4 +43,9 @@ + + 3.9 + 4.12 + + diff --git a/maven-archetype/src/main/resources/archetype-resources/pom.xml b/maven-archetype/src/main/resources/archetype-resources/pom.xml index 2a73687e2c..fc568349bc 100644 --- a/maven-archetype/src/main/resources/archetype-resources/pom.xml +++ b/maven-archetype/src/main/resources/archetype-resources/pom.xml @@ -1,23 +1,13 @@ - + 4.0.0 ${groupId} ${artifactId} ${version} war - - UTF-8 - 1.8 - 1.8 - false - ${liberty-plugin-version} - 9080 - 9443 - 2.0 - 2.1 - - ${artifactId} @@ -80,4 +70,16 @@ + + UTF-8 + 1.8 + 1.8 + false + ${liberty-plugin-version} + 9080 + 9443 + 2.0 + 2.1 + + diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml index cfa59bdc39..cf6ea85cb5 100644 --- a/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml +++ b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 com.baeldung.userdaomodule userdaomodule @@ -14,11 +16,6 @@ 1.0 - - 1.0 - 1.0 - - com.baeldung.entitymodule @@ -37,4 +34,9 @@ + + 1.0 + 1.0 + + diff --git a/ninja/pom.xml b/ninja/pom.xml index afb1d509b8..9b80dc26c8 100644 --- a/ninja/pom.xml +++ b/ninja/pom.xml @@ -1,6 +1,8 @@ - + 4.0.0 ninja @@ -10,19 +12,34 @@ http://www.ninjaframework.org - - 6.5.0 - 9.4.18.v20190429 - 3.3.4 - 2.1.3 - 1.4.186 - 3.2 - 1.8 - 1.8 - 1.3.1 - 2.8.2 - 2.2 - + + + org.webjars + bootstrap + ${bootstrap.version} + + + org.webjars + jquery + ${jquery.version} + + + com.h2database + h2 + ${h2.version} + + + org.ninjaframework + ninja-standalone + ${ninja.version} + + + org.ninjaframework + ninja-test-utilities + ${ninja.version} + test + + @@ -131,10 +148,8 @@ - - + + ninja.standalone.NinjaJetty @@ -161,32 +176,19 @@
- - - org.webjars - bootstrap - ${bootstrap.version} - - - org.webjars - jquery - ${jquery.version} - - - com.h2database - h2 - ${h2.version} - - - org.ninjaframework - ninja-standalone - ${ninja.version} - - - org.ninjaframework - ninja-test-utilities - ${ninja.version} - test - - + + + 6.5.0 + 9.4.18.v20190429 + 3.3.4 + 2.1.3 + 1.4.186 + 3.2 + 1.8 + 1.8 + 1.3.1 + 2.8.2 + 2.2 + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-springdoc/pom.xml b/spring-boot-modules/spring-boot-springdoc/pom.xml index fd8a9e71ae..c99a9c2b24 100644 --- a/spring-boot-modules/spring-boot-springdoc/pom.xml +++ b/spring-boot-modules/spring-boot-springdoc/pom.xml @@ -1,7 +1,8 @@ - + 4.0.0 spring-boot-springdoc 0.0.1-SNAPSHOT @@ -16,11 +17,6 @@ ../../parent-boot-2 - - 1.8 - 1.2.32 - - org.springframework.boot @@ -63,6 +59,11 @@ + + 1.8 + 1.2.32 + + integration diff --git a/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml b/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml index c13aeb890e..8643309645 100644 --- a/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml +++ b/spring-cloud/spring-cloud-zuul/spring-zuul-post-filter/pom.xml @@ -1,7 +1,8 @@ - + spring-cloud-zuul com.baeldung.spring.cloud @@ -10,10 +11,6 @@ 4.0.0 spring-zuul-post-filter - - Hoxton.SR1 - - org.springframework.cloud @@ -21,5 +18,8 @@ + + Hoxton.SR1 + \ No newline at end of file From 73a571e395cf174dfa44e6355d6301bfc6a614dc Mon Sep 17 00:00:00 2001 From: maryarm <45322329+maryarm@users.noreply.github.com> Date: Sun, 22 Mar 2020 07:00:43 +0430 Subject: [PATCH 193/278] KTLN-18: Kotlin Microservice With Spring Boot (#8913) --- spring-reactive-kotlin/pom.xml | 87 +++++++++++++++++++ .../HealthTrackerApplication.kt | 11 +++ .../config/DBConfiguration.kt | 28 ++++++ .../controller/HealthRecordController.kt | 44 ++++++++++ .../controller/ProfileController.kt | 15 ++++ .../model/AverageHealthStatus.kt | 3 + .../bootmicroservice/model/HealthRecord.kt | 8 ++ .../bootmicroservice/model/Profile.kt | 8 ++ .../repository/HealthRecordRepository.kt | 13 +++ .../repository/ProfileRepository.kt | 8 ++ .../src/main/resources/application.yml | 1 + .../controller/ProfileControllerTest.kt | 51 +++++++++++ 12 files changed, 277 insertions(+) create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt create mode 100644 spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt create mode 100644 spring-reactive-kotlin/src/main/resources/application.yml create mode 100644 spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt diff --git a/spring-reactive-kotlin/pom.xml b/spring-reactive-kotlin/pom.xml index 3a693837df..cbb143f6ec 100644 --- a/spring-reactive-kotlin/pom.xml +++ b/spring-reactive-kotlin/pom.xml @@ -5,6 +5,7 @@ spring-reactive-kotlin spring-reactive-kotlin Demo project for Spring Boot + jar @@ -23,6 +24,18 @@ org.springframework.boot spring-boot-starter-webflux + + org.springframework.boot.experimental + spring-boot-starter-data-r2dbc + + + org.springframework.boot + spring-boot-starter-actuator + + + io.r2dbc + r2dbc-h2 + com.fasterxml.jackson.module jackson-module-kotlin @@ -38,21 +51,95 @@ reactor-test test + + + org.springframework.boot.experimental + spring-boot-test-autoconfigure-r2dbc + test + + + io.projectreactor + reactor-test + test + + + + + + org.springframework.boot.experimental + spring-boot-bom-r2dbc + 0.1.0.M3 + pom + import + + + + + src/main/kotlin + src/test/kotlin kotlin-maven-plugin + + + compile + compile + + compile + + + + test-compile + test-compile + + test-compile + + + org.jetbrains.kotlin ${kotlin.version} -Xjsr305=strict + 1.8 + + spring + jpa + + + + org.jetbrains.kotlin + kotlin-maven-allopen + ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-maven-noarg + ${kotlin.version} + + + + 1.8 + 1.3.70 + 2.2.5.RELEASE + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + + + diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt new file mode 100644 index 0000000000..c70057b5de --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/HealthTrackerApplication.kt @@ -0,0 +1,11 @@ +package com.baeldung.bootmicroservice + +import org.springframework.boot.autoconfigure.SpringBootApplication +import org.springframework.boot.runApplication + +@SpringBootApplication +class HealthTrackerApplication + +fun main(args: Array) { + runApplication(*args) +} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt new file mode 100644 index 0000000000..b14682cc5c --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/config/DBConfiguration.kt @@ -0,0 +1,28 @@ +package com.baeldung.bootmicroservice.config; + +import org.springframework.context.annotation.Configuration +import org.springframework.data.r2dbc.core.DatabaseClient + +@Configuration +class DBConfiguration(db: DatabaseClient) { + init { + val initDb = db.execute { + """ CREATE TABLE IF NOT EXISTS profile ( + id SERIAL PRIMARY KEY, + first_name VARCHAR(20) NOT NULL, + last_name VARCHAR(20) NOT NULL, + birth_date DATE NOT NULL + ); + CREATE TABLE IF NOT EXISTS health_record( + id SERIAL PRIMARY KEY, + profile_id LONG NOT NULL, + temperature DECIMAL NOT NULL, + blood_pressure DECIMAL NOT NULL, + heart_rate DECIMAL, + date DATE NOT NULL + ); + """ + } + initDb.then().subscribe() + } +} diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt new file mode 100644 index 0000000000..620f187b7b --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/HealthRecordController.kt @@ -0,0 +1,44 @@ +package com.baeldung.bootmicroservice.controller + +import com.baeldung.bootmicroservice.model.AverageHealthStatus +import com.baeldung.bootmicroservice.model.HealthRecord +import com.baeldung.bootmicroservice.repository.HealthRecordRepository +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController +import reactor.core.publisher.Mono + +@RestController +class HealthRecordController(val repository: HealthRecordRepository) { + + @PostMapping("/health/{profileId}/record") + fun storeHealthRecord(@PathVariable("profileId") profileId: Long, @RequestBody record: HealthRecord): Mono = + repository.save(HealthRecord(null + , profileId + , record.temperature + , record.bloodPressure + , record.heartRate + , record.date)) + + @GetMapping("/health/{profileId}/avg") + fun fetchHealthRecordAverage(@PathVariable("profileId") profileId: Long): Mono = + repository.findByProfileId(profileId) + .reduce( + AverageHealthStatus(0, 0.0, 0.0, 0.0) + , { s, r -> + AverageHealthStatus(s.cnt + 1 + , s.temperature + r.temperature + , s.bloodPressure + r.bloodPressure + , s.heartRate + r.heartRate + ) + } + ).map { s -> + AverageHealthStatus(s.cnt + , if (s.cnt != 0) s.temperature / s.cnt else 0.0 + , if (s.cnt != 0) s.bloodPressure / s.cnt else 0.0 + , if (s.cnt != 0) s.heartRate / s.cnt else 0.0) + } + +} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt new file mode 100644 index 0000000000..1dc3bcdc50 --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/controller/ProfileController.kt @@ -0,0 +1,15 @@ +package com.baeldung.bootmicroservice.controller + +import com.baeldung.bootmicroservice.model.Profile +import com.baeldung.bootmicroservice.repository.ProfileRepository +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController +import reactor.core.publisher.Mono + +@RestController +class ProfileController(val repository: ProfileRepository) { + + @PostMapping("/profile") + fun save(@RequestBody profile: Profile): Mono = repository.save(profile) +} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt new file mode 100644 index 0000000000..3141146b9c --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/AverageHealthStatus.kt @@ -0,0 +1,3 @@ +package com.baeldung.bootmicroservice.model; + +class AverageHealthStatus(var cnt: Int, var temperature: Double, var bloodPressure: Double, var heartRate: Double) diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt new file mode 100644 index 0000000000..71c534027f --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/HealthRecord.kt @@ -0,0 +1,8 @@ +package com.baeldung.bootmicroservice.model + +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Table +import java.time.LocalDate + +@Table +data class HealthRecord(@Id var id: Long?, var profileId: Long?, var temperature: Double, var bloodPressure: Double, var heartRate: Double, var date: LocalDate) \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt new file mode 100644 index 0000000000..cbb7e675ea --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/model/Profile.kt @@ -0,0 +1,8 @@ +package com.baeldung.bootmicroservice.model + +import org.springframework.data.annotation.Id +import org.springframework.data.relational.core.mapping.Table +import java.time.LocalDateTime + +@Table +data class Profile(@Id var id:Long?, var firstName : String, var lastName : String, var birthDate: LocalDateTime) \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt new file mode 100644 index 0000000000..8cc91f06e4 --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/HealthRecordRepository.kt @@ -0,0 +1,13 @@ +package com.baeldung.bootmicroservice.repository + +import com.baeldung.bootmicroservice.model.HealthRecord +import org.springframework.data.r2dbc.repository.Query +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository +import reactor.core.publisher.Flux + +@Repository +interface HealthRecordRepository: ReactiveCrudRepository { + @Query("select p.* from health_record p where p.profile_id = :profileId ") + fun findByProfileId(profileId: Long): Flux +} \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt new file mode 100644 index 0000000000..eee8c5fcbe --- /dev/null +++ b/spring-reactive-kotlin/src/main/kotlin/com/baeldung/bootmicroservice/repository/ProfileRepository.kt @@ -0,0 +1,8 @@ +package com.baeldung.bootmicroservice.repository + +import com.baeldung.bootmicroservice.model.Profile +import org.springframework.data.repository.reactive.ReactiveCrudRepository +import org.springframework.stereotype.Repository + +@Repository +interface ProfileRepository: ReactiveCrudRepository \ No newline at end of file diff --git a/spring-reactive-kotlin/src/main/resources/application.yml b/spring-reactive-kotlin/src/main/resources/application.yml new file mode 100644 index 0000000000..d75683f905 --- /dev/null +++ b/spring-reactive-kotlin/src/main/resources/application.yml @@ -0,0 +1 @@ +management.endpoints.web.exposure.include: health,metrics \ No newline at end of file diff --git a/spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt b/spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt new file mode 100644 index 0000000000..51481af3d7 --- /dev/null +++ b/spring-reactive-kotlin/src/test/kotlin/com/baeldung/bootmicroservice/controller/ProfileControllerTest.kt @@ -0,0 +1,51 @@ +package com.baeldung.bootmicroservice.controller; + +import com.baeldung.bootmicroservice.model.Profile +import com.fasterxml.jackson.databind.ObjectMapper +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.http.MediaType +import org.springframework.test.web.reactive.server.WebTestClient +import java.time.LocalDateTime + +@SpringBootTest +class ProfileControllerTest { + @Autowired + lateinit var controller: ProfileController + + @Autowired + lateinit var mapper: ObjectMapper ; + + lateinit var client: WebTestClient + lateinit var profile: String + + @BeforeEach + fun setup() { + client = WebTestClient.bindToController(controller).build() + profile = mapper.writeValueAsString(Profile(null, "kotlin", "reactive", LocalDateTime.now())) + } + + @Test + fun whenRequestProfile_thenStatusShouldBeOk() { + client.post() + .uri("/profile") + .contentType(MediaType.APPLICATION_JSON) + .bodyValue(profile) + .exchange() + .expectStatus().isOk + } + + @Test + fun whenRequestProfile_thenIdShouldBeNotNull() { + client.post() + .uri("/profile") + .contentType(MediaType.APPLICATION_JSON) + .bodyValue(profile) + .exchange() + .expectBody() + .jsonPath("$.id") + .isNotEmpty + } +} From c9569ac3a02e8c3f61a7827222e8c71625ea7582 Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Sun, 22 Mar 2020 08:09:36 +0530 Subject: [PATCH 194/278] BAEL-3909: Moved code to another module (#8931) --- .../core-java-string-operations-2/pom.xml | 6 ++++++ .../baeldung/pdf/base64/EncodeDecodeUnitTest.java | 0 .../src/test/resources/input.pdf | Bin pdf/pom.xml | 7 ------- 4 files changed, 6 insertions(+), 7 deletions(-) rename {pdf => core-java-modules/core-java-string-operations-2}/src/test/java/com/baeldung/pdf/base64/EncodeDecodeUnitTest.java (100%) rename {pdf => core-java-modules/core-java-string-operations-2}/src/test/resources/input.pdf (100%) diff --git a/core-java-modules/core-java-string-operations-2/pom.xml b/core-java-modules/core-java-string-operations-2/pom.xml index 079556712e..a00ae80f13 100644 --- a/core-java-modules/core-java-string-operations-2/pom.xml +++ b/core-java-modules/core-java-string-operations-2/pom.xml @@ -64,6 +64,11 @@ jmh-generator-annprocess ${jmh-generator.version} + + commons-codec + commons-codec + ${commons-codec.version} + org.assertj @@ -113,6 +118,7 @@ 6.0.2.Final 3.0.0 2.2.6 + 1.14 diff --git a/pdf/src/test/java/com/baeldung/pdf/base64/EncodeDecodeUnitTest.java b/core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/pdf/base64/EncodeDecodeUnitTest.java similarity index 100% rename from pdf/src/test/java/com/baeldung/pdf/base64/EncodeDecodeUnitTest.java rename to core-java-modules/core-java-string-operations-2/src/test/java/com/baeldung/pdf/base64/EncodeDecodeUnitTest.java diff --git a/pdf/src/test/resources/input.pdf b/core-java-modules/core-java-string-operations-2/src/test/resources/input.pdf similarity index 100% rename from pdf/src/test/resources/input.pdf rename to core-java-modules/core-java-string-operations-2/src/test/resources/input.pdf diff --git a/pdf/pom.xml b/pdf/pom.xml index 88836c5ce9..d148aa1670 100644 --- a/pdf/pom.xml +++ b/pdf/pom.xml @@ -13,12 +13,6 @@ - - commons-codec - commons-codec - ${commons-codec.version} - - org.apache.pdfbox pdfbox-tools @@ -86,7 +80,6 @@ 3.15 1.8 3.15 - 1.14 From 05e79680cfee68d6df3b8681fe9129bc3011b3e2 Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Sat, 21 Mar 2020 20:58:04 -0600 Subject: [PATCH 195/278] BAEL-3069 Remove git ignore file, add the new module name to the parent pom file. --- persistence-modules/pom.xml | 1 + .../spring-persistence-simple-2/.gitignore | 13 ------------- 2 files changed, 1 insertion(+), 13 deletions(-) delete mode 100644 persistence-modules/spring-persistence-simple-2/.gitignore diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 15b62d5d77..675f8270eb 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -69,6 +69,7 @@ spring-jpa spring-persistence-simple + spring-persistence-simple-2 diff --git a/persistence-modules/spring-persistence-simple-2/.gitignore b/persistence-modules/spring-persistence-simple-2/.gitignore deleted file mode 100644 index 83c05e60c8..0000000000 --- a/persistence-modules/spring-persistence-simple-2/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -*.class - -#folders# -/target -/neoDb* -/data -/src/main/webapp/WEB-INF/classes -*/META-INF/* - -# Packaged files # -*.jar -*.war -*.ear \ No newline at end of file From 2fa275119ce57a3f3319445d9e67fa9c615b0b1c Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 20:48:49 +0100 Subject: [PATCH 196/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-acl --- .../main/java/{org => com}/baeldung/acl/Application.java | 2 +- .../java/{org => com}/baeldung/acl/config/ACLContext.java | 2 +- .../acl/config/AclMethodSecurityConfiguration.java | 2 +- .../baeldung/acl/config/JPAPersistenceConfig.java | 8 ++++---- .../acl/persistence/dao/NoticeMessageRepository.java | 4 ++-- .../baeldung/acl/persistence/entity/NoticeMessage.java | 2 +- .../spring-security-acl/src/main/resources/acl-data.sql | 2 +- ....properties => com.baeldung.acl.datasource.properties} | 0 .../baeldung/acl/SpringACLIntegrationTest.java | 8 ++++---- .../src/test/java/org/baeldung/SpringContextTest.java | 2 +- 10 files changed, 16 insertions(+), 16 deletions(-) rename spring-security-modules/spring-security-acl/src/main/java/{org => com}/baeldung/acl/Application.java (91%) rename spring-security-modules/spring-security-acl/src/main/java/{org => com}/baeldung/acl/config/ACLContext.java (99%) rename spring-security-modules/spring-security-acl/src/main/java/{org => com}/baeldung/acl/config/AclMethodSecurityConfiguration.java (96%) rename spring-security-modules/spring-security-acl/src/main/java/{org => com}/baeldung/acl/config/JPAPersistenceConfig.java (66%) rename spring-security-modules/spring-security-acl/src/main/java/{org => com}/baeldung/acl/persistence/dao/NoticeMessageRepository.java (88%) rename spring-security-modules/spring-security-acl/src/main/java/{org => com}/baeldung/acl/persistence/entity/NoticeMessage.java (92%) rename spring-security-modules/spring-security-acl/src/main/resources/{org.baeldung.acl.datasource.properties => com.baeldung.acl.datasource.properties} (100%) rename spring-security-modules/spring-security-acl/src/test/java/{org => com}/baeldung/acl/SpringACLIntegrationTest.java (96%) diff --git a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/Application.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/Application.java similarity index 91% rename from spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/Application.java rename to spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/Application.java index 665ca64076..b18a3a6527 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/Application.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/Application.java @@ -1,4 +1,4 @@ -package org.baeldung.acl; +package com.baeldung.acl; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/ACLContext.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/ACLContext.java similarity index 99% rename from spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/ACLContext.java rename to spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/ACLContext.java index 337e745c3c..cb60ef1d45 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/ACLContext.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/ACLContext.java @@ -1,4 +1,4 @@ -package org.baeldung.acl.config; +package com.baeldung.acl.config; import javax.sql.DataSource; diff --git a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/AclMethodSecurityConfiguration.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/AclMethodSecurityConfiguration.java similarity index 96% rename from spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/AclMethodSecurityConfiguration.java rename to spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/AclMethodSecurityConfiguration.java index e503cb1a41..1a8788b906 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/AclMethodSecurityConfiguration.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/AclMethodSecurityConfiguration.java @@ -1,4 +1,4 @@ -package org.baeldung.acl.config; +package com.baeldung.acl.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/JPAPersistenceConfig.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/JPAPersistenceConfig.java similarity index 66% rename from spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/JPAPersistenceConfig.java rename to spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/JPAPersistenceConfig.java index 24d170e56c..5f7fff5ff3 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/config/JPAPersistenceConfig.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/config/JPAPersistenceConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.acl.config; +package com.baeldung.acl.config; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Configuration; @@ -8,9 +8,9 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; @Configuration @EnableTransactionManagement -@EnableJpaRepositories(basePackages = "org.baeldung.acl.persistence.dao") -@PropertySource("classpath:org.baeldung.acl.datasource.properties") -@EntityScan(basePackages={ "org.baeldung.acl.persistence.entity" }) +@EnableJpaRepositories(basePackages = "com.baeldung.acl.persistence.dao") +@PropertySource("classpath:com.baeldung.acl.datasource.properties") +@EntityScan(basePackages={ "com.baeldung.acl.persistence.entity" }) public class JPAPersistenceConfig { } diff --git a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/persistence/dao/NoticeMessageRepository.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/dao/NoticeMessageRepository.java similarity index 88% rename from spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/persistence/dao/NoticeMessageRepository.java rename to spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/dao/NoticeMessageRepository.java index 91a2af7d83..be1a0118fc 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/persistence/dao/NoticeMessageRepository.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/dao/NoticeMessageRepository.java @@ -1,8 +1,8 @@ -package org.baeldung.acl.persistence.dao; +package com.baeldung.acl.persistence.dao; import java.util.List; -import org.baeldung.acl.persistence.entity.NoticeMessage; +import com.baeldung.acl.persistence.entity.NoticeMessage; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.query.Param; import org.springframework.security.access.prepost.PostAuthorize; diff --git a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/persistence/entity/NoticeMessage.java b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/entity/NoticeMessage.java similarity index 92% rename from spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/persistence/entity/NoticeMessage.java rename to spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/entity/NoticeMessage.java index bd1e866f83..80c04146e4 100644 --- a/spring-security-modules/spring-security-acl/src/main/java/org/baeldung/acl/persistence/entity/NoticeMessage.java +++ b/spring-security-modules/spring-security-acl/src/main/java/com/baeldung/acl/persistence/entity/NoticeMessage.java @@ -1,4 +1,4 @@ -package org.baeldung.acl.persistence.entity; +package com.baeldung.acl.persistence.entity; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql b/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql index a4e0011834..3b48c83f3c 100644 --- a/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql +++ b/spring-security-modules/spring-security-acl/src/main/resources/acl-data.sql @@ -4,7 +4,7 @@ INSERT INTO acl_sid (id, principal, sid) VALUES (3, 0, 'ROLE_EDITOR'); INSERT INTO acl_class (id, class) VALUES -(1, 'org.baeldung.acl.persistence.entity.NoticeMessage'); +(1, 'com.baeldung.acl.persistence.entity.NoticeMessage'); INSERT INTO system_message(id,content) VALUES (1,'First Level Message'), diff --git a/spring-security-modules/spring-security-acl/src/main/resources/org.baeldung.acl.datasource.properties b/spring-security-modules/spring-security-acl/src/main/resources/com.baeldung.acl.datasource.properties similarity index 100% rename from spring-security-modules/spring-security-acl/src/main/resources/org.baeldung.acl.datasource.properties rename to spring-security-modules/spring-security-acl/src/main/resources/com.baeldung.acl.datasource.properties diff --git a/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/acl/SpringACLIntegrationTest.java b/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/acl/SpringACLIntegrationTest.java similarity index 96% rename from spring-security-modules/spring-security-acl/src/test/java/org/baeldung/acl/SpringACLIntegrationTest.java rename to spring-security-modules/spring-security-acl/src/test/java/com/baeldung/acl/SpringACLIntegrationTest.java index 1460d4f47b..dfdeafe059 100644 --- a/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/acl/SpringACLIntegrationTest.java +++ b/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/acl/SpringACLIntegrationTest.java @@ -1,12 +1,12 @@ -package org.baeldung.acl; +package com.baeldung.acl; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.util.List; -import org.baeldung.acl.persistence.dao.NoticeMessageRepository; -import org.baeldung.acl.persistence.entity.NoticeMessage; +import com.baeldung.acl.persistence.dao.NoticeMessageRepository; +import com.baeldung.acl.persistence.entity.NoticeMessage; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -39,7 +39,7 @@ public class SpringACLIntegrationTest extends AbstractJUnit4SpringContextTests{ private static String EDITTED_CONTENT = "EDITED"; @Configuration - @ComponentScan("org.baeldung.acl.*") + @ComponentScan("com.baeldung.acl.*") public static class SpringConfig { } diff --git a/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/SpringContextTest.java index 74f26e2e5a..6ecc431ddd 100644 --- a/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/SpringContextTest.java @@ -1,6 +1,6 @@ package org.baeldung; -import org.baeldung.acl.Application; +import com.baeldung.acl.Application; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; From a9360918bab6cdc03ddf05166b59e3288b649f27 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 20:50:18 +0100 Subject: [PATCH 197/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-angular --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-security-modules/spring-security-angular/server/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-security-modules/spring-security-angular/server/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-angular/server/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-security-modules/spring-security-angular/server/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-angular/server/src/test/java/com/baeldung/SpringContextTest.java index e61d512bca..49314c0575 100644 --- a/spring-security-modules/spring-security-angular/server/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-angular/server/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From bc90bba63518e4daa88e93b2f21d3934844a5665 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 20:51:39 +0100 Subject: [PATCH 198/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-cache-control --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-security-modules/spring-security-cache-control/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-security-modules/spring-security-cache-control/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-cache-control/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-security-modules/spring-security-cache-control/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-cache-control/src/test/java/com/baeldung/SpringContextTest.java index 8fbaa7169b..0cde5d829d 100644 --- a/spring-security-modules/spring-security-cache-control/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-cache-control/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 1d7aedeaad7e709453c846bcb2322c5f2ce49632 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 20:54:54 +0100 Subject: [PATCH 199/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-kerberos --- .../src/main/java/{org => com}/baeldung/Application.java | 2 +- .../java/{org => com}/baeldung/config/WebSecurityConfig.java | 4 ++-- .../baeldung/security/DummyUserDetailsService.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename spring-security-modules/spring-security-kerberos/src/main/java/{org => com}/baeldung/Application.java (92%) rename spring-security-modules/spring-security-kerberos/src/main/java/{org => com}/baeldung/config/WebSecurityConfig.java (97%) rename spring-security-modules/spring-security-kerberos/src/main/java/{org => com}/baeldung/security/DummyUserDetailsService.java (95%) diff --git a/spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/Application.java b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/Application.java similarity index 92% rename from spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/Application.java rename to spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/Application.java index 39c2b51356..37dbe7dab8 100644 --- a/spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/Application.java +++ b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/Application.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/config/WebSecurityConfig.java similarity index 97% rename from spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java rename to spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/config/WebSecurityConfig.java index 49a1cf0a8e..c1c206e5c9 100644 --- a/spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/config/WebSecurityConfig.java +++ b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/config/WebSecurityConfig.java @@ -1,6 +1,6 @@ -package org.baeldung.config; +package com.baeldung.config; -import org.baeldung.security.DummyUserDetailsService; +import com.baeldung.security.DummyUserDetailsService; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.FileSystemResource; diff --git a/spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/security/DummyUserDetailsService.java similarity index 95% rename from spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java rename to spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/security/DummyUserDetailsService.java index 10d71fca8f..6ddd6c8969 100644 --- a/spring-security-modules/spring-security-kerberos/src/main/java/org/baeldung/security/DummyUserDetailsService.java +++ b/spring-security-modules/spring-security-kerberos/src/main/java/com/baeldung/security/DummyUserDetailsService.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.core.userdetails.User; From d6e6e5a8cad28041a88fc5ed8e49fb480430acb3 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:01:20 +0100 Subject: [PATCH 200/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-ldap --- .../main/java/{org => com}/baeldung/SampleLDAPApplication.java | 2 +- .../java/{org => com}/baeldung/controller/MyController.java | 2 +- .../java/{org => com}/baeldung/security/SecurityConfig.java | 2 +- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) rename spring-security-modules/spring-security-ldap/src/main/java/{org => com}/baeldung/SampleLDAPApplication.java (98%) rename spring-security-modules/spring-security-ldap/src/main/java/{org => com}/baeldung/controller/MyController.java (98%) rename spring-security-modules/spring-security-ldap/src/main/java/{org => com}/baeldung/security/SecurityConfig.java (97%) rename spring-security-modules/spring-security-ldap/src/test/java/{org => com}/baeldung/SpringContextTest.java (85%) diff --git a/spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/SampleLDAPApplication.java b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/SampleLDAPApplication.java similarity index 98% rename from spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/SampleLDAPApplication.java rename to spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/SampleLDAPApplication.java index 5936aa30ef..ec585f2387 100644 --- a/spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/SampleLDAPApplication.java +++ b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/SampleLDAPApplication.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/controller/MyController.java b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/controller/MyController.java similarity index 98% rename from spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/controller/MyController.java rename to spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/controller/MyController.java index e347bd8633..7c746cfb31 100644 --- a/spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/controller/MyController.java +++ b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/controller/MyController.java @@ -1,4 +1,4 @@ -package org.baeldung.controller; +package com.baeldung.controller; import java.security.Principal; import java.util.Arrays; diff --git a/spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/security/SecurityConfig.java b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/security/SecurityConfig.java similarity index 97% rename from spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/security/SecurityConfig.java rename to spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/security/SecurityConfig.java index 0d444e36ff..a00cb02459 100644 --- a/spring-security-modules/spring-security-ldap/src/main/java/org/baeldung/security/SecurityConfig.java +++ b/spring-security-modules/spring-security-ldap/src/main/java/com/baeldung/security/SecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; diff --git a/spring-security-modules/spring-security-ldap/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-ldap/src/test/java/com/baeldung/SpringContextTest.java similarity index 85% rename from spring-security-modules/spring-security-ldap/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-ldap/src/test/java/com/baeldung/SpringContextTest.java index 30ba7671d8..a15ca31980 100644 --- a/spring-security-modules/spring-security-ldap/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-ldap/src/test/java/com/baeldung/SpringContextTest.java @@ -1,5 +1,6 @@ -package org.baeldung; +package com.baeldung; +import com.baeldung.SampleLDAPApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; From 15a48fcb7810c6d3f507e8e377915c5e01368489 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:06:42 +0100 Subject: [PATCH 201/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc-custom --- .../MySimpleUrlAuthenticationSuccessHandler.java | 2 +- .../java/{org => com}/baeldung/spring/MvcConfig.java | 8 ++++---- .../{org => com}/baeldung/spring/SecSecurityConfig.java | 5 +++-- .../baeldung/web/controller/BankController.java | 2 +- .../baeldung/web/controller/FooController.java | 4 ++-- .../baeldung/web/controller/LoginController.java | 2 +- .../baeldung/web/controller/PrintUserController.java | 2 +- .../src/main/java/{org => com}/baeldung/web/dto/Foo.java | 2 +- .../baeldung/web/interceptor/LoggerInterceptor.java | 2 +- .../web/interceptor/SessionTimerInterceptor.java | 2 +- .../baeldung/web/interceptor/UserInterceptor.java | 2 +- .../src/main/resources/webSecurityConfig.xml | 9 ++------- .../java/{org => com}/baeldung/SpringContextTest.java | 6 +++--- .../security/csrf/CsrfAbstractIntegrationTest.java | 4 ++-- .../security/csrf/CsrfDisabledIntegrationTest.java | 6 +++--- .../security/csrf/CsrfEnabledIntegrationTest.java | 6 +++--- .../baeldung/security/spring/ManualSecurityConfig.java | 2 +- .../security/spring/ManualSecurityIntegrationTest.java | 4 ++-- .../baeldung/security/spring/SecurityWithCsrfConfig.java | 2 +- .../security/spring/SecurityWithoutCsrfConfig.java | 2 +- .../interceptor/LoggerInterceptorIntegrationTest.java | 6 +++--- .../SessionTimerInterceptorIntegrationTest.java | 6 +++--- .../web/interceptor/UserInterceptorIntegrationTest.java | 6 +++--- 23 files changed, 44 insertions(+), 48 deletions(-) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/spring/MvcConfig.java (89%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/spring/SecSecurityConfig.java (92%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/controller/BankController.java (96%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/controller/FooController.java (96%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/controller/LoginController.java (97%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/controller/PrintUserController.java (95%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/dto/Foo.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/interceptor/LoggerInterceptor.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/interceptor/SessionTimerInterceptor.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/main/java/{org => com}/baeldung/web/interceptor/UserInterceptor.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/SpringContextTest.java (82%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/security/csrf/CsrfAbstractIntegrationTest.java (95%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/security/csrf/CsrfDisabledIntegrationTest.java (87%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/security/csrf/CsrfEnabledIntegrationTest.java (88%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/security/spring/ManualSecurityConfig.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/security/spring/ManualSecurityIntegrationTest.java (96%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/security/spring/SecurityWithCsrfConfig.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/security/spring/SecurityWithoutCsrfConfig.java (98%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java (91%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java (93%) rename spring-security-modules/spring-security-mvc-custom/src/test/java/{org => com}/baeldung/web/interceptor/UserInterceptorIntegrationTest.java (92%) diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java index 73c186cae3..728445952e 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; import java.util.Collection; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 89% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java index db6141d43e..fb54df155c 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java @@ -1,8 +1,8 @@ -package org.baeldung.spring; +package com.baeldung.spring; -import org.baeldung.web.interceptor.LoggerInterceptor; -import org.baeldung.web.interceptor.SessionTimerInterceptor; -import org.baeldung.web.interceptor.UserInterceptor; +import com.baeldung.web.interceptor.LoggerInterceptor; +import com.baeldung.web.interceptor.SessionTimerInterceptor; +import com.baeldung.web.interceptor.UserInterceptor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 92% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/SecSecurityConfig.java index fe00e6943b..9cee909ad4 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -1,6 +1,7 @@ -package org.baeldung.spring; +package com.baeldung.spring; -import org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler; +import com.baeldung.security.MySimpleUrlAuthenticationSuccessHandler; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.authentication.AuthenticationManager; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/BankController.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/BankController.java similarity index 96% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/BankController.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/BankController.java index 1a4322c611..c4bbde21f2 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/BankController.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/BankController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/FooController.java similarity index 96% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/FooController.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/FooController.java index 5a3c85d220..6f9268c976 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/FooController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; @@ -7,7 +7,7 @@ import java.util.List; import javax.servlet.http.HttpServletResponse; -import org.baeldung.web.dto.Foo; +import com.baeldung.web.dto.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.HttpStatus; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/LoginController.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/LoginController.java similarity index 97% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/LoginController.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/LoginController.java index 99bf345a41..8a823cdf7e 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/LoginController.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/LoginController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/PrintUserController.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/PrintUserController.java similarity index 95% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/PrintUserController.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/PrintUserController.java index 78f164c7f1..9623471f12 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/controller/PrintUserController.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/controller/PrintUserController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.springframework.security.core.context.SecurityContext; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/dto/Foo.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/dto/Foo.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/dto/Foo.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/dto/Foo.java index 02283e7df9..b349e75b72 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/dto/Foo.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/dto/Foo.java @@ -1,4 +1,4 @@ -package org.baeldung.web.dto; +package com.baeldung.web.dto; import java.io.Serializable; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/LoggerInterceptor.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/LoggerInterceptor.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java index 7c68d3e9c7..b54fda5a82 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/LoggerInterceptor.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/LoggerInterceptor.java @@ -1,4 +1,4 @@ -package org.baeldung.web.interceptor; +package com.baeldung.web.interceptor; import com.google.common.base.Strings; import org.slf4j.Logger; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/SessionTimerInterceptor.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/SessionTimerInterceptor.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java index 90199347b4..38e852305c 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/SessionTimerInterceptor.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/SessionTimerInterceptor.java @@ -1,4 +1,4 @@ -package org.baeldung.web.interceptor; +package com.baeldung.web.interceptor; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/UserInterceptor.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/UserInterceptor.java rename to spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java index 6b808d885e..cd64a20842 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/org/baeldung/web/interceptor/UserInterceptor.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/web/interceptor/UserInterceptor.java @@ -1,4 +1,4 @@ -package org.baeldung.web.interceptor; +package com.baeldung.web.interceptor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml index e79e14abeb..4853e6669b 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml +++ b/spring-security-modules/spring-security-mvc-custom/src/main/resources/webSecurityConfig.xml @@ -22,7 +22,7 @@ - + @@ -31,10 +31,5 @@ - - - - + ù \ No newline at end of file diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/SpringContextTest.java similarity index 82% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/SpringContextTest.java index 5ee80d856a..3a73503bca 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/SpringContextTest.java @@ -1,7 +1,7 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.spring.MvcConfig; -import org.baeldung.spring.SecSecurityConfig; +import com.baeldung.spring.MvcConfig; +import com.baeldung.spring.SecSecurityConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java similarity index 95% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java index 44424bf7f9..97972b7358 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfAbstractIntegrationTest.java @@ -1,11 +1,11 @@ -package org.baeldung.security.csrf; +package com.baeldung.security.csrf; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user; import javax.servlet.Filter; -import org.baeldung.web.dto.Foo; +import com.baeldung.web.dto.Foo; import org.junit.Before; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfDisabledIntegrationTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java similarity index 87% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfDisabledIntegrationTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java index 1d16e08514..a1c8be9daf 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfDisabledIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfDisabledIntegrationTest.java @@ -1,10 +1,10 @@ -package org.baeldung.security.csrf; +package com.baeldung.security.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.baeldung.security.spring.SecurityWithoutCsrfConfig; -import org.baeldung.spring.MvcConfig; +import com.baeldung.security.spring.SecurityWithoutCsrfConfig; +import com.baeldung.spring.MvcConfig; import org.junit.Test; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfEnabledIntegrationTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java similarity index 88% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfEnabledIntegrationTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java index 9d882973bd..87e5005e17 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/csrf/CsrfEnabledIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/csrf/CsrfEnabledIntegrationTest.java @@ -1,11 +1,11 @@ -package org.baeldung.security.csrf; +package com.baeldung.security.csrf; import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.csrf; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.baeldung.security.spring.SecurityWithCsrfConfig; -import org.baeldung.spring.MvcConfig; +import com.baeldung.security.spring.SecurityWithCsrfConfig; +import com.baeldung.spring.MvcConfig; import org.junit.Test; import org.springframework.http.MediaType; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityConfig.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityConfig.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java index 23d13a0ff1..438cec38bb 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.security.spring; +package com.baeldung.security.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityIntegrationTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java similarity index 96% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityIntegrationTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java index afc86bd74c..002ba8df3e 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/ManualSecurityIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/ManualSecurityIntegrationTest.java @@ -1,11 +1,11 @@ -package org.baeldung.security.spring; +package com.baeldung.security.spring; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import javax.servlet.http.HttpSession; -import org.baeldung.spring.MvcConfig; +import com.baeldung.spring.MvcConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/SecurityWithCsrfConfig.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/SecurityWithCsrfConfig.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java index ca401622c0..9b3ac50546 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/SecurityWithCsrfConfig.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithCsrfConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.security.spring; +package com.baeldung.security.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/SecurityWithoutCsrfConfig.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java similarity index 98% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/SecurityWithoutCsrfConfig.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java index 1067c70fea..4a1263b498 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/security/spring/SecurityWithoutCsrfConfig.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/security/spring/SecurityWithoutCsrfConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.security.spring; +package com.baeldung.security.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java similarity index 91% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java index c33c9a04e8..9e850861bf 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/LoggerInterceptorIntegrationTest.java @@ -1,10 +1,10 @@ -package org.baeldung.web.interceptor; +package com.baeldung.web.interceptor; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.baeldung.security.spring.SecurityWithoutCsrfConfig; -import org.baeldung.spring.MvcConfig; +import com.baeldung.security.spring.SecurityWithoutCsrfConfig; +import com.baeldung.spring.MvcConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java similarity index 93% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java index bdc1be2c44..07bc22f184 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/SessionTimerInterceptorIntegrationTest.java @@ -1,12 +1,12 @@ -package org.baeldung.web.interceptor; +package com.baeldung.web.interceptor; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import javax.servlet.http.HttpSession; -import org.baeldung.security.spring.SecurityWithoutCsrfConfig; -import org.baeldung.spring.MvcConfig; +import com.baeldung.security.spring.SecurityWithoutCsrfConfig; +import com.baeldung.spring.MvcConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/UserInterceptorIntegrationTest.java b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java similarity index 92% rename from spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/UserInterceptorIntegrationTest.java rename to spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java index a85fd999a6..b7547cb23a 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/test/java/org/baeldung/web/interceptor/UserInterceptorIntegrationTest.java +++ b/spring-security-modules/spring-security-mvc-custom/src/test/java/com/baeldung/web/interceptor/UserInterceptorIntegrationTest.java @@ -1,10 +1,10 @@ -package org.baeldung.web.interceptor; +package com.baeldung.web.interceptor; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import org.baeldung.security.spring.SecurityWithoutCsrfConfig; -import org.baeldung.spring.MvcConfig; +import com.baeldung.security.spring.SecurityWithoutCsrfConfig; +import com.baeldung.spring.MvcConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; From d1a28cbd6a9ed17a96852de66d4de7cd23e38a02 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:38:14 +0100 Subject: [PATCH 202/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-acl (finalized) --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-security-modules/spring-security-acl/src/test/java/{org => com}/baeldung/SpringContextTest.java (94%) diff --git a/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/SpringContextTest.java similarity index 94% rename from spring-security-modules/spring-security-acl/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-acl/src/test/java/com/baeldung/SpringContextTest.java index 6ecc431ddd..e60983733e 100644 --- a/spring-security-modules/spring-security-acl/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-acl/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import com.baeldung.acl.Application; import org.junit.Test; From c1b2f97a53227fa3a993e072a60a9922de96a8d4 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:39:57 +0100 Subject: [PATCH 203/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc-custom (finalized) --- .../src/main/java/com/baeldung/spring/MvcConfig.java | 2 +- .../spring-security-mvc-custom/src/main/webapp/WEB-INF/web.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java index fb54df155c..583825a66a 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java +++ b/spring-security-modules/spring-security-mvc-custom/src/main/java/com/baeldung/spring/MvcConfig.java @@ -16,7 +16,7 @@ import org.springframework.web.servlet.view.JstlView; @EnableWebMvc @Configuration -@ComponentScan("org.baeldung.web.controller") +@ComponentScan("com.baeldung.web.controller") public class MvcConfig implements WebMvcConfigurer { public MvcConfig() { diff --git a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/web.xml index e805828809..61fd248f53 100644 --- a/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-mvc-custom/src/main/webapp/WEB-INF/web.xml @@ -20,7 +20,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring From ead60ef1f78543b60fa3002439cf984ec90dbec4 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:11:07 +0100 Subject: [PATCH 204/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc-digest-auth --- .../baeldung/basic/MyBasicAuthenticationEntryPoint.java | 2 +- .../HttpComponentsClientHttpRequestFactoryDigestAuth.java | 2 +- .../java/{org => com}/baeldung/spring/ClientConfig.java | 4 ++-- .../main/java/{org => com}/baeldung/spring/MvcConfig.java | 2 +- .../{org => com}/baeldung/spring/SecSecurityConfig.java | 2 +- .../java/{org => com}/baeldung/SpringContextTest.java | 8 ++++---- .../{org => com}/baeldung/client/RawClientLiveTest.java | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) rename spring-security-modules/spring-security-mvc-digest-auth/src/main/java/{org => com}/baeldung/basic/MyBasicAuthenticationEntryPoint.java (97%) rename spring-security-modules/spring-security-mvc-digest-auth/src/main/java/{org => com}/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java (98%) rename spring-security-modules/spring-security-mvc-digest-auth/src/main/java/{org => com}/baeldung/spring/ClientConfig.java (94%) rename spring-security-modules/spring-security-mvc-digest-auth/src/main/java/{org => com}/baeldung/spring/MvcConfig.java (97%) rename spring-security-modules/spring-security-mvc-digest-auth/src/main/java/{org => com}/baeldung/spring/SecSecurityConfig.java (93%) rename spring-security-modules/spring-security-mvc-digest-auth/src/test/java/{org => com}/baeldung/SpringContextTest.java (78%) rename spring-security-modules/spring-security-mvc-digest-auth/src/test/java/{org => com}/baeldung/client/RawClientLiveTest.java (94%) diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/basic/MyBasicAuthenticationEntryPoint.java b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java similarity index 97% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/basic/MyBasicAuthenticationEntryPoint.java rename to spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java index c51c0a0bc8..1b9ffc3db8 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/basic/MyBasicAuthenticationEntryPoint.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package org.baeldung.basic; +package com.baeldung.basic; import java.io.IOException; import java.io.PrintWriter; diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java similarity index 98% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java rename to spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java index 1e6f213305..67c2d6031f 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryDigestAuth.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package com.baeldung.client; import org.apache.http.HttpHost; import org.apache.http.client.AuthCache; diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/ClientConfig.java b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/ClientConfig.java similarity index 94% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/ClientConfig.java rename to spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/ClientConfig.java index f305321f13..b7145daaea 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/ClientConfig.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/ClientConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.apache.http.HttpHost; import org.apache.http.auth.AuthScope; @@ -7,7 +7,7 @@ import org.apache.http.client.CredentialsProvider; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.baeldung.client.HttpComponentsClientHttpRequestFactoryDigestAuth; +import com.baeldung.client.HttpComponentsClientHttpRequestFactoryDigestAuth; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 97% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/MvcConfig.java index 74c11478ee..0d9962cda0 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/MvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 93% rename from spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java index 4ce80dab9f..cddef4d508 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/SpringContextTest.java similarity index 78% rename from spring-security-modules/spring-security-mvc-digest-auth/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/SpringContextTest.java index cd2b796308..080935c8c1 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/SpringContextTest.java @@ -1,8 +1,8 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.spring.ClientConfig; -import org.baeldung.spring.MvcConfig; -import org.baeldung.spring.SecSecurityConfig; +import com.baeldung.spring.ClientConfig; +import com.baeldung.spring.MvcConfig; +import com.baeldung.spring.SecSecurityConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/org/baeldung/client/RawClientLiveTest.java b/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/client/RawClientLiveTest.java similarity index 94% rename from spring-security-modules/spring-security-mvc-digest-auth/src/test/java/org/baeldung/client/RawClientLiveTest.java rename to spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/client/RawClientLiveTest.java index e8dcf82ebc..de6dca3ec4 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/org/baeldung/client/RawClientLiveTest.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/test/java/com/baeldung/client/RawClientLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package com.baeldung.client; import java.io.IOException; @@ -6,7 +6,7 @@ import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.baeldung.spring.ClientConfig; +import com.baeldung.spring.ClientConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; From 56c6d78bd55ef43eddc1e31337e5fe0bbc286574 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:16:32 +0100 Subject: [PATCH 205/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc-persisted-remember-me --- .../{org => com}/baeldung/controller/MyController.java | 2 +- .../security/MySimpleUrlAuthenticationSuccessHandler.java | 2 +- .../java/{org => com}/baeldung/security/SecurityRole.java | 2 +- .../security/SecurityWebApplicationInitializer.java | 2 +- .../baeldung/service/MyUserDetailsService.java | 4 ++-- .../main/java/{org => com}/baeldung/spring/MvcConfig.java | 4 ++-- .../{org => com}/baeldung/spring/PersistenceConfig.java | 2 +- .../java/{org => com}/baeldung/spring/SecurityConfig.java | 2 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- .../java/{org => com}/baeldung/SpringContextTest.java | 8 ++++---- 10 files changed, 15 insertions(+), 15 deletions(-) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/controller/MyController.java (96%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java (99%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/security/SecurityRole.java (78%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/security/SecurityWebApplicationInitializer.java (90%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/service/MyUserDetailsService.java (96%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/spring/MvcConfig.java (95%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/spring/PersistenceConfig.java (97%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/{org => com}/baeldung/spring/SecurityConfig.java (95%) rename spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/{org => com}/baeldung/SpringContextTest.java (78%) diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/controller/MyController.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/controller/MyController.java similarity index 96% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/controller/MyController.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/controller/MyController.java index 51202225ee..0ef07a2c19 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/controller/MyController.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/controller/MyController.java @@ -1,4 +1,4 @@ -package org.baeldung.controller; +package com.baeldung.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java similarity index 99% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java index 22fd2cdcb6..5d3c59be11 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/MySimpleUrlAuthenticationSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; import java.util.Collection; diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/SecurityRole.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityRole.java similarity index 78% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/SecurityRole.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityRole.java index e41e7a4c4f..ffe385996d 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/SecurityRole.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityRole.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; /** * Simple enum of Security Roles available. diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/SecurityWebApplicationInitializer.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java similarity index 90% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/SecurityWebApplicationInitializer.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java index 75f782e7dc..98eb4cd41c 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/security/SecurityWebApplicationInitializer.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/service/MyUserDetailsService.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/service/MyUserDetailsService.java similarity index 96% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/service/MyUserDetailsService.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/service/MyUserDetailsService.java index e6c77110b3..34782bdfab 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/service/MyUserDetailsService.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/service/MyUserDetailsService.java @@ -1,8 +1,8 @@ -package org.baeldung.service; +package com.baeldung.service; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.baeldung.security.SecurityRole; +import com.baeldung.security.SecurityRole; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.User; diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 95% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/MvcConfig.java index d4e0c55004..6fa3b522e7 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/MvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -14,7 +14,7 @@ import org.springframework.web.servlet.view.JstlView; * Spring Web Configuration. */ @EnableWebMvc -@ComponentScan("org.baeldung") +@ComponentScan("com.baeldung") @Configuration public class MvcConfig extends WebMvcConfigurerAdapter { diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/PersistenceConfig.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/PersistenceConfig.java similarity index 97% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/PersistenceConfig.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/PersistenceConfig.java index 02308e64fb..fe7b82b63d 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/PersistenceConfig.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/PersistenceConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import javax.sql.DataSource; diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/SecurityConfig.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/SecurityConfig.java similarity index 95% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/SecurityConfig.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/SecurityConfig.java index 2d9bb8e731..d3cfff81cb 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/org/baeldung/spring/SecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/java/com/baeldung/spring/SecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/web.xml index aa52205420..11b922a801 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/main/webapp/WEB-INF/web.xml @@ -19,7 +19,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring diff --git a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/com/baeldung/SpringContextTest.java similarity index 78% rename from spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/com/baeldung/SpringContextTest.java index 8113ed0fbe..bf4951c83a 100644 --- a/spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-mvc-persisted-remember-me/src/test/java/com/baeldung/SpringContextTest.java @@ -1,8 +1,8 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.spring.MvcConfig; -import org.baeldung.spring.PersistenceConfig; -import org.baeldung.spring.SecurityConfig; +import com.baeldung.spring.MvcConfig; +import com.baeldung.spring.PersistenceConfig; +import com.baeldung.spring.SecurityConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; From 833355f08d23f8c2ffc2f02999a8d54c2db88a19 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:18:03 +0100 Subject: [PATCH 206/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc-socket --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename spring-security-modules/spring-security-mvc-socket/src/test/java/{org => com}/baeldung/SpringContextTest.java (97%) diff --git a/spring-security-modules/spring-security-mvc-socket/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-mvc-socket/src/test/java/com/baeldung/SpringContextTest.java similarity index 97% rename from spring-security-modules/spring-security-mvc-socket/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-mvc-socket/src/test/java/com/baeldung/SpringContextTest.java index 7b9c738904..4ef4948601 100644 --- a/spring-security-modules/spring-security-mvc-socket/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-mvc-socket/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From a12f9e878a142f32432c8efb26804bf0b096e859 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:20:39 +0100 Subject: [PATCH 207/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-react --- .../main/java/{org => com}/baeldung/spring/MvcConfig.java | 2 +- .../{org => com}/baeldung/spring/SecSecurityConfig.java | 2 +- .../spring-security-react/src/main/webapp/WEB-INF/web.xml | 2 +- .../test/java/{org => com}/baeldung/SpringContextTest.java | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) rename spring-security-modules/spring-security-react/src/main/java/{org => com}/baeldung/spring/MvcConfig.java (98%) rename spring-security-modules/spring-security-react/src/main/java/{org => com}/baeldung/spring/SecSecurityConfig.java (98%) rename spring-security-modules/spring-security-react/src/test/java/{org => com}/baeldung/SpringContextTest.java (82%) diff --git a/spring-security-modules/spring-security-react/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 98% rename from spring-security-modules/spring-security-react/src/main/java/org/baeldung/spring/MvcConfig.java rename to spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/MvcConfig.java index f970b84585..f8acdfe2ac 100644 --- a/spring-security-modules/spring-security-react/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/MvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-react/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 98% rename from spring-security-modules/spring-security-react/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/SecSecurityConfig.java index c64b433544..7b67028647 100644 --- a/spring-security-modules/spring-security-react/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-modules/spring-security-react/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; diff --git a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/web.xml index eef48ec9b3..bc6f310147 100644 --- a/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-react/src/main/webapp/WEB-INF/web.xml @@ -15,7 +15,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring diff --git a/spring-security-modules/spring-security-react/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-react/src/test/java/com/baeldung/SpringContextTest.java similarity index 82% rename from spring-security-modules/spring-security-react/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-react/src/test/java/com/baeldung/SpringContextTest.java index cfef3322dc..43ddb515eb 100644 --- a/spring-security-modules/spring-security-react/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-react/src/test/java/com/baeldung/SpringContextTest.java @@ -1,7 +1,7 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.spring.MvcConfig; -import org.baeldung.spring.SecSecurityConfig; +import com.baeldung.spring.MvcConfig; +import com.baeldung.spring.SecSecurityConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; From b993d0762d4bad1ee1ce5b0a17b001bed559d7b7 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:25:10 +0100 Subject: [PATCH 208/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-rest --- .../{org => com}/baeldung/errorhandling/ApiError.java | 2 +- .../errorhandling/CustomRestExceptionHandler.java | 2 +- .../{org => com}/baeldung/persistence/model/Foo.java | 2 +- .../baeldung/security/SecurityJavaConfig.java | 10 +++++----- .../security/SecurityWebApplicationInitializer.java | 2 +- ...ySavedRequestAwareAuthenticationSuccessHandler.java | 2 +- .../security/web/RestAuthenticationEntryPoint.java | 2 +- .../{org => com}/baeldung/spring/ClientWebConfig.java | 2 +- .../baeldung/spring/SecurityXmlConfig.java | 4 ++-- .../java/{org => com}/baeldung/spring/WebConfig.java | 4 ++-- .../{org => com}/baeldung/swagger2/SwaggerConfig.java | 4 ++-- .../baeldung/web/controller/AsyncController.java | 4 ++-- .../baeldung/web/controller/CustomController.java | 2 +- .../baeldung/web/controller/FooController.java | 4 ++-- .../baeldung/web/controller/RootController.java | 2 +- .../baeldung/web/error/CustomAccessDeniedHandler.java | 2 +- .../web/error/RestResponseEntityExceptionHandler.java | 2 +- .../web/exception/MyResourceNotFoundException.java | 2 +- .../baeldung/web/service/AsyncService.java | 2 +- .../baeldung/web/service/AsyncServiceImpl.java | 2 +- .../src/main/resources/webSecurityConfig.xml | 2 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- .../java/{org => com}/baeldung/SpringContextTest.java | 8 ++++---- .../baeldung/errorhandling/FooLiveTest.java | 5 ++--- .../baeldung/web/AsyncControllerIntegrationTest.java | 10 +++++----- .../{org => com}/baeldung/web/SwaggerLiveTest.java | 2 +- .../java/{org => com}/baeldung/web/TestConfig.java | 4 ++-- 27 files changed, 45 insertions(+), 46 deletions(-) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/errorhandling/ApiError.java (97%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/errorhandling/CustomRestExceptionHandler.java (99%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/persistence/model/Foo.java (97%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/security/SecurityJavaConfig.java (92%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/security/SecurityWebApplicationInitializer.java (90%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/security/web/MySavedRequestAwareAuthenticationSuccessHandler.java (98%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/security/web/RestAuthenticationEntryPoint.java (95%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/spring/ClientWebConfig.java (91%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/spring/SecurityXmlConfig.java (77%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/spring/WebConfig.java (95%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/swagger2/SwaggerConfig.java (94%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/controller/AsyncController.java (94%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/controller/CustomController.java (90%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/controller/FooController.java (94%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/controller/RootController.java (94%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/error/CustomAccessDeniedHandler.java (96%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/error/RestResponseEntityExceptionHandler.java (99%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/exception/MyResourceNotFoundException.java (92%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/service/AsyncService.java (81%) rename spring-security-modules/spring-security-rest/src/main/java/{org => com}/baeldung/web/service/AsyncServiceImpl.java (97%) rename spring-security-modules/spring-security-rest/src/test/java/{org => com}/baeldung/SpringContextTest.java (77%) rename spring-security-modules/spring-security-rest/src/test/java/{org => com}/baeldung/errorhandling/FooLiveTest.java (96%) rename spring-security-modules/spring-security-rest/src/test/java/{org => com}/baeldung/web/AsyncControllerIntegrationTest.java (87%) rename spring-security-modules/spring-security-rest/src/test/java/{org => com}/baeldung/web/SwaggerLiveTest.java (95%) rename spring-security-modules/spring-security-rest/src/test/java/{org => com}/baeldung/web/TestConfig.java (89%) diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/errorhandling/ApiError.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/errorhandling/ApiError.java similarity index 97% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/errorhandling/ApiError.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/errorhandling/ApiError.java index 8a1ddd8882..0fba2deca5 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/errorhandling/ApiError.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/errorhandling/ApiError.java @@ -1,4 +1,4 @@ -package org.baeldung.errorhandling; +package com.baeldung.errorhandling; import java.util.Arrays; import java.util.List; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/errorhandling/CustomRestExceptionHandler.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/errorhandling/CustomRestExceptionHandler.java similarity index 99% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/errorhandling/CustomRestExceptionHandler.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/errorhandling/CustomRestExceptionHandler.java index cd4d58e60c..02bc0a2512 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/errorhandling/CustomRestExceptionHandler.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/errorhandling/CustomRestExceptionHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.errorhandling; +package com.baeldung.errorhandling; import java.util.ArrayList; import java.util.List; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/persistence/model/Foo.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/persistence/model/Foo.java similarity index 97% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/persistence/model/Foo.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/persistence/model/Foo.java index 05a7c7b9a0..d85cca1dcc 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/persistence/model/Foo.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/persistence/model/Foo.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.model; +package com.baeldung.persistence.model; import java.io.Serializable; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/SecurityJavaConfig.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/SecurityJavaConfig.java similarity index 92% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/SecurityJavaConfig.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/SecurityJavaConfig.java index 74623080b5..d20198c2bb 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/SecurityJavaConfig.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/SecurityJavaConfig.java @@ -1,8 +1,8 @@ -package org.baeldung.security; +package com.baeldung.security; -import org.baeldung.security.web.MySavedRequestAwareAuthenticationSuccessHandler; -import org.baeldung.security.web.RestAuthenticationEntryPoint; -import org.baeldung.web.error.CustomAccessDeniedHandler; +import com.baeldung.security.web.MySavedRequestAwareAuthenticationSuccessHandler; +import com.baeldung.security.web.RestAuthenticationEntryPoint; +import com.baeldung.web.error.CustomAccessDeniedHandler; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -20,7 +20,7 @@ import org.springframework.security.web.authentication.SimpleUrlAuthenticationFa @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) -@ComponentScan("org.baeldung.security") +@ComponentScan("com.baeldung.security") public class SecurityJavaConfig extends WebSecurityConfigurerAdapter { @Autowired diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/SecurityWebApplicationInitializer.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java similarity index 90% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/SecurityWebApplicationInitializer.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java index 33978962bb..77e70d5b84 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/SecurityWebApplicationInitializer.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/SecurityWebApplicationInitializer.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/web/MySavedRequestAwareAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/web/MySavedRequestAwareAuthenticationSuccessHandler.java similarity index 98% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/web/MySavedRequestAwareAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/web/MySavedRequestAwareAuthenticationSuccessHandler.java index c56568e979..2d74ed9dca 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/web/MySavedRequestAwareAuthenticationSuccessHandler.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/web/MySavedRequestAwareAuthenticationSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security.web; +package com.baeldung.security.web; import java.io.IOException; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/web/RestAuthenticationEntryPoint.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/web/RestAuthenticationEntryPoint.java similarity index 95% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/web/RestAuthenticationEntryPoint.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/web/RestAuthenticationEntryPoint.java index 643e2f0575..162ee46727 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/security/web/RestAuthenticationEntryPoint.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/security/web/RestAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package org.baeldung.security.web; +package com.baeldung.security.web; import java.io.IOException; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/ClientWebConfig.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/ClientWebConfig.java similarity index 91% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/ClientWebConfig.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/ClientWebConfig.java index 8e20358a5a..db24817f5b 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/ClientWebConfig.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/ClientWebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/SecurityXmlConfig.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/SecurityXmlConfig.java similarity index 77% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/SecurityXmlConfig.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/SecurityXmlConfig.java index 0830a1ebe1..92f7cea784 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/SecurityXmlConfig.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/SecurityXmlConfig.java @@ -1,10 +1,10 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.ComponentScan; // @Configuration // @ImportResource({ "classpath:webSecurityConfig.xml" }) -@ComponentScan("org.baeldung.security") +@ComponentScan("com.baeldung.security") public class SecurityXmlConfig { public SecurityXmlConfig() { diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/WebConfig.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/WebConfig.java similarity index 95% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/WebConfig.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/WebConfig.java index dba07dc4e5..84b211a9bd 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/spring/WebConfig.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/spring/WebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -12,7 +12,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.view.InternalResourceViewResolver; @Configuration -@ComponentScan("org.baeldung.web") +@ComponentScan("com.baeldung.web") @EnableWebMvc @EnableAsync public class WebConfig implements WebMvcConfigurer { diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/swagger2/SwaggerConfig.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/swagger2/SwaggerConfig.java similarity index 94% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/swagger2/SwaggerConfig.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/swagger2/SwaggerConfig.java index 67c760353d..c8c4227ebf 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/swagger2/SwaggerConfig.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/swagger2/SwaggerConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.swagger2; +package com.baeldung.swagger2; import static com.google.common.collect.Lists.newArrayList; @@ -25,7 +25,7 @@ public class SwaggerConfig { @Bean public Docket api() { return new Docket(DocumentationType.SWAGGER_2).select() - .apis(RequestHandlerSelectors.basePackage("org.baeldung.web.controller")) + .apis(RequestHandlerSelectors.basePackage("com.baeldung.web.controller")) .paths(PathSelectors.ant("/foos/*")) .build() .apiInfo(apiInfo()) diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/AsyncController.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/AsyncController.java similarity index 94% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/AsyncController.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/AsyncController.java index f6f1c392cb..c2123913c6 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/AsyncController.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/AsyncController.java @@ -1,11 +1,11 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import java.util.concurrent.Callable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.baeldung.web.service.AsyncService; +import com.baeldung.web.service.AsyncService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/CustomController.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/CustomController.java similarity index 90% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/CustomController.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/CustomController.java index 7d40b9bb8d..d833d3af7a 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/CustomController.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/CustomController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/FooController.java similarity index 94% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/FooController.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/FooController.java index f914f82215..033bf2d1e3 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/FooController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; @@ -6,7 +6,7 @@ import java.util.List; import javax.servlet.http.HttpServletResponse; -import org.baeldung.persistence.model.Foo; +import com.baeldung.persistence.model.Foo; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/RootController.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/RootController.java similarity index 94% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/RootController.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/RootController.java index 4253ed7a59..3abbe8a309 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/controller/RootController.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/controller/RootController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/error/CustomAccessDeniedHandler.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/error/CustomAccessDeniedHandler.java similarity index 96% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/error/CustomAccessDeniedHandler.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/error/CustomAccessDeniedHandler.java index cc07417427..6c686cd9e9 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/error/CustomAccessDeniedHandler.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/error/CustomAccessDeniedHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.web.error; +package com.baeldung.web.error; import java.io.IOException; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java similarity index 99% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java index 9ff4f040fe..9e6ae78d27 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/error/RestResponseEntityExceptionHandler.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/error/RestResponseEntityExceptionHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.web.error; +package com.baeldung.web.error; import org.springframework.dao.DataAccessException; import org.springframework.dao.DataIntegrityViolationException; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java similarity index 92% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java index 14b61f9832..fd002efc28 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/exception/MyResourceNotFoundException.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/exception/MyResourceNotFoundException.java @@ -1,4 +1,4 @@ -package org.baeldung.web.exception; +package com.baeldung.web.exception; public final class MyResourceNotFoundException extends RuntimeException { diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncService.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/service/AsyncService.java similarity index 81% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncService.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/service/AsyncService.java index 1ba4dfa4cb..ee07313ee8 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncService.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/service/AsyncService.java @@ -1,4 +1,4 @@ -package org.baeldung.web.service; +package com.baeldung.web.service; import java.util.concurrent.Callable; diff --git a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncServiceImpl.java b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/service/AsyncServiceImpl.java similarity index 97% rename from spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncServiceImpl.java rename to spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/service/AsyncServiceImpl.java index d6d7f53dd7..8aebbc3234 100644 --- a/spring-security-modules/spring-security-rest/src/main/java/org/baeldung/web/service/AsyncServiceImpl.java +++ b/spring-security-modules/spring-security-rest/src/main/java/com/baeldung/web/service/AsyncServiceImpl.java @@ -1,4 +1,4 @@ -package org.baeldung.web.service; +package com.baeldung.web.service; import java.util.concurrent.Callable; diff --git a/spring-security-modules/spring-security-rest/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-rest/src/main/resources/webSecurityConfig.xml index edd3cba39c..2c0a0bc774 100644 --- a/spring-security-modules/spring-security-rest/src/main/resources/webSecurityConfig.xml +++ b/spring-security-modules/spring-security-rest/src/main/resources/webSecurityConfig.xml @@ -30,7 +30,7 @@ + class="com.baeldung.security.MySavedRequestAwareAuthenticationSuccessHandler" /> diff --git a/spring-security-modules/spring-security-rest/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-rest/src/main/webapp/WEB-INF/web.xml index 3195603837..663c17bc56 100644 --- a/spring-security-modules/spring-security-rest/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-rest/src/main/webapp/WEB-INF/web.xml @@ -17,7 +17,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring diff --git a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/SpringContextTest.java similarity index 77% rename from spring-security-modules/spring-security-rest/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-rest/src/test/java/com/baeldung/SpringContextTest.java index 11586ce670..bcc66558cb 100644 --- a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/SpringContextTest.java @@ -1,8 +1,8 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.security.SecurityJavaConfig; -import org.baeldung.spring.ClientWebConfig; -import org.baeldung.spring.WebConfig; +import com.baeldung.security.SecurityJavaConfig; +import com.baeldung.spring.ClientWebConfig; +import com.baeldung.spring.WebConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; diff --git a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/errorhandling/FooLiveTest.java b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/errorhandling/FooLiveTest.java similarity index 96% rename from spring-security-modules/spring-security-rest/src/test/java/org/baeldung/errorhandling/FooLiveTest.java rename to spring-security-modules/spring-security-rest/src/test/java/com/baeldung/errorhandling/FooLiveTest.java index 8d1db5736f..e08a24676a 100644 --- a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/errorhandling/FooLiveTest.java +++ b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/errorhandling/FooLiveTest.java @@ -1,10 +1,9 @@ -package org.baeldung.errorhandling; +package com.baeldung.errorhandling; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import org.baeldung.errorhandling.ApiError; -import org.baeldung.web.TestConfig; +import com.baeldung.web.TestConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.http.HttpStatus; diff --git a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/AsyncControllerIntegrationTest.java b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/AsyncControllerIntegrationTest.java similarity index 87% rename from spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/AsyncControllerIntegrationTest.java rename to spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/AsyncControllerIntegrationTest.java index 1e5e1b7d85..bf93c14f1f 100644 --- a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/AsyncControllerIntegrationTest.java +++ b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/AsyncControllerIntegrationTest.java @@ -1,9 +1,9 @@ -package org.baeldung.web; +package com.baeldung.web; -import org.baeldung.security.SecurityJavaConfig; -import org.baeldung.spring.ClientWebConfig; -import org.baeldung.spring.WebConfig; -import org.baeldung.web.controller.AsyncController; +import com.baeldung.security.SecurityJavaConfig; +import com.baeldung.spring.ClientWebConfig; +import com.baeldung.spring.WebConfig; +import com.baeldung.web.controller.AsyncController; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/SwaggerLiveTest.java b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/SwaggerLiveTest.java similarity index 95% rename from spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/SwaggerLiveTest.java rename to spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/SwaggerLiveTest.java index 792b3e28ce..3f86b63503 100644 --- a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/SwaggerLiveTest.java +++ b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/SwaggerLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung.web; +package com.baeldung.web; import static org.junit.Assert.assertEquals; diff --git a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/TestConfig.java b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/TestConfig.java similarity index 89% rename from spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/TestConfig.java rename to spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/TestConfig.java index 61bd6e776b..ddb7240611 100644 --- a/spring-security-modules/spring-security-rest/src/test/java/org/baeldung/web/TestConfig.java +++ b/spring-security-modules/spring-security-rest/src/test/java/com/baeldung/web/TestConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.web; +package com.baeldung.web; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; @@ -7,7 +7,7 @@ import org.springframework.web.multipart.MultipartResolver; import org.springframework.web.multipart.commons.CommonsMultipartResolver; @Configuration -@ComponentScan({ "org.baeldung.web" }) +@ComponentScan({ "com.baeldung.web" }) public class TestConfig { @Bean From 43299dc08224064454c8cf00a36b4f2fecebd03d Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:27:36 +0100 Subject: [PATCH 209/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-rest-basic-auth --- .../baeldung/basic/MyBasicAuthenticationEntryPoint.java | 2 +- .../HttpComponentsClientHttpRequestFactoryBasicAuth.java | 2 +- .../{org => com}/baeldung/client/RestTemplateFactory.java | 2 +- .../{org => com}/baeldung/client/spring/ClientConfig.java | 2 +- .../main/java/{org => com}/baeldung/filter/CustomFilter.java | 2 +- .../baeldung/filter/CustomWebSecurityConfigurerAdapter.java | 4 ++-- .../MySavedRequestAwareAuthenticationSuccessHandler.java | 2 +- .../baeldung/security/RestAuthenticationEntryPoint.java | 2 +- .../java/{org => com}/baeldung/spring/SecSecurityConfig.java | 2 +- .../src/main/java/{org => com}/baeldung/spring/WebConfig.java | 2 +- .../{org => com}/baeldung/web/controller/BarController.java | 4 ++-- .../{org => com}/baeldung/web/controller/FooController.java | 4 ++-- .../src/main/java/{org => com}/baeldung/web/dto/Bar.java | 2 +- .../src/main/java/{org => com}/baeldung/web/dto/Foo.java | 2 +- .../src/main/resources/webSecurityConfig.xml | 2 +- .../test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 16 files changed, 19 insertions(+), 19 deletions(-) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/basic/MyBasicAuthenticationEntryPoint.java (97%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java (97%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/client/RestTemplateFactory.java (97%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/client/spring/ClientConfig.java (88%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/filter/CustomFilter.java (94%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/filter/CustomWebSecurityConfigurerAdapter.java (95%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java (98%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/security/RestAuthenticationEntryPoint.java (96%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/spring/SecSecurityConfig.java (93%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/spring/WebConfig.java (96%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/web/controller/BarController.java (95%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/web/controller/FooController.java (92%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/web/dto/Bar.java (86%) rename spring-security-modules/spring-security-rest-basic-auth/src/main/java/{org => com}/baeldung/web/dto/Foo.java (86%) rename spring-security-modules/spring-security-rest-basic-auth/src/test/java/{org => com}/baeldung/SpringContextTest.java (94%) diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/basic/MyBasicAuthenticationEntryPoint.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java similarity index 97% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/basic/MyBasicAuthenticationEntryPoint.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java index f440bbd10c..07344819c0 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/basic/MyBasicAuthenticationEntryPoint.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/basic/MyBasicAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package org.baeldung.basic; +package com.baeldung.basic; import org.springframework.security.core.AuthenticationException; import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java similarity index 97% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java index a2f51d343b..81f82a2c1c 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/HttpComponentsClientHttpRequestFactoryBasicAuth.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package com.baeldung.client; import java.net.URI; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/RestTemplateFactory.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/RestTemplateFactory.java similarity index 97% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/RestTemplateFactory.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/RestTemplateFactory.java index 3ed0bc82b7..aac4f8cebd 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/RestTemplateFactory.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/RestTemplateFactory.java @@ -1,4 +1,4 @@ -package org.baeldung.client; +package com.baeldung.client; import org.apache.http.HttpHost; import org.springframework.beans.factory.FactoryBean; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/spring/ClientConfig.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/spring/ClientConfig.java similarity index 88% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/spring/ClientConfig.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/spring/ClientConfig.java index 73e602855c..dd834628a6 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/client/spring/ClientConfig.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/spring/ClientConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.client.spring; +package com.baeldung.client.spring; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/filter/CustomFilter.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/filter/CustomFilter.java similarity index 94% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/filter/CustomFilter.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/filter/CustomFilter.java index 01e5b0b59d..6bb12610fa 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/filter/CustomFilter.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/filter/CustomFilter.java @@ -1,4 +1,4 @@ -package org.baeldung.filter; +package com.baeldung.filter; import org.springframework.web.filter.GenericFilterBean; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/filter/CustomWebSecurityConfigurerAdapter.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java similarity index 95% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/filter/CustomWebSecurityConfigurerAdapter.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java index 7ca2a80c52..fb597e46c8 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/filter/CustomWebSecurityConfigurerAdapter.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/filter/CustomWebSecurityConfigurerAdapter.java @@ -1,6 +1,6 @@ -package org.baeldung.filter; +package com.baeldung.filter; -import org.baeldung.security.RestAuthenticationEntryPoint; +import com.baeldung.security.RestAuthenticationEntryPoint; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java similarity index 98% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java index 698052fa2b..7dc53e3e1e 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/security/RestAuthenticationEntryPoint.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java similarity index 96% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/security/RestAuthenticationEntryPoint.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java index 77aa32ff97..1ae89adb89 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/security/RestAuthenticationEntryPoint.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 93% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java index 4ce80dab9f..cddef4d508 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/spring/WebConfig.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/WebConfig.java similarity index 96% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/spring/WebConfig.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/WebConfig.java index 5876e1307b..e9d0d277f1 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/spring/WebConfig.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/WebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import java.util.List; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/controller/BarController.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/controller/BarController.java similarity index 95% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/controller/BarController.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/controller/BarController.java index 5f32b9f73b..6f7dc91e7e 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/controller/BarController.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/controller/BarController.java @@ -1,9 +1,9 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import java.nio.charset.Charset; import org.apache.commons.codec.binary.Base64; -import org.baeldung.web.dto.Bar; +import com.baeldung.web.dto.Bar; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.http.HttpHeaders; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/controller/FooController.java similarity index 92% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/controller/FooController.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/controller/FooController.java index b50edb2dcf..461a5e351a 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/controller/FooController.java @@ -1,6 +1,6 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; -import org.baeldung.web.dto.Foo; +import com.baeldung.web.dto.Foo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; import org.springframework.security.access.prepost.PreAuthorize; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/dto/Bar.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/dto/Bar.java similarity index 86% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/dto/Bar.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/dto/Bar.java index d33e39a823..eb139b0ec1 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/dto/Bar.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/dto/Bar.java @@ -1,4 +1,4 @@ -package org.baeldung.web.dto; +package com.baeldung.web.dto; import java.io.Serializable; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/dto/Foo.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/dto/Foo.java similarity index 86% rename from spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/dto/Foo.java rename to spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/dto/Foo.java index 09c1dac933..23cfab132d 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/org/baeldung/web/dto/Foo.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/web/dto/Foo.java @@ -1,4 +1,4 @@ -package org.baeldung.web.dto; +package com.baeldung.web.dto; import java.io.Serializable; diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-rest-basic-auth/src/main/resources/webSecurityConfig.xml index a93dc841b6..2ff9a1de15 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/resources/webSecurityConfig.xml +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/resources/webSecurityConfig.xml @@ -23,6 +23,6 @@ - + \ No newline at end of file diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-rest-basic-auth/src/test/java/com/baeldung/SpringContextTest.java similarity index 94% rename from spring-security-modules/spring-security-rest-basic-auth/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-rest-basic-auth/src/test/java/com/baeldung/SpringContextTest.java index f54cbf3b7b..91b34757e2 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 4e839f8e324d3bf68b8d2dac5ba13d96f0350472 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:29:21 +0100 Subject: [PATCH 210/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-rest-custom --- .../{org => com}/baeldung/config/MainWebAppInitializer.java | 2 +- .../baeldung/config/child/MethodSecurityConfig.java | 2 +- .../java/{org => com}/baeldung/config/child/WebConfig.java | 2 +- .../{org => com}/baeldung/config/parent/SecurityConfig.java | 4 ++-- .../{org => com}/baeldung/config/parent/ServiceConfig.java | 2 +- .../baeldung/security/AuthenticationFacade.java | 2 +- .../baeldung/security/CustomAuthenticationProvider.java | 2 +- .../baeldung/security/IAuthenticationFacade.java | 2 +- .../MySavedRequestAwareAuthenticationSuccessHandler.java | 2 +- .../baeldung/security/RestAuthenticationEntryPoint.java | 2 +- .../main/java/{org => com}/baeldung/service/FooService.java | 4 ++-- .../java/{org => com}/baeldung/service/IFooService.java | 4 ++-- .../java/{org => com}/baeldung/service/RunAsService.java | 2 +- .../{org => com}/baeldung/web/controller/FooController.java | 6 +++--- .../controller/GetUserWithCustomInterfaceController.java | 4 ++-- .../controller/GetUserWithHTTPServletRequestController.java | 2 +- .../baeldung/web/controller/RunAsController.java | 2 +- .../baeldung/web/controller/SecurityController.java | 2 +- .../baeldung/web/controller/SecurityController1.java | 2 +- .../baeldung/web/controller/SecurityController3.java | 2 +- .../baeldung/web/controller/ViewController.java | 2 +- .../src/main/java/{org => com}/baeldung/web/dto/Foo.java | 2 +- 22 files changed, 28 insertions(+), 28 deletions(-) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/config/MainWebAppInitializer.java (98%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/config/child/MethodSecurityConfig.java (97%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/config/child/WebConfig.java (98%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/config/parent/SecurityConfig.java (93%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/config/parent/ServiceConfig.java (95%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/security/AuthenticationFacade.java (93%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/security/CustomAuthenticationProvider.java (98%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/security/IAuthenticationFacade.java (82%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java (98%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/security/RestAuthenticationEntryPoint.java (96%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/service/FooService.java (93%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/service/IFooService.java (52%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/service/RunAsService.java (94%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/FooController.java (91%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/GetUserWithCustomInterfaceController.java (90%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/GetUserWithHTTPServletRequestController.java (95%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/RunAsController.java (95%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/SecurityController.java (94%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/SecurityController1.java (97%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/SecurityController3.java (95%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/controller/ViewController.java (90%) rename spring-security-modules/spring-security-rest-custom/src/main/java/{org => com}/baeldung/web/dto/Foo.java (86%) diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/MainWebAppInitializer.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/MainWebAppInitializer.java similarity index 98% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/MainWebAppInitializer.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/MainWebAppInitializer.java index 0a11cdab72..f24c96a686 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/MainWebAppInitializer.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/MainWebAppInitializer.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import java.util.Set; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/child/MethodSecurityConfig.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/MethodSecurityConfig.java similarity index 97% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/child/MethodSecurityConfig.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/MethodSecurityConfig.java index bc9a9f161b..7fb282ae8b 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/child/MethodSecurityConfig.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/MethodSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config.child; +package com.baeldung.config.child; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/WebConfig.java similarity index 98% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/WebConfig.java index 7cbbcf31fa..0c95acc177 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/child/WebConfig.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/WebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config.child; +package com.baeldung.config.child; import java.util.List; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/SecurityConfig.java similarity index 93% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/SecurityConfig.java index fb3880a33f..36ce898fb6 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/SecurityConfig.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/SecurityConfig.java @@ -1,6 +1,6 @@ -package org.baeldung.config.parent; +package com.baeldung.config.parent; -import org.baeldung.security.CustomAuthenticationProvider; +import com.baeldung.security.CustomAuthenticationProvider; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/ServiceConfig.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/ServiceConfig.java similarity index 95% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/ServiceConfig.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/ServiceConfig.java index 02af0165f4..6e45a32a87 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/config/parent/ServiceConfig.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/ServiceConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config.parent; +package com.baeldung.config.parent; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/AuthenticationFacade.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/AuthenticationFacade.java similarity index 93% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/AuthenticationFacade.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/AuthenticationFacade.java index 5a3c77b070..bcf0ef0499 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/AuthenticationFacade.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/AuthenticationFacade.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/CustomAuthenticationProvider.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/CustomAuthenticationProvider.java similarity index 98% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/CustomAuthenticationProvider.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/CustomAuthenticationProvider.java index 4b9b3e8ee9..8e67714431 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/CustomAuthenticationProvider.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/CustomAuthenticationProvider.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.util.ArrayList; import java.util.List; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/IAuthenticationFacade.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/IAuthenticationFacade.java similarity index 82% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/IAuthenticationFacade.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/IAuthenticationFacade.java index d1223e41cf..bffbc3fef0 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/IAuthenticationFacade.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/IAuthenticationFacade.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.security.core.Authentication; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java similarity index 98% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java index 698052fa2b..7dc53e3e1e 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/MySavedRequestAwareAuthenticationSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/RestAuthenticationEntryPoint.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java similarity index 96% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/RestAuthenticationEntryPoint.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java index 77aa32ff97..1ae89adb89 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/security/RestAuthenticationEntryPoint.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/security/RestAuthenticationEntryPoint.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/FooService.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/FooService.java similarity index 93% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/FooService.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/FooService.java index cb374ae4b0..f97c357566 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/FooService.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/FooService.java @@ -1,6 +1,6 @@ -package org.baeldung.service; +package com.baeldung.service; -import org.baeldung.web.dto.Foo; +import com.baeldung.web.dto.Foo; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/IFooService.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/IFooService.java similarity index 52% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/IFooService.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/IFooService.java index de234b1b45..3ab1faf98b 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/IFooService.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/IFooService.java @@ -1,6 +1,6 @@ -package org.baeldung.service; +package com.baeldung.service; -import org.baeldung.web.dto.Foo; +import com.baeldung.web.dto.Foo; public interface IFooService { diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/RunAsService.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/RunAsService.java similarity index 94% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/RunAsService.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/RunAsService.java index a6320f8b81..412330006b 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/service/RunAsService.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/service/RunAsService.java @@ -1,4 +1,4 @@ -package org.baeldung.service; +package com.baeldung.service; import org.springframework.security.access.annotation.Secured; import org.springframework.security.core.Authentication; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/FooController.java similarity index 91% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/FooController.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/FooController.java index 74fd5e403f..696dcccd02 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/FooController.java @@ -1,7 +1,7 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; -import org.baeldung.service.IFooService; -import org.baeldung.web.dto.Foo; +import com.baeldung.service.IFooService; +import com.baeldung.web.dto.Foo; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/GetUserWithCustomInterfaceController.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/GetUserWithCustomInterfaceController.java similarity index 90% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/GetUserWithCustomInterfaceController.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/GetUserWithCustomInterfaceController.java index b8521d6663..4166ca9102 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/GetUserWithCustomInterfaceController.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/GetUserWithCustomInterfaceController.java @@ -1,6 +1,6 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; -import org.baeldung.security.IAuthenticationFacade; +import com.baeldung.security.IAuthenticationFacade; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.stereotype.Controller; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/GetUserWithHTTPServletRequestController.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/GetUserWithHTTPServletRequestController.java similarity index 95% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/GetUserWithHTTPServletRequestController.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/GetUserWithHTTPServletRequestController.java index ace5688697..2e6951132d 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/GetUserWithHTTPServletRequestController.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/GetUserWithHTTPServletRequestController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import java.security.Principal; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/RunAsController.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/RunAsController.java similarity index 95% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/RunAsController.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/RunAsController.java index 08f39aa5f2..13a3f45bf3 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/RunAsController.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/RunAsController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.springframework.security.access.annotation.Secured; import org.springframework.security.core.Authentication; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController.java similarity index 94% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController.java index 7cf57a5275..f35940f54c 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import java.security.Principal; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController1.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController1.java similarity index 97% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController1.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController1.java index d06f15af93..1951e04dcb 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController1.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController1.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationEventPublisher; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController3.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController3.java similarity index 95% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController3.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController3.java index fb207b43dd..2dcb98286b 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/SecurityController3.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/SecurityController3.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.springframework.security.core.Authentication; import org.springframework.security.core.userdetails.UserDetails; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/ViewController.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/ViewController.java similarity index 90% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/ViewController.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/ViewController.java index fbcb9b979e..870331f134 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/controller/ViewController.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/controller/ViewController.java @@ -1,4 +1,4 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/dto/Foo.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/dto/Foo.java similarity index 86% rename from spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/dto/Foo.java rename to spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/dto/Foo.java index 09c1dac933..23cfab132d 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/org/baeldung/web/dto/Foo.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/web/dto/Foo.java @@ -1,4 +1,4 @@ -package org.baeldung.web.dto; +package com.baeldung.web.dto; import java.io.Serializable; From 20e72465ccad732536a2be7b9ef2f4b7f479a2ab Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:33:21 +0100 Subject: [PATCH 211/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-sso --- .../java/{org => com}/baeldung/config/AuthServerConfig.java | 2 +- .../baeldung/config/AuthorizationServerApplication.java | 2 +- .../java/{org => com}/baeldung/config/SecurityConfig.java | 2 +- .../java/{org => com}/baeldung/config/UserController.java | 2 +- .../test/java/{org => com}/baeldung/SpringContextTest.java | 4 ++-- .../java/{org => com}/baeldung/UserInfoEndpointLiveTest.java | 2 +- .../src/main/java/com}/baeldung/config/UiApplication.java | 4 ++-- .../src/main/java/com}/baeldung/config/UiSecurityConfig.java | 2 +- .../src/main/java/com}/baeldung/config/UiWebConfig.java | 2 +- .../src/test/java/com}/baeldung/SpringContextTest.java | 4 ++-- .../src/main/java/com}/baeldung/config/UiApplication.java | 4 ++-- .../src/main/java/com}/baeldung/config/UiSecurityConfig.java | 2 +- .../src/main/java/com}/baeldung/config/UiWebConfig.java | 2 +- .../src/test/java/com}/baeldung/SpringContextTest.java | 4 ++-- 14 files changed, 19 insertions(+), 19 deletions(-) rename spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/{org => com}/baeldung/config/AuthServerConfig.java (98%) rename spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/{org => com}/baeldung/config/AuthorizationServerApplication.java (95%) rename spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/{org => com}/baeldung/config/SecurityConfig.java (98%) rename spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/{org => com}/baeldung/config/UserController.java (92%) rename spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/{org => com}/baeldung/SpringContextTest.java (86%) rename spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/{org => com}/baeldung/UserInfoEndpointLiveTest.java (99%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui/src/main/java/org => spring-security-sso-ui-2/src/main/java/com}/baeldung/config/UiApplication.java (95%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui/src/main/java/org => spring-security-sso-ui-2/src/main/java/com}/baeldung/config/UiSecurityConfig.java (96%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui/src/main/java/org => spring-security-sso-ui-2/src/main/java/com}/baeldung/config/UiWebConfig.java (97%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui/src/test/java/org => spring-security-sso-ui-2/src/test/java/com}/baeldung/SpringContextTest.java (88%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui-2/src/main/java/org => spring-security-sso-ui/src/main/java/com}/baeldung/config/UiApplication.java (95%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui-2/src/main/java/org => spring-security-sso-ui/src/main/java/com}/baeldung/config/UiSecurityConfig.java (96%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui-2/src/main/java/org => spring-security-sso-ui/src/main/java/com}/baeldung/config/UiWebConfig.java (97%) rename spring-security-modules/spring-security-sso/{spring-security-sso-ui-2/src/test/java/org => spring-security-sso-ui/src/test/java/com}/baeldung/SpringContextTest.java (88%) diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/AuthServerConfig.java b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java similarity index 98% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/AuthServerConfig.java rename to spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java index 0835f3d721..9a6400abdf 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/AuthServerConfig.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthServerConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/AuthorizationServerApplication.java b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java similarity index 95% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/AuthorizationServerApplication.java rename to spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java index b74d2f144c..5cfcb2bb5b 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/AuthorizationServerApplication.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/AuthorizationServerApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/SecurityConfig.java b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java similarity index 98% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/SecurityConfig.java rename to spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java index 2254de8e39..29c7549753 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/SecurityConfig.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/SecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/UserController.java b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java similarity index 92% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/UserController.java rename to spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java index 28128f9d97..80415fbd30 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/org/baeldung/config/UserController.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/main/java/com/baeldung/config/UserController.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import java.security.Principal; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java similarity index 86% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java index f677f683b2..1f07837da9 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/SpringContextTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.config.AuthorizationServerApplication; +import com.baeldung.config.AuthorizationServerApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/org/baeldung/UserInfoEndpointLiveTest.java b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java similarity index 99% rename from spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/org/baeldung/UserInfoEndpointLiveTest.java rename to spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java index ffdb1df8fe..104f980dd2 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/org/baeldung/UserInfoEndpointLiveTest.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/src/test/java/com/baeldung/UserInfoEndpointLiveTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import static org.junit.Assert.assertEquals; import java.util.HashMap; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiApplication.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java similarity index 95% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiApplication.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java index 07d875d805..ca178cfa7e 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiApplication.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -6,10 +6,10 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer import org.springframework.context.annotation.Bean; import org.springframework.web.context.request.RequestContextListener; - @SpringBootApplication public class UiApplication extends SpringBootServletInitializer { + @Bean public RequestContextListener requestContextListener() { return new RequestContextListener(); diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiSecurityConfig.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java similarity index 96% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiSecurityConfig.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java index de81ada9e0..7ef1392659 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiSecurityConfig.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiWebConfig.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java similarity index 97% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiWebConfig.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java index c17bb85173..ae5008daa3 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/org/baeldung/config/UiWebConfig.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/com/baeldung/config/UiWebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java similarity index 88% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java index 61a2a022ed..1eeab34e94 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/com/baeldung/SpringContextTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.config.UiApplication; +import com.baeldung.config.UiApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiApplication.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java similarity index 95% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiApplication.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java index 0c20853aed..16d94d6d80 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiApplication.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiApplication.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -6,10 +6,10 @@ import org.springframework.boot.web.servlet.support.SpringBootServletInitializer import org.springframework.context.annotation.Bean; import org.springframework.web.context.request.RequestContextListener; + @SpringBootApplication public class UiApplication extends SpringBootServletInitializer { - @Bean public RequestContextListener requestContextListener() { return new RequestContextListener(); diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiSecurityConfig.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java similarity index 96% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiSecurityConfig.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java index de81ada9e0..7ef1392659 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiSecurityConfig.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.boot.autoconfigure.security.oauth2.client.EnableOAuth2Sso; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiWebConfig.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java similarity index 97% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiWebConfig.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java index c17bb85173..ae5008daa3 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/main/java/org/baeldung/config/UiWebConfig.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/main/java/com/baeldung/config/UiWebConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.config; +package com.baeldung.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java similarity index 88% rename from spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java index 61a2a022ed..1eeab34e94 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui/src/test/java/com/baeldung/SpringContextTest.java @@ -1,6 +1,6 @@ -package org.baeldung; +package com.baeldung; -import org.baeldung.config.UiApplication; +import com.baeldung.config.UiApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; From abc4259c99d0a2cf1dfac4949cf809f1d8bcf43f Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:34:53 +0100 Subject: [PATCH 212/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-x509 --- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- .../src/test/java/{org => com}/baeldung/SpringContextTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) rename spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/{org => com}/baeldung/SpringContextTest.java (95%) diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/SpringContextTest.java index 5c65dd3e8a..1c89f706ab 100644 --- a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/SpringContextTest.java similarity index 95% rename from spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/org/baeldung/SpringContextTest.java rename to spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/SpringContextTest.java index 5c65dd3e8a..1c89f706ab 100644 --- a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/org/baeldung/SpringContextTest.java +++ b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/SpringContextTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; From 8586e8de2ac7b35d0970f559ecd5027f713298ea Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:41:34 +0100 Subject: [PATCH 213/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc-digest-auth (finalized) --- .../src/main/java/com/baeldung/spring/SecSecurityConfig.java | 2 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java index cddef4d508..4ba9d47f8d 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -6,7 +6,7 @@ import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource({ "classpath:webSecurityConfig.xml" }) -@ComponentScan("org.baeldung.security") +@ComponentScan("com.baeldung.security") public class SecSecurityConfig { public SecSecurityConfig() { diff --git a/spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/web.xml index bebd5d9cd3..25f5a91932 100644 --- a/spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-mvc-digest-auth/src/main/webapp/WEB-INF/web.xml @@ -16,7 +16,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring From 06347b6f1fcef93425b7e2bc2ff72b6ea3975684 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:42:33 +0100 Subject: [PATCH 214/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc-login --- .../src/main/resources/channelWebSecurityConfig.xml | 2 +- .../src/main/resources/webSecurityConfig.xml | 6 +++--- .../src/test/resources/mvc-servlet.xml | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-security-modules/spring-security-mvc-login/src/main/resources/channelWebSecurityConfig.xml b/spring-security-modules/spring-security-mvc-login/src/main/resources/channelWebSecurityConfig.xml index eff3e1a1a1..8b8b4cd2f3 100644 --- a/spring-security-modules/spring-security-mvc-login/src/main/resources/channelWebSecurityConfig.xml +++ b/spring-security-modules/spring-security-mvc-login/src/main/resources/channelWebSecurityConfig.xml @@ -23,7 +23,7 @@ - + diff --git a/spring-security-modules/spring-security-mvc-login/src/main/resources/webSecurityConfig.xml b/spring-security-modules/spring-security-mvc-login/src/main/resources/webSecurityConfig.xml index 8a83bf5e93..543792fadc 100644 --- a/spring-security-modules/spring-security-mvc-login/src/main/resources/webSecurityConfig.xml +++ b/spring-security-modules/spring-security-mvc-login/src/main/resources/webSecurityConfig.xml @@ -25,11 +25,11 @@ - + - + - + diff --git a/spring-security-modules/spring-security-mvc-login/src/test/resources/mvc-servlet.xml b/spring-security-modules/spring-security-mvc-login/src/test/resources/mvc-servlet.xml index 4568d319b8..aee837c977 100644 --- a/spring-security-modules/spring-security-mvc-login/src/test/resources/mvc-servlet.xml +++ b/spring-security-modules/spring-security-mvc-login/src/test/resources/mvc-servlet.xml @@ -3,6 +3,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> - + \ No newline at end of file From 15ead38004ecbed71101788557425c5412f94ff6 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:43:08 +0100 Subject: [PATCH 215/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-rest-custom (finalized) --- .../main/java/com/baeldung/config/MainWebAppInitializer.java | 4 ++-- .../src/main/java/com/baeldung/config/child/WebConfig.java | 2 +- .../main/java/com/baeldung/config/parent/SecurityConfig.java | 2 +- .../main/java/com/baeldung/config/parent/ServiceConfig.java | 2 +- .../src/main/webapp/WEB-INF/web_old.xml | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/MainWebAppInitializer.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/MainWebAppInitializer.java index f24c96a686..4957a2604a 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/MainWebAppInitializer.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/MainWebAppInitializer.java @@ -30,7 +30,7 @@ public class MainWebAppInitializer implements WebApplicationInitializer { // Create the 'root' Spring application context final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); - root.scan("org.baeldung.config.parent"); + root.scan("com.baeldung.config.parent"); // root.getEnvironment().setDefaultProfiles("embedded"); // Manages the lifecycle of the root application context @@ -38,7 +38,7 @@ public class MainWebAppInitializer implements WebApplicationInitializer { // Handles requests into the application final AnnotationConfigWebApplicationContext childWebApplicationContext = new AnnotationConfigWebApplicationContext(); - childWebApplicationContext.scan("org.baeldung.config.child"); + childWebApplicationContext.scan("com.baeldung.config.child"); final ServletRegistration.Dynamic appServlet = sc.addServlet("api", new DispatcherServlet(childWebApplicationContext)); appServlet.setLoadOnStartup(1); final Set mappingConflicts = appServlet.addMapping("/"); diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/WebConfig.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/WebConfig.java index 0c95acc177..011528e3cc 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/WebConfig.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/child/WebConfig.java @@ -23,7 +23,7 @@ import org.thymeleaf.templateresolver.ITemplateResolver; @Configuration @EnableWebMvc -@ComponentScan("org.baeldung.web") +@ComponentScan("com.baeldung.web") //@ImportResource({ "classpath:prop.xml" }) //@PropertySource("classpath:foo.properties") public class WebConfig implements WebMvcConfigurer { diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/SecurityConfig.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/SecurityConfig.java index 36ce898fb6..c4d29ed5b7 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/SecurityConfig.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/SecurityConfig.java @@ -12,7 +12,7 @@ import org.springframework.security.config.annotation.web.configuration.WebSecur @Configuration //@ImportResource({ "classpath:webSecurityConfig.xml" }) @EnableWebSecurity -@ComponentScan("org.baeldung.security") +@ComponentScan("com.baeldung.security") public class SecurityConfig extends WebSecurityConfigurerAdapter { @Autowired diff --git a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/ServiceConfig.java b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/ServiceConfig.java index 6e45a32a87..55f837f674 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/ServiceConfig.java +++ b/spring-security-modules/spring-security-rest-custom/src/main/java/com/baeldung/config/parent/ServiceConfig.java @@ -7,7 +7,7 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; @Configuration -@ComponentScan("org.baeldung.service") +@ComponentScan("com.baeldung.service") // @ImportResource({ "classpath:prop.xml" }) @PropertySource("classpath:foo.properties") public class ServiceConfig { diff --git a/spring-security-modules/spring-security-rest-custom/src/main/webapp/WEB-INF/web_old.xml b/spring-security-modules/spring-security-rest-custom/src/main/webapp/WEB-INF/web_old.xml index 0fa9abd258..a498fdfd47 100644 --- a/spring-security-modules/spring-security-rest-custom/src/main/webapp/WEB-INF/web_old.xml +++ b/spring-security-modules/spring-security-rest-custom/src/main/webapp/WEB-INF/web_old.xml @@ -16,7 +16,7 @@ contextConfigLocation - org.baeldung.config.parent + com.baeldung.config.parent @@ -29,7 +29,7 @@ org.springframework.web.servlet.DispatcherServlet - + 1 From dee9427fb75f665a8bda63b200fc425892aa2e05 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:43:28 +0100 Subject: [PATCH 216/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-rest-basic-auth (finalized) --- .../src/main/java/com/baeldung/client/spring/ClientConfig.java | 2 +- .../src/main/java/com/baeldung/spring/SecSecurityConfig.java | 2 +- .../src/main/java/com/baeldung/spring/WebConfig.java | 2 +- .../src/main/webapp/WEB-INF/web.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/spring/ClientConfig.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/spring/ClientConfig.java index dd834628a6..03994b55a5 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/spring/ClientConfig.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/client/spring/ClientConfig.java @@ -4,7 +4,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration -@ComponentScan("org.baeldung.client") +@ComponentScan("com.baeldung.client") public class ClientConfig { public ClientConfig() { diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java index cddef4d508..4ba9d47f8d 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -6,7 +6,7 @@ import org.springframework.context.annotation.ImportResource; @Configuration @ImportResource({ "classpath:webSecurityConfig.xml" }) -@ComponentScan("org.baeldung.security") +@ComponentScan("com.baeldung.security") public class SecSecurityConfig { public SecSecurityConfig() { diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/WebConfig.java b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/WebConfig.java index e9d0d277f1..8d5c1dc7f1 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/WebConfig.java +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/java/com/baeldung/spring/WebConfig.java @@ -11,7 +11,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @Configuration @EnableWebMvc -@ComponentScan("org.baeldung.web") +@ComponentScan("com.baeldung.web") public class WebConfig implements WebMvcConfigurer { public WebConfig() { diff --git a/spring-security-modules/spring-security-rest-basic-auth/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-rest-basic-auth/src/main/webapp/WEB-INF/web.xml index 83b4aeb0a7..4b2dd54266 100644 --- a/spring-security-modules/spring-security-rest-basic-auth/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-rest-basic-auth/src/main/webapp/WEB-INF/web.xml @@ -12,7 +12,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring From 19c1d9fa11369efd819974b1b01400b87a89d553 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:43:46 +0100 Subject: [PATCH 217/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-sso (finalized) --- spring-security-modules/spring-security-sso/pom.xml | 2 +- .../spring-security-sso/spring-security-sso-auth-server/pom.xml | 2 +- .../spring-security-sso/spring-security-sso-kerberos/pom.xml | 2 +- .../spring-security-sso/spring-security-sso-ui-2/pom.xml | 2 +- .../spring-security-sso/spring-security-sso-ui/pom.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/spring-security-modules/spring-security-sso/pom.xml b/spring-security-modules/spring-security-sso/pom.xml index 3d9c1bf595..4e5bb49aa3 100644 --- a/spring-security-modules/spring-security-sso/pom.xml +++ b/spring-security-modules/spring-security-sso/pom.xml @@ -2,7 +2,7 @@ 4.0.0 - org.baeldung + com.baeldung spring-security-sso 1.0.0-SNAPSHOT spring-security-sso diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/pom.xml b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/pom.xml index 933cb6a2b2..3537c01e46 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/pom.xml +++ b/spring-security-modules/spring-security-sso/spring-security-sso-auth-server/pom.xml @@ -7,7 +7,7 @@ war - org.baeldung + com.baeldung spring-security-sso 1.0.0-SNAPSHOT diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/pom.xml b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/pom.xml index 88b9354538..0864ead1c4 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/pom.xml +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/pom.xml @@ -6,7 +6,7 @@ spring-security-sso-kerberos - org.baeldung + com.baeldung spring-security-sso 1.0.0-SNAPSHOT diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/pom.xml b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/pom.xml index 10592a5e92..0645ba3593 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/pom.xml +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui-2/pom.xml @@ -7,7 +7,7 @@ war - org.baeldung + com.baeldung spring-security-sso 1.0.0-SNAPSHOT diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-ui/pom.xml b/spring-security-modules/spring-security-sso/spring-security-sso-ui/pom.xml index 2f0ac3a42e..d34317a4b0 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-ui/pom.xml +++ b/spring-security-modules/spring-security-sso/spring-security-sso-ui/pom.xml @@ -7,7 +7,7 @@ war - org.baeldung + com.baeldung spring-security-sso 1.0.0-SNAPSHOT From 37fe2f968d6684842562a17586b5500ffd1ca0ae Mon Sep 17 00:00:00 2001 From: dupirefr Date: Thu, 19 Mar 2020 21:44:56 +0100 Subject: [PATCH 218/278] [JAVA-961] Standardize packages in spring-security-modules: spring-security-mvc --- .../java/com/baeldung/monitoring/MetricRegistrySingleton.java | 2 +- .../spring-security-mvc/src/main/webapp/WEB-INF/web.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java index e2224996c2..ce122db609 100644 --- a/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java +++ b/spring-security-modules/spring-security-mvc/src/main/java/com/baeldung/monitoring/MetricRegistrySingleton.java @@ -13,7 +13,7 @@ public final class MetricRegistrySingleton { public static final MetricRegistry metrics = new MetricRegistry(); static { - Logger logger = LoggerFactory.getLogger("org.baeldung.monitoring"); + Logger logger = LoggerFactory.getLogger("com.baeldung.monitoring"); final Slf4jReporter reporter = Slf4jReporter.forRegistry(metrics).outputTo(logger).convertRatesTo(TimeUnit.SECONDS).convertDurationsTo(TimeUnit.MILLISECONDS).build(); reporter.start(5, TimeUnit.MINUTES); } diff --git a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/web.xml b/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/web.xml index 88087c92ed..ec6bc0d3b4 100644 --- a/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-modules/spring-security-mvc/src/main/webapp/WEB-INF/web.xml @@ -30,7 +30,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring @@ -60,7 +60,7 @@ \ No newline at end of file From cac1779e0d10646f2c31eab47ac20747fc1283ea Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 16:52:39 +0530 Subject: [PATCH 220/278] JAVA-626 : retired modules java-math and java-math-2 --- java-math-2/README.md | 9 -- java-math-2/pom.xml | 29 ----- .../algorithms/gcd/GCDImplementation.java | 55 -------- java-math-2/src/main/resources/logback.xml | 13 -- .../gcd/GCDImplementationUnitTest.java | 32 ----- .../logarithm/LogarithmUnitTest.java | 31 ----- java-math/.gitignore | 4 - java-math/README.md | 16 --- java-math/pom.xml | 89 ------------- .../ApacheCommonsCombinationGenerator.java | 29 ----- .../CombinatoricsLibCombinationGenerator.java | 13 -- .../GuavaCombinationsGenerator.java | 17 --- .../IterativeCombinationGenerator.java | 52 -------- ...electionRecursiveCombinationGenerator.java | 53 -------- .../SetRecursiveCombinationGenerator.java | 50 -------- .../DistanceBetweenPointsService.java | 38 ------ .../algorithms/factorial/Factorial.java | 63 --------- .../LinesIntersectionService.java | 21 --- .../mercator/EllipticalMercator.java | 22 ---- .../algorithms/mercator/Mercator.java | 10 -- .../mercator/SphericalMercator.java | 14 -- .../percentage/PercentageCalculator.java | 21 --- .../algorithms/rectanglesoverlap/Point.java | 29 ----- .../rectanglesoverlap/Rectangle.java | 40 ------ .../roundedup/RoundUpToHundred.java | 20 --- .../com/baeldung/matrices/HomemadeMatrix.java | 23 ---- .../BigMatrixMultiplicationBenchmarking.java | 121 ------------------ .../matrices/benchmark/BigMatrixProvider.java | 46 ------- .../MatrixMultiplicationBenchmarking.java | 86 ------------- .../matrices/benchmark/MatrixProvider.java | 33 ----- java-math/src/main/resources/logback.xml | 13 -- .../combination/CombinationUnitTest.java | 35 ----- .../DistanceBetweenPointsServiceUnitTest.java | 52 -------- .../factorial/FactorialUnitTest.java | 72 ----------- .../LinesIntersectionServiceUnitTest.java | 40 ------ .../mercator/EllipticalMercatorUnitTest.java | 22 ---- .../mercator/SphericalMercatorUnitTest.java | 21 --- .../PercentageCalculatorUnitTest.java | 33 ----- .../rectanglesoverlap/RectangleUnitTest.java | 39 ------ .../roundedup/RoundUpToHundredUnitTest.java | 14 -- .../matrices/apache/RealMatrixUnitTest.java | 41 ------ .../matrices/colt/DoubleMatrix2DUnitTest.java | 46 ------- .../matrices/ejml/SimpleMatrixUnitTest.java | 41 ------ .../homemade/HomemadeMatrixUnitTest.java | 54 -------- .../matrices/la4j/Basic2DMatrixUnitTest.java | 42 ------ .../matrices/nd4j/INDArrayUnitTest.java | 42 ------ 46 files changed, 1686 deletions(-) delete mode 100644 java-math-2/README.md delete mode 100644 java-math-2/pom.xml delete mode 100644 java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java delete mode 100644 java-math-2/src/main/resources/logback.xml delete mode 100644 java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java delete mode 100644 java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java delete mode 100644 java-math/.gitignore delete mode 100644 java-math/README.md delete mode 100644 java-math/pom.xml delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java delete mode 100644 java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java delete mode 100644 java-math/src/main/java/com/baeldung/matrices/HomemadeMatrix.java delete mode 100644 java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java delete mode 100644 java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java delete mode 100644 java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java delete mode 100644 java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java delete mode 100644 java-math/src/main/resources/logback.xml delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java delete mode 100644 java-math/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java diff --git a/java-math-2/README.md b/java-math-2/README.md deleted file mode 100644 index 5345564d5d..0000000000 --- a/java-math-2/README.md +++ /dev/null @@ -1,9 +0,0 @@ -## Java Math - -This module contains articles about math in Java. - -### Relevant articles: - -- [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms) -- [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor) -- More articles: [[<-- prev]](/../java-math) diff --git a/java-math-2/pom.xml b/java-math-2/pom.xml deleted file mode 100644 index 7bc05a3a86..0000000000 --- a/java-math-2/pom.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - 4.0.0 - java-math-2 - 0.0.1-SNAPSHOT - java-math-2 - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.assertj - assertj-core - ${org.assertj.core.version} - test - - - - - - 3.9.0 - - - \ No newline at end of file diff --git a/java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java b/java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java deleted file mode 100644 index d4844abd9c..0000000000 --- a/java-math-2/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.baeldung.algorithms.gcd; - -public class GCDImplementation { - - public static int gcdByBruteForce(int n1, int n2) { - int gcd = 1; - for (int i = 1; i <= n1 && i <= n2; i++) { - if (n1 % i == 0 && n2 % i == 0) { - gcd = i; - } - } - return gcd; - } - - public static int gcdByEuclidsAlgorithm(int n1, int n2) { - if (n2 == 0) { - return n1; - } - return gcdByEuclidsAlgorithm(n2, n1 % n2); - } - - public static int gcdBySteinsAlgorithm(int n1, int n2) { - if (n1 == 0) { - return n2; - } - - if (n2 == 0) { - return n1; - } - - int n; - for (n = 0; ((n1 | n2) & 1) == 0; n++) { - n1 >>= 1; - n2 >>= 1; - } - - while ((n1 & 1) == 0) { - n1 >>= 1; - } - - do { - while ((n2 & 1) == 0) { - n2 >>= 1; - } - - if (n1 > n2) { - int temp = n1; - n1 = n2; - n2 = temp; - } - n2 = (n2 - n1); - } while (n2 != 0); - return n1 << n; - } -} diff --git a/java-math-2/src/main/resources/logback.xml b/java-math-2/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/java-math-2/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java b/java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java deleted file mode 100644 index d2c91a2eb8..0000000000 --- a/java-math-2/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.algorithms.gcd; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class GCDImplementationUnitTest { - - @Test - public void whenCalculatingGCDByBruteForceMethod_thenCorrect() { - int n1 = 60; - int n2 = 90; - int gcd = GCDImplementation.gcdByBruteForce(n1, n2); - assertThat(gcd).isEqualTo(30); - } - - @Test - public void whenCalculatingGCDByEuclidsAlgorithm_thenCorrect() { - int n1 = 60; - int n2 = 90; - int gcd = GCDImplementation.gcdByEuclidsAlgorithm(n1, n2); - assertThat(gcd).isEqualTo(30); - } - - @Test - public void whenCalculatingGCDBySteinsAlgorithm_thenCorrect() { - int n1 = 60; - int n2 = 90; - int gcd = GCDImplementation.gcdBySteinsAlgorithm(n1, n2); - assertThat(gcd).isEqualTo(30); - } -} diff --git a/java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java b/java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java deleted file mode 100644 index facad1edc4..0000000000 --- a/java-math-2/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.algorithms.logarithm; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.Test; - -public class LogarithmUnitTest { - - @Test - public void givenLog10_shouldReturnValidResults() { - assertEquals(Math.log10(100), 2); - assertEquals(Math.log10(1000), 3); - } - - @Test - public void givenLogE_shouldReturnValidResults() { - assertEquals(Math.log(Math.E), 1); - assertEquals(Math.log(10), 2.30258, 0.00001); - } - - @Test - public void givenCustomLog_shouldReturnValidResults() { - assertEquals(customLog(2, 256), 8); - assertEquals(customLog(10, 100), 2); - } - - private static double customLog(double base, double logNumber) { - return Math.log(logNumber) / Math.log(base); - } - -} diff --git a/java-math/.gitignore b/java-math/.gitignore deleted file mode 100644 index 30b2b7442c..0000000000 --- a/java-math/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -/target/ -.settings/ -.classpath -.project \ No newline at end of file diff --git a/java-math/README.md b/java-math/README.md deleted file mode 100644 index 49ff5afde1..0000000000 --- a/java-math/README.md +++ /dev/null @@ -1,16 +0,0 @@ -## Java Math - -This module contains articles about math in Java. - -### Relevant articles: - -- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) -- [Generate Combinations in Java](https://www.baeldung.com/java-combinations-algorithm) -- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap) -- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points) -- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines) -- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred) -- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage) -- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) -- [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging) -- [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication) diff --git a/java-math/pom.xml b/java-math/pom.xml deleted file mode 100644 index 9b4af4c13d..0000000000 --- a/java-math/pom.xml +++ /dev/null @@ -1,89 +0,0 @@ - - - 4.0.0 - java-math - 0.0.1-SNAPSHOT - java-math - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - org.apache.commons - commons-math3 - ${commons-math3.version} - - - org.ejml - ejml-all - ${ejml.version} - - - org.nd4j - nd4j-native - ${nd4j.version} - - - org.la4j - la4j - ${la4j.version} - - - colt - colt - ${colt.version} - - - com.google.guava - guava - ${guava.version} - - - org.assertj - assertj-core - ${org.assertj.core.version} - test - - - com.github.dpaukov - combinatoricslib3 - ${combinatoricslib3.version} - - - - org.openjdk.jmh - jmh-generator-annprocess - ${jmh.version} - - - - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - - - - 3.6.1 - 3.9.0 - 27.0.1-jre - 3.3.0 - 0.38 - 1.0.0-beta4 - 1.2.0 - 0.6.0 - 1.19 - - - \ No newline at end of file diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java deleted file mode 100644 index 40142ce940..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.algorithms.combination; - -import java.util.Arrays; -import java.util.Iterator; - -import org.apache.commons.math3.util.CombinatoricsUtils; - -public class ApacheCommonsCombinationGenerator { - - private static final int N = 6; - private static final int R = 3; - - /** - * Print all combinations of r elements from a set - * @param n - number of elements in set - * @param r - number of elements in selection - */ - public static void generate(int n, int r) { - Iterator iterator = CombinatoricsUtils.combinationsIterator(n, r); - while (iterator.hasNext()) { - final int[] combination = iterator.next(); - System.out.println(Arrays.toString(combination)); - } - } - - public static void main(String[] args) { - generate(N, R); - } -} \ No newline at end of file diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java deleted file mode 100644 index 0afdeefb8b..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.algorithms.combination; - -import org.paukov.combinatorics3.Generator; - -public class CombinatoricsLibCombinationGenerator { - - public static void main(String[] args) { - Generator.combination(0, 1, 2, 3, 4, 5) - .simple(3) - .stream() - .forEach(System.out::println); - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java deleted file mode 100644 index d2783881ba..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.baeldung.algorithms.combination; - -import java.util.Arrays; -import java.util.Set; - -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Sets; - -public class GuavaCombinationsGenerator { - - public static void main(String[] args) { - - Set> combinations = Sets.combinations(ImmutableSet.of(0, 1, 2, 3, 4, 5), 3); - System.out.println(combinations.size()); - System.out.println(Arrays.toString(combinations.toArray())); - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java deleted file mode 100644 index 676d2f41e3..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.algorithms.combination; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class IterativeCombinationGenerator { - - private static final int N = 5; - private static final int R = 2; - - /** - * Generate all combinations of r elements from a set - * @param n the number of elements in input set - * @param r the number of elements in a combination - * @return the list containing all combinations - */ - public List generate(int n, int r) { - List combinations = new ArrayList<>(); - int[] combination = new int[r]; - - // initialize with lowest lexicographic combination - for (int i = 0; i < r; i++) { - combination[i] = i; - } - - while (combination[r - 1] < n) { - combinations.add(combination.clone()); - - // generate next combination in lexicographic order - int t = r - 1; - while (t != 0 && combination[t] == n - r + t) { - t--; - } - combination[t]++; - for (int i = t + 1; i < r; i++) { - combination[i] = combination[i - 1] + 1; - } - } - - return combinations; - } - - public static void main(String[] args) { - IterativeCombinationGenerator generator = new IterativeCombinationGenerator(); - List combinations = generator.generate(N, R); - System.out.println(combinations.size()); - for (int[] combination : combinations) { - System.out.println(Arrays.toString(combination)); - } - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java deleted file mode 100644 index 52305b8c2f..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.baeldung.algorithms.combination; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class SelectionRecursiveCombinationGenerator { - - private static final int N = 6; - private static final int R = 3; - - /** - * Generate all combinations of r elements from a set - * @param n - number of elements in input set - * @param r - number of elements to be chosen - * @return the list containing all combinations - */ - public List generate(int n, int r) { - List combinations = new ArrayList<>(); - helper(combinations, new int[r], 0, n - 1, 0); - return combinations; - } - - /** - * Choose elements from set by recursing over elements selected - * @param combinations - List to store generated combinations - * @param data - current combination - * @param start - starting element of remaining set - * @param end - last element of remaining set - * @param index - number of elements chosen so far. - */ - private void helper(List combinations, int data[], int start, int end, int index) { - if (index == data.length) { - int[] combination = data.clone(); - combinations.add(combination); - } else { - int max = Math.min(end, end + 1 - data.length + index); - for (int i = start; i <= max; i++) { - data[index] = i; - helper(combinations, data, i + 1, end, index + 1); - } - } - } - - public static void main(String[] args) { - SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator(); - List combinations = generator.generate(N, R); - for (int[] combination : combinations) { - System.out.println(Arrays.toString(combination)); - } - System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N); - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java b/java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java deleted file mode 100644 index a73447b31d..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.baeldung.algorithms.combination; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -public class SetRecursiveCombinationGenerator { - - private static final int N = 5; - private static final int R = 2; - - /** - * Generate all combinations of r elements from a set - * @param n - number of elements in set - * @param r - number of elements in selection - * @return the list containing all combinations - */ - public List generate(int n, int r) { - List combinations = new ArrayList<>(); - helper(combinations, new int[r], 0, n-1, 0); - return combinations; - } - - /** - * @param combinations - List to contain the generated combinations - * @param data - List of elements in the selection - * @param start - index of the starting element in the remaining set - * @param end - index of the last element in the set - * @param index - number of elements selected so far - */ - private void helper(List combinations, int data[], int start, int end, int index) { - if (index == data.length) { - int[] combination = data.clone(); - combinations.add(combination); - } else if (start <= end) { - data[index] = start; - helper(combinations, data, start + 1, end, index + 1); - helper(combinations, data, start + 1, end, index); - } - } - - public static void main(String[] args) { - SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator(); - List combinations = generator.generate(N, R); - for (int[] combination : combinations) { - System.out.println(Arrays.toString(combination)); - } - System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N); - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java b/java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java deleted file mode 100644 index 0c8eb86a38..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.algorithms.distancebetweenpoints; - -import java.awt.geom.Point2D; - -public class DistanceBetweenPointsService { - - public double calculateDistanceBetweenPoints( - double x1, - double y1, - double x2, - double y2) { - - return Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1)); - } - - public double calculateDistanceBetweenPointsWithHypot( - double x1, - double y1, - double x2, - double y2) { - - double ac = Math.abs(y2 - y1); - double cb = Math.abs(x2 - x1); - - return Math.hypot(ac, cb); - } - - public double calculateDistanceBetweenPointsWithPoint2D( - double x1, - double y1, - double x2, - double y2) { - - return Point2D.distance(x1, y1, x2, y2); - - } - -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java b/java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java deleted file mode 100644 index 43d2221773..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/factorial/Factorial.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.algorithms.factorial; - -import java.math.BigInteger; -import java.util.stream.LongStream; - -import org.apache.commons.math3.util.CombinatoricsUtils; - -import com.google.common.math.BigIntegerMath; - -public class Factorial { - - public long factorialUsingForLoop(int n) { - long fact = 1; - for (int i = 2; i <= n; i++) { - fact = fact * i; - } - return fact; - } - - public long factorialUsingStreams(int n) { - return LongStream.rangeClosed(1, n) - .reduce(1, (long x, long y) -> x * y); - } - - public long factorialUsingRecursion(int n) { - if (n <= 2) { - return n; - } - return n * factorialUsingRecursion(n - 1); - } - - private Long[] factorials = new Long[20]; - - public long factorialUsingMemoize(int n) { - - if (factorials[n] != null) { - return factorials[n]; - } - - if (n <= 2) { - return n; - } - long nthValue = n * factorialUsingMemoize(n - 1); - factorials[n] = nthValue; - return nthValue; - } - - public BigInteger factorialHavingLargeResult(int n) { - BigInteger result = BigInteger.ONE; - for (int i = 2; i <= n; i++) - result = result.multiply(BigInteger.valueOf(i)); - return result; - } - - public long factorialUsingApacheCommons(int n) { - return CombinatoricsUtils.factorial(n); - } - - public BigInteger factorialUsingGuava(int n) { - return BigIntegerMath.factorial(n); - } - -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java b/java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java deleted file mode 100644 index 35d6c8b424..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.algorithms.linesintersection; - -import java.awt.Point; -import java.util.Optional; - -public class LinesIntersectionService { - - public Optional calculateIntersectionPoint(double m1, double b1, double m2, double b2) { - - if (m1 == m2) { - return Optional.empty(); - } - - double x = (b2 - b1) / (m1 - m2); - double y = m1 * x + b1; - - Point point = new Point(); - point.setLocation(x, y); - return Optional.of(point); - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java deleted file mode 100644 index e1c41f9518..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.algorithms.mercator; - -class EllipticalMercator extends Mercator { - - @Override - double yAxisProjection(double input) { - - input = Math.min(Math.max(input, -89.5), 89.5); - double earthDimensionalRateNormalized = 1.0 - Math.pow(RADIUS_MINOR / RADIUS_MAJOR, 2); - - double inputOnEarthProj = Math.sqrt(earthDimensionalRateNormalized) * Math.sin( Math.toRadians(input)); - - inputOnEarthProj = Math.pow(((1.0 - inputOnEarthProj)/(1.0+inputOnEarthProj)), 0.5 * Math.sqrt(earthDimensionalRateNormalized)); - double inputOnEarthProjNormalized = Math.tan(0.5 * ((Math.PI*0.5) - Math.toRadians(input)))/inputOnEarthProj; - return (-1) * RADIUS_MAJOR * Math.log(inputOnEarthProjNormalized); - } - - @Override - double xAxisProjection(double input) { - return RADIUS_MAJOR * Math.toRadians(input); - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java deleted file mode 100644 index b289b1839d..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/mercator/Mercator.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.baeldung.algorithms.mercator; - -abstract class Mercator { - final static double RADIUS_MAJOR = 6378137.0; - final static double RADIUS_MINOR = 6356752.3142; - - abstract double yAxisProjection(double input); - - abstract double xAxisProjection(double input); -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java b/java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java deleted file mode 100644 index 1be976d82e..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.algorithms.mercator; - -public class SphericalMercator extends Mercator { - - @Override - double xAxisProjection(double input) { - return Math.toRadians(input) * RADIUS_MAJOR; - } - - @Override - double yAxisProjection(double input) { - return Math.log(Math.tan(Math.PI / 4 + Math.toRadians(input) / 2)) * RADIUS_MAJOR; - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java b/java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java deleted file mode 100644 index f69b23146e..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.algorithms.percentage; - -import java.util.Scanner; - -public class PercentageCalculator { - - public double calculatePercentage(double obtained,double total){ - return obtained*100/total; - } - - public static void main(String[] args) { - PercentageCalculator pc = new PercentageCalculator(); - Scanner in = new Scanner(System.in); - System.out.println("Enter obtained marks:"); - double obtained = in.nextDouble(); - System.out.println("Enter total marks:"); - double total =in.nextDouble(); - System.out.println("Percentage obtained :"+pc.calculatePercentage(obtained,total)); - } - -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java b/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java deleted file mode 100644 index 68b1e7c594..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.baeldung.algorithms.rectanglesoverlap; - -public class Point { - - private int x; - private int y; - - public Point(int x, int y) { - this.x = x; - this.y = y; - } - - public int getX() { - return x; - } - - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java b/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java deleted file mode 100644 index 38f5edec61..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.algorithms.rectanglesoverlap; - -public class Rectangle { - - private Point bottomLeft; - private Point topRight; - - public Rectangle(Point bottomLeft, Point topRight) { - this.bottomLeft = bottomLeft; - this.topRight = topRight; - } - - public Point getBottomLeft() { - return bottomLeft; - } - - public void setBottomLeft(Point bottomLeft) { - this.bottomLeft = bottomLeft; - } - - public Point getTopRight() { - return topRight; - } - - public void setTopRight(Point topRight) { - this.topRight = topRight; - } - - public boolean isOverlapping(Rectangle other) { - // one rectangle is to the top of the other - if (this.topRight.getY() < other.bottomLeft.getY() || this.bottomLeft.getY() > other.topRight.getY()) { - return false; - } - // one rectangle is to the left of the other - if (this.topRight.getX() < other.bottomLeft.getX() || this.bottomLeft.getX() > other.topRight.getX()) { - return false; - } - return true; - } -} diff --git a/java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java b/java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java deleted file mode 100644 index 333019e294..0000000000 --- a/java-math/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.baeldung.algorithms.roundedup; - -import java.util.Scanner; - -public class RoundUpToHundred { - - public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - double input = scanner.nextDouble(); - scanner.close(); - - RoundUpToHundred.round(input); - } - - static long round(double input) { - long i = (long) Math.ceil(input); - return ((i + 99) / 100) * 100; - }; - -} diff --git a/java-math/src/main/java/com/baeldung/matrices/HomemadeMatrix.java b/java-math/src/main/java/com/baeldung/matrices/HomemadeMatrix.java deleted file mode 100644 index 0676250959..0000000000 --- a/java-math/src/main/java/com/baeldung/matrices/HomemadeMatrix.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.baeldung.matrices; - -public class HomemadeMatrix { - public static double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) { - double[][] result = new double[firstMatrix.length][secondMatrix[0].length]; - - for (int row = 0; row < result.length; row++) { - for (int col = 0; col < result[row].length; col++) { - result[row][col] = multiplyMatricesCell(firstMatrix, secondMatrix, row, col); - } - } - - return result; - } - - private static double multiplyMatricesCell(double[][] firstMatrix, double[][] secondMatrix, int row, int col) { - double cell = 0; - for (int i = 0; i < secondMatrix.length; i++) { - cell += firstMatrix[row][i] * secondMatrix[i][col]; - } - return cell; - } -} \ No newline at end of file diff --git a/java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java b/java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java deleted file mode 100644 index 2ed983f733..0000000000 --- a/java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java +++ /dev/null @@ -1,121 +0,0 @@ -package com.baeldung.matrices.benchmark; - -import cern.colt.matrix.DoubleFactory2D; -import cern.colt.matrix.DoubleMatrix2D; -import cern.colt.matrix.linalg.Algebra; -import com.baeldung.matrices.HomemadeMatrix; -import org.apache.commons.math3.linear.Array2DRowRealMatrix; -import org.apache.commons.math3.linear.RealMatrix; -import org.ejml.simple.SimpleMatrix; -import org.la4j.Matrix; -import org.la4j.matrix.dense.Basic2DMatrix; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.runner.Runner; -import org.openjdk.jmh.runner.options.ChainedOptionsBuilder; -import org.openjdk.jmh.runner.options.OptionsBuilder; - -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -public class BigMatrixMultiplicationBenchmarking { - private static final int DEFAULT_FORKS = 2; - private static final int DEFAULT_WARMUP_ITERATIONS = 5; - private static final int DEFAULT_MEASUREMENT_ITERATIONS = 10; - - public static void main(String[] args) throws Exception { - Map parameters = parseParameters(args); - - ChainedOptionsBuilder builder = new OptionsBuilder() - .include(BigMatrixMultiplicationBenchmarking.class.getSimpleName()) - .mode(Mode.AverageTime) - .forks(forks(parameters)) - .warmupIterations(warmupIterations(parameters)) - .measurementIterations(measurementIterations(parameters)) - .timeUnit(TimeUnit.SECONDS); - - parameters.forEach(builder::param); - - new Runner(builder.build()).run(); - } - - private static Map parseParameters(String[] args) { - return Arrays.stream(args) - .map(arg -> arg.split("=")) - .collect(Collectors.toMap( - arg -> arg[0], - arg -> arg[1] - )); - } - - private static int forks(Map parameters) { - String forks = parameters.remove("forks"); - return parseOrDefault(forks, DEFAULT_FORKS); - } - - private static int warmupIterations(Map parameters) { - String warmups = parameters.remove("warmupIterations"); - return parseOrDefault(warmups, DEFAULT_WARMUP_ITERATIONS); - } - - private static int measurementIterations(Map parameters) { - String measurements = parameters.remove("measurementIterations"); - return parseOrDefault(measurements, DEFAULT_MEASUREMENT_ITERATIONS); - } - - private static int parseOrDefault(String parameter, int defaultValue) { - return parameter != null ? Integer.parseInt(parameter) : defaultValue; - } - - @Benchmark - public Object homemadeMatrixMultiplication(BigMatrixProvider matrixProvider) { - return HomemadeMatrix.multiplyMatrices(matrixProvider.getFirstMatrix(), matrixProvider.getSecondMatrix()); - } - - @Benchmark - public Object ejmlMatrixMultiplication(BigMatrixProvider matrixProvider) { - SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); - SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); - - return firstMatrix.mult(secondMatrix); - } - - @Benchmark - public Object apacheCommonsMatrixMultiplication(BigMatrixProvider matrixProvider) { - RealMatrix firstMatrix = new Array2DRowRealMatrix(matrixProvider.getFirstMatrix()); - RealMatrix secondMatrix = new Array2DRowRealMatrix(matrixProvider.getSecondMatrix()); - - return firstMatrix.multiply(secondMatrix); - } - - @Benchmark - public Object la4jMatrixMultiplication(BigMatrixProvider matrixProvider) { - Matrix firstMatrix = new Basic2DMatrix(matrixProvider.getFirstMatrix()); - Matrix secondMatrix = new Basic2DMatrix(matrixProvider.getSecondMatrix()); - - return firstMatrix.multiply(secondMatrix); - } - - @Benchmark - public Object nd4jMatrixMultiplication(BigMatrixProvider matrixProvider) { - INDArray firstMatrix = Nd4j.create(matrixProvider.getFirstMatrix()); - INDArray secondMatrix = Nd4j.create(matrixProvider.getSecondMatrix()); - - return firstMatrix.mmul(secondMatrix); - } - - @Benchmark - public Object coltMatrixMultiplication(BigMatrixProvider matrixProvider) { - DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense; - - DoubleMatrix2D firstMatrix = doubleFactory2D.make(matrixProvider.getFirstMatrix()); - DoubleMatrix2D secondMatrix = doubleFactory2D.make(matrixProvider.getSecondMatrix()); - - Algebra algebra = new Algebra(); - return algebra.mult(firstMatrix, secondMatrix); - } -} \ No newline at end of file diff --git a/java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java b/java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java deleted file mode 100644 index d0f8a03fe3..0000000000 --- a/java-math/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.matrices.benchmark; - -import org.openjdk.jmh.annotations.Param; -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.Setup; -import org.openjdk.jmh.annotations.State; -import org.openjdk.jmh.infra.BenchmarkParams; - -import java.util.Random; -import java.util.stream.DoubleStream; - -@State(Scope.Benchmark) -public class BigMatrixProvider { - @Param({}) - private int matrixSize; - private double[][] firstMatrix; - private double[][] secondMatrix; - - public BigMatrixProvider() {} - - @Setup - public void setup(BenchmarkParams parameters) { - firstMatrix = createMatrix(matrixSize); - secondMatrix = createMatrix(matrixSize); - } - - private double[][] createMatrix(int matrixSize) { - Random random = new Random(); - - double[][] result = new double[matrixSize][matrixSize]; - for (int row = 0; row < result.length; row++) { - for (int col = 0; col < result[row].length; col++) { - result[row][col] = random.nextDouble(); - } - } - return result; - } - - public double[][] getFirstMatrix() { - return firstMatrix; - } - - public double[][] getSecondMatrix() { - return secondMatrix; - } -} \ No newline at end of file diff --git a/java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java b/java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java deleted file mode 100644 index fdb423e8da..0000000000 --- a/java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.baeldung.matrices.benchmark; - -import cern.colt.matrix.DoubleFactory2D; -import cern.colt.matrix.DoubleMatrix2D; -import cern.colt.matrix.linalg.Algebra; -import com.baeldung.matrices.HomemadeMatrix; -import org.apache.commons.math3.linear.Array2DRowRealMatrix; -import org.apache.commons.math3.linear.RealMatrix; -import org.ejml.simple.SimpleMatrix; -import org.la4j.Matrix; -import org.la4j.matrix.dense.Basic2DMatrix; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.openjdk.jmh.annotations.Benchmark; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.runner.Runner; -import org.openjdk.jmh.runner.options.Options; -import org.openjdk.jmh.runner.options.OptionsBuilder; - -import java.util.concurrent.TimeUnit; - -public class MatrixMultiplicationBenchmarking { - - public static void main(String[] args) throws Exception { - Options opt = new OptionsBuilder() - .include(MatrixMultiplicationBenchmarking.class.getSimpleName()) - .exclude(BigMatrixMultiplicationBenchmarking.class.getSimpleName()) - .mode(Mode.AverageTime) - .forks(2) - .warmupIterations(10) - .measurementIterations(10) - .timeUnit(TimeUnit.MICROSECONDS) - .build(); - - new Runner(opt).run(); - } - - @Benchmark - public Object homemadeMatrixMultiplication(MatrixProvider matrixProvider) { - return HomemadeMatrix.multiplyMatrices(matrixProvider.getFirstMatrix(), matrixProvider.getSecondMatrix()); - } - - @Benchmark - public Object ejmlMatrixMultiplication(MatrixProvider matrixProvider) { - SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); - SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); - - return firstMatrix.mult(secondMatrix); - } - - @Benchmark - public Object apacheCommonsMatrixMultiplication(MatrixProvider matrixProvider) { - RealMatrix firstMatrix = new Array2DRowRealMatrix(matrixProvider.getFirstMatrix()); - RealMatrix secondMatrix = new Array2DRowRealMatrix(matrixProvider.getSecondMatrix()); - - return firstMatrix.multiply(secondMatrix); - } - - @Benchmark - public Object la4jMatrixMultiplication(MatrixProvider matrixProvider) { - Matrix firstMatrix = new Basic2DMatrix(matrixProvider.getFirstMatrix()); - Matrix secondMatrix = new Basic2DMatrix(matrixProvider.getSecondMatrix()); - - return firstMatrix.multiply(secondMatrix); - } - - @Benchmark - public Object nd4jMatrixMultiplication(MatrixProvider matrixProvider) { - INDArray firstMatrix = Nd4j.create(matrixProvider.getFirstMatrix()); - INDArray secondMatrix = Nd4j.create(matrixProvider.getSecondMatrix()); - - return firstMatrix.mmul(secondMatrix); - } - - @Benchmark - public Object coltMatrixMultiplication(MatrixProvider matrixProvider) { - DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense; - - DoubleMatrix2D firstMatrix = doubleFactory2D.make(matrixProvider.getFirstMatrix()); - DoubleMatrix2D secondMatrix = doubleFactory2D.make(matrixProvider.getSecondMatrix()); - - Algebra algebra = new Algebra(); - return algebra.mult(firstMatrix, secondMatrix); - } - -} \ No newline at end of file diff --git a/java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java b/java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java deleted file mode 100644 index d401ba2ab6..0000000000 --- a/java-math/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.matrices.benchmark; - -import org.openjdk.jmh.annotations.Scope; -import org.openjdk.jmh.annotations.State; - -@State(Scope.Benchmark) -public class MatrixProvider { - private double[][] firstMatrix; - private double[][] secondMatrix; - - public MatrixProvider() { - firstMatrix = - new double[][] { - new double[] {1d, 5d}, - new double[] {2d, 3d}, - new double[] {1d ,7d} - }; - - secondMatrix = - new double[][] { - new double[] {1d, 2d, 3d, 7d}, - new double[] {5d, 2d, 8d, 1d} - }; - } - - public double[][] getFirstMatrix() { - return firstMatrix; - } - - public double[][] getSecondMatrix() { - return secondMatrix; - } -} \ No newline at end of file diff --git a/java-math/src/main/resources/logback.xml b/java-math/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/java-math/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java deleted file mode 100644 index 987b6ddae6..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.baeldung.algorithms.combination; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.List; - -import org.junit.Test; - -public class CombinationUnitTest { - - private static final int N = 5; - private static final int R = 3; - private static final int nCr = 10; - - @Test - public void givenSetAndSelectionSize_whenCalculatedUsingSetRecursiveAlgorithm_thenExpectedCount() { - SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator(); - List selection = generator.generate(N, R); - assertEquals(nCr, selection.size()); - } - - @Test - public void givenSetAndSelectionSize_whenCalculatedUsingSelectionRecursiveAlgorithm_thenExpectedCount() { - SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator(); - List selection = generator.generate(N, R); - assertEquals(nCr, selection.size()); - } - - @Test - public void givenSetAndSelectionSize_whenCalculatedUsingIterativeAlgorithm_thenExpectedCount() { - IterativeCombinationGenerator generator = new IterativeCombinationGenerator(); - List selection = generator.generate(N, R); - assertEquals(nCr, selection.size()); - } -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java deleted file mode 100644 index 784681a807..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.baeldung.algorithms.distancebetweenpoints; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class DistanceBetweenPointsServiceUnitTest { - - private DistanceBetweenPointsService service = new DistanceBetweenPointsService(); - - @Test - public void givenTwoPoints_whenCalculateDistanceByFormula_thenCorrect() { - - double x1 = 3; - double y1 = 4; - double x2 = 7; - double y2 = 1; - - double distance = service.calculateDistanceBetweenPoints(x1, y1, x2, y2); - - assertEquals(distance, 5, 0.001); - - } - - @Test - public void givenTwoPoints_whenCalculateDistanceWithHypot_thenCorrect() { - - double x1 = 3; - double y1 = 4; - double x2 = 7; - double y2 = 1; - - double distance = service.calculateDistanceBetweenPointsWithHypot(x1, y1, x2, y2); - - assertEquals(distance, 5, 0.001); - - } - - @Test - public void givenTwoPoints_whenCalculateDistanceWithPoint2D_thenCorrect() { - - double x1 = 3; - double y1 = 4; - double x2 = 7; - double y2 = 1; - - double distance = service.calculateDistanceBetweenPointsWithPoint2D(x1, y1, x2, y2); - - assertEquals(distance, 5, 0.001); - - } -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java deleted file mode 100644 index c185dba62b..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.baeldung.algorithms.factorial; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.math.BigInteger; - -import org.junit.Before; -import org.junit.Test; - -public class FactorialUnitTest { - - Factorial factorial; - - @Before - public void setup() { - factorial = new Factorial(); - } - - @Test - public void whenCalculatingFactorialUsingForLoop_thenCorrect() { - int n = 5; - - assertThat(factorial.factorialUsingForLoop(n)).isEqualTo(120); - } - - @Test - public void whenCalculatingFactorialUsingStreams_thenCorrect() { - int n = 5; - - assertThat(factorial.factorialUsingStreams(n)).isEqualTo(120); - } - - @Test - public void whenCalculatingFactorialUsingRecursion_thenCorrect() { - int n = 5; - - assertThat(factorial.factorialUsingRecursion(n)).isEqualTo(120); - } - - @Test - public void whenCalculatingFactorialUsingMemoize_thenCorrect() { - int n = 5; - - assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(120); - - n = 6; - - assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(720); - } - - @Test - public void whenCalculatingFactorialHavingLargeResult_thenCorrect() { - int n = 22; - - assertThat(factorial.factorialHavingLargeResult(n)).isEqualTo(new BigInteger("1124000727777607680000")); - } - - @Test - public void whenCalculatingFactorialUsingApacheCommons_thenCorrect() { - int n = 5; - - assertThat(factorial.factorialUsingApacheCommons(n)).isEqualTo(120); - } - - @Test - public void whenCalculatingFactorialUsingGuava_thenCorrect() { - int n = 22; - - assertThat(factorial.factorialUsingGuava(n)).isEqualTo(new BigInteger("1124000727777607680000")); - } - -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java deleted file mode 100644 index 22371107f3..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.algorithms.linesintersection; - -import java.awt.Point; -import java.util.Optional; - -import org.junit.Test; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertEquals; - -public class LinesIntersectionServiceUnitTest { - private LinesIntersectionService service = new LinesIntersectionService(); - - @Test - public void givenNotParallelLines_whenCalculatePoint_thenPresent() { - - double m1 = 0; - double b1 = 0; - double m2 = 1; - double b2 = -1; - - Optional point = service.calculateIntersectionPoint(m1, b1, m2, b2); - - assertTrue(point.isPresent()); - assertEquals(point.get().getX(), 1, 0.001); - assertEquals(point.get().getY(), 0, 0.001); - } - - @Test - public void givenParallelLines_whenCalculatePoint_thenEmpty() { - double m1 = 1; - double b1 = 0; - double m2 = 1; - double b2 = -1; - - Optional point = service.calculateIntersectionPoint(m1, b1, m2, b2); - - assertFalse(point.isPresent()); - } -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java deleted file mode 100644 index 96b644c46c..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.algorithms.mercator; - -import org.junit.Assert; -import org.junit.Test; - - -public class EllipticalMercatorUnitTest { - - @Test - public void giventThatTheInputIs22_whenXAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { - Mercator mercator = new EllipticalMercator(); - double result = mercator.xAxisProjection(22); - Assert.assertEquals(result, 2449028.7974520186, 0.0); - } - - @Test - public void giventThatTheInputIs44_whenYAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { - Mercator mercator = new EllipticalMercator(); - double result = mercator.yAxisProjection(44); - Assert.assertEquals(result, 5435749.887511954, 0.0); - } -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java deleted file mode 100644 index 348c6ad3e4..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.baeldung.algorithms.mercator; - -import org.junit.Assert; -import org.junit.Test; - -public class SphericalMercatorUnitTest { - - @Test - public void giventThatTheInputIs22_whenXAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { - Mercator mercator = new SphericalMercator(); - double result = mercator.xAxisProjection(22); - Assert.assertEquals(result, 2449028.7974520186, 0.0); - } - - @Test - public void giventThatTheInputIs44_whenYAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { - Mercator mercator = new SphericalMercator(); - double result = mercator.yAxisProjection(44); - Assert.assertEquals(result, 5465442.183322753, 0.0); - } -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java deleted file mode 100644 index e49acc0c4b..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.algorithms.percentage; - -import org.junit.Assert; -import org.junit.Test; - -public class PercentageCalculatorUnitTest { - private PercentageCalculator pc = new PercentageCalculator(); - - @Test - public void whenPass2Integers_thenShouldCalculatePercentage(){ - Assert.assertEquals("Result not as expected", - 50.0,pc.calculatePercentage(50,100),0.1); - } - - @Test - public void whenPassObtainedMarksAsDouble_thenShouldCalculatePercentage(){ - Assert.assertEquals("Result not as expected",5.05, - pc.calculatePercentage(50.5,1000),0.1); - } - - @Test - public void whenPassTotalMarksAsDouble_thenShouldCalculatePercentage(){ - Assert.assertEquals("Result not as expected",19.6, - pc.calculatePercentage(5,25.5),0.1); - } - - @Test - public void whenPass2DoubleNumbers_thenShouldCalculatePercentage(){ - Assert.assertEquals("Result not as expected",20, - pc.calculatePercentage(5.5,27.5),0.1); - } - -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java deleted file mode 100644 index e4bb614b48..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.baeldung.algorithms.rectanglesoverlap; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertFalse; -import org.junit.Test; - -public class RectangleUnitTest { - - @Test - public void givenTwoOverlappingRectangles_whenisOverlappingCalled_shouldReturnTrue() { - Rectangle rectangle1 = new Rectangle(new Point(2, 1), new Point(4, 3)); - Rectangle rectangle2 = new Rectangle(new Point(1, 1), new Point(6, 4)); - assertTrue(rectangle1.isOverlapping(rectangle2)); - - rectangle1 = new Rectangle(new Point(-5, -2), new Point(2, 3)); - rectangle2 = new Rectangle(new Point(-2, -1), new Point(5, 2)); - assertTrue(rectangle1.isOverlapping(rectangle2)); - - rectangle1 = new Rectangle(new Point(-5, 1), new Point(2, 4)); - rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, 5)); - assertTrue(rectangle1.isOverlapping(rectangle2)); - } - - @Test - public void givenTwoNonOverlappingRectangles_whenisOverlappingCalled_shouldReturnFalse() { - Rectangle rectangle1 = new Rectangle(new Point(-5, 1), new Point(-3, 4)); - Rectangle rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, 5)); - assertFalse(rectangle1.isOverlapping(rectangle2)); - - rectangle1 = new Rectangle(new Point(-5, 1), new Point(3, 4)); - rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, -1)); - assertFalse(rectangle1.isOverlapping(rectangle2)); - - rectangle1 = new Rectangle(new Point(-2, 1), new Point(0, 3)); - rectangle2 = new Rectangle(new Point(3, 1), new Point(5, 4)); - assertFalse(rectangle1.isOverlapping(rectangle2)); - } - -} diff --git a/java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java b/java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java deleted file mode 100644 index 5191d65787..0000000000 --- a/java-math/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.algorithms.roundedup; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -public class RoundUpToHundredUnitTest { - @Test - public void givenInput_whenRound_thenRoundUpToTheNearestHundred() { - assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99)); - assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2)); - assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400)); - } -} diff --git a/java-math/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java b/java-math/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java deleted file mode 100644 index e7d99fbe3e..0000000000 --- a/java-math/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.matrices.apache; - -import org.apache.commons.math3.linear.Array2DRowRealMatrix; -import org.apache.commons.math3.linear.RealMatrix; -import org.junit.jupiter.api.Test; -import org.openjdk.jmh.annotations.*; - -import static org.assertj.core.api.Assertions.assertThat; - -class RealMatrixUnitTest { - - @Test - void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { - RealMatrix firstMatrix = new Array2DRowRealMatrix( - new double[][] { - new double[] {1d, 5d}, - new double[] {2d, 3d}, - new double[] {1d ,7d} - } - ); - - RealMatrix secondMatrix = new Array2DRowRealMatrix( - new double[][] { - new double[] {1d, 2d, 3d, 7d}, - new double[] {5d, 2d, 8d, 1d} - } - ); - - RealMatrix expected = new Array2DRowRealMatrix( - new double[][] { - new double[] {26d, 12d, 43d, 12d}, - new double[] {17d, 10d, 30d, 17d}, - new double[] {36d, 16d, 59d, 14d} - } - ); - - RealMatrix actual = firstMatrix.multiply(secondMatrix); - - assertThat(actual).isEqualTo(expected); - } -} diff --git a/java-math/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java b/java-math/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java deleted file mode 100644 index da66cd7d61..0000000000 --- a/java-math/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.baeldung.matrices.colt; - -import cern.colt.matrix.DoubleFactory2D; -import cern.colt.matrix.DoubleMatrix2D; -import cern.colt.matrix.linalg.Algebra; -import org.junit.jupiter.api.Test; -import org.openjdk.jmh.annotations.*; - -import static org.assertj.core.api.Assertions.assertThat; - -class DoubleMatrix2DUnitTest { - - @Test - void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { - DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense; - - DoubleMatrix2D firstMatrix = doubleFactory2D.make( - new double[][] { - new double[] {1d, 5d}, - new double[] {2d, 3d}, - new double[] {1d ,7d} - } - ); - - DoubleMatrix2D secondMatrix = doubleFactory2D.make( - new double[][] { - new double[] {1d, 2d, 3d, 7d}, - new double[] {5d, 2d, 8d, 1d} - } - ); - - DoubleMatrix2D expected = doubleFactory2D.make( - new double[][] { - new double[] {26d, 12d, 43d, 12d}, - new double[] {17d, 10d, 30d, 17d}, - new double[] {36d, 16d, 59d, 14d} - } - ); - - Algebra algebra = new Algebra(); - DoubleMatrix2D actual = algebra.mult(firstMatrix, secondMatrix); - - assertThat(actual).isEqualTo(expected); - } - -} \ No newline at end of file diff --git a/java-math/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java b/java-math/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java deleted file mode 100644 index 60381ece63..0000000000 --- a/java-math/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.baeldung.matrices.ejml; - -import org.ejml.simple.SimpleMatrix; -import org.junit.jupiter.api.Test; -import org.openjdk.jmh.annotations.*; - -import static org.assertj.core.api.Assertions.assertThat; - -class SimpleMatrixUnitTest { - - @Test - void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { - SimpleMatrix firstMatrix = new SimpleMatrix( - new double[][] { - new double[] {1d, 5d}, - new double[] {2d, 3d}, - new double[] {1d ,7d} - } - ); - - SimpleMatrix secondMatrix = new SimpleMatrix( - new double[][] { - new double[] {1d, 2d, 3d, 7d}, - new double[] {5d, 2d, 8d, 1d} - } - ); - - SimpleMatrix expected = new SimpleMatrix( - new double[][] { - new double[] {26d, 12d, 43d, 12d}, - new double[] {17d, 10d, 30d, 17d}, - new double[] {36d, 16d, 59d, 14d} - } - ); - - SimpleMatrix actual = firstMatrix.mult(secondMatrix); - - assertThat(actual).matches(m -> m.isIdentical(expected, 0d)); - } - -} \ No newline at end of file diff --git a/java-math/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java b/java-math/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java deleted file mode 100644 index d1a062ee79..0000000000 --- a/java-math/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.baeldung.matrices.homemade; - -import org.junit.jupiter.api.Test; -import org.openjdk.jmh.annotations.*; - -import static org.assertj.core.api.Assertions.assertThat; - -class HomemadeMatrixUnitTest { - - @Test - void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { - double[][] firstMatrix = { - new double[]{1d, 5d}, - new double[]{2d, 3d}, - new double[]{1d, 7d} - }; - - double[][] secondMatrix = { - new double[]{1d, 2d, 3d, 7d}, - new double[]{5d, 2d, 8d, 1d} - }; - - double[][] expected = { - new double[]{26d, 12d, 43d, 12d}, - new double[]{17d, 10d, 30d, 17d}, - new double[]{36d, 16d, 59d, 14d} - }; - - double[][] actual = multiplyMatrices(firstMatrix, secondMatrix); - - assertThat(actual).isEqualTo(expected); - } - - private double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) { - double[][] result = new double[firstMatrix.length][secondMatrix[0].length]; - - for (int row = 0; row < result.length; row++) { - for (int col = 0; col < result[row].length; col++) { - result[row][col] = multiplyMatricesCell(firstMatrix, secondMatrix, row, col); - } - } - - return result; - } - - private double multiplyMatricesCell(double[][] firstMatrix, double[][] secondMatrix, int row, int col) { - double cell = 0; - for (int i = 0; i < secondMatrix.length; i++) { - cell += firstMatrix[row][i] * secondMatrix[i][col]; - } - return cell; - } - -} \ No newline at end of file diff --git a/java-math/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java b/java-math/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java deleted file mode 100644 index 01731a3dd5..0000000000 --- a/java-math/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.matrices.la4j; - -import org.junit.jupiter.api.Test; -import org.la4j.Matrix; -import org.la4j.matrix.dense.Basic2DMatrix; -import org.openjdk.jmh.annotations.*; - -import static org.assertj.core.api.Assertions.assertThat; - -class Basic2DMatrixUnitTest { - - @Test - void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { - Matrix firstMatrix = new Basic2DMatrix( - new double[][]{ - new double[]{1d, 5d}, - new double[]{2d, 3d}, - new double[]{1d, 7d} - } - ); - - Matrix secondMatrix = new Basic2DMatrix( - new double[][]{ - new double[]{1d, 2d, 3d, 7d}, - new double[]{5d, 2d, 8d, 1d} - } - ); - - Matrix expected = new Basic2DMatrix( - new double[][]{ - new double[]{26d, 12d, 43d, 12d}, - new double[]{17d, 10d, 30d, 17d}, - new double[]{36d, 16d, 59d, 14d} - } - ); - - Matrix actual = firstMatrix.multiply(secondMatrix); - - assertThat(actual).isEqualTo(expected); - } - -} \ No newline at end of file diff --git a/java-math/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java b/java-math/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java deleted file mode 100644 index 72ef60a571..0000000000 --- a/java-math/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.baeldung.matrices.nd4j; - -import org.junit.jupiter.api.Test; -import org.nd4j.linalg.api.ndarray.INDArray; -import org.nd4j.linalg.factory.Nd4j; -import org.openjdk.jmh.annotations.*; - -import static org.assertj.core.api.Assertions.assertThat; - -class INDArrayUnitTest { - - @Test - void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { - INDArray firstMatrix = Nd4j.create( - new double[][]{ - new double[]{1d, 5d}, - new double[]{2d, 3d}, - new double[]{1d, 7d} - } - ); - - INDArray secondMatrix = Nd4j.create( - new double[][] { - new double[] {1d, 2d, 3d, 7d}, - new double[] {5d, 2d, 8d, 1d} - } - ); - - INDArray expected = Nd4j.create( - new double[][] { - new double[] {26d, 12d, 43d, 12d}, - new double[] {17d, 10d, 30d, 17d}, - new double[] {36d, 16d, 59d, 14d} - } - ); - - INDArray actual = firstMatrix.mmul(secondMatrix); - - assertThat(actual).isEqualTo(expected); - } - -} \ No newline at end of file From 05e0753a9cd40eb33b32430ae2503540bfa06449 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 16:55:04 +0530 Subject: [PATCH 221/278] JAVA-626: Added 3 articles --- .../core-java-lang-math/README.md | 4 ++ .../algorithms/gcd/GCDImplementation.java | 55 +++++++++++++++++++ .../percentage/PercentageCalculator.java | 21 +++++++ .../gcd/GCDImplementationUnitTest.java | 32 +++++++++++ .../logarithm/LogarithmUnitTest.java | 31 +++++++++++ .../PercentageCalculatorUnitTest.java | 33 +++++++++++ 6 files changed, 176 insertions(+) create mode 100644 core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java create mode 100644 core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java create mode 100644 core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java create mode 100644 core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java create mode 100644 core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java diff --git a/core-java-modules/core-java-lang-math/README.md b/core-java-modules/core-java-lang-math/README.md index ec97a2ada4..8a822d75fd 100644 --- a/core-java-modules/core-java-lang-math/README.md +++ b/core-java-modules/core-java-lang-math/README.md @@ -10,3 +10,7 @@ - [Basic Calculator in Java](https://www.baeldung.com/java-basic-calculator) - [Overflow and Underflow in Java](https://www.baeldung.com/java-overflow-underflow) - [Obtaining a Power Set of a Set in Java](https://www.baeldung.com/java-power-set-of-a-set) +- [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms) +- [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor) +- [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage) +- More articles: [[<-- next]](/../core-java-lang-math-2) diff --git a/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java new file mode 100644 index 0000000000..d4844abd9c --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/gcd/GCDImplementation.java @@ -0,0 +1,55 @@ +package com.baeldung.algorithms.gcd; + +public class GCDImplementation { + + public static int gcdByBruteForce(int n1, int n2) { + int gcd = 1; + for (int i = 1; i <= n1 && i <= n2; i++) { + if (n1 % i == 0 && n2 % i == 0) { + gcd = i; + } + } + return gcd; + } + + public static int gcdByEuclidsAlgorithm(int n1, int n2) { + if (n2 == 0) { + return n1; + } + return gcdByEuclidsAlgorithm(n2, n1 % n2); + } + + public static int gcdBySteinsAlgorithm(int n1, int n2) { + if (n1 == 0) { + return n2; + } + + if (n2 == 0) { + return n1; + } + + int n; + for (n = 0; ((n1 | n2) & 1) == 0; n++) { + n1 >>= 1; + n2 >>= 1; + } + + while ((n1 & 1) == 0) { + n1 >>= 1; + } + + do { + while ((n2 & 1) == 0) { + n2 >>= 1; + } + + if (n1 > n2) { + int temp = n1; + n1 = n2; + n2 = temp; + } + n2 = (n2 - n1); + } while (n2 != 0); + return n1 << n; + } +} diff --git a/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java new file mode 100644 index 0000000000..f69b23146e --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/main/java/com/baeldung/algorithms/percentage/PercentageCalculator.java @@ -0,0 +1,21 @@ +package com.baeldung.algorithms.percentage; + +import java.util.Scanner; + +public class PercentageCalculator { + + public double calculatePercentage(double obtained,double total){ + return obtained*100/total; + } + + public static void main(String[] args) { + PercentageCalculator pc = new PercentageCalculator(); + Scanner in = new Scanner(System.in); + System.out.println("Enter obtained marks:"); + double obtained = in.nextDouble(); + System.out.println("Enter total marks:"); + double total =in.nextDouble(); + System.out.println("Percentage obtained :"+pc.calculatePercentage(obtained,total)); + } + +} diff --git a/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java new file mode 100644 index 0000000000..d2c91a2eb8 --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/gcd/GCDImplementationUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.algorithms.gcd; + +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GCDImplementationUnitTest { + + @Test + public void whenCalculatingGCDByBruteForceMethod_thenCorrect() { + int n1 = 60; + int n2 = 90; + int gcd = GCDImplementation.gcdByBruteForce(n1, n2); + assertThat(gcd).isEqualTo(30); + } + + @Test + public void whenCalculatingGCDByEuclidsAlgorithm_thenCorrect() { + int n1 = 60; + int n2 = 90; + int gcd = GCDImplementation.gcdByEuclidsAlgorithm(n1, n2); + assertThat(gcd).isEqualTo(30); + } + + @Test + public void whenCalculatingGCDBySteinsAlgorithm_thenCorrect() { + int n1 = 60; + int n2 = 90; + int gcd = GCDImplementation.gcdBySteinsAlgorithm(n1, n2); + assertThat(gcd).isEqualTo(30); + } +} diff --git a/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java new file mode 100644 index 0000000000..facad1edc4 --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/logarithm/LogarithmUnitTest.java @@ -0,0 +1,31 @@ +package com.baeldung.algorithms.logarithm; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Test; + +public class LogarithmUnitTest { + + @Test + public void givenLog10_shouldReturnValidResults() { + assertEquals(Math.log10(100), 2); + assertEquals(Math.log10(1000), 3); + } + + @Test + public void givenLogE_shouldReturnValidResults() { + assertEquals(Math.log(Math.E), 1); + assertEquals(Math.log(10), 2.30258, 0.00001); + } + + @Test + public void givenCustomLog_shouldReturnValidResults() { + assertEquals(customLog(2, 256), 8); + assertEquals(customLog(10, 100), 2); + } + + private static double customLog(double base, double logNumber) { + return Math.log(logNumber) / Math.log(base); + } + +} diff --git a/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java new file mode 100644 index 0000000000..e49acc0c4b --- /dev/null +++ b/core-java-modules/core-java-lang-math/src/test/java/com/baeldung/algorithms/percentage/PercentageCalculatorUnitTest.java @@ -0,0 +1,33 @@ +package com.baeldung.algorithms.percentage; + +import org.junit.Assert; +import org.junit.Test; + +public class PercentageCalculatorUnitTest { + private PercentageCalculator pc = new PercentageCalculator(); + + @Test + public void whenPass2Integers_thenShouldCalculatePercentage(){ + Assert.assertEquals("Result not as expected", + 50.0,pc.calculatePercentage(50,100),0.1); + } + + @Test + public void whenPassObtainedMarksAsDouble_thenShouldCalculatePercentage(){ + Assert.assertEquals("Result not as expected",5.05, + pc.calculatePercentage(50.5,1000),0.1); + } + + @Test + public void whenPassTotalMarksAsDouble_thenShouldCalculatePercentage(){ + Assert.assertEquals("Result not as expected",19.6, + pc.calculatePercentage(5,25.5),0.1); + } + + @Test + public void whenPass2DoubleNumbers_thenShouldCalculatePercentage(){ + Assert.assertEquals("Result not as expected",20, + pc.calculatePercentage(5.5,27.5),0.1); + } + +} From 96cfd0af12cf909a57ceecbdb1df8436f0cd83b2 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 16:56:34 +0530 Subject: [PATCH 222/278] JAVA-626 : Added new module, replacement for the retired java-math --- .../core-java-lang-math-2/.gitignore | 4 + .../core-java-lang-math-2/README.md | 16 +++ .../core-java-lang-math-2/pom.xml | 90 +++++++++++++ .../ApacheCommonsCombinationGenerator.java | 29 +++++ .../CombinatoricsLibCombinationGenerator.java | 13 ++ .../GuavaCombinationsGenerator.java | 17 +++ .../IterativeCombinationGenerator.java | 52 ++++++++ ...electionRecursiveCombinationGenerator.java | 53 ++++++++ .../SetRecursiveCombinationGenerator.java | 50 ++++++++ .../DistanceBetweenPointsService.java | 38 ++++++ .../algorithms/factorial/Factorial.java | 63 +++++++++ .../LinesIntersectionService.java | 21 +++ .../mercator/EllipticalMercator.java | 22 ++++ .../algorithms/mercator/Mercator.java | 10 ++ .../mercator/SphericalMercator.java | 14 ++ .../algorithms/rectanglesoverlap/Point.java | 29 +++++ .../rectanglesoverlap/Rectangle.java | 40 ++++++ .../roundedup/RoundUpToHundred.java | 20 +++ .../com/baeldung/matrices/HomemadeMatrix.java | 23 ++++ .../BigMatrixMultiplicationBenchmarking.java | 121 ++++++++++++++++++ .../matrices/benchmark/BigMatrixProvider.java | 46 +++++++ .../MatrixMultiplicationBenchmarking.java | 86 +++++++++++++ .../matrices/benchmark/MatrixProvider.java | 33 +++++ .../src/main/resources/logback.xml | 13 ++ .../combination/CombinationUnitTest.java | 35 +++++ .../DistanceBetweenPointsServiceUnitTest.java | 52 ++++++++ .../factorial/FactorialUnitTest.java | 72 +++++++++++ .../LinesIntersectionServiceUnitTest.java | 40 ++++++ .../mercator/EllipticalMercatorUnitTest.java | 22 ++++ .../mercator/SphericalMercatorUnitTest.java | 21 +++ .../rectanglesoverlap/RectangleUnitTest.java | 39 ++++++ .../roundedup/RoundUpToHundredUnitTest.java | 14 ++ .../matrices/apache/RealMatrixUnitTest.java | 41 ++++++ .../matrices/colt/DoubleMatrix2DUnitTest.java | 46 +++++++ .../matrices/ejml/SimpleMatrixUnitTest.java | 41 ++++++ .../homemade/HomemadeMatrixUnitTest.java | 54 ++++++++ .../matrices/la4j/Basic2DMatrixUnitTest.java | 42 ++++++ .../matrices/nd4j/INDArrayUnitTest.java | 42 ++++++ 38 files changed, 1464 insertions(+) create mode 100644 core-java-modules/core-java-lang-math-2/.gitignore create mode 100644 core-java-modules/core-java-lang-math-2/README.md create mode 100644 core-java-modules/core-java-lang-math-2/pom.xml create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/factorial/Factorial.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/HomemadeMatrix.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java create mode 100644 core-java-modules/core-java-lang-math-2/src/main/resources/logback.xml create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java create mode 100644 core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java diff --git a/core-java-modules/core-java-lang-math-2/.gitignore b/core-java-modules/core-java-lang-math-2/.gitignore new file mode 100644 index 0000000000..30b2b7442c --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/.gitignore @@ -0,0 +1,4 @@ +/target/ +.settings/ +.classpath +.project \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/README.md b/core-java-modules/core-java-lang-math-2/README.md new file mode 100644 index 0000000000..f05c8804ba --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -0,0 +1,16 @@ +## Java Math + +This module contains articles about math in Java. + +### Relevant articles: + +- [Calculate Factorial in Java](https://www.baeldung.com/java-calculate-factorial) +- [Generate Combinations in Java](https://www.baeldung.com/java-combinations-algorithm) +- [Check If Two Rectangles Overlap In Java](https://www.baeldung.com/java-check-if-two-rectangles-overlap) +- [Calculate the Distance Between Two Points in Java](https://www.baeldung.com/java-distance-between-two-points) +- [Find the Intersection of Two Lines in Java](https://www.baeldung.com/java-intersection-of-two-lines) +- [Round Up to the Nearest Hundred](https://www.baeldung.com/java-round-up-nearest-hundred) +- [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) +- [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging) +- [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication) +- More articles: [[<-- prev]](/../core-java-lang-math) diff --git a/core-java-modules/core-java-lang-math-2/pom.xml b/core-java-modules/core-java-lang-math-2/pom.xml new file mode 100644 index 0000000000..92ebcc6a94 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + core-java-lang-math-2 + 0.0.1-SNAPSHOT + core-java-lang-math-2 + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../../parent-java + + + + + org.apache.commons + commons-math3 + ${commons-math3.version} + + + org.ejml + ejml-all + ${ejml.version} + + + org.nd4j + nd4j-native + ${nd4j.version} + + + org.la4j + la4j + ${la4j.version} + + + colt + colt + ${colt.version} + + + com.google.guava + guava + ${guava.version} + + + org.assertj + assertj-core + ${org.assertj.core.version} + test + + + com.github.dpaukov + combinatoricslib3 + ${combinatoricslib3.version} + + + + org.openjdk.jmh + jmh-generator-annprocess + ${jmh.version} + + + + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + + + + + 3.6.1 + 3.9.0 + 27.0.1-jre + 3.3.0 + 0.38 + 1.0.0-beta4 + 1.2.0 + 0.6.0 + 1.19 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java new file mode 100644 index 0000000000..40142ce940 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/ApacheCommonsCombinationGenerator.java @@ -0,0 +1,29 @@ +package com.baeldung.algorithms.combination; + +import java.util.Arrays; +import java.util.Iterator; + +import org.apache.commons.math3.util.CombinatoricsUtils; + +public class ApacheCommonsCombinationGenerator { + + private static final int N = 6; + private static final int R = 3; + + /** + * Print all combinations of r elements from a set + * @param n - number of elements in set + * @param r - number of elements in selection + */ + public static void generate(int n, int r) { + Iterator iterator = CombinatoricsUtils.combinationsIterator(n, r); + while (iterator.hasNext()) { + final int[] combination = iterator.next(); + System.out.println(Arrays.toString(combination)); + } + } + + public static void main(String[] args) { + generate(N, R); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java new file mode 100644 index 0000000000..0afdeefb8b --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/CombinatoricsLibCombinationGenerator.java @@ -0,0 +1,13 @@ +package com.baeldung.algorithms.combination; + +import org.paukov.combinatorics3.Generator; + +public class CombinatoricsLibCombinationGenerator { + + public static void main(String[] args) { + Generator.combination(0, 1, 2, 3, 4, 5) + .simple(3) + .stream() + .forEach(System.out::println); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java new file mode 100644 index 0000000000..d2783881ba --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/GuavaCombinationsGenerator.java @@ -0,0 +1,17 @@ +package com.baeldung.algorithms.combination; + +import java.util.Arrays; +import java.util.Set; + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +public class GuavaCombinationsGenerator { + + public static void main(String[] args) { + + Set> combinations = Sets.combinations(ImmutableSet.of(0, 1, 2, 3, 4, 5), 3); + System.out.println(combinations.size()); + System.out.println(Arrays.toString(combinations.toArray())); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java new file mode 100644 index 0000000000..676d2f41e3 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/IterativeCombinationGenerator.java @@ -0,0 +1,52 @@ +package com.baeldung.algorithms.combination; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class IterativeCombinationGenerator { + + private static final int N = 5; + private static final int R = 2; + + /** + * Generate all combinations of r elements from a set + * @param n the number of elements in input set + * @param r the number of elements in a combination + * @return the list containing all combinations + */ + public List generate(int n, int r) { + List combinations = new ArrayList<>(); + int[] combination = new int[r]; + + // initialize with lowest lexicographic combination + for (int i = 0; i < r; i++) { + combination[i] = i; + } + + while (combination[r - 1] < n) { + combinations.add(combination.clone()); + + // generate next combination in lexicographic order + int t = r - 1; + while (t != 0 && combination[t] == n - r + t) { + t--; + } + combination[t]++; + for (int i = t + 1; i < r; i++) { + combination[i] = combination[i - 1] + 1; + } + } + + return combinations; + } + + public static void main(String[] args) { + IterativeCombinationGenerator generator = new IterativeCombinationGenerator(); + List combinations = generator.generate(N, R); + System.out.println(combinations.size()); + for (int[] combination : combinations) { + System.out.println(Arrays.toString(combination)); + } + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java new file mode 100644 index 0000000000..52305b8c2f --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SelectionRecursiveCombinationGenerator.java @@ -0,0 +1,53 @@ +package com.baeldung.algorithms.combination; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SelectionRecursiveCombinationGenerator { + + private static final int N = 6; + private static final int R = 3; + + /** + * Generate all combinations of r elements from a set + * @param n - number of elements in input set + * @param r - number of elements to be chosen + * @return the list containing all combinations + */ + public List generate(int n, int r) { + List combinations = new ArrayList<>(); + helper(combinations, new int[r], 0, n - 1, 0); + return combinations; + } + + /** + * Choose elements from set by recursing over elements selected + * @param combinations - List to store generated combinations + * @param data - current combination + * @param start - starting element of remaining set + * @param end - last element of remaining set + * @param index - number of elements chosen so far. + */ + private void helper(List combinations, int data[], int start, int end, int index) { + if (index == data.length) { + int[] combination = data.clone(); + combinations.add(combination); + } else { + int max = Math.min(end, end + 1 - data.length + index); + for (int i = start; i <= max; i++) { + data[index] = i; + helper(combinations, data, i + 1, end, index + 1); + } + } + } + + public static void main(String[] args) { + SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator(); + List combinations = generator.generate(N, R); + for (int[] combination : combinations) { + System.out.println(Arrays.toString(combination)); + } + System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java new file mode 100644 index 0000000000..a73447b31d --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/combination/SetRecursiveCombinationGenerator.java @@ -0,0 +1,50 @@ +package com.baeldung.algorithms.combination; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class SetRecursiveCombinationGenerator { + + private static final int N = 5; + private static final int R = 2; + + /** + * Generate all combinations of r elements from a set + * @param n - number of elements in set + * @param r - number of elements in selection + * @return the list containing all combinations + */ + public List generate(int n, int r) { + List combinations = new ArrayList<>(); + helper(combinations, new int[r], 0, n-1, 0); + return combinations; + } + + /** + * @param combinations - List to contain the generated combinations + * @param data - List of elements in the selection + * @param start - index of the starting element in the remaining set + * @param end - index of the last element in the set + * @param index - number of elements selected so far + */ + private void helper(List combinations, int data[], int start, int end, int index) { + if (index == data.length) { + int[] combination = data.clone(); + combinations.add(combination); + } else if (start <= end) { + data[index] = start; + helper(combinations, data, start + 1, end, index + 1); + helper(combinations, data, start + 1, end, index); + } + } + + public static void main(String[] args) { + SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator(); + List combinations = generator.generate(N, R); + for (int[] combination : combinations) { + System.out.println(Arrays.toString(combination)); + } + System.out.printf("generated %d combinations of %d items from %d ", combinations.size(), R, N); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java new file mode 100644 index 0000000000..0c8eb86a38 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsService.java @@ -0,0 +1,38 @@ +package com.baeldung.algorithms.distancebetweenpoints; + +import java.awt.geom.Point2D; + +public class DistanceBetweenPointsService { + + public double calculateDistanceBetweenPoints( + double x1, + double y1, + double x2, + double y2) { + + return Math.sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1)); + } + + public double calculateDistanceBetweenPointsWithHypot( + double x1, + double y1, + double x2, + double y2) { + + double ac = Math.abs(y2 - y1); + double cb = Math.abs(x2 - x1); + + return Math.hypot(ac, cb); + } + + public double calculateDistanceBetweenPointsWithPoint2D( + double x1, + double y1, + double x2, + double y2) { + + return Point2D.distance(x1, y1, x2, y2); + + } + +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/factorial/Factorial.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/factorial/Factorial.java new file mode 100644 index 0000000000..43d2221773 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/factorial/Factorial.java @@ -0,0 +1,63 @@ +package com.baeldung.algorithms.factorial; + +import java.math.BigInteger; +import java.util.stream.LongStream; + +import org.apache.commons.math3.util.CombinatoricsUtils; + +import com.google.common.math.BigIntegerMath; + +public class Factorial { + + public long factorialUsingForLoop(int n) { + long fact = 1; + for (int i = 2; i <= n; i++) { + fact = fact * i; + } + return fact; + } + + public long factorialUsingStreams(int n) { + return LongStream.rangeClosed(1, n) + .reduce(1, (long x, long y) -> x * y); + } + + public long factorialUsingRecursion(int n) { + if (n <= 2) { + return n; + } + return n * factorialUsingRecursion(n - 1); + } + + private Long[] factorials = new Long[20]; + + public long factorialUsingMemoize(int n) { + + if (factorials[n] != null) { + return factorials[n]; + } + + if (n <= 2) { + return n; + } + long nthValue = n * factorialUsingMemoize(n - 1); + factorials[n] = nthValue; + return nthValue; + } + + public BigInteger factorialHavingLargeResult(int n) { + BigInteger result = BigInteger.ONE; + for (int i = 2; i <= n; i++) + result = result.multiply(BigInteger.valueOf(i)); + return result; + } + + public long factorialUsingApacheCommons(int n) { + return CombinatoricsUtils.factorial(n); + } + + public BigInteger factorialUsingGuava(int n) { + return BigIntegerMath.factorial(n); + } + +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java new file mode 100644 index 0000000000..35d6c8b424 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/linesintersection/LinesIntersectionService.java @@ -0,0 +1,21 @@ +package com.baeldung.algorithms.linesintersection; + +import java.awt.Point; +import java.util.Optional; + +public class LinesIntersectionService { + + public Optional calculateIntersectionPoint(double m1, double b1, double m2, double b2) { + + if (m1 == m2) { + return Optional.empty(); + } + + double x = (b2 - b1) / (m1 - m2); + double y = m1 * x + b1; + + Point point = new Point(); + point.setLocation(x, y); + return Optional.of(point); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java new file mode 100644 index 0000000000..e1c41f9518 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/EllipticalMercator.java @@ -0,0 +1,22 @@ +package com.baeldung.algorithms.mercator; + +class EllipticalMercator extends Mercator { + + @Override + double yAxisProjection(double input) { + + input = Math.min(Math.max(input, -89.5), 89.5); + double earthDimensionalRateNormalized = 1.0 - Math.pow(RADIUS_MINOR / RADIUS_MAJOR, 2); + + double inputOnEarthProj = Math.sqrt(earthDimensionalRateNormalized) * Math.sin( Math.toRadians(input)); + + inputOnEarthProj = Math.pow(((1.0 - inputOnEarthProj)/(1.0+inputOnEarthProj)), 0.5 * Math.sqrt(earthDimensionalRateNormalized)); + double inputOnEarthProjNormalized = Math.tan(0.5 * ((Math.PI*0.5) - Math.toRadians(input)))/inputOnEarthProj; + return (-1) * RADIUS_MAJOR * Math.log(inputOnEarthProjNormalized); + } + + @Override + double xAxisProjection(double input) { + return RADIUS_MAJOR * Math.toRadians(input); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java new file mode 100644 index 0000000000..b289b1839d --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/Mercator.java @@ -0,0 +1,10 @@ +package com.baeldung.algorithms.mercator; + +abstract class Mercator { + final static double RADIUS_MAJOR = 6378137.0; + final static double RADIUS_MINOR = 6356752.3142; + + abstract double yAxisProjection(double input); + + abstract double xAxisProjection(double input); +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java new file mode 100644 index 0000000000..1be976d82e --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/mercator/SphericalMercator.java @@ -0,0 +1,14 @@ +package com.baeldung.algorithms.mercator; + +public class SphericalMercator extends Mercator { + + @Override + double xAxisProjection(double input) { + return Math.toRadians(input) * RADIUS_MAJOR; + } + + @Override + double yAxisProjection(double input) { + return Math.log(Math.tan(Math.PI / 4 + Math.toRadians(input) / 2)) * RADIUS_MAJOR; + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java new file mode 100644 index 0000000000..68b1e7c594 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Point.java @@ -0,0 +1,29 @@ +package com.baeldung.algorithms.rectanglesoverlap; + +public class Point { + + private int x; + private int y; + + public Point(int x, int y) { + this.x = x; + this.y = y; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java new file mode 100644 index 0000000000..38f5edec61 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/rectanglesoverlap/Rectangle.java @@ -0,0 +1,40 @@ +package com.baeldung.algorithms.rectanglesoverlap; + +public class Rectangle { + + private Point bottomLeft; + private Point topRight; + + public Rectangle(Point bottomLeft, Point topRight) { + this.bottomLeft = bottomLeft; + this.topRight = topRight; + } + + public Point getBottomLeft() { + return bottomLeft; + } + + public void setBottomLeft(Point bottomLeft) { + this.bottomLeft = bottomLeft; + } + + public Point getTopRight() { + return topRight; + } + + public void setTopRight(Point topRight) { + this.topRight = topRight; + } + + public boolean isOverlapping(Rectangle other) { + // one rectangle is to the top of the other + if (this.topRight.getY() < other.bottomLeft.getY() || this.bottomLeft.getY() > other.topRight.getY()) { + return false; + } + // one rectangle is to the left of the other + if (this.topRight.getX() < other.bottomLeft.getX() || this.bottomLeft.getX() > other.topRight.getX()) { + return false; + } + return true; + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java new file mode 100644 index 0000000000..333019e294 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/algorithms/roundedup/RoundUpToHundred.java @@ -0,0 +1,20 @@ +package com.baeldung.algorithms.roundedup; + +import java.util.Scanner; + +public class RoundUpToHundred { + + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + double input = scanner.nextDouble(); + scanner.close(); + + RoundUpToHundred.round(input); + } + + static long round(double input) { + long i = (long) Math.ceil(input); + return ((i + 99) / 100) * 100; + }; + +} diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/HomemadeMatrix.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/HomemadeMatrix.java new file mode 100644 index 0000000000..0676250959 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/HomemadeMatrix.java @@ -0,0 +1,23 @@ +package com.baeldung.matrices; + +public class HomemadeMatrix { + public static double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) { + double[][] result = new double[firstMatrix.length][secondMatrix[0].length]; + + for (int row = 0; row < result.length; row++) { + for (int col = 0; col < result[row].length; col++) { + result[row][col] = multiplyMatricesCell(firstMatrix, secondMatrix, row, col); + } + } + + return result; + } + + private static double multiplyMatricesCell(double[][] firstMatrix, double[][] secondMatrix, int row, int col) { + double cell = 0; + for (int i = 0; i < secondMatrix.length; i++) { + cell += firstMatrix[row][i] * secondMatrix[i][col]; + } + return cell; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java new file mode 100644 index 0000000000..2ed983f733 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixMultiplicationBenchmarking.java @@ -0,0 +1,121 @@ +package com.baeldung.matrices.benchmark; + +import cern.colt.matrix.DoubleFactory2D; +import cern.colt.matrix.DoubleMatrix2D; +import cern.colt.matrix.linalg.Algebra; +import com.baeldung.matrices.HomemadeMatrix; +import org.apache.commons.math3.linear.Array2DRowRealMatrix; +import org.apache.commons.math3.linear.RealMatrix; +import org.ejml.simple.SimpleMatrix; +import org.la4j.Matrix; +import org.la4j.matrix.dense.Basic2DMatrix; +import org.nd4j.linalg.api.ndarray.INDArray; +import org.nd4j.linalg.factory.Nd4j; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.ChainedOptionsBuilder; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.Arrays; +import java.util.Map; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +public class BigMatrixMultiplicationBenchmarking { + private static final int DEFAULT_FORKS = 2; + private static final int DEFAULT_WARMUP_ITERATIONS = 5; + private static final int DEFAULT_MEASUREMENT_ITERATIONS = 10; + + public static void main(String[] args) throws Exception { + Map parameters = parseParameters(args); + + ChainedOptionsBuilder builder = new OptionsBuilder() + .include(BigMatrixMultiplicationBenchmarking.class.getSimpleName()) + .mode(Mode.AverageTime) + .forks(forks(parameters)) + .warmupIterations(warmupIterations(parameters)) + .measurementIterations(measurementIterations(parameters)) + .timeUnit(TimeUnit.SECONDS); + + parameters.forEach(builder::param); + + new Runner(builder.build()).run(); + } + + private static Map parseParameters(String[] args) { + return Arrays.stream(args) + .map(arg -> arg.split("=")) + .collect(Collectors.toMap( + arg -> arg[0], + arg -> arg[1] + )); + } + + private static int forks(Map parameters) { + String forks = parameters.remove("forks"); + return parseOrDefault(forks, DEFAULT_FORKS); + } + + private static int warmupIterations(Map parameters) { + String warmups = parameters.remove("warmupIterations"); + return parseOrDefault(warmups, DEFAULT_WARMUP_ITERATIONS); + } + + private static int measurementIterations(Map parameters) { + String measurements = parameters.remove("measurementIterations"); + return parseOrDefault(measurements, DEFAULT_MEASUREMENT_ITERATIONS); + } + + private static int parseOrDefault(String parameter, int defaultValue) { + return parameter != null ? Integer.parseInt(parameter) : defaultValue; + } + + @Benchmark + public Object homemadeMatrixMultiplication(BigMatrixProvider matrixProvider) { + return HomemadeMatrix.multiplyMatrices(matrixProvider.getFirstMatrix(), matrixProvider.getSecondMatrix()); + } + + @Benchmark + public Object ejmlMatrixMultiplication(BigMatrixProvider matrixProvider) { + SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); + SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); + + return firstMatrix.mult(secondMatrix); + } + + @Benchmark + public Object apacheCommonsMatrixMultiplication(BigMatrixProvider matrixProvider) { + RealMatrix firstMatrix = new Array2DRowRealMatrix(matrixProvider.getFirstMatrix()); + RealMatrix secondMatrix = new Array2DRowRealMatrix(matrixProvider.getSecondMatrix()); + + return firstMatrix.multiply(secondMatrix); + } + + @Benchmark + public Object la4jMatrixMultiplication(BigMatrixProvider matrixProvider) { + Matrix firstMatrix = new Basic2DMatrix(matrixProvider.getFirstMatrix()); + Matrix secondMatrix = new Basic2DMatrix(matrixProvider.getSecondMatrix()); + + return firstMatrix.multiply(secondMatrix); + } + + @Benchmark + public Object nd4jMatrixMultiplication(BigMatrixProvider matrixProvider) { + INDArray firstMatrix = Nd4j.create(matrixProvider.getFirstMatrix()); + INDArray secondMatrix = Nd4j.create(matrixProvider.getSecondMatrix()); + + return firstMatrix.mmul(secondMatrix); + } + + @Benchmark + public Object coltMatrixMultiplication(BigMatrixProvider matrixProvider) { + DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense; + + DoubleMatrix2D firstMatrix = doubleFactory2D.make(matrixProvider.getFirstMatrix()); + DoubleMatrix2D secondMatrix = doubleFactory2D.make(matrixProvider.getSecondMatrix()); + + Algebra algebra = new Algebra(); + return algebra.mult(firstMatrix, secondMatrix); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java new file mode 100644 index 0000000000..d0f8a03fe3 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/BigMatrixProvider.java @@ -0,0 +1,46 @@ +package com.baeldung.matrices.benchmark; + +import org.openjdk.jmh.annotations.Param; +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.Setup; +import org.openjdk.jmh.annotations.State; +import org.openjdk.jmh.infra.BenchmarkParams; + +import java.util.Random; +import java.util.stream.DoubleStream; + +@State(Scope.Benchmark) +public class BigMatrixProvider { + @Param({}) + private int matrixSize; + private double[][] firstMatrix; + private double[][] secondMatrix; + + public BigMatrixProvider() {} + + @Setup + public void setup(BenchmarkParams parameters) { + firstMatrix = createMatrix(matrixSize); + secondMatrix = createMatrix(matrixSize); + } + + private double[][] createMatrix(int matrixSize) { + Random random = new Random(); + + double[][] result = new double[matrixSize][matrixSize]; + for (int row = 0; row < result.length; row++) { + for (int col = 0; col < result[row].length; col++) { + result[row][col] = random.nextDouble(); + } + } + return result; + } + + public double[][] getFirstMatrix() { + return firstMatrix; + } + + public double[][] getSecondMatrix() { + return secondMatrix; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java new file mode 100644 index 0000000000..fdb423e8da --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixMultiplicationBenchmarking.java @@ -0,0 +1,86 @@ +package com.baeldung.matrices.benchmark; + +import cern.colt.matrix.DoubleFactory2D; +import cern.colt.matrix.DoubleMatrix2D; +import cern.colt.matrix.linalg.Algebra; +import com.baeldung.matrices.HomemadeMatrix; +import org.apache.commons.math3.linear.Array2DRowRealMatrix; +import org.apache.commons.math3.linear.RealMatrix; +import org.ejml.simple.SimpleMatrix; +import org.la4j.Matrix; +import org.la4j.matrix.dense.Basic2DMatrix; +import org.nd4j.linalg.api.ndarray.INDArray; +import org.nd4j.linalg.factory.Nd4j; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.concurrent.TimeUnit; + +public class MatrixMultiplicationBenchmarking { + + public static void main(String[] args) throws Exception { + Options opt = new OptionsBuilder() + .include(MatrixMultiplicationBenchmarking.class.getSimpleName()) + .exclude(BigMatrixMultiplicationBenchmarking.class.getSimpleName()) + .mode(Mode.AverageTime) + .forks(2) + .warmupIterations(10) + .measurementIterations(10) + .timeUnit(TimeUnit.MICROSECONDS) + .build(); + + new Runner(opt).run(); + } + + @Benchmark + public Object homemadeMatrixMultiplication(MatrixProvider matrixProvider) { + return HomemadeMatrix.multiplyMatrices(matrixProvider.getFirstMatrix(), matrixProvider.getSecondMatrix()); + } + + @Benchmark + public Object ejmlMatrixMultiplication(MatrixProvider matrixProvider) { + SimpleMatrix firstMatrix = new SimpleMatrix(matrixProvider.getFirstMatrix()); + SimpleMatrix secondMatrix = new SimpleMatrix(matrixProvider.getSecondMatrix()); + + return firstMatrix.mult(secondMatrix); + } + + @Benchmark + public Object apacheCommonsMatrixMultiplication(MatrixProvider matrixProvider) { + RealMatrix firstMatrix = new Array2DRowRealMatrix(matrixProvider.getFirstMatrix()); + RealMatrix secondMatrix = new Array2DRowRealMatrix(matrixProvider.getSecondMatrix()); + + return firstMatrix.multiply(secondMatrix); + } + + @Benchmark + public Object la4jMatrixMultiplication(MatrixProvider matrixProvider) { + Matrix firstMatrix = new Basic2DMatrix(matrixProvider.getFirstMatrix()); + Matrix secondMatrix = new Basic2DMatrix(matrixProvider.getSecondMatrix()); + + return firstMatrix.multiply(secondMatrix); + } + + @Benchmark + public Object nd4jMatrixMultiplication(MatrixProvider matrixProvider) { + INDArray firstMatrix = Nd4j.create(matrixProvider.getFirstMatrix()); + INDArray secondMatrix = Nd4j.create(matrixProvider.getSecondMatrix()); + + return firstMatrix.mmul(secondMatrix); + } + + @Benchmark + public Object coltMatrixMultiplication(MatrixProvider matrixProvider) { + DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense; + + DoubleMatrix2D firstMatrix = doubleFactory2D.make(matrixProvider.getFirstMatrix()); + DoubleMatrix2D secondMatrix = doubleFactory2D.make(matrixProvider.getSecondMatrix()); + + Algebra algebra = new Algebra(); + return algebra.mult(firstMatrix, secondMatrix); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java new file mode 100644 index 0000000000..d401ba2ab6 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/java/com/baeldung/matrices/benchmark/MatrixProvider.java @@ -0,0 +1,33 @@ +package com.baeldung.matrices.benchmark; + +import org.openjdk.jmh.annotations.Scope; +import org.openjdk.jmh.annotations.State; + +@State(Scope.Benchmark) +public class MatrixProvider { + private double[][] firstMatrix; + private double[][] secondMatrix; + + public MatrixProvider() { + firstMatrix = + new double[][] { + new double[] {1d, 5d}, + new double[] {2d, 3d}, + new double[] {1d ,7d} + }; + + secondMatrix = + new double[][] { + new double[] {1d, 2d, 3d, 7d}, + new double[] {5d, 2d, 8d, 1d} + }; + } + + public double[][] getFirstMatrix() { + return firstMatrix; + } + + public double[][] getSecondMatrix() { + return secondMatrix; + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/main/resources/logback.xml b/core-java-modules/core-java-lang-math-2/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java new file mode 100644 index 0000000000..987b6ddae6 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/combination/CombinationUnitTest.java @@ -0,0 +1,35 @@ +package com.baeldung.algorithms.combination; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; + +import org.junit.Test; + +public class CombinationUnitTest { + + private static final int N = 5; + private static final int R = 3; + private static final int nCr = 10; + + @Test + public void givenSetAndSelectionSize_whenCalculatedUsingSetRecursiveAlgorithm_thenExpectedCount() { + SetRecursiveCombinationGenerator generator = new SetRecursiveCombinationGenerator(); + List selection = generator.generate(N, R); + assertEquals(nCr, selection.size()); + } + + @Test + public void givenSetAndSelectionSize_whenCalculatedUsingSelectionRecursiveAlgorithm_thenExpectedCount() { + SelectionRecursiveCombinationGenerator generator = new SelectionRecursiveCombinationGenerator(); + List selection = generator.generate(N, R); + assertEquals(nCr, selection.size()); + } + + @Test + public void givenSetAndSelectionSize_whenCalculatedUsingIterativeAlgorithm_thenExpectedCount() { + IterativeCombinationGenerator generator = new IterativeCombinationGenerator(); + List selection = generator.generate(N, R); + assertEquals(nCr, selection.size()); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java new file mode 100644 index 0000000000..784681a807 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/distancebetweenpoints/DistanceBetweenPointsServiceUnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.algorithms.distancebetweenpoints; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class DistanceBetweenPointsServiceUnitTest { + + private DistanceBetweenPointsService service = new DistanceBetweenPointsService(); + + @Test + public void givenTwoPoints_whenCalculateDistanceByFormula_thenCorrect() { + + double x1 = 3; + double y1 = 4; + double x2 = 7; + double y2 = 1; + + double distance = service.calculateDistanceBetweenPoints(x1, y1, x2, y2); + + assertEquals(distance, 5, 0.001); + + } + + @Test + public void givenTwoPoints_whenCalculateDistanceWithHypot_thenCorrect() { + + double x1 = 3; + double y1 = 4; + double x2 = 7; + double y2 = 1; + + double distance = service.calculateDistanceBetweenPointsWithHypot(x1, y1, x2, y2); + + assertEquals(distance, 5, 0.001); + + } + + @Test + public void givenTwoPoints_whenCalculateDistanceWithPoint2D_thenCorrect() { + + double x1 = 3; + double y1 = 4; + double x2 = 7; + double y2 = 1; + + double distance = service.calculateDistanceBetweenPointsWithPoint2D(x1, y1, x2, y2); + + assertEquals(distance, 5, 0.001); + + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java new file mode 100644 index 0000000000..c185dba62b --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/factorial/FactorialUnitTest.java @@ -0,0 +1,72 @@ +package com.baeldung.algorithms.factorial; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.math.BigInteger; + +import org.junit.Before; +import org.junit.Test; + +public class FactorialUnitTest { + + Factorial factorial; + + @Before + public void setup() { + factorial = new Factorial(); + } + + @Test + public void whenCalculatingFactorialUsingForLoop_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingForLoop(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingStreams_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingStreams(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingRecursion_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingRecursion(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingMemoize_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(120); + + n = 6; + + assertThat(factorial.factorialUsingMemoize(n)).isEqualTo(720); + } + + @Test + public void whenCalculatingFactorialHavingLargeResult_thenCorrect() { + int n = 22; + + assertThat(factorial.factorialHavingLargeResult(n)).isEqualTo(new BigInteger("1124000727777607680000")); + } + + @Test + public void whenCalculatingFactorialUsingApacheCommons_thenCorrect() { + int n = 5; + + assertThat(factorial.factorialUsingApacheCommons(n)).isEqualTo(120); + } + + @Test + public void whenCalculatingFactorialUsingGuava_thenCorrect() { + int n = 22; + + assertThat(factorial.factorialUsingGuava(n)).isEqualTo(new BigInteger("1124000727777607680000")); + } + +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java new file mode 100644 index 0000000000..22371107f3 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/linesintersection/LinesIntersectionServiceUnitTest.java @@ -0,0 +1,40 @@ +package com.baeldung.algorithms.linesintersection; + +import java.awt.Point; +import java.util.Optional; + +import org.junit.Test; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertEquals; + +public class LinesIntersectionServiceUnitTest { + private LinesIntersectionService service = new LinesIntersectionService(); + + @Test + public void givenNotParallelLines_whenCalculatePoint_thenPresent() { + + double m1 = 0; + double b1 = 0; + double m2 = 1; + double b2 = -1; + + Optional point = service.calculateIntersectionPoint(m1, b1, m2, b2); + + assertTrue(point.isPresent()); + assertEquals(point.get().getX(), 1, 0.001); + assertEquals(point.get().getY(), 0, 0.001); + } + + @Test + public void givenParallelLines_whenCalculatePoint_thenEmpty() { + double m1 = 1; + double b1 = 0; + double m2 = 1; + double b2 = -1; + + Optional point = service.calculateIntersectionPoint(m1, b1, m2, b2); + + assertFalse(point.isPresent()); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java new file mode 100644 index 0000000000..96b644c46c --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/EllipticalMercatorUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.algorithms.mercator; + +import org.junit.Assert; +import org.junit.Test; + + +public class EllipticalMercatorUnitTest { + + @Test + public void giventThatTheInputIs22_whenXAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { + Mercator mercator = new EllipticalMercator(); + double result = mercator.xAxisProjection(22); + Assert.assertEquals(result, 2449028.7974520186, 0.0); + } + + @Test + public void giventThatTheInputIs44_whenYAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { + Mercator mercator = new EllipticalMercator(); + double result = mercator.yAxisProjection(44); + Assert.assertEquals(result, 5435749.887511954, 0.0); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java new file mode 100644 index 0000000000..348c6ad3e4 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/mercator/SphericalMercatorUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.algorithms.mercator; + +import org.junit.Assert; +import org.junit.Test; + +public class SphericalMercatorUnitTest { + + @Test + public void giventThatTheInputIs22_whenXAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { + Mercator mercator = new SphericalMercator(); + double result = mercator.xAxisProjection(22); + Assert.assertEquals(result, 2449028.7974520186, 0.0); + } + + @Test + public void giventThatTheInputIs44_whenYAxisProjectionIsCalled_thenTheResultIsTheCorrectOne() { + Mercator mercator = new SphericalMercator(); + double result = mercator.yAxisProjection(44); + Assert.assertEquals(result, 5465442.183322753, 0.0); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java new file mode 100644 index 0000000000..e4bb614b48 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/rectanglesoverlap/RectangleUnitTest.java @@ -0,0 +1,39 @@ +package com.baeldung.algorithms.rectanglesoverlap; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import org.junit.Test; + +public class RectangleUnitTest { + + @Test + public void givenTwoOverlappingRectangles_whenisOverlappingCalled_shouldReturnTrue() { + Rectangle rectangle1 = new Rectangle(new Point(2, 1), new Point(4, 3)); + Rectangle rectangle2 = new Rectangle(new Point(1, 1), new Point(6, 4)); + assertTrue(rectangle1.isOverlapping(rectangle2)); + + rectangle1 = new Rectangle(new Point(-5, -2), new Point(2, 3)); + rectangle2 = new Rectangle(new Point(-2, -1), new Point(5, 2)); + assertTrue(rectangle1.isOverlapping(rectangle2)); + + rectangle1 = new Rectangle(new Point(-5, 1), new Point(2, 4)); + rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, 5)); + assertTrue(rectangle1.isOverlapping(rectangle2)); + } + + @Test + public void givenTwoNonOverlappingRectangles_whenisOverlappingCalled_shouldReturnFalse() { + Rectangle rectangle1 = new Rectangle(new Point(-5, 1), new Point(-3, 4)); + Rectangle rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, 5)); + assertFalse(rectangle1.isOverlapping(rectangle2)); + + rectangle1 = new Rectangle(new Point(-5, 1), new Point(3, 4)); + rectangle2 = new Rectangle(new Point(-2, -2), new Point(5, -1)); + assertFalse(rectangle1.isOverlapping(rectangle2)); + + rectangle1 = new Rectangle(new Point(-2, 1), new Point(0, 3)); + rectangle2 = new Rectangle(new Point(3, 1), new Point(5, 4)); + assertFalse(rectangle1.isOverlapping(rectangle2)); + } + +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java new file mode 100644 index 0000000000..5191d65787 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/algorithms/roundedup/RoundUpToHundredUnitTest.java @@ -0,0 +1,14 @@ +package com.baeldung.algorithms.roundedup; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class RoundUpToHundredUnitTest { + @Test + public void givenInput_whenRound_thenRoundUpToTheNearestHundred() { + assertEquals("Rounded up to hundred", 100, RoundUpToHundred.round(99)); + assertEquals("Rounded up to three hundred ", 300, RoundUpToHundred.round(200.2)); + assertEquals("Returns same rounded value", 400, RoundUpToHundred.round(400)); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java new file mode 100644 index 0000000000..e7d99fbe3e --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/apache/RealMatrixUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.matrices.apache; + +import org.apache.commons.math3.linear.Array2DRowRealMatrix; +import org.apache.commons.math3.linear.RealMatrix; +import org.junit.jupiter.api.Test; +import org.openjdk.jmh.annotations.*; + +import static org.assertj.core.api.Assertions.assertThat; + +class RealMatrixUnitTest { + + @Test + void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { + RealMatrix firstMatrix = new Array2DRowRealMatrix( + new double[][] { + new double[] {1d, 5d}, + new double[] {2d, 3d}, + new double[] {1d ,7d} + } + ); + + RealMatrix secondMatrix = new Array2DRowRealMatrix( + new double[][] { + new double[] {1d, 2d, 3d, 7d}, + new double[] {5d, 2d, 8d, 1d} + } + ); + + RealMatrix expected = new Array2DRowRealMatrix( + new double[][] { + new double[] {26d, 12d, 43d, 12d}, + new double[] {17d, 10d, 30d, 17d}, + new double[] {36d, 16d, 59d, 14d} + } + ); + + RealMatrix actual = firstMatrix.multiply(secondMatrix); + + assertThat(actual).isEqualTo(expected); + } +} diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java new file mode 100644 index 0000000000..da66cd7d61 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/colt/DoubleMatrix2DUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.matrices.colt; + +import cern.colt.matrix.DoubleFactory2D; +import cern.colt.matrix.DoubleMatrix2D; +import cern.colt.matrix.linalg.Algebra; +import org.junit.jupiter.api.Test; +import org.openjdk.jmh.annotations.*; + +import static org.assertj.core.api.Assertions.assertThat; + +class DoubleMatrix2DUnitTest { + + @Test + void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { + DoubleFactory2D doubleFactory2D = DoubleFactory2D.dense; + + DoubleMatrix2D firstMatrix = doubleFactory2D.make( + new double[][] { + new double[] {1d, 5d}, + new double[] {2d, 3d}, + new double[] {1d ,7d} + } + ); + + DoubleMatrix2D secondMatrix = doubleFactory2D.make( + new double[][] { + new double[] {1d, 2d, 3d, 7d}, + new double[] {5d, 2d, 8d, 1d} + } + ); + + DoubleMatrix2D expected = doubleFactory2D.make( + new double[][] { + new double[] {26d, 12d, 43d, 12d}, + new double[] {17d, 10d, 30d, 17d}, + new double[] {36d, 16d, 59d, 14d} + } + ); + + Algebra algebra = new Algebra(); + DoubleMatrix2D actual = algebra.mult(firstMatrix, secondMatrix); + + assertThat(actual).isEqualTo(expected); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java new file mode 100644 index 0000000000..60381ece63 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/ejml/SimpleMatrixUnitTest.java @@ -0,0 +1,41 @@ +package com.baeldung.matrices.ejml; + +import org.ejml.simple.SimpleMatrix; +import org.junit.jupiter.api.Test; +import org.openjdk.jmh.annotations.*; + +import static org.assertj.core.api.Assertions.assertThat; + +class SimpleMatrixUnitTest { + + @Test + void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { + SimpleMatrix firstMatrix = new SimpleMatrix( + new double[][] { + new double[] {1d, 5d}, + new double[] {2d, 3d}, + new double[] {1d ,7d} + } + ); + + SimpleMatrix secondMatrix = new SimpleMatrix( + new double[][] { + new double[] {1d, 2d, 3d, 7d}, + new double[] {5d, 2d, 8d, 1d} + } + ); + + SimpleMatrix expected = new SimpleMatrix( + new double[][] { + new double[] {26d, 12d, 43d, 12d}, + new double[] {17d, 10d, 30d, 17d}, + new double[] {36d, 16d, 59d, 14d} + } + ); + + SimpleMatrix actual = firstMatrix.mult(secondMatrix); + + assertThat(actual).matches(m -> m.isIdentical(expected, 0d)); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java new file mode 100644 index 0000000000..d1a062ee79 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/homemade/HomemadeMatrixUnitTest.java @@ -0,0 +1,54 @@ +package com.baeldung.matrices.homemade; + +import org.junit.jupiter.api.Test; +import org.openjdk.jmh.annotations.*; + +import static org.assertj.core.api.Assertions.assertThat; + +class HomemadeMatrixUnitTest { + + @Test + void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { + double[][] firstMatrix = { + new double[]{1d, 5d}, + new double[]{2d, 3d}, + new double[]{1d, 7d} + }; + + double[][] secondMatrix = { + new double[]{1d, 2d, 3d, 7d}, + new double[]{5d, 2d, 8d, 1d} + }; + + double[][] expected = { + new double[]{26d, 12d, 43d, 12d}, + new double[]{17d, 10d, 30d, 17d}, + new double[]{36d, 16d, 59d, 14d} + }; + + double[][] actual = multiplyMatrices(firstMatrix, secondMatrix); + + assertThat(actual).isEqualTo(expected); + } + + private double[][] multiplyMatrices(double[][] firstMatrix, double[][] secondMatrix) { + double[][] result = new double[firstMatrix.length][secondMatrix[0].length]; + + for (int row = 0; row < result.length; row++) { + for (int col = 0; col < result[row].length; col++) { + result[row][col] = multiplyMatricesCell(firstMatrix, secondMatrix, row, col); + } + } + + return result; + } + + private double multiplyMatricesCell(double[][] firstMatrix, double[][] secondMatrix, int row, int col) { + double cell = 0; + for (int i = 0; i < secondMatrix.length; i++) { + cell += firstMatrix[row][i] * secondMatrix[i][col]; + } + return cell; + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java new file mode 100644 index 0000000000..01731a3dd5 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/la4j/Basic2DMatrixUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.matrices.la4j; + +import org.junit.jupiter.api.Test; +import org.la4j.Matrix; +import org.la4j.matrix.dense.Basic2DMatrix; +import org.openjdk.jmh.annotations.*; + +import static org.assertj.core.api.Assertions.assertThat; + +class Basic2DMatrixUnitTest { + + @Test + void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { + Matrix firstMatrix = new Basic2DMatrix( + new double[][]{ + new double[]{1d, 5d}, + new double[]{2d, 3d}, + new double[]{1d, 7d} + } + ); + + Matrix secondMatrix = new Basic2DMatrix( + new double[][]{ + new double[]{1d, 2d, 3d, 7d}, + new double[]{5d, 2d, 8d, 1d} + } + ); + + Matrix expected = new Basic2DMatrix( + new double[][]{ + new double[]{26d, 12d, 43d, 12d}, + new double[]{17d, 10d, 30d, 17d}, + new double[]{36d, 16d, 59d, 14d} + } + ); + + Matrix actual = firstMatrix.multiply(secondMatrix); + + assertThat(actual).isEqualTo(expected); + } + +} \ No newline at end of file diff --git a/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java new file mode 100644 index 0000000000..72ef60a571 --- /dev/null +++ b/core-java-modules/core-java-lang-math-2/src/test/java/com/baeldung/matrices/nd4j/INDArrayUnitTest.java @@ -0,0 +1,42 @@ +package com.baeldung.matrices.nd4j; + +import org.junit.jupiter.api.Test; +import org.nd4j.linalg.api.ndarray.INDArray; +import org.nd4j.linalg.factory.Nd4j; +import org.openjdk.jmh.annotations.*; + +import static org.assertj.core.api.Assertions.assertThat; + +class INDArrayUnitTest { + + @Test + void givenTwoMatrices_whenMultiply_thenMultiplicatedMatrix() { + INDArray firstMatrix = Nd4j.create( + new double[][]{ + new double[]{1d, 5d}, + new double[]{2d, 3d}, + new double[]{1d, 7d} + } + ); + + INDArray secondMatrix = Nd4j.create( + new double[][] { + new double[] {1d, 2d, 3d, 7d}, + new double[] {5d, 2d, 8d, 1d} + } + ); + + INDArray expected = Nd4j.create( + new double[][] { + new double[] {26d, 12d, 43d, 12d}, + new double[] {17d, 10d, 30d, 17d}, + new double[] {36d, 16d, 59d, 14d} + } + ); + + INDArray actual = firstMatrix.mmul(secondMatrix); + + assertThat(actual).isEqualTo(expected); + } + +} \ No newline at end of file From 1aba93f3aa0a02420b955db74ec9e8d698489dd5 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 16:57:48 +0530 Subject: [PATCH 223/278] JAVA-626 : added new module to parent module's pom --- core-java-modules/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 326d4bb1c5..5e7ffa37b9 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -76,6 +76,7 @@ core-java-lang core-java-lang-2 core-java-lang-math + core-java-lang-math-2 core-java-lang-oop core-java-lang-oop-2 core-java-lang-oop-3 From 3e9da83493fcaa099930e0885093248eaf7f9840 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 16:59:20 +0530 Subject: [PATCH 224/278] JAVA-626 : removed retired modules from parent pom --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index a295439951..1c887245db 100644 --- a/pom.xml +++ b/pom.xml @@ -455,8 +455,6 @@ javafx java-jdi java-lite - java-math - java-math-2 java-numbers java-numbers-2 java-numbers-3 From ca2694209b61ecebed3010ef7e8a0b54183d94a2 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 17:01:55 +0530 Subject: [PATCH 225/278] removed retired modules from parent pom --- pom.xml | 2 -- 1 file changed, 2 deletions(-) diff --git a/pom.xml b/pom.xml index 1c887245db..b896d61f91 100644 --- a/pom.xml +++ b/pom.xml @@ -966,8 +966,6 @@ javafx java-jdi java-lite - java-math - java-math-2 java-numbers java-numbers-2 java-numbers-3 From eeb864af710ef4e21386048665ea25bb7b0e29cc Mon Sep 17 00:00:00 2001 From: sergio41 Date: Sun, 22 Mar 2020 14:26:52 +0100 Subject: [PATCH 226/278] [BAEL-3910] Code Upload --- .../src/main/resources/config.properties | 1 + .../stringtoolong/StringTooLongUnitTest.java | 38 +++++++++++++++++++ .../src/test/resources/stringtoolong.txt | 1 + 3 files changed, 40 insertions(+) create mode 100644 core-java-modules/core-java-strings/src/main/resources/config.properties create mode 100644 core-java-modules/core-java-strings/src/test/java/com/baeldung/stringtoolong/StringTooLongUnitTest.java create mode 100644 core-java-modules/core-java-strings/src/test/resources/stringtoolong.txt diff --git a/core-java-modules/core-java-strings/src/main/resources/config.properties b/core-java-modules/core-java-strings/src/main/resources/config.properties new file mode 100644 index 0000000000..8197c13543 --- /dev/null +++ b/core-java-modules/core-java-strings/src/main/resources/config.properties @@ -0,0 +1 @@ +string.too.long= StringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLong diff --git a/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringtoolong/StringTooLongUnitTest.java b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringtoolong/StringTooLongUnitTest.java new file mode 100644 index 0000000000..4035cadb83 --- /dev/null +++ b/core-java-modules/core-java-strings/src/test/java/com/baeldung/stringtoolong/StringTooLongUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.stringtoolong; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; + +public class StringTooLongUnitTest { + @Test + public void whenDeclaringTooLongString_thenCompilationError() { + String stringTooLong = ""; + assertThat(stringTooLong).isNotEmpty(); + } + + @Test + public void whenStoringInFileTooLongString_thenNoCompilationError() throws IOException { + FileInputStream fis = new FileInputStream("src/test/resources/stringtoolong.txt"); + String stringTooLong = IOUtils.toString(fis, "UTF-8"); + assertThat(stringTooLong).isNotEmpty(); + } + + @Test + public void whenStoringInPropertiesString_thenNoCompilationError() throws IOException { + String sValue = null; + try (InputStream input = new FileInputStream("src/main/resources/config.properties")) { + Properties prop = new Properties(); + prop.load(input); + sValue = prop.getProperty("string.too.long"); + } + assertThat(sValue).isNotEmpty(); + } +} + \ No newline at end of file diff --git a/core-java-modules/core-java-strings/src/test/resources/stringtoolong.txt b/core-java-modules/core-java-strings/src/test/resources/stringtoolong.txt new file mode 100644 index 0000000000..6b2649aaa8 --- /dev/null +++ b/core-java-modules/core-java-strings/src/test/resources/stringtoolong.txt @@ -0,0 +1 @@ + StringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLongStringTooLong \ No newline at end of file From 9bd0dfa6d978e9315ecdc83adafb5b0c0575317f Mon Sep 17 00:00:00 2001 From: "amit.pandey" Date: Sun, 22 Mar 2020 21:40:42 +0530 Subject: [PATCH 227/278] updated hibernate version --- persistence-modules/hibernate-mapping/pom.xml | 2 +- persistence-modules/hibernate5/pom.xml | 2 +- .../main/java/com/baeldung/hibernate/pojo/PointEntity.java | 3 ++- .../main/java/com/baeldung/hibernate/pojo/PolygonEntity.java | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/persistence-modules/hibernate-mapping/pom.xml b/persistence-modules/hibernate-mapping/pom.xml index c7318ee425..4eabc5d298 100644 --- a/persistence-modules/hibernate-mapping/pom.xml +++ b/persistence-modules/hibernate-mapping/pom.xml @@ -65,7 +65,7 @@ - 5.3.10.Final + 5.4.12.Final 3.8.0 6.0.16.Final 3.0.1-b11 diff --git a/persistence-modules/hibernate5/pom.xml b/persistence-modules/hibernate5/pom.xml index ffeff5ee4a..7f04abc09f 100644 --- a/persistence-modules/hibernate5/pom.xml +++ b/persistence-modules/hibernate5/pom.xml @@ -77,7 +77,7 @@ - 5.3.7.Final + 5.4.12.Final 6.0.6 2.2.3 3.8.0 diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java index 736abde866..7a88a8bedc 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PointEntity.java @@ -1,12 +1,13 @@ package com.baeldung.hibernate.pojo; -import com.vividsolutions.jts.geom.Point; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import org.locationtech.jts.geom.Point; + @Entity public class PointEntity { diff --git a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java index 69208c8cd4..3144a88a16 100644 --- a/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java +++ b/persistence-modules/hibernate5/src/main/java/com/baeldung/hibernate/pojo/PolygonEntity.java @@ -1,11 +1,11 @@ package com.baeldung.hibernate.pojo; -import com.vividsolutions.jts.geom.Polygon; - import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; +import org.locationtech.jts.geom.Polygon; + @Entity public class PolygonEntity { From abf06202695479623623cef89f8a08b0255f2e2c Mon Sep 17 00:00:00 2001 From: Kai Yuan Date: Tue, 17 Mar 2020 00:31:37 +0100 Subject: [PATCH 228/278] [BAEL-3914] java regex: \\s vs \\s+ --- ...ReplaceAllWithWhitespaceRegexUnitTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 core-java-modules/core-java-regex/src/test/java/com/baeldung/replaceall/ReplaceAllWithWhitespaceRegexUnitTest.java diff --git a/core-java-modules/core-java-regex/src/test/java/com/baeldung/replaceall/ReplaceAllWithWhitespaceRegexUnitTest.java b/core-java-modules/core-java-regex/src/test/java/com/baeldung/replaceall/ReplaceAllWithWhitespaceRegexUnitTest.java new file mode 100644 index 0000000000..a95d1afd80 --- /dev/null +++ b/core-java-modules/core-java-regex/src/test/java/com/baeldung/replaceall/ReplaceAllWithWhitespaceRegexUnitTest.java @@ -0,0 +1,32 @@ +package com.baeldung.replaceall; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ReplaceAllWithWhitespaceRegexUnitTest { + private static final String INPUT_STR = "Text With Whitespaces! "; + + @Test + public void givenString_whenReplaceBySingleCharClass_thenGetExpect() { + String expected = "Text___With_____Whitespaces!___"; + String result = INPUT_STR.replaceAll("\\s", "_"); + assertEquals(expected, result); + } + + @Test + public void givenString_whenReplaceBySingleCharClassWithPlus_thenGetExpect() { + String expected = "Text_With_Whitespaces!_"; + String result = INPUT_STR.replaceAll("\\s+", "_"); + assertEquals(expected, result); + } + + @Test + public void givenString_whenRemoveByWhitespace_thenGetSameResult() { + String expected = "TextWithWhitespaces!"; + String result1 = INPUT_STR.replaceAll("\\s", ""); + String result2 = INPUT_STR.replaceAll("\\s+", ""); + assertEquals(expected, result1); + assertEquals(result1, result2); + } +} From 8d83e7cf1bcc4fcf616dbca6b71c9317ab826442 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 22:54:40 +0530 Subject: [PATCH 229/278] JAVA-626 : Updated README description --- core-java-modules/core-java-lang-math-2/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-lang-math-2/README.md b/core-java-modules/core-java-lang-math-2/README.md index f05c8804ba..0e0f1991c4 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -1,6 +1,6 @@ -## Java Math +========= -This module contains articles about math in Java. +## Core Java 8 Cookbooks and Examples - Part 2 ### Relevant articles: From bc6ef10c6db2b88235552650f2735fa8a7473235 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 23:38:04 +0530 Subject: [PATCH 230/278] JAVA-4: removed hibernate5-mapping module --- .../hibernate5-mapping/README.md | 11 --- .../hibernate5-mapping/pom.xml | 76 --------------- .../com/baeldung/hibernate/HibernateUtil.java | 96 ------------------- .../main/resources/META-INF/persistence.xml | 18 ---- .../src/main/resources/logback.xml | 13 --- 5 files changed, 214 deletions(-) delete mode 100644 persistence-modules/hibernate5-mapping/README.md delete mode 100644 persistence-modules/hibernate5-mapping/pom.xml delete mode 100644 persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java delete mode 100644 persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml delete mode 100644 persistence-modules/hibernate5-mapping/src/main/resources/logback.xml diff --git a/persistence-modules/hibernate5-mapping/README.md b/persistence-modules/hibernate5-mapping/README.md deleted file mode 100644 index f18b0b63de..0000000000 --- a/persistence-modules/hibernate5-mapping/README.md +++ /dev/null @@ -1,11 +0,0 @@ -## Hibernate 5 - -This module contains articles about Hibernate 5. - -### Relevant articles: - -- [Dynamic Mapping with Hibernate](http://www.baeldung.com/hibernate-dynamic-mapping) -- [Hibernate Inheritance Mapping](http://www.baeldung.com/hibernate-inheritance) -- [Mapping A Hibernate Query to a Custom Class](https://www.baeldung.com/hibernate-query-to-custom-class) -- [Hibernate – Mapping Date and Time](http://www.baeldung.com/hibernate-date-time) -- [Mapping LOB Data in Hibernate](http://www.baeldung.com/hibernate-lob) \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/pom.xml b/persistence-modules/hibernate5-mapping/pom.xml deleted file mode 100644 index 59e0547671..0000000000 --- a/persistence-modules/hibernate5-mapping/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - 4.0.0 - hibernate5-mapping - 0.0.1-SNAPSHOT - hibernate5-mapping - - - com.baeldung - persistence-modules - 1.0.0-SNAPSHOT - - - - - org.hibernate - hibernate-core - ${hibernate.version} - - - org.assertj - assertj-core - ${assertj-core.version} - test - - - com.h2database - h2 - ${h2.version} - - - org.hibernate - hibernate-spatial - ${hibernate.version} - - - org.opengeo - geodb - ${geodb.version} - - - mysql - mysql-connector-java - ${mysql.version} - - - ch.vorburger.mariaDB4j - mariaDB4j - ${mariaDB4j.version} - - - org.hibernate - hibernate-testing - ${hibernate.version} - - - - - - geodb-repo - GeoDB repository - http://repo.boundlessgeo.com/main/ - - - - - 5.3.7.Final - 6.0.6 - 2.2.3 - 3.8.0 - 0.9 - - - diff --git a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java deleted file mode 100644 index 28e1af49ed..0000000000 --- a/persistence-modules/hibernate5-mapping/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ /dev/null @@ -1,96 +0,0 @@ -package com.baeldung.hibernate; - -import java.io.FileInputStream; -import java.io.IOException; -import java.net.URL; -import java.util.Properties; - -import org.apache.commons.lang3.StringUtils; -import org.hibernate.SessionFactory; -import org.hibernate.boot.Metadata; -import org.hibernate.boot.MetadataSources; -import org.hibernate.boot.registry.StandardServiceRegistryBuilder; -import org.hibernate.service.ServiceRegistry; - -import com.baeldung.hibernate.entities.DeptEmployee; -import com.baeldung.hibernate.pojo.Employee; -import com.baeldung.hibernate.pojo.EntityDescription; -import com.baeldung.hibernate.pojo.Phone; -import com.baeldung.hibernate.pojo.TemporalValues; -import com.baeldung.hibernate.pojo.inheritance.Animal; -import com.baeldung.hibernate.pojo.inheritance.Bag; -import com.baeldung.hibernate.pojo.inheritance.Book; -import com.baeldung.hibernate.pojo.inheritance.Car; -import com.baeldung.hibernate.pojo.inheritance.MyEmployee; -import com.baeldung.hibernate.pojo.inheritance.MyProduct; -import com.baeldung.hibernate.pojo.inheritance.Pen; -import com.baeldung.hibernate.pojo.inheritance.Pet; -import com.baeldung.hibernate.pojo.inheritance.Vehicle; - -public class HibernateUtil { - private static String PROPERTY_FILE_NAME; - - public static SessionFactory getSessionFactory() throws IOException { - return getSessionFactory(null); - } - - public static SessionFactory getSessionFactory(String propertyFileName) throws IOException { - PROPERTY_FILE_NAME = propertyFileName; - ServiceRegistry serviceRegistry = configureServiceRegistry(); - return makeSessionFactory(serviceRegistry); - } - - public static SessionFactory getSessionFactoryByProperties(Properties properties) throws IOException { - ServiceRegistry serviceRegistry = configureServiceRegistry(properties); - return makeSessionFactory(serviceRegistry); - } - - private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) { - MetadataSources metadataSources = new MetadataSources(serviceRegistry); - - metadataSources.addPackage("com.baeldung.hibernate.pojo"); - metadataSources.addAnnotatedClass(Employee.class); - metadataSources.addAnnotatedClass(Phone.class); - metadataSources.addAnnotatedClass(EntityDescription.class); - metadataSources.addAnnotatedClass(TemporalValues.class); - metadataSources.addAnnotatedClass(DeptEmployee.class); - metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); - metadataSources.addAnnotatedClass(Animal.class); - metadataSources.addAnnotatedClass(Bag.class); - metadataSources.addAnnotatedClass(Book.class); - metadataSources.addAnnotatedClass(Car.class); - metadataSources.addAnnotatedClass(MyEmployee.class); - metadataSources.addAnnotatedClass(MyProduct.class); - metadataSources.addAnnotatedClass(Pen.class); - metadataSources.addAnnotatedClass(Pet.class); - metadataSources.addAnnotatedClass(Vehicle.class); - - - Metadata metadata = metadataSources.getMetadataBuilder() - .build(); - - return metadata.getSessionFactoryBuilder() - .build(); - - } - - private static ServiceRegistry configureServiceRegistry() throws IOException { - return configureServiceRegistry(getProperties()); - } - - private static ServiceRegistry configureServiceRegistry(Properties properties) throws IOException { - return new StandardServiceRegistryBuilder().applySettings(properties) - .build(); - } - - public static Properties getProperties() throws IOException { - Properties properties = new Properties(); - URL propertiesURL = Thread.currentThread() - .getContextClassLoader() - .getResource(StringUtils.defaultString(PROPERTY_FILE_NAME, "hibernate.properties")); - try (FileInputStream inputStream = new FileInputStream(propertiesURL.getFile())) { - properties.load(inputStream); - } - return properties; - } -} \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml deleted file mode 100644 index 474eeb7a44..0000000000 --- a/persistence-modules/hibernate5-mapping/src/main/resources/META-INF/persistence.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - Hibernate EntityManager Demo - true - - - - - - - - - - \ No newline at end of file diff --git a/persistence-modules/hibernate5-mapping/src/main/resources/logback.xml b/persistence-modules/hibernate5-mapping/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/persistence-modules/hibernate5-mapping/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file From a081a6cf6ddbc4af29bd77f2638d28a39f3634f7 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Sun, 22 Mar 2020 23:40:34 +0530 Subject: [PATCH 231/278] JAVA-4: modified README files to add proper descriptions, and https to some links --- persistence-modules/hibernate-annotations/README.md | 4 ++-- persistence-modules/hibernate-enterprise/README.md | 6 +++--- persistence-modules/hibernate-jpa/README.md | 8 ++++---- persistence-modules/hibernate-mapping/README.md | 8 ++++---- persistence-modules/hibernate5/README.md | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/persistence-modules/hibernate-annotations/README.md b/persistence-modules/hibernate-annotations/README.md index 2813dbdda3..393cf82bfd 100644 --- a/persistence-modules/hibernate-annotations/README.md +++ b/persistence-modules/hibernate-annotations/README.md @@ -1,10 +1,10 @@ ## Hibernate Annotations -This module contains articles about Hibernate Annotations. +This module contains articles about Annotations used in Hibernate. ### Relevant Articles: - [Custom Types in Hibernate and the @Type Annotation](https://www.baeldung.com/hibernate-custom-types) - [@JoinColumn Annotation Explained](https://www.baeldung.com/jpa-join-column) - [Difference Between @JoinColumn and mappedBy](https://www.baeldung.com/jpa-joincolumn-vs-mappedby) -- [Hibernate One to Many Annotation Tutorial](http://www.baeldung.com/hibernate-one-to-many) +- [Hibernate One to Many Annotation Tutorial](https://www.baeldung.com/hibernate-one-to-many) - [Hibernate @WhereJoinTable Annotation](https://www.baeldung.com/hibernate-wherejointable) diff --git a/persistence-modules/hibernate-enterprise/README.md b/persistence-modules/hibernate-enterprise/README.md index c48092e6a2..c5606d0970 100644 --- a/persistence-modules/hibernate-enterprise/README.md +++ b/persistence-modules/hibernate-enterprise/README.md @@ -1,11 +1,11 @@ ## Hibernate Enterprise -This module contains articles about Hibernate. +This module contains articles about enterprise concerns such as Multitenancy, Errors, Exceptions, Logging and more in Hibernate. ### Relevant articles: -- [Introduction to Hibernate Spatial](http://www.baeldung.com/hibernate-spatial) -- [A Guide to Multitenancy in Hibernate 5](http://www.baeldung.com/hibernate-5-multitenancy) +- [Introduction to Hibernate Spatial](https://www.baeldung.com/hibernate-spatial) +- [A Guide to Multitenancy in Hibernate 5](https://www.baeldung.com/hibernate-5-multitenancy) - [Hibernate Aggregate Functions](https://www.baeldung.com/hibernate-aggregate-functions) - [Common Hibernate Exceptions](https://www.baeldung.com/hibernate-exceptions) - [Hibernate Error “Not all named parameters have been set”](https://www.baeldung.com/hibernate-error-named-parameters-not-set) diff --git a/persistence-modules/hibernate-jpa/README.md b/persistence-modules/hibernate-jpa/README.md index fb1d46cf9b..d0a253f028 100644 --- a/persistence-modules/hibernate-jpa/README.md +++ b/persistence-modules/hibernate-jpa/README.md @@ -1,13 +1,13 @@ ## Hibernate JPA -This module contains articles about Hibernate JPA. +This module contains articles specific to use of Hibernate as a JPA implementation, such as Locking, Bootstrapping, One-to-One Relationship, Persistence Context, and more. ### Relevant articles: -- [JPA Attribute Converters](http://www.baeldung.com/jpa-attribute-converters) -- [Pessimistic Locking in JPA](http://www.baeldung.com/jpa-pessimistic-locking) +- [JPA Attribute Converters](https://www.baeldung.com/jpa-attribute-converters) +- [Pessimistic Locking in JPA](https://www.baeldung.com/jpa-pessimistic-locking) - [Bootstrapping JPA Programmatically in Java](http://www.baeldung.com/java-bootstrap-jpa) -- [Optimistic Locking in JPA](http://www.baeldung.com/jpa-optimistic-locking) +- [Optimistic Locking in JPA](https://www.baeldung.com/jpa-optimistic-locking) - [Criteria API – An Example of IN Expressions](https://www.baeldung.com/jpa-criteria-api-in-expressions) - [One-to-One Relationship in JPA](https://www.baeldung.com/jpa-one-to-one) - [Enabling Transaction Locks in Spring Data JPA](https://www.baeldung.com/java-jpa-transaction-locks) diff --git a/persistence-modules/hibernate-mapping/README.md b/persistence-modules/hibernate-mapping/README.md index 5ba73f35f3..b5d0cb2f99 100644 --- a/persistence-modules/hibernate-mapping/README.md +++ b/persistence-modules/hibernate-mapping/README.md @@ -7,9 +7,9 @@ This module contains articles about Object-relational Mapping (ORM) with Hiberna - [Persisting Maps with Hibernate](https://www.baeldung.com/hibernate-persisting-maps) - [Difference Between @Size, @Length, and @Column(length=value)](https://www.baeldung.com/jpa-size-length-column-differences) - [Hibernate Validator Specific Constraints](https://www.baeldung.com/hibernate-validator-constraints) -- [Dynamic Mapping with Hibernate](http://www.baeldung.com/hibernate-dynamic-mapping) -- [Hibernate Inheritance Mapping](http://www.baeldung.com/hibernate-inheritance) +- [Dynamic Mapping with Hibernate](https://www.baeldung.com/hibernate-dynamic-mapping) +- [Hibernate Inheritance Mapping](https://www.baeldung.com/hibernate-inheritance) - [Mapping A Hibernate Query to a Custom Class](https://www.baeldung.com/hibernate-query-to-custom-class) -- [Hibernate – Mapping Date and Time](http://www.baeldung.com/hibernate-date-time) -- [Mapping LOB Data in Hibernate](http://www.baeldung.com/hibernate-lob) +- [Hibernate – Mapping Date and Time](https://www.baeldung.com/hibernate-date-time) +- [Mapping LOB Data in Hibernate](https://www.baeldung.com/hibernate-lob) - [FetchMode in Hibernate](https://www.baeldung.com/hibernate-fetchmode) diff --git a/persistence-modules/hibernate5/README.md b/persistence-modules/hibernate5/README.md index b7a254d836..bd437c80eb 100644 --- a/persistence-modules/hibernate5/README.md +++ b/persistence-modules/hibernate5/README.md @@ -4,8 +4,8 @@ This module contains articles about Hibernate 5. Let's not add more articles her ### Relevant articles: -- [An Overview of Identifiers in Hibernate](http://www.baeldung.com/hibernate-identifiers) -- [Hibernate Interceptors](http://www.baeldung.com/hibernate-interceptor) +- [An Overview of Identifiers in Hibernate](https://www.baeldung.com/hibernate-identifiers) +- [Hibernate Interceptors](https://www.baeldung.com/hibernate-interceptor) - [Hibernate Entity Lifecycle](https://www.baeldung.com/hibernate-entity-lifecycle) - [Hibernate 5 Naming Strategy Configuration](https://www.baeldung.com/hibernate-naming-strategy) - [Proxy in Hibernate load() Method](https://www.baeldung.com/hibernate-proxy-load-method) From 538f07945a130cdcd0d5b52f7169aa51c5494b46 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Sun, 22 Mar 2020 14:06:39 -0500 Subject: [PATCH 232/278] BAEL-3304 - spatialguru.net@gmail.com (#8883) * BAEL-3304 - Add openapi generator client * BAEL-3304 - Add openapi generator client * BAEL-3304 - Add openapi generator client to root module * Remove .gitignore --- spring-swagger-codegen/pom.xml | 1 + .../.openapi-generator-ignore | 23 + .../.openapi-generator/VERSION | 1 + .../.travis.yml | 22 + .../README.md | 174 ++++ .../build.gradle | 120 +++ .../build.sbt | 0 .../docs/Category.md | 13 + .../docs/ModelApiResponse.md | 14 + .../docs/Order.md | 27 + .../docs/Pet.md | 27 + .../docs/PetApi.md | 581 ++++++++++++++ .../docs/StoreApi.md | 276 +++++++ .../docs/Tag.md | 13 + .../docs/User.md | 19 + .../docs/UserApi.md | 525 ++++++++++++ .../git_push.sh | 58 ++ .../gradle.properties | 2 + .../gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 58702 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + .../gradlew | 183 +++++ .../gradlew.bat | 100 +++ .../pom.xml | 274 +++++++ .../settings.gradle | 1 + .../src/main/AndroidManifest.xml | 3 + .../baeldung/petstore/client/api/PetApi.java | 477 +++++++++++ .../petstore/client/api/StoreApi.java | 240 ++++++ .../baeldung/petstore/client/api/UserApi.java | 441 ++++++++++ .../petstore/client/invoker/ApiClient.java | 750 ++++++++++++++++++ .../invoker/CustomInstantDeserializer.java | 233 ++++++ .../client/invoker/RFC3339DateFormat.java | 32 + .../client/invoker/auth/ApiKeyAuth.java | 62 ++ .../client/invoker/auth/Authentication.java | 14 + .../client/invoker/auth/HttpBasicAuth.java | 38 + .../client/invoker/auth/HttpBearerAuth.java | 34 + .../petstore/client/invoker/auth/OAuth.java | 24 + .../client/invoker/auth/OAuthFlow.java | 5 + .../petstore/client/model/Category.java | 131 +++ .../client/model/ModelApiResponse.java | 162 ++++ .../baeldung/petstore/client/model/Order.java | 296 +++++++ .../baeldung/petstore/client/model/Pet.java | 310 ++++++++ .../baeldung/petstore/client/model/Tag.java | 131 +++ .../baeldung/petstore/client/model/User.java | 317 ++++++++ .../petstore/client/api/PetApiTest.java | 167 ++++ .../petstore/client/api/StoreApiTest.java | 95 +++ .../petstore/client/api/UserApiTest.java | 161 ++++ .../petstore/client/model/CategoryTest.java | 49 ++ .../client/model/ModelApiResponseTest.java | 57 ++ .../petstore/client/model/OrderTest.java | 81 ++ .../petstore/client/model/PetTest.java | 81 ++ .../petstore/client/model/TagTest.java | 49 ++ .../petstore/client/model/UserTest.java | 97 +++ 52 files changed, 6996 insertions(+) create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator-ignore create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator/VERSION create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/.travis.yml create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/README.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/build.gradle create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/build.sbt create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/Category.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/ModelApiResponse.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/Order.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/Pet.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/PetApi.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/StoreApi.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/Tag.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/User.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/docs/UserApi.md create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/git_push.sh create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/gradle.properties create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/gradle/wrapper/gradle-wrapper.jar create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/gradle/wrapper/gradle-wrapper.properties create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/gradlew create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/gradlew.bat create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/settings.gradle create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/AndroidManifest.xml create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/PetApi.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/StoreApi.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/UserApi.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/ApiClient.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/CustomInstantDeserializer.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/RFC3339DateFormat.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/ApiKeyAuth.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/Authentication.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBasicAuth.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBearerAuth.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuth.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuthFlow.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Category.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/ModelApiResponse.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Order.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Pet.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Tag.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/User.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/PetApiTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/StoreApiTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/UserApiTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/CategoryTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/ModelApiResponseTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/OrderTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/PetTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/TagTest.java create mode 100644 spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/UserTest.java diff --git a/spring-swagger-codegen/pom.xml b/spring-swagger-codegen/pom.xml index dee9415679..39d8902956 100644 --- a/spring-swagger-codegen/pom.xml +++ b/spring-swagger-codegen/pom.xml @@ -15,6 +15,7 @@ spring-swagger-codegen-api-client + spring-openapi-generator-api-client spring-swagger-codegen-app diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator-ignore b/spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator-ignore new file mode 100644 index 0000000000..7484ee590a --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator/VERSION b/spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator/VERSION new file mode 100644 index 0000000000..ec87108d82 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.2.3 \ No newline at end of file diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/.travis.yml b/spring-swagger-codegen/spring-openapi-generator-api-client/.travis.yml new file mode 100644 index 0000000000..e3bdf2af1b --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/.travis.yml @@ -0,0 +1,22 @@ +# +# Generated by OpenAPI Generator: https://openapi-generator.tech +# +# Ref: https://docs.travis-ci.com/user/languages/java/ +# +language: java +jdk: + - openjdk12 + - openjdk11 + - openjdk10 + - openjdk9 + - openjdk8 +before_install: + # ensure gradlew has proper permission + - chmod a+x ./gradlew +script: + # test using maven + #- mvn test + # test using gradle + - gradle test + # test using sbt + # - sbt test diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/README.md b/spring-swagger-codegen/spring-openapi-generator-api-client/README.md new file mode 100644 index 0000000000..01fd596268 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/README.md @@ -0,0 +1,174 @@ +# spring-openapi-generator-api-client + +Swagger Petstore + +- API version: 1.0.3 + +- Build date: 2020-03-15T06:14:01.568992-05:00[America/Chicago] + +This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + + +*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)* + +## Requirements + +Building the API client library requires: + +1. Java 1.8+ +2. Maven/Gradle + +## Installation + +To install the API client library to your local Maven repository, simply execute: + +```shell +mvn clean install +``` + +To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: + +```shell +mvn clean deploy +``` + +Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information. + +### Maven users + +Add this dependency to your project's POM: + +```xml + + com.baeldung + spring-openapi-generator-api-client + 0.0.1-SNAPSHOT + compile + +``` + +### Gradle users + +Add this dependency to your project's build file: + +```groovy +compile "com.baeldung:spring-openapi-generator-api-client:0.0.1-SNAPSHOT" +``` + +### Others + +At first generate the JAR by executing: + +```shell +mvn clean package +``` + +Then manually install the following JARs: + +- `target/spring-openapi-generator-api-client-0.0.1-SNAPSHOT.jar` +- `target/lib/*.jar` + +## Getting Started + +Please follow the [installation](#installation) instruction and execute the following Java code: + +```java + +import com.baeldung.petstore.client.invoker.*; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.model.*; +import com.baeldung.petstore.client.api.PetApi; + +public class PetApiExample { + + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + Pet body = new Pet(); // Pet | Pet object that needs to be added to the store + try { + apiInstance.addPet(body); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#addPet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} + +``` + +## Documentation for API Endpoints + +All URIs are relative to *https://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PetApi* | [**addPet**](docs/PetApi.md#addPet) | **POST** /pet | Add a new pet to the store +*PetApi* | [**deletePet**](docs/PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet +*PetApi* | [**findPetsByStatus**](docs/PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status +*PetApi* | [**findPetsByTags**](docs/PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags +*PetApi* | [**getPetById**](docs/PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID +*PetApi* | [**updatePet**](docs/PetApi.md#updatePet) | **PUT** /pet | Update an existing pet +*PetApi* | [**updatePetWithForm**](docs/PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data +*PetApi* | [**uploadFile**](docs/PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image +*StoreApi* | [**deleteOrder**](docs/StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*StoreApi* | [**getInventory**](docs/StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status +*StoreApi* | [**getOrderById**](docs/StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID +*StoreApi* | [**placeOrder**](docs/StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet +*UserApi* | [**createUser**](docs/UserApi.md#createUser) | **POST** /user | Create user +*UserApi* | [**createUsersWithArrayInput**](docs/UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array +*UserApi* | [**createUsersWithListInput**](docs/UserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array +*UserApi* | [**deleteUser**](docs/UserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user +*UserApi* | [**getUserByName**](docs/UserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name +*UserApi* | [**loginUser**](docs/UserApi.md#loginUser) | **GET** /user/login | Logs user into the system +*UserApi* | [**logoutUser**](docs/UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session +*UserApi* | [**updateUser**](docs/UserApi.md#updateUser) | **PUT** /user/{username} | Updated user + + +## Documentation for Models + + - [Category](docs/Category.md) + - [ModelApiResponse](docs/ModelApiResponse.md) + - [Order](docs/Order.md) + - [Pet](docs/Pet.md) + - [Tag](docs/Tag.md) + - [User](docs/User.md) + + +## Documentation for Authorization + +Authentication schemes defined for the API: +### api_key + + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + +### petstore_auth + + +- **Type**: OAuth +- **Flow**: implicit +- **Authorization URL**: https://petstore.swagger.io/oauth/authorize +- **Scopes**: + - read:pets: read your pets + - write:pets: modify pets in your account + + +## Recommendation + +It's recommended to create an instance of `ApiClient` per thread in a multithreaded environment to avoid any potential issues. + +## Author + +apiteam@swagger.io + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/build.gradle b/spring-swagger-codegen/spring-openapi-generator-api-client/build.gradle new file mode 100644 index 0000000000..d86deb75b8 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/build.gradle @@ -0,0 +1,120 @@ +apply plugin: 'idea' +apply plugin: 'eclipse' + +group = 'com.baeldung' +version = '0.0.1-SNAPSHOT' + +buildscript { + repositories { + maven { url "https://repo1.maven.org/maven2" } + jcenter() + } + dependencies { + classpath 'com.android.tools.build:gradle:1.5.+' + classpath 'com.github.dcendents:android-maven-gradle-plugin:1.3' + } +} + +repositories { + jcenter() +} + + +if(hasProperty('target') && target == 'android') { + + apply plugin: 'com.android.library' + apply plugin: 'com.github.dcendents.android-maven' + + android { + compileSdkVersion 23 + buildToolsVersion '23.0.2' + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + + // Rename the aar correctly + libraryVariants.all { variant -> + variant.outputs.each { output -> + def outputFile = output.outputFile + if (outputFile != null && outputFile.name.endsWith('.aar')) { + def fileName = "${project.name}-${variant.baseName}-${version}.aar" + output.outputFile = new File(outputFile.parent, fileName) + } + } + } + + dependencies { + provided 'javax.annotation:jsr250-api:1.0' + } + } + + afterEvaluate { + android.libraryVariants.all { variant -> + def task = project.tasks.create "jar${variant.name.capitalize()}", Jar + task.description = "Create jar artifact for ${variant.name}" + task.dependsOn variant.javaCompile + task.from variant.javaCompile.destinationDir + task.destinationDir = project.file("${project.buildDir}/outputs/jar") + task.archiveName = "${project.name}-${variant.baseName}-${version}.jar" + artifacts.add('archives', task); + } + } + + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + artifacts { + archives sourcesJar + } + +} else { + + apply plugin: 'java' + apply plugin: 'maven' + + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + + install { + repositories.mavenInstaller { + pom.artifactId = 'spring-openapi-generator-api-client' + } + } + + task execute(type:JavaExec) { + main = System.getProperty('mainClass') + classpath = sourceSets.main.runtimeClasspath + } +} + +ext { + swagger_annotations_version = "1.5.22" + jackson_version = "2.10.1" + jackson_databind_version = "2.10.1" + jackson_databind_nullable_version = "0.2.1" + spring_web_version = "4.3.9.RELEASE" + jodatime_version = "2.9.9" + junit_version = "4.13" + jackson_threeten_version = "2.9.10" +} + +dependencies { + compile "io.swagger:swagger-annotations:$swagger_annotations_version" + compile "com.google.code.findbugs:jsr305:3.0.2" + compile "org.springframework:spring-web:$spring_web_version" + compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" + compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version" + compile "com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:$jackson_version" + compile "org.openapitools:jackson-databind-nullable:$jackson_databind_nullable_version" + compile "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$jackson_version" + compile "com.github.joschi.jackson:jackson-datatype-threetenbp:$jackson_threeten_version" + testCompile "junit:junit:$junit_version" +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/build.sbt b/spring-swagger-codegen/spring-openapi-generator-api-client/build.sbt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Category.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Category.md new file mode 100644 index 0000000000..848fb61818 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Category.md @@ -0,0 +1,13 @@ + + +# Category + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **Long** | | [optional] +**name** | **String** | | [optional] + + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/ModelApiResponse.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/ModelApiResponse.md new file mode 100644 index 0000000000..14fb7f1ed2 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/ModelApiResponse.md @@ -0,0 +1,14 @@ + + +# ModelApiResponse + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**code** | **Integer** | | [optional] +**type** | **String** | | [optional] +**message** | **String** | | [optional] + + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Order.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Order.md new file mode 100644 index 0000000000..409fc4cc96 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Order.md @@ -0,0 +1,27 @@ + + +# Order + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **Long** | | [optional] +**petId** | **Long** | | [optional] +**quantity** | **Integer** | | [optional] +**shipDate** | [**OffsetDateTime**](OffsetDateTime.md) | | [optional] +**status** | [**StatusEnum**](#StatusEnum) | Order Status | [optional] +**complete** | **Boolean** | | [optional] + + + +## Enum: StatusEnum + +Name | Value +---- | ----- +PLACED | "placed" +APPROVED | "approved" +DELIVERED | "delivered" + + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Pet.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Pet.md new file mode 100644 index 0000000000..37ac007b79 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Pet.md @@ -0,0 +1,27 @@ + + +# Pet + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **Long** | | [optional] +**category** | [**Category**](Category.md) | | [optional] +**name** | **String** | | +**photoUrls** | **List<String>** | | +**tags** | [**List<Tag>**](Tag.md) | | [optional] +**status** | [**StatusEnum**](#StatusEnum) | pet status in the store | [optional] + + + +## Enum: StatusEnum + +Name | Value +---- | ----- +AVAILABLE | "available" +PENDING | "pending" +SOLD | "sold" + + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/PetApi.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/PetApi.md new file mode 100644 index 0000000000..56e81ea3aa --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/PetApi.md @@ -0,0 +1,581 @@ +# PetApi + +All URIs are relative to *https://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**addPet**](PetApi.md#addPet) | **POST** /pet | Add a new pet to the store +[**deletePet**](PetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet +[**findPetsByStatus**](PetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status +[**findPetsByTags**](PetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags +[**getPetById**](PetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID +[**updatePet**](PetApi.md#updatePet) | **PUT** /pet | Update an existing pet +[**updatePetWithForm**](PetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data +[**uploadFile**](PetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image + + + +## addPet + +> addPet(body) + +Add a new pet to the store + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + Pet body = new Pet(); // Pet | Pet object that needs to be added to the store + try { + apiInstance.addPet(body); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#addPet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | + +### Return type + +null (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **405** | Invalid input | - | + + +## deletePet + +> deletePet(petId, apiKey) + +Deletes a pet + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + Long petId = 56L; // Long | Pet id to delete + String apiKey = "apiKey_example"; // String | + try { + apiInstance.deletePet(petId, apiKey); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#deletePet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **Long**| Pet id to delete | + **apiKey** | **String**| | [optional] + +### Return type + +null (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **400** | Invalid ID supplied | - | +| **404** | Pet not found | - | + + +## findPetsByStatus + +> List<Pet> findPetsByStatus(status) + +Finds Pets by status + +Multiple status values can be provided with comma separated strings + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + List status = Arrays.asList("available"); // List | Status values that need to be considered for filter + try { + List result = apiInstance.findPetsByStatus(status); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#findPetsByStatus"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **status** | [**List<String>**](String.md)| Status values that need to be considered for filter | [enum: available, pending, sold] + +### Return type + +[**List<Pet>**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, application/xml + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | +| **400** | Invalid status value | - | + + +## findPetsByTags + +> List<Pet> findPetsByTags(tags) + +Finds Pets by tags + +Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + List tags = Arrays.asList(); // List | Tags to filter by + try { + List result = apiInstance.findPetsByTags(tags); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#findPetsByTags"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **tags** | [**List<String>**](String.md)| Tags to filter by | + +### Return type + +[**List<Pet>**](Pet.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, application/xml + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | +| **400** | Invalid tag value | - | + + +## getPetById + +> Pet getPetById(petId) + +Find pet by ID + +Returns a single pet + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure API key authorization: api_key + ApiKeyAuth api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key"); + api_key.setApiKey("YOUR API KEY"); + // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) + //api_key.setApiKeyPrefix("Token"); + + PetApi apiInstance = new PetApi(defaultClient); + Long petId = 56L; // Long | ID of pet to return + try { + Pet result = apiInstance.getPetById(petId); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#getPetById"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **Long**| ID of pet to return | + +### Return type + +[**Pet**](Pet.md) + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, application/xml + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | +| **400** | Invalid ID supplied | - | +| **404** | Pet not found | - | + + +## updatePet + +> updatePet(body) + +Update an existing pet + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + Pet body = new Pet(); // Pet | Pet object that needs to be added to the store + try { + apiInstance.updatePet(body); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#updatePet"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Pet**](Pet.md)| Pet object that needs to be added to the store | + +### Return type + +null (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/json, application/xml +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **400** | Invalid ID supplied | - | +| **404** | Pet not found | - | +| **405** | Validation exception | - | + + +## updatePetWithForm + +> updatePetWithForm(petId, name, status) + +Updates a pet in the store with form data + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + Long petId = 56L; // Long | ID of pet that needs to be updated + String name = "name_example"; // String | Updated name of the pet + String status = "status_example"; // String | Updated status of the pet + try { + apiInstance.updatePetWithForm(petId, name, status); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#updatePetWithForm"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **Long**| ID of pet that needs to be updated | + **name** | **String**| Updated name of the pet | [optional] + **status** | **String**| Updated status of the pet | [optional] + +### Return type + +null (empty response body) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: application/x-www-form-urlencoded +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **405** | Invalid input | - | + + +## uploadFile + +> ModelApiResponse uploadFile(petId, additionalMetadata, file) + +uploads an image + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.PetApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure OAuth2 access token for authorization: petstore_auth + OAuth petstore_auth = (OAuth) defaultClient.getAuthentication("petstore_auth"); + petstore_auth.setAccessToken("YOUR ACCESS TOKEN"); + + PetApi apiInstance = new PetApi(defaultClient); + Long petId = 56L; // Long | ID of pet to update + String additionalMetadata = "additionalMetadata_example"; // String | Additional data to pass to server + File file = new File("/path/to/file"); // File | file to upload + try { + ModelApiResponse result = apiInstance.uploadFile(petId, additionalMetadata, file); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling PetApi#uploadFile"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **petId** | **Long**| ID of pet to update | + **additionalMetadata** | **String**| Additional data to pass to server | [optional] + **file** | **File**| file to upload | [optional] + +### Return type + +[**ModelApiResponse**](ModelApiResponse.md) + +### Authorization + +[petstore_auth](../README.md#petstore_auth) + +### HTTP request headers + +- **Content-Type**: multipart/form-data +- **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/StoreApi.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/StoreApi.md new file mode 100644 index 0000000000..7a70c0bdbc --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/StoreApi.md @@ -0,0 +1,276 @@ +# StoreApi + +All URIs are relative to *https://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**deleteOrder**](StoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +[**getInventory**](StoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status +[**getOrderById**](StoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID +[**placeOrder**](StoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet + + + +## deleteOrder + +> deleteOrder(orderId) + +Delete purchase order by ID + +For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.StoreApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + StoreApi apiInstance = new StoreApi(defaultClient); + Long orderId = 56L; // Long | ID of the order that needs to be deleted + try { + apiInstance.deleteOrder(orderId); + } catch (ApiException e) { + System.err.println("Exception when calling StoreApi#deleteOrder"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **orderId** | **Long**| ID of the order that needs to be deleted | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **400** | Invalid ID supplied | - | +| **404** | Order not found | - | + + +## getInventory + +> Map<String, Integer> getInventory() + +Returns pet inventories by status + +Returns a map of status codes to quantities + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.auth.*; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.StoreApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + // Configure API key authorization: api_key + ApiKeyAuth api_key = (ApiKeyAuth) defaultClient.getAuthentication("api_key"); + api_key.setApiKey("YOUR API KEY"); + // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null) + //api_key.setApiKeyPrefix("Token"); + + StoreApi apiInstance = new StoreApi(defaultClient); + try { + Map result = apiInstance.getInventory(); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling StoreApi#getInventory"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +**Map<String, Integer>** + +### Authorization + +[api_key](../README.md#api_key) + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | + + +## getOrderById + +> Order getOrderById(orderId) + +Find purchase order by ID + +For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.StoreApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + StoreApi apiInstance = new StoreApi(defaultClient); + Long orderId = 56L; // Long | ID of pet that needs to be fetched + try { + Order result = apiInstance.getOrderById(orderId); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling StoreApi#getOrderById"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **orderId** | **Long**| ID of pet that needs to be fetched | + +### Return type + +[**Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, application/xml + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | +| **400** | Invalid ID supplied | - | +| **404** | Order not found | - | + + +## placeOrder + +> Order placeOrder(body) + +Place an order for a pet + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.StoreApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + StoreApi apiInstance = new StoreApi(defaultClient); + Order body = new Order(); // Order | order placed for purchasing the pet + try { + Order result = apiInstance.placeOrder(body); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling StoreApi#placeOrder"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**Order**](Order.md)| order placed for purchasing the pet | + +### Return type + +[**Order**](Order.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: application/json, application/xml + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | +| **400** | Invalid Order | - | + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Tag.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Tag.md new file mode 100644 index 0000000000..f24eba7d22 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/Tag.md @@ -0,0 +1,13 @@ + + +# Tag + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **Long** | | [optional] +**name** | **String** | | [optional] + + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/User.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/User.md new file mode 100644 index 0000000000..c4ea94b7fc --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/User.md @@ -0,0 +1,19 @@ + + +# User + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**id** | **Long** | | [optional] +**username** | **String** | | [optional] +**firstName** | **String** | | [optional] +**lastName** | **String** | | [optional] +**email** | **String** | | [optional] +**password** | **String** | | [optional] +**phone** | **String** | | [optional] +**userStatus** | **Integer** | User Status | [optional] + + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/docs/UserApi.md b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/UserApi.md new file mode 100644 index 0000000000..ff3815e352 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/docs/UserApi.md @@ -0,0 +1,525 @@ +# UserApi + +All URIs are relative to *https://petstore.swagger.io/v2* + +Method | HTTP request | Description +------------- | ------------- | ------------- +[**createUser**](UserApi.md#createUser) | **POST** /user | Create user +[**createUsersWithArrayInput**](UserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array +[**createUsersWithListInput**](UserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array +[**deleteUser**](UserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user +[**getUserByName**](UserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name +[**loginUser**](UserApi.md#loginUser) | **GET** /user/login | Logs user into the system +[**logoutUser**](UserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session +[**updateUser**](UserApi.md#updateUser) | **PUT** /user/{username} | Updated user + + + +## createUser + +> createUser(body) + +Create user + +This can only be done by the logged in user. + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + User body = new User(); // User | Created user object + try { + apiInstance.createUser(body); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#createUser"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**User**](User.md)| Created user object | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **0** | successful operation | - | + + +## createUsersWithArrayInput + +> createUsersWithArrayInput(body) + +Creates list of users with given input array + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + List body = Arrays.asList(); // List | List of user object + try { + apiInstance.createUsersWithArrayInput(body); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#createUsersWithArrayInput"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**List<User>**](User.md)| List of user object | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **0** | successful operation | - | + + +## createUsersWithListInput + +> createUsersWithListInput(body) + +Creates list of users with given input array + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + List body = Arrays.asList(); // List | List of user object + try { + apiInstance.createUsersWithListInput(body); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#createUsersWithListInput"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **body** | [**List<User>**](User.md)| List of user object | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **0** | successful operation | - | + + +## deleteUser + +> deleteUser(username) + +Delete user + +This can only be done by the logged in user. + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + String username = "username_example"; // String | The name that needs to be deleted + try { + apiInstance.deleteUser(username); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#deleteUser"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| The name that needs to be deleted | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **400** | Invalid username supplied | - | +| **404** | User not found | - | + + +## getUserByName + +> User getUserByName(username) + +Get user by user name + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + String username = "username_example"; // String | The name that needs to be fetched. Use user1 for testing. + try { + User result = apiInstance.getUserByName(username); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#getUserByName"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| The name that needs to be fetched. Use user1 for testing. | + +### Return type + +[**User**](User.md) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, application/xml + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | - | +| **400** | Invalid username supplied | - | +| **404** | User not found | - | + + +## loginUser + +> String loginUser(username, password) + +Logs user into the system + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + String username = "username_example"; // String | The user name for login + String password = "password_example"; // String | The password for login in clear text + try { + String result = apiInstance.loginUser(username, password); + System.out.println(result); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#loginUser"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| The user name for login | + **password** | **String**| The password for login in clear text | + +### Return type + +**String** + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: application/json, application/xml + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **200** | successful operation | * X-Rate-Limit - calls per hour allowed by the user
* X-Expires-After - date in UTC when token expires
| +| **400** | Invalid username/password supplied | - | + + +## logoutUser + +> logoutUser() + +Logs out current logged in user session + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + try { + apiInstance.logoutUser(); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#logoutUser"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + +This endpoint does not need any parameter. + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: Not defined +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **0** | successful operation | - | + + +## updateUser + +> updateUser(username, body) + +Updated user + +This can only be done by the logged in user. + +### Example + +```java +// Import classes: +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.invoker.ApiException; +import com.baeldung.petstore.client.invoker.Configuration; +import com.baeldung.petstore.client.invoker.models.*; +import com.baeldung.petstore.client.api.UserApi; + +public class Example { + public static void main(String[] args) { + ApiClient defaultClient = Configuration.getDefaultApiClient(); + defaultClient.setBasePath("https://petstore.swagger.io/v2"); + + UserApi apiInstance = new UserApi(defaultClient); + String username = "username_example"; // String | name that need to be updated + User body = new User(); // User | Updated user object + try { + apiInstance.updateUser(username, body); + } catch (ApiException e) { + System.err.println("Exception when calling UserApi#updateUser"); + System.err.println("Status code: " + e.getCode()); + System.err.println("Reason: " + e.getResponseBody()); + System.err.println("Response headers: " + e.getResponseHeaders()); + e.printStackTrace(); + } + } +} +``` + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **username** | **String**| name that need to be updated | + **body** | [**User**](User.md)| Updated user object | + +### Return type + +null (empty response body) + +### Authorization + +No authorization required + +### HTTP request headers + +- **Content-Type**: application/json +- **Accept**: Not defined + +### HTTP response details +| Status code | Description | Response headers | +|-------------|-------------|------------------| +| **400** | Invalid user supplied | - | +| **404** | User not found | - | + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/git_push.sh b/spring-swagger-codegen/spring-openapi-generator-api-client/git_push.sh new file mode 100644 index 0000000000..ced3be2b0c --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/git_push.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# ref: https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/ +# +# Usage example: /bin/sh ./git_push.sh wing328 openapi-pestore-perl "minor update" "gitlab.com" + +git_user_id=$1 +git_repo_id=$2 +release_note=$3 +git_host=$4 + +if [ "$git_host" = "" ]; then + git_host="github.com" + echo "[INFO] No command line input provided. Set \$git_host to $git_host" +fi + +if [ "$git_user_id" = "" ]; then + git_user_id="GIT_USER_ID" + echo "[INFO] No command line input provided. Set \$git_user_id to $git_user_id" +fi + +if [ "$git_repo_id" = "" ]; then + git_repo_id="GIT_REPO_ID" + echo "[INFO] No command line input provided. Set \$git_repo_id to $git_repo_id" +fi + +if [ "$release_note" = "" ]; then + release_note="Minor update" + echo "[INFO] No command line input provided. Set \$release_note to $release_note" +fi + +# Initialize the local directory as a Git repository +git init + +# Adds the files in the local repository and stages them for commit. +git add . + +# Commits the tracked changes and prepares them to be pushed to a remote repository. +git commit -m "$release_note" + +# Sets the new remote +git_remote=`git remote` +if [ "$git_remote" = "" ]; then # git remote not defined + + if [ "$GIT_TOKEN" = "" ]; then + echo "[INFO] \$GIT_TOKEN (environment variable) is not set. Using the git credential in your environment." + git remote add origin https://${git_host}/${git_user_id}/${git_repo_id}.git + else + git remote add origin https://${git_user_id}:${GIT_TOKEN}@${git_host}/${git_user_id}/${git_repo_id}.git + fi + +fi + +git pull origin master + +# Pushes (Forces) the changes in the local repository up to the remote repository +echo "Git pushing to https://${git_host}/${git_user_id}/${git_repo_id}.git" +git push origin master 2>&1 | grep -v 'To https' + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/gradle.properties b/spring-swagger-codegen/spring-openapi-generator-api-client/gradle.properties new file mode 100644 index 0000000000..05644f0754 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/gradle.properties @@ -0,0 +1,2 @@ +# Uncomment to build for Android +#target = android \ No newline at end of file diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/gradle/wrapper/gradle-wrapper.jar b/spring-swagger-codegen/spring-openapi-generator-api-client/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000000000000000000000000000000000..cc4fdc293d0e50b0ad9b65c16e7ddd1db2f6025b GIT binary patch literal 58702 zcma&OV~}W3vL#%;<*Hk@ZQHhO+qTVHwr$(CZQFL$+?np4n10i5zVAmKMC6WrGGd+F zD|4@NHj-D$z)bJV;MYNJ&!D%)v-fQ%q0JG$_z5GVUJTPg0MHPf1TvicY#6DXYBBQ4M`$iC~gA;06+%@0HFQPLj-JXogAJ1j+fRqw^4M` zcW^RxAfl%+w9SiS>QwBUTAfuFAjPXc2DHf6*sr+V+jLQj^m@DQgHTPmAb@F z8%GyCfcQkhWWlT31%4$PtV4tV*LI?J#C4orYI~WU(cSR{aEs^ycxY`1>j1po>yDMi zh4W$pMaecV*mCsOsPLxQ#Xc!RXhpXy*p3S2Hl8t}H7x#p5V6G5va4jV;5^S^+>+x&#zzv4!R}wB;)TyU zE_N~}nN>DTG+uZns%_eI=DL1E#<--Sccx30gvMT}^eu`2-u|{qQZ58(rA2aBYE*ZD zm|*12zg*@J$n|tbH%Mp|d|O9W%VT~xG})R=Ld5z<(z%DOO6=MF3Xh-aF%9Hf$?1N9%8Pkev{wun$jZ2 z^i*EhRt8Ve<7`Wyz~iMZDye+XVn}O%qbhV`wHL+%P+n)K&-UMuZw^RRfeQ)%K=k*m zq5l7mf`4K_WkV5B73~MxajljrjGiJqpiV#>0FkyyrB)@HY!;Ln(7JJ*W(>d5#^ubU zVAkTMs*CHzzvUa^nRu0*f-(ek+VZw+@P~}a;;(K=|!9Mhv(~y-mlW);J zb&bB=vySHG`u?j&_6dh^*se*l_B3avjlE|!!Cb0pXyEXRbLy*@WEQ4|)M<`p8Q!rfDJ2RI!u1hPzNjy&)(kcY~GaD6?)7#dCbm`NFh?Y_g$#!+Qrie7%<7P}<-+W@{sxi4JYI{iY zk0(>m$DxOI=~-&eXf2bfh^&(U@o)>(iA1_wJ%B(+nFH+ceib%HEck32QL=J(BNFh`f>St1%llF8chX7#cp*;z}& zcTeXkwsXhf+e;##!FS2yi=2cChcYfzm$wQJ z9%4kAq)wLHf5wfcj!A|xDsAiAOHRzf*)Z-|daN9y5jK-*R{Q0?xaSX-3m|WeuZ`BJ z>eTi@uQ{OGSDIJ#Iu@JPtOy!C?q)g*6SHORg)eAJGh8b-I*X_+xNqZ|OXEsQ-RWte ze`zjjeV9PpE3ac2za+Rs=PA;%QZ>T{x(TRzwWLp_X^2yC-DOEMUy5So!npzL&-@}u z#>uK#&`i&c%J$!bsntEJhY@rF(>6eY;6RoI5Qkn!&<80X5+1(x$T|wR-ad?4N1N^a0)nBj#&EkVvQ?I_+8t*%l#VK&I?uo$ERI1HMu4P2rLMeH%m3 zZ|HA^*O^dA$gb$`Cw;z9?G?m3@nH6TNYJ04Fd-M2wp8@(;vAvJ ztFoni)BLwncQ3@cO*^+6u;(&D<;N;RKb)_NQ_Qu&?@h3MWvo>6FHG%%*smTwj3;dG zQJnT7Wb?4!XmV^>N@ZkA7Jv9kAfD-gCHu2i+!A!}y98SO><8g}t;1JOOxj>#l zM!?y|j5fR3WY2(&_HSGjgMa?Zif<M@d8W z)4>Ptm@zj|xX=bbt$=j}@a_s|xdp6-tRlq6D|xb_;`9oJlkYF1AH%?Pzv$eIAogMi zf(_H*5t({Arfs5XAPj46pjiudQw?dulW-=OUqBVa)OW9E;^R+NDr&LES&m_nmP>Ga zPf)7_&Gn(3v1qu_a^qW9w4#XIEfgiHOQ(LDi=E&(-DcUSfuQE0`ULsRvS}fpS@<)3 z|CbQSi49rU{<4|XU;kiV|C7}Gld$}Yh5YXjg^W$~ovobybuZ^&YwBR^=qP3G=wxhT z?C_5Trbu~95mOoIXUmEOY646_j4ZL)ubCM{qFkl1u*%xs%#18a4!(*b<&edy<8t2w z_zUxWS5fypUp9ue+eswoJSyv*J&=*3;2;q9U?j>n^q?)}c8+}4Ns8oToBJgD;Ug=y zOa0>{VFrLJutjR{PJmm(P9lPzoPi{K!I{l)pGwDy59p-uxHB9I&7zl11lkCu(}*A< zh492AmxsgwEondBpB^{`I*L&Ut40fjM^JS8VdAWQMlwc>_RUM5|Mjes!36DGqW`xs z4tU4`CpOk|vew8!(L}fEvv5&-3#GqZ(#1EZF4ekDQ@y*$tMDEeG?nOUiS-KXG=rAZ zHUDlMo@X&yzo1TdE6b6!s#f{*45V-T3`e2)w5Ra3l>JWf46`v?Y6B&7*1$eS4M(3% z9C~G@N@RXm)8~EXL*9IObA+PwD)`%64fON_8}&pqjrg|2LmP{W^<0@W`9s^*i#F}V;E8~`-}(4@R4kz?t(RjA;y-r%s^=)15%C> zbF;NZET~nybEsmUr8sH^Hgq^xc^n$ZP=GcZ!-X-Go7J4nByj8%?aQ`c{88;p15Kf>|0h+5BLkM&@KI-(flp^npO3MC~W@Uyjv* z6Hu!4#(NtZJ0*;_{8^xcLrC4-zK$BVo7S5V=eg?R8P;BOpK3Xwms+Jt-8R6us zf_rUHFYHn~lu!)U$e$#%UBz7d8YS;mq}xx$T1PIi=4={c-_cY6OVc<=){mOVn>~J$ zW*2PB%*40eE^c+d=PP7J@bqIX_h4u6b6#W|ir<;IlR`#s`Q*_Z8Q?*s_&emuu8D;NSiPX9mK?>$CwcbjhCuv zO&u(0)@}8nZe=Fl*0uMri02oYDjs#g$OHCZ6oTXV2Y0TrZ}+o%{%i)OAJBj2xHC|F5o+`Qmq`$`2EaL=uePwq%k<;6S2n=w%_9vj$8NO|{` zTEg*tK8PU#DnQ#dQ2mMJaaL|HV;BCn?eQ%d0vY@S7Pu@7 zsf5u`T=bL7NfyYO?K^PR_|jap@K|qQ zmO8CK+&O3fzgEnp2|_=^K9ln~QhxjgMM>EQqY@k@@#np@FnZq|C{EyEP7^NurUm0q zW5rKmiy%__KE>YItATyMhE({0%ve10la=mUd<^AcB{T_$Y`2_N-x;F#3xTORXvhPZ7psmqhXy?WxxB5w!m*4&Q;?t$4Kt?m_em-htVDxora24&6~5z$MG(RT{trtp(L( zy&VDT{@p9_DGoq+I|abw$E!TyTO7j6dWQ25dqdKV*z3E?n-p|IG42ZUnNok? zY4K{y{27bUT@#|Zcni!tIgjE`j=-0rl(tVlWEn>5x7BJBkt0iw6j^4n1f2i^6ebo; zt^&Yb##}W0$3xhH&Nz*nANYpO$emARR6-FWX;C?(l7+}<97Ay#!y%BI6^st=LaJ>n zu{ORVJ9%`f*oy85MUf@Fek@T_+ML0-0b$lkEE2y8h%#P^X6+cn)IEXa@T7CQ{fV z-{^wJGN*+T!NsAH@VNM3tWG;%y{pVF2m z2*0+i?o40zSKVq_S18#=0RrJIse+;5cv#a`*`wNs+B%Ln8#e0v^I>7a_33h?lHo14 zg)CbDfGMyH2cj%7C`>|Rrg;U?$&y!z(U10>(dHKQsf9*=z)&@9u@w%y+e@*CnUS|E z*O^cQqM*!sD|e!u(yhXPi$Sl<$daf3sq@Iexafxt3F#2R&=cK z!gT-qto{oVdGUIxC0q`tg)B-Zy(pxGx}&svoA}7p=}jb3jEjQ!v6=afKI!2`&M{#tY$~3LR}#G#U2up2L{} zMGSX>Yjg6-^vWgeX0i;Nb0=gQmYa!|r0rRUshm2+z3AlehjfTqRGnRAmGhHY3`R_@ zPh4GAF@=nkRz;xMO3TPh$)9Iq?Fs5B@~)QIntSyeBy^10!ts?9Z@tK&L6xJd9 zNzaaz6zvrtr&MPQ@UD)njFUtFupwB zv+8%r`c@#asm}cKW^*x0%v_k3faHOnRLt7vzVFlqslue32rt(NNXnkS+fMSM&^u)8 zC`p{on>0pf=1id|vzdTnBLB;v%*ta`o_lzj21u+U-cTRXR%sxE%4k<(bU!orfsJ&v z3FLM2UT_*)BJm1^W;Z{0;z^_e=N&QXSO>rdB`*cp>yGnjHJt$ zcJd~52X&k1b<-`2R{bqLm*E(W{=|-)RTB*i$h4TdV12@beTkR&*iJ==ck*QlFiQ52 zBZ|o_LP06C?Sgs3VJ=oZQU0vK6#}f9gHSs)JB7TU2h~}UVe%unJA!URBgJ# zI~26)lGD4yk~ngKRg;(s4f@PccDZaL{Y=%6UKHl&k|M@Zc4vdx-DX4{belQ);URF? zyxW+|Ziv}%Y!sFdY@YO))Z|f34L(WjN*v#EfZHn6m)X@;TzQ@wIjl4B_TieZY}qY`mG}3VL{w?; z&O>sZ8)YnW+eLuW@rhClOOCZe2YP@4YWKN?P{c~zFUj*U?OayavPUo!r{uqA1<8h! zs0=rKKlwJYk~34F9$q6fQ&jnw_|@cTn{_kA8sUZ#2(Lb@R$NL*u>08yYGx{p6OeX~ zr7!lwGqMSury(v5=1_9%#*MORl2apGf(MQIQTMN35yE3l`^OS7r;SKS6&v-5q}Gw* zNWI*4OKBD&2YbCr8c{ifn~-9w-v+mV49W+k)$jjU@WA+Aok01SA#X$Sspj}*r52!- zNqOS<0%uMUZeSp+*i1TEO$KGKn7EwzW=s?(b5X^@3s5k*80ns2I2|bTHU+bWZ$x;j z`k@>)1G#JgT=F!8awgol?DqK^S4R*g?e}2rOYRVMUKKxSudO(hOLnnL zQqpxPNouLiQFYJs3?7!9f6!-#Pi83{q3-GgOA|{btKup4fYDu-JFOK~Q1c3KD@fdJ z?uABYOkHA^Fc~l0gTAy4geF<-1UqdS=b=UM6Xi30mPhy1-f^aQh9H(jwFl5w*X`Mh z=Ee5C?038GEqSVTd!67bn9*zQg-r8RIH3$$ zf8vWEBbOc`_0U{b)t)Toa~~<7c-K_=G%*iTW^?6mj9{#)@|# zku9R^IDzbzzERz~fpxFrU*it;-Iu&m!CAtM&$)6^2rMyV4 z$+e!$(e)!UY(Sc9n6hkr^n&cvqy8}NfZz+AQc8fU9lNczlP>5D3qzWoR55YvH94^* z-S%SVQ96pK3|Yo`75D&85)xij9Dl8AO8{J*{_yhs-KtsLXUYqwieO(nfrkB@%|OyI>yF+1G?m7>X&djb(HBNNw3KX;Ma*oMV)cV0xzxmIy+5>yz>l_LLH)VyRnYYce zw$?q!hJzX0TlE0+o5QJDM~sPrjVCN7#|32#rUkc>?-eN6Q0RqQTAl~`&isrQg)ass z+x5XapaYh{Dj`+V096?w)w2!Cnmh?x1WmFC$jEFY4;V)XAl3*tBS)V)3TbL)g46_g zCw9pl^!3OCTOcaEP!?==guEAw;VZ}fE6K-;@qD-Rx~td+j(N>)Wv$_mqFTH_wVZNEEuDG!0T`HXLsf+_E=X3lw4`_&d5&YMl%H733ckO){vZm znFLS`;5J#^`5~unet`V#*Y5In3yb|Ax z|A6b^F37!_z$_{6h{7l~<{u7{Fx*A*#zw{GD)6e}n6f<|)&7`S-txiz3Jm4S5hV&8 zm|Ncc{j_~`^pQ*I#w21;(jwi8GnH4efO;R|r4$tH~i;Bcmp^sP9) zjhJne@yzU&XvFNoc~i(wQ?nE`o6Hk~!;x(%xh7?zvigH2g`!v8L-vEN0DvV3?m( zSW(TZ%2AWf`rS}GGMqUj!8yCp#|fR--Vxfj=9}YD97Gocdj=S z0zkF-jsO>EcPTB1zRO$++k^bH%O`=UkHdHT^5?{$)ot<-K2XIE7js*4OjF)BsVjCJ z*KN)!FdM*sh=fB$p8*EzZmGJp?B_=a-90$FI{S$LLjBU$(lxUj;9 zIBszmA*129W+YE;Yy{J~3uyOr<2A(`*cu0IJN#tmUfz2jIWQi_h)_-V6o+5CjbX!1$lz6?QYU za&|O#F%~hmGUhil{M+J|*0<3&{a1%ONp-^!Qx*LOTYY}L!r9BbTxCjHMuUR0E(uH` z!b$*ZMdnB{b2vsb<&P6})+%O=%a8@~$fjbtfF@Z>^Q@enTOJ%VT)Rdc!wX|@iq9i}HaFZAeY6g8xGZY7h-r1sy_<#YU6}I?L zwvf0ePE5PKbK>2RiJOFO5xNhMY+kt`Qi?Oxo&@xH$<^Q;Nb(&rjPBAcv;XtmSY90z z;oIFFl%lDq$o&kYQ;aSHZHD@W({Y1hw<-I>7f_X8wc?%hNDlo~Ig;63RlHNhw~#R3 zA*f5D_Qo`4_ajY4Gr{mLs*(Fxh(U%oua_u3r%`H!TI)@R!!iqV8IOhIOzI@=7QJ=G zV$(9mEVL(7DvPn0j%_cOZN|vvNg8*PHma`6+oS;PDz%iOFyo0n0e%$<#A3r~$=I0T zDL*{AREUGx&C2}?I9cVL`UcPyawTqA4j-4%Mr-4`9#8GX1jiJkKGpHVr1~Rj#zFaZ zqmE!<|1JCi!LDG?1^Ys62xz(p;Uu!QZB7!C0#piy1_9=e?^s@-sd1gs!h$;Q`TNtf z3N4Elsgl#={#U`~&}FNvH78MLjjavl1x*4pNVr338>%sfHu>bxo2#eZN2ee9q#*Jg zDk_=OBR;8t6=pBN0aj)&Nj}pzqqUYW(tfk?bXTdKbNQFSUMCyN-!b0#3?Z;ijzx$M z^Eo6Eq*NO!Y8K;84H4MHj_xwBYc|3>+D(PFj7ejhECG@5@Pk&8dG<)HwwO2~j7KV6 z0$s}=*D;ek#8$a*sxVlC_`qFkM0%BQQ@v2H&Aq@G9XCQt^^x<8w*=MbZV)@aPrrn; z`6r*&f`x&1lp)`5>-|-4%l&W4jy~LydfN;iq?Y8Xx>Sh#2Lx@FXo|5{WKp@y-x;)7 zl;;_Y*-Nu3pcH-)p0(tP~3xO_u~>HpCdEfgyq7V-!ZZ{?`6v_b-vx< zuu|gm5mG6c@D{FYMLuzvG+A2T&6&`n>XM%s`+Qtj)5XdpyFOnz3KLSCOxaCEUl()M z3b~FYqA3FT1#SY{p36h%M^gBQpB2QzEdtM9hMBMRMu{|rf}(;S85&|A!|Aj}?fMKaju!y>_AS}#hRe_!&%8V=6+oPPtE zOOJ-Rcrf>hNq@lG{{@$H?6ikt@!A2OePLe{MBIWSPz7{u(I} z$PXzD;leHG?Xl0FnWt+Wrkrk*|e3P~YVF@N$y&L929cc=#-!*k)HZKDo8!#+t|?9p0z1KSDKclB&M6~hN5<9~^DIltXKR$+iK*h9k$|@Qoy9H}PSI;b(v>w`8(k70@sfa4nRweeiwZ-syP3zPSsyK_8Te9*(FQdm+ z84ZDah4PGehH72w=Q8bx;pK5juT67rJKb|ovD#COI^l6z0eBidn$!Y?T2;5sN+vTV z$`%Edb<%-Oq@NPZy<2Z3m;$}!9JzIuVK6;fJi>>m3q!Lr!2xXRq+l0LvZIR_PNYrP57E#sCvD^4UU2GVr*Rx`QcT}yQanF z3i~!-2Vkk4S%4Hd2baDvrM2g(&1jZaA1!vLi!I#5wX6g^&PE`0-TovM(%wuaPXAno z`a&j{ai=TsgKpc1C3|)tY#!4>SPBbMnchi}glCBwaNE(4`gi}JY0;`|m`s{HtaP@& zHxwCt#2&z9A7O+=v>za}LW~}G>_tWo$dsRX)f1L=+tZF5E&RBA#jUC|N9ZPa_&z5= zekCOsIfOh`p(&S8dnkE~9#(;BAh8qzi5JYT0nP7x&Hga3v`XFdRN|$5Ry#mq*AN$J zV)l~LSq}2d{EJ@%{TLnkRVn*sdM{_b|4!x73|Ux9{%S;FPyhfZ{xg;P2ZmMuA*cMG zipYNeI7{u98`22!_phwRk|lyX#49r%Lq1aZAabxs6MP79J3Kxh0z1E>MzLS6Ee5u+ z@od~O#6yMa;R}eI*a|ZB$ar0BT`%X4+kyxqW4s+D3rV176EAsfS**6-swZ9OIPRZ& zlmIH>ppe;l28`Kd0z(alw^r<%RlDpI6hv)6Gs?GIpffKApgx^)2-6jAzjZE0BtPBC z0z8!#C5AP${zTF$-Z^v%^ie8LI*rvR+*xc=>fa;`SRUSLAio?qL;jVFV1Bw4K>D+i zyEQ}vyG2HTx>W?Ul&MhxUXK7n;yfN)QS`foM!4>4-(PGwxW!^^UyKOz(v+1BejI*& zQSkV|m5=JF4T0k*+|h|3dx`ZKBVX7H4{5iakAxnD#J=9igW@LS;HE_8$lZy1l|$wX zn<8-$u=7&li+^MB(1y~Mz7lj7?oYf%1k{wT#?(Mep094qqnPv7*OYkQ#7$pkU5U24 zzPLEwAb<VIp_uUE~+r5)jt(>>Bg48_{)twH$QJDSBrUS!j{lX z)SK$6dfLWt)c9%Cml+sRp*OHXB?e4hbYZQo!@=6 zBPTpi&6&atD*#Cn6f@5<>79Mq7o0^E!NH)bD26g}?@qg%*AYeE6Tec@F?y9Q8i}^s zz`)l`8>;h75!kL!`&*_hsX1%2)(lWr|7!}@gn%MfwY8vN0=pMm3WesCRv5e*5m4z|u(zbYCpuxO9$bY)hkL|}mRj{3dlRgNK)#PJp#vR=ka^TZ(tKVI<>M~ekIfd2 zm3UDUNW*ZvS5L|SF334|YD>LJk(EqgPpVxtzwclUNaH70zWDVt^1+cz|F?RdF4HHn z@4~Gs`lj!0dWi2n#>7C@B$Qf7|t{1!3mtrO1H7 zi{=I#^Oa1jJiFI!j>PualW+ncHJ)TelW$bv2MqUG1xK7R z%TsQfTn)7D3}XYU+{?Hq!I&fqi4>DmryMiO?!aN!T4fnwq2vsuB^s6fPW@u*h-JwG zNniJFR(RI*?5HV=tqO)lv}CRv_eNEBR%z}Vnftv0+DUH^OCODH#&;{+aw^1vR z-c~|Mk+o?j-^Z+rR4s z-gNA5guTuab7N`{Y@eT&)!xF8#AeetvQ6d!W4BlO;0#0TxS_( zMm-A-u+h7-PjmOQHlh{Hxn+J$jh?uEtc8RG8tu->og@ z86A%eUt+P8E3oLXIrq#K(nCF@L12>=DVT3ec6Vn=B^B;>D=O%op+0BT;T)FHZ`I93 z^5|bpJC_kB92`alM40Am>Yz5o1gxkIGRYQ)x^+R|TCK)r;Qyq6+~S9Uy9nr^nkvc- zxw~#_9eBBJcZNK0yFZxUK4h>u$8;4k-KpNTblRgS(y&u~u&J;O!aqAMYJp+(BED*d z^I#F7vPOEADj}Pziprs=a{%qgz#eso$j`At7pN~bDw%&ba-+4pI}T*?w-z^_~DfD~Z3Tg+#M#u{s&uRF^dr5RFZh7<|WNEG;P z-_SzXTbHc^yD$r;WJqqJkA7^(zN`nzQ5V16nG~Zobuy)a)(T@Ik>V!qOfw;e z)?AZXjzDJg%BkIEY&bm&BczLuWY~k}3Zyx#)jxg1A9R`sz!_dCb!|13b*3PiA@(E6 z9HmG2R>-YrW93UMQO}XE4loI(*er9J*wDUd1se!pzdpoB_v6^lQl}+!6e5MS`+bU#_b*a5Pkt;o+lOV4loyn2P z$3;z-cX>$R{6M4q%b}aMBF}6N+0RCE70bB;XwHV~JLO&!EB)Cgo9ta_>>Os1HNfaY z4PNu7BGhw`6}cm>glh6i^)Ja{rpLHix?C?u;(e&GI{?!E7$9hd*5c^iL?;6Kwn z@qbBE|3UMF|F$Ok>7YY?CeMzMes@CZJQ?&|R8v5M@XvW}jjxhjl`gzl;rvy6Nn9$K z;1TKGpUgZs`vR!t-sD~2ar{58-;2k`H(MIWr_cujtSCpjue(R z(a7R{q`G+;8qD8D1e?1zWv+pPFtk=k#>f`yqZo)3KwCBgABgQbq%hu4q}h+Bdyh?* z#Rlr*$38^Ru%m9FUTQL2Xy^j|f%*4H*{zWFRsMbs6@u{JM{48fq;F;QFV%6Dn!6X0 zEAr2G{RmY8;Jlmws#%7Hl_TvQMbLnN0KGK=9)1u=Vb&#V27UwM#U+)$hn#hlXxBxO zM~<3s(W;fe-0%mVWtZ)oN|h-01@5z=u(z!V>)I9-IepH|_q6NR_DA>2hxGKt-QX;H6(^FXwcBndi1s%qn2sH-rsuON7*ARP6Qt$2XIy3d#cn8sLh&7#USTFn3 zQm-o6-Bnofon2V;oq-v1@Ye@NuH$Z~+th}Cs>F7=H#=4PKLp%-!EwR&0`a}XL=br< zF>&?HNr}9ahB-EA7a({^_6`taBwmB~hJG)p>8r^vq0J_+o`sOq<{s2~2t}W&1f5`l zj;E0nmt?YRp{ONhti9{4&rvt5uoS0CO@%+Yv>+}ROQAGP3VLu^S4fe{ZRoGviEXMF zhM=I=Eg2~^5PIwEq{~Wt?inz13!axZU3knx_)Ey9<)z<=!TnCPHvs1l^spF`@INYQ zY|J1RWri-^D9mVY5Z{u+bXg#}3rUwSXX>&@PN+017W@!L5H8CvZf0wZxQ=UrHJ{Um z$Z;~3t6ARGql*O1^YY(h4awy!h_brE6&k9B&5l;ya>jDyW5?o$q~=1iV!t7#8&QOx6P zhQIm55sij*Ef-G_?k^$AjK2j?=QQ?^=r{MDaGZ7`Yo*Kp1uoZ=&5|O)D#xAHL)n9_l6-E!b zVV@8ny;`XU#X2((4cTmv5unmYzUmJ>Hm+Kvht&a+j3nr!sljTHUZn^0w@L|WKw2TO zRO>T!>jutIzNI5U_KL}vd00oi6$aJqPeJwq)lIr(2Gt#52i@sqCFaWC)pS$pYoRCK zd*$)r6FCClYp+n>gCqVF>x)ghAbl+h${~Mc_sQGk@+sR@b(88l zcx?*Usr}v|kV!RPfS%HK>Bn{7tdEV$CB5Z@=uy4>^(o(%@R|_7dq69s1(X_8szPZ! zSS~$LCX>-}F=io=YcY~9!vqo3&dh9_Mosio`zO6i|$&p;-9%+~sdYNrVE?Q8rS+eHx z4O$l|b3FUT#2jb(WU<`oKAjGQUsoCgE1(c>3byBNPhKeJ7f4S-hBRqRyePY)im;>H z)hyFuFTDqx*ZgXo$hn+u>TGs~=Bjqr3bhPmXG)v8){EU;N*58NKU5;EIZl z9%|JomX+b6M#jS2`B%~!+`EStMD{|y^P=`xPbD$o6;|!((h!+y%7Y{DuC!NCKDIN1 zER-J?vZ$2el4y~!-0vWjNRoC|ARB`IX@M&;?ZpULcAIu`zlH9 z&JK#H);Ij~fqoT{59}OI#ViA%!lPYyd@kHg*hyI;iMdCtw2&eLHOd1*N%2Y!BG*H_ zu@E?VbtZlI{7B{C>A^b3njh=KdF!=rQ!)oIjwkP{t^I{2q&emQ-C1&U&fPC_viACTbT;(A3qRJeGINz^!0N26vQ~o|#pmjp-Zq46%+{X9n zLGKqhLh4`-(*oDHqHU~-45_+pe(BICF$*0jD&FW?ED=vn=t?p9X(%AH9+;6NcJ8JF zASkf}LfT7Z3u*#i$ml`gKIS>3jrTla--x##EDM{w{>Iu9qV!x95ECU*W_O`q>hcCa zswU!;H3R{}(A6aQ(B)lImTF$BzF;$V_?It*+8ZeiZa|b8n_DN4jUfI0jIA6Q6*c0f(uq~DxrNm!$~G=Uz=qP*)?qc(}|7MQZT&B=Um zr{Lj_R7QJAlwD=CoYpjQsUyu1)C9p5CE)%3nb)~WtP;@6(qGG`*qDT zS(zM>&R<;Z23V|80%3s!`0QpTt0Ay;*xLJeE|DP5@x?a!1)`g= z-1}G_LxiiO(*?R*{(yH#&yl|Seyx6*+ETayQtv7Htk3WPvI;U!@h-e$)gw9>pyKmB zk8#$3BF-ou%=`9_3)Q`0ttk$cymvULFS`Khmjes=2(-QY@eVjJ)rSD)z)1No&o+dz zrGItPZ$QuD;Nqt~U{J?9VlM0g{kx!4$?!?=o?um>#7tjMzrLfv<@pI&cp*5H>XPPZ zu8Xh&6y7v0pGDiQqd-~tBjK%-SO8$8kG&44|{09|FO5BoNkV6~JX>g{b#NHJW?gmM# zhbcS|M9fDc44(seG%$hK#va#4YL98mddGDi2qr;@CeiWO!!`DrF<%=_^*3JgoZiSj zdEv30G5`7ex`XP4#6cG;AQ}(|>CcCTGiom^pc*j-Mz1_oGp4iP*>N125YeWCw#L4H z*>u2Ih8jVRJ?rOj-7KbU7KXpYs2UZf)Vf}(lsM(oiB>tgqX2tILJitw_x z&7gq;`b}qrL{lEA3DaXDOi~HQ!^?xxjjVW|#Z+Ek&GKA2dYgO@zB2V*eY zx>@D06X)(FUz3xz99V3v*k7x|wxiFxv>=N$1Chfp>CErJq)gnf=P!u-QKrYnulzdQ zP56u!AH2^QVnuxTJjcQtlflq>PSm4C!$^fv4V_XsIO2d=O8|J`4bUDtjBchJ!14~3 z#mgUPYF*Z?k;Y)Igdx3yQg8L)M=c%}p3!P-0KOuXI+{*LXJ&w)$gzxeTyr`)h-Nc! z`$xa<>T2pbuU0VR?#FPEM44XDRw+cM6U1R2aLQpGHX40=4Er=lp&2aN#P1IA3|r+L z?5jaRyCgN)b(KuS+(x9rPLLjY&4^YY{0T2Ai%`f0p}sG*R!}{DSf7GdPJ=C2MT1ND zUJ@#y06`CNc9n?13R2KY1K*SYeV87wG%bjcIbn+AR8*FS<{?wWomTT5@`}~z3bFAJ zLR-wmE$iwwJ-TnVEhl{{?+??DJ?DWk~VaX-L3-RLtprT2%z-GfD{UVBR~T}zymA0 z6VZ;1Qr%5q#+Oz#3)`D(%WVWWS4BW6%ZvAtt!u25FO@e{X`)_LH>p&pFzx(wvNEO- z!2$Z}`iynmY2j&UCmRNB)9Cn3MXRls&PFVHzkzr;)B^BCMY~6lYY>0rsKT zm4}RV`Q7tbn)Aseay%@-I6ZT~PBsO?D|>kG*%(PGo=|gZ#0zsmE})xxtAvaCe&$1? z(7GyH&^jm!cguuMo@CPA&-lrdE&Aq8GIOuUK9jt{K0ldcvJJp7I`ZMx-EYj$)hl~) zFM!U~HxgO+lb$1cIK-nvz<5OPs(@d4tB6DUa3?-bJ98|dv-kIdtMS;9BuLc{a~_wW zO$u`rNymsAeMH9zh(|w=<*V z&&B{&O0Am`<$iBa)>pNZ6cO`d^3B5%=gmsH(HYZw6!U(c@}#)19F}`BT+yOfamJY$ zYOmy2m^k+ADH2klhAJMLq;6>t3)NREUgk*cjJHg{NBkVhDORNK;v5362&NN=y*Ef- z$vxYTG5Ga{SI&C93^Gsu9G-osqbC9PbsC&@xxGlF?o{!rs9|YpEE?P8ix#yS`7JUy z%ez(_Q%I^RwPrW%rFF(+mE}rp#Wtg@^>O7T(@LFA7j{LNrL=XGDyB-|3<*mqLL_UA zUZz?ulF$5O59-WWZ!d@hRxC@4d6?okW%`1$#<5w9eh>4Cyr#xe5%VPG@TBe#HA^O} z1&q{T_TMTr($f<()ah%TXapiGp}`MAC7>0I=Cx*t+bXy+gMyk*#(A~ft=&4YBdQki zQ}I=c;etc@sD4?l`eYaksPtJnx5OUaZ6u;7p64DUuI`omrWjht5$8+cqb6Hw75WNX z@D(fl7tDl2H)H%QYyX3>cL0*DZPv8+ZgaP7+t_W}wr$(CZQHhO+qUig`^@>y%s1~j z6Y)pXii(P=SQS<4iS=aOnR(rqe#b*BR~GN+bMNQSnhcMHxhVf6D7_zYs}@oo$eK9sZig1_lH0|C z&<1W;8dh6lutS+|02t0VqRfh9R+%!~9YsQ>cw-uGi!YMSo?19?Sty(u{GRqmTx8Zv zLz|nph}CNn+4a~dDzMog(j+NForDvDjLwub!b;p@dLHSBO0kjaI0CPZ)8B2(HNL&A zdr8Pw@u(POF1J*groJ~!1|E(GmnR3L6`P*3C;v?R zDw-pBC=u%}<}P_);mn-_cE}am&b1_WlqnWVzFS;*NhwoOb%+#0nI|H*Bw6_0R(=Kj z;7@eEqYkW2OvWkoz|yY1gZAJw8=>KShthS*ANzYdDT61^AK)>0H%LV4q3}hw?bkA$ zF$tz;<5T59v0Zd$)unmJ{vu_7eGDP6+pe(H&n^3E)g^rB?pn?GT9l1gztAUpR*+Kvt=FE~M zq5rZM&9v>ww1mzrK)vx*0;;?tnqA@Q;FBC@$2~=gy#jW$bAJUNIl_YpT)``*9nnkV zF!&XBK8(PeQfnScH*JaYqy{1bN4MwF=&g2)`!Kuo165*d^1Sc_d{I4>6V=>74c%g4 zXE_M`b@syq%jQx9VRp@ba!rY|MRhr!S3bN!1RT}^I(2gXE`KT57Y;maGA&dHM#`4* zy%@6YB0A6Z^?fg!$4Gq0auM47(jE$Y4osH zhydBwQ-S~vMS7)hg;AC=MRf~AHZu|Ue*bk=ff`!Ol1%=|W-a+~l)QH04q^oeMZHj~ z8$8jQn(n1#O!_7sg1hi;{v%?nd&gK7tfN3I{A0j zcg`ISk^Ir4G=(SvV$v}DE(nE+%rgFkT%cu5VR0Qa^H4-xPC*7Y*+E8#xvyepS#xYE+FyIIi0|5$J%mKAB58%MgleT%Zx42e^L`TdA~Ips z=NvgHNpYZju?*J>oNcmd^(nFUc+-bu4*+9)qIwU^g?1_4-&-`uZm&f7F^1?@3IvJc{gnlh?no$E9jFIfJ8i+33;o-!b2hD@}}{o}J4{l{44v z3Cd{3Lj%9^E43SBXmIvwsA2_8sXgRu=4=H{j9R(fYcCzOXriTZ51l+HcXr@)^?rK* zmc89=w8MW+txdobBh`X4rMvY#vuv0GIEO67sgL}mIw$pNW6s8Fd=t z@58{pFs^Oz&g}CPr8EL~QyUjk&}1qyO4;-6m0MRd4J9T2r5_j+YdeKP%Q+jnWNdV| zUJLU&d%m|g&3B83R^8K^WM{0at+=9UdVAzTnL+CqdcT#($38|-fQ|BJbHY4vk=ANj zvX?ek_oYp6t8bQz-T){|-5OGrv`IGd?>X*h(s{MvQ{j>fZbx<^-)&(j8(N+z^sftB z;V$0+Wd0oUR^&)Q+2bHfLt#V~jZT$UPUbkd#vD#zZJ&huG+-;T%sU~ONA?a`Va|T%I0yd%0*Xr3>p#slVg7Y<6o&Bx856S zg;7Q>mCFF?xq_m}VG5`(0fIX(V=yvQ;xjpwNhrLFMui8xdBw2aFOvI3t6-NG3%+d= z>1un%A{1+tFrn2nu2%`-hiqYhXDga3%{ZVkC@ROtTcA;g*E@K4i_G1&^P#Pl_9*m& zwBVKqZhrf4bhw@M)78cm zBMB!;A)H{6h6AjEv&|DGxYRmY|e_ARf_dMIvm*-i4hR#IU_#A_QYP@L|sHs zo@Ky_Bx6e2??_k;7vjibD#pM*T7`h9V&s(moOn_x^N|9{gkOtFY~gDqSo+7meUjBR zK2jiOsA%PwD|1*KC^m(-WZ5j2AWi;81kCi5t)KouHKt|R6m{m!!n|4YN3yyBo0mSZ zN^yj9>I9Y6dI&$!T7&$%3Ccxua0-&DoNJFbCV%1;h^-U&1Q+@47qrKld+QNGOrh{a z27PfD|L06XuL1+ZMc{_7rB7bd&WD%*lbypj>|K|<#2#t+qPXH zTm`5QC)ktLW5+G&4lhvX8DgOK)|mvQ_b^HuJ&=wP%Z6%;E+Bx|#|Q}vOoGR(jK}sD zk9x4A-V%Hs#G>J5XldT-W&|Kv(!mEi;J38jdK>L|Q7~<_no&|~Fdc~yhC~%VqQc2e z2|pva(YaxgaE`xa5=u=WkhtI|f`XRHhA6|>1`)hDgYzt9kByS$l*OQ2O-a#Iq%SLz zV^&-mn{^KrM6&BueyiV}>&)9rr)de2+DkV8##PSmko(<`nqPVr^n_V~UoIi`_yVdB zzcj4`b5QijKNrR%0AYi<`{NDb!y1^#Pv|K2N8<&wlO7-JDa5Yp?eM)pf>PbMq@)Wr zvki0Y1yLr2WfDb`RBPgq^VC(KH;ofR#9^i$TaMi9J6p5TP5F8<&ofnvL|`*(;urRO z?0k?7WiOd&^v);ux~R9Hznc3moOxE+O$lYV0Ku|hENFV~?Lt!QZlMNp1%d#^Rv!pC zfq`*V)n<`Io8N2XGBOjLYB}#{g#>o-?Hmb6$VyvSN@nI?3{y-pdNvcYe%&%CIeh?s zWfdM@$o~R)P|M>ElHW0BAMI=ozdH-Fle#Dvq-bpmPg-!rDY|1*o|1dvDh9{`{gt%n zFemDyrWMrywXJ+rV5r%UR~0T*75`i&rM4=%7}ulJyHu{rZw;C$r+nn@cLyLgh0d-A z(3SS5tW>ZK0in8bOH$vW>HIcipgUXYGUq49#>Ixff27cCfWz$0vR4Dmq}CBw<~4Sh zDe9adM$vVItE_)3FJT5Bgk}V=1g+Qvf5+hpxwh78gHe$<|r1^Nh?B&_~xSq+nVdY+~dc4GJ?e5EpV zXs-H~6poV`Kh5kok2qSUMD?0&WXKs7T0?Z-J8zti^WD-*_fo zhAqM(p+l2*(|b>aZC+?aK~^_VCZkP0>}TxdEC-KcmAx*YS?wTK?cW>PjS+NxM==Wg zg}e_*NcH%2(J=+WVL+;P)kz0c@48^4ZuemowCO=rriJFSD|#7D2oO{}$kCbL0#0%2 zQe&D2wwJ3%d|+L`bE=&9k_~(BOe$ZFap$YMGL$&$D0=mJ9n%He#RRlC3f=|WyrI0L zA_qS=kzzw8f_QiJYg_b?xA6UgBS0tT_Y$!9>(J-Q|m=O+8+wIPlb5i=-aU~kBf=4dD zd6Q8*EoKqRCcMNO5q%nez-osz1XT6PZ+r7r7A_{!vpDIfE$$yCUU66H>HOUO>u7aE zs*>|KS24COy<^3O^xXssCI`2iF%;A&7{j1UDk9dvv< zsUbj2HMoFr%{j!bRrmyt%jM|4UKza#}%Vf*_fEvi$*6J-h}oRdsdinr_W1-)p24zB*p9tfDdUa27+yi5W`#8+~eE_NyvNZgCP48jF8P; zgYS#IP!@sLe^SeCy4jwre}sC*A4Vk3|EzFISR4QEai+j{bL%-B#Nlt4WJN3eh+Uo) zVtaBF&A%PtbaaH`A~$h0I(5#|WARn>4Hbxy+Jn-$LdJWL+&({?oGdxCC?@gw`D44O zZ)fV$Yi@4u-zGU|!cfh6Eq?2C3Nn%TL2ZoA1+5g5O#q6$QGS|1C!;H{)PU?dDlSGU zLGKxOa;zm!C-Zghet4U7l(%LaEQnKF+>ECNt@`F07q-JO?%%X~*k}Yndc#f*iq0`hgW#iOvymYI0Ur}T;8qZ+%f1paM#v7e! zUS~+CMQqEbYZ%Ix+4iKAGa>>DLya7d_5zQo_zm&bP6F_75Qk^L7A%?p74r#_+3V6R z@m)%h$SZlQi)PpLLYyya^FulLkrPuM%+!YnWBCX|f#M*ph-`6S5IH3F;Os;ZZ&cDq z<~WF?be7SQre3OHq63A%t27ee4>e--Q*N)lFkAI_P@Yoq?Bd0s)IIqLY)xtXU`k>x zfQK0;b2n0v{oPhQju4$`uD>)Syw=X_l}YEfVF8)awhULL-sJNdq;z8~(wyAEW&sDx zxqHk8ufaTXHNnIUP~eE&k>D!g#IVt73wHY+ugJwtuy74u* z1qC32jRV4EWbz*0B5d5qGm7FB;V0Z>C63g4n6hW?!BfHU=hqZbuGx&ccdij#|lWok>4#{m^Fy>{`JdOS zjIM(Tuf4sYrJltP%2vW!U)Mt5hd5_vs^{onYW=T{?nF6taSUF>uPLMY@>8Y#vd&fU zJg$MqI>EOkIj}Gpu%?+k{%zvX7zqvMeuMm%YD6eLoHxL?e6eW>J~|~Z&lHB^r_Ag0 z{*SlMeG(r}i;4UY6e1TDhAnY@tyh=*e7>7?vlwq>&py69o*=hIE389P!iE)Fe1v;HN5fVGS&&jBzQk*Q}Rb%{FF5H zt;vL@*J)TU^_AGy%>+&9)+R@9XQHe9%Cr#w>Q$NM0~WAiktZl>9`I-Ypc0UjVU1rn z_FPNg@88w2iz;NHBJ8)vM$%1oe7QzSs;NxSieG5h->Cq6`M#YqU;tx=1hYym@h%fi zzWLOcEgsbZ>jW|mkR)qpxv-Z}J6iTzy?L3sZiv!nbZ3a;A~Hu3j6-^%FcrouBW^*9 zwOO;eD$2J8edza=ZDF&}5X#=B9O(;A4zyM&5yTvxuoqjP+FZY!ZYI`_D=;czTJF-e z1-$=(BE%9~*+c%p5UT&+n27&>tc8D77L`o(F_e)w^~KRuv4^AdNE-D~2I(p(SCPRP zc{V^gm}JdYd(~~{max0nhdPp5j3){eJ z$LuzR9V>9)451K&?27Aps3vsd_bU(1EDOA~g;@vOO2Ty`4MFO9u=`!_wEKPQp>9L& zzuUbCBGHhsuxYBy-^Uw`)=n5pSF5)!a6qfH$^u&=0GA(}B-Ixjj|ce?Bp(~$q^7BqWU|H8 zKU!?5P@+8*_63=^7)|h<=`vW)2%PZF(`Q0Lr0x5QLjWKIQZB9)OOB_ISy!Mx`E{lJ z1=1d&Ic*{{_h#6sNH^Hz)~vB7gCTbuUkVrOm(pCye57-0NUsKiFMeA#@NBB+F5<+s{(H7mQAPQx`OR z8xRz&uf&f&-?8paW&Q%EHCq$Lv~}lCIW%s>Wxj&$Majn9D~*{Yn8jBZ3b9-fuz!82Hn?&ZI2_JZYAy$kb_?7m*?J z7EcrbL2*)gJ(Wl`yg~c)vC1w>dR$LezB90-T0%EZo|KuQOirNpKJAd) zr+w2F#9m@j64vevMEx_$M}ESx!oajKsI7|Q#c-fWRsS7nAgMlxf$l`eoBx6_u1LP` z5wVEEAYNPN*iXKJza7=aP+z_r$z;5})SQGWl0SrU7qL5T>MpzjZPVq~an6pv29s{gIn1Rh z$*Vp>0p=05JN|HRiyOCbpgpZ@;9Xj|o3DNV!%Xn6t3hE>(=2$dFuEx{osGXYv`m73 z@j>86*-gsSS^3mR)HB6Bj1fy+E{@9e{bcRLU_iAqDzdQUqG)+sqNE`h1 z$3w4loJ+!{F4NdK!E7Vu6L}j5d=VnffP!j5b(b5(u}{;?o9PB`YLsrEsOeE8IUM8F zj!}~kYF^$l^i7CS$AnS+a4#EnWySE!?hNnzWe>=ETyc4WCXpNzZ9R&vLWR9n2)aFS zeT`FE>ZzLpjPr*qdk%A3<`U8cpr3K~?abpqM})l-j}Hz+9tJcw;_-BzCtzpYoNVk^ zd4xI@9~_|+Y_6S*Kx+?A$c)OqC718Wiat0Sl%qFMhix0?j{gw1XO9$zQhjjoeDj|S z8hS*$R7Ol=9=Sd-9s*OgZAC1sMC*(iexn}3CMYJdNZu8^S5)5@Bxo7ayS4fG2D@ns z(Y9t_4DB(20CAx~=eL=RM?RRc4|4V{?Qe z=>g3K7H^2nxwHm|*N+zhk9ET-=0ak5wZAxM<)DFY7|^q+@a_=>AXMj@vZG11mH%nQ zn9XfRt7)!V&u0~v+`DaED;5~WX_cQ6~@iQ$)`#bKdk&+uvYtZMGQ??&zRmpw zbc5donS&q;jPQE_7rh5{ONJKBM;cxKH>r!f)K=VDf}bfc1B4Nv3C}__D{B|kU4Q04E((6!W^q+&Xb=m`c#S!$wEEp4py_0 zDJO?v%A16hzF;#-Lt+DUyec?VXUS?%21=wBiJ<}TTQMa&n$+5wnHr4sni_Hb`tFO; z((Kg?Xh0p)JZnUc=-mE(Ls`z5)+Qr8;F0R92sj9yEJx1kK&wQ8S2S`)h+Qk?^jShBw0n z^g^Pht7xCZvs&|5W95{bypf4acXhX`O_>*QyEk183j48^Ws>JcasVrhs5G9;&2dyi z%>jCf;J1W^x5i(=Cvt|^PAWSdNG}XTJ@;UD+R!_#xn5!VD8@`C$I>Ipes@q*x>0`l z)z8=i*VF~+bxTYjaCr)lzaDau^|9V&q!IlGwQu0TKbn4oBljDL$D`d(xUR1D_M2H5 z_D)E{)YMOgPe9j&Ta=X`w!K8L8Fz1tOon!uWan9)huounS4Mh4dF)BRXPW~rZ){=b z8GKrX8h<5U_7;gkNu2?Vha=mHR?g_-tDJ7e(~;kBqw^DncZb0-heR1$Eu84i7(X`&aR*AQIwovW z>fz)N@L0uBeI%!;>fF*(y?aB?LspSl*h;#V3|hH@lSBCC>z%=##r4vBD?~% zIcaMD#Ep&MMR|QloYSVm4m`6&D~o=K)KUR!2dn`e7}AFYi4ni=M| zwlXp`cKoTc{O?pVGTu@effshzIQL;~Uran3$O8b$6lS*o0sT!BoyZd(zz&P7axA%@Nz)_qI zkD$LWxQoOtM=CJA^aux0eMxT|$TTV{XcUf%R6YWWWpb~~Wr+7tk~!$o(-O!M!{#H? z)jCw2taNz0WO)=*Gud3!7Hi9?DqB;9JQ_pLDASj_PC!c^M|om%q>Zz+S3oK5Y^V&l+!?6vHO@6@c? z%)vqVE`pRD|ItbFC1kt4ApdNC)&9im8NW=RUr>

@up^y4&I8N>~wvL%f(S2W%NN zf&x46sN${5Gh+I9cd>g-O|x3@x#@hdvU54zx*WtnC#5%quWk43w{;_G!4&;N;wy-O z?urjbDnKfp2u4gknf&*wBJS`YfdzBa#pf^Lo9ei}Z)MCk6MP}h0OYrd8`jVipqsRTq}lh>h#|o4yiA zbPQLKXatZ+L=I$?XEGfd7x*_lf|=3xKLi)yj}jQ9pD+OPrv;Mqe+~uywe$sD4D}uV z4@_J6*&E>)?K_L=^f9)ZpbIb0tyI>qF^OuZ;8LrA_T9JRowWUXNjyBVFxj7 zcFv)I!ZI!9%3&ro1=#}qZ!W@`!*%Do@xlC)>lS-KJPYY3@3mXj^ZUgyXXo8DiZ)0M z@ORv8NQ5xIiv%yy7WuvM3l7ZnaX8M-u4s`LZ2-*e2V%BIin4U@4b=3ps|#~L^v#DXv3GDk8H#;lK%qAV<%I5Z8dd3-sIMfqq2WY52;$Y7| zC@8Z_G%EJ3tOhCq_Ad3l4=IN9=Ee$7k#R%^@JPd7SnqL~*a3EWdfPj^Ft)B}bgnkr zBT1I)!g2ha@JU#wQW1op@1SkuaGVJcEJVhstebVvoHV+n`EI?;^p~M~tfk#K1CBi- zF<+3FQvDXkoVE)E6Bj9T)Vlo9rjgCj>S}EH&DnJgn49L@7ZaI=v&F?OY*>NLOQ-u43cR-0P{LGZCyKsW{^hNC8iDiqJ{~) zNqU!S?7Gb=jXSc_T>xTosLbq!#)VKVs^hKlReb|!_v(O0B(=A8tA0Fic+K)>Lc!(J zge-eb*cuWjJCE_q)D}kLQ`X73XAD=didg`EDAk|uw*rjJ1Yj*bj<;`v&pOnps=(g<^CaeJRd*q!NQ`O zTAcA*KCphxtD>M<0l)OpWo@|W=Vs)XFpM7C;96VQR+W3~AXoqC9@yN@7J9kuboR-H zHL8|U?V*D#Jg&`hR95a1#ByH}mfw|kcIP#b2%C}r_nxhIoWdo%k*DB;N)%#~P458H zR&1-?mh?}HxGi(-dh@nkK_H45IB{y)%qwup^p85vZeUpqh|G;9wr%q$_*4*|PS(bw z3$<2M;y;*(WAtHSM--PRyA1<)1Xe^(yuRRaZX9nR0oP5%Wg)P(ak|_q$^7Cd)NP#f zFt*;;hP)je2EkvO_Juc*@6Fd}(xbH@+`c?h1(9yjJzcLY^!{hs3;2?q^IfrF`+D{7 zeAjrrb~tUbxms|met4=I%jCVN6O3DEeY8_%NiNb1EvTu>AI1J!n@36jd$2##c}B>0 z4L;|^v$`6=K#^tk;MTA+ji{smQT)gaODj-((|WI%X2JbpJ46#0RZ&FMJeh+Z<&>04 z)cI;7Dm)CZ1Q9H0Ge@zDXKAsB9dZbg4?1joh3}_)K2k;c^(s6)kl-$}hLll_T0$(y z-4SgpruNv#}%R(l@3!%tj5l!d~Np>{BXo}gF5QWAP7*n?JW-N~>|I~-Sokci&_Ho87f;meu+(2@Yz45X{^W92m`3_^%9FadE5^cGO72ffn`$&G} zGOIPIF?FsLh^0eater8)<@~LjNIyP(W7F~ackhd7ase+Gfo@-RBG6$Q+CeDbE-eiO! z66k;0^Ze3P9kEj(yiZ!_vx)K5>+Jrl2af_iKMbiG*Z6y})9{?`w@LyvBpEEC99HEm z94J&4%248p>c%Nb+Y?Mm9%w8P;5(?F8nINf&_*-><^LeQ6{hj_UPeUhLmtxd+Vmgt zX+WF*G|x;d1!gF0D5?$*b6|tDV#m<_?(f{b+Jd?J92?)y8t>gZ+-KQ+Bj*PJW__xR zdf03Su)GBsi{L~F7m?zTiiu`Wk!YO=QO{H#)PP2?loJ6bfRs0oKxO3+aYm9`#}5V$ z`x646$5C08JvW-c>mV&jy+a+V^zH9IQ#Inj?BmB?I0~jhx7qLD!cSQ9{<) zCB(xvh>|7z&?P1A6fTeZ=vH4`HaRJenyQMrBMl$uNuOX#!uWTr0YsU$pvq9H4wY>t zl^X-E=|ppy073iT6Xv?zU&~*SOz)S{s$uTKR(W@_aAsUm!9UD9D`~`uK!3`Buc{%2B4{J%ioRlMx&#kB{e!Avb zJrlj#<)~p=4r6CfO9_3Cn1xhg=x7nk+LY}yn%fvBEBY;q4p`CSxj7WfX^CU5+@tJWJi(W&KcO*jj5x;xDLZ*AxFvIAYA@P8yW`o)9#pos(U zSgS*I-N9vd=^11lccI*yNQxzMgJ!_I?64MNHZL9-U_DIfm>8g{k^fj)WeFHM8I_z& zZ3l@3<|n0jQSo~R0*Qcqvf~?+vNohOl*bzy=)XeN;2a3p1~0V$$gAWoVuI=*iPkyO z;E~luur&+0{@(mshrT+g9pcf!^T48w$vch$Nigsv6ylw&q=E-ICa#nDgi$8vmBC($ z=yLuLM0U-^2^S`{_ZwTz$|kB|ZzUr`AM@J;{X1nZJEj`$4skl+fss?6#-GZt`JdU# zvVUW}%8!tF0rBe>`+r}#|FsnVkBs^MUX+ze>dHSpWnWVCqdl~T@Zci3NHq%q1q0&Z zjiRz*rIA75MSd&j>=Hq=uts|mK)cc}S884FYT9`Ym2Gbq-?zNU&7M-!u<)j1^s21K z7oJaB$L#M;cjw#E-oI~{yJTr2o((;6binRCTJm*%J0nrPf%?1jgigQI5bI~2dsFN451~NyCYYvfVfu5!YwE`!Uv%`& zB-2spw{|p}vcNP<;@k3}sV|3_r|H|Z4JC9~&KtI*)@JhM?U=mg#m3PjRVoE+M zVYM5uWSO==K5bE81EEz2?F$jdRB^ec45FWK&Dz+e}E=Op=h#{z^;qey2Dx+2Q2qzwA-MpAB% z6U&685w0+}tjouEmcVXOF$U)7w=8u*B7piVzASTr-X|xfrQR1uvc@IZr$CD4MUVF| zMre!R*v|cBT}rB>9#r~c4@(}lBCp$9)X`O$7f_9s)8|{>$Da!Go_qr=;4rtnr7TgXUpffMV9akHEvEw*Z&g!2Env6(!b;)$Zkq!j9UGy>Zopi zUQ<$5Ex<;BxM?&1+E#8>B$er2c?TqH!q^=LX)1lV=@=!xtMbm`$gt70@|} z8AM$V_n1o@=*E15EncO@{DFc)hEBSA@Nbk=GkNsF#}_mBtmF20k$-)eOP+G`q*EAP^>>5d@ea zg6^gb37{ol+=uYC3->5=jbqd}&J|19Oh}yYviQ}E@&>94`r85c>mo=XKA{q~2C*8q z1(8IqD#!fuWdW8DT^RfX)ssdyOzHq^sC=mmY``qcE8^g-o852h1`FBL)_0fHqqzW%Y(brO+X5H!1sl*7|2>*^XZQ^Um1qp- zj{+=uY~SxwTj1)2rmt7luK=kSptJDqqF#W3sech+R{=RBs5U1mcd@_EU~~8?dsmUjsf7tKBg%yZYVwFEDFu zWWQwnb~$%v)IaYXT;h~afPZz{4^@br zn($GS68Obz0BZLqKb0MyvEEp-F z%XZOu9nt29ll>hIY!o7Ulpi znv6Q&d-;x1Q#smNV37IAjmqJ`f>4;j)zs}@5Ggb8NHQ&r9}YcFk1=s0qSmfDIT zL}IzQfY+Hb7z3YWw>3^;vPtIw+@lL;+6f0j=R`K1?Rs$3&Ft1)@NM5zV1L&`Vbl&7 zswRx&Edg?U7fqYMBpWQ6jO&vI*KI5odc0(9&B?LUS$lNhs$&T-QLab-p|8suK`a9N zU;>Q)dneC-M2!FT|4RScQqNRUcScY|-Hb2FWK7ixX)w*zIKVgM!)R>CsoYSb9@Lsy zLJk9)H;@1=N~KM;fxCA80PT1w>bSwB_El6JKa7XzdPVs_qfTy_HegHLC>RgUxX-lj zs_$O^k~(_!_WADl_zRBtc0-mj? zs$_XlVRk8UA;TzI%p`NZo^_F0EiGU(u~@&bF!!jgly!a1es#9LBez7Usio}j;#J*M zYwchj{qF*wFL`?T^AP-=5n(>kT+$T_0iGHp4PM3Z+@Rs&k(ghDz;|7e>IBW%Q&>Q* z*|!8m`k0#8(2SfZzjS1JdAS)iL*a3Q>Tt-uHB0^>6;1Ac&)lXvA#A+^~TF&^<-Px{Arzw?$8;b z6(xcC)ary#!{#M(-LV!}WvwJ94Y}p+dl+)^9$xeZPD9+g#b-y4E)=6{dZvMSy(4bs zQqd@m1o^6YxMp0{hxGGmxj9Cv;|d+QcXE|*vQbI!0Pil2SOuAXlwDZl!rN-01kujv z`f06S5M~gsjn6G_ql(Z9v;Hz>hvm)t+G*Reo}Oz2DoZC~IJYFxV3=*1bcDI#V-ehb z`yS4?O;M_uUKUWRm9-0*%jA%+L}L(ouJ)NW*6>k4H0cLNq(fNgHv4Jnoecj0zTR!} zd#20Z0rVivt#5;(=aRdjZc}W37m&` zO8hf+O$5W$AK*8A8`$z*=vRHy=*QmoFlAg=(s#RhNTHVYC1}1K@hC|GVLZ=F6-*0x z{+sO$vPen^=y*Dt6A!PzJ!}(6LIqT()R5jys9m(YH-ka(Nn?~~Rtl-H*pP{zU-MQ? zlXus*&2qLymA^@KO>Y@ZjhbR)e1(|kVQ~2STn}zH$Hv*3wWt5KBjg$eN#@{G$fcMS8-`5K^IA7m_aM6 z`$)$n`bVh3x<&!)d?X1WLQ9uG9!?;qPGiS*BaH;RE}RifZm9eNEHWtim)l0DD^SyZww8iac z7r6e^#bzT+IQYWSF&Kq!LAalh*r_;Wzi*>jtu~LuXq%d^sr49_?y34lr!u2w+EXxL ztvGKYoa^y*IC%Ypz%YnJV8{reNW^fpBHc9m`O*l>0iqm+au0Ze=X^~VrnQF?&PU+5 zvDnPzI3)KOpigkw6k+Ys(1~ggta{l}hmoJQoMZf-VJ+IOf#vtk(!25;+d@FGwm{aR zAx2bT?D_&PU}I*Rt}$?_UtrnE;npz+3Wm#cQDminaPZX-ZsD&rZgNMlOP>~lPs)5- z1VY9g@uu8tU)@>Vy33Lo9Nkp)j+fdu6g^!Frwn87+^Rz~KEqIZNvGPU)wR*jLB$B}I$TO*f~!7t4654oLO6t8V2r?1+T_Q&0K0 z4682u*_{u6j(?P@{;`Y5=-T~Y%Kr<77Z}0&gZ+aQ{5EN9gm5}+3o-ZC$|VI0^CJnl zlu@4piaXoYaQOv8RMg_I3w0k1bN&6lEJ=n~1W@$^LZ*+5?6;J{!0RU%BNqm{<~-t- zYBiVcsKMtWrxI-wsbMy>B;oLhCnBi?O$~EZ4$9!UcL&30S4}6G<>y$P0t(I%#Lna} zX_$_w@IIB}3veH9GP|^0P;_>@eR7vav@g)kd8j3{^_~v_K#JRObGNy!PKV z%zyngxUd z^s@D@xs>D?9|0^XQSe9+5fMBr9-1rL2ipylxZmKI{+KWoVU3B__h9-y+tCNq0iyqW8C?N<_=wTWv36hc-;u6_5$-8<-iG^wVX{rs#%*o<0 zP`zZD%9FKz8kA)Pi`QrR2c(!`3^|x4*s*D2BB*E3p1pCB6wSJ(K~r=?GY2zKWbkSM zk97>~}>cv zb$Jz&BN$J`J1%`SPSlD!*ydwZh|}u@DspA$4$sz zuve=&^SCLUwSd_bGS|G?7q|}mlM8;PN?3s*Qn`LoL_I|_0v+g4G5lm(&>D&~sR6?l znI)Ws=bL^}57Jk}tm&JypgNPrn=57ljDoPx5vC%_rIdlHBI-9tCQd3ccs7 z8t-*ywH72aUrR7)OSDPqV2JeQ%}`Fj)8^<7+S({A|0d~}AU_#mFK*xIuPXctHbR_6 z0>4#tdv;L;zy3>@ngEyuC~{UEld$Xby%R!P6GeG0aQ`p@>*JR7p_5+YHPKN^V4fk3 zP=|o0bY4goP@xf7HieU5*Pudrp}QZK@B~{n6cMl7DMdWz@t^;~@D^eU<>!6(45Z(_ zk$+hp^uOOo|9MRR!MG0pHBKn;ANR0%BC@7!gZmJPZJXt>$m&mX8a!}cI&=T z^1$X1PVvlD`DVXD#eo%T9Hq`v^hcCB+%v=fj3To3%ZWn%=JZC_ zoex%j4J+ zbQX)n1VtYQf2U6; zl+lO7)ctA65@v(JWy3f!Jhj+syx9tcQ)P2qi3?*W-Zw#Ork|#Fs{k`fVV_!Mn!xL3 zIk}JIQwGd7Ve?#cLD_l3;B&IP`k1Ad;eT4RS=pW5A1i9B3J!lo3 z!WN4Denb)1o>9tu9*MQeIgR3$ z0rD%TiSRC-!526-Q_<1bGYn58#9j%95VT-muFHVK2w+EN#G8i;i`sA@UJgGpB~}7x zXT$xV`dKsMX!X;9Ku-Kvd`_&(SCYV;p<-2TVNbPS!mBJ-Wd&_+BDCO7!-ztt23Z4X=cs@kswD@}xU^1g^h~pu=^6pW ze8CszeDle6mmn7p6^EWdfD|dyNB$Hf%@?7eA4}|ajD2dyBKnD5ou30#)271<>qDF}GnvD)t$ z2fj&M*=&%VGF>YIAwtb!y?Ie|YWR?x(XuT5a+5#3i=W?qc_A~KjWxnJccu=Xz$PiiuHzL7#&Jt#VEx6v~-8J%V@+^q|MYi z{c+eNd4k(vCCT3b1G%D0UknFNZ?%lsqRm{_Bk#15n|;|H)9O&HOroVE-FG(hc4&ZE z(2P$V`Y^c7#KE)tx3Id<0tT%cp7~`AFs#cqf_JH!mS_Fm3^W1T!JXma96S=IrQy{} zb0%%7OB-G)J8g)5WpUWTd10Kg^gMRt${vh%)nB};`vmNAbL>TCRA6}wIE<1qWykbg zPcCUTMV-!d>owCDM3^BD{hCpJcQE*pH$gV#ErC;Wx|Pm9SnipSi4GEzX%cltZ8sf0 z4GJEGTyuxoh}YL_^g{rSCj(Mn9xB&ZpEqiyz-a5H?)=3b8E8s zNV4xhy4dT&cqJb_1$w&<_Ly*)afAyxX!#R8gU)gG)(#SXrbXZnoP4uq5;X(XFv+a6 zX>3lBn@9^3=&!a@Iy7C*kVuccxvO@qV6GM z%IEWSgV;mL3SA>lp*KOzvB5IVgDpwgX_;?gI5YK6==zNjtGgy=}3pI7Ml z*K=k&-d*&zJ{n?u+*PW8qBhLLy>UlMZiEIK|oHw$2rs9WFwD^(_d8L4@aT5=s?a8c%PT*VUVg&tO4QDy2SY zjm2bF%vg0dwTFqL)$eqaDox6HxHo5b zNFgp5r*h$E+lpT*h%KuH+&3V2#-tv2SyzkL$JGiwZeF>fbV(hQ2BwSr_!rt3?1T{# z3+p)Tl>z*Z!>MQQ>u0C#>Grq9WuFghUm2<38IZ<^qz{5X#CQaF zf*+9#(YJ9s#v$mL$-q)RasrGY`j8?J&3!QZLlA<|;QEREfPSG;1T6Zobq2^_0kt5q z09VRDG;Z8JCf6j{ENFc;@3BBW=)L0zw=Nv`9rTWlU%SG*pCtHSWjNhK_eeShOUWc1 zguBW=S8?nd=TBUyH^szUGwHcZ_085TFwz#|m8>-DLDz_i63t}Q{&1Hz4#&BBM00Rg zVBLmTo3$&AFIBXyzJFV$-LXKdTj9!w1s4u$sTtwJ%L#eIW7Q-qMV*+xeM-%y0(?Xu zYf$T);aSqS%JCFk#=-}_oMlbLI6SL(vsS@VW3P{axttW?Aj^|nTNjt{WwB<@*PDZT z83dbE=PjR;JkTlb_0}gc$vw%DL8IuHL48?t7bk-p_2$2S%@_`iYL2H6r(tbXtG6$H zi1#UpOr)gY$kAjz^D_2qA(d?Drx*fE7ciOz|S65GQ?@VtM-pB2z zI4+D&hV8ICIAo>$0u9M+c}S*w#r~(Y`X!*Ot*s<>_$|Jy`Jtq%-UyXuOq-?62R=8(;>I?z9KdCKML;#{YLY$;T>XZm?=UMn_|2rJTDP1Hb8tg|jxd^v+7b=!NmtTqBeh&ZS#8&>3NHz5w>{Y4R_ zO^gPq`R-cbRMDwPNbP_#R>)zaj_`d(XF|e#kUT~iLdsnipk{POw`}Y61ZAD0nZ%DK z`9$<-)~~Drk;!X=k_bh1nq3~u>-~rbzMYZ?_?z4aK6~P}R|Rp=V)u!VrbLFxIW+2b z>QCbRY0tN4TkELh&c0Z?EZk3qPr_Z~pM`RmqbUOkJ-FMoK2VOdHC4y-G}8eV+DZWk zX6jN-&=s0$n)ykYm32Cz^-9AHW)kRCfBXP_Rx{TG3mN7#g=+BS3*~Hwshl1}_t0Tr z@>%){i8cncHw7ld83d}Tbd$lY)kp&6w=djR4OnT|iOe!>@!}5DO!8*$5^bG9=g)2C zhntFe*FYJuTv6y}J@zbU^Oo(_A470wLp;z+iI}Hu+#FvD9GC*|JoXx#vUsEWFMWzs zrZu`29dr4^OWAsvC}BUpF4b3865d`bCI=`twM+)7OHA!s+~FKJo5g*Z3)bGBekB6l z{^OH$w2KEi*_gGoh!}k-;;t>d zONzdN&YtPqo8~CDbOb*JqmAK3!_<^zKpEMCm1_Aw;5Ap z5mLu5wB~x0{)K=s#@QHe4QB^QHDEk8EK5WS~XtNf1f;f+>NG|?7@i{z{;oEixJ8NF5> zqrFoEMY^>gJf2r0h7)7!AZa0;Q)Gm-_udiHd6-r+nLkdP8Idjb7YZHg0a|P*pi7*?SHZmWTU_)ek9rzu5jNMxZ1-PQ*8;dpg0KMZ+ zvg<$xcKwT1PCU?+SNM$wAHJ2tf2-A$Hg|CNMu7i3u;2Rm|Lb+l{H9sv<-UiSxL|KC zp<+^oL`w;+0@uOD5|ltr1!It<>CyM9qAyLPU7^`<<=sZwJj}lcAO#Jed;j1|xZP-) z_$diC9(R?o{+&~-z0B_J_6ANFjEe%X=ZqU66Q?A1(h!AWTU?EZ3$shuPcfd!pqaK8 z!fD0;=)T-Z(rPPKxoI++8v5w=@#2 zMjXbSXl5Z|#_JGO8fUn|tFn|N+D7@TQwqfCT14gR8eKfo(XD8)29;&w))lNX3C4^C z4_yvO`*Vokel4~CYWw|m?mdP`6}1AN$VtBqzG;7rd!*;vK*TA97s|PqHCZ{xFnm)~ z9s2x4@urFRS56_BvH!qM3*$k#n1pR|IB6|zmWY+93=<3xqmsN1=9s}qAI$)aN{!JH zA_;b-#~mdM`1_d@qW?<#VVuI_28>DS-W;HRhS3j+m07d#0Xp|#ZnIhhr8t)5s_EE` zT3JNF4UnQUH9EOWEO^G^5&wflY#veqIXg;kE-My3<3l<9gfNQkP1q**CvbxQNd9i4 z?}rC`rg%nf{cI18sklEK1$F*5M?}!fAVS$8bbE-G#XWNyeA8y{>>3X2v0d-+Oj2Nm zDM~hDkKQMEUONW4)V08yH^lSkurW|St2O-qg*X|7z@2eK@Q#PRzc^?S&VF!iHkZ9r zQ|_p96s8ueJgP3de8T?u*X4X7*PB1c+u43Z4}DJ|zhVoT0A8Fiv)KyX%2cjV8ZN3c ztL25YZ~Q;dWu@}E_5AmW*7O3qy%ypGR;@9T0t)F($+h1UowgLH!l=2w zK!qu7u!lkB2db9ff@F80U3Y&HLxo6uuR{t-k=~4>KaMap`91+%-=X4x zPIjb`(iwV6mt`gQh|&>5t)M7K(0ED|DJt@k5JMGy`CcbL;4X9eMpYv9y3t4yjy&B0 zXf?}(|7;DEY^&|$+8O=?lHh`ed24Gb-U*!6TTaZ0@pw}Q7YzJ;?~UHyTPQ)J#Zvh? z@zWJEmhvLkp>o(em;{^vHcBnExu;CTR9eB;(I!)lr!hG6E{)ZFyun7Nb=JW@0qs@d zEkQlh4xOnd+KSSjO@HD@I=o=|<+>iix{rdun$Lsk$f(=9m_IWJCWN&~H&6?b*q;D~ z_z1*N#2($~+O|WY^B2XDwT~$_Z>S36GLjfaX(W-3%cth0B?O@ffccd9nP^2UYXi03 z4uGbbTuq5S1&7(wk?e{h zVAQ9y(!U+Xu-73g-D=uy!XCaY0}{*g46Aw(uj3Y^`bK2@ecVX7t+Z{Sba#VZYI$;U za)t(vXQ(p)x&2Z1>e|kteyh;gzRHrGHZFI%Py~Mt0qoEdxHKWd^)3)GmjLTWKW3do zAjEvy9GP>k;}a@@mp%Hf?5FySdRRTR601M)xPFMIdDtwb#x(F{<^lxbF(}O2M7WWp zl2Z1I|46W47x`fC9WM8*U=}&;9?~EtEz$n{MNV}jhKm(Yw$~vO&R{W4Hb*>XipJ>;XH2Jpx|a+wMXI;lt6wo3Z)Ljs`DHXyJ)$LIq``b zD^gxc6cys%uUQ7+5cWzYV*7mU@Rfg|8&gPjCfdIbLD}~qVEcDktbY!{zmfonO8n{L7g&g|Bl-aN0_nVe5{2&8e+`xB zMjki8%CJ(Aq9@AD?tZ1GGLZ5Aq1*=~L5L@!tSX&ponNexPDz*N=h8YKH9L-P81rF9{!7(z-F7_b$_>=@tomyjdThM!y<6Bae zY{vdG=_1{p8)N}8ioS;C@(dr@R_)}T5C%c>V|b~c;5LhRi;iAu8)R}ulL@=&s@Zk6 z>}ySWoQ>vDwvcTPx>kHaVbZ+SX}@rki*GH~J4+^t9PC z=u|fHt=14)lle{6cYvOX)mZ&GBJ2{g$@KN8b~e?65RAYOh7N;tzih~EAExjN@1q+I z%{fZHMf2P&Y=78aW10S)9?~lu7_`s|<`1A++aoC^NWXxm+jurhppAHvH?dRhvT4g} zhq=&!vD%Yows`SWp3OsVWit8a_qg>5DDv6w@3>Lm9=CAtDXgJv-m&d;~GjW^oz$Nk(#o z1@_a2@uE@10q#}vxN(esT?KbwBA8PA?NrPEpYyT)cg5-dgKbER+m`sAk2Ta?uU_9) zg!RR|*tAsgGaqGH!bakI{!w92PLLRFM>=soXI*OIYUm4;7fv+@-Rlppk~yYy-;f~Y zcJ%Gk`t85CQyCv0$GhmhL<<5aHHdw~BEFM9lm%|p%#Hbwp&mQodTollzGque(8vY{ zR52gtrQ4dcCO!$xA&Ru#v!AX@CL$(HRaHtn!s|1duc@egD!o=UGEWK_r5cS7tNhs` zXU)qVDM>CVNreLwc-GFA*S^Fo;8zo42_DKC(|j8o_}K(;FZ+tK^h}zcEzqyTWWgS@ zh9q-VNo7ZrCv?L8M>F4XBPFc`LGn%7C|ap&BD@1pRflYD?8kcG=Bv?7FhDcF#Y3#* zBRajkVLtbCw0g{{;BLZUXNXE4Z14wHVE*azZ*o4JS@ma$C)d8`c`ZbJk2~_fGvavN z!>{FFkFc8!sb3(TVQQgHCSQ14xZrpu4#;GuWJm0@kuVUqKsRotYGY2ARIOEe##N}v zbX>=47@whw*!`#5H)A98{>QVNI>*K~_FtOT@KY!+UcqjB1B4c-kBRlkrvGYy$QybV zF8{s^o4$h=|CZeN&(Hsd7yXB2N>uui`3|dpKDi%`*(GRz2+1RcH;9hQ4`lzsvXF{^ zASDO;(yU6hckQ&eg3FKILw=zn1_~wR^}Q~zbJj$#j2DQXx|*2syq}!7`gpznAoJzm zJ{9JZ${c8jVh$6aDWuQe$D)R<=VV3+B8O&3?z7tEs@|;vc)&p7En(D+ufG#Db6+i2 zG_pH>tN{ti&V+3C6i?=zx8Hu>Rb89an+j^Ca#Z|_`WR}?UZ%#yU8jLIFGa^8Qht-2 zPIzqsHkga93Dl`Ym)3uh-Nbi}_SsrnFPardtK(KG0R0Alo=5;j>-W%a zv;YBaW_n*32D(HTYQ0$f1D}mzt}0b00pREwqaDs63=9t4-W0$vOrgWA$;f-Z?&gN` z#Y@8Jh((?U{Aty(@Y^H#kv>kR!#)il7cQQrqnK(M8+N!FX;TKysz_yWVeZyih+bxz zPFhwq*I9wiJQZaX@R@Fd zhm)M^g4J!ocM&Sr#Je(})eKrZfmJTtsBOj#%QhS~p?;xq0xat>K!`S6yqJ+fOHe7RiPEXH z=n0VtGLibuH)7tE89ep3(GVosQpm zp|j;a@eEz7Rpe-uw=-^hN9oU9&rT-Yo*rL_J%lQb4~8PawCJ#I-}SFFF?tvaaBG!b zTBym%9f;9t*5>+-4c`T6gEj75YQhMztT$#gMLkh}wXQgjGilvp^{t|I(d@IA0>GVn zVpcietfni2yDnL&wq|Q@girp$h%7qMbnk`ys)1-$xqmNOeHiRAOobh0h4dia@LIh{ zy#XGd*48bZ$YIF~Nt-&b2;LJ)iLy;M0aw48LMd|`3NK3}exvO%Kva$Hkbmypq|qc`#aotE2e&8Cg`toXsxK7lp#v2NQs4T)#v(*T` z4V-l$BJ&{B?HBmT8)3|K-ss)Yn$YH3|v82T4{qFo{drP++b-XdQ8sW`iIaxs@bhmv(W2Fxcau^uSMsEK>Rj z73{pi-93B=GkRE^q(gv}Me`lRD$4u##NtahUMW~WV<_G(mZgpxEkT>ktO&T}AiKv) zYPQQC9FaFTI5u-gy3R1+TJ&fCfwY)wTXYdcPDt(be=m1EX>Vna?{aVX*1{P79o+jr zI=)23ZJRl{?>rL)3bcdo`T_?kA{z$wVkc$8Dd{}$~`4ejC5hO@{QnXc#T z0QlFBFY^6Xn)J?tY@wU`ojVNF&?|( zbnfCK%xS|Q_1F^Kz7K?C~u(8lI(naxFtb;QU!&?z02`H&FF z!mkS)m6y@=PwvK@>EsMeD+WefGIOsvHuV@0?F+bwogS6kg5}ae=zx=nP;tE?I({Q9 zVRtg!inDjc7#8DG$VPEZA`5Im)BVEC9nv_2iK;;wK}ioH&CPgGbexUQ@(Sj9_!r)kvXCJ%encU1>SYu&bJCU4kM% zu&#jOS{6FHo~6ie5+zx|y)N0k&eb>APMu|luTQ!uedH$Hsv?C|)pDP8od%Zf@L%DB z?d11_^zWLo_?E2r{+*gqwzl}c2v(iS;|kx#LLQem@jm+B5D2$HA>`r^fywY7wJ~#Z zlu(rd>NV}eigu2Sg3_d8bT4$Y1!1Cz(0o0K*t*bc)*B~uYRT4w>&?@r zUBxz}*FN1|;CfKaECVr%Gk{uFjmY}Z+SHu@@koWD{1&W1mY!%e<_Q}MIwi={u_m2rB<#9V4J9>?*vl5oRZfXJTmY|e!7f;(GLTw$3dyXdC-ur& zs_ZQKr0CpVi2L-7ErFzqvnpB^fdXWKiYzKQQQ2%ZnB1O5i8%H>MR9pfj2#q3(f2sp zVrO!56^9YP@>1p*qBZ4b(z8B}iwWo#QPzJfZ2n5J5;l5WWJQI2))jQh@YnAnpn|kj!GlSHn`h1%4Pf10 z#$`L|cVl)t_`K}u(j}W>gTh}T{@E_S>wj}-5oWCtG&&=!2_|H?_mnV%zl1v9mRA+J zCMJ^31?>7-WTFszA&y6w3_lSx!8<+n4o@pN{Lvn?<(T0BQ29+UM7(g`QwA~LQZnP4 zU<-r)B?xOkj>kLd9>>fmqNQU{&&ZyHsS0l7`|r20kw*Fg+V}Ep%kOXy>A!Ju{=wRr z>gIY{gR!3yX{l`P-^*cF>v;4mcY)877@BGh6?uPPO0p)^#==jixyOm%O^2i+HnD$i ze?W{vh|)s_^3w|j@ozPP_FI*1=|dX1LRy)u(_anX@r5O@{4qT2{jrrkJ8^;;`Yz`p z>!R$W?6kPNC|ix|@r2;3ey4=Td0YGEQ?Ht>j(7H!;}2=V^6W0W$^`7 zI4ep!?~O!v5~B<=*F@yi7{w_Ts5@e*KyKL4voF&)g4EC{VF$Szr8e2F46~Y@w1hMV zB%|OUt0FB_LN@$5!IPUVer2bGG~Q`Jtd_L+EQLyuIkjw*8Ta0}ElPt!T7GJ#Kxo*& zonOLfp)?We+vTM-Y)^7ym3oj22{2xeP&!pdpt(j%`AtU70i5Ar?K>M$lchY5>M(Uj~|*+YrLz+Z9N3Kui`=?Fe|1= zh!)mB7k+gDHRK;^CKd1GKRWJjSI>*YMszDj=op$RO-x?XI{$YHU5cHrjt6NIvle|B z#L$juDFK31N_xp**g>|YiJyMW_!Wp>UXUE`c*Np>XD~WQ6<0EWeTxkBn;XiVq$xQnv48#Lm*K9f1Q8ZhUc3t@ zaByP4iMp@`I;U1fwS$bkGAwxxx!D;{Fr(r!oG;(WaktP|&V_b?=8BQmip6Luj5$0| zhc~53_*^ZlbQ-2(Y8FF)29@X0^xnMcQ5Se~#b*hLhQt+n2DLTSmsT`OMuM0oSz=k* zm^XohSF%XMksLI`ycclL8ia^bIX9+^&a4uqXvT>sPv0wq!P{{4E3DjB=sm@V$Y7%! zC+sm1RYq9hN$~{yN{e7VltX_cA)c|!n;*q?dYXczgf!fg(noPLrnnxesgD==To z8kL8^Xe6-n;aMKLfz8PlRF#MSv?4>??F%vaeY|2;u^2((FqEY{<}^6LdJYlC1ZqB3 z2{oA5)w({3mp4GtYs<#=m=-G}^`WExESws{F`1^KHG35pCaemZYTNP4S&coDVz1)h z8*Z79OCNUVzXp0;MeWe`E?DxliQF|%2gv+p-JXPDdv`g^VtVM@?JFJ?P6J_C73sK& z0ASccOU!}Lgai6b!cl)%Gh6~G=;U>AUOIwkc2>p3YGZLOhFEDwM3HA02;!~cRX5T<+xEU;Np547z(7REiT>>AxDj?=02(=YF7$%UbodGTeWgW)mhUq%ohVGsscH}xZ zFvAmi7P59!*J~lG8ifrnwf6T!fOnxnfy+8QVkBu4a81qdeDepEiW>$<4BTR0#DoQW#Xh48w zkOr5#77d`5aa;OS*H+0?*2SoI*}r^XC-_7qOqyh=csx#Lg>hkQ;q_?!}lL-SJD0?H4&BRTO`(T7`&1=fH z0g9@7?8b;wGwu11oSm{o@(2a)+v}dEcFaqdFJr`Tp%QNrqmIDFSa17nefwd?;NaEU z(#gt`FJTu}HP<`XFin|1%8^^}AmpUB1EQQ$c0SzBm)=_Eg<(8417DwupI)rljtaNr zZ!AN8cyEV!L^3VFlg#OVE8?Kq_gdBKK8{@L9YI6kM5O`k4C2vLnrurQ>zRO>*pd){ zz3B0|ccsUkB^<*IiL?N3Kcj2iHMHJbD41!e)8V1H5xSTc=e~^O90+yHjLh1Wa+A!h zsoiZ6;mE2e)6``%fiuL#d5-M={fwoxF9fU!#-A*n=IWKM&w6fl-e<0p zdsn$Tzxt~Hkl3`0vvVNwF?#PRg}gj1OfgXZX(wfV=*t!t0bR$4n!F}W{m&0LlNF>A&2Jm-taK&Yln0GU5z zg!R9P+|Jc4c&$~?;e0^r=y@EmV%*K6r^IyM+Jo+v?U}Zaph@_=ol40*wb0{(PeHbw z>xTsnVu8b9`43^L!`Rw3ZM>{%%-%P=J3nCihI4UopHu_=f*oEV;eU>t>SB?$kzDv;~WH^`S`elYG z*-6@0jA_omI-bj}^^@vts~0>)LPgL8s+ErVUw*UB zn`>FfTXiWa>Yw|TgrdG!mqU0}+vBytAJ2b>*|<^jXExZ(40s1!Ut^ay;5%C{%nu$2 zbZvhO{fsa>86G*RgW~X&k394u-+}H!zIo7Z&};6f5()C}?n}|IG45FpuWdi9^=+;x zLEm@I&%xhMM?DW5^0LP-2JU1xXOkf`?vdP!_h6`9Lce+3LqXD#@fSzqSMJfQsX>po z@MJYcqzFT;M4JJ6KWrV@<4Ke*#febLn_ z>w@cZkC(cLHm<6wz6*Xncuo@WbSZYya>K>a#F$Q|dc{UKB&?WBzW0e+N)Jg&82PLQ zj>?XA{Sm?dxM?5gAqP{{fM{M1+0cp!ZwQS$68d&|B}{jputRd}xdt{nA9Q$@l1OjN zwPBRPEZM+OjDqt}$}*WW&=}cSj4W?1h_)37eOx+ZRA=B&{?i+b>yYDNWV}UbYk=)Q zP>aH+hvg2lDxPoOodbaFV4spi`Gh}cc6QhgZ_BsdPLKH=`oZCekYCCWnS}93Y+G@} za!L0GzeR8iHDvG>isJs$IH~dIu+43%6sAgXN?`AKa`S4wTD&sOfq!yL+ooa`CK*a5zP0v<5_Vz--GC62C>eyW3Jv6(Yq3-K%NWL6Xy!!|CEm|)Mz%W>E z8o}p}6cv@1RSD1*Et%D)=A1BlM=CzT0YvvVP&fOXK}KZ{D8k`P?nVeeRZiT)*pEM% z=FU_qeKs+p%;7KvQdJQe#e{H?@5!Jesxq)<)e46sH(6w?SKJ)^FkwkxQ^6~{Jy>!L z?-0%cPaPB9Qg7@EGm^=Q4d9)a>IGPIM!an+Kj=s0)XsqsL{vM{mxvH33e!z(xV#6{ z`Ke{~DFS`$k{wC!l};Mz_P4M{A9wg2cg30(J!DExlI6~DOy0jNOTs*m^C+sdVS>|8 zKQbY|-cZxXWaaYAPh&a(6n8nMC$E#4Ax1dG1^7U`kbyP)eNt<$z# zeKqf8_zvmg@OpT5%}K7@-KjUNJ3r7^Rf>FD;loeDy{U_?lNQ`5X zXHyC%i3!D^8iGWLS`tcKhJXqJ60@d+&adg%I-N)y%VpG8B@euw1mA7gj8|K2kPH>G~2^m))x1XKx$48W}sSyxP{S^wVRF|HV zSk#xKrLp;$DhJ9vDqaY%EILEM2Ie>ubBPA(l^rv|ENJbGe@9V+j@`0`*N(IrXNb+t z205{qs|n4g|1uYbn6-A<23RGq1$3V8EW-~7xP9?syH(BlAPhezomNa`j4br9Fz z)=~FT)xlItaCuX3-KK2-mJdlf2&(s_-7;NWiW66eC_FeWNyhAkMMLJM8Npo?+Ozl3 zBevk_Vd?ByzGrXwCsVhv6s(Tp+}Ppw3y4LwYlS3-2BbkP8R^(QNOla#O~s?%vbkoe zBg7QnQr#UJByEJVsd2iM+}^v!s~Q^P|b?a;Rxpn}(?tsFwEWKETpFp4?3BvCi5gy4)HQYE#UD<7N|{(C=aHd(2(eQrshhDxlelF8qM>` z?!0>eag8!)0GMz9P1*xxHa$t6>2EWBNqBCD`#9Y24Ad)Tu`6xK*_p{(M;4Dbj0LQy z%O9jFpEv&AJWr7I^R~32?HCc~v6<%wf!D(hX9T6A8GT&3cqG%Ov}t_I^NJRnkCk?) z40aie{3tP3S-krhh($@gBH7JJs$BGY!0`02RLo%7Lxm;5!mS%1%yUC9v`4f>ieE4H z#l!OqX^|s43*g(cuhNd>V;JW(jq>3?_#5Zu!R`cQIIF)&sZ$kIb0@Y*8LZGeMsTds znrK>jN8=W3HoVhJ8%0!N;w!@&QL5YHfg-HJ%tTy__Huju0)K2$Wl{|%)5`w*z1p=m zqk(I6-12zJ=u`GR8QMYSslPAtZ@0EflK#cS$XoUTvUzAD5C{~PM{Op$pD8|ftE~PX z{g+?P+@KCOnx(#?cP%8e!)k;X?=ysdA>^SgL=k26OVx%=wa~L|(d(mYv!{8dcze6j z_h|LI<1^Y z5rl?QRzUbq<^7^<3Nrw4iZW@%LvB%uj&Gr+rJ~GIy%hkFrYABRAUnS$q%D0>;?e0F z*YC*NTZCx#;`B%J6dANYbnJuKuiyJ@rPo1!W(yoV9-N|E*bi?ZPSQpCp{sJ6NZ*CU zkKUycUA-@@e-CT-x2UC~bWalsYqBGg!6ArFWmEw1t)0(NT zZ%ah9P*p#+ogxb4pG<{n=s1{w6yf)5Pnc7k->i4J$D=#oy!(LeDbH6emaBR=LFm?bmTzLCYIaUSX9i+(Np3Ech~* zZHTPZ`qMW7@!C0m)ySk|8>=iz9uk3a={c)1BmX_(iy>YbGwBzbB70ITRD;4)n5Re3 zv3feudeh@Wv$Z^3LRkfij>W8`O&Xe0GmItv={wtBH*eWd&MAov7wPat zRX+eoZInHV$FwzpEE#?ASl&^}UDi!0=un=cDFEG_WE^xJtRnhKeVAkBcPLe5t$F(B zdMxkAZQBM_DexyTjp?KgPItFnTep?d7nJi;%7+2_B3wz#V@$6<-6N=m@0Eb_ma<*2 ztl1m5s--y1ew_AvXWGOBMlS{P^oSw+WJ3-`l?LTUxly?Y@u^I6d#dM}QeckO61;u5 z*oLSY({aV(R;c;E4J-16B^vd3ZXp@#!TXInjaahq0>{!8;$%ZPqW!!dTfeZcQFyZ1 z>`NnKReAcFyh{VoCo(Ecg&r#L7$AT&J50!dWuZCSI$7O;2*rs6tQS_bbKP5x$#Btj|uuR!tp8n*%I3T z#I*o#zgxZ75dLNmV{k-117H-Xi89zDKYCfrph%G{*9i8aW)#fi>{Od&bOn&EF~ftt z+7Pq>z)@g8x%{iNrNriHjL8#Tcz|$oqk6D3K2kKbzn0Hlx!8MjN0IXyEo3x@M3g3*q)7 zf=$>mM3McVz#U|myVoDXx{f+xFGNmwCa95_dZ&z|Bvtyn?%{DPH&dD&SoE3s&_z0x z;~M43AnS-z%h+87s-#;(dqrM5{(uxI-x``q{p*WxUWkEWpcdlud)Nt*NWi7ZdDIrC z_*E;|%V30~wZFY1*p<%OpJEBchiO-F5;>!XwzZz1kddp zLZ#w8zx>=scB@Ztd0c#j?z|9PpBNz*-EK)g4%Ib=AD#i#u%c_fz|}vELP1yJH;%_G zBIz&kcdB@=G(LXklqV+FuusvJHyD%Dgh&vGat^kil{edhO2WkgZP$cFd57ALEfGEm zA{ooH`(!1zw_6z}?LjLUIq8nv7yXTl)rjW5#`YLa&C~01FLasqF-bD~i?@MUFJQU& zSK^=jJ}|QE;-6WsfAZ7xKB+J(n3l$B6d_yYh*tf=XlZKuwE1eZmsuk&H(f!fH*$*- z=8VRBrHYD*9hKoEhI<&FNX$4HtbcL+-fc8Vrj^C=axFkI+|CN6am>_(t&OL%n-LR| zXL0(#i=SzkCh-Z&b)93uyM`NMyhTR&m(~3<4n_DN8BWx=fa0lu|1Wo@HZ_;#WnRA` zFqhUtg=`xdz#g5)lATxmS6KhH?*TGIn9kY;$7BRg7*A5X&9B*MBPkOrMH%aA`I`Ybng+8#5_=~W4X{{&s zp|@|-*oP4uBv0IA7toH!!d(J7dy@Ny_DjwVaC~P;D|)N5{HHp?{K9H-kn(a+Nk${B z{~CaG+Xi)9`xa=0zdbJ0|5IlAA7J1gd)GgZAo4rry6_u?XS4cB)X(^@9Ed(@ps{>e z$;(f|5Hm3q2K9j6W_=e0u=dNMOQhZ68_T_L_>>Y5@dZ<#gj*R+J$2&S-1*dXk7=Ic zjqk;++de;1`r?`E$jeg1i2Mzpa9gs94gq1K#1G6!EvdaUQY3boUDqWoRNM3Rt;Ks? z|EIDufroPId>lu~1>khSb`Z}t=!`zW%eR6~<(n0XDNNTWf@b}bdxZX%T;np@o~ z(jpSKP@+_Hy(&v?mP+^bo{8~rj4|)&GoP_^zP~ePd(Lw_=l4G;fL^t`kw|tiVN}*L z&USsIm7Jk{c%)>R9*x(!@`lVOub%65yrN#sRP#t;S$u}Rid7@pCX|9Mh#q$0D>wVy z`ks^`e)vp6hryw}6~U=;H&Wd3y($#i=Gfb3f0I37m4Co6CP43!Z(x-N`X5osp1tms ze%c3}6kDxdVi;xvDg5Kk=TLkvqlYWfL@LvboWsVW+U`h~6rz383{`x@j1I34O>A9u z(OF!w(7xw%ab7W5$HpM}K%Mf9$YGm+jk=D;r>mTjH9CcgYjXwbLtab1OI>AUy5g{C zP+qH{X$!n|DOCvC7Z1h zLb#ijLmCEVemlBALG`lx+>j-CJM z{h@xv#Js&KqkRhBOy1ko*g1^9E1Qrp(!v^?%anZ^SMoN$#p>Wa#eciXlWFTD1ES($ zH&V4-ltR*P33%k}#G;=mJh;o#As5=>+aU21_EK|k|9@jb19hYPwg}ym-xdxYfL#h6fHhzqHN zYkcGRSE)zjf>t}WM{V$3mj0`ekRsBM<`vXf`EFyewPD2G@^lO3*a69qCC@P{(GljB zE`En-IER~AWiM9AR!j4{Uk=#yOt;C+#-Op<(;EA!y|FJxLO9WFXBeaS><3EcaP&*( zzo~{Dmbt3xpYxQDABzsC^mB-j_Y4fixsHDJ@(yo#wk?L1;9ELcW8OHntM9o~DYh@8 zuPLcd@fq&(3&k|dQ~tzN!->&}k}9$L;?Dn7wRQCA2?Hg$*v-@qnn$E{Tf&&2xYXs+ z_LD(>AN;Ua#b*3^n-u!hwIU%`r>>7{oU5eb3t#wbl-7!T;3rgjJ92pfS?_rEApy7Y zS9*>cy#}|gS#39hFKYTV!#^#)X~5`sPNONB&!GZCky=_LR?Jg)3KK5)P-{=pn-RD7 z|KV4UFm2h_XU&_LWA-qv&zCnd!%S81{Fg%;N=8@A{_{GzSaQPzz=BLBF>Q^P|%BeNnwjwq79i}r|@D4J&`6WOqN zeY4?>G@M^Cmc%VrU_17)(9zUH(3Np8iJwT-!F6ng7(=exsw5C*3 z$^`UBU)w+AjcY3CzPctu1(Qyh&@|3*@)ERG>GdpMP7qb49B)w7x`l3AJg7h}x;0XH zOs6_OLo-O7?~z)8VTm_**C=p9U)bW;@Ae%!8vjrG)&fz`lo;@0df-oa--Bn=Is4xK z#g*H=;%p+BqtiVPugD@`558mx$YcUuh-p4BSDQ-0sDU59vNdxwQMcM|u4!j8JDY#` z79(TupPA21fk;WyiB1KNgrKIg*_v#(GB2B@A%#i?(d?zypHcFT)lO%(98W6yOD8?n5M)czS{wx5WqGz2>X%9Wh`BayD&NpQEt}Go42UWTnwA<_|%>>Wwvn$^e4>v zR$*TaG$)R%LWU<(G(D&=EHM@W|V)P*a|Qn z4hw+b3E`aZ&|L|Ph28KG?7aw1*qPfsFcbDhMwm-!oR~lMl;&Nk!8XJQb&MP8{HDZk z@nIuXL@4_N7sa1zs|pLiwv~uL@+mF^IG9+%O0bI^qVyq&3ni{R?O;vVhz!xpO5sA2 zlPwu61)H)UQWF_mNO7=eft6tY3qjn5ACL*xp{QoJiP>sQd;1H>C zumXmzaWkg(sYz|Yx`GcxA$*%sF8G{}N5KsPpCLiSqRSQ*W8W6=(*p?eRqY(+kLsBF zECF0j_>T|>v%g_sCZ}r@ymgC^g`4J*x!=fzKLNa*i0Hg+o}&Y=W@mJx1uo<878fG( z+vDkl-FzEfaG9BzS*t|m?iMT2se)iLW5(_odEUJ)I~zW5%Y{PefPe47&D?g75rz66 D613UA literal 0 HcmV?d00001 diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/gradle/wrapper/gradle-wrapper.properties b/spring-swagger-codegen/spring-openapi-generator-api-client/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..94920145f3 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/gradlew b/spring-swagger-codegen/spring-openapi-generator-api-client/gradlew new file mode 100644 index 0000000000..2fe81a7d95 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/gradlew @@ -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" "$@" diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/gradlew.bat b/spring-swagger-codegen/spring-openapi-generator-api-client/gradlew.bat new file mode 100644 index 0000000000..9618d8d960 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/gradlew.bat @@ -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 diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml b/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml new file mode 100644 index 0000000000..cc70a9f654 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/pom.xml @@ -0,0 +1,274 @@ + + 4.0.0 + com.baeldung + spring-openapi-generator-api-client + jar + spring-openapi-generator-api-client + 0.0.1-SNAPSHOT + https://github.com/openapitools/openapi-generator + OpenAPI Java + + scm:git:git@github.com:openapitools/openapi-generator.git + scm:git:git@github.com:openapitools/openapi-generator.git + https://github.com/openapitools/openapi-generator + + + + + Unlicense + http://www.apache.org/licenses/LICENSE-2.0.html + repo + + + + + + OpenAPI-Generator Contributors + team@openapitools.org + OpenAPITools.org + http://openapitools.org + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M1 + + + enforce-maven + + enforce + + + + + 2.2.0 + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.12 + + + + loggerPath + conf/log4j.properties + + + -Xms512m -Xmx1500m + methods + pertest + + + + maven-dependency-plugin + + + package + + copy-dependencies + + + ${project.build.directory}/lib + + + + + + + + org.apache.maven.plugins + maven-jar-plugin + 2.2 + + + + jar + test-jar + + + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.10 + + + add_sources + generate-sources + + add-source + + + + src/main/java + + + + + add_test_sources + generate-test-sources + + add-test-source + + + + src/test/java + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.6.1 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.10.4 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + + + + + sign-artifacts + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + + + + + + + io.swagger + swagger-annotations + ${swagger-annotations-version} + + + + + com.google.code.findbugs + jsr305 + 3.0.2 + + + + + org.springframework + spring-web + ${spring-web-version} + + + + + com.fasterxml.jackson.core + jackson-core + ${jackson-version} + + + com.fasterxml.jackson.core + jackson-annotations + ${jackson-version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson-databind-version} + + + com.fasterxml.jackson.jaxrs + jackson-jaxrs-json-provider + ${jackson-version} + + + org.openapitools + jackson-databind-nullable + ${jackson-databind-nullable-version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson-version} + + + com.github.joschi.jackson + jackson-datatype-threetenbp + ${jackson-threetenbp-version} + + + + + junit + junit + ${junit-version} + test + + + + UTF-8 + 1.5.22 + 4.3.9.RELEASE + 2.10.1 + 2.10.1 + 0.2.1 + 2.9.10 + 1.0.0 + 4.13 + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/settings.gradle b/spring-swagger-codegen/spring-openapi-generator-api-client/settings.gradle new file mode 100644 index 0000000000..06a087cb49 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "spring-openapi-generator-api-client" \ No newline at end of file diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/AndroidManifest.xml b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/AndroidManifest.xml new file mode 100644 index 0000000000..cd581f9f78 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/AndroidManifest.xml @@ -0,0 +1,3 @@ + + + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/PetApi.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/PetApi.java new file mode 100644 index 0000000000..b7256c81fb --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/PetApi.java @@ -0,0 +1,477 @@ +package com.baeldung.petstore.client.api; + +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.model.ModelApiResponse; +import com.baeldung.petstore.client.model.Pet; + +import java.io.File; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.core.io.FileSystemResource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestClientException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +@Component("com.baeldung.petstore.client.api.PetApi") +public class PetApi { + private ApiClient apiClient; + + public PetApi() { + this(new ApiClient()); + } + + @Autowired + public PetApi(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + /** + * Add a new pet to the store + * + *

405 - Invalid input + * @param body Pet object that needs to be added to the store (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void addPet(Pet body) throws RestClientException { + addPetWithHttpInfo(body); + } + + /** + * Add a new pet to the store + * + *

405 - Invalid input + * @param body Pet object that needs to be added to the store (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity addPetWithHttpInfo(Pet body) throws RestClientException { + Object postBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling addPet"); + } + + String path = apiClient.expandPath("/pet", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/json", "application/xml" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "petstore_auth" }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Deletes a pet + * + *

400 - Invalid ID supplied + *

404 - Pet not found + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void deletePet(Long petId, String apiKey) throws RestClientException { + deletePetWithHttpInfo(petId, apiKey); + } + + /** + * Deletes a pet + * + *

400 - Invalid ID supplied + *

404 - Pet not found + * @param petId Pet id to delete (required) + * @param apiKey (optional) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity deletePetWithHttpInfo(Long petId, String apiKey) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'petId' is set + if (petId == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling deletePet"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("petId", petId); + String path = apiClient.expandPath("/pet/{petId}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + if (apiKey != null) + headerParams.add("api_key", apiClient.parameterToString(apiKey)); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "petstore_auth" }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Finds Pets by status + * Multiple status values can be provided with comma separated strings + *

200 - successful operation + *

400 - Invalid status value + * @param status Status values that need to be considered for filter (required) + * @return List<Pet> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public List findPetsByStatus(List status) throws RestClientException { + return findPetsByStatusWithHttpInfo(status).getBody(); + } + + /** + * Finds Pets by status + * Multiple status values can be provided with comma separated strings + *

200 - successful operation + *

400 - Invalid status value + * @param status Status values that need to be considered for filter (required) + * @return ResponseEntity<List<Pet>> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity> findPetsByStatusWithHttpInfo(List status) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'status' is set + if (status == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'status' when calling findPetsByStatus"); + } + + String path = apiClient.expandPath("/pet/findByStatus", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "status", status)); + + final String[] accepts = { + "application/json", "application/xml" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "petstore_auth" }; + + ParameterizedTypeReference> returnType = new ParameterizedTypeReference>() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + *

200 - successful operation + *

400 - Invalid tag value + * @param tags Tags to filter by (required) + * @return List<Pet> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + @Deprecated + public List findPetsByTags(List tags) throws RestClientException { + return findPetsByTagsWithHttpInfo(tags).getBody(); + } + + /** + * Finds Pets by tags + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + *

200 - successful operation + *

400 - Invalid tag value + * @param tags Tags to filter by (required) + * @return ResponseEntity<List<Pet>> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + @Deprecated + public ResponseEntity> findPetsByTagsWithHttpInfo(List tags) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'tags' is set + if (tags == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'tags' when calling findPetsByTags"); + } + + String path = apiClient.expandPath("/pet/findByTags", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase(Locale.ROOT)), "tags", tags)); + + final String[] accepts = { + "application/json", "application/xml" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "petstore_auth" }; + + ParameterizedTypeReference> returnType = new ParameterizedTypeReference>() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Find pet by ID + * Returns a single pet + *

200 - successful operation + *

400 - Invalid ID supplied + *

404 - Pet not found + * @param petId ID of pet to return (required) + * @return Pet + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public Pet getPetById(Long petId) throws RestClientException { + return getPetByIdWithHttpInfo(petId).getBody(); + } + + /** + * Find pet by ID + * Returns a single pet + *

200 - successful operation + *

400 - Invalid ID supplied + *

404 - Pet not found + * @param petId ID of pet to return (required) + * @return ResponseEntity<Pet> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity getPetByIdWithHttpInfo(Long petId) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'petId' is set + if (petId == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling getPetById"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("petId", petId); + String path = apiClient.expandPath("/pet/{petId}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { + "application/json", "application/xml" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "api_key" }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Update an existing pet + * + *

400 - Invalid ID supplied + *

404 - Pet not found + *

405 - Validation exception + * @param body Pet object that needs to be added to the store (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void updatePet(Pet body) throws RestClientException { + updatePetWithHttpInfo(body); + } + + /** + * Update an existing pet + * + *

400 - Invalid ID supplied + *

404 - Pet not found + *

405 - Validation exception + * @param body Pet object that needs to be added to the store (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity updatePetWithHttpInfo(Pet body) throws RestClientException { + Object postBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling updatePet"); + } + + String path = apiClient.expandPath("/pet", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/json", "application/xml" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "petstore_auth" }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Updates a pet in the store with form data + * + *

405 - Invalid input + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void updatePetWithForm(Long petId, String name, String status) throws RestClientException { + updatePetWithFormWithHttpInfo(petId, name, status); + } + + /** + * Updates a pet in the store with form data + * + *

405 - Invalid input + * @param petId ID of pet that needs to be updated (required) + * @param name Updated name of the pet (optional) + * @param status Updated status of the pet (optional) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity updatePetWithFormWithHttpInfo(Long petId, String name, String status) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'petId' is set + if (petId == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling updatePetWithForm"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("petId", petId); + String path = apiClient.expandPath("/pet/{petId}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + if (name != null) + formParams.add("name", name); + if (status != null) + formParams.add("status", status); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/x-www-form-urlencoded" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "petstore_auth" }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * uploads an image + * + *

200 - successful operation + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return ModelApiResponse + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ModelApiResponse uploadFile(Long petId, String additionalMetadata, File file) throws RestClientException { + return uploadFileWithHttpInfo(petId, additionalMetadata, file).getBody(); + } + + /** + * uploads an image + * + *

200 - successful operation + * @param petId ID of pet to update (required) + * @param additionalMetadata Additional data to pass to server (optional) + * @param file file to upload (optional) + * @return ResponseEntity<ModelApiResponse> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity uploadFileWithHttpInfo(Long petId, String additionalMetadata, File file) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'petId' is set + if (petId == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling uploadFile"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("petId", petId); + String path = apiClient.expandPath("/pet/{petId}/uploadImage", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + if (additionalMetadata != null) + formParams.add("additionalMetadata", additionalMetadata); + if (file != null) + formParams.add("file", new FileSystemResource(file)); + + final String[] accepts = { + "application/json" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "multipart/form-data" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "petstore_auth" }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/StoreApi.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/StoreApi.java new file mode 100644 index 0000000000..792617bc28 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/StoreApi.java @@ -0,0 +1,240 @@ +package com.baeldung.petstore.client.api; + +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.model.Order; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestClientException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +@Component("com.baeldung.petstore.client.api.StoreApi") +public class StoreApi { + private ApiClient apiClient; + + public StoreApi() { + this(new ApiClient()); + } + + @Autowired + public StoreApi(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + /** + * Delete purchase order by ID + * For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors + *

400 - Invalid ID supplied + *

404 - Order not found + * @param orderId ID of the order that needs to be deleted (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void deleteOrder(Long orderId) throws RestClientException { + deleteOrderWithHttpInfo(orderId); + } + + /** + * Delete purchase order by ID + * For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors + *

400 - Invalid ID supplied + *

404 - Order not found + * @param orderId ID of the order that needs to be deleted (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity deleteOrderWithHttpInfo(Long orderId) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'orderId' is set + if (orderId == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'orderId' when calling deleteOrder"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("orderId", orderId); + String path = apiClient.expandPath("/store/order/{orderId}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + *

200 - successful operation + * @return Map<String, Integer> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public Map getInventory() throws RestClientException { + return getInventoryWithHttpInfo().getBody(); + } + + /** + * Returns pet inventories by status + * Returns a map of status codes to quantities + *

200 - successful operation + * @return ResponseEntity<Map<String, Integer>> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity> getInventoryWithHttpInfo() throws RestClientException { + Object postBody = null; + + String path = apiClient.expandPath("/store/inventory", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { + "application/json" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { "api_key" }; + + ParameterizedTypeReference> returnType = new ParameterizedTypeReference>() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Find purchase order by ID + * For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + *

200 - successful operation + *

400 - Invalid ID supplied + *

404 - Order not found + * @param orderId ID of pet that needs to be fetched (required) + * @return Order + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public Order getOrderById(Long orderId) throws RestClientException { + return getOrderByIdWithHttpInfo(orderId).getBody(); + } + + /** + * Find purchase order by ID + * For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + *

200 - successful operation + *

400 - Invalid ID supplied + *

404 - Order not found + * @param orderId ID of pet that needs to be fetched (required) + * @return ResponseEntity<Order> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity getOrderByIdWithHttpInfo(Long orderId) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'orderId' is set + if (orderId == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'orderId' when calling getOrderById"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("orderId", orderId); + String path = apiClient.expandPath("/store/order/{orderId}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { + "application/json", "application/xml" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Place an order for a pet + * + *

200 - successful operation + *

400 - Invalid Order + * @param body order placed for purchasing the pet (required) + * @return Order + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public Order placeOrder(Order body) throws RestClientException { + return placeOrderWithHttpInfo(body).getBody(); + } + + /** + * Place an order for a pet + * + *

200 - successful operation + *

400 - Invalid Order + * @param body order placed for purchasing the pet (required) + * @return ResponseEntity<Order> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity placeOrderWithHttpInfo(Order body) throws RestClientException { + Object postBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling placeOrder"); + } + + String path = apiClient.expandPath("/store/order", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { + "application/json", "application/xml" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/json" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/UserApi.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/UserApi.java new file mode 100644 index 0000000000..c7cb0b803d --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/api/UserApi.java @@ -0,0 +1,441 @@ +package com.baeldung.petstore.client.api; + +import com.baeldung.petstore.client.invoker.ApiClient; +import com.baeldung.petstore.client.model.User; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestClientException; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +@Component("com.baeldung.petstore.client.api.UserApi") +public class UserApi { + private ApiClient apiClient; + + public UserApi() { + this(new ApiClient()); + } + + @Autowired + public UserApi(ApiClient apiClient) { + this.apiClient = apiClient; + } + + public ApiClient getApiClient() { + return apiClient; + } + + public void setApiClient(ApiClient apiClient) { + this.apiClient = apiClient; + } + + /** + * Create user + * This can only be done by the logged in user. + *

0 - successful operation + * @param body Created user object (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void createUser(User body) throws RestClientException { + createUserWithHttpInfo(body); + } + + /** + * Create user + * This can only be done by the logged in user. + *

0 - successful operation + * @param body Created user object (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity createUserWithHttpInfo(User body) throws RestClientException { + Object postBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUser"); + } + + String path = apiClient.expandPath("/user", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/json" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Creates list of users with given input array + * + *

0 - successful operation + * @param body List of user object (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void createUsersWithArrayInput(List body) throws RestClientException { + createUsersWithArrayInputWithHttpInfo(body); + } + + /** + * Creates list of users with given input array + * + *

0 - successful operation + * @param body List of user object (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity createUsersWithArrayInputWithHttpInfo(List body) throws RestClientException { + Object postBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUsersWithArrayInput"); + } + + String path = apiClient.expandPath("/user/createWithArray", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/json" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Creates list of users with given input array + * + *

0 - successful operation + * @param body List of user object (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void createUsersWithListInput(List body) throws RestClientException { + createUsersWithListInputWithHttpInfo(body); + } + + /** + * Creates list of users with given input array + * + *

0 - successful operation + * @param body List of user object (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity createUsersWithListInputWithHttpInfo(List body) throws RestClientException { + Object postBody = body; + + // verify the required parameter 'body' is set + if (body == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling createUsersWithListInput"); + } + + String path = apiClient.expandPath("/user/createWithList", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/json" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.POST, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Delete user + * This can only be done by the logged in user. + *

400 - Invalid username supplied + *

404 - User not found + * @param username The name that needs to be deleted (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void deleteUser(String username) throws RestClientException { + deleteUserWithHttpInfo(username); + } + + /** + * Delete user + * This can only be done by the logged in user. + *

400 - Invalid username supplied + *

404 - User not found + * @param username The name that needs to be deleted (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity deleteUserWithHttpInfo(String username) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'username' is set + if (username == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'username' when calling deleteUser"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("username", username); + String path = apiClient.expandPath("/user/{username}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.DELETE, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Get user by user name + * + *

200 - successful operation + *

400 - Invalid username supplied + *

404 - User not found + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return User + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public User getUserByName(String username) throws RestClientException { + return getUserByNameWithHttpInfo(username).getBody(); + } + + /** + * Get user by user name + * + *

200 - successful operation + *

400 - Invalid username supplied + *

404 - User not found + * @param username The name that needs to be fetched. Use user1 for testing. (required) + * @return ResponseEntity<User> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity getUserByNameWithHttpInfo(String username) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'username' is set + if (username == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'username' when calling getUserByName"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("username", username); + String path = apiClient.expandPath("/user/{username}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { + "application/json", "application/xml" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Logs user into the system + * + *

200 - successful operation + *

400 - Invalid username/password supplied + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return String + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public String loginUser(String username, String password) throws RestClientException { + return loginUserWithHttpInfo(username, password).getBody(); + } + + /** + * Logs user into the system + * + *

200 - successful operation + *

400 - Invalid username/password supplied + * @param username The user name for login (required) + * @param password The password for login in clear text (required) + * @return ResponseEntity<String> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity loginUserWithHttpInfo(String username, String password) throws RestClientException { + Object postBody = null; + + // verify the required parameter 'username' is set + if (username == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'username' when calling loginUser"); + } + + // verify the required parameter 'password' is set + if (password == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'password' when calling loginUser"); + } + + String path = apiClient.expandPath("/user/login", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + queryParams.putAll(apiClient.parameterToMultiValueMap(null, "username", username)); + queryParams.putAll(apiClient.parameterToMultiValueMap(null, "password", password)); + + final String[] accepts = { + "application/json", "application/xml" + }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Logs out current logged in user session + * + *

0 - successful operation + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void logoutUser() throws RestClientException { + logoutUserWithHttpInfo(); + } + + /** + * Logs out current logged in user session + * + *

0 - successful operation + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity logoutUserWithHttpInfo() throws RestClientException { + Object postBody = null; + + String path = apiClient.expandPath("/user/logout", Collections.emptyMap()); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } + /** + * Updated user + * This can only be done by the logged in user. + *

400 - Invalid user supplied + *

404 - User not found + * @param username name that need to be updated (required) + * @param body Updated user object (required) + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public void updateUser(String username, User body) throws RestClientException { + updateUserWithHttpInfo(username, body); + } + + /** + * Updated user + * This can only be done by the logged in user. + *

400 - Invalid user supplied + *

404 - User not found + * @param username name that need to be updated (required) + * @param body Updated user object (required) + * @return ResponseEntity<Void> + * @throws RestClientException if an error occurs while attempting to invoke the API + */ + public ResponseEntity updateUserWithHttpInfo(String username, User body) throws RestClientException { + Object postBody = body; + + // verify the required parameter 'username' is set + if (username == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'username' when calling updateUser"); + } + + // verify the required parameter 'body' is set + if (body == null) { + throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'body' when calling updateUser"); + } + + // create path and map variables + final Map uriVariables = new HashMap(); + uriVariables.put("username", username); + String path = apiClient.expandPath("/user/{username}", uriVariables); + + final MultiValueMap queryParams = new LinkedMultiValueMap(); + final HttpHeaders headerParams = new HttpHeaders(); + final MultiValueMap cookieParams = new LinkedMultiValueMap(); + final MultiValueMap formParams = new LinkedMultiValueMap(); + + final String[] accepts = { }; + final List accept = apiClient.selectHeaderAccept(accepts); + final String[] contentTypes = { + "application/json" + }; + final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); + + String[] authNames = new String[] { }; + + ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; + return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, cookieParams, formParams, accept, contentType, authNames, returnType); + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/ApiClient.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/ApiClient.java new file mode 100644 index 0000000000..5a10828c47 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/ApiClient.java @@ -0,0 +1,750 @@ +package com.baeldung.petstore.client.invoker; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule; + +import com.baeldung.petstore.client.invoker.auth.ApiKeyAuth; +import com.baeldung.petstore.client.invoker.auth.Authentication; +import com.baeldung.petstore.client.invoker.auth.HttpBasicAuth; +import com.baeldung.petstore.client.invoker.auth.HttpBearerAuth; +import com.baeldung.petstore.client.invoker.auth.OAuth; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; +import java.text.DateFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.TimeZone; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.openapitools.jackson.nullable.JsonNullableModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpRequest; +import org.springframework.http.InvalidMediaTypeException; +import org.springframework.http.MediaType; +import org.springframework.http.RequestEntity; +import org.springframework.http.RequestEntity.BodyBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter; +import org.springframework.stereotype.Component; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; +import org.springframework.util.StringUtils; +import org.springframework.web.client.RestClientException; +import org.springframework.web.client.RestTemplate; +import org.springframework.web.util.UriComponentsBuilder; +import org.threeten.bp.*; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +@Component("com.baeldung.petstore.client.invoker.ApiClient") +public class ApiClient { + public enum CollectionFormat { + CSV(","), TSV("\t"), SSV(" "), PIPES("|"), MULTI(null); + + private final String separator; + private CollectionFormat(String separator) { + this.separator = separator; + } + + private String collectionToString(Collection collection) { + return StringUtils.collectionToDelimitedString(collection, separator); + } + } + + private boolean debugging = false; + + private HttpHeaders defaultHeaders = new HttpHeaders(); + private MultiValueMap defaultCookies = new LinkedMultiValueMap(); + + private String basePath = "https://petstore.swagger.io/v2"; + + private RestTemplate restTemplate; + + private Map authentications; + + private DateFormat dateFormat; + + public ApiClient() { + this.restTemplate = buildRestTemplate(); + init(); + } + + @Autowired + public ApiClient(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + init(); + } + + protected void init() { + // Use RFC3339 format for date and datetime. + // See http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14 + this.dateFormat = new RFC3339DateFormat(); + + // Use UTC as the default time zone. + this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); + + // Set default User-Agent. + setUserAgent("Java-SDK"); + + // Setup authentications (key: authentication name, value: authentication). + authentications = new HashMap(); + authentications.put("api_key", new ApiKeyAuth("header", "api_key")); + authentications.put("petstore_auth", new OAuth()); + // Prevent the authentications from being modified. + authentications = Collections.unmodifiableMap(authentications); + } + + /** + * Get the current base path + * @return String the base path + */ + public String getBasePath() { + return basePath; + } + + /** + * Set the base path, which should include the host + * @param basePath the base path + * @return ApiClient this client + */ + public ApiClient setBasePath(String basePath) { + this.basePath = basePath; + return this; + } + + /** + * Get authentications (key: authentication name, value: authentication). + * @return Map the currently configured authentication types + */ + public Map getAuthentications() { + return authentications; + } + + /** + * Get authentication for the given name. + * + * @param authName The authentication name + * @return The authentication, null if not found + */ + public Authentication getAuthentication(String authName) { + return authentications.get(authName); + } + + /** + * Helper method to set token for HTTP bearer authentication. + * @param bearerToken the token + */ + public void setBearerToken(String bearerToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBearerAuth) { + ((HttpBearerAuth) auth).setBearerToken(bearerToken); + return; + } + } + throw new RuntimeException("No Bearer authentication configured!"); + } + + /** + * Helper method to set username for the first HTTP basic authentication. + * @param username the username + */ + public void setUsername(String username) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setUsername(username); + return; + } + } + throw new RuntimeException("No HTTP basic authentication configured!"); + } + + /** + * Helper method to set password for the first HTTP basic authentication. + * @param password the password + */ + public void setPassword(String password) { + for (Authentication auth : authentications.values()) { + if (auth instanceof HttpBasicAuth) { + ((HttpBasicAuth) auth).setPassword(password); + return; + } + } + throw new RuntimeException("No HTTP basic authentication configured!"); + } + + /** + * Helper method to set API key value for the first API key authentication. + * @param apiKey the API key + */ + public void setApiKey(String apiKey) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKey(apiKey); + return; + } + } + throw new RuntimeException("No API key authentication configured!"); + } + + /** + * Helper method to set API key prefix for the first API key authentication. + * @param apiKeyPrefix the API key prefix + */ + public void setApiKeyPrefix(String apiKeyPrefix) { + for (Authentication auth : authentications.values()) { + if (auth instanceof ApiKeyAuth) { + ((ApiKeyAuth) auth).setApiKeyPrefix(apiKeyPrefix); + return; + } + } + throw new RuntimeException("No API key authentication configured!"); + } + + /** + * Helper method to set access token for the first OAuth2 authentication. + * @param accessToken the access token + */ + public void setAccessToken(String accessToken) { + for (Authentication auth : authentications.values()) { + if (auth instanceof OAuth) { + ((OAuth) auth).setAccessToken(accessToken); + return; + } + } + throw new RuntimeException("No OAuth2 authentication configured!"); + } + + /** + * Set the User-Agent header's value (by adding to the default header map). + * @param userAgent the user agent string + * @return ApiClient this client + */ + public ApiClient setUserAgent(String userAgent) { + addDefaultHeader("User-Agent", userAgent); + return this; + } + + /** + * Add a default header. + * + * @param name The header's name + * @param value The header's value + * @return ApiClient this client + */ + public ApiClient addDefaultHeader(String name, String value) { + if (defaultHeaders.containsKey(name)) { + defaultHeaders.remove(name); + } + defaultHeaders.add(name, value); + return this; + } + + /** + * Add a default cookie. + * + * @param name The cookie's name + * @param value The cookie's value + * @return ApiClient this client + */ + public ApiClient addDefaultCookie(String name, String value) { + if (defaultCookies.containsKey(name)) { + defaultCookies.remove(name); + } + defaultCookies.add(name, value); + return this; + } + + public void setDebugging(boolean debugging) { + List currentInterceptors = this.restTemplate.getInterceptors(); + if(debugging) { + if (currentInterceptors == null) { + currentInterceptors = new ArrayList(); + } + ClientHttpRequestInterceptor interceptor = new ApiClientHttpRequestInterceptor(); + currentInterceptors.add(interceptor); + this.restTemplate.setInterceptors(currentInterceptors); + } else { + if (currentInterceptors != null && !currentInterceptors.isEmpty()) { + Iterator iter = currentInterceptors.iterator(); + while (iter.hasNext()) { + ClientHttpRequestInterceptor interceptor = iter.next(); + if (interceptor instanceof ApiClientHttpRequestInterceptor) { + iter.remove(); + } + } + this.restTemplate.setInterceptors(currentInterceptors); + } + } + this.debugging = debugging; + } + + /** + * Check that whether debugging is enabled for this API client. + * @return boolean true if this client is enabled for debugging, false otherwise + */ + public boolean isDebugging() { + return debugging; + } + + /** + * Get the date format used to parse/format date parameters. + * @return DateFormat format + */ + public DateFormat getDateFormat() { + return dateFormat; + } + + /** + * Set the date format used to parse/format date parameters. + * @param dateFormat Date format + * @return API client + */ + public ApiClient setDateFormat(DateFormat dateFormat) { + this.dateFormat = dateFormat; + for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ + if(converter instanceof AbstractJackson2HttpMessageConverter){ + ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); + mapper.setDateFormat(dateFormat); + } + } + return this; + } + + /** + * Parse the given string into Date object. + * @param str the string to parse + * @return the Date parsed from the string + */ + public Date parseDate(String str) { + try { + return dateFormat.parse(str); + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + /** + * Format the given Date object into string. + * @param date the date to format + * @return the formatted date as string + */ + public String formatDate(Date date) { + return dateFormat.format(date); + } + + /** + * Format the given parameter object into string. + * @param param the object to convert + * @return String the parameter represented as a String + */ + public String parameterToString(Object param) { + if (param == null) { + return ""; + } else if (param instanceof Date) { + return formatDate( (Date) param); + } else if (param instanceof Collection) { + StringBuilder b = new StringBuilder(); + for(Object o : (Collection) param) { + if(b.length() > 0) { + b.append(","); + } + b.append(String.valueOf(o)); + } + return b.toString(); + } else { + return String.valueOf(param); + } + } + + /** + * Formats the specified collection path parameter to a string value. + * + * @param collectionFormat The collection format of the parameter. + * @param values The values of the parameter. + * @return String representation of the parameter + */ + public String collectionPathParameterToString(CollectionFormat collectionFormat, Collection values) { + // create the value based on the collection format + if (CollectionFormat.MULTI.equals(collectionFormat)) { + // not valid for path params + return parameterToString(values); + } + + // collectionFormat is assumed to be "csv" by default + if(collectionFormat == null) { + collectionFormat = CollectionFormat.CSV; + } + + return collectionFormat.collectionToString(values); + } + + /** + * Converts a parameter to a {@link MultiValueMap} for use in REST requests + * @param collectionFormat The format to convert to + * @param name The name of the parameter + * @param value The parameter's value + * @return a Map containing the String value(s) of the input parameter + */ + public MultiValueMap parameterToMultiValueMap(CollectionFormat collectionFormat, String name, Object value) { + final MultiValueMap params = new LinkedMultiValueMap(); + + if (name == null || name.isEmpty() || value == null) { + return params; + } + + if(collectionFormat == null) { + collectionFormat = CollectionFormat.CSV; + } + + Collection valueCollection = null; + if (value instanceof Collection) { + valueCollection = (Collection) value; + } else { + params.add(name, parameterToString(value)); + return params; + } + + if (valueCollection.isEmpty()){ + return params; + } + + if (collectionFormat.equals(CollectionFormat.MULTI)) { + for (Object item : valueCollection) { + params.add(name, parameterToString(item)); + } + return params; + } + + List values = new ArrayList(); + for(Object o : valueCollection) { + values.add(parameterToString(o)); + } + params.add(name, collectionFormat.collectionToString(values)); + + return params; + } + + /** + * Check if the given {@code String} is a JSON MIME. + * @param mediaType the input MediaType + * @return boolean true if the MediaType represents JSON, false otherwise + */ + public boolean isJsonMime(String mediaType) { + // "* / *" is default to JSON + if ("*/*".equals(mediaType)) { + return true; + } + + try { + return isJsonMime(MediaType.parseMediaType(mediaType)); + } catch (InvalidMediaTypeException e) { + } + return false; + } + + /** + * Check if the given MIME is a JSON MIME. + * JSON MIME examples: + * application/json + * application/json; charset=UTF8 + * APPLICATION/JSON + * @param mediaType the input MediaType + * @return boolean true if the MediaType represents JSON, false otherwise + */ + public boolean isJsonMime(MediaType mediaType) { + return mediaType != null && (MediaType.APPLICATION_JSON.isCompatibleWith(mediaType) || mediaType.getSubtype().matches("^.*\\+json[;]?\\s*$")); + } + + /** + * Select the Accept header's value from the given accepts array: + * if JSON exists in the given array, use it; + * otherwise use all of them (joining into a string) + * + * @param accepts The accepts array to select from + * @return List The list of MediaTypes to use for the Accept header + */ + public List selectHeaderAccept(String[] accepts) { + if (accepts.length == 0) { + return null; + } + for (String accept : accepts) { + MediaType mediaType = MediaType.parseMediaType(accept); + if (isJsonMime(mediaType)) { + return Collections.singletonList(mediaType); + } + } + return MediaType.parseMediaTypes(StringUtils.arrayToCommaDelimitedString(accepts)); + } + + /** + * Select the Content-Type header's value from the given array: + * if JSON exists in the given array, use it; + * otherwise use the first one of the array. + * + * @param contentTypes The Content-Type array to select from + * @return MediaType The Content-Type header to use. If the given array is empty, JSON will be used. + */ + public MediaType selectHeaderContentType(String[] contentTypes) { + if (contentTypes.length == 0) { + return MediaType.APPLICATION_JSON; + } + for (String contentType : contentTypes) { + MediaType mediaType = MediaType.parseMediaType(contentType); + if (isJsonMime(mediaType)) { + return mediaType; + } + } + return MediaType.parseMediaType(contentTypes[0]); + } + + /** + * Select the body to use for the request + * @param obj the body object + * @param formParams the form parameters + * @param contentType the content type of the request + * @return Object the selected body + */ + protected Object selectBody(Object obj, MultiValueMap formParams, MediaType contentType) { + boolean isForm = MediaType.MULTIPART_FORM_DATA.isCompatibleWith(contentType) || MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType); + return isForm ? formParams : obj; + } + + /** + * Expand path template with variables + * @param pathTemplate path template with placeholders + * @param variables variables to replace + * @return path with placeholders replaced by variables + */ + public String expandPath(String pathTemplate, Map variables) { + return restTemplate.getUriTemplateHandler().expand(pathTemplate, variables).toString(); + } + + /** + * Invoke API by sending HTTP request with the given options. + * + * @param the return type to use + * @param path The sub-path of the HTTP URL + * @param method The request method + * @param queryParams The query parameters + * @param body The request body object + * @param headerParams The header parameters + * @param cookieParams The cookie parameters + * @param formParams The form parameters + * @param accept The request's Accept header + * @param contentType The request's Content-Type header + * @param authNames The authentications to apply + * @param returnType The return type into which to deserialize the response + * @return ResponseEntity<T> The response of the chosen type + */ + public ResponseEntity invokeAPI(String path, HttpMethod method, MultiValueMap queryParams, Object body, HttpHeaders headerParams, MultiValueMap cookieParams, MultiValueMap formParams, List accept, MediaType contentType, String[] authNames, ParameterizedTypeReference returnType) throws RestClientException { + updateParamsForAuth(authNames, queryParams, headerParams, cookieParams); + + final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(path); + if (queryParams != null) { + //encode the query parameters in case they contain unsafe characters + for (List values : queryParams.values()) { + if (values != null) { + for (int i = 0; i < values.size(); i++) { + try { + values.set(i, URLEncoder.encode(values.get(i), "utf8")); + } catch (UnsupportedEncodingException e) { + + } + } + } + } + builder.queryParams(queryParams); + } + + URI uri; + try { + uri = new URI(builder.build().toUriString()); + } catch(URISyntaxException ex) { + throw new RestClientException("Could not build URL: " + builder.toUriString(), ex); + } + + final BodyBuilder requestBuilder = RequestEntity.method(method, uri); + if(accept != null) { + requestBuilder.accept(accept.toArray(new MediaType[accept.size()])); + } + if(contentType != null) { + requestBuilder.contentType(contentType); + } + + addHeadersToRequest(headerParams, requestBuilder); + addHeadersToRequest(defaultHeaders, requestBuilder); + addCookiesToRequest(cookieParams, requestBuilder); + addCookiesToRequest(defaultCookies, requestBuilder); + + RequestEntity requestEntity = requestBuilder.body(selectBody(body, formParams, contentType)); + + ResponseEntity responseEntity = restTemplate.exchange(requestEntity, returnType); + + if (responseEntity.getStatusCode().is2xxSuccessful()) { + return responseEntity; + } else { + // The error handler built into the RestTemplate should handle 400 and 500 series errors. + throw new RestClientException("API returned " + responseEntity.getStatusCode() + " and it wasn't handled by the RestTemplate error handler"); + } + } + + /** + * Add headers to the request that is being built + * @param headers The headers to add + * @param requestBuilder The current request + */ + protected void addHeadersToRequest(HttpHeaders headers, BodyBuilder requestBuilder) { + for (Entry> entry : headers.entrySet()) { + List values = entry.getValue(); + for(String value : values) { + if (value != null) { + requestBuilder.header(entry.getKey(), value); + } + } + } + } + + /** + * Add cookies to the request that is being built + * @param cookies The cookies to add + * @param requestBuilder The current request + */ + protected void addCookiesToRequest(MultiValueMap cookies, BodyBuilder requestBuilder) { + if (!cookies.isEmpty()) { + requestBuilder.header("Cookie", buildCookieHeader(cookies)); + } + } + + /** + * Build cookie header. Keeps a single value per cookie (as per + * RFC6265 section 5.3). + * + * @param cookies map all cookies + * @return header string for cookies. + */ + private String buildCookieHeader(MultiValueMap cookies) { + final StringBuilder cookieValue = new StringBuilder(); + String delimiter = ""; + for (final Map.Entry> entry : cookies.entrySet()) { + final String value = entry.getValue().get(entry.getValue().size() - 1); + cookieValue.append(String.format("%s%s=%s", delimiter, entry.getKey(), value)); + delimiter = "; "; + } + return cookieValue.toString(); + } + + /** + * Build the RestTemplate used to make HTTP requests. + * @return RestTemplate + */ + protected RestTemplate buildRestTemplate() { + RestTemplate restTemplate = new RestTemplate(); + for(HttpMessageConverter converter:restTemplate.getMessageConverters()){ + if(converter instanceof AbstractJackson2HttpMessageConverter){ + ObjectMapper mapper = ((AbstractJackson2HttpMessageConverter)converter).getObjectMapper(); + ThreeTenModule module = new ThreeTenModule(); + module.addDeserializer(Instant.class, CustomInstantDeserializer.INSTANT); + module.addDeserializer(OffsetDateTime.class, CustomInstantDeserializer.OFFSET_DATE_TIME); + module.addDeserializer(ZonedDateTime.class, CustomInstantDeserializer.ZONED_DATE_TIME); + mapper.registerModule(module); + mapper.registerModule(new JsonNullableModule()); + } + } + // This allows us to read the response more than once - Necessary for debugging. + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory())); + return restTemplate; + } + + /** + * Update query and header parameters based on authentication settings. + * + * @param authNames The authentications to apply + * @param queryParams The query parameters + * @param headerParams The header parameters + */ + private void updateParamsForAuth(String[] authNames, MultiValueMap queryParams, HttpHeaders headerParams, MultiValueMap cookieParams) { + for (String authName : authNames) { + Authentication auth = authentications.get(authName); + if (auth == null) { + throw new RestClientException("Authentication undefined: " + authName); + } + auth.applyToParams(queryParams, headerParams, cookieParams); + } + } + + private class ApiClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { + private final Log log = LogFactory.getLog(ApiClientHttpRequestInterceptor.class); + + @Override + public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { + logRequest(request, body); + ClientHttpResponse response = execution.execute(request, body); + logResponse(response); + return response; + } + + private void logRequest(HttpRequest request, byte[] body) throws UnsupportedEncodingException { + log.info("URI: " + request.getURI()); + log.info("HTTP Method: " + request.getMethod()); + log.info("HTTP Headers: " + headersToString(request.getHeaders())); + log.info("Request Body: " + new String(body, StandardCharsets.UTF_8)); + } + + private void logResponse(ClientHttpResponse response) throws IOException { + log.info("HTTP Status Code: " + response.getRawStatusCode()); + log.info("Status Text: " + response.getStatusText()); + log.info("HTTP Headers: " + headersToString(response.getHeaders())); + log.info("Response Body: " + bodyToString(response.getBody())); + } + + private String headersToString(HttpHeaders headers) { + StringBuilder builder = new StringBuilder(); + for(Entry> entry : headers.entrySet()) { + builder.append(entry.getKey()).append("=["); + for(String value : entry.getValue()) { + builder.append(value).append(","); + } + builder.setLength(builder.length() - 1); // Get rid of trailing comma + builder.append("],"); + } + builder.setLength(builder.length() - 1); // Get rid of trailing comma + return builder.toString(); + } + + private String bodyToString(InputStream body) throws IOException { + StringBuilder builder = new StringBuilder(); + BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(body, StandardCharsets.UTF_8)); + String line = bufferedReader.readLine(); + while (line != null) { + builder.append(line).append(System.lineSeparator()); + line = bufferedReader.readLine(); + } + bufferedReader.close(); + return builder.toString(); + } + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/CustomInstantDeserializer.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/CustomInstantDeserializer.java new file mode 100644 index 0000000000..6957818fb4 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/CustomInstantDeserializer.java @@ -0,0 +1,233 @@ +package com.baeldung.petstore.client.invoker; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonTokenId; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.datatype.threetenbp.DecimalUtils; +import com.fasterxml.jackson.datatype.threetenbp.deser.ThreeTenDateTimeDeserializerBase; +import com.fasterxml.jackson.datatype.threetenbp.function.BiFunction; +import com.fasterxml.jackson.datatype.threetenbp.function.Function; + +import java.io.IOException; +import java.math.BigDecimal; + +import org.threeten.bp.DateTimeException; +import org.threeten.bp.DateTimeUtils; +import org.threeten.bp.Instant; +import org.threeten.bp.OffsetDateTime; +import org.threeten.bp.ZoneId; +import org.threeten.bp.ZonedDateTime; +import org.threeten.bp.format.DateTimeFormatter; +import org.threeten.bp.temporal.Temporal; +import org.threeten.bp.temporal.TemporalAccessor; + +/** + * Deserializer for ThreeTen temporal {@link Instant}s, {@link OffsetDateTime}, and {@link ZonedDateTime}s. + * Adapted from the jackson threetenbp InstantDeserializer to add support for deserializing rfc822 format. + * + * @author Nick Williams + */ +public class CustomInstantDeserializer + extends ThreeTenDateTimeDeserializerBase { + private static final long serialVersionUID = 1L; + + public static final CustomInstantDeserializer INSTANT = new CustomInstantDeserializer( + Instant.class, DateTimeFormatter.ISO_INSTANT, + new Function() { + @Override + public Instant apply(TemporalAccessor temporalAccessor) { + return Instant.from(temporalAccessor); + } + }, + new Function() { + @Override + public Instant apply(FromIntegerArguments a) { + return Instant.ofEpochMilli(a.value); + } + }, + new Function() { + @Override + public Instant apply(FromDecimalArguments a) { + return Instant.ofEpochSecond(a.integer, a.fraction); + } + }, + null + ); + + public static final CustomInstantDeserializer OFFSET_DATE_TIME = new CustomInstantDeserializer( + OffsetDateTime.class, DateTimeFormatter.ISO_OFFSET_DATE_TIME, + new Function() { + @Override + public OffsetDateTime apply(TemporalAccessor temporalAccessor) { + return OffsetDateTime.from(temporalAccessor); + } + }, + new Function() { + @Override + public OffsetDateTime apply(FromIntegerArguments a) { + return OffsetDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); + } + }, + new Function() { + @Override + public OffsetDateTime apply(FromDecimalArguments a) { + return OffsetDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); + } + }, + new BiFunction() { + @Override + public OffsetDateTime apply(OffsetDateTime d, ZoneId z) { + return d.withOffsetSameInstant(z.getRules().getOffset(d.toLocalDateTime())); + } + } + ); + + public static final CustomInstantDeserializer ZONED_DATE_TIME = new CustomInstantDeserializer( + ZonedDateTime.class, DateTimeFormatter.ISO_ZONED_DATE_TIME, + new Function() { + @Override + public ZonedDateTime apply(TemporalAccessor temporalAccessor) { + return ZonedDateTime.from(temporalAccessor); + } + }, + new Function() { + @Override + public ZonedDateTime apply(FromIntegerArguments a) { + return ZonedDateTime.ofInstant(Instant.ofEpochMilli(a.value), a.zoneId); + } + }, + new Function() { + @Override + public ZonedDateTime apply(FromDecimalArguments a) { + return ZonedDateTime.ofInstant(Instant.ofEpochSecond(a.integer, a.fraction), a.zoneId); + } + }, + new BiFunction() { + @Override + public ZonedDateTime apply(ZonedDateTime zonedDateTime, ZoneId zoneId) { + return zonedDateTime.withZoneSameInstant(zoneId); + } + } + ); + + protected final Function fromMilliseconds; + + protected final Function fromNanoseconds; + + protected final Function parsedToValue; + + protected final BiFunction adjust; + + protected CustomInstantDeserializer(Class supportedType, + DateTimeFormatter parser, + Function parsedToValue, + Function fromMilliseconds, + Function fromNanoseconds, + BiFunction adjust) { + super(supportedType, parser); + this.parsedToValue = parsedToValue; + this.fromMilliseconds = fromMilliseconds; + this.fromNanoseconds = fromNanoseconds; + this.adjust = adjust == null ? new BiFunction() { + @Override + public T apply(T t, ZoneId zoneId) { + return t; + } + } : adjust; + } + + @SuppressWarnings("unchecked") + protected CustomInstantDeserializer(CustomInstantDeserializer base, DateTimeFormatter f) { + super((Class) base.handledType(), f); + parsedToValue = base.parsedToValue; + fromMilliseconds = base.fromMilliseconds; + fromNanoseconds = base.fromNanoseconds; + adjust = base.adjust; + } + + @Override + protected JsonDeserializer withDateFormat(DateTimeFormatter dtf) { + if (dtf == _formatter) { + return this; + } + return new CustomInstantDeserializer(this, dtf); + } + + @Override + public T deserialize(JsonParser parser, DeserializationContext context) throws IOException { + //NOTE: Timestamps contain no timezone info, and are always in configured TZ. Only + //string values have to be adjusted to the configured TZ. + switch (parser.getCurrentTokenId()) { + case JsonTokenId.ID_NUMBER_FLOAT: { + BigDecimal value = parser.getDecimalValue(); + long seconds = value.longValue(); + int nanoseconds = DecimalUtils.extractNanosecondDecimal(value, seconds); + return fromNanoseconds.apply(new FromDecimalArguments( + seconds, nanoseconds, getZone(context))); + } + + case JsonTokenId.ID_NUMBER_INT: { + long timestamp = parser.getLongValue(); + if (context.isEnabled(DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS)) { + return this.fromNanoseconds.apply(new FromDecimalArguments( + timestamp, 0, this.getZone(context) + )); + } + return this.fromMilliseconds.apply(new FromIntegerArguments( + timestamp, this.getZone(context) + )); + } + + case JsonTokenId.ID_STRING: { + String string = parser.getText().trim(); + if (string.length() == 0) { + return null; + } + if (string.endsWith("+0000")) { + string = string.substring(0, string.length() - 5) + "Z"; + } + T value; + try { + TemporalAccessor acc = _formatter.parse(string); + value = parsedToValue.apply(acc); + if (context.isEnabled(DeserializationFeature.ADJUST_DATES_TO_CONTEXT_TIME_ZONE)) { + return adjust.apply(value, this.getZone(context)); + } + } catch (DateTimeException e) { + throw _peelDTE(e); + } + return value; + } + } + throw context.mappingException("Expected type float, integer, or string."); + } + + private ZoneId getZone(DeserializationContext context) { + // Instants are always in UTC, so don't waste compute cycles + return (_valueClass == Instant.class) ? null : DateTimeUtils.toZoneId(context.getTimeZone()); + } + + private static class FromIntegerArguments { + public final long value; + public final ZoneId zoneId; + + private FromIntegerArguments(long value, ZoneId zoneId) { + this.value = value; + this.zoneId = zoneId; + } + } + + private static class FromDecimalArguments { + public final long integer; + public final int fraction; + public final ZoneId zoneId; + + private FromDecimalArguments(long integer, int fraction, ZoneId zoneId) { + this.integer = integer; + this.fraction = fraction; + this.zoneId = zoneId; + } + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/RFC3339DateFormat.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/RFC3339DateFormat.java new file mode 100644 index 0000000000..46083815a6 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/RFC3339DateFormat.java @@ -0,0 +1,32 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +package com.baeldung.petstore.client.invoker; + +import com.fasterxml.jackson.databind.util.ISO8601DateFormat; +import com.fasterxml.jackson.databind.util.ISO8601Utils; + +import java.text.FieldPosition; +import java.util.Date; + + +public class RFC3339DateFormat extends ISO8601DateFormat { + + // Same as ISO8601DateFormat but serializing milliseconds. + @Override + public StringBuffer format(Date date, StringBuffer toAppendTo, FieldPosition fieldPosition) { + String value = ISO8601Utils.format(date, true); + toAppendTo.append(value); + return toAppendTo; + } + +} \ No newline at end of file diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/ApiKeyAuth.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/ApiKeyAuth.java new file mode 100644 index 0000000000..b494b52050 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/ApiKeyAuth.java @@ -0,0 +1,62 @@ +package com.baeldung.petstore.client.invoker.auth; + +import org.springframework.http.HttpHeaders; +import org.springframework.util.MultiValueMap; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class ApiKeyAuth implements Authentication { + private final String location; + private final String paramName; + + private String apiKey; + private String apiKeyPrefix; + + public ApiKeyAuth(String location, String paramName) { + this.location = location; + this.paramName = paramName; + } + + public String getLocation() { + return location; + } + + public String getParamName() { + return paramName; + } + + public String getApiKey() { + return apiKey; + } + + public void setApiKey(String apiKey) { + this.apiKey = apiKey; + } + + public String getApiKeyPrefix() { + return apiKeyPrefix; + } + + public void setApiKeyPrefix(String apiKeyPrefix) { + this.apiKeyPrefix = apiKeyPrefix; + } + + @Override + public void applyToParams(MultiValueMap queryParams, HttpHeaders headerParams, MultiValueMap cookieParams) { + if (apiKey == null) { + return; + } + String value; + if (apiKeyPrefix != null) { + value = apiKeyPrefix + " " + apiKey; + } else { + value = apiKey; + } + if (location.equals("query")) { + queryParams.add(paramName, value); + } else if (location.equals("header")) { + headerParams.add(paramName, value); + } else if (location.equals("cookie")) { + cookieParams.add(paramName, value); + } + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/Authentication.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/Authentication.java new file mode 100644 index 0000000000..8d55110d1b --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/Authentication.java @@ -0,0 +1,14 @@ +package com.baeldung.petstore.client.invoker.auth; + +import org.springframework.http.HttpHeaders; +import org.springframework.util.MultiValueMap; + +public interface Authentication { + /** + * Apply authentication settings to header and / or query parameters. + * @param queryParams The query parameters for the request + * @param headerParams The header parameters for the request + * @param cookieParams The cookie parameters for the request + */ + public void applyToParams(MultiValueMap queryParams, HttpHeaders headerParams, MultiValueMap cookieParams); +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBasicAuth.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBasicAuth.java new file mode 100644 index 0000000000..4c1dad6e7c --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBasicAuth.java @@ -0,0 +1,38 @@ +package com.baeldung.petstore.client.invoker.auth; + +import java.nio.charset.StandardCharsets; + +import org.springframework.http.HttpHeaders; +import org.springframework.util.Base64Utils; +import org.springframework.util.MultiValueMap; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class HttpBasicAuth implements Authentication { + private String username; + private String password; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + @Override + public void applyToParams(MultiValueMap queryParams, HttpHeaders headerParams, MultiValueMap cookieParams) { + if (username == null && password == null) { + return; + } + String str = (username == null ? "" : username) + ":" + (password == null ? "" : password); + headerParams.add(HttpHeaders.AUTHORIZATION, "Basic " + Base64Utils.encodeToString(str.getBytes(StandardCharsets.UTF_8))); + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBearerAuth.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBearerAuth.java new file mode 100644 index 0000000000..46ab6cabce --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/HttpBearerAuth.java @@ -0,0 +1,34 @@ +package com.baeldung.petstore.client.invoker.auth; + +import org.springframework.http.HttpHeaders; +import org.springframework.util.MultiValueMap; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class HttpBearerAuth implements Authentication { + private final String scheme; + private String bearerToken; + + public HttpBearerAuth(String scheme) { + this.scheme = scheme; + } + + public String getBearerToken() { + return bearerToken; + } + + public void setBearerToken(String bearerToken) { + this.bearerToken = bearerToken; + } + + @Override + public void applyToParams(MultiValueMap queryParams, HttpHeaders headerParams, MultiValueMap cookieParams) { + if (bearerToken == null) { + return; + } + headerParams.add(HttpHeaders.AUTHORIZATION, (scheme != null ? upperCaseBearer(scheme) + " " : "") + bearerToken); + } + + private static String upperCaseBearer(String scheme) { + return ("bearer".equalsIgnoreCase(scheme)) ? "Bearer" : scheme; + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuth.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuth.java new file mode 100644 index 0000000000..b9e0f986ac --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuth.java @@ -0,0 +1,24 @@ +package com.baeldung.petstore.client.invoker.auth; + +import org.springframework.http.HttpHeaders; +import org.springframework.util.MultiValueMap; + +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class OAuth implements Authentication { + private String accessToken; + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + @Override + public void applyToParams(MultiValueMap queryParams, HttpHeaders headerParams, MultiValueMap cookieParams) { + if (accessToken != null) { + headerParams.add(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken); + } + } +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuthFlow.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuthFlow.java new file mode 100644 index 0000000000..235e0b7f55 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/invoker/auth/OAuthFlow.java @@ -0,0 +1,5 @@ +package com.baeldung.petstore.client.invoker.auth; + +public enum OAuthFlow { + accessCode, implicit, password, application +} \ No newline at end of file diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Category.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Category.java new file mode 100644 index 0000000000..2bb7ebe9f6 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Category.java @@ -0,0 +1,131 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.Objects; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Category + */ +@JsonPropertyOrder({ + Category.JSON_PROPERTY_ID, + Category.JSON_PROPERTY_NAME +}) +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class Category { + public static final String JSON_PROPERTY_ID = "id"; + private Long id; + + public static final String JSON_PROPERTY_NAME = "name"; + private String name; + + + public Category id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Category name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Category category = (Category) o; + return Objects.equals(this.id, category.id) && + Objects.equals(this.name, category.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Category {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/ModelApiResponse.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/ModelApiResponse.java new file mode 100644 index 0000000000..107e08b8b9 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/ModelApiResponse.java @@ -0,0 +1,162 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.Objects; + +import io.swagger.annotations.ApiModelProperty; + +/** + * ModelApiResponse + */ +@JsonPropertyOrder({ + ModelApiResponse.JSON_PROPERTY_CODE, + ModelApiResponse.JSON_PROPERTY_TYPE, + ModelApiResponse.JSON_PROPERTY_MESSAGE +}) +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class ModelApiResponse { + public static final String JSON_PROPERTY_CODE = "code"; + private Integer code; + + public static final String JSON_PROPERTY_TYPE = "type"; + private String type; + + public static final String JSON_PROPERTY_MESSAGE = "message"; + private String message; + + + public ModelApiResponse code(Integer code) { + + this.code = code; + return this; + } + + /** + * Get code + * @return code + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_CODE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Integer getCode() { + return code; + } + + + public void setCode(Integer code) { + this.code = code; + } + + + public ModelApiResponse type(String type) { + + this.type = type; + return this; + } + + /** + * Get type + * @return type + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_TYPE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getType() { + return type; + } + + + public void setType(String type) { + this.type = type; + } + + + public ModelApiResponse message(String message) { + + this.message = message; + return this; + } + + /** + * Get message + * @return message + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_MESSAGE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getMessage() { + return message; + } + + + public void setMessage(String message) { + this.message = message; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ModelApiResponse _apiResponse = (ModelApiResponse) o; + return Objects.equals(this.code, _apiResponse.code) && + Objects.equals(this.type, _apiResponse.type) && + Objects.equals(this.message, _apiResponse.message); + } + + @Override + public int hashCode() { + return Objects.hash(code, type, message); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class ModelApiResponse {\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" message: ").append(toIndentedString(message)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Order.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Order.java new file mode 100644 index 0000000000..b041595785 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Order.java @@ -0,0 +1,296 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonValue; + +import java.util.Objects; + +import org.threeten.bp.OffsetDateTime; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Order + */ +@JsonPropertyOrder({ + Order.JSON_PROPERTY_ID, + Order.JSON_PROPERTY_PET_ID, + Order.JSON_PROPERTY_QUANTITY, + Order.JSON_PROPERTY_SHIP_DATE, + Order.JSON_PROPERTY_STATUS, + Order.JSON_PROPERTY_COMPLETE +}) +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class Order { + public static final String JSON_PROPERTY_ID = "id"; + private Long id; + + public static final String JSON_PROPERTY_PET_ID = "petId"; + private Long petId; + + public static final String JSON_PROPERTY_QUANTITY = "quantity"; + private Integer quantity; + + public static final String JSON_PROPERTY_SHIP_DATE = "shipDate"; + private OffsetDateTime shipDate; + + /** + * Order Status + */ + public enum StatusEnum { + PLACED("placed"), + + APPROVED("approved"), + + DELIVERED("delivered"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + public static final String JSON_PROPERTY_STATUS = "status"; + private StatusEnum status; + + public static final String JSON_PROPERTY_COMPLETE = "complete"; + private Boolean complete; + + + public Order id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Order petId(Long petId) { + + this.petId = petId; + return this; + } + + /** + * Get petId + * @return petId + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_PET_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Long getPetId() { + return petId; + } + + + public void setPetId(Long petId) { + this.petId = petId; + } + + + public Order quantity(Integer quantity) { + + this.quantity = quantity; + return this; + } + + /** + * Get quantity + * @return quantity + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_QUANTITY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Integer getQuantity() { + return quantity; + } + + + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + + public Order shipDate(OffsetDateTime shipDate) { + + this.shipDate = shipDate; + return this; + } + + /** + * Get shipDate + * @return shipDate + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_SHIP_DATE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public OffsetDateTime getShipDate() { + return shipDate; + } + + + public void setShipDate(OffsetDateTime shipDate) { + this.shipDate = shipDate; + } + + + public Order status(StatusEnum status) { + + this.status = status; + return this; + } + + /** + * Order Status + * @return status + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "Order Status") + @JsonProperty(JSON_PROPERTY_STATUS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public StatusEnum getStatus() { + return status; + } + + + public void setStatus(StatusEnum status) { + this.status = status; + } + + + public Order complete(Boolean complete) { + + this.complete = complete; + return this; + } + + /** + * Get complete + * @return complete + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_COMPLETE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Boolean getComplete() { + return complete; + } + + + public void setComplete(Boolean complete) { + this.complete = complete; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Order order = (Order) o; + return Objects.equals(this.id, order.id) && + Objects.equals(this.petId, order.petId) && + Objects.equals(this.quantity, order.quantity) && + Objects.equals(this.shipDate, order.shipDate) && + Objects.equals(this.status, order.status) && + Objects.equals(this.complete, order.complete); + } + + @Override + public int hashCode() { + return Objects.hash(id, petId, quantity, shipDate, status, complete); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Order {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" petId: ").append(toIndentedString(petId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" shipDate: ").append(toIndentedString(shipDate)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append(" complete: ").append(toIndentedString(complete)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Pet.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Pet.java new file mode 100644 index 0000000000..3709cd5371 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Pet.java @@ -0,0 +1,310 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import com.fasterxml.jackson.annotation.JsonValue; + +import com.baeldung.petstore.client.model.Category; +import com.baeldung.petstore.client.model.Tag; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Pet + */ +@JsonPropertyOrder({ + Pet.JSON_PROPERTY_ID, + Pet.JSON_PROPERTY_CATEGORY, + Pet.JSON_PROPERTY_NAME, + Pet.JSON_PROPERTY_PHOTO_URLS, + Pet.JSON_PROPERTY_TAGS, + Pet.JSON_PROPERTY_STATUS +}) +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class Pet { + public static final String JSON_PROPERTY_ID = "id"; + private Long id; + + public static final String JSON_PROPERTY_CATEGORY = "category"; + private Category category; + + public static final String JSON_PROPERTY_NAME = "name"; + private String name; + + public static final String JSON_PROPERTY_PHOTO_URLS = "photoUrls"; + private List photoUrls = new ArrayList<>(); + + public static final String JSON_PROPERTY_TAGS = "tags"; + private List tags = null; + + /** + * pet status in the store + */ + public enum StatusEnum { + AVAILABLE("available"), + + PENDING("pending"), + + SOLD("sold"); + + private String value; + + StatusEnum(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static StatusEnum fromValue(String value) { + for (StatusEnum b : StatusEnum.values()) { + if (b.value.equals(value)) { + return b; + } + } + throw new IllegalArgumentException("Unexpected value '" + value + "'"); + } + } + + public static final String JSON_PROPERTY_STATUS = "status"; + private StatusEnum status; + + + public Pet id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Pet category(Category category) { + + this.category = category; + return this; + } + + /** + * Get category + * @return category + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_CATEGORY) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Category getCategory() { + return category; + } + + + public void setCategory(Category category) { + this.category = category; + } + + + public Pet name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @ApiModelProperty(example = "doggie", required = true, value = "") + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + public Pet photoUrls(List photoUrls) { + + this.photoUrls = photoUrls; + return this; + } + + public Pet addPhotoUrlsItem(String photoUrlsItem) { + this.photoUrls.add(photoUrlsItem); + return this; + } + + /** + * Get photoUrls + * @return photoUrls + **/ + @ApiModelProperty(required = true, value = "") + @JsonProperty(JSON_PROPERTY_PHOTO_URLS) + @JsonInclude(value = JsonInclude.Include.ALWAYS) + + public List getPhotoUrls() { + return photoUrls; + } + + + public void setPhotoUrls(List photoUrls) { + this.photoUrls = photoUrls; + } + + + public Pet tags(List tags) { + + this.tags = tags; + return this; + } + + public Pet addTagsItem(Tag tagsItem) { + if (this.tags == null) { + this.tags = new ArrayList<>(); + } + this.tags.add(tagsItem); + return this; + } + + /** + * Get tags + * @return tags + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_TAGS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public List getTags() { + return tags; + } + + + public void setTags(List tags) { + this.tags = tags; + } + + + public Pet status(StatusEnum status) { + + this.status = status; + return this; + } + + /** + * pet status in the store + * @return status + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "pet status in the store") + @JsonProperty(JSON_PROPERTY_STATUS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public StatusEnum getStatus() { + return status; + } + + + public void setStatus(StatusEnum status) { + this.status = status; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Pet pet = (Pet) o; + return Objects.equals(this.id, pet.id) && + Objects.equals(this.category, pet.category) && + Objects.equals(this.name, pet.name) && + Objects.equals(this.photoUrls, pet.photoUrls) && + Objects.equals(this.tags, pet.tags) && + Objects.equals(this.status, pet.status); + } + + @Override + public int hashCode() { + return Objects.hash(id, category, name, photoUrls, tags, status); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Pet {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" category: ").append(toIndentedString(category)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" photoUrls: ").append(toIndentedString(photoUrls)).append("\n"); + sb.append(" tags: ").append(toIndentedString(tags)).append("\n"); + sb.append(" status: ").append(toIndentedString(status)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Tag.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Tag.java new file mode 100644 index 0000000000..7ee50c69b0 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/Tag.java @@ -0,0 +1,131 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.Objects; + +import io.swagger.annotations.ApiModelProperty; + +/** + * Tag + */ +@JsonPropertyOrder({ + Tag.JSON_PROPERTY_ID, + Tag.JSON_PROPERTY_NAME +}) +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class Tag { + public static final String JSON_PROPERTY_ID = "id"; + private Long id; + + public static final String JSON_PROPERTY_NAME = "name"; + private String name; + + + public Tag id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public Tag name(String name) { + + this.name = name; + return this; + } + + /** + * Get name + * @return name + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getName() { + return name; + } + + + public void setName(String name) { + this.name = name; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Tag tag = (Tag) o; + return Objects.equals(this.id, tag.id) && + Objects.equals(this.name, tag.name); + } + + @Override + public int hashCode() { + return Objects.hash(id, name); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Tag {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/User.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/User.java new file mode 100644 index 0000000000..ba12953ed3 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/main/java/com/baeldung/petstore/client/model/User.java @@ -0,0 +1,317 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +import java.util.Objects; + +import io.swagger.annotations.ApiModelProperty; + +/** + * User + */ +@JsonPropertyOrder({ + User.JSON_PROPERTY_ID, + User.JSON_PROPERTY_USERNAME, + User.JSON_PROPERTY_FIRST_NAME, + User.JSON_PROPERTY_LAST_NAME, + User.JSON_PROPERTY_EMAIL, + User.JSON_PROPERTY_PASSWORD, + User.JSON_PROPERTY_PHONE, + User.JSON_PROPERTY_USER_STATUS +}) +@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2020-03-15T06:14:01.568992-05:00[America/Chicago]") +public class User { + public static final String JSON_PROPERTY_ID = "id"; + private Long id; + + public static final String JSON_PROPERTY_USERNAME = "username"; + private String username; + + public static final String JSON_PROPERTY_FIRST_NAME = "firstName"; + private String firstName; + + public static final String JSON_PROPERTY_LAST_NAME = "lastName"; + private String lastName; + + public static final String JSON_PROPERTY_EMAIL = "email"; + private String email; + + public static final String JSON_PROPERTY_PASSWORD = "password"; + private String password; + + public static final String JSON_PROPERTY_PHONE = "phone"; + private String phone; + + public static final String JSON_PROPERTY_USER_STATUS = "userStatus"; + private Integer userStatus; + + + public User id(Long id) { + + this.id = id; + return this; + } + + /** + * Get id + * @return id + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_ID) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Long getId() { + return id; + } + + + public void setId(Long id) { + this.id = id; + } + + + public User username(String username) { + + this.username = username; + return this; + } + + /** + * Get username + * @return username + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_USERNAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getUsername() { + return username; + } + + + public void setUsername(String username) { + this.username = username; + } + + + public User firstName(String firstName) { + + this.firstName = firstName; + return this; + } + + /** + * Get firstName + * @return firstName + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_FIRST_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getFirstName() { + return firstName; + } + + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + + public User lastName(String lastName) { + + this.lastName = lastName; + return this; + } + + /** + * Get lastName + * @return lastName + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_LAST_NAME) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getLastName() { + return lastName; + } + + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + + public User email(String email) { + + this.email = email; + return this; + } + + /** + * Get email + * @return email + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_EMAIL) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getEmail() { + return email; + } + + + public void setEmail(String email) { + this.email = email; + } + + + public User password(String password) { + + this.password = password; + return this; + } + + /** + * Get password + * @return password + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_PASSWORD) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getPassword() { + return password; + } + + + public void setPassword(String password) { + this.password = password; + } + + + public User phone(String phone) { + + this.phone = phone; + return this; + } + + /** + * Get phone + * @return phone + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "") + @JsonProperty(JSON_PROPERTY_PHONE) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public String getPhone() { + return phone; + } + + + public void setPhone(String phone) { + this.phone = phone; + } + + + public User userStatus(Integer userStatus) { + + this.userStatus = userStatus; + return this; + } + + /** + * User Status + * @return userStatus + **/ + @javax.annotation.Nullable + @ApiModelProperty(value = "User Status") + @JsonProperty(JSON_PROPERTY_USER_STATUS) + @JsonInclude(value = JsonInclude.Include.USE_DEFAULTS) + + public Integer getUserStatus() { + return userStatus; + } + + + public void setUserStatus(Integer userStatus) { + this.userStatus = userStatus; + } + + + @Override + public boolean equals(java.lang.Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + User user = (User) o; + return Objects.equals(this.id, user.id) && + Objects.equals(this.username, user.username) && + Objects.equals(this.firstName, user.firstName) && + Objects.equals(this.lastName, user.lastName) && + Objects.equals(this.email, user.email) && + Objects.equals(this.password, user.password) && + Objects.equals(this.phone, user.phone) && + Objects.equals(this.userStatus, user.userStatus); + } + + @Override + public int hashCode() { + return Objects.hash(id, username, firstName, lastName, email, password, phone, userStatus); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class User {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" username: ").append(toIndentedString(username)).append("\n"); + sb.append(" firstName: ").append(toIndentedString(firstName)).append("\n"); + sb.append(" lastName: ").append(toIndentedString(lastName)).append("\n"); + sb.append(" email: ").append(toIndentedString(email)).append("\n"); + sb.append(" password: ").append(toIndentedString(password)).append("\n"); + sb.append(" phone: ").append(toIndentedString(phone)).append("\n"); + sb.append(" userStatus: ").append(toIndentedString(userStatus)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces + * (except the first line). + */ + private String toIndentedString(java.lang.Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } + +} + diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/PetApiTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/PetApiTest.java new file mode 100644 index 0000000000..8854e8e3d4 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/PetApiTest.java @@ -0,0 +1,167 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.api; + +import com.baeldung.petstore.client.model.ModelApiResponse; +import com.baeldung.petstore.client.model.Pet; + +import java.io.File; +import java.util.List; + +import org.junit.Ignore; +import org.junit.Test; + +/** + * API tests for PetApi + */ +@Ignore +public class PetApiTest { + + private final PetApi api = new PetApi(); + + + /** + * Add a new pet to the store + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void addPetTest() { + Pet body = null; + api.addPet(body); + + // TODO: test validations + } + + /** + * Deletes a pet + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void deletePetTest() { + Long petId = null; + String apiKey = null; + api.deletePet(petId, apiKey); + + // TODO: test validations + } + + /** + * Finds Pets by status + * + * Multiple status values can be provided with comma separated strings + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void findPetsByStatusTest() { + List status = null; + List response = api.findPetsByStatus(status); + + // TODO: test validations + } + + /** + * Finds Pets by tags + * + * Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void findPetsByTagsTest() { + List tags = null; + List response = api.findPetsByTags(tags); + + // TODO: test validations + } + + /** + * Find pet by ID + * + * Returns a single pet + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void getPetByIdTest() { + Long petId = null; + Pet response = api.getPetById(petId); + + // TODO: test validations + } + + /** + * Update an existing pet + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void updatePetTest() { + Pet body = null; + api.updatePet(body); + + // TODO: test validations + } + + /** + * Updates a pet in the store with form data + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void updatePetWithFormTest() { + Long petId = null; + String name = null; + String status = null; + api.updatePetWithForm(petId, name, status); + + // TODO: test validations + } + + /** + * uploads an image + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void uploadFileTest() { + Long petId = null; + String additionalMetadata = null; + File file = null; + ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file); + + // TODO: test validations + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/StoreApiTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/StoreApiTest.java new file mode 100644 index 0000000000..444429bd42 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/StoreApiTest.java @@ -0,0 +1,95 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.api; + +import com.baeldung.petstore.client.model.Order; + +import java.util.Map; + +import org.junit.Ignore; +import org.junit.Test; + +/** + * API tests for StoreApi + */ +@Ignore +public class StoreApiTest { + + private final StoreApi api = new StoreApi(); + + + /** + * Delete purchase order by ID + * + * For valid response try integer IDs with positive integer value. Negative or non-integer values will generate API errors + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void deleteOrderTest() { + Long orderId = null; + api.deleteOrder(orderId); + + // TODO: test validations + } + + /** + * Returns pet inventories by status + * + * Returns a map of status codes to quantities + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void getInventoryTest() { + Map response = api.getInventory(); + + // TODO: test validations + } + + /** + * Find purchase order by ID + * + * For valid response try integer IDs with value >= 1 and <= 10. Other values will generated exceptions + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void getOrderByIdTest() { + Long orderId = null; + Order response = api.getOrderById(orderId); + + // TODO: test validations + } + + /** + * Place an order for a pet + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void placeOrderTest() { + Order body = null; + Order response = api.placeOrder(body); + + // TODO: test validations + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/UserApiTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/UserApiTest.java new file mode 100644 index 0000000000..c73b47ecb2 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/api/UserApiTest.java @@ -0,0 +1,161 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.api; + +import com.baeldung.petstore.client.model.User; + +import java.util.List; + +import org.junit.Ignore; +import org.junit.Test; + +/** + * API tests for UserApi + */ +@Ignore +public class UserApiTest { + + private final UserApi api = new UserApi(); + + + /** + * Create user + * + * This can only be done by the logged in user. + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void createUserTest() { + User body = null; + api.createUser(body); + + // TODO: test validations + } + + /** + * Creates list of users with given input array + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void createUsersWithArrayInputTest() { + List body = null; + api.createUsersWithArrayInput(body); + + // TODO: test validations + } + + /** + * Creates list of users with given input array + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void createUsersWithListInputTest() { + List body = null; + api.createUsersWithListInput(body); + + // TODO: test validations + } + + /** + * Delete user + * + * This can only be done by the logged in user. + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void deleteUserTest() { + String username = null; + api.deleteUser(username); + + // TODO: test validations + } + + /** + * Get user by user name + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void getUserByNameTest() { + String username = null; + User response = api.getUserByName(username); + + // TODO: test validations + } + + /** + * Logs user into the system + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void loginUserTest() { + String username = null; + String password = null; + String response = api.loginUser(username, password); + + // TODO: test validations + } + + /** + * Logs out current logged in user session + * + * + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void logoutUserTest() { + api.logoutUser(); + + // TODO: test validations + } + + /** + * Updated user + * + * This can only be done by the logged in user. + * + * @throws ApiException + * if the Api call fails + */ + @Test + public void updateUserTest() { + String username = null; + User body = null; + api.updateUser(username, body); + + // TODO: test validations + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/CategoryTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/CategoryTest.java new file mode 100644 index 0000000000..7be1b285c3 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/CategoryTest.java @@ -0,0 +1,49 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import org.junit.Test; + + +/** + * Model tests for Category + */ +public class CategoryTest { + private final Category model = new Category(); + + /** + * Model tests for Category + */ + @Test + public void testCategory() { + // TODO: test Category + } + + /** + * Test the property 'id' + */ + @Test + public void idTest() { + // TODO: test id + } + + /** + * Test the property 'name' + */ + @Test + public void nameTest() { + // TODO: test name + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/ModelApiResponseTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/ModelApiResponseTest.java new file mode 100644 index 0000000000..55f742f862 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/ModelApiResponseTest.java @@ -0,0 +1,57 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import org.junit.Test; + + +/** + * Model tests for ModelApiResponse + */ +public class ModelApiResponseTest { + private final ModelApiResponse model = new ModelApiResponse(); + + /** + * Model tests for ModelApiResponse + */ + @Test + public void testModelApiResponse() { + // TODO: test ModelApiResponse + } + + /** + * Test the property 'code' + */ + @Test + public void codeTest() { + // TODO: test code + } + + /** + * Test the property 'type' + */ + @Test + public void typeTest() { + // TODO: test type + } + + /** + * Test the property 'message' + */ + @Test + public void messageTest() { + // TODO: test message + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/OrderTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/OrderTest.java new file mode 100644 index 0000000000..edbacea028 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/OrderTest.java @@ -0,0 +1,81 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import org.junit.Test; + + +/** + * Model tests for Order + */ +public class OrderTest { + private final Order model = new Order(); + + /** + * Model tests for Order + */ + @Test + public void testOrder() { + // TODO: test Order + } + + /** + * Test the property 'id' + */ + @Test + public void idTest() { + // TODO: test id + } + + /** + * Test the property 'petId' + */ + @Test + public void petIdTest() { + // TODO: test petId + } + + /** + * Test the property 'quantity' + */ + @Test + public void quantityTest() { + // TODO: test quantity + } + + /** + * Test the property 'shipDate' + */ + @Test + public void shipDateTest() { + // TODO: test shipDate + } + + /** + * Test the property 'status' + */ + @Test + public void statusTest() { + // TODO: test status + } + + /** + * Test the property 'complete' + */ + @Test + public void completeTest() { + // TODO: test complete + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/PetTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/PetTest.java new file mode 100644 index 0000000000..78951acaba --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/PetTest.java @@ -0,0 +1,81 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import org.junit.Test; + + +/** + * Model tests for Pet + */ +public class PetTest { + private final Pet model = new Pet(); + + /** + * Model tests for Pet + */ + @Test + public void testPet() { + // TODO: test Pet + } + + /** + * Test the property 'id' + */ + @Test + public void idTest() { + // TODO: test id + } + + /** + * Test the property 'category' + */ + @Test + public void categoryTest() { + // TODO: test category + } + + /** + * Test the property 'name' + */ + @Test + public void nameTest() { + // TODO: test name + } + + /** + * Test the property 'photoUrls' + */ + @Test + public void photoUrlsTest() { + // TODO: test photoUrls + } + + /** + * Test the property 'tags' + */ + @Test + public void tagsTest() { + // TODO: test tags + } + + /** + * Test the property 'status' + */ + @Test + public void statusTest() { + // TODO: test status + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/TagTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/TagTest.java new file mode 100644 index 0000000000..16efed2570 --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/TagTest.java @@ -0,0 +1,49 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import org.junit.Test; + + +/** + * Model tests for Tag + */ +public class TagTest { + private final Tag model = new Tag(); + + /** + * Model tests for Tag + */ + @Test + public void testTag() { + // TODO: test Tag + } + + /** + * Test the property 'id' + */ + @Test + public void idTest() { + // TODO: test id + } + + /** + * Test the property 'name' + */ + @Test + public void nameTest() { + // TODO: test name + } + +} diff --git a/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/UserTest.java b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/UserTest.java new file mode 100644 index 0000000000..d84cfb21ca --- /dev/null +++ b/spring-swagger-codegen/spring-openapi-generator-api-client/src/test/java/com/baeldung/petstore/client/model/UserTest.java @@ -0,0 +1,97 @@ +/* + * Swagger Petstore + * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.3 + * Contact: apiteam@swagger.io + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +package com.baeldung.petstore.client.model; + +import org.junit.Test; + + +/** + * Model tests for User + */ +public class UserTest { + private final User model = new User(); + + /** + * Model tests for User + */ + @Test + public void testUser() { + // TODO: test User + } + + /** + * Test the property 'id' + */ + @Test + public void idTest() { + // TODO: test id + } + + /** + * Test the property 'username' + */ + @Test + public void usernameTest() { + // TODO: test username + } + + /** + * Test the property 'firstName' + */ + @Test + public void firstNameTest() { + // TODO: test firstName + } + + /** + * Test the property 'lastName' + */ + @Test + public void lastNameTest() { + // TODO: test lastName + } + + /** + * Test the property 'email' + */ + @Test + public void emailTest() { + // TODO: test email + } + + /** + * Test the property 'password' + */ + @Test + public void passwordTest() { + // TODO: test password + } + + /** + * Test the property 'phone' + */ + @Test + public void phoneTest() { + // TODO: test phone + } + + /** + * Test the property 'userStatus' + */ + @Test + public void userStatusTest() { + // TODO: test userStatus + } + +} From 0a48cad1c3a034ad1a48e811649148f4670d8f0c Mon Sep 17 00:00:00 2001 From: pazis Date: Mon, 23 Mar 2020 02:05:05 +0000 Subject: [PATCH 233/278] BAEL-3881 --- algorithms-miscellaneous-6/pom.xml | 15 +++++++++ .../gradientdescent/GradientDescent.java | 33 +++++++++++++++++++ .../GradientDescentUnitTest.java | 20 +++++++++++ pom.xml | 2 ++ 4 files changed, 70 insertions(+) create mode 100644 algorithms-miscellaneous-6/pom.xml create mode 100644 algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/gradientdescent/GradientDescent.java create mode 100644 algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/gradientdescent/GradientDescentUnitTest.java diff --git a/algorithms-miscellaneous-6/pom.xml b/algorithms-miscellaneous-6/pom.xml new file mode 100644 index 0000000000..5daa000ea3 --- /dev/null +++ b/algorithms-miscellaneous-6/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + algorithms-miscellaneous-6 + 0.0.1-SNAPSHOT + algorithms-miscellaneous-6 + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + diff --git a/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/gradientdescent/GradientDescent.java b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/gradientdescent/GradientDescent.java new file mode 100644 index 0000000000..c5db3a4a06 --- /dev/null +++ b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/gradientdescent/GradientDescent.java @@ -0,0 +1,33 @@ +package com.baeldung.algorithms.gradientdescent; + +import java.util.function.Function; + +public class GradientDescent { + + private final double precision = 0.000001; + + public double findLocalMinimum(Function f, double initialX) { + double stepCoefficient = 0.1; + double previousStep = 1.0; + double currentX = initialX; + double previousX = initialX; + double previousY = f.apply(previousX); + int iter = 100; + + currentX += stepCoefficient * previousY; + + while (previousStep > precision && iter > 0) { + iter--; + double currentY = f.apply(currentX); + if (currentY > previousY) { + stepCoefficient = -stepCoefficient / 2; + } + previousX = currentX; + currentX += stepCoefficient * previousY; + previousY = currentY; + previousStep = StrictMath.abs(currentX - previousX); + } + return currentX; + } + +} diff --git a/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/gradientdescent/GradientDescentUnitTest.java b/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/gradientdescent/GradientDescentUnitTest.java new file mode 100644 index 0000000000..34d3e188f2 --- /dev/null +++ b/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/gradientdescent/GradientDescentUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung.algorithms.gradientdescent; + +import static org.junit.Assert.assertTrue; + +import java.util.function.Function; + +import org.junit.Test; + +public class GradientDescentUnitTest { + + @Test + public void givenFunction_whenStartingPointIsOne_thenLocalMinimumIsFound() { + Function df = x -> + StrictMath.abs(StrictMath.pow(x, 3)) - (3 * StrictMath.pow(x, 2)) + x; + GradientDescent gd = new GradientDescent(); + double res = gd.findLocalMinimum(df, 1); + assertTrue(res > 1.78); + assertTrue(res < 1.84); + } +} diff --git a/pom.xml b/pom.xml index 15331d8c95..45bdf9747e 100644 --- a/pom.xml +++ b/pom.xml @@ -342,6 +342,7 @@ algorithms-miscellaneous-3 algorithms-miscellaneous-4 algorithms-miscellaneous-5 + algorithms-miscellaneous-6 algorithms-searching algorithms-sorting algorithms-sorting-2 @@ -853,6 +854,7 @@ algorithms-miscellaneous-3 algorithms-miscellaneous-4 algorithms-miscellaneous-5 + algorithms-miscellaneous-6 algorithms-searching algorithms-sorting algorithms-sorting-2 From 9ead49e028f7db5fd5b8bce659c378c9fd5d08e5 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:07:01 +0800 Subject: [PATCH 234/278] Update README.md --- core-java-modules/core-java-9/README.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/core-java-modules/core-java-9/README.md b/core-java-modules/core-java-9/README.md index bfd426b9c1..2dbf159750 100644 --- a/core-java-modules/core-java-9/README.md +++ b/core-java-modules/core-java-9/README.md @@ -10,6 +10,3 @@ This module contains articles about Java 9 core features - [Initialize a HashMap in Java](https://www.baeldung.com/java-initialize-hashmap) - [Immutable Set in Java](https://www.baeldung.com/java-immutable-set) - [Immutable ArrayList in Java](https://www.baeldung.com/java-immutable-list) - -Note: also contains part of the code for the article -[How to Filter a Collection in Java](https://www.baeldung.com/java-collection-filtering). From d90933973e6f6c12ab110033b42370c344e68890 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:18:10 +0800 Subject: [PATCH 235/278] Update README.md --- core-java-modules/core-java-arrays/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-arrays/README.md b/core-java-modules/core-java-arrays/README.md index 42fe3f83a1..9d9db9ab81 100644 --- a/core-java-modules/core-java-arrays/README.md +++ b/core-java-modules/core-java-arrays/README.md @@ -10,7 +10,6 @@ This module contains articles about Java arrays - [Multi-Dimensional Arrays In Java](https://www.baeldung.com/java-jagged-arrays) - [Find Sum and Average in a Java Array](https://www.baeldung.com/java-array-sum-average) - [Arrays in Java: A Reference Guide](https://www.baeldung.com/java-arrays-guide) -- [Read and Write User Input in Java](https://www.baeldung.com/java-console-input-output) - [How to Reverse an Array in Java](http://www.baeldung.com/java-invert-array) - [Sorting Arrays in Java](https://www.baeldung.com/java-sorting-arrays) - [Checking If an Array Is Sorted in Java](https://www.baeldung.com/java-check-sorted-array) From cbf3815f0969390902a352331da268d45b46e16c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:22:55 +0800 Subject: [PATCH 236/278] Update README.md --- spring-security-modules/spring-security-rest/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-security-modules/spring-security-rest/README.md b/spring-security-modules/spring-security-rest/README.md index f7e91b85dc..26c101d32c 100644 --- a/spring-security-modules/spring-security-rest/README.md +++ b/spring-security-modules/spring-security-rest/README.md @@ -8,12 +8,11 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring The "Learn Spring Security" Classes: http://github.learnspringsecurity.com ### Relevant Articles: -- [Spring REST Service Security](https://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/) + - [Setting Up Swagger 2 with a Spring REST API](https://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) - [Custom Error Message Handling for REST API](https://www.baeldung.com/global-error-handler-in-a-spring-rest-api) - [Spring Security Context Propagation with @Async](https://www.baeldung.com/spring-security-async-principal-propagation) - [Servlet 3 Async Support with Spring MVC and Spring Security](https://www.baeldung.com/spring-mvc-async-security) - [Intro to Spring Security Expressions](https://www.baeldung.com/spring-security-expressions) -- [Spring Security for a REST API](https://www.baeldung.com/securing-a-restful-web-service-with-spring-security) - [Spring Security Expressions - hasRole Example](https://www.baeldung.com/spring-security-expressions-basic) - [Error Handling for REST with Spring](https://www.baeldung.com/exception-handling-for-rest-with-spring) From 54a4a3655ef2e949dd18142dbd47ad6413b421e4 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:29:09 +0800 Subject: [PATCH 237/278] Delete README.md --- .../spring-boot-runtime/disabling-console-log4j2/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-runtime/disabling-console-log4j2/README.md diff --git a/spring-boot-modules/spring-boot-runtime/disabling-console-log4j2/README.md b/spring-boot-modules/spring-boot-runtime/disabling-console-log4j2/README.md deleted file mode 100644 index 554f051b41..0000000000 --- a/spring-boot-modules/spring-boot-runtime/disabling-console-log4j2/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging) From 2a65df46dbf696094ff5e099b1d9ddcb0932f5df Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:32:12 +0800 Subject: [PATCH 238/278] Update README.md --- testing-modules/junit5-migration/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing-modules/junit5-migration/README.md b/testing-modules/junit5-migration/README.md index 84e540b466..5cc9db8bd3 100644 --- a/testing-modules/junit5-migration/README.md +++ b/testing-modules/junit5-migration/README.md @@ -5,6 +5,6 @@ This module contains articles about migrating to JUnit 5. The code for the JUnit 4 - JUnit 5 E-book is in `com.baeldung.junit4` and `com.baeldung.junit5`. ### Relevant Articles: -- [JUnit 5 Migration](https://www.baeldung.com/junit-5-migration) + - [A Quick JUnit vs TestNG Comparison](https://www.baeldung.com/junit-vs-testng) - [Assertions in JUnit 4 and JUnit 5](https://www.baeldung.com/junit-assertions) From 9240a08f5a3df45942d640a5381008d331fb0327 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:37:23 +0800 Subject: [PATCH 239/278] Delete README.md --- .../spring-boot-runtime/disabling-console-jul/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-runtime/disabling-console-jul/README.md diff --git a/spring-boot-modules/spring-boot-runtime/disabling-console-jul/README.md b/spring-boot-modules/spring-boot-runtime/disabling-console-jul/README.md deleted file mode 100644 index 554f051b41..0000000000 --- a/spring-boot-modules/spring-boot-runtime/disabling-console-jul/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [How to Disable Console Logging in Spring Boot](https://www.baeldung.com/spring-boot-disable-console-logging) From 825fd077970bac4924fd7797ba4425d92aae2360 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:42:04 +0800 Subject: [PATCH 240/278] Update README.md --- java-numbers/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/java-numbers/README.md b/java-numbers/README.md index eee6fceab1..8f53006b38 100644 --- a/java-numbers/README.md +++ b/java-numbers/README.md @@ -8,7 +8,6 @@ This module contains articles about numbers in Java. - [BigDecimal and BigInteger in Java](http://www.baeldung.com/java-bigdecimal-biginteger) - [Find All Pairs of Numbers in an Array That Add Up to a Given Sum](http://www.baeldung.com/java-algorithm-number-pairs-sum) - [Java – Random Long, Float, Integer and Double](http://www.baeldung.com/java-generate-random-long-float-integer-double) -- [Using Math.sin with Degrees](https://www.baeldung.com/java-math-sin-degrees) - [A Practical Guide to DecimalFormat](http://www.baeldung.com/java-decimalformat) - [Calculating the nth Root in Java](https://www.baeldung.com/java-nth-root) - [Convert Double to String, Removing Decimal Places](https://www.baeldung.com/java-double-to-string) From eac4d6a71548399ac89810143ec849ab9055e181 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:44:34 +0800 Subject: [PATCH 241/278] Update README.md --- core-java-modules/core-java-lang-syntax/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-lang-syntax/README.md b/core-java-modules/core-java-lang-syntax/README.md index bef03b98ad..ae0958e961 100644 --- a/core-java-modules/core-java-lang-syntax/README.md +++ b/core-java-modules/core-java-lang-syntax/README.md @@ -5,7 +5,6 @@ This module contains articles about Java syntax ### Relevant Articles: - [The Basics of Java Generics](https://www.baeldung.com/java-generics) - [Java Primitive Conversions](https://www.baeldung.com/java-primitive-conversions) -- [The Java continue and break Keywords](https://www.baeldung.com/java-continue-and-break) - [A Guide to Creating Objects in Java](https://www.baeldung.com/java-initialization) - [A Guide to Java Loops](https://www.baeldung.com/java-loops) - [Varargs in Java](https://www.baeldung.com/java-varargs) From 11f23a2f6b7ac2c75402fe8c203f46d138dac166 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:45:49 +0800 Subject: [PATCH 242/278] Update README.md --- core-java-modules/core-java-lang-syntax/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-lang-syntax/README.md b/core-java-modules/core-java-lang-syntax/README.md index ae0958e961..f28a675258 100644 --- a/core-java-modules/core-java-lang-syntax/README.md +++ b/core-java-modules/core-java-lang-syntax/README.md @@ -8,7 +8,6 @@ This module contains articles about Java syntax - [A Guide to Creating Objects in Java](https://www.baeldung.com/java-initialization) - [A Guide to Java Loops](https://www.baeldung.com/java-loops) - [Varargs in Java](https://www.baeldung.com/java-varargs) -- [A Guide to Java Enums](https://www.baeldung.com/a-guide-to-java-enums) - [Infinite Loops in Java](https://www.baeldung.com/infinite-loops-java) - [Java Switch Statement](https://www.baeldung.com/java-switch) - [Breaking Out of Nested Loops](https://www.baeldung.com/java-breaking-out-nested-loop) From 6f89368718e8a203566081251831de8ced9c4f68 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:46:45 +0800 Subject: [PATCH 243/278] Update README.md --- core-java-modules/core-java-lang-syntax/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-lang-syntax/README.md b/core-java-modules/core-java-lang-syntax/README.md index f28a675258..f74fa1b546 100644 --- a/core-java-modules/core-java-lang-syntax/README.md +++ b/core-java-modules/core-java-lang-syntax/README.md @@ -8,7 +8,6 @@ This module contains articles about Java syntax - [A Guide to Creating Objects in Java](https://www.baeldung.com/java-initialization) - [A Guide to Java Loops](https://www.baeldung.com/java-loops) - [Varargs in Java](https://www.baeldung.com/java-varargs) -- [Infinite Loops in Java](https://www.baeldung.com/infinite-loops-java) - [Java Switch Statement](https://www.baeldung.com/java-switch) - [Breaking Out of Nested Loops](https://www.baeldung.com/java-breaking-out-nested-loop) - [Java Do-While Loop](https://www.baeldung.com/java-do-while-loop) From 4084fbf62646d33e60215bbb7cb4d6856006f456 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:48:05 +0800 Subject: [PATCH 244/278] Delete README.md --- bazel/bazelgreeting/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 bazel/bazelgreeting/README.md diff --git a/bazel/bazelgreeting/README.md b/bazel/bazelgreeting/README.md deleted file mode 100644 index 528f797c21..0000000000 --- a/bazel/bazelgreeting/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Building Java Applications with Bazel](https://www.baeldung.com/bazel-build-tool) From df6fd3681d43035c71abefdfbfa2acdfaaa25806 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:50:03 +0800 Subject: [PATCH 245/278] Update README.md --- testing-modules/mockito-2/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index d7069949e4..8cd2869524 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -3,6 +3,5 @@ - [Mockito’s Java 8 Features](https://www.baeldung.com/mockito-2-java-8) - [Lazy Verification with Mockito 2](https://www.baeldung.com/mockito-2-lazy-verification) - [Mockito Strict Stubbing and The UnnecessaryStubbingException](https://www.baeldung.com/mockito-unnecessary-stubbing-exception) -- [Quick Guide to BDDMockito](https://www.baeldung.com/bdd-mockito) - [Mockito – Using Spies](https://www.baeldung.com/mockito-spy) - [Mockito and Fluent APIs](https://www.baeldung.com/mockito-fluent-apis) From 4cb7ca6472dbc9a5075c3bb1ad257c6498d23a4a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:50:53 +0800 Subject: [PATCH 246/278] Update README.md --- testing-modules/mockito-2/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index 8cd2869524..064366dfd5 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -3,5 +3,4 @@ - [Mockito’s Java 8 Features](https://www.baeldung.com/mockito-2-java-8) - [Lazy Verification with Mockito 2](https://www.baeldung.com/mockito-2-lazy-verification) - [Mockito Strict Stubbing and The UnnecessaryStubbingException](https://www.baeldung.com/mockito-unnecessary-stubbing-exception) -- [Mockito – Using Spies](https://www.baeldung.com/mockito-spy) - [Mockito and Fluent APIs](https://www.baeldung.com/mockito-fluent-apis) From 89b01e2908f5671d3da370ef912d00481cb8b052 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:53:56 +0800 Subject: [PATCH 247/278] Update README.md --- spring-boot-modules/spring-boot-custom-starter/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-custom-starter/README.md b/spring-boot-modules/spring-boot-custom-starter/README.md index d74dc222d5..667be7ca40 100644 --- a/spring-boot-modules/spring-boot-custom-starter/README.md +++ b/spring-boot-modules/spring-boot-custom-starter/README.md @@ -1,6 +1,6 @@ ## Spring Boot Custom Starter -This module contains articles about writing [Spring Boot Starters](https://www.baeldung.com/spring-boot-starters). +This module contains articles about writing Spring Boot Starters. ### Relevant Articles: - [Creating a Custom Starter with Spring Boot](https://www.baeldung.com/spring-boot-custom-starter) From b7a00cb1270db6c2c820966bacadae6370358af1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:55:39 +0800 Subject: [PATCH 248/278] Update README.md --- core-java-modules/core-java-lang-oop-2/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/core-java-modules/core-java-lang-oop-2/README.md b/core-java-modules/core-java-lang-oop-2/README.md index 035d464c50..c48a3f5cd9 100644 --- a/core-java-modules/core-java-lang-oop-2/README.md +++ b/core-java-modules/core-java-lang-oop-2/README.md @@ -12,7 +12,6 @@ This module contains articles about Object-oriented programming (OOP) in Java - [Immutable Objects in Java](https://www.baeldung.com/java-immutable-object) - [Inheritance and Composition (Is-a vs Has-a relationship) in Java](https://www.baeldung.com/java-inheritance-composition) - [A Guide to Constructors in Java](https://www.baeldung.com/java-constructors) -- [Composition, Aggregation, and Association in Java](https://www.baeldung.com/java-composition-aggregation-association) - [Static and Default Methods in Interfaces in Java](https://www.baeldung.com/java-static-default-methods) - [Java Copy Constructor](https://www.baeldung.com/java-copy-constructor) - [Abstract Classes in Java](https://www.baeldung.com/java-abstract-class) From 53098cb731ea0d3abcfd9ee65ac7d08ad942140f Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:57:01 +0800 Subject: [PATCH 249/278] Update README.md --- spring-all/README.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/spring-all/README.md b/spring-all/README.md index d71b8569cf..9ad78aa1ee 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -1,7 +1,3 @@ ## Spring All This module contains articles about Spring - -### Relevant Articles: - -- [The @Scheduled Annotation in Spring](https://www.baeldung.com/spring-scheduled-tasks) From 102d8ee3a3a87dc259282697e99b81b8ee319be1 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:58:04 +0800 Subject: [PATCH 250/278] Delete README.md --- .../data-jpa-application/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/README.md diff --git a/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/README.md b/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/README.md deleted file mode 100644 index 443ec07183..0000000000 --- a/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-application/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles - -- [Unable to Find @SpringBootConfiguration with @DataJpaTest](https://www.baeldung.com/spring-boot-unable-to-find-springbootconfiguration-with-datajpatest) From 27f4e9032f60773403d8f4256ead87f7e3e6cf44 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:59:48 +0800 Subject: [PATCH 251/278] Update README.md --- java-math-2/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/java-math-2/README.md b/java-math-2/README.md index ca809e8623..7c459cc576 100644 --- a/java-math-2/README.md +++ b/java-math-2/README.md @@ -1,8 +1,3 @@ ## Java Math This module contains articles about math in Java. - -### Relevant articles: - -- [Basic Calculator in Java](https://www.baeldung.com/basic-calculator-in-java) -- More articles: [[<-- prev]](/../java-math) From f0373c1fbb5c17bf0d431389db24b8a6f4491da2 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 19:01:02 +0800 Subject: [PATCH 252/278] Delete README.md --- .../spring-boot-config-jpa-error/data-jpa-library/README.md | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/README.md diff --git a/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/README.md b/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/README.md deleted file mode 100644 index 4e852f8a90..0000000000 --- a/spring-boot-modules/spring-boot-config-jpa-error/data-jpa-library/README.md +++ /dev/null @@ -1,3 +0,0 @@ -### Relevant Articles: - -- [Unable to Find @SpringBootConfiguration with @DataJpaTest](https://www.baeldung.com/spring-boot-unable-to-find-springbootconfiguration-with-datajpatest) From f145d644c9d787a1a4b90c467b73383e818a230c Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Mon, 23 Mar 2020 19:04:46 +0800 Subject: [PATCH 253/278] Update README.md --- .../spring-security-sso/spring-security-sso-kerberos/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md index 0227d9ac70..3aa092edb8 100644 --- a/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md +++ b/spring-security-modules/spring-security-sso/spring-security-sso-kerberos/README.md @@ -1,4 +1,3 @@ ## Relevant articles: -- [Introduction to SPNEGO/Kerberos Authentication in Spring](https://www.baeldung.com/spring-security-kerberos) - [Spring Security Kerberos Integration](https://www.baeldung.com/spring-security-kerberos-integration) From abd46c4349f07b36e279b7fa6fa310ac1ea52a17 Mon Sep 17 00:00:00 2001 From: Amit Pandey Date: Mon, 23 Mar 2020 19:58:34 +0530 Subject: [PATCH 254/278] fix integration test cases (#8727) * fix integration test cases * fix integration test cases * used dynamic port in the integration test cases --- spring-5-reactive-client/pom.xml | 4 +- .../reactive/ReactiveIntegrationTest.java | 48 +++++++++++++++---- .../simultaneous/ClientIntegrationTest.java | 9 ++-- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/spring-5-reactive-client/pom.xml b/spring-5-reactive-client/pom.xml index e3c41f8b84..cc728398f3 100644 --- a/spring-5-reactive-client/pom.xml +++ b/spring-5-reactive-client/pom.xml @@ -92,8 +92,8 @@ com.github.tomakehurst - wiremock - 2.24.1 + wiremock-standalone + 2.26.0 test diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java index 394ff42e5f..1d2197a381 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java @@ -1,37 +1,67 @@ package com.baeldung.reactive; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; import com.baeldung.reactive.model.Foo; +import com.github.tomakehurst.wiremock.WireMockServer; import reactor.core.publisher.Mono; +@RunWith(SpringRunner.class) @SpringBootTest public class ReactiveIntegrationTest { private WebClient client; - - @BeforeEach - public void before() { - client = WebClient.create("http://localhost:8080"); + private int singleRequestTime = 1000; + private WireMockServer wireMockServer; + + @Before + public void setup() { + wireMockServer = new WireMockServer(wireMockConfig().dynamicPort()); + wireMockServer.start(); + configureFor("localhost", wireMockServer.port()); + client = WebClient.create("http://localhost:" + wireMockServer.port()); } - // + @After + public void tearDown() { + wireMockServer.stop(); + } @Test public void whenMonoReactiveEndpointIsConsumed_thenCorrectOutput() { - final Mono fooMono = client.get().uri("/foos/123").exchange().log(); + stubFor(get(urlEqualTo("/foo/123")).willReturn(aResponse().withFixedDelay(singleRequestTime) + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody("{\"id\":123, \"name\":\"foo\"}"))); + + final Mono fooMono = client.get().uri("/foo/123").exchange().log(); System.out.println(fooMono.subscribe()); } @Test public void whenFluxReactiveEndpointIsConsumed_thenCorrectOutput() throws InterruptedException { - client.get().uri("/foos") + stubFor(get(urlEqualTo("/foo")).willReturn(aResponse().withFixedDelay(singleRequestTime) + .withStatus(200) + .withHeader("Content-Type", "application/json") + .withBody("{\"id\":1, \"name\":\"foo\"}"))); + + client.get().uri("/foo") .retrieve() .bodyToFlux(Foo.class).log() .subscribe(System.out::println); diff --git a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java index d74a64d9c9..43454daf17 100644 --- a/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java +++ b/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java @@ -5,6 +5,7 @@ import org.junit.Before; import org.junit.After; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringRunner; import com.github.tomakehurst.wiremock.WireMockServer; @@ -19,15 +20,19 @@ import static org.junit.Assert.assertEquals; @RunWith(SpringRunner.class) @SpringBootTest +@DirtiesContext public class ClientIntegrationTest { private WireMockServer wireMockServer; + private Client client; + @Before public void setup() { - wireMockServer = new WireMockServer(wireMockConfig().port(8089)); + wireMockServer = new WireMockServer(wireMockConfig().dynamicPort()); wireMockServer.start(); configureFor("localhost", wireMockServer.port()); + client = new Client("http://localhost:" + wireMockServer.port()); } @After @@ -52,8 +57,6 @@ public class ClientIntegrationTest { .boxed() .collect(Collectors.toList()); - Client client = new Client("http://localhost:8089"); - // Act long start = System.currentTimeMillis(); List users = client.fetchUsers(userIds) From 1062b4fef65b2d6d54b724c4f46f0b8c36b69b6f Mon Sep 17 00:00:00 2001 From: Karsten Silz <1061209+ksilz@users.noreply.github.com> Date: Mon, 23 Mar 2020 18:17:16 +0000 Subject: [PATCH 255/278] BAEL-3911 (#8939) * Initial version of the code. * Addressed PR comment. --- .../dayofweek/DayOfWeekExtractor.java | 35 +++++++++++++ .../dayofweek/DayOfWeekExtractorUnitTest.java | 52 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 core-java-modules/core-java-date-operations-2/src/main/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractor.java create mode 100644 core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractorUnitTest.java diff --git a/core-java-modules/core-java-date-operations-2/src/main/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractor.java b/core-java-modules/core-java-date-operations-2/src/main/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractor.java new file mode 100644 index 0000000000..b027790e35 --- /dev/null +++ b/core-java-modules/core-java-date-operations-2/src/main/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractor.java @@ -0,0 +1,35 @@ +package com.baeldung.datetime.dayofweek; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.time.DayOfWeek; +import java.time.LocalDate; +import java.time.format.TextStyle; +import java.util.Calendar; +import java.util.Date; +import java.util.Locale; + +public class DayOfWeekExtractor { + + public static int getDayNumberOld(Date date) { + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + return cal.get(Calendar.DAY_OF_WEEK); + } + + public static String getDayStringOld(Date date, Locale locale ) { + DateFormat formatter = new SimpleDateFormat("EEEE", locale); + return formatter.format(date); + } + + public static int getDayNumberNew(LocalDate date) { + DayOfWeek day = date.getDayOfWeek(); + return day.getValue(); + } + + public static String getDayStringNew(LocalDate date, Locale locale ) { + DayOfWeek day = date.getDayOfWeek(); + return day.getDisplayName(TextStyle.FULL, locale); + } + +} diff --git a/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractorUnitTest.java b/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractorUnitTest.java new file mode 100644 index 0000000000..0dfd50dca2 --- /dev/null +++ b/core-java-modules/core-java-date-operations-2/src/test/java/com/baeldung/datetime/dayofweek/DayOfWeekExtractorUnitTest.java @@ -0,0 +1,52 @@ +package com.baeldung.datetime.dayofweek; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.LocalDate; +import java.util.Calendar; +import java.util.Locale; + +import org.junit.Test; + +public class DayOfWeekExtractorUnitTest { + + private DateFormat oldDateParser = new SimpleDateFormat("yyyy-MM-dd"); + + @Test + public void givenFeb29_2020_thenOldSaturdayNumber() throws ParseException { + assertThat(DayOfWeekExtractor.getDayNumberOld(oldDateParser.parse("2020-02-29")) == Calendar.SATURDAY); + } + + @Test + public void givenFeb29_2020_and_localeUS_thenOldSaturdayText() throws ParseException { + assertThat("Saturday".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.US)) ); + } + + @Test + public void givenFeb29_2020_and_localeDE_thenOldSaturdayText() throws ParseException { + assertThat("Samstag".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.GERMANY)) ); + } + + @Test + public void givenFeb29_2020_thenNewSaturdayNumber() throws ParseException { + assertThat(DayOfWeekExtractor.getDayNumberNew(LocalDate.parse("2020-02-29")) == Calendar.SATURDAY); + } + + @Test + public void givenFeb29_2020_and_localeUS_thenNewSaturdayText() throws ParseException { + assertThat("Saturday".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.US)) ); + } + + @Test + public void givenFeb29_2020_and_localeDE_thenNewSaturdayText() throws ParseException { + assertThat("Samstag".equals(DayOfWeekExtractor.getDayStringOld(oldDateParser.parse("2020-02-29"), Locale.GERMANY)) ); + } + + +} + + + From 060557608c8a11bdb31e707eedc41e91b2cf9af6 Mon Sep 17 00:00:00 2001 From: Sampada <46674082+sampada07@users.noreply.github.com> Date: Tue, 24 Mar 2020 08:37:48 +0530 Subject: [PATCH 256/278] BAEL-3883: Boruvka's minimum spanning tree, moved code to newer module (#8949) algorithms-miscellaneous-6 --- algorithms-miscellaneous-5/pom.xml | 6 -- .../algorithms/boruvka/BoruvkaMST.java | 61 -------------- .../algorithms/boruvka/DisjointSet.java | 49 ----------- .../com/baeldung/algorithms/boruvka/Edge.java | 40 --------- .../baeldung/algorithms/boruvka/Graph.java | 64 -------------- .../baeldung/algorithms/boruvka/Input.java | 65 -------------- .../com/baeldung/algorithms/boruvka/Tree.java | 63 -------------- .../algorithms/boruvka/BoruvkaUnitTest.java | 48 ----------- algorithms-miscellaneous-6/pom.xml | 12 +++ .../algorithms/boruvka/BoruvkaMST.java | 84 +++++++++++++++++++ .../algorithms/boruvka/UnionFind.java | 39 +++++++++ .../algorithms/boruvka/BoruvkaUnitTest.java | 37 ++++++++ 12 files changed, 172 insertions(+), 396 deletions(-) delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/DisjointSet.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Edge.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Graph.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Input.java delete mode 100644 algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Tree.java delete mode 100644 algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java create mode 100644 algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java create mode 100644 algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/UnionFind.java create mode 100644 algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java diff --git a/algorithms-miscellaneous-5/pom.xml b/algorithms-miscellaneous-5/pom.xml index f2db71a6da..4131e1791d 100644 --- a/algorithms-miscellaneous-5/pom.xml +++ b/algorithms-miscellaneous-5/pom.xml @@ -41,11 +41,6 @@ guava ${guava.version} - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - org.junit.platform junit-platform-commons @@ -78,7 +73,6 @@ 1.11 3.6.1 28.1-jre - 2.10.2 1.6.0 diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java deleted file mode 100644 index 0f8bc5b296..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.baeldung.algorithms.boruvka; - -public class BoruvkaMST { - - private static Tree mst = new Tree(); - private static int totalWeight; - - public BoruvkaMST(Graph graph) { - DisjointSet dSet = new DisjointSet(graph.getNodes()); - - // repeat at most log N times or until we have N-1 edges - for (int t = 1; t < graph.getNodes() && mst.getEdgeCount() < graph.getNodes() - 1; t = t + t) { - - // foreach tree in forest, find closest edge - Edge[] closestEdgeArray = new Edge[graph.getNodes()]; - for (Edge edge : graph.getAllEdges()) { - int first = edge.getFirst(); - int second = edge.getSecond(); - int firstParent = dSet.getParent(first); - int secondParent = dSet.getParent(second); - if (firstParent == secondParent) { - continue; // same tree - } - if (closestEdgeArray[firstParent] == null || edge.getWeight() < closestEdgeArray[firstParent].getWeight()) { - closestEdgeArray[firstParent] = edge; - } - if (closestEdgeArray[secondParent] == null || edge.getWeight() < closestEdgeArray[secondParent].getWeight()) { - closestEdgeArray[secondParent] = edge; - } - } - - // add newly discovered edges to MST - for (int i = 0; i < graph.getNodes(); i++) { - Edge edge = closestEdgeArray[i]; - if (edge != null) { - int first = edge.getFirst(); - int second = edge.getSecond(); - // don't add the same edge twice - if (dSet.getParent(first) != dSet.getParent(second)) { - mst.addEdge(edge); - totalWeight += edge.getWeight(); - dSet.union(first, second); - } - } - } - } - } - - public Iterable getMST() { - return mst; - } - - public int getTotalWeight() { - return totalWeight; - } - - public String toString() { - return "MST: " + mst.toString() + " | Total Weight: " + totalWeight; - } - -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/DisjointSet.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/DisjointSet.java deleted file mode 100644 index 7769686e36..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/DisjointSet.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.algorithms.boruvka; - -import java.util.Arrays; - -public class DisjointSet { - - private int[] nodeParents; - private int[] nodeRanks; - - public DisjointSet(int n) { - nodeParents = new int[n]; - nodeRanks = new int[n]; - for (int i = 0; i < n; i++) { - nodeParents[i] = i; - nodeRanks[i] = 0; - } - } - - public int getParent(int node) { - while (node != nodeParents[node]) { - node = nodeParents[node]; - } - return node; - } - - public void union(int node1, int node2) { - int node1Parent = getParent(node1); - int node2Parent = getParent(node2); - if (node1Parent == node2Parent) { - return; - } - - if (nodeRanks[node1Parent] < nodeRanks[node2Parent]) { - nodeParents[node1Parent] = node2Parent; - } - else if (nodeRanks[node1Parent] > nodeRanks[node2Parent]) { - nodeParents[node2Parent] = node1Parent; - } - else { - nodeParents[node2Parent] = node1Parent; - nodeRanks[node1Parent]++; - } - } - - public String toString() { - return "Parent: " + Arrays.toString(nodeParents) + "Rank: " + Arrays.toString(nodeRanks); - } - -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Edge.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Edge.java deleted file mode 100644 index 6ee136fc48..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Edge.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.baeldung.algorithms.boruvka; - -public class Edge { - - private final int first; - private final int second; - private final int weight; - - public Edge(int first, int second, int weight) { - this.first = first; - this.second = second; - this.weight = weight; - } - - public double getWeight() { - return weight; - } - - public int getFirst() { - return first; - } - - public int getSecond() { - return second; - } - - public int getOtherNode(int firstNode) { - int secondNode = 0; - if (firstNode == first) - secondNode = second; - else if (firstNode == second) - secondNode = first; - return secondNode; - } - - public String toString() { - return String.format("%d-%d %d", first, second, weight); - } - -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Graph.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Graph.java deleted file mode 100644 index e899007dfa..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Graph.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.algorithms.boruvka; - -import java.io.IOException; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; - -public class Graph { - - private int nodes; - private int edges; - private Tree[] trees; - - public Graph(Input jsonGraph) throws JsonParseException, JsonMappingException, IOException { - nodes = jsonGraph.getNodes(); - trees = (Tree[]) new Tree[nodes]; - for (int i = 0; i < nodes; i++) { - trees[i] = new Tree(); - } - - int edgesFromInput = jsonGraph.getEdges(); - for (int i = 0; i < edgesFromInput; i++) { - int first = jsonGraph.getEdgeList() - .get(i) - .getFirst(); - int second = jsonGraph.getEdgeList() - .get(i) - .getSecond(); - int weight = jsonGraph.getEdgeList() - .get(i) - .getWeight(); - Edge edge = new Edge(first, second, weight); - - trees[first].addEdge(edge); - trees[second].addEdge(edge); - edges++; - } - - } - - public int getNodes() { - return nodes; - } - - public int getEdges() { - return edges; - } - - public Iterable iterableTree(int i) { - return trees[i]; - } - - public Iterable getAllEdges() { - Iterable list = new Tree(); - for (int i = 0; i < nodes; i++) { - for (Edge edge : iterableTree(i)) { - if (edge.getOtherNode(i) > i) { - ((Tree) list).addEdge(edge); - } - } - } - return list; - } -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Input.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Input.java deleted file mode 100644 index b52720d5e9..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Input.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.baeldung.algorithms.boruvka; - -import java.util.List; - -public class Input { - private int nodes; - private int edges; - private List edgeList; - - public int getNodes() { - return nodes; - } - - public void setNodes(int nodes) { - this.nodes = nodes; - } - - public int getEdges() { - return edges; - } - - public void setEdges(int edges) { - this.edges = edges; - } - - public List getEdgeList() { - return edgeList; - } - - public void setEdgeList(List edgeList) { - this.edgeList = edgeList; - } - - static class E { - private int first; - private int second; - private int weight; - - public int getFirst() { - return first; - } - - public void setFirst(int first) { - this.first = first; - } - - public int getSecond() { - return second; - } - - public void setSecond(int second) { - this.second = second; - } - - public int getWeight() { - return weight; - } - - public void setWeight(int weight) { - this.weight = weight; - } - - } - -} diff --git a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Tree.java b/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Tree.java deleted file mode 100644 index cc28233e07..0000000000 --- a/algorithms-miscellaneous-5/src/main/java/com/baeldung/algorithms/boruvka/Tree.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.baeldung.algorithms.boruvka; - -import java.util.Iterator; - -public class Tree implements Iterable { - private Node root; - private int edgeCount; - - private static class Node { - private Edge edge; - private Node next; - - public String toString() { - String nextStr = next != null ? next.toString() : ""; - return edge.toString() + " | " + nextStr; - } - } - - public Tree() { - root = null; - edgeCount = 0; - } - - public int getEdgeCount() { - return edgeCount; - } - - public void addEdge(Edge edge) { - Node oldRoot = root; - root = new Node(); - root.edge = edge; - root.next = oldRoot; - edgeCount++; - } - - public String toString() { - String rootStr = root != null ? root.toString() : ""; - return "Tree: " + rootStr + "Size: " + edgeCount; - } - - public Iterator iterator() { - return new LinkedIterator(root); - } - - private class LinkedIterator implements Iterator { - private Node current; - - public LinkedIterator(Node root) { - current = root; - } - - public boolean hasNext() { - return current != null; - } - - public Edge next() { - Edge edge = current.edge; - current = current.next; - return edge; - } - } - -} diff --git a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java b/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java deleted file mode 100644 index 1d03d2d4d9..0000000000 --- a/algorithms-miscellaneous-5/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.baeldung.algorithms.boruvka; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; - -import org.junit.Before; -import org.junit.Test; - -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -public class BoruvkaUnitTest { - - private Input input; - private static String INPUT_JSON = "/input.json"; - - @Before - public void convertInputJsonToObject() throws JsonParseException, JsonMappingException, IOException { - ObjectMapper mapper = new ObjectMapper(); - StringBuilder jsonStr = new StringBuilder(); - try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(BoruvkaMST.class.getResourceAsStream(INPUT_JSON)))) { - String line; - while ((line = bufferedReader.readLine()) != null) { - jsonStr.append(line) - .append("\n"); - } - } - - input = mapper.readValue(jsonStr.toString(), Input.class); - - } - - @Test - public void givenInputGraph_whenBoruvkaPerformed_thenMinimumSpanningTree() throws JsonParseException, JsonMappingException, IOException { - Graph graph = new Graph(input); - BoruvkaMST boruvkaMST = new BoruvkaMST(graph); - - Tree mst = (Tree) boruvkaMST.getMST(); - - assertEquals(30, boruvkaMST.getTotalWeight()); - assertEquals(4, mst.getEdgeCount()); - } - -} diff --git a/algorithms-miscellaneous-6/pom.xml b/algorithms-miscellaneous-6/pom.xml index 5daa000ea3..fda9cf10f9 100644 --- a/algorithms-miscellaneous-6/pom.xml +++ b/algorithms-miscellaneous-6/pom.xml @@ -11,5 +11,17 @@ parent-modules 1.0.0-SNAPSHOT + + + + com.google.guava + guava + ${guava.version} + + + + + 28.1-jre + diff --git a/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java new file mode 100644 index 0000000000..7dae21648c --- /dev/null +++ b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/BoruvkaMST.java @@ -0,0 +1,84 @@ +package com.baeldung.algorithms.boruvka; + +import com.google.common.graph.EndpointPair; +import com.google.common.graph.MutableValueGraph; +import com.google.common.graph.ValueGraphBuilder; + +public class BoruvkaMST { + + private static MutableValueGraph mst = ValueGraphBuilder.undirected() + .build(); + private static int totalWeight; + + public BoruvkaMST(MutableValueGraph graph) { + + int size = graph.nodes().size(); + + UnionFind uf = new UnionFind(size); + + // repeat at most log N times or until we have N-1 edges + for (int t = 1; t < size && mst.edges().size() < size - 1; t = t + t) { + + EndpointPair[] closestEdgeArray = new EndpointPair[size]; + + // foreach tree in graph, find closest edge + for (EndpointPair edge : graph.edges()) { + int u = edge.nodeU(); + int v = edge.nodeV(); + int uParent = uf.find(u); + int vParent = uf.find(v); + if (uParent == vParent) { + continue; // same tree + } + + int weight = graph.edgeValueOrDefault(u, v, 0); + + if (closestEdgeArray[uParent] == null) { + closestEdgeArray[uParent] = edge; + } + if (closestEdgeArray[vParent] == null) { + closestEdgeArray[vParent] = edge; + } + + int uParentWeight = graph.edgeValueOrDefault(closestEdgeArray[uParent].nodeU(), closestEdgeArray[uParent].nodeV(), 0); + int vParentWeight = graph.edgeValueOrDefault(closestEdgeArray[vParent].nodeU(), closestEdgeArray[vParent].nodeV(), 0); + + if (weight < uParentWeight) { + closestEdgeArray[uParent] = edge; + } + if (weight < vParentWeight) { + closestEdgeArray[vParent] = edge; + } + } + + // add newly discovered edges to MST + for (int i = 0; i < size; i++) { + EndpointPair edge = closestEdgeArray[i]; + if (edge != null) { + int u = edge.nodeU(); + int v = edge.nodeV(); + int weight = graph.edgeValueOrDefault(u, v, 0); + // don't add the same edge twice + if (uf.find(u) != uf.find(v)) { + mst.putEdgeValue(u, v, weight); + totalWeight += weight; + uf.union(u, v); + } + } + } + } + } + + public MutableValueGraph getMST() { + return mst; + } + + public int getTotalWeight() { + return totalWeight; + } + + public String toString() { + return "MST: " + mst.toString() + " | Total Weight: " + totalWeight; + } + +} diff --git a/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/UnionFind.java b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/UnionFind.java new file mode 100644 index 0000000000..33c9c4a4c8 --- /dev/null +++ b/algorithms-miscellaneous-6/src/main/java/com/baeldung/algorithms/boruvka/UnionFind.java @@ -0,0 +1,39 @@ +package com.baeldung.algorithms.boruvka; + +public class UnionFind { + private int[] parents; + private int[] ranks; + + public UnionFind(int n) { + parents = new int[n]; + ranks = new int[n]; + for (int i = 0; i < n; i++) { + parents[i] = i; + ranks[i] = 0; + } + } + + public int find(int u) { + while (u != parents[u]) { + u = parents[u]; + } + return u; + } + + public void union(int u, int v) { + int uParent = find(u); + int vParent = find(v); + if (uParent == vParent) { + return; + } + + if (ranks[uParent] < ranks[vParent]) { + parents[uParent] = vParent; + } else if (ranks[uParent] > ranks[vParent]) { + parents[vParent] = uParent; + } else { + parents[vParent] = uParent; + ranks[uParent]++; + } + } +} diff --git a/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java b/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java new file mode 100644 index 0000000000..e61e1e668d --- /dev/null +++ b/algorithms-miscellaneous-6/src/test/java/com/baeldung/algorithms/boruvka/BoruvkaUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.algorithms.boruvka; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +import com.google.common.graph.MutableValueGraph; +import com.google.common.graph.ValueGraphBuilder; + +public class BoruvkaUnitTest { + + private MutableValueGraph graph; + + @Before + public void setup() { + graph = ValueGraphBuilder.undirected() + .build(); + graph.putEdgeValue(0, 1, 8); + graph.putEdgeValue(0, 2, 5); + graph.putEdgeValue(1, 2, 9); + graph.putEdgeValue(1, 3, 11); + graph.putEdgeValue(2, 3, 15); + graph.putEdgeValue(2, 4, 10); + graph.putEdgeValue(3, 4, 7); + } + + @Test + public void givenInputGraph_whenBoruvkaPerformed_thenMinimumSpanningTree() { + BoruvkaMST boruvkaMST = new BoruvkaMST(graph); + MutableValueGraph mst = boruvkaMST.getMST(); + + assertEquals(30, boruvkaMST.getTotalWeight()); + assertEquals(4, mst.edges().size()); + } + +} From ff87d3ecc246a9c8cc3eed792dad0ce44338e54b Mon Sep 17 00:00:00 2001 From: Gang Wu Date: Mon, 23 Mar 2020 22:00:55 -0600 Subject: [PATCH 257/278] BAEL-3069 Remove final keyword, add more empty lines for readability. --- .../src/main/java/com/baeldung/jdbc/EmployeeDAO.java | 2 +- .../src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java b/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java index a7adb7933a..b5bf9452ed 100644 --- a/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java +++ b/persistence-modules/spring-persistence-simple-2/src/main/java/com/baeldung/jdbc/EmployeeDAO.java @@ -9,7 +9,7 @@ import org.springframework.stereotype.Repository; public class EmployeeDAO { private JdbcTemplate jdbcTemplate; - public void setDataSource(final DataSource dataSource) { + public void setDataSource(DataSource dataSource) { jdbcTemplate = new JdbcTemplate(dataSource); } diff --git a/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java b/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java index a64ba9b2f0..71e8fb4263 100644 --- a/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java +++ b/persistence-modules/spring-persistence-simple-2/src/test/java/com/baeldung/jdbc/EmployeeDAOUnitTest.java @@ -27,10 +27,12 @@ public class EmployeeDAOUnitTest { ReflectionTestUtils.setField(employeeDAO, "jdbcTemplate", jdbcTemplate); Mockito.when(jdbcTemplate.queryForObject("SELECT COUNT(*) FROM EMPLOYEE", Integer.class)) .thenReturn(4); + assertEquals(4, employeeDAO.getCountOfEmployees()); Mockito.when(jdbcTemplate.queryForObject(Mockito.anyString(), Mockito.eq(Integer.class))) .thenReturn(3); + assertEquals(3, employeeDAO.getCountOfEmployees()); } @@ -40,8 +42,10 @@ public class EmployeeDAOUnitTest { .addScript("classpath:jdbc/schema.sql") .addScript("classpath:jdbc/test-data.sql") .build(); + EmployeeDAO employeeDAO = new EmployeeDAO(); employeeDAO.setDataSource(dataSource); + assertEquals(4, employeeDAO.getCountOfEmployees()); } } From 147a3fc2d5f8e05e98a288e9fad4d5625368b61a Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 24 Mar 2020 14:49:36 +0800 Subject: [PATCH 258/278] Update README.md --- logging-modules/log-mdc/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/logging-modules/log-mdc/README.md b/logging-modules/log-mdc/README.md index 3841224824..b676d3ba76 100644 --- a/logging-modules/log-mdc/README.md +++ b/logging-modules/log-mdc/README.md @@ -1,8 +1,8 @@ ### Relevant Articles: - TBD -- [Improved Java Logging with Mapped Diagnostic Context (MDC)](http://www.baeldung.com/mdc-in-log4j-2-logback) -- [Java Logging with Nested Diagnostic Context (NDC)](http://www.baeldung.com/java-logging-ndc-log4j) -- [Drools Using Rules from Excel Files](http://www.baeldung.com/drools-excel) +- [Improved Java Logging with Mapped Diagnostic Context (MDC)](https://www.baeldung.com/mdc-in-log4j-2-logback) +- [Java Logging with Nested Diagnostic Context (NDC)](https:www.baeldung.com/java-logging-ndc-log4j) +- [Drools Using Rules from Excel Files](https://www.baeldung.com/drools-excel) ### References From c3976ffa90911b02656325114eaaabfb6912dd54 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 24 Mar 2020 14:53:24 +0800 Subject: [PATCH 259/278] Update README.MD --- spring-boot-modules/spring-boot/README.MD | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index b15ab7dbe5..4f731f2627 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -26,3 +26,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) - [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) - [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) +- [Running Setup Data on Startup in Spring](https://www.baeldung.com/running-setup-logic-on-startup-in-spring) From 470575f3ff923831f49abe769223c8b159713ee7 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Tue, 24 Mar 2020 15:05:36 +0800 Subject: [PATCH 260/278] Update README.md --- spring-reactor/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-reactor/README.md b/spring-reactor/README.md index b92478f6fb..f8cf2898f1 100644 --- a/spring-reactor/README.md +++ b/spring-reactor/README.md @@ -4,4 +4,4 @@ This module contains articles about Spring Reactor ## Relevant articles: -- [Introduction to Spring Reactor](https://www.baeldung.com/spring-reactor) +- [Introduction to Project Reactor Bus](https://www.baeldung.com/reactor-bus) From 361615f48b960d83b121f83ae6b0afca538054bc Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:45:07 +0800 Subject: [PATCH 261/278] Update README.md --- spring-mvc-basics-3/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-basics-3/README.md b/spring-mvc-basics-3/README.md index 180cee498b..074c60152c 100644 --- a/spring-mvc-basics-3/README.md +++ b/spring-mvc-basics-3/README.md @@ -12,4 +12,5 @@ This module contains articles about Spring MVC - [Excluding URLs for a Filter in a Spring Web Application](https://www.baeldung.com/spring-exclude-filter) - [Guide to Flash Attributes in a Spring Web Application](https://www.baeldung.com/spring-web-flash-attributes) - [Handling URL Encoded Form Data in Spring REST](https://www.baeldung.com/spring-url-encoded-form-data) +- [Reading HttpServletRequest Multiple Times in Spring](https://www.baeldung.com/spring-reading-httpservletrequest-multiple-times) - More articles: [[<-- prev]](/spring-mvc-basics-2)[[more -->]](/spring-mvc-basics-4) From 6420d62d09f7f5120b4bd2c11668363955256e65 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:48:12 +0800 Subject: [PATCH 262/278] Update README.md --- algorithms-miscellaneous-5/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/algorithms-miscellaneous-5/README.md b/algorithms-miscellaneous-5/README.md index 87a328e446..6e0de7d64e 100644 --- a/algorithms-miscellaneous-5/README.md +++ b/algorithms-miscellaneous-5/README.md @@ -19,4 +19,5 @@ This module contains articles about algorithms. Some classes of algorithms, e.g. - [Balanced Brackets Algorithm in Java](https://www.baeldung.com/java-balanced-brackets-algorithm) - [Efficiently Merge Sorted Java Sequences](https://www.baeldung.com/java-merge-sorted-sequences) - [Introduction to Greedy Algorithms with Java](https://www.baeldung.com/java-greedy-algorithms) +- [The Caesar Cipher in Java](https://www.baeldung.com/java-caesar-cipher) - More articles: [[<-- prev]](/../algorithms-miscellaneous-4) From f5afce0b95de6621dce734c4a849567a9916a900 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Wed, 25 Mar 2020 10:50:09 +0800 Subject: [PATCH 263/278] Update README.md --- spring-scheduling/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-scheduling/README.md b/spring-scheduling/README.md index bf34fb60de..4ee306c0e0 100644 --- a/spring-scheduling/README.md +++ b/spring-scheduling/README.md @@ -4,4 +4,4 @@ - [Guide to Spring Retry](https://www.baeldung.com/spring-retry) - [How To Do @Async in Spring](https://www.baeldung.com/spring-async) - [Conditionally Enable Scheduled Jobs in Spring](https://www.baeldung.com/spring-scheduled-enabled-conditionally) - +- [Remote Debugging with IntelliJ IDEA](https://www.baeldung.com/intellij-remote-debugging) From 50c9b1c75e20598078473f83e8c92755dbd27eb8 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 25 Mar 2020 12:07:06 +0530 Subject: [PATCH 264/278] JAVA-626: Updated Next and Prev links in README --- core-java-modules/core-java-lang-math-2/README.md | 2 +- core-java-modules/core-java-lang-math/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-lang-math-2/README.md b/core-java-modules/core-java-lang-math-2/README.md index 0e0f1991c4..9382414245 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -13,4 +13,4 @@ - [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) - [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging) - [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication) -- More articles: [[<-- prev]](/../core-java-lang-math) +- More articles: [[<-- Prev]](/../core-java-lang-math) diff --git a/core-java-modules/core-java-lang-math/README.md b/core-java-modules/core-java-lang-math/README.md index 8a822d75fd..834799d6c6 100644 --- a/core-java-modules/core-java-lang-math/README.md +++ b/core-java-modules/core-java-lang-math/README.md @@ -13,4 +13,4 @@ - [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms) - [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor) - [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage) -- More articles: [[<-- next]](/../core-java-lang-math-2) +- More articles: [[Next -->]](/../core-java-lang-math-2) From 532d2a32eef22eb85e6c1cb7d03c303ff4361b58 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 25 Mar 2020 12:10:44 +0530 Subject: [PATCH 265/278] JAVA-626: Updated Next and Prev links in README --- core-java-modules/core-java-lang-math-2/README.md | 2 +- core-java-modules/core-java-lang-math/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core-java-modules/core-java-lang-math-2/README.md b/core-java-modules/core-java-lang-math-2/README.md index 9382414245..09039f6ed0 100644 --- a/core-java-modules/core-java-lang-math-2/README.md +++ b/core-java-modules/core-java-lang-math-2/README.md @@ -13,4 +13,4 @@ - [Convert Latitude and Longitude to a 2D Point in Java](https://www.baeldung.com/java-convert-latitude-longitude) - [Debugging with Eclipse](https://www.baeldung.com/eclipse-debugging) - [Matrix Multiplication in Java](https://www.baeldung.com/java-matrix-multiplication) -- More articles: [[<-- Prev]](/../core-java-lang-math) +- More articles: [[<-- Prev]](/core-java-modules/core-java-lang-math) diff --git a/core-java-modules/core-java-lang-math/README.md b/core-java-modules/core-java-lang-math/README.md index 834799d6c6..9295349f82 100644 --- a/core-java-modules/core-java-lang-math/README.md +++ b/core-java-modules/core-java-lang-math/README.md @@ -13,4 +13,4 @@ - [Calculating Logarithms in Java](https://www.baeldung.com/java-logarithms) - [Finding Greatest Common Divisor in Java](https://www.baeldung.com/java-greatest-common-divisor) - [Calculate Percentage in Java](https://www.baeldung.com/java-calculate-percentage) -- More articles: [[Next -->]](/../core-java-lang-math-2) +- More articles: [[Next -->]](/core-java-modules/core-java-lang-math-2) From d2dacc22ba59c48bd3e7d2524d440d694cfb663e Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 25 Mar 2020 23:06:05 +0530 Subject: [PATCH 266/278] JAVA-625: Moved 3 articles from java-numbers-2 to java-numbers-3 --- .../main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java | 2 -- .../main/java/com/baeldung/numbersinrange/NumbersInARange.java | 0 .../java/com/baeldung/numbersinrange/RandomNumbersInARange.java | 0 .../com/baeldung/fibonacci/FibonacciSeriesUtilsUnitTest.java | 0 .../com/baeldung/numbersinrange/NumbersInARangeUnitTest.java | 0 .../baeldung/numbersinrange/RandomNumbersInARangeUnitTest.java | 0 6 files changed, 2 deletions(-) rename {java-numbers-2 => java-numbers-3}/src/main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java (96%) rename {java-numbers-2 => java-numbers-3}/src/main/java/com/baeldung/numbersinrange/NumbersInARange.java (100%) rename {java-numbers-2 => java-numbers-3}/src/main/java/com/baeldung/numbersinrange/RandomNumbersInARange.java (100%) rename {java-numbers-2 => java-numbers-3}/src/test/java/com/baeldung/fibonacci/FibonacciSeriesUtilsUnitTest.java (100%) rename {java-numbers-2 => java-numbers-3}/src/test/java/com/baeldung/numbersinrange/NumbersInARangeUnitTest.java (100%) rename {java-numbers-2 => java-numbers-3}/src/test/java/com/baeldung/numbersinrange/RandomNumbersInARangeUnitTest.java (100%) diff --git a/java-numbers-2/src/main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java b/java-numbers-3/src/main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java similarity index 96% rename from java-numbers-2/src/main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java rename to java-numbers-3/src/main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java index 943fcffa56..616f3ab28f 100644 --- a/java-numbers-2/src/main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java +++ b/java-numbers-3/src/main/java/com/baeldung/fibonacci/FibonacciSeriesUtils.java @@ -1,7 +1,5 @@ package com.baeldung.fibonacci; -import static java.lang.Math.pow; - public class FibonacciSeriesUtils { public static int nthFibonacciTermRecursiveMethod(int n) { diff --git a/java-numbers-2/src/main/java/com/baeldung/numbersinrange/NumbersInARange.java b/java-numbers-3/src/main/java/com/baeldung/numbersinrange/NumbersInARange.java similarity index 100% rename from java-numbers-2/src/main/java/com/baeldung/numbersinrange/NumbersInARange.java rename to java-numbers-3/src/main/java/com/baeldung/numbersinrange/NumbersInARange.java diff --git a/java-numbers-2/src/main/java/com/baeldung/numbersinrange/RandomNumbersInARange.java b/java-numbers-3/src/main/java/com/baeldung/numbersinrange/RandomNumbersInARange.java similarity index 100% rename from java-numbers-2/src/main/java/com/baeldung/numbersinrange/RandomNumbersInARange.java rename to java-numbers-3/src/main/java/com/baeldung/numbersinrange/RandomNumbersInARange.java diff --git a/java-numbers-2/src/test/java/com/baeldung/fibonacci/FibonacciSeriesUtilsUnitTest.java b/java-numbers-3/src/test/java/com/baeldung/fibonacci/FibonacciSeriesUtilsUnitTest.java similarity index 100% rename from java-numbers-2/src/test/java/com/baeldung/fibonacci/FibonacciSeriesUtilsUnitTest.java rename to java-numbers-3/src/test/java/com/baeldung/fibonacci/FibonacciSeriesUtilsUnitTest.java diff --git a/java-numbers-2/src/test/java/com/baeldung/numbersinrange/NumbersInARangeUnitTest.java b/java-numbers-3/src/test/java/com/baeldung/numbersinrange/NumbersInARangeUnitTest.java similarity index 100% rename from java-numbers-2/src/test/java/com/baeldung/numbersinrange/NumbersInARangeUnitTest.java rename to java-numbers-3/src/test/java/com/baeldung/numbersinrange/NumbersInARangeUnitTest.java diff --git a/java-numbers-2/src/test/java/com/baeldung/numbersinrange/RandomNumbersInARangeUnitTest.java b/java-numbers-3/src/test/java/com/baeldung/numbersinrange/RandomNumbersInARangeUnitTest.java similarity index 100% rename from java-numbers-2/src/test/java/com/baeldung/numbersinrange/RandomNumbersInARangeUnitTest.java rename to java-numbers-3/src/test/java/com/baeldung/numbersinrange/RandomNumbersInARangeUnitTest.java From 529720c911fef7de6e2d551b024a431adcf74bdd Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 25 Mar 2020 23:06:33 +0530 Subject: [PATCH 267/278] JAVA-625: Updated README for both modules --- java-numbers-2/README.md | 3 --- java-numbers-3/README.md | 8 ++++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/java-numbers-2/README.md b/java-numbers-2/README.md index ba9e14965d..48f9acd32d 100644 --- a/java-numbers-2/README.md +++ b/java-numbers-2/README.md @@ -13,7 +13,4 @@ This module contains articles about numbers in Java. - [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers) - [Finding the Least Common Multiple in Java](https://www.baeldung.com/java-least-common-multiple) - [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers) -- [Generating Random Numbers in a Range in Java](https://www.baeldung.com/java-generating-random-numbers-in-range) -- [Listing Numbers Within a Range in Java](https://www.baeldung.com/java-listing-numbers-within-a-range) -- [Fibonacci Series in Java](https://www.baeldung.com/java-fibonacci) - More articles: [[<-- prev]](/../java-numbers) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index 835b8b0b54..035fc0c789 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -1,5 +1,13 @@ +## Java Number Cookbooks and Examples + +This module contains articles about numbers in Java. + ### Relevant Articles: - [Generating Random Numbers](https://www.baeldung.com/java-generating-random-numbers) - [Convert Double to Long in Java](https://www.baeldung.com/java-convert-double-long) - [Check for null Before Calling Parse in Double.parseDouble](https://www.baeldung.com/java-check-null-parse-double) +- [Generating Random Numbers in a Range in Java](https://www.baeldung.com/java-generating-random-numbers-in-range) +- [Listing Numbers Within a Range in Java](https://www.baeldung.com/java-listing-numbers-within-a-range) +- [Fibonacci Series in Java](https://www.baeldung.com/java-fibonacci) +- More articles: [[<-- prev]](/../java-numbers-2) From 525d960cf02a75ff4300eb6e4ba6bae37e75069f Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 25 Mar 2020 23:10:20 +0530 Subject: [PATCH 268/278] JAVA-625: Added next link to second module --- java-numbers-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-numbers-2/README.md b/java-numbers-2/README.md index 48f9acd32d..fc852aab19 100644 --- a/java-numbers-2/README.md +++ b/java-numbers-2/README.md @@ -13,4 +13,4 @@ This module contains articles about numbers in Java. - [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers) - [Finding the Least Common Multiple in Java](https://www.baeldung.com/java-least-common-multiple) - [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers) -- More articles: [[<-- prev]](/../java-numbers) +- More articles: [[<-- prev]](/../java-numbers) [[next -->]](/../java-numbers-3) From 65dd613fb8c48d1d7e7244e6fb39d4c4353c8d70 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 25 Mar 2020 23:13:19 +0530 Subject: [PATCH 269/278] JAVA-625: Updated README links --- java-numbers-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-numbers-2/README.md b/java-numbers-2/README.md index fc852aab19..1d996e32cc 100644 --- a/java-numbers-2/README.md +++ b/java-numbers-2/README.md @@ -13,4 +13,4 @@ This module contains articles about numbers in Java. - [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers) - [Finding the Least Common Multiple in Java](https://www.baeldung.com/java-least-common-multiple) - [Binary Numbers in Java](https://www.baeldung.com/java-binary-numbers) -- More articles: [[<-- prev]](/../java-numbers) [[next -->]](/../java-numbers-3) +- More articles: [[<-- prev]](/java-numbers) [[next -->]](/java-numbers-3) From 9f609d4d84abc8cd68911c96ecdfdb7779dbe701 Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Wed, 25 Mar 2020 23:15:01 +0530 Subject: [PATCH 270/278] JAVA-625: Updated README Prev link --- java-numbers-3/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java-numbers-3/README.md b/java-numbers-3/README.md index 035fc0c789..598acfb927 100644 --- a/java-numbers-3/README.md +++ b/java-numbers-3/README.md @@ -10,4 +10,4 @@ This module contains articles about numbers in Java. - [Generating Random Numbers in a Range in Java](https://www.baeldung.com/java-generating-random-numbers-in-range) - [Listing Numbers Within a Range in Java](https://www.baeldung.com/java-listing-numbers-within-a-range) - [Fibonacci Series in Java](https://www.baeldung.com/java-fibonacci) -- More articles: [[<-- prev]](/../java-numbers-2) +- More articles: [[<-- prev]](/java-numbers-2) From c5ba081f7c1ca22380f69303722802d8e140488a Mon Sep 17 00:00:00 2001 From: Yavuz Tas <12643010+yavuztas@users.noreply.github.com> Date: Thu, 26 Mar 2020 04:23:14 +0100 Subject: [PATCH 271/278] sample codes for article BAEL-3581 (#8942) --- persistence-modules/hibernate-jpa/pom.xml | 8 +- .../entitymanager/getreference/Game.java | 38 ++++ .../entitymanager/getreference/Player.java | 50 +++++ .../src/main/resources/META-INF/create-db.sql | 3 + .../src/main/resources/META-INF/data.sql | 5 + .../src/main/resources/META-INF/drop-db.sql | 2 + .../main/resources/META-INF/persistence.xml | 86 +++++++- .../GetReferenceH2IntegrationTest.java | 194 ++++++++++++++++++ .../GetReferenceMySQLManualTest.java | 185 +++++++++++++++++ .../GetReferencePostgreSQLManualTest.java | 185 +++++++++++++++++ 10 files changed, 754 insertions(+), 2 deletions(-) create mode 100644 persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Game.java create mode 100644 persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Player.java create mode 100644 persistence-modules/hibernate-jpa/src/main/resources/META-INF/create-db.sql create mode 100644 persistence-modules/hibernate-jpa/src/main/resources/META-INF/data.sql create mode 100644 persistence-modules/hibernate-jpa/src/main/resources/META-INF/drop-db.sql create mode 100644 persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceH2IntegrationTest.java create mode 100644 persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceMySQLManualTest.java create mode 100644 persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferencePostgreSQLManualTest.java diff --git a/persistence-modules/hibernate-jpa/pom.xml b/persistence-modules/hibernate-jpa/pom.xml index 67f40d5017..07b1ee1c51 100644 --- a/persistence-modules/hibernate-jpa/pom.xml +++ b/persistence-modules/hibernate-jpa/pom.xml @@ -81,11 +81,17 @@ jmh-generator-annprocess ${openjdk-jmh.version} + + org.postgresql + postgresql + ${postgresql.version} + 5.3.7.Final - 6.0.6 + 8.0.13 + 42.2.11 2.2.3 3.8.0 1.21 diff --git a/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Game.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Game.java new file mode 100644 index 0000000000..1de8de0327 --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Game.java @@ -0,0 +1,38 @@ +package com.baeldung.hibernate.entitymanager.getreference; + +import javax.persistence.Entity; +import javax.persistence.Id; + +@Entity +public class Game { + + @Id + private Long id; + + private String name; + + public Game() { + } + + public Game(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Player.java b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Player.java new file mode 100644 index 0000000000..459a3a00ad --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/main/java/com/baeldung/hibernate/entitymanager/getreference/Player.java @@ -0,0 +1,50 @@ +package com.baeldung.hibernate.entitymanager.getreference; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Player { + + @Id + private Long id; + + private String name; + + @ManyToOne + private Game game; + + public Player() { + } + + public Player(Long id, String name) { + this.id = id; + this.name = name; + } + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Game getGame() { + return game; + } + + public void setGame(Game game) { + this.game = game; + } + +} diff --git a/persistence-modules/hibernate-jpa/src/main/resources/META-INF/create-db.sql b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/create-db.sql new file mode 100644 index 0000000000..7074b603f6 --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/create-db.sql @@ -0,0 +1,3 @@ +create table Game (id bigint not null, name varchar(255), primary key (id)); +create table Player (id bigint not null, name varchar(255), game_id bigint, primary key (id)); +alter table Player add constraint FKohr86afuapoujklti79wo27aa foreign key (game_id) references Game(id); \ No newline at end of file diff --git a/persistence-modules/hibernate-jpa/src/main/resources/META-INF/data.sql b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/data.sql new file mode 100644 index 0000000000..1e83082801 --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/data.sql @@ -0,0 +1,5 @@ +insert into Game (id, name) values (1, 'Game 1'); +insert into Game (id, name) values (2, 'Game 2'); +insert into Player (game_id, name, id) values (null, 'Player 1', 1); +insert into Player (game_id, name, id) values (null, 'Player 2', 2); +insert into Player (game_id, name, id) values (null, 'Player 3', 3); \ No newline at end of file diff --git a/persistence-modules/hibernate-jpa/src/main/resources/META-INF/drop-db.sql b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/drop-db.sql new file mode 100644 index 0000000000..275324fcae --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/drop-db.sql @@ -0,0 +1,2 @@ +drop table if exists Player; +drop table if exists Game; \ No newline at end of file diff --git a/persistence-modules/hibernate-jpa/src/main/resources/META-INF/persistence.xml b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/persistence.xml index 4dfade1af3..c2d5bf59ab 100644 --- a/persistence-modules/hibernate-jpa/src/main/resources/META-INF/persistence.xml +++ b/persistence-modules/hibernate-jpa/src/main/resources/META-INF/persistence.xml @@ -5,7 +5,7 @@ version="2.0"> Hibernate EntityManager Demo - com.baeldung.hibernate.pojo.Movie + com.baeldung.hibernate.pojo.Movie true @@ -16,4 +16,88 @@ + + + EntityManager getReference persistence unit + com.baeldung.hibernate.entitymanager.getreference.Game + com.baeldung.hibernate.entitymanager.getreference.Player + true + + + + + + + + + + + + + + + + + + + EntityManager getReference persistence unit + com.baeldung.hibernate.entitymanager.getreference.Game + com.baeldung.hibernate.entitymanager.getreference.Player + true + + + + + + + + + + + + + + + + + + + + + + + + + EntityManager getReference persistence unit + com.baeldung.hibernate.entitymanager.getreference.Game + com.baeldung.hibernate.entitymanager.getreference.Player + true + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceH2IntegrationTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceH2IntegrationTest.java new file mode 100644 index 0000000000..e8e6aeed7c --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceH2IntegrationTest.java @@ -0,0 +1,194 @@ +package com.baeldung.hibernate.entitymanager.getreference; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import org.junit.jupiter.api.*; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class GetReferenceH2IntegrationTest { + + private static EntityManagerFactory entityManagerFactory; + private static EntityManager entityManager; + + private static final PrintStream SystemOut = System.out; + private static OutputStream output; + + @BeforeAll + public static void setup() { + // close some specific loggers so that we can clearly see Hibernate: SQL queries + ((Logger) LoggerFactory.getLogger("org.hibernate.SQL")).setLevel(Level.OFF); + ((Logger) LoggerFactory.getLogger("org.hibernate.type.descriptor.sql")).setLevel(Level.OFF); + ((Logger) LoggerFactory.getLogger("org.hibernate.stat")).setLevel(Level.OFF); + + entityManagerFactory = Persistence.createEntityManagerFactory("com.baeldung.hibernate.entitymanager.game_player_h2"); + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + + entityManager.persist(new Game(1L, "Game 1")); + entityManager.persist(new Game(2L, "Game 2")); + entityManager.persist(new Player(1L, "Player 1")); + entityManager.persist(new Player(2L, "Player 2")); + entityManager.persist(new Player(3L, "Player 3")); + + entityManager.getTransaction().commit(); + entityManager.clear(); + entityManager.close(); + } + + private void runInTransaction(Runnable task) { + // We create new persistence context for each test method to discard Hibernate first level cache. + // So that we can see the behavior of getReference() method in a non-cached environment. + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + task.run(); + entityManager.getTransaction().commit(); + // In any case, we use clear() and close() to make all the managed entities detached and cleared. + // So, we can be sure we test always on a clear persistence context. + entityManager.clear(); + entityManager.close(); + } + + @BeforeEach + public void beforeEach() { + // stubbing System.out printStream + output = new ByteArrayOutputStream(); + System.setOut(new PrintStream(output)); + } + + @AfterEach + public void afterEach() { + System.setOut(SystemOut); + // we print to see original output after each test method + System.out.print(output.toString()); + } + + @AfterAll + public static void tearDown() { + entityManagerFactory.close(); + } + + @Test + public void whenUsingFindMethodToUpdateGame_thenExecutesSelectForGame() { + + runInTransaction(() -> { + Game game1 = entityManager.find(Game.class, 1L); + game1.setName("Game Updated 1"); + + entityManager.persist(game1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: update Game set name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToUpdateGame_thenExecutesSelectForGame() { + + runInTransaction(() -> { + Game game1 = entityManager.getReference(Game.class, 1L); + game1.setName("Game Updated 2"); + + entityManager.persist(game1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: update Game set name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingFindMethodToDeletePlayer_thenExecutesSelectForPlayer() { + + runInTransaction(() -> { + Player player2 = entityManager.find(Player.class, 2L); + entityManager.remove(player2); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: delete from Player where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToDeletePlayer_thenExecutesSelectForPlayer() { + + runInTransaction(() -> { + Player player3 = entityManager.getReference(Player.class, 3L); + entityManager.remove(player3); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: delete from Player where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingFindMethodToUpdatePlayersGame_thenExecutesSelectForGame() { + + runInTransaction((() -> { + Game game1 = entityManager.find(Game.class, 1L); + + Player player1 = entityManager.find(Player.class, 1L); + player1.setGame(game1); + + entityManager.persist(player1); + })); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: update Player set game_id=?, name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToUpdatePlayersGame_thenDoesNotExecuteSelectForGame() { + + runInTransaction(() -> { + Game game2 = entityManager.getReference(Game.class, 2L); + + Player player1 = entityManager.find(Player.class, 1L); + player1.setGame(game2); + + entityManager.persist(player1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: update Player set game_id=?, name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + +} diff --git a/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceMySQLManualTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceMySQLManualTest.java new file mode 100644 index 0000000000..2b7c5e8119 --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferenceMySQLManualTest.java @@ -0,0 +1,185 @@ +package com.baeldung.hibernate.entitymanager.getreference; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import org.junit.jupiter.api.*; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * We need to have a running MySQL instance and a schema named "baeldung" ready in order to execute this integration test + */ +public class GetReferenceMySQLManualTest { + + private static EntityManagerFactory entityManagerFactory; + private static EntityManager entityManager; + + private static final PrintStream SystemOut = System.out; + private static OutputStream output; + + @BeforeAll + public static void setup() { + // close some specific loggers so that we can clearly see Hibernate: SQL queries + ((Logger) LoggerFactory.getLogger("org.hibernate.SQL")).setLevel(Level.OFF); + ((Logger) LoggerFactory.getLogger("org.hibernate.type.descriptor.sql")).setLevel(Level.OFF); + ((Logger) LoggerFactory.getLogger("org.hibernate.stat")).setLevel(Level.OFF); + + entityManagerFactory = Persistence.createEntityManagerFactory("com.baeldung.hibernate.entitymanager.game_player_mysql"); + } + + private void runInTransaction(Runnable task) { + // We create new persistence context for each test method to discard Hibernate first level cache. + // So that we can see the behavior of getReference() method in a non-cached environment. + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + task.run(); + entityManager.getTransaction().commit(); + // In any case, we use clear() and close() to make all the managed entities detached and cleared. + // So, we can be sure we test always on a clear persistence context. + entityManager.clear(); + entityManager.close(); + } + + @BeforeEach + public void beforeEach() { + // stubbing System.out printStream + output = new ByteArrayOutputStream(); + System.setOut(new PrintStream(output)); + } + + @AfterEach + public void afterEach() { + System.setOut(SystemOut); + // we print to see original output after each test method + System.out.print(output.toString()); + } + + @AfterAll + public static void tearDown() { + entityManagerFactory.close(); + } + + @Test + public void whenUsingFindMethodToUpdateGame_thenExecutesSelectForGame() { + + runInTransaction(() -> { + Game game1 = entityManager.find(Game.class, 1L); + game1.setName("Game Updated 1"); + + entityManager.persist(game1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: update Game set name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToUpdateGame_thenExecutesSelectForGame() { + + runInTransaction(() -> { + Game game1 = entityManager.getReference(Game.class, 1L); + game1.setName("Game Updated 2"); + + entityManager.persist(game1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: update Game set name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingFindMethodToDeletePlayer_thenExecutesSelectForPlayer() { + + runInTransaction(() -> { + Player player2 = entityManager.find(Player.class, 2L); + entityManager.remove(player2); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: delete from Player where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToDeletePlayer_thenExecutesSelectForPlayer() { + + runInTransaction(() -> { + Player player3 = entityManager.getReference(Player.class, 3L); + entityManager.remove(player3); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: delete from Player where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingFindMethodToUpdatePlayersGame_thenExecutesSelectForGame() { + + runInTransaction((() -> { + Game game1 = entityManager.find(Game.class, 1L); + + Player player1 = entityManager.find(Player.class, 1L); + player1.setGame(game1); + + entityManager.persist(player1); + })); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: update Player set game_id=?, name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToUpdatePlayersGame_thenDoesNotExecuteSelectForGame() { + + runInTransaction(() -> { + Game game2 = entityManager.getReference(Game.class, 2L); + + Player player1 = entityManager.find(Player.class, 1L); + player1.setGame(game2); + + entityManager.persist(player1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: update Player set game_id=?, name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + +} diff --git a/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferencePostgreSQLManualTest.java b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferencePostgreSQLManualTest.java new file mode 100644 index 0000000000..17f6b10b8a --- /dev/null +++ b/persistence-modules/hibernate-jpa/src/test/java/com/baeldung/hibernate/entitymanager/getreference/GetReferencePostgreSQLManualTest.java @@ -0,0 +1,185 @@ +package com.baeldung.hibernate.entitymanager.getreference; + +import ch.qos.logback.classic.Level; +import ch.qos.logback.classic.Logger; +import org.junit.jupiter.api.*; +import org.slf4j.LoggerFactory; + +import javax.persistence.EntityManager; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; +import java.io.ByteArrayOutputStream; +import java.io.OutputStream; +import java.io.PrintStream; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +/** + * We need to have a running PostgreSQL instance in order to execute this integration test + */ +public class GetReferencePostgreSQLManualTest { + + private static EntityManagerFactory entityManagerFactory; + private static EntityManager entityManager; + + private static final PrintStream SystemOut = System.out; + private static OutputStream output; + + @BeforeAll + public static void setup() { + // close some specific loggers so that we can clearly see Hibernate: SQL queries + ((Logger) LoggerFactory.getLogger("org.hibernate.SQL")).setLevel(Level.OFF); + ((Logger) LoggerFactory.getLogger("org.hibernate.type.descriptor.sql")).setLevel(Level.OFF); + ((Logger) LoggerFactory.getLogger("org.hibernate.stat")).setLevel(Level.OFF); + + entityManagerFactory = Persistence.createEntityManagerFactory("com.baeldung.hibernate.entitymanager.game_player_postgresql"); + } + + private void runInTransaction(Runnable task) { + // We create new persistence context for each test method to discard Hibernate first level cache. + // So that we can see the behavior of getReference() method in a non-cached environment. + entityManager = entityManagerFactory.createEntityManager(); + entityManager.getTransaction().begin(); + task.run(); + entityManager.getTransaction().commit(); + // In any case, we use clear() and close() to make all the managed entities detached and cleared. + // So, we can be sure we test always on a clear persistence context. + entityManager.clear(); + entityManager.close(); + } + + @BeforeEach + public void beforeEach() { + // stubbing System.out printStream + output = new ByteArrayOutputStream(); + System.setOut(new PrintStream(output)); + } + + @AfterEach + public void afterEach() { + System.setOut(SystemOut); + // we print to see original output after each test method + System.out.print(output.toString()); + } + + @AfterAll + public static void tearDown() { + entityManagerFactory.close(); + } + + @Test + public void whenUsingFindMethodToUpdateGame_thenExecutesSelectForGame() { + + runInTransaction(() -> { + Game game1 = entityManager.find(Game.class, 1L); + game1.setName("Game Updated 1"); + + entityManager.persist(game1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: update Game set name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToUpdateGame_thenExecutesSelectForGame() { + + runInTransaction(() -> { + Game game1 = entityManager.getReference(Game.class, 1L); + game1.setName("Game Updated 2"); + + entityManager.persist(game1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: update Game set name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingFindMethodToDeletePlayer_thenExecutesSelectForPlayer() { + + runInTransaction(() -> { + Player player2 = entityManager.find(Player.class, 2L); + entityManager.remove(player2); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: delete from Player where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToDeletePlayer_thenExecutesSelectForPlayer() { + + runInTransaction(() -> { + Player player3 = entityManager.getReference(Player.class, 3L); + entityManager.remove(player3); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: delete from Player where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingFindMethodToUpdatePlayersGame_thenExecutesSelectForGame() { + + runInTransaction((() -> { + Game game1 = entityManager.find(Game.class, 1L); + + Player player1 = entityManager.find(Player.class, 1L); + player1.setGame(game1); + + entityManager.persist(player1); + })); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select game0_.id as id1_0_0_, game0_.name as name2_0_0_ from Game game0_ where game0_.id=?\n"); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: update Player set game_id=?, name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + + @Test + public void whenUsingGetReferenceMethodToUpdatePlayersGame_thenDoesNotExecuteSelectForGame() { + + runInTransaction(() -> { + Game game2 = entityManager.getReference(Game.class, 2L); + + Player player1 = entityManager.find(Player.class, 1L); + player1.setGame(game2); + + entityManager.persist(player1); + }); + + StringBuilder expected = new StringBuilder(); + expected.append("Hibernate: select "); + expected.append("player0_.id as id1_1_0_, player0_.game_id as game_id3_1_0_, "); + expected.append("player0_.name as name2_1_0_, game1_.id as id1_0_1_, game1_.name as name2_0_1_ "); + expected.append("from Player player0_ left outer join Game game1_ on player0_.game_id=game1_.id where player0_.id=?\n"); + expected.append("Hibernate: update Player set game_id=?, name=? where id=?\n"); + + assertEquals(expected.toString(), output.toString()); + } + +} From 32ff2077a37ab1bea794aaca9eb9a3f566e055c9 Mon Sep 17 00:00:00 2001 From: Graham Cox Date: Thu, 26 Mar 2020 04:31:54 +0000 Subject: [PATCH 272/278] Examples for collection transformations in Kotlin (#8912) --- .../transformations/AssociateUnitTest.kt | 48 +++++++++++++++++ .../transformations/FilterUnitTest.kt | 43 +++++++++++++++ .../transformations/FlattenUnitTest.kt | 21 ++++++++ .../transformations/JoinToUnitTest.kt | 46 ++++++++++++++++ .../transformations/MapUnitTest.kt | 53 +++++++++++++++++++ .../transformations/ReduceUnitTest.kt | 22 ++++++++ .../transformations/ZipUnitTest.kt | 34 ++++++++++++ 7 files changed, 267 insertions(+) create mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt create mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt create mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt create mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt create mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt create mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt create mode 100644 core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt new file mode 100644 index 0000000000..68f7040c4c --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/AssociateUnitTest.kt @@ -0,0 +1,48 @@ +package com.baeldung.collections.transformations + +import org.junit.Assert.assertEquals +import org.junit.Test + +class AssociateUnitTest { + @Test + fun testToMap() { + val input = listOf(Pair("one", 1), Pair("two", 2)) + val map = input.toMap() + assertEquals(mapOf("one" to 1, "two" to 2), map) + } + + @Test + fun testAssociateWith() { + val inputs = listOf("Hi", "there") + val map = inputs.associateWith { k -> k.length } + assertEquals(mapOf("Hi" to 2, "there" to 5), map) + } + + @Test + fun testAssociateBy() { + val inputs = listOf("Hi", "there") + val map = inputs.associateBy { v -> v.length } + assertEquals(mapOf(2 to "Hi", 5 to "there"), map) + } + + @Test + fun testAssociate() { + val inputs = listOf("Hi", "there") + val map = inputs.associate { e -> Pair(e.toUpperCase(), e.reversed()) } + assertEquals(mapOf("HI" to "iH", "THERE" to "ereht"), map) + } + + @Test + fun testAssociateByDuplicateKeys() { + val inputs = listOf("one", "two") + val map = inputs.associateBy { v -> v.length } + assertEquals(mapOf(3 to "two"), map) + } + + @Test + fun testGroupBy() { + val inputs = listOf("one", "two", "three") + val map = inputs.groupBy { v -> v.length } + assertEquals(mapOf(3 to listOf("one", "two"), 5 to listOf("three")), map) + } +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt new file mode 100644 index 0000000000..591577e4f3 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FilterUnitTest.kt @@ -0,0 +1,43 @@ +package com.baeldung.collections.transformations + +import org.junit.Assert.assertEquals +import org.junit.Test + +class FilterUnitTest { + @Test + fun testFilterWithLambda() { + val input = listOf(1, 2, 3, 4, 5) + val filtered = input.filter { it <= 3 } + assertEquals(listOf(1, 2, 3), filtered) + } + + @Test + fun testFilterWithMethodReference() { + val input = listOf(1, 2, 3, 4, 5) + val filtered = input.filter(this::isSmall) + assertEquals(listOf(1, 2, 3), filtered) + } + + @Test + fun testFilterNotWithMethodReference() { + val input = listOf(1, 2, 3, 4, 5) + val filtered = input.filterNot(this::isSmall) + assertEquals(listOf(4, 5), filtered) + } + + @Test + fun testFilterIndexed() { + val input = listOf(5, 4, 3, 2, 1) + val filtered = input.filterIndexed { index, element -> index < 3 } + assertEquals(listOf(5, 4, 3), filtered) + } + + @Test + fun testFilterNotNull() { + val nullable: List = listOf("Hello", null, "World") + val nonnull: List = nullable.filterNotNull() + assertEquals(listOf("Hello", "World"), nonnull) + } + + private fun isSmall(i: Int) = i <= 3 +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt new file mode 100644 index 0000000000..69fbceb8e3 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/FlattenUnitTest.kt @@ -0,0 +1,21 @@ +package com.baeldung.collections.transformations + +import org.junit.Assert.assertEquals +import org.junit.Test + +class FlattenUnitTest { + @Test + fun testFlatten() { + val inputs = listOf("one", "two", "three") + val characters = inputs.map(String::toList) + val flattened = characters.flatten(); + assertEquals(listOf('o', 'n', 'e', 't', 'w', 'o', 't', 'h', 'r', 'e', 'e'), flattened) + } + + @Test + fun testFlatMap() { + val inputs = listOf("one", "two", "three") + val characters = inputs.flatMap(String::toList) + assertEquals(listOf('o', 'n', 'e', 't', 'w', 'o', 't', 'h', 'r', 'e', 'e'), characters) + } +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt new file mode 100644 index 0000000000..2ac0cdca50 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/JoinToUnitTest.kt @@ -0,0 +1,46 @@ +package com.baeldung.collections.transformations + +import org.junit.Assert.assertEquals +import org.junit.Test + +class JoinToUnitTest { + @Test + fun testJoinToString() { + val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") + + val simpleString = inputs.joinToString() + assertEquals("Jan, Feb, Mar, Apr, May", simpleString) + + val detailedString = inputs.joinToString(separator = ",", prefix="Months: ", postfix=".") + assertEquals("Months: Jan,Feb,Mar,Apr,May.", detailedString) + } + + @Test + fun testJoinToStringLimits() { + val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") + + val simpleString = inputs.joinToString(limit = 3) + assertEquals("Jan, Feb, Mar, ...", simpleString) + } + + @Test + fun testJoinToStringTransform() { + val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") + + val simpleString = inputs.joinToString(transform = String::toUpperCase) + assertEquals("JAN, FEB, MAR, APR, MAY", simpleString) + } + + @Test + fun testJoinTo() { + val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") + + val output = StringBuilder() + output.append("My ") + .append(inputs.size) + .append(" elements: ") + inputs.joinTo(output) + + assertEquals("My 5 elements: Jan, Feb, Mar, Apr, May", output.toString()) + } +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt new file mode 100644 index 0000000000..e22fcbe903 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/MapUnitTest.kt @@ -0,0 +1,53 @@ +package com.baeldung.collections.transformations + +import org.junit.Assert.assertEquals +import org.junit.Test + +class MapUnitTest { + @Test + fun testMapWithLambda() { + val input = listOf("one", "two", "three") + + val reversed = input.map { it.reversed() } + assertEquals(listOf("eno", "owt", "eerht"), reversed) + + val lengths = input.map { it.length } + assertEquals(listOf(3, 3, 5), lengths) + } + + @Test + fun testMapIndexed() { + val input = listOf(3, 2, 1) + val result = input.mapIndexed { index, value -> index * value } + assertEquals(listOf(0, 2, 2), result) + } + + @Test + fun testMapNotNull() { + val input = listOf(1, 2, 3, 4, 5) + val smallSquares = input.mapNotNull { + if (it <= 3) { + it * it + } else { + null + } + } + assertEquals(listOf(1, 4, 9), smallSquares) + } + + @Test + fun mapMapKeys() { + val inputs = mapOf("one" to 1, "two" to 2, "three" to 3) + + val uppercases = inputs.mapKeys { it.key.toUpperCase() } + assertEquals(mapOf("ONE" to 1, "TWO" to 2, "THREE" to 3), uppercases) + } + + @Test + fun mapMapValues() { + val inputs = mapOf("one" to 1, "two" to 2, "three" to 3) + + val squares = inputs.mapValues { it.value * it.value } + assertEquals(mapOf("one" to 1, "two" to 4, "three" to 9), squares) + } +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt new file mode 100644 index 0000000000..6821b7cdb9 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ReduceUnitTest.kt @@ -0,0 +1,22 @@ +package com.baeldung.collections.transformations + +import org.junit.Assert.assertEquals +import org.junit.Test + +class ReduceUnitTest { + @Test + fun testJoinToStringAsReduce() { + val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") + + val result = inputs.reduce { acc, next -> "$acc, $next" } + assertEquals("Jan, Feb, Mar, Apr, May", result) + } + + @Test + fun testFoldToLength() { + val inputs = listOf("Jan", "Feb", "Mar", "Apr", "May") + + val result = inputs.fold(0) { acc, next -> acc + next.length } + assertEquals(15, result) + } +} \ No newline at end of file diff --git a/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt new file mode 100644 index 0000000000..66aeeceef4 --- /dev/null +++ b/core-kotlin-modules/core-kotlin-collections/src/test/kotlin/com/baeldung/collections/transformations/ZipUnitTest.kt @@ -0,0 +1,34 @@ +package com.baeldung.collections.transformations + +import org.junit.Assert.assertEquals +import org.junit.Test + +class ZipUnitTest { + @Test + fun testZip() { + val left = listOf("one", "two", "three") + val right = listOf(1, 2, 3) + val zipped = left.zip(right) + assertEquals (listOf(Pair("one", 1), Pair("two", 2), Pair("three", 3)), zipped) + } + + @Test + fun testZipShort() { + val left = listOf("one", "two") + val right = listOf(1, 2, 3) + val zipped = left.zip(right) + assertEquals (listOf(Pair("one", 1), Pair("two", 2)), zipped) + } + + @Test + fun testUnzip() { + val left = listOf("one", "two", "three") + val right = listOf(1, 2, 3) + val zipped = left.zip(right) + + val (newLeft, newRight) = zipped.unzip() + assertEquals(left, newLeft) + assertEquals(right, newRight) + } + +} \ No newline at end of file From 2adb66df0c2fba69e84e0f8dcaa4b0993aa5de94 Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 26 Mar 2020 16:02:49 +0800 Subject: [PATCH 273/278] Update README.md --- java-math-2/README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/java-math-2/README.md b/java-math-2/README.md index 7c459cc576..8b13789179 100644 --- a/java-math-2/README.md +++ b/java-math-2/README.md @@ -1,3 +1 @@ -## Java Math -This module contains articles about math in Java. From 2f0fbac05e43d5ad00283998e62f0159a32719ec Mon Sep 17 00:00:00 2001 From: johnA1331 <53036378+johnA1331@users.noreply.github.com> Date: Thu, 26 Mar 2020 16:03:01 +0800 Subject: [PATCH 274/278] Delete README.md --- java-math-2/README.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 java-math-2/README.md diff --git a/java-math-2/README.md b/java-math-2/README.md deleted file mode 100644 index 8b13789179..0000000000 --- a/java-math-2/README.md +++ /dev/null @@ -1 +0,0 @@ - From 071a86a22358e40c03e17202ecb6e9cc104a78c0 Mon Sep 17 00:00:00 2001 From: Krzysztof Woyke Date: Thu, 26 Mar 2020 15:12:26 +0100 Subject: [PATCH 275/278] JAVA-1098: Add code for the Spring Boot Exit Codes --- .../spring-boot-basic-customization/README.md | 1 + .../event/ExitCodeEventDemoApplication.java | 31 +++++++++++++++++++ ...xitCodeExceptionMapperDemoApplication.java | 31 +++++++++++++++++++ .../ExitCodeGeneratorDemoApplication.java | 22 +++++++++++++ spring-boot-modules/spring-boot/README.MD | 1 - 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/event/ExitCodeEventDemoApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exception/ExitCodeExceptionMapperDemoApplication.java create mode 100644 spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/generator/ExitCodeGeneratorDemoApplication.java diff --git a/spring-boot-modules/spring-boot-basic-customization/README.md b/spring-boot-modules/spring-boot-basic-customization/README.md index a3d9f1b1fc..6c067fc5a1 100644 --- a/spring-boot-modules/spring-boot-basic-customization/README.md +++ b/spring-boot-modules/spring-boot-basic-customization/README.md @@ -11,3 +11,4 @@ This module contains articles about Spring Boot customization - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) - [How to Define a Spring Boot Filter?](https://www.baeldung.com/spring-boot-add-filter) - [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon) + - [Spring Boot Exit Codes](https://www.baeldung.com/spring-boot-exit-codes) diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/event/ExitCodeEventDemoApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/event/ExitCodeEventDemoApplication.java new file mode 100644 index 0000000000..c28f908fb8 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/event/ExitCodeEventDemoApplication.java @@ -0,0 +1,31 @@ +package com.baeldung.exitcode.event; + +import org.springframework.boot.ExitCodeEvent; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.event.EventListener; + +@SpringBootApplication +public class ExitCodeEventDemoApplication { + + public static void main(String[] args) { + System.exit( + SpringApplication.exit( + SpringApplication.run(ExitCodeEventDemoApplication.class, args) + ) + ); + } + + @Bean + DemoListener demoListenerBean() { + return new DemoListener(); + } + + private static class DemoListener { + @EventListener + public void exitEvent(ExitCodeEvent event) { + System.out.println("Exit code: " + event.getExitCode()); + } + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exception/ExitCodeExceptionMapperDemoApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exception/ExitCodeExceptionMapperDemoApplication.java new file mode 100644 index 0000000000..44b4ff36f5 --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/exception/ExitCodeExceptionMapperDemoApplication.java @@ -0,0 +1,31 @@ +package com.baeldung.exitcode.exception; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.ExitCodeExceptionMapper; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; + +@SpringBootApplication +public class ExitCodeExceptionMapperDemoApplication { + + public static void main(String[] args) { + SpringApplication.run(ExitCodeExceptionMapperDemoApplication.class, args); + } + + @Bean + CommandLineRunner createException() { + return args -> Integer.parseInt("test"); + } + + @Bean + ExitCodeExceptionMapper exitCodeToExceptionMapper() { + return exception -> { + // set exit code based on the exception type + if (exception.getCause() instanceof NumberFormatException) { + return 80; + } + return 1; + }; + } +} diff --git a/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/generator/ExitCodeGeneratorDemoApplication.java b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/generator/ExitCodeGeneratorDemoApplication.java new file mode 100644 index 0000000000..7f7acbe86e --- /dev/null +++ b/spring-boot-modules/spring-boot-basic-customization/src/main/java/com/baeldung/exitcode/generator/ExitCodeGeneratorDemoApplication.java @@ -0,0 +1,22 @@ +package com.baeldung.exitcode.generator; + +import org.springframework.boot.ExitCodeGenerator; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ExitCodeGeneratorDemoApplication implements ExitCodeGenerator { + + public static void main(String[] args) { + System.exit( + SpringApplication.exit( + SpringApplication.run(ExitCodeGeneratorDemoApplication.class, args) + ) + ); + } + + @Override + public int getExitCode() { + return 42; + } +} diff --git a/spring-boot-modules/spring-boot/README.MD b/spring-boot-modules/spring-boot/README.MD index b15ab7dbe5..c95fe51842 100644 --- a/spring-boot-modules/spring-boot/README.MD +++ b/spring-boot-modules/spring-boot/README.MD @@ -22,7 +22,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [An Introduction to Kong](https://www.baeldung.com/kong) - [Spring Boot: Configuring a Main Class](https://www.baeldung.com/spring-boot-main-class) - [A Quick Intro to the SpringBootServletInitializer](https://www.baeldung.com/spring-boot-servlet-initializer) -- [Guide to the Favicon in Spring Boot](https://www.baeldung.com/spring-boot-favicon) - [Spring Shutdown Callbacks](https://www.baeldung.com/spring-shutdown-callbacks) - [Container Configuration in Spring Boot 2](https://www.baeldung.com/embeddedservletcontainercustomizer-configurableembeddedservletcontainer-spring-boot) - [Validation in Spring Boot](https://www.baeldung.com/spring-boot-bean-validation) From f03374a805a914dc80da93af1fde0c09e63e8dae Mon Sep 17 00:00:00 2001 From: Konstantinos Karavitis Date: Thu, 26 Mar 2020 19:57:09 +0200 Subject: [PATCH 276/278] [BAEL-3913] Prevent Application / CommandLineRunner classes from executing during JUnit testing (#8920) * kkaravitis@gmail.com hexagonal architecture in java * Removed evaluation article code * Removed evaluation article code * [BAEL-3913] Initial commit for prevent commandline application runner execution during JUnit test article * [BAEL-3913] Fixed broken lines format and reduced the test method names length * [BAEL-3913] Fixed broken lines format --- .../spring-boot-testing/README.md | 1 + .../ApplicationCommandLineRunnerApp.java | 11 +++++ .../ApplicationRunnerTaskExecutor.java | 27 ++++++++++++ .../execution/CommandLineTaskExecutor.java | 26 +++++++++++ .../runner/execution/TaskService.java | 14 ++++++ .../LoadSpringContextIntegrationTest.java | 43 +++++++++++++++++++ .../RunApplicationIntegrationTest.java | 26 +++++++++++ ...icationWithTestProfileIntegrationTest.java | 33 ++++++++++++++ ...tionWithTestPropertiesIntegrationTest.java | 32 ++++++++++++++ 9 files changed, 213 insertions(+) create mode 100644 spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationCommandLineRunnerApp.java create mode 100644 spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationRunnerTaskExecutor.java create mode 100644 spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/CommandLineTaskExecutor.java create mode 100644 spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/TaskService.java create mode 100644 spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestProfileIntegrationTest.java create mode 100644 spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestPropertiesIntegrationTest.java diff --git a/spring-boot-modules/spring-boot-testing/README.md b/spring-boot-modules/spring-boot-testing/README.md index 882e2be766..9bbaf337d7 100644 --- a/spring-boot-modules/spring-boot-testing/README.md +++ b/spring-boot-modules/spring-boot-testing/README.md @@ -13,3 +13,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Setting the Log Level in Spring Boot when Testing](https://www.baeldung.com/spring-boot-testing-log-level) - [Embedded Redis Server with Spring Boot Test](https://www.baeldung.com/spring-embedded-redis) - [Testing Spring Boot @ConfigurationProperties](https://www.baeldung.com/spring-boot-testing-configurationproperties) +- [Prevent ApplicationRunner or CommandLineRunner Beans From Executing During Junit Testing]() diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationCommandLineRunnerApp.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationCommandLineRunnerApp.java new file mode 100644 index 0000000000..76e18dfd2f --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationCommandLineRunnerApp.java @@ -0,0 +1,11 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ApplicationCommandLineRunnerApp { + public static void main(String[] args) { + SpringApplication.run(ApplicationCommandLineRunnerApp.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationRunnerTaskExecutor.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationRunnerTaskExecutor.java new file mode 100644 index 0000000000..3bf08491bf --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/ApplicationRunnerTaskExecutor.java @@ -0,0 +1,27 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Profile("!test") +@ConditionalOnProperty( + prefix = "application.runner", + value = "enabled", + havingValue = "true", + matchIfMissing = true) +@Component +public class ApplicationRunnerTaskExecutor implements ApplicationRunner { + private TaskService taskService; + + public ApplicationRunnerTaskExecutor(TaskService taskService) { + this.taskService = taskService; + } + + @Override + public void run(ApplicationArguments args) throws Exception { + taskService.execute("application runner task"); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/CommandLineTaskExecutor.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/CommandLineTaskExecutor.java new file mode 100644 index 0000000000..38fd3b9c0a --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/CommandLineTaskExecutor.java @@ -0,0 +1,26 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; + +@Profile("!test") +@ConditionalOnProperty( + prefix = "command.line.runner", + value = "enabled", + havingValue = "true", + matchIfMissing = true) +@Component +public class CommandLineTaskExecutor implements CommandLineRunner { + private TaskService taskService; + + public CommandLineTaskExecutor(TaskService taskService) { + this.taskService = taskService; + } + + @Override + public void run(String... args) throws Exception { + taskService.execute("command line runner task"); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/TaskService.java b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/TaskService.java new file mode 100644 index 0000000000..dac437e72d --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/main/java/com/baeldung/prevent/commandline/application/runner/execution/TaskService.java @@ -0,0 +1,14 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +@Service +public class TaskService { + private static Logger logger = LoggerFactory.getLogger(TaskService.class); + + public void execute(String task) { + logger.info("do " + task); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java new file mode 100644 index 0000000000..6698094550 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/LoadSpringContextIntegrationTest.java @@ -0,0 +1,43 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.boot.test.mock.mockito.SpyBean; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +import com.baeldung.prevent.commandline.application.runner.execution.ApplicationCommandLineRunnerApp; +import com.baeldung.prevent.commandline.application.runner.execution.TaskService; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { ApplicationCommandLineRunnerApp.class }, + initializers = ConfigFileApplicationContextInitializer.class) +public class LoadSpringContextIntegrationTest { + @SpyBean + TaskService taskService; + + @SpyBean + CommandLineRunner commandLineRunner; + + @SpyBean + ApplicationRunner applicationRunner; + + @Test + void whenContextLoads_thenRunnersDoNotRun() throws Exception { + assertNotNull(taskService); + assertNotNull(commandLineRunner); + assertNotNull(applicationRunner); + + verify(taskService, times(0)).execute(any()); + verify(commandLineRunner, times(0)).run(any()); + verify(applicationRunner, times(0)).run(any()); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java new file mode 100644 index 0000000000..26a7339f1d --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationIntegrationTest.java @@ -0,0 +1,26 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.SpyBean; + +import com.baeldung.prevent.commandline.application.runner.execution.ApplicationRunnerTaskExecutor; +import com.baeldung.prevent.commandline.application.runner.execution.CommandLineTaskExecutor; + +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +@SpringBootTest +class RunApplicationIntegrationTest { + @SpyBean + ApplicationRunnerTaskExecutor applicationRunnerTaskExecutor; + @SpyBean + CommandLineTaskExecutor commandLineTaskExecutor; + + @Test + void whenContextLoads_thenRunnersRun() throws Exception { + verify(applicationRunnerTaskExecutor, times(1)).run(any()); + verify(commandLineTaskExecutor, times(1)).run(any()); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestProfileIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestProfileIntegrationTest.java new file mode 100644 index 0000000000..333cd2ab91 --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestProfileIntegrationTest.java @@ -0,0 +1,33 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ActiveProfiles; + +import com.baeldung.prevent.commandline.application.runner.execution.ApplicationRunnerTaskExecutor; +import com.baeldung.prevent.commandline.application.runner.execution.CommandLineTaskExecutor; +import com.baeldung.prevent.commandline.application.runner.execution.TaskService; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ActiveProfiles("test") +@SpringBootTest +class RunApplicationWithTestProfileIntegrationTest { + @Autowired + private ApplicationContext context; + + @Test + void whenContextLoads_thenRunnersAreNotLoaded() { + assertNotNull(context.getBean(TaskService.class)); + assertThrows(NoSuchBeanDefinitionException.class, + () -> context.getBean(CommandLineTaskExecutor.class), + "CommandLineRunner should not be loaded during this integration test"); + assertThrows(NoSuchBeanDefinitionException.class, + () -> context.getBean(ApplicationRunnerTaskExecutor.class), + "ApplicationRunner should not be loaded during this integration test"); + } +} diff --git a/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestPropertiesIntegrationTest.java b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestPropertiesIntegrationTest.java new file mode 100644 index 0000000000..264a06a41e --- /dev/null +++ b/spring-boot-modules/spring-boot-testing/src/test/java/com/baeldung/prevent/commandline/application/runner/execution/RunApplicationWithTestPropertiesIntegrationTest.java @@ -0,0 +1,32 @@ +package com.baeldung.prevent.commandline.application.runner.execution; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.NoSuchBeanDefinitionException; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ApplicationContext; + +import com.baeldung.prevent.commandline.application.runner.execution.ApplicationRunnerTaskExecutor; +import com.baeldung.prevent.commandline.application.runner.execution.CommandLineTaskExecutor; +import com.baeldung.prevent.commandline.application.runner.execution.TaskService; + +@SpringBootTest(properties = { + "command.line.runner.enabled=false", + "application.runner.enabled=false" }) +class RunApplicationWithTestPropertiesIntegrationTest { + @Autowired + private ApplicationContext context; + + @Test + void whenContextLoads_thenRunnersAreNotLoaded() { + assertNotNull(context.getBean(TaskService.class)); + assertThrows(NoSuchBeanDefinitionException.class, + () -> context.getBean(CommandLineTaskExecutor.class), + "CommandLineRunner should not be loaded during this integration test"); + assertThrows(NoSuchBeanDefinitionException.class, + () -> context.getBean(ApplicationRunnerTaskExecutor.class), + "ApplicationRunner should not be loaded during this integration test"); + } +} From c2c26425aa4ed5ea5b17d1f8fd489d1999080471 Mon Sep 17 00:00:00 2001 From: Donato Rimenti Date: Mon, 23 Mar 2020 14:17:54 +0100 Subject: [PATCH 277/278] [JAVA-969] Added JCenter repository for missing springfox dependency --- spring-boot-modules/spring-boot-mvc-2/pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-boot-modules/spring-boot-mvc-2/pom.xml b/spring-boot-modules/spring-boot-mvc-2/pom.xml index edebd41986..b6d145c101 100644 --- a/spring-boot-modules/spring-boot-mvc-2/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-2/pom.xml @@ -79,7 +79,11 @@ Spring Milestones https://repo.spring.io/milestone - + + jcenter-snapshots + jcenter + http://oss.jfrog.org/artifactory/oss-snapshot-local/ + From 2ba09756f7fe2efdb8198d4cba4952e1e88a4314 Mon Sep 17 00:00:00 2001 From: Antonio Moreno Date: Tue, 24 Mar 2020 23:43:49 +0000 Subject: [PATCH 278/278] BAEL-3928 Comparing Long values in Java --- .../comparelong/CompareLongUnitTest.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java diff --git a/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java new file mode 100644 index 0000000000..ab4ea2b657 --- /dev/null +++ b/core-java-modules/core-java-lang-2/src/test/java/com/baeldung/comparelong/CompareLongUnitTest.java @@ -0,0 +1,53 @@ +package com.baeldung.comparelong; + +import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Test; + +public class CompareLongUnitTest { + + @Test + public void givenLongValuesLessThan128_whenUsingReferenceComparater_thenSuccess() { + + Long l1 = 127L; + Long l2 = 127L; + + assertThat(l1 == l2).isTrue(); + } + + @Test + public void givenLongValuesGreaterOrEqualsThan128_whenUsingReferenceComparater_thenFails() { + + Long l1 = 128L; + Long l2 = 128L; + + assertThat(l1 == l2).isFalse(); + } + + @Test + public void givenLongValuesGreaterOrEqualsThan128_whenUsingEquals_thenSuccess() { + + Long l1 = 128L; + Long l2 = 128L; + + assertThat(l1.equals(l2)).isTrue(); + } + + @Test + public void givenLongValuesGreaterOrEqualsThan128_whenUsingComparisonOperator_andLongValue_thenSuccess() { + + Long l1 = 128L; + Long l2 = 128L; + + assertThat(l1.longValue() == l2.longValue()).isTrue(); + } + + @Test + public void givenLongValuesGreaterOrEqualsThan128_whenUsingCasting_thenSuccess() { + + Long l1 = 128L; + Long l2 = 128L; + + assertThat((long) l1 == (long) l2).isTrue(); + } + +} \ No newline at end of file