From 4798036089d1db858d60a045e8fa4ebd84070ed4 Mon Sep 17 00:00:00 2001 From: Priyesh Mashelkar Date: Tue, 4 Sep 2018 00:01:25 +0100 Subject: [PATCH 01/24] Added entities and basic select --- .../hibernate/entities/Department.java | 16 +++++++ .../baeldung/hibernate/entities/Employee.java | 47 +++++++++++++++++++ .../hibernate/CustomClassIntegrationTest.java | 36 ++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java create mode 100644 hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java new file mode 100644 index 0000000000..12a9bda5f9 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java @@ -0,0 +1,16 @@ +package com.baeldung.hibernate.entities; + +import java.util.List; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class Department { + @Id + long id; + String name; + @OneToMany(mappedBy="department") + List employees; +} diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java new file mode 100644 index 0000000000..8b5c554c44 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java @@ -0,0 +1,47 @@ +package com.baeldung.hibernate.entities; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Employee { + @Id + long id; + String employeeNumber; + String name; + String designation; + @ManyToOne + 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 String getDesignation() { + return designation; + } + public void setDesignation(String designation) { + this.designation = designation; + } + public Department getDepartment() { + return department; + } + public void setDepartment(Department department) { + this.department = department; + } +} diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java new file mode 100644 index 0000000000..8b2fd4854d --- /dev/null +++ b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java @@ -0,0 +1,36 @@ +package com.baeldung.hibernate; + +import static org.junit.jupiter.api.Assertions.*; + +import java.io.IOException; +import java.util.List; +import java.util.TimeZone; + +import org.hibernate.Session; +import org.hibernate.Transaction; +import org.hibernate.query.Query; +import org.junit.Before; +import org.junit.jupiter.api.Test; + +class CustomClassIntegrationTest { + + private Session session; + + private Transaction transaction; + + @Before + public void setUp() throws IOException { + session = HibernateUtil.getSessionFactory().openSession(); + transaction = session.beginTransaction(); + session.createNativeQuery("delete from employee").executeUpdate(); + session.createNativeQuery("delete from department").executeUpdate(); + transaction.commit(); + } + + @Test + void whenAllEmployeesSelected_ThenObjectGraphReturned() { + Query query = session.createQuery("from employee"); + List employees = query.list(); + } + +} From fbe433ebb47a6306028a3878de2b053e8597c8eb Mon Sep 17 00:00:00 2001 From: Priyesh Mashelkar Date: Wed, 5 Sep 2018 00:13:08 +0100 Subject: [PATCH 02/24] Added Result --- .../hibernate/entities/Department.java | 19 +++++++++++++ .../baeldung/hibernate/entities/Employee.java | 1 + .../com/baeldung/hibernate/pojo/Result.java | 27 +++++++++++++++++++ .../hibernate/CustomClassIntegrationTest.java | 21 +++++++++++---- 4 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java index 12a9bda5f9..fec7b04462 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java @@ -5,6 +5,7 @@ import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; +import javax.persistence.Table; @Entity public class Department { @@ -13,4 +14,22 @@ public class Department { String name; @OneToMany(mappedBy="department") List employees; + 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/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java index 8b5c554c44..eec7c54d93 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java @@ -3,6 +3,7 @@ package com.baeldung.hibernate.entities; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; +import javax.persistence.Table; @Entity public class Employee { diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java new file mode 100644 index 0000000000..6893060dd8 --- /dev/null +++ b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java @@ -0,0 +1,27 @@ +package com.baeldung.hibernate.pojo; + +public class Result { + String employeeName; + String departmentName; + + public Result(String employeeName, String departmentName) { + this.employeeName = employeeName; + this.departmentName = departmentName; + } + + 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/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java index 8b2fd4854d..c2ccef5c85 100644 --- a/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java +++ b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java @@ -10,27 +10,38 @@ import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.query.Query; import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import com.baeldung.hibernate.pojo.Result; + class CustomClassIntegrationTest { private Session session; private Transaction transaction; - @Before + @BeforeEach public void setUp() throws IOException { session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); - session.createNativeQuery("delete from employee").executeUpdate(); - session.createNativeQuery("delete from department").executeUpdate(); + session.createNativeQuery("delete from emp").executeUpdate(); + session.createNativeQuery("delete from dept").executeUpdate(); transaction.commit(); + transaction = session.beginTransaction(); } @Test - void whenAllEmployeesSelected_ThenObjectGraphReturned() { - Query query = session.createQuery("from employee"); + public void whenAllEmployeesSelected_ThenObjectGraphReturned() { + @SuppressWarnings("unchecked") + Query query = session.createQuery("from Employee"); List employees = query.list(); } + + @Test + public void whenResultConstructorInSelect_ThenListOfResultReturned() { + Query query = session.createQuery("select new Result(e.name, e.department.name) from Employee e"); + List employees = query.list(); + } } From a50baf1be379bc5e339e0db881301f7c7f76cf13 Mon Sep 17 00:00:00 2001 From: priyeshmashelkar Date: Wed, 5 Sep 2018 17:27:25 +0100 Subject: [PATCH 03/24] Added tests --- .../com/baeldung/hibernate/HibernateUtil.java | 46 ++++++++++++---- .../hibernate/entities/Department.java | 12 +++-- .../entities/{Employee.java => Manager.java} | 16 +++--- .../com/baeldung/hibernate/pojo/Result.java | 3 ++ .../hibernate/CustomClassIntegrationTest.java | 54 ++++++++++++++----- 5 files changed, 94 insertions(+), 37 deletions(-) rename hibernate5/src/main/java/com/baeldung/hibernate/entities/{Employee.java => Manager.java} (78%) diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java index e8fdabebbc..c75f8e358f 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -1,12 +1,10 @@ package com.baeldung.hibernate; -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.*; -import com.baeldung.hibernate.pojo.Person; -import com.baeldung.hibernate.pojo.inheritance.*; +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; @@ -14,10 +12,34 @@ 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; +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; +import com.baeldung.hibernate.pojo.Product; +import com.baeldung.hibernate.pojo.Student; +import com.baeldung.hibernate.pojo.TemporalValues; +import com.baeldung.hibernate.pojo.User; +import com.baeldung.hibernate.pojo.UserProfile; +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 SessionFactory sessionFactory; @@ -70,6 +92,8 @@ public class HibernateUtil { metadataSources.addAnnotatedClass(PessimisticLockingCourse.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Customer.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Address.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Manager.class); + metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); Metadata metadata = metadataSources.buildMetadata(); return metadata.getSessionFactoryBuilder() diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java index fec7b04462..ceabfc742e 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java @@ -5,7 +5,6 @@ import java.util.List; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.OneToMany; -import javax.persistence.Table; @Entity public class Department { @@ -13,7 +12,12 @@ public class Department { long id; String name; @OneToMany(mappedBy="department") - List employees; + List employees; + + public Department(String name) { + this.name = name; + } + public long getId() { return id; } @@ -26,10 +30,10 @@ public class Department { public void setName(String name) { this.name = name; } - public List getEmployees() { + public List getEmployees() { return employees; } - public void setEmployees(List employees) { + public void setEmployees(List employees) { this.employees = employees; } } diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Manager.java similarity index 78% rename from hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java rename to hibernate5/src/main/java/com/baeldung/hibernate/entities/Manager.java index eec7c54d93..d9d8e8d40f 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Employee.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Manager.java @@ -3,18 +3,22 @@ package com.baeldung.hibernate.entities; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.ManyToOne; -import javax.persistence.Table; @Entity -public class Employee { +public class Manager { @Id long id; String employeeNumber; String name; - String designation; @ManyToOne Department department; + public Manager(String name, String employeeNumber, Department department) { + this.name = name; + this.employeeNumber = employeeNumber; + this.department = department; + } + public long getId() { return id; } @@ -33,12 +37,6 @@ public class Employee { public void setName(String name) { this.name = name; } - public String getDesignation() { - return designation; - } - public void setDesignation(String designation) { - this.designation = designation; - } public Department getDepartment() { return department; } diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java index 6893060dd8..588a895c14 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java @@ -9,6 +9,9 @@ public class Result { this.departmentName = departmentName; } + public Result() { + } + public String getEmployeeName() { return employeeName; } diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java index c2ccef5c85..622063b828 100644 --- a/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java +++ b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java @@ -1,18 +1,19 @@ package com.baeldung.hibernate; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; import java.util.List; -import java.util.TimeZone; import org.hibernate.Session; import org.hibernate.Transaction; import org.hibernate.query.Query; -import org.junit.Before; +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.entities.Manager; import com.baeldung.hibernate.pojo.Result; class CustomClassIntegrationTest { @@ -25,23 +26,50 @@ class CustomClassIntegrationTest { public void setUp() throws IOException { session = HibernateUtil.getSessionFactory().openSession(); transaction = session.beginTransaction(); - session.createNativeQuery("delete from emp").executeUpdate(); - session.createNativeQuery("delete from dept").executeUpdate(); + session.createNativeQuery("delete from manager").executeUpdate(); + session.createNativeQuery("delete from department").executeUpdate(); + Department department = new Department("Sales"); + Manager employee = new Manager("John Smith", "001", department); + session.persist(department); + session.persist(employee); transaction.commit(); transaction = session.beginTransaction(); } @Test - public void whenAllEmployeesSelected_ThenObjectGraphReturned() { - @SuppressWarnings("unchecked") - Query query = session.createQuery("from Employee"); - List employees = query.list(); + public void whenAllManagersAreSelected_ThenObjectGraphIsReturned() { + Query query = session.createQuery("from com.baeldung.hibernate.entities.Manager"); + List managers = query.list(); + Manager manager = managers.get(0); + assertEquals("John Smith", manager.getName()); + assertEquals("Sales", manager.getDepartment().getName()); } - @Test - public void whenResultConstructorInSelect_ThenListOfResultReturned() { - Query query = session.createQuery("select new Result(e.name, e.department.name) from Employee e"); - List employees = query.list(); + public void whenIndividualPropertiesAreSelected_ThenObjectArrayIsReturned() { + Query query = session.createQuery("select m.name, m.department.name from com.baeldung.hibernate.entities.Manager 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 Manager 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.Manager 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()); } } From f7a797352926a75b9b2377ffacd2b9fddd54f578 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 9 Sep 2018 10:22:08 +0300 Subject: [PATCH 04/24] fix reactor test --- .../com/baeldung/reactor/ReactorIntegrationTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/reactor-core/src/test/java/com/baeldung/reactor/ReactorIntegrationTest.java b/reactor-core/src/test/java/com/baeldung/reactor/ReactorIntegrationTest.java index 56650ba306..e3060b8e02 100644 --- a/reactor-core/src/test/java/com/baeldung/reactor/ReactorIntegrationTest.java +++ b/reactor-core/src/test/java/com/baeldung/reactor/ReactorIntegrationTest.java @@ -37,14 +37,14 @@ public class ReactorIntegrationTest { Flux.just(1, 2, 3, 4) .log() .map(i -> i * 2) - .zipWith(Flux.range(0, Integer.MAX_VALUE).log(), (two, one) -> String.format("First Flux: %d, Second Flux: %d", one, two)) + .zipWith(Flux.range(0, Integer.MAX_VALUE).log(), (one, two) -> String.format("First Flux: %d, Second Flux: %d", one, two)) .subscribe(elements::add); assertThat(elements).containsExactly( - "First Flux: 0, Second Flux: 2", - "First Flux: 1, Second Flux: 4", - "First Flux: 2, Second Flux: 6", - "First Flux: 3, Second Flux: 8"); + "First Flux: 2, Second Flux: 0", + "First Flux: 4, Second Flux: 1", + "First Flux: 6, Second Flux: 2", + "First Flux: 8, Second Flux: 3"); } @Test From e3226c650152db55e5530cb7da03ee56edfe220b Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 9 Sep 2018 15:05:57 +0300 Subject: [PATCH 05/24] Update README.md --- kotlin-libraries/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/kotlin-libraries/README.md b/kotlin-libraries/README.md index ce30c71792..30c4d03ded 100644 --- a/kotlin-libraries/README.md +++ b/kotlin-libraries/README.md @@ -6,5 +6,4 @@ - [Writing Specifications with Kotlin and Spek](http://www.baeldung.com/kotlin-spek) - [Processing JSON with Kotlin and Klaxson](http://www.baeldung.com/kotlin-json-klaxson) - [Kotlin with Ktor](http://www.baeldung.com/kotlin-ktor) -- [Idiomatic Logging in Kotlin](http://www.baeldung.com/kotlin-logging) -- [Guide to the Kotlin Exposed Framework](https://www.baeldung.com/kotlin-exposed-persistence) \ No newline at end of file +- [Guide to the Kotlin Exposed Framework](https://www.baeldung.com/kotlin-exposed-persistence) From dbdbe79910104271a0ac0457b67735837cd99cb1 Mon Sep 17 00:00:00 2001 From: priyeshmashelkar Date: Tue, 11 Sep 2018 10:46:05 +0100 Subject: [PATCH 06/24] Renamed Manager to DeptEmployee --- .../com/baeldung/hibernate/HibernateUtil.java | 3 +- .../hibernate/entities/Department.java | 22 +++++++---- .../{Manager.java => DeptEmployee.java} | 39 ++++++++++++++----- .../com/baeldung/hibernate/pojo/Result.java | 5 ++- .../hibernate/CustomClassIntegrationTest.java | 24 ++++++------ 5 files changed, 61 insertions(+), 32 deletions(-) rename hibernate5/src/main/java/com/baeldung/hibernate/entities/{Manager.java => DeptEmployee.java} (59%) diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java index c75f8e358f..849d271cd4 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/HibernateUtil.java @@ -5,6 +5,7 @@ import java.io.IOException; import java.net.URL; import java.util.Properties; +import com.baeldung.hibernate.entities.DeptEmployee; import org.apache.commons.lang3.StringUtils; import org.hibernate.SessionFactory; import org.hibernate.boot.Metadata; @@ -92,7 +93,7 @@ public class HibernateUtil { metadataSources.addAnnotatedClass(PessimisticLockingCourse.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Customer.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.pessimisticlocking.Address.class); - metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Manager.class); + metadataSources.addAnnotatedClass(DeptEmployee.class); metadataSources.addAnnotatedClass(com.baeldung.hibernate.entities.Department.class); Metadata metadata = metadataSources.buildMetadata(); diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java index ceabfc742e..ff94f4f849 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/Department.java @@ -2,17 +2,18 @@ package com.baeldung.hibernate.entities; import java.util.List; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.OneToMany; +import javax.persistence.*; @Entity public class Department { @Id - long id; - String name; + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + @OneToMany(mappedBy="department") - List employees; + private List employees; public Department(String name) { this.name = name; @@ -21,19 +22,24 @@ public class Department { 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() { + + public List getEmployees() { return employees; } - public void setEmployees(List employees) { + + public void setEmployees(List employees) { this.employees = employees; } } diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Manager.java b/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java similarity index 59% rename from hibernate5/src/main/java/com/baeldung/hibernate/entities/Manager.java rename to hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java index d9d8e8d40f..7a51009b62 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/entities/Manager.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/entities/DeptEmployee.java @@ -1,19 +1,23 @@ package com.baeldung.hibernate.entities; -import javax.persistence.Entity; -import javax.persistence.Id; -import javax.persistence.ManyToOne; +import javax.persistence.*; @Entity -public class Manager { +public class DeptEmployee { @Id - long id; - String employeeNumber; - String name; - @ManyToOne - Department department; + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String employeeNumber; + + private String designation; + + private String name; + + @ManyToOne + private Department department; - public Manager(String name, String employeeNumber, Department department) { + public DeptEmployee(String name, String employeeNumber, Department department) { this.name = name; this.employeeNumber = employeeNumber; this.department = department; @@ -22,25 +26,40 @@ public class Manager { 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 getDesignation() { + return designation; + } + + public void setDesignation(String designation) { + this.designation = designation; + } } diff --git a/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java index 588a895c14..607269a267 100644 --- a/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java +++ b/hibernate5/src/main/java/com/baeldung/hibernate/pojo/Result.java @@ -1,8 +1,9 @@ package com.baeldung.hibernate.pojo; public class Result { - String employeeName; - String departmentName; + private String employeeName; + + private String departmentName; public Result(String employeeName, String departmentName) { this.employeeName = employeeName; diff --git a/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java index 622063b828..29ae55b773 100644 --- a/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java +++ b/hibernate5/src/test/java/com/baeldung/hibernate/CustomClassIntegrationTest.java @@ -5,6 +5,7 @@ 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; @@ -13,10 +14,9 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import com.baeldung.hibernate.entities.Department; -import com.baeldung.hibernate.entities.Manager; import com.baeldung.hibernate.pojo.Result; -class CustomClassIntegrationTest { +public class CustomClassIntegrationTest { private Session session; @@ -29,7 +29,7 @@ class CustomClassIntegrationTest { session.createNativeQuery("delete from manager").executeUpdate(); session.createNativeQuery("delete from department").executeUpdate(); Department department = new Department("Sales"); - Manager employee = new Manager("John Smith", "001", department); + DeptEmployee employee = new DeptEmployee("John Smith", "001", department); session.persist(department); session.persist(employee); transaction.commit(); @@ -38,16 +38,16 @@ class CustomClassIntegrationTest { @Test public void whenAllManagersAreSelected_ThenObjectGraphIsReturned() { - Query query = session.createQuery("from com.baeldung.hibernate.entities.Manager"); - List managers = query.list(); - Manager manager = managers.get(0); - assertEquals("John Smith", manager.getName()); - assertEquals("Sales", manager.getDepartment().getName()); + 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.Manager m"); + 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]); @@ -56,7 +56,8 @@ class CustomClassIntegrationTest { @Test public void whenResultConstructorInSelect_ThenListOfResultIsReturned() { - Query query = session.createQuery("select new com.baeldung.hibernate.pojo.Result(m.name, m.department.name) from Manager m"); + 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()); @@ -65,7 +66,8 @@ class CustomClassIntegrationTest { @Test public void whenResultTransformerOnQuery_ThenListOfResultIsReturned() { - Query query = session.createQuery("select m.name as employeeName, m.department.name as departmentName from com.baeldung.hibernate.entities.Manager m"); + 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); From 33e7ce89ce7593664f14023f38e1e48bbc2c968d Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Wed, 12 Sep 2018 20:09:27 +0400 Subject: [PATCH 07/24] Adding Examples for ZonedDateTime, OffsetDateTime and OffsetTime --- .../java/com/baeldung/manifest/MANIFEST.MF | 1 + .../zoneddatetime/OffsetDateTimeExample.java | 17 +++++++++++ .../zoneddatetime/OffsetTimeExample.java | 18 +++++++++++ .../zoneddatetime/ZoneDateTimeExample.java | 21 +++++++++++++ .../OffsetDateTimeExampleUnitTest.java | 25 ++++++++++++++++ .../OffsetTimeExampleUnitTest.java | 25 ++++++++++++++++ .../ZoneDateTimeExampleUnitTest.java | 30 +++++++++++++++++++ 7 files changed, 137 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF create mode 100644 core-java/src/main/java/com/baeldung/zoneddatetime/OffsetDateTimeExample.java create mode 100644 core-java/src/main/java/com/baeldung/zoneddatetime/OffsetTimeExample.java create mode 100644 core-java/src/main/java/com/baeldung/zoneddatetime/ZoneDateTimeExample.java create mode 100644 core-java/src/test/java/com/baeldung/zoneddatetime/OffsetDateTimeExampleUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/zoneddatetime/OffsetTimeExampleUnitTest.java create mode 100644 core-java/src/test/java/com/baeldung/zoneddatetime/ZoneDateTimeExampleUnitTest.java diff --git a/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF b/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF new file mode 100644 index 0000000000..a363171952 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF @@ -0,0 +1 @@ +Main-Class: com.baeldung.manifest.AppExample diff --git a/core-java/src/main/java/com/baeldung/zoneddatetime/OffsetDateTimeExample.java b/core-java/src/main/java/com/baeldung/zoneddatetime/OffsetDateTimeExample.java new file mode 100644 index 0000000000..a22de0db18 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/zoneddatetime/OffsetDateTimeExample.java @@ -0,0 +1,17 @@ +package com.baeldung.zoneddatetime; + +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.ZoneOffset; + +public class OffsetDateTimeExample { + + public OffsetDateTime getCurrentTimeByZoneOffset(String region) { + LocalDateTime now = LocalDateTime.now(); + ZoneId zone = ZoneId.of(region); + ZoneOffset zoneOffSet= zone.getRules().getOffset(now); + OffsetDateTime date = OffsetDateTime.now(zoneOffSet); + return date; + } +} diff --git a/core-java/src/main/java/com/baeldung/zoneddatetime/OffsetTimeExample.java b/core-java/src/main/java/com/baeldung/zoneddatetime/OffsetTimeExample.java new file mode 100644 index 0000000000..7d926c0562 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/zoneddatetime/OffsetTimeExample.java @@ -0,0 +1,18 @@ +package com.baeldung.zoneddatetime; + +import java.time.LocalDateTime; +import java.time.OffsetTime; +import java.time.ZoneId; +import java.time.ZoneOffset; + +public class OffsetTimeExample { + + public OffsetTime getCurrentTimeByZoneOffset(String region) { + LocalDateTime now = LocalDateTime.now(); + ZoneId zone = ZoneId.of(region); + ZoneOffset zoneOffSet = zone.getRules() + .getOffset(now); + OffsetTime time = OffsetTime.now(zoneOffSet); + return time; + } +} diff --git a/core-java/src/main/java/com/baeldung/zoneddatetime/ZoneDateTimeExample.java b/core-java/src/main/java/com/baeldung/zoneddatetime/ZoneDateTimeExample.java new file mode 100644 index 0000000000..b54b8c5225 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/zoneddatetime/ZoneDateTimeExample.java @@ -0,0 +1,21 @@ +package com.baeldung.zoneddatetime; + +import java.time.ZoneId; +import java.time.ZonedDateTime; + +public class ZoneDateTimeExample { + + public ZonedDateTime getCurrentTimeByZoneId(String region) { + ZoneId zone = ZoneId.of(region); + ZonedDateTime date = ZonedDateTime.now(zone); + return date; + } + + public ZonedDateTime convertZonedDateTime(ZonedDateTime sourceDate, String destZone) { + + ZoneId destZoneId = ZoneId.of(destZone); + ZonedDateTime destDate = sourceDate.withZoneSameInstant(destZoneId); + + return destDate; + } +} diff --git a/core-java/src/test/java/com/baeldung/zoneddatetime/OffsetDateTimeExampleUnitTest.java b/core-java/src/test/java/com/baeldung/zoneddatetime/OffsetDateTimeExampleUnitTest.java new file mode 100644 index 0000000000..c60f6967f9 --- /dev/null +++ b/core-java/src/test/java/com/baeldung/zoneddatetime/OffsetDateTimeExampleUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.zoneddatetime; + +import static org.junit.Assert.assertTrue; + +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import java.time.ZoneId; + +import org.junit.Test; + +public class OffsetDateTimeExampleUnitTest { + + OffsetDateTimeExample offsetDateTimeExample = new OffsetDateTimeExample(); + + @Test + public void givenZoneOffset_whenGetCurrentTime_thenResultHasZone() { + String zone = "Europe/Berlin"; + OffsetDateTime time = offsetDateTimeExample.getCurrentTimeByZoneOffset(zone); + + assertTrue(time.getOffset() + .equals(ZoneId.of(zone) + .getRules() + .getOffset(LocalDateTime.now()))); + } +} diff --git a/core-java/src/test/java/com/baeldung/zoneddatetime/OffsetTimeExampleUnitTest.java b/core-java/src/test/java/com/baeldung/zoneddatetime/OffsetTimeExampleUnitTest.java new file mode 100644 index 0000000000..0e1206dc5b --- /dev/null +++ b/core-java/src/test/java/com/baeldung/zoneddatetime/OffsetTimeExampleUnitTest.java @@ -0,0 +1,25 @@ +package com.baeldung.zoneddatetime; + +import static org.junit.Assert.assertTrue; + +import java.time.LocalDateTime; +import java.time.OffsetTime; +import java.time.ZoneId; + +import org.junit.Test; + +public class OffsetTimeExampleUnitTest { + + OffsetTimeExample offsetTimeExample = new OffsetTimeExample(); + + @Test + public void givenZoneOffset_whenGetCurrentTime_thenResultHasZone() { + String zone = "Europe/Berlin"; + OffsetTime time = offsetTimeExample.getCurrentTimeByZoneOffset(zone); + + assertTrue(time.getOffset() + .equals(ZoneId.of(zone) + .getRules() + .getOffset(LocalDateTime.now()))); + } +} diff --git a/core-java/src/test/java/com/baeldung/zoneddatetime/ZoneDateTimeExampleUnitTest.java b/core-java/src/test/java/com/baeldung/zoneddatetime/ZoneDateTimeExampleUnitTest.java new file mode 100644 index 0000000000..7f4f9cd17c --- /dev/null +++ b/core-java/src/test/java/com/baeldung/zoneddatetime/ZoneDateTimeExampleUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.zoneddatetime; + +import static org.junit.Assert.assertTrue; + +import java.time.ZoneId; +import java.time.ZonedDateTime; + +import org.junit.Test; + +public class ZoneDateTimeExampleUnitTest { + + ZoneDateTimeExample zoneDateTimeExample = new ZoneDateTimeExample(); + + @Test + public void givenZone_whenGetCurrentTime_thenResultHasZone() { + String zone = "Europe/Berlin"; + ZonedDateTime time = zoneDateTimeExample.getCurrentTimeByZoneId(zone); + assertTrue(time.getZone() + .equals(ZoneId.of(zone))); + } + + @Test + public void givenZones_whenConvertDateByZone_thenGetConstantDiff() { + String sourceZone = "Europe/Berlin"; + String destZone = "Asia/Tokyo"; + ZonedDateTime sourceDate = zoneDateTimeExample.getCurrentTimeByZoneId(sourceZone); + ZonedDateTime destDate = zoneDateTimeExample.convertZonedDateTime(sourceDate, destZone); + assertTrue(sourceDate.toInstant().compareTo(destDate.toInstant()) == 0); + } +} From e8a48fbad29d4daa41a18805db88a2651b400060 Mon Sep 17 00:00:00 2001 From: RanjeetKaur17 Date: Wed, 12 Sep 2018 20:11:40 +0400 Subject: [PATCH 08/24] Removing unused file. --- core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF | 1 - 1 file changed, 1 deletion(-) delete mode 100644 core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF diff --git a/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF b/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF deleted file mode 100644 index a363171952..0000000000 --- a/core-java/src/main/java/com/baeldung/manifest/MANIFEST.MF +++ /dev/null @@ -1 +0,0 @@ -Main-Class: com.baeldung.manifest.AppExample From 521c34159592f316dba1ca555cbb78d0d56e308d Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 14 Sep 2018 08:05:43 +0300 Subject: [PATCH 09/24] add main class for boot-mvc module --- spring-boot-mvc/pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spring-boot-mvc/pom.xml b/spring-boot-mvc/pom.xml index e456155f36..9ca187db5d 100644 --- a/spring-boot-mvc/pom.xml +++ b/spring-boot-mvc/pom.xml @@ -46,6 +46,10 @@ org.springframework.boot spring-boot-maven-plugin + + com.baeldung.springbootmvc.SpringBootMvcApplication + JAR + @@ -56,6 +60,7 @@ 1.8 1.10.0 + com.baeldung.springbootmvc.SpringBootMvcApplication From 05e1700fb76cb7e4c373f8cc66269d16d05885b6 Mon Sep 17 00:00:00 2001 From: Wosin Date: Sat, 15 Sep 2018 13:14:57 +0200 Subject: [PATCH 10/24] Moved Flink related code from libraries to libraries-data module. (#5253) --- libraries-data/pom.xml | 72 ++++++++++++++++++- .../com/baeldung/flink/FlinkDataPipeline.java | 0 .../java/com/baeldung/flink/LineSplitter.java | 0 .../java/com/baeldung/flink/WordCount.java | 0 .../baeldung/flink/connector/Consumers.java | 0 .../baeldung/flink/connector/Producers.java | 0 .../java/com/baeldung/flink/model/Backup.java | 0 .../baeldung/flink/model/InputMessage.java | 1 - .../flink/operator/BackupAggregator.java | 0 .../InputMessageTimestampAssigner.java | 0 .../flink/operator/WordsCapitalizer.java | 0 .../schema/BackupSerializationSchema.java | 0 .../InputMessageDeserializationSchema.java | 2 - .../flink/BackupCreatorIntegrationTest.java | 0 .../flink/WordCapitalizerIntegrationTest.java | 0 .../flink/WordCountIntegrationTest.java | 0 libraries/pom.xml | 45 +----------- 17 files changed, 71 insertions(+), 49 deletions(-) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/FlinkDataPipeline.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/LineSplitter.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/WordCount.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/connector/Consumers.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/connector/Producers.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/model/Backup.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/model/InputMessage.java (99%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/operator/BackupAggregator.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/operator/InputMessageTimestampAssigner.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/operator/WordsCapitalizer.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/schema/BackupSerializationSchema.java (100%) rename {libraries => libraries-data}/src/main/java/com/baeldung/flink/schema/InputMessageDeserializationSchema.java (89%) rename {libraries => libraries-data}/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java (100%) rename {libraries => libraries-data}/src/test/java/com/baeldung/flink/WordCountIntegrationTest.java (100%) diff --git a/libraries-data/pom.xml b/libraries-data/pom.xml index 2b83328295..5b34a903ce 100644 --- a/libraries-data/pom.xml +++ b/libraries-data/pom.xml @@ -147,7 +147,6 @@ jmapper-core ${jmapper.version} - org.apache.crunch @@ -185,7 +184,72 @@ - + + org.apache.flink + flink-connector-kafka-0.11_2.11 + ${flink.version} + + + org.apache.flink + flink-streaming-java_2.11 + ${flink.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + org.apache.flink + flink-core + ${flink.version} + + + commons-logging + commons-logging + + + + + org.apache.flink + flink-java + ${flink.version} + + + commons-logging + commons-logging + + + + + org.apache.flink + flink-test-utils_2.11 + ${flink.version} + test + + + org.assertj + assertj-core + ${assertj.version} + + + org.awaitility + awaitility + ${awaitility.version} + test + + + org.awaitility + awaitility-proxy + ${awaitility.version} + test + + @@ -336,6 +400,10 @@ 2.4.0 2.8.2 1.1.0 + 1.5.0 + 2.8.5 + 3.0.0 + 3.6.2 3.8.4 1.8 3.0.0 diff --git a/libraries/src/main/java/com/baeldung/flink/FlinkDataPipeline.java b/libraries-data/src/main/java/com/baeldung/flink/FlinkDataPipeline.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/FlinkDataPipeline.java rename to libraries-data/src/main/java/com/baeldung/flink/FlinkDataPipeline.java diff --git a/libraries/src/main/java/com/baeldung/flink/LineSplitter.java b/libraries-data/src/main/java/com/baeldung/flink/LineSplitter.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/LineSplitter.java rename to libraries-data/src/main/java/com/baeldung/flink/LineSplitter.java diff --git a/libraries/src/main/java/com/baeldung/flink/WordCount.java b/libraries-data/src/main/java/com/baeldung/flink/WordCount.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/WordCount.java rename to libraries-data/src/main/java/com/baeldung/flink/WordCount.java diff --git a/libraries/src/main/java/com/baeldung/flink/connector/Consumers.java b/libraries-data/src/main/java/com/baeldung/flink/connector/Consumers.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/connector/Consumers.java rename to libraries-data/src/main/java/com/baeldung/flink/connector/Consumers.java diff --git a/libraries/src/main/java/com/baeldung/flink/connector/Producers.java b/libraries-data/src/main/java/com/baeldung/flink/connector/Producers.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/connector/Producers.java rename to libraries-data/src/main/java/com/baeldung/flink/connector/Producers.java diff --git a/libraries/src/main/java/com/baeldung/flink/model/Backup.java b/libraries-data/src/main/java/com/baeldung/flink/model/Backup.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/model/Backup.java rename to libraries-data/src/main/java/com/baeldung/flink/model/Backup.java diff --git a/libraries/src/main/java/com/baeldung/flink/model/InputMessage.java b/libraries-data/src/main/java/com/baeldung/flink/model/InputMessage.java similarity index 99% rename from libraries/src/main/java/com/baeldung/flink/model/InputMessage.java rename to libraries-data/src/main/java/com/baeldung/flink/model/InputMessage.java index 183fa69c11..b3f75256ae 100644 --- a/libraries/src/main/java/com/baeldung/flink/model/InputMessage.java +++ b/libraries-data/src/main/java/com/baeldung/flink/model/InputMessage.java @@ -18,7 +18,6 @@ public class InputMessage { public String getSender() { return sender; } - public void setSender(String sender) { this.sender = sender; } diff --git a/libraries/src/main/java/com/baeldung/flink/operator/BackupAggregator.java b/libraries-data/src/main/java/com/baeldung/flink/operator/BackupAggregator.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/operator/BackupAggregator.java rename to libraries-data/src/main/java/com/baeldung/flink/operator/BackupAggregator.java diff --git a/libraries/src/main/java/com/baeldung/flink/operator/InputMessageTimestampAssigner.java b/libraries-data/src/main/java/com/baeldung/flink/operator/InputMessageTimestampAssigner.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/operator/InputMessageTimestampAssigner.java rename to libraries-data/src/main/java/com/baeldung/flink/operator/InputMessageTimestampAssigner.java diff --git a/libraries/src/main/java/com/baeldung/flink/operator/WordsCapitalizer.java b/libraries-data/src/main/java/com/baeldung/flink/operator/WordsCapitalizer.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/operator/WordsCapitalizer.java rename to libraries-data/src/main/java/com/baeldung/flink/operator/WordsCapitalizer.java diff --git a/libraries/src/main/java/com/baeldung/flink/schema/BackupSerializationSchema.java b/libraries-data/src/main/java/com/baeldung/flink/schema/BackupSerializationSchema.java similarity index 100% rename from libraries/src/main/java/com/baeldung/flink/schema/BackupSerializationSchema.java rename to libraries-data/src/main/java/com/baeldung/flink/schema/BackupSerializationSchema.java diff --git a/libraries/src/main/java/com/baeldung/flink/schema/InputMessageDeserializationSchema.java b/libraries-data/src/main/java/com/baeldung/flink/schema/InputMessageDeserializationSchema.java similarity index 89% rename from libraries/src/main/java/com/baeldung/flink/schema/InputMessageDeserializationSchema.java rename to libraries-data/src/main/java/com/baeldung/flink/schema/InputMessageDeserializationSchema.java index 1df456bbe5..9aaf8b9877 100644 --- a/libraries/src/main/java/com/baeldung/flink/schema/InputMessageDeserializationSchema.java +++ b/libraries-data/src/main/java/com/baeldung/flink/schema/InputMessageDeserializationSchema.java @@ -1,8 +1,6 @@ package com.baeldung.flink.schema; import com.baeldung.flink.model.InputMessage; -import com.fasterxml.jackson.annotation.JsonAutoDetect; -import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.apache.flink.api.common.serialization.DeserializationSchema; diff --git a/libraries/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/flink/BackupCreatorIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/flink/WordCapitalizerIntegrationTest.java diff --git a/libraries/src/test/java/com/baeldung/flink/WordCountIntegrationTest.java b/libraries-data/src/test/java/com/baeldung/flink/WordCountIntegrationTest.java similarity index 100% rename from libraries/src/test/java/com/baeldung/flink/WordCountIntegrationTest.java rename to libraries-data/src/test/java/com/baeldung/flink/WordCountIntegrationTest.java diff --git a/libraries/pom.xml b/libraries/pom.xml index f7980f10f6..91c54b6113 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -154,45 +154,7 @@ commons-dbutils ${commons.dbutils.version} - - org.apache.flink - flink-connector-kafka-0.11_2.11 - ${flink.version} - - - org.apache.flink - flink-streaming-java_2.11 - ${flink.version} - - - org.apache.flink - flink-core - ${flink.version} - - - commons-logging - commons-logging - - - - - org.apache.flink - flink-java - ${flink.version} - - - commons-logging - commons-logging - - - - - org.apache.flink - flink-test-utils_2.11 - ${flink.version} - test - org.apache.commons commons-math3 @@ -239,11 +201,7 @@ jackson-databind ${jackson.version} - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - ${jackson.version} - + org.datanucleus @@ -900,7 +858,6 @@ 4.5.3 2.5 - 1.5.0 2.8.5 2.92 1.9.26 From 2e0edf12b120f680500dc9c5a1676be2e9cdb0ea Mon Sep 17 00:00:00 2001 From: Krzysztof Majewski Date: Sat, 15 Sep 2018 13:57:25 +0000 Subject: [PATCH 11/24] Bael 2145 concatenate strings in kotlin (#5208) * BAEL-2145 * BAEL-2145 * BAEL-2145 --- .../kotlin/StringConcatenationTest.kt | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/StringConcatenationTest.kt diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/StringConcatenationTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/StringConcatenationTest.kt new file mode 100644 index 0000000000..9c371614a4 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/StringConcatenationTest.kt @@ -0,0 +1,48 @@ +package com.baeldung.kotlin + +import org.junit.Test +import kotlin.test.assertEquals + +class StringConcatenationTest { + + @Test + fun givenTwoStrings_concatenateWithTemplates_thenEquals() { + val a = "Hello" + val b = "Baeldung" + val c = "$a $b" + + assertEquals("Hello Baeldung", c) + } + + @Test + fun givenTwoStrings_concatenateWithPlusOperator_thenEquals() { + val a = "Hello" + val b = "Baeldung" + val c = a + " " + b + + assertEquals("Hello Baeldung", c) + } + + @Test + fun givenTwoStrings_concatenateWithStringBuilder_thenEquals() { + val a = "Hello" + val b = "Baeldung" + + val builder = StringBuilder() + builder.append(a).append(" ").append(b) + + val c = builder.toString() + + assertEquals("Hello Baeldung", c) + } + + @Test + fun givenTwoStrings_concatenateWithPlusMethod_thenEquals() { + val a = "Hello" + val b = "Baeldung" + val c = a.plus(" ").plus(b) + + assertEquals("Hello Baeldung", c) + } + +} From 8d65e267e65653d485744589cc398c78e5a565b7 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 15 Sep 2018 17:15:15 +0300 Subject: [PATCH 12/24] add bidimap key test --- .../baeldung/commons/collections/BidiMapUnitTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java b/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java index e46d8654a2..64e13a277e 100644 --- a/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java +++ b/libraries/src/test/java/com/baeldung/commons/collections/BidiMapUnitTest.java @@ -42,4 +42,13 @@ public class BidiMapUnitTest { map.put("key1", "value1"); assertEquals(map.getKey("value1"), "key1"); } + + @Test + public void givenKeyValue_whenAddValue_thenReplaceFirstKey() { + BidiMap map = new DualHashBidiMap<>(); + map.put("key1", "value1"); + map.put("key2", "value1"); + assertEquals(map.size(), 1); + assertFalse(map.containsKey("key1")); + } } From 265c01575180d64f7075db4e0a57d96b89f273f1 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Mon, 10 Sep 2018 00:00:06 +0530 Subject: [PATCH 13/24] [BAEL-8870] - Added modules in the parent module build --- pom.xml | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/pom.xml b/pom.xml index 7a7e2d7f64..35f5667656 100644 --- a/pom.xml +++ b/pom.xml @@ -604,6 +604,80 @@ jnosql spring-boot-angular-ecommerce jta + + java-websocket + + + + apache-bval + apache-shiro + apache-spark + + checker-plugin + + + core-java-sun + custom-pmd + dagger + data-structures + dubbo + + + + + jni + jooby + + + + ratpack + + spring-boot-autoconfiguration + spring-boot-custom-starter + + + spring-data-rest-querydsl + + spring-mobile + + spring-mvc-simple + + spring-rest-hal-browser + spring-rest-shell + spring-rest-template + spring-roo + spring-security-stormpath + sse-jaxrs + + stripe + + + wicket + xstream + cas/cas-secured-app + + + guest/deep-jsf + + + + guest/memory-leaks + guest/remote-debugging + guest/spring-boot-app + + + guest/thread-pools + guest/tomcat-app + jenkins/hello-world + + + + spring-boot-custom-starter/greeter + spring-boot-h2/spring-boot-h2-database + spring-boot-h2/spring-boot-h2-remote-app + guest\webservices\rest-client + + guest\webservices\spring-rest-service From 3c89c8c7f309459817cd46dc5f91126b8742be65 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sat, 15 Sep 2018 19:40:50 +0530 Subject: [PATCH 14/24] [BAEL-8870] - Commented guest modules and added in the intergratopm profile too --- pom.xml | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 83 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 35f5667656..18ff0f70de 100644 --- a/pom.xml +++ b/pom.xml @@ -657,17 +657,17 @@ cas/cas-secured-app - guest/deep-jsf - + + - guest/memory-leaks - guest/remote-debugging - guest/spring-boot-app + + + - guest/thread-pools - guest/tomcat-app + + jenkins/hello-world @@ -675,9 +675,9 @@ spring-boot-custom-starter/greeter spring-boot-h2/spring-boot-h2-database spring-boot-h2/spring-boot-h2-remote-app - guest\webservices\rest-client + - guest\webservices\spring-rest-service + @@ -921,7 +921,80 @@ - + + java-websocket + + + + apache-bval + apache-shiro + apache-spark + + checker-plugin + + + core-java-sun + custom-pmd + dagger + data-structures + dubbo + + + + + jni + jooby + + + + ratpack + + spring-boot-autoconfiguration + spring-boot-custom-starter + + + spring-data-rest-querydsl + + spring-mobile + + spring-mvc-simple + + spring-rest-hal-browser + spring-rest-shell + spring-rest-template + spring-roo + spring-security-stormpath + sse-jaxrs + + stripe + + + wicket + xstream + cas/cas-secured-app + + + + + + + + + + + + + + jenkins/hello-world + + + + spring-boot-custom-starter/greeter + spring-boot-h2/spring-boot-h2-database + spring-boot-h2/spring-boot-h2-remote-app + + + From 2603129320a098743069f7158a9d93a1c40d6b7b Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sat, 15 Sep 2018 20:57:55 +0530 Subject: [PATCH 15/24] [BAEL-8870] - Commented jws module for build failure --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 18ff0f70de..66293fe31b 100644 --- a/pom.xml +++ b/pom.xml @@ -405,7 +405,7 @@ json jsoup testing-modules/junit-5 - jws + libraries libraries-data libraries-server From 31af57528e1e8a853f9b3f63e91b4e4a187c0392 Mon Sep 17 00:00:00 2001 From: rozagerardo Date: Sun, 16 Sep 2018 01:46:42 -0300 Subject: [PATCH 16/24] [BAEL-1626] testing-modules | A Quick Guide to @TestPropertySource (#5255) * *added tests using testpropertysource * fix: using property for version in pom file * fix, added dependency with compile scope to build successfully on mvn clean install --- .../spring-context-testing/pom.xml | 25 ++++++++++++++++++ .../ClassUsingProperty.java | 15 +++++++++++ ...aultTestPropertySourceIntegrationTest.java | 26 +++++++++++++++++++ ...tionTestPropertySourceIntegrationTest.java | 26 +++++++++++++++++++ ...tiesTestPropertySourceIntegrationTest.java | 26 +++++++++++++++++++ ...stPropertySourceIntegrationTest.properties | 1 + .../test/resources/other-location.properties | 1 + 7 files changed, 120 insertions(+) create mode 100644 testing-modules/spring-context-testing/pom.xml create mode 100644 testing-modules/spring-context-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java create mode 100644 testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.java create mode 100644 testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/LocationTestPropertySourceIntegrationTest.java create mode 100644 testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java create mode 100644 testing-modules/spring-context-testing/src/test/resources/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.properties create mode 100644 testing-modules/spring-context-testing/src/test/resources/other-location.properties diff --git a/testing-modules/spring-context-testing/pom.xml b/testing-modules/spring-context-testing/pom.xml new file mode 100644 index 0000000000..148192d6c5 --- /dev/null +++ b/testing-modules/spring-context-testing/pom.xml @@ -0,0 +1,25 @@ + + 4.0.0 + com.baeldung + spring-context-testing + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter + ${spring.boot.starter.version} + + + org.springframework.boot + spring-boot-starter-test + test + ${spring.boot.starter.version} + + + + + 2.0.4.RELEASE + + diff --git a/testing-modules/spring-context-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java b/testing-modules/spring-context-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java new file mode 100644 index 0000000000..d545daf0df --- /dev/null +++ b/testing-modules/spring-context-testing/src/main/java/com/baeldung/testpropertysource/ClassUsingProperty.java @@ -0,0 +1,15 @@ +package com.baeldung.testpropertysource; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +@Component +public class ClassUsingProperty { + + @Value("${baeldung.testpropertysource.one}") + private String propertyOne; + + public String retrievePropertyOne() { + return propertyOne; + } +} diff --git a/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.java b/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.java new file mode 100644 index 0000000000..f983abdd54 --- /dev/null +++ b/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.java @@ -0,0 +1,26 @@ +package com.baeldung.testpropertysource; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = ClassUsingProperty.class) +@TestPropertySource +public class DefaultTestPropertySourceIntegrationTest { + + @Autowired + ClassUsingProperty classUsingProperty; + + @Test + public void givenDefaultTestPropertySource_whenVariableOneRetrieved_thenValueInDefaultFileReturned() { + String output = classUsingProperty.retrievePropertyOne(); + + assertThat(output).isEqualTo("default-value"); + } +} diff --git a/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/LocationTestPropertySourceIntegrationTest.java b/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/LocationTestPropertySourceIntegrationTest.java new file mode 100644 index 0000000000..93d4cc58da --- /dev/null +++ b/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/LocationTestPropertySourceIntegrationTest.java @@ -0,0 +1,26 @@ +package com.baeldung.testpropertysource; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = ClassUsingProperty.class) +@TestPropertySource(locations = "/other-location.properties") +public class LocationTestPropertySourceIntegrationTest { + + @Autowired + ClassUsingProperty classUsingProperty; + + @Test + public void givenDefaultTestPropertySource_whenVariableOneRetrieved_thenValueInDefaultFileReturned() { + String output = classUsingProperty.retrievePropertyOne(); + + assertThat(output).isEqualTo("other-location-value"); + } +} diff --git a/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java b/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java new file mode 100644 index 0000000000..d98e2b9f98 --- /dev/null +++ b/testing-modules/spring-context-testing/src/test/java/com/baeldung/testpropertysource/PropertiesTestPropertySourceIntegrationTest.java @@ -0,0 +1,26 @@ +package com.baeldung.testpropertysource; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@ContextConfiguration(classes = ClassUsingProperty.class) +@TestPropertySource(locations = "/other-location.properties", properties = "baeldung.testpropertysource.one=other-properties-value") +public class PropertiesTestPropertySourceIntegrationTest { + + @Autowired + ClassUsingProperty classUsingProperty; + + @Test + public void givenDefaultTestPropertySource_whenVariableOneRetrieved_thenValueInDefaultFileReturned() { + String output = classUsingProperty.retrievePropertyOne(); + + assertThat(output).isEqualTo("other-properties-value"); + } +} diff --git a/testing-modules/spring-context-testing/src/test/resources/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.properties b/testing-modules/spring-context-testing/src/test/resources/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.properties new file mode 100644 index 0000000000..a443a2b776 --- /dev/null +++ b/testing-modules/spring-context-testing/src/test/resources/com/baeldung/testpropertysource/DefaultTestPropertySourceIntegrationTest.properties @@ -0,0 +1 @@ +baeldung.testpropertysource.one=default-value \ No newline at end of file diff --git a/testing-modules/spring-context-testing/src/test/resources/other-location.properties b/testing-modules/spring-context-testing/src/test/resources/other-location.properties new file mode 100644 index 0000000000..6ef791ec75 --- /dev/null +++ b/testing-modules/spring-context-testing/src/test/resources/other-location.properties @@ -0,0 +1 @@ +baeldung.testpropertysource.one=other-location-value \ No newline at end of file From 77137e4011d7e977f4c8ca0ed131ebf46fb0b196 Mon Sep 17 00:00:00 2001 From: Dhawal Kapil Date: Sun, 16 Sep 2018 11:31:39 +0530 Subject: [PATCH 17/24] BAEL-8965 Update "Spring Bean Scopes" article - Updated changes for new spring bean scopes examples --- spring-all/pom.xml | 9 +++++ .../org/baeldung/scopes/ScopesController.java | 39 +++++++++++++------ .../baeldung/spring/config/ScopesConfig.java | 12 ++++-- .../webapp/WEB-INF/view/scopesExample.jsp | 8 ++-- 4 files changed, 49 insertions(+), 19 deletions(-) diff --git a/spring-all/pom.xml b/spring-all/pom.xml index c4c4cf7963..9df14873a2 100644 --- a/spring-all/pom.xml +++ b/spring-all/pom.xml @@ -45,6 +45,15 @@ spring-shell ${org.springframework.shell.version} + + org.springframework + spring-websocket + + + org.springframework + spring-messaging + + org.springframework diff --git a/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java b/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java index 73df386aff..9257a3aa3a 100644 --- a/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java +++ b/spring-all/src/main/java/org/baeldung/scopes/ScopesController.java @@ -13,21 +13,36 @@ import org.springframework.web.bind.annotation.RequestMapping; public class ScopesController { public static final Logger LOG = LoggerFactory.getLogger(ScopesController.class); - @Resource(name = "requestMessage") - HelloMessageGenerator requestMessage; + @Resource(name = "requestScopedBean") + HelloMessageGenerator requestScopedBean; - @Resource(name = "sessionMessage") - HelloMessageGenerator sessionMessage; + @Resource(name = "sessionScopedBean") + HelloMessageGenerator sessionScopedBean; - @RequestMapping("/scopes") - public String getScopes(final Model model) { - LOG.info("Request Message:" + requestMessage.getMessage()); - LOG.info("Session Message" + sessionMessage.getMessage()); - requestMessage.setMessage("Good morning!"); - sessionMessage.setMessage("Good afternoon!"); - model.addAttribute("requestMessage", requestMessage.getMessage()); - model.addAttribute("sessionMessage", sessionMessage.getMessage()); + @Resource(name = "applicationScopedBean") + HelloMessageGenerator applicationScopedBean; + + @RequestMapping("/scopes/request") + public String getRequestScopeMessage(final Model model) { + model.addAttribute("previousMessage", requestScopedBean.getMessage()); + requestScopedBean.setMessage("Request Scope Message!"); + model.addAttribute("currentMessage", requestScopedBean.getMessage()); return "scopesExample"; } + @RequestMapping("/scopes/session") + public String getSessionScopeMessage(final Model model) { + model.addAttribute("previousMessage", sessionScopedBean.getMessage()); + sessionScopedBean.setMessage("Session Scope Message!"); + model.addAttribute("currentMessage", sessionScopedBean.getMessage()); + return "scopesExample"; + } + + @RequestMapping("/scopes/application") + public String getApplicationScopeMessage(final Model model) { + model.addAttribute("previousMessage", applicationScopedBean.getMessage()); + applicationScopedBean.setMessage("Application Scope Message!"); + model.addAttribute("currentMessage", applicationScopedBean.getMessage()); + return "scopesExample"; + } } diff --git a/spring-all/src/main/java/org/baeldung/spring/config/ScopesConfig.java b/spring-all/src/main/java/org/baeldung/spring/config/ScopesConfig.java index fb34725508..b5fe494ee2 100644 --- a/spring-all/src/main/java/org/baeldung/spring/config/ScopesConfig.java +++ b/spring-all/src/main/java/org/baeldung/spring/config/ScopesConfig.java @@ -27,19 +27,25 @@ public class ScopesConfig { @Bean @Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS) - public HelloMessageGenerator requestMessage() { + public HelloMessageGenerator requestScopedBean() { return new HelloMessageGenerator(); } @Bean @Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS) - public HelloMessageGenerator sessionMessage() { + public HelloMessageGenerator sessionScopedBean() { return new HelloMessageGenerator(); } @Bean @Scope(value = WebApplicationContext.SCOPE_APPLICATION, proxyMode = ScopedProxyMode.TARGET_CLASS) - public HelloMessageGenerator globalSessionMessage() { + public HelloMessageGenerator applicationScopedBean() { + return new HelloMessageGenerator(); + } + + @Bean + @Scope(scopeName = "websocket", proxyMode = ScopedProxyMode.TARGET_CLASS) + public HelloMessageGenerator websocketScopedBean() { return new HelloMessageGenerator(); } diff --git a/spring-all/src/main/webapp/WEB-INF/view/scopesExample.jsp b/spring-all/src/main/webapp/WEB-INF/view/scopesExample.jsp index 7974cf0220..0946f1b5ef 100644 --- a/spring-all/src/main/webapp/WEB-INF/view/scopesExample.jsp +++ b/spring-all/src/main/webapp/WEB-INF/view/scopesExample.jsp @@ -2,9 +2,9 @@ -

Bean Scopes Examples

-
- Request Message: ${requestMessage }
- Session Message: ${sessionMessage } +

Bean Scopes Examples

+
Previous Message: ${previousMessage } +
Current Message: ${currentMessage } +
\ No newline at end of file From 476c07f24475c2f03569ea9a0770bd7ac464d44f Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 16 Sep 2018 12:51:27 +0300 Subject: [PATCH 18/24] Create README.md --- optaplanner/README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 optaplanner/README.md diff --git a/optaplanner/README.md b/optaplanner/README.md new file mode 100644 index 0000000000..d793be1f2a --- /dev/null +++ b/optaplanner/README.md @@ -0,0 +1,3 @@ +### Relevant articles + +- [Guide to OptaPlanner](https://www.baeldung.com/opta-planner) From 9108183846362b1e2a5db3fb930f7384115ede3e Mon Sep 17 00:00:00 2001 From: Hai Nguyen Date: Mon, 17 Sep 2018 00:02:36 +0800 Subject: [PATCH 19/24] BAEL-2147 Kotlin Data Class from Json using GSON (#5220) * BAEL-1846: Java Image to Base64 String * Move from using main method to Junit test * Update to use environment variables for testing * reformat and add test file * spring boot jsp security taglibs * add more test * add more test * refactor spring config * refactor spring config * Update README.md * fi alignment * fix requested comments * additional tests and content * additional tests and content * update examples * Delete Readme file * edit form example * adding example for spring boot security tag libs * Remove old tag libs module * BAEL-2147 Add GsonTest * BAEL-2147 Remove unused import --- .../com/baeldung/kotlin/gson/GsonUnitTest.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core-kotlin/src/test/kotlin/com/baeldung/kotlin/gson/GsonUnitTest.kt diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/gson/GsonUnitTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/gson/GsonUnitTest.kt new file mode 100644 index 0000000000..bdf44d3b49 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/gson/GsonUnitTest.kt @@ -0,0 +1,30 @@ +package com.baeldung.kotlin.gson + +import com.google.gson.Gson + +import org.junit.Assert +import org.junit.Test + +class GsonUnitTest { + + var gson = Gson() + + @Test + fun givenObject_thenGetJSONString() { + var jsonString = gson.toJson(TestModel(1,"Test")) + Assert.assertEquals(jsonString, "{\"id\":1,\"description\":\"Test\"}") + } + + @Test + fun givenJSONString_thenGetObject() { + var jsonString = "{\"id\":1,\"description\":\"Test\"}"; + var testModel = gson.fromJson(jsonString, TestModel::class.java) + Assert.assertEquals(testModel.id, 1) + Assert.assertEquals(testModel.description, "Test") + } + + data class TestModel( + val id: Int, + val description: String + ) +} \ No newline at end of file From cd242f89d3c304bdc53443d91d59d4d1b96ed7dc Mon Sep 17 00:00:00 2001 From: Predrag Maric Date: Sun, 16 Sep 2018 18:05:22 +0200 Subject: [PATCH 20/24] BAEL-2070 Renamed application class (#5266) --- ...uration.java => SpringDependenciesExampleApplication.java} | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename spring-core/src/main/java/com/baeldung/dependency/exception/app/{CustomConfiguration.java => SpringDependenciesExampleApplication.java} (73%) diff --git a/spring-core/src/main/java/com/baeldung/dependency/exception/app/CustomConfiguration.java b/spring-core/src/main/java/com/baeldung/dependency/exception/app/SpringDependenciesExampleApplication.java similarity index 73% rename from spring-core/src/main/java/com/baeldung/dependency/exception/app/CustomConfiguration.java rename to spring-core/src/main/java/com/baeldung/dependency/exception/app/SpringDependenciesExampleApplication.java index 4366cb617a..e45438a9fe 100644 --- a/spring-core/src/main/java/com/baeldung/dependency/exception/app/CustomConfiguration.java +++ b/spring-core/src/main/java/com/baeldung/dependency/exception/app/SpringDependenciesExampleApplication.java @@ -6,8 +6,8 @@ import org.springframework.context.annotation.ComponentScan; @SpringBootApplication @ComponentScan(basePackages = "com.baeldung.dependency.exception") -public class CustomConfiguration { +public class SpringDependenciesExampleApplication { public static void main(String[] args) { - SpringApplication.run(CustomConfiguration.class, args); + SpringApplication.run(SpringDependenciesExampleApplication.class, args); } } From 237f8ef944d8ac34e71ad2eb0c6280b4c6609072 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 16 Sep 2018 19:56:05 +0300 Subject: [PATCH 21/24] fix spring-jpa start --- .../java/org/baeldung/config/PersistenceJPAConfig.java | 6 +++--- .../src/main/java/org/baeldung/config/WebInitializer.java | 2 +- .../{criteria/repository => dao}/BookRepository.java | 4 ++-- .../repository => dao}/BookRepositoryCustom.java | 4 ++-- .../{criteria => }/dao/BookRepositoryImpl.java | 5 ++--- .../{criteria/repository => dao}/BookService.java | 8 ++++---- .../{criteria/repository => dao}/BookSpecifications.java | 4 ++-- .../baeldung/persistence/{criteria => }/model/Book.java | 2 +- .../spring-jpa/src/main/resources/persistence.xml | 2 -- 9 files changed, 17 insertions(+), 20 deletions(-) rename persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/{criteria/repository => dao}/BookRepository.java (71%) rename persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/{criteria/repository => dao}/BookRepositoryCustom.java (58%) rename persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/{criteria => }/dao/BookRepositoryImpl.java (87%) rename persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/{criteria/repository => dao}/BookService.java (63%) rename persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/{criteria/repository => dao}/BookSpecifications.java (78%) rename persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/{criteria => }/model/Book.java (91%) diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java index 78c4116c67..ec0d4bca3c 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/PersistenceJPAConfig.java @@ -78,9 +78,9 @@ public class PersistenceJPAConfig { final Properties hibernateProperties = new Properties(); hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); - hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", env.getProperty("hibernate.cache.use_second_level_cache")); - hibernateProperties.setProperty("hibernate.cache.use_query_cache", env.getProperty("hibernate.cache.use_query_cache")); - // hibernateProperties.setProperty("hibernate.globally_quoted_identifiers", "true"); + hibernateProperties.setProperty("hibernate.cache.use_second_level_cache", "false"); + + return hibernateProperties; } diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java index 1c8ce5400f..cf6e69eb39 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/config/WebInitializer.java @@ -5,7 +5,7 @@ import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatche public class WebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class[] getRootConfigClasses() { - return new Class[] { PersistenceJNDIConfig.class }; + return new Class[] { PersistenceJPAConfig.class }; } @Override diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookRepository.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepository.java similarity index 71% rename from persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookRepository.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepository.java index af30ae461e..114cf48c7c 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookRepository.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepository.java @@ -1,6 +1,6 @@ -package org.baeldung.persistence.criteria.repository; +package org.baeldung.persistence.dao; -import org.baeldung.persistence.criteria.model.Book; +import org.baeldung.persistence.model.Book; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookRepositoryCustom.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepositoryCustom.java similarity index 58% rename from persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookRepositoryCustom.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepositoryCustom.java index 35330cfa3c..b939907572 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookRepositoryCustom.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepositoryCustom.java @@ -1,8 +1,8 @@ -package org.baeldung.persistence.criteria.repository; +package org.baeldung.persistence.dao; import java.util.List; -import org.baeldung.persistence.criteria.model.Book; +import org.baeldung.persistence.model.Book; public interface BookRepositoryCustom { diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/dao/BookRepositoryImpl.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepositoryImpl.java similarity index 87% rename from persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/dao/BookRepositoryImpl.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepositoryImpl.java index f782d69e1e..6e9aa998d7 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/dao/BookRepositoryImpl.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookRepositoryImpl.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.criteria.dao; +package org.baeldung.persistence.dao; import java.util.ArrayList; import java.util.List; @@ -10,8 +10,7 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; -import org.baeldung.persistence.criteria.model.Book; -import org.baeldung.persistence.criteria.repository.BookRepositoryCustom; +import org.baeldung.persistence.model.Book; import org.springframework.stereotype.Repository; @Repository diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookService.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookService.java similarity index 63% rename from persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookService.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookService.java index 7b1aff857e..88b769e9bf 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookService.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookService.java @@ -1,12 +1,12 @@ -package org.baeldung.persistence.criteria.repository; +package org.baeldung.persistence.dao; -import static org.baeldung.persistence.criteria.repository.BookSpecifications.hasAuthor; -import static org.baeldung.persistence.criteria.repository.BookSpecifications.titleContains; +import static org.baeldung.persistence.dao.BookSpecifications.hasAuthor; +import static org.baeldung.persistence.dao.BookSpecifications.titleContains; import static org.springframework.data.jpa.domain.Specifications.where; import java.util.List; -import org.baeldung.persistence.criteria.model.Book; +import org.baeldung.persistence.model.Book; import org.springframework.stereotype.Service; @Service diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookSpecifications.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookSpecifications.java similarity index 78% rename from persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookSpecifications.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookSpecifications.java index 392b750977..ed9540060d 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/repository/BookSpecifications.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/dao/BookSpecifications.java @@ -1,6 +1,6 @@ -package org.baeldung.persistence.criteria.repository; +package org.baeldung.persistence.dao; -import org.baeldung.persistence.criteria.model.Book; +import org.baeldung.persistence.model.Book; import org.springframework.data.jpa.domain.Specification; public class BookSpecifications { diff --git a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/model/Book.java b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/Book.java similarity index 91% rename from persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/model/Book.java rename to persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/Book.java index beb6c0190c..754bd179d1 100644 --- a/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/criteria/model/Book.java +++ b/persistence-modules/spring-jpa/src/main/java/org/baeldung/persistence/model/Book.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.criteria.model; +package org.baeldung.persistence.model; import javax.persistence.Entity; import javax.persistence.Id; diff --git a/persistence-modules/spring-jpa/src/main/resources/persistence.xml b/persistence-modules/spring-jpa/src/main/resources/persistence.xml index 65bad29cdc..6304fa0a65 100644 --- a/persistence-modules/spring-jpa/src/main/resources/persistence.xml +++ b/persistence-modules/spring-jpa/src/main/resources/persistence.xml @@ -21,8 +21,6 @@ ${hibernate.hbm2ddl.auto} ${hibernate.dialect} - ${hibernate.cache.use_second_level_cache} - ${hibernate.cache.use_query_cache} From 4a84a83597277d5ad3476d6fcc62bb4ff757db12 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 16 Sep 2018 20:38:28 +0300 Subject: [PATCH 22/24] fix surefire parallel config --- spring-5/pom.xml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/spring-5/pom.xml b/spring-5/pom.xml index 9f60b8a364..293edb5bda 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -1,5 +1,6 @@ - 4.0.0 com.baeldung @@ -134,7 +135,26 @@ + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + methods + true + + **/*IntegrationTest.java + **/*IntTest.java + **/*LongRunningUnitTest.java + **/*ManualTest.java + **/JdbcTest.java + **/*LiveTest.java + + + +
@@ -142,6 +162,8 @@ 1.5.6 4.1 ${project.build.directory}/generated-snippets + 2.21.0 + From c493e00819cf02c52556bdaca2ae95723b09a4a7 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 16 Sep 2018 22:03:38 +0300 Subject: [PATCH 23/24] add mappingstrategy opencsv method --- .../opencsv/examples/sync/BeanExamples.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libraries/src/main/java/com/baeldung/opencsv/examples/sync/BeanExamples.java b/libraries/src/main/java/com/baeldung/opencsv/examples/sync/BeanExamples.java index 76d044ca60..086f32677e 100644 --- a/libraries/src/main/java/com/baeldung/opencsv/examples/sync/BeanExamples.java +++ b/libraries/src/main/java/com/baeldung/opencsv/examples/sync/BeanExamples.java @@ -18,16 +18,19 @@ import java.util.List; public class BeanExamples { public static List beanBuilderExample(Path path, Class clazz) { + ColumnPositionMappingStrategy ms = new ColumnPositionMappingStrategy(); + return beanBuilderExample(path, clazz, ms); + } + + public static List beanBuilderExample(Path path, Class clazz, MappingStrategy ms) { CsvTransfer csvTransfer = new CsvTransfer(); try { - ColumnPositionMappingStrategy ms = new ColumnPositionMappingStrategy(); ms.setType(clazz); Reader reader = Files.newBufferedReader(path); - CsvToBean cb = new CsvToBeanBuilder(reader) - .withType(clazz) - .withMappingStrategy(ms) - .build(); + CsvToBean cb = new CsvToBeanBuilder(reader).withType(clazz) + .withMappingStrategy(ms) + .build(); csvTransfer.setCsvList(cb.parse()); reader.close(); @@ -40,11 +43,10 @@ public class BeanExamples { public static String writeCsvFromBean(Path path) { try { - Writer writer = new FileWriter(path.toString()); + Writer writer = new FileWriter(path.toString()); - StatefulBeanToCsv sbc = new StatefulBeanToCsvBuilder(writer) - .withSeparator(CSVWriter.DEFAULT_SEPARATOR) - .build(); + StatefulBeanToCsv sbc = new StatefulBeanToCsvBuilder(writer).withSeparator(CSVWriter.DEFAULT_SEPARATOR) + .build(); List list = new ArrayList<>(); list.add(new WriteExampleBean("Test1", "sfdsf", "fdfd")); From 845564612507d91fd69c04cb01115d3cbd65ffc4 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Mon, 17 Sep 2018 22:15:58 +0200 Subject: [PATCH 24/24] Rename CoroutinesTest.kt to CoroutinesUnitTest.kt (#5281) --- .../baeldung/kotlin/{CoroutinesTest.kt => CoroutinesUnitTest.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename core-kotlin/src/test/kotlin/com/baeldung/kotlin/{CoroutinesTest.kt => CoroutinesUnitTest.kt} (100%) diff --git a/core-kotlin/src/test/kotlin/com/baeldung/kotlin/CoroutinesTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/kotlin/CoroutinesUnitTest.kt similarity index 100% rename from core-kotlin/src/test/kotlin/com/baeldung/kotlin/CoroutinesTest.kt rename to core-kotlin/src/test/kotlin/com/baeldung/kotlin/CoroutinesUnitTest.kt