diff --git a/guest/logback-example/pom.xml b/guest/logback-example/pom.xml
new file mode 100644
index 0000000000..9d88c94197
--- /dev/null
+++ b/guest/logback-example/pom.xml
@@ -0,0 +1,41 @@
+
+ 4.0.0
+ com.stackify
+ logback-example
+ 0.0.1-SNAPSHOT
+
+
+
+ ch.qos.logback
+ logback-classic
+ 1.2.3
+
+
+
+ junit
+ junit
+ 4.12
+
+
+
+ org.codehaus.janino
+ janino
+ 3.0.7
+
+
+
+
+
+
+
+ maven-compiler-plugin
+ 3.5
+
+ 1.8
+ 1.8
+
+
+
+
+
\ No newline at end of file
diff --git a/guest/logback-example/src/main/java/com/stackify/logging/IgnoreLoggerFilter.java b/guest/logback-example/src/main/java/com/stackify/logging/IgnoreLoggerFilter.java
new file mode 100644
index 0000000000..c0eb414588
--- /dev/null
+++ b/guest/logback-example/src/main/java/com/stackify/logging/IgnoreLoggerFilter.java
@@ -0,0 +1,28 @@
+package com.stackify.logging;
+
+import org.slf4j.Marker;
+
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.turbo.TurboFilter;
+import ch.qos.logback.core.spi.FilterReply;
+
+public class IgnoreLoggerFilter extends TurboFilter {
+
+ private String loggerName;
+
+ @Override
+ public FilterReply decide(Marker marker, Logger logger, Level level, String format, Object[] params, Throwable t) {
+ if (loggerName == null) {
+ return FilterReply.NEUTRAL;
+ } else if (loggerName.equals(logger.getName())) {
+ return FilterReply.DENY;
+ } else
+ return FilterReply.NEUTRAL;
+ }
+
+ public void setLoggerName(String loggerName) {
+ this.loggerName = loggerName;
+ }
+
+}
diff --git a/guest/logback-example/src/main/java/com/stackify/models/Employee.java b/guest/logback-example/src/main/java/com/stackify/models/Employee.java
new file mode 100644
index 0000000000..1d040b372b
--- /dev/null
+++ b/guest/logback-example/src/main/java/com/stackify/models/Employee.java
@@ -0,0 +1,43 @@
+package com.stackify.models;
+
+public class Employee {
+
+ private String email;
+ private String name;
+
+ private double salary;
+
+ public Employee() {
+ }
+
+ public Employee(String email, String name, double salary) {
+ this.email = email;
+ this.name = name;
+ this.salary = salary;
+ }
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public double getSalary() {
+ return salary;
+ }
+
+ public void setSalary(double salary) {
+ this.salary = salary;
+ }
+
+}
diff --git a/guest/logback-example/src/main/java/com/stackify/services/EmployeeService.java b/guest/logback-example/src/main/java/com/stackify/services/EmployeeService.java
new file mode 100644
index 0000000000..1795101f40
--- /dev/null
+++ b/guest/logback-example/src/main/java/com/stackify/services/EmployeeService.java
@@ -0,0 +1,11 @@
+package com.stackify.services;
+
+import com.stackify.models.Employee;
+
+public class EmployeeService {
+
+ public double calculateBonus(Employee user) {
+ return 0.1 * user.getSalary();
+ }
+
+}
diff --git a/guest/logback-example/src/main/resources/application.properties b/guest/logback-example/src/main/resources/application.properties
new file mode 100644
index 0000000000..601f964ff3
--- /dev/null
+++ b/guest/logback-example/src/main/resources/application.properties
@@ -0,0 +1 @@
+env=dev
\ No newline at end of file
diff --git a/guest/logback-example/src/main/resources/logback.xml b/guest/logback-example/src/main/resources/logback.xml
new file mode 100644
index 0000000000..d8ec24c7c3
--- /dev/null
+++ b/guest/logback-example/src/main/resources/logback.xml
@@ -0,0 +1,151 @@
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
+
+ System.out
+
+
+
+
+
+
+
+
+ log-%d{yyyy-MM-dd}.log
+ 30
+ 3GB
+
+
+ 3MB
+
+
+ %d [%thread] %-5level %logger{50} - %msg%n
+
+
+
+
+
+ userRole
+ ANONYMOUS
+
+
+
+ ${userRole}.log
+
+ %d [%thread] %level %mdc %logger{50} - %msg%n
+
+
+
+
+
+
+
+
+ %d %green([%thread]) %highlight(%level) %logger{50} - %msg%n
+
+
+
+
+
+
+ %thread%level%logger%msg
+
+
+ log.html
+
+
+
+
+
+ ERROR
+ ACCEPT
+ DENY
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
+
+ System.err
+
+
+
+
+ WARN
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
+
+
+
+
+
+
+ return (level > DEBUG && message.toLowerCase().contains("employee"));
+
+ DENY
+ NEUTRAL
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
+
+
+
+
+
+ 2
+
+
+
+ ignoredColorLogger
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/guest/logback-example/src/test/java/com/stackify/services/EmployeeServiceTest.java b/guest/logback-example/src/test/java/com/stackify/services/EmployeeServiceTest.java
new file mode 100644
index 0000000000..187b27e1df
--- /dev/null
+++ b/guest/logback-example/src/test/java/com/stackify/services/EmployeeServiceTest.java
@@ -0,0 +1,74 @@
+package com.stackify.services;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
+
+import com.stackify.models.Employee;
+
+import ch.qos.logback.classic.Level;
+
+public class EmployeeServiceTest {
+ private static final Logger logger = LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
+
+ private EmployeeService employeeService = new EmployeeService();
+
+ @Test
+ public void testAppenders() {
+ Logger rollingFileLogger = LoggerFactory.getLogger("rollingFileLogger");
+ rollingFileLogger.info("Testing rolling file logger");
+
+ MDC.put("userRole", "ADMIN");
+ Logger siftingLogger = LoggerFactory.getLogger("roleSiftingLogger");
+ siftingLogger.info("Admin Action");
+ }
+
+ @Test
+ public void testLayouts() {
+ Logger htmlLogger = LoggerFactory.getLogger("htmlLogger");
+ htmlLogger.error("Employee Information Update Failed");
+ htmlLogger.info("New Account Created");
+
+ Logger colorLogger = LoggerFactory.getLogger("colorLogger");
+ colorLogger.error("Employee Information Update Failed");
+ colorLogger.info("New Account Created");
+ }
+
+ @Test
+ public void testLogLevel() {
+ ch.qos.logback.classic.Logger rollingFileLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger("rollingFileLogger");
+ rollingFileLogger.setLevel(Level.DEBUG);
+ rollingFileLogger.debug("Testing Log Level");
+ }
+
+ @Test
+ public void testParameter() {
+ Employee employee = new Employee("john@gmail.com", "John", 2000);
+ if (logger.isDebugEnabled()) {
+ logger.debug("The bonus for employee: " + employee.getName() + " is " + employeeService.calculateBonus(employee));
+ }
+ logger.debug("The bonus for employee {} is {}", employee.getName(), employeeService.calculateBonus(employee));
+ }
+
+ @Test
+ public void testFilters() {
+ Logger levelFilterLogger = LoggerFactory.getLogger("levelFilterLogger");
+ levelFilterLogger.error("Employee Information Update Failed");
+ Logger thresholdFilterLogger = LoggerFactory.getLogger("thresholdFilterLogger");
+ thresholdFilterLogger.trace("Employee record inserted");
+ Logger evaluatorFilterLogger = LoggerFactory.getLogger("evaluatorFilterLogger");
+ evaluatorFilterLogger.debug("Employee account deactivated");
+ }
+
+ @Test
+ public void testIgnoredLogger() {
+ Logger colorLogger = LoggerFactory.getLogger("ignoredColorLogger");
+ colorLogger.info("Ignored Log Message");
+ }
+
+ @Test
+ public void testConditionalConfiguration() {
+ logger.trace("Employee record updated");
+ }
+}
diff --git a/libraries/pom.xml b/libraries/pom.xml
index cf77d197a2..e9603b1453 100644
--- a/libraries/pom.xml
+++ b/libraries/pom.xml
@@ -105,6 +105,92 @@
+
+
+
+ maven-antrun-plugin
+ 1.8
+
+
+ generateMithra
+ generate-sources
+
+ run
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ com.goldmansachs.reladomo
+ reladomogen
+ ${reladomo.version}
+
+
+
+ com.goldmansachs.reladomo
+ reladomo-gen-util
+ ${reladomo.version}
+
+
+
+
+
+ org.codehaus.mojo
+ build-helper-maven-plugin
+ 3.0.0
+
+
+ add-source
+ generate-sources
+
+ add-source
+
+
+
+ ${project.build.directory}/generated-sources/reladomo
+
+
+
+
+ add-resource
+ generate-resources
+
+ add-resource
+
+
+
+
+ ${project.build.directory}/generated-db/
+
+
+
+
+
+
+
+
@@ -497,6 +583,16 @@
gt-swing
${geotools.version}
+
+ com.goldmansachs.reladomo
+ reladomo
+ ${reladomo.version}
+
+
+ com.goldmansachs.reladomo
+ reladomo-test-util
+ ${reladomo.version}
+
@@ -563,6 +659,6 @@
0.6.5
0.9.0
15.2
+ 16.5.1
-
-
+
\ No newline at end of file
diff --git a/libraries/src/main/java/com/baeldung/chronicle/queue/ChronicleQueue.java b/libraries/src/main/java/com/baeldung/chronicle/queue/ChronicleQueue.java
index b7770e0b78..f6bd25c0fe 100644
--- a/libraries/src/main/java/com/baeldung/chronicle/queue/ChronicleQueue.java
+++ b/libraries/src/main/java/com/baeldung/chronicle/queue/ChronicleQueue.java
@@ -7,7 +7,7 @@ import net.openhft.chronicle.ExcerptAppender;
public class ChronicleQueue {
- public static void writeToQueue(
+ static void writeToQueue(
Chronicle chronicle, String stringValue, int intValue, long longValue, double doubleValue)
throws IOException {
ExcerptAppender appender = chronicle.createAppender();
diff --git a/libraries/src/main/java/com/baeldung/reladomo/Department.java b/libraries/src/main/java/com/baeldung/reladomo/Department.java
new file mode 100644
index 0000000000..d26ddafbf4
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/Department.java
@@ -0,0 +1,15 @@
+package com.baeldung.reladomo;
+
+public class Department extends DepartmentAbstract {
+ public Department() {
+ super();
+ // You must not modify this constructor. Mithra calls this internally.
+ // You can call this constructor. You can also add new constructors.
+ }
+
+ public Department(long id, String name) {
+ super();
+ this.setId(id);
+ this.setName(name);
+ }
+}
diff --git a/libraries/src/main/java/com/baeldung/reladomo/DepartmentDatabaseObject.java b/libraries/src/main/java/com/baeldung/reladomo/DepartmentDatabaseObject.java
new file mode 100644
index 0000000000..4cfb5cb055
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/DepartmentDatabaseObject.java
@@ -0,0 +1,4 @@
+package com.baeldung.reladomo;
+public class DepartmentDatabaseObject extends DepartmentDatabaseObjectAbstract
+{
+}
diff --git a/libraries/src/main/java/com/baeldung/reladomo/DepartmentList.java b/libraries/src/main/java/com/baeldung/reladomo/DepartmentList.java
new file mode 100644
index 0000000000..edad6bc1f4
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/DepartmentList.java
@@ -0,0 +1,25 @@
+package com.baeldung.reladomo;
+import com.gs.fw.finder.Operation;
+import java.util.*;
+public class DepartmentList extends DepartmentListAbstract
+{
+ public DepartmentList()
+ {
+ super();
+ }
+
+ public DepartmentList(int initialSize)
+ {
+ super(initialSize);
+ }
+
+ public DepartmentList(Collection c)
+ {
+ super(c);
+ }
+
+ public DepartmentList(Operation operation)
+ {
+ super(operation);
+ }
+}
diff --git a/libraries/src/main/java/com/baeldung/reladomo/Employee.java b/libraries/src/main/java/com/baeldung/reladomo/Employee.java
new file mode 100644
index 0000000000..519e841282
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/Employee.java
@@ -0,0 +1,16 @@
+package com.baeldung.reladomo;
+public class Employee extends EmployeeAbstract
+{
+ public Employee()
+ {
+ super();
+ // You must not modify this constructor. Mithra calls this internally.
+ // You can call this constructor. You can also add new constructors.
+ }
+
+ public Employee(long id, String name){
+ super();
+ this.setId(id);
+ this.setName(name);
+ }
+}
diff --git a/libraries/src/main/java/com/baeldung/reladomo/EmployeeDatabaseObject.java b/libraries/src/main/java/com/baeldung/reladomo/EmployeeDatabaseObject.java
new file mode 100644
index 0000000000..407049f342
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/EmployeeDatabaseObject.java
@@ -0,0 +1,4 @@
+package com.baeldung.reladomo;
+public class EmployeeDatabaseObject extends EmployeeDatabaseObjectAbstract
+{
+}
diff --git a/libraries/src/main/java/com/baeldung/reladomo/EmployeeList.java b/libraries/src/main/java/com/baeldung/reladomo/EmployeeList.java
new file mode 100644
index 0000000000..4e759898c3
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/EmployeeList.java
@@ -0,0 +1,25 @@
+package com.baeldung.reladomo;
+import com.gs.fw.finder.Operation;
+import java.util.*;
+public class EmployeeList extends EmployeeListAbstract
+{
+ public EmployeeList()
+ {
+ super();
+ }
+
+ public EmployeeList(int initialSize)
+ {
+ super(initialSize);
+ }
+
+ public EmployeeList(Collection c)
+ {
+ super(c);
+ }
+
+ public EmployeeList(Operation operation)
+ {
+ super(operation);
+ }
+}
diff --git a/libraries/src/main/java/com/baeldung/reladomo/ReladomoApplication.java b/libraries/src/main/java/com/baeldung/reladomo/ReladomoApplication.java
new file mode 100644
index 0000000000..c6b242d3ae
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/ReladomoApplication.java
@@ -0,0 +1,54 @@
+package com.baeldung.reladomo;
+
+import java.io.InputStream;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.gs.fw.common.mithra.MithraManager;
+import com.gs.fw.common.mithra.MithraManagerProvider;
+
+public class ReladomoApplication {
+
+ public static void main(String[] args) {
+
+ try {
+ ReladomoConnectionManager.getInstance().createTables();
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ }
+
+ MithraManager mithraManager = MithraManagerProvider.getMithraManager();
+ mithraManager.setTransactionTimeout(120);
+
+ try (InputStream is = ReladomoApplication.class.getClassLoader().getResourceAsStream("ReladomoRuntimeConfig.xml")) {
+ MithraManagerProvider.getMithraManager().readConfiguration(is);
+
+ Department department = new Department(1, "IT");
+ Employee employee = new Employee(1, "John");
+ department.getEmployees().add(employee);
+ department.cascadeInsert();
+
+ Department depFound = DepartmentFinder.findByPrimaryKey(1);
+ System.out.println("Department Name:" + department.getName());
+
+ Employee empFound = EmployeeFinder.findOne(EmployeeFinder.name().eq("John"));
+ System.out.println("Employee Id:" + empFound.getId());
+ empFound.setName("Steven");
+ empFound.delete();
+ Department depDetached = DepartmentFinder.findByPrimaryKey(1).getDetachedCopy();
+
+ mithraManager.executeTransactionalCommand(tx -> {
+ Department dep = new Department(2, "HR");
+ Employee emp = new Employee(2, "Jim");
+ dep.getEmployees().add(emp);
+ dep.cascadeInsert();
+ return null;
+ });
+
+ } catch (java.io.IOException e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/libraries/src/main/java/com/baeldung/reladomo/ReladomoConnectionManager.java b/libraries/src/main/java/com/baeldung/reladomo/ReladomoConnectionManager.java
new file mode 100644
index 0000000000..66a8f9ff99
--- /dev/null
+++ b/libraries/src/main/java/com/baeldung/reladomo/ReladomoConnectionManager.java
@@ -0,0 +1,92 @@
+package com.baeldung.reladomo;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.TimeZone;
+import java.util.stream.Stream;
+
+import org.h2.tools.RunScript;
+
+import com.gs.fw.common.mithra.bulkloader.BulkLoader;
+import com.gs.fw.common.mithra.bulkloader.BulkLoaderException;
+import com.gs.fw.common.mithra.connectionmanager.SourcelessConnectionManager;
+import com.gs.fw.common.mithra.connectionmanager.XAConnectionManager;
+import com.gs.fw.common.mithra.databasetype.DatabaseType;
+import com.gs.fw.common.mithra.databasetype.H2DatabaseType;
+
+public class ReladomoConnectionManager implements SourcelessConnectionManager {
+
+ private static ReladomoConnectionManager instance;
+
+ private XAConnectionManager xaConnectionManager;
+
+ private final String databaseName = "myDb";
+
+ public static synchronized ReladomoConnectionManager getInstance() {
+ if (instance == null) {
+ instance = new ReladomoConnectionManager();
+ }
+ return instance;
+ }
+
+ private ReladomoConnectionManager() {
+ this.createConnectionManager();
+ }
+
+ private XAConnectionManager createConnectionManager() {
+ xaConnectionManager = new XAConnectionManager();
+ xaConnectionManager.setDriverClassName("org.h2.Driver");
+ xaConnectionManager.setJdbcConnectionString("jdbc:h2:mem:" + databaseName);
+ xaConnectionManager.setJdbcUser("sa");
+ xaConnectionManager.setJdbcPassword("");
+ xaConnectionManager.setPoolName("My Connection Pool");
+ xaConnectionManager.setInitialSize(1);
+ xaConnectionManager.setPoolSize(10);
+ xaConnectionManager.initialisePool();
+ return xaConnectionManager;
+ }
+
+ @Override
+ public BulkLoader createBulkLoader() throws BulkLoaderException {
+ return null;
+ }
+
+ @Override
+ public Connection getConnection() {
+ return xaConnectionManager.getConnection();
+ }
+
+ @Override
+ public DatabaseType getDatabaseType() {
+ return H2DatabaseType.getInstance();
+ }
+
+ @Override
+ public TimeZone getDatabaseTimeZone() {
+ return TimeZone.getDefault();
+ }
+
+ @Override
+ public String getDatabaseIdentifier() {
+ return databaseName;
+ }
+
+ public void createTables() throws Exception {
+ Path ddlPath = Paths.get(ClassLoader.getSystemResource("sql").toURI());
+
+ try (Connection conn = xaConnectionManager.getConnection(); Stream list = Files.list(ddlPath);) {
+ list.forEach(path -> {
+ try {
+ RunScript.execute(conn, Files.newBufferedReader(path));
+ } catch (SQLException | IOException exc) {
+ exc.printStackTrace();
+ }
+ });
+ }
+ }
+
+}
diff --git a/libraries/src/main/resources/ReladomoRuntimeConfig.xml b/libraries/src/main/resources/ReladomoRuntimeConfig.xml
new file mode 100644
index 0000000000..7181e75406
--- /dev/null
+++ b/libraries/src/main/resources/ReladomoRuntimeConfig.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/libraries/src/main/resources/reladomo/Department.xml b/libraries/src/main/resources/reladomo/Department.xml
new file mode 100644
index 0000000000..a284965cd6
--- /dev/null
+++ b/libraries/src/main/resources/reladomo/Department.xml
@@ -0,0 +1,11 @@
+
+ com.baeldung.reladomo
+ Department
+ departments
+
+
+
+
+ Employee.departmentId = this.id
+
+
\ No newline at end of file
diff --git a/libraries/src/main/resources/reladomo/Employee.xml b/libraries/src/main/resources/reladomo/Employee.xml
new file mode 100644
index 0000000000..00e360bc67
--- /dev/null
+++ b/libraries/src/main/resources/reladomo/Employee.xml
@@ -0,0 +1,9 @@
+
+ com.baeldung.reladomo
+ Employee
+ employees
+
+
+
+
+
\ No newline at end of file
diff --git a/libraries/src/main/resources/reladomo/ReladomoClassList.xml b/libraries/src/main/resources/reladomo/ReladomoClassList.xml
new file mode 100644
index 0000000000..99118a745d
--- /dev/null
+++ b/libraries/src/main/resources/reladomo/ReladomoClassList.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceUnitTest.java b/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceLongRunningUnitTest.java
similarity index 86%
rename from libraries/src/test/java/com/baeldung/awaitility/AsyncServiceUnitTest.java
rename to libraries/src/test/java/com/baeldung/awaitility/AsyncServiceLongRunningUnitTest.java
index 43537965f8..d17a7dcf1b 100644
--- a/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceUnitTest.java
+++ b/libraries/src/test/java/com/baeldung/awaitility/AsyncServiceLongRunningUnitTest.java
@@ -11,10 +11,13 @@ import java.util.concurrent.TimeUnit;
import static org.awaitility.Awaitility.await;
import static org.awaitility.Awaitility.fieldIn;
import static org.awaitility.Awaitility.given;
+import static org.awaitility.Awaitility.setDefaultPollDelay;
+import static org.awaitility.Awaitility.setDefaultPollInterval;
+import static org.awaitility.Awaitility.setDefaultTimeout;
import static org.awaitility.proxy.AwaitilityClassProxy.to;
import static org.hamcrest.Matchers.equalTo;
-public class AsyncServiceUnitTest {
+public class AsyncServiceLongRunningUnitTest {
private AsyncService asyncService;
@Before
@@ -41,9 +44,9 @@ public class AsyncServiceUnitTest {
@Test
public void givenAsyncService_whenInitialize_thenInitOccurs_withDefualts() {
- Awaitility.setDefaultPollInterval(10, TimeUnit.MILLISECONDS);
- Awaitility.setDefaultPollDelay(Duration.ZERO);
- Awaitility.setDefaultTimeout(Duration.ONE_MINUTE);
+ setDefaultPollInterval(10, TimeUnit.MILLISECONDS);
+ setDefaultPollDelay(Duration.ZERO);
+ setDefaultTimeout(Duration.ONE_MINUTE);
asyncService.initialize();
await().until(asyncService::isInitialized);
diff --git a/libraries/src/test/java/com/baeldung/chronicle/queue/ChronicleQueueTest.java b/libraries/src/test/java/com/baeldung/chronicle/queue/ChronicleQueueIntegrationTest.java
similarity index 96%
rename from libraries/src/test/java/com/baeldung/chronicle/queue/ChronicleQueueTest.java
rename to libraries/src/test/java/com/baeldung/chronicle/queue/ChronicleQueueIntegrationTest.java
index e64aaed544..9c0a0ac910 100644
--- a/libraries/src/test/java/com/baeldung/chronicle/queue/ChronicleQueueTest.java
+++ b/libraries/src/test/java/com/baeldung/chronicle/queue/ChronicleQueueIntegrationTest.java
@@ -13,7 +13,7 @@ import net.openhft.chronicle.ChronicleQueueBuilder;
import net.openhft.chronicle.ExcerptTailer;
import net.openhft.chronicle.tools.ChronicleTools;
-public class ChronicleQueueTest {
+public class ChronicleQueueIntegrationTest {
@Test
public void givenSetOfValues_whenWriteToQueue_thenWriteSuccesfully() throws IOException {
diff --git a/libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java b/libraries/src/test/java/com/baeldung/hll/HLLLongRunningUnitTest.java
similarity index 98%
rename from libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java
rename to libraries/src/test/java/com/baeldung/hll/HLLLongRunningUnitTest.java
index e208add3c8..5ecd4442d8 100644
--- a/libraries/src/test/java/com/baeldung/hll/HLLUnitTest.java
+++ b/libraries/src/test/java/com/baeldung/hll/HLLLongRunningUnitTest.java
@@ -11,7 +11,7 @@ import java.util.stream.LongStream;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
-public class HLLUnitTest {
+public class HLLLongRunningUnitTest {
@Test
public void givenHLL_whenAddHugeAmountOfNumbers_thenShouldReturnEstimatedCardinality() {
diff --git a/libraries/src/test/java/com/baeldung/reladomo/ReladomoTest.java b/libraries/src/test/java/com/baeldung/reladomo/ReladomoTest.java
new file mode 100644
index 0000000000..61c29e8aa3
--- /dev/null
+++ b/libraries/src/test/java/com/baeldung/reladomo/ReladomoTest.java
@@ -0,0 +1,38 @@
+package com.baeldung.reladomo;
+
+import static org.junit.Assert.*;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.gs.fw.common.mithra.test.ConnectionManagerForTests;
+import com.gs.fw.common.mithra.test.MithraTestResource;
+
+public class ReladomoTest {
+ private MithraTestResource mithraTestResource;
+
+ @Before
+ public void setUp() throws Exception {
+ this.mithraTestResource = new MithraTestResource("reladomo/ReladomoTestConfig.xml");
+
+ final ConnectionManagerForTests connectionManager = ConnectionManagerForTests.getInstanceForDbName("testDb");
+ this.mithraTestResource.createSingleDatabase(connectionManager);
+
+ mithraTestResource.addTestDataToDatabase("reladomo/test-data.txt", connectionManager);
+
+ this.mithraTestResource.setUp();
+ }
+
+ @Test
+ public void whenGetTestData_thenOk() {
+ Employee employee = EmployeeFinder.findByPrimaryKey(1);
+ assertEquals(employee.getName(), "Paul");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ this.mithraTestResource.tearDown();
+ }
+
+}
diff --git a/libraries/src/test/resources/reladomo/ReladomoTestConfig.xml b/libraries/src/test/resources/reladomo/ReladomoTestConfig.xml
new file mode 100644
index 0000000000..a1951f09b7
--- /dev/null
+++ b/libraries/src/test/resources/reladomo/ReladomoTestConfig.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/libraries/src/test/resources/reladomo/test-data.txt b/libraries/src/test/resources/reladomo/test-data.txt
new file mode 100644
index 0000000000..8e407278ac
--- /dev/null
+++ b/libraries/src/test/resources/reladomo/test-data.txt
@@ -0,0 +1,7 @@
+class com.baeldung.reladomo.Department
+id, name
+1, "Marketing"
+
+class com.baeldung.reladomo.Employee
+id, name
+1, "Paul"
\ No newline at end of file
diff --git a/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/LambdaExpressionsIntegrationTest.java b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/LambdaExpressionsIntegrationTest.java
new file mode 100644
index 0000000000..a1454c16cc
--- /dev/null
+++ b/log4j2/src/test/java/com/baeldung/logging/log4j2/tests/LambdaExpressionsIntegrationTest.java
@@ -0,0 +1,33 @@
+package com.baeldung.logging.log4j2.tests;
+
+import java.util.Random;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.junit.Test;
+
+public class LambdaExpressionsIntegrationTest {
+
+ private static final Logger logger = LogManager.getRootLogger();
+
+ @Test
+ public void whenCheckLogMessage_thenOk() {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Numer is {}", getRandomNumber());
+ }
+ }
+
+ @Test
+ public void whenUseLambdaExpression_thenOk() {
+ logger.trace("Number is {}", () -> getRandomNumber());
+ logger.trace("Name is {} and age is {}", () -> getName(), () -> getRandomNumber());
+ }
+
+ private int getRandomNumber() {
+ return (new Random()).nextInt(10);
+ }
+
+ private String getName() {
+ return "John";
+ }
+}
diff --git a/ratpack/pom.xml b/ratpack/pom.xml
index 7a75ec50b7..3f953b3ed0 100644
--- a/ratpack/pom.xml
+++ b/ratpack/pom.xml
@@ -40,16 +40,38 @@
ratpack-hikari
${ratpack.version}
+
+ io.ratpack
+ ratpack-hystrix
+ ${ratpack.version}
+
+
+ io.ratpack
+ ratpack-rx
+ ${ratpack.version}
+
io.ratpack
ratpack-test
${ratpack.version}
+ test
com.h2database
h2
1.4.193
+
+
+ org.apache.httpcomponents
+ httpclient
+ 4.5.3
+
+
+ org.apache.httpcomponents
+ httpcore
+ 4.4.6
+
diff --git a/ratpack/src/main/java/com/baeldung/hystrix/HystrixAsyncHttpCommand.java b/ratpack/src/main/java/com/baeldung/hystrix/HystrixAsyncHttpCommand.java
new file mode 100644
index 0000000000..a1a19150c3
--- /dev/null
+++ b/ratpack/src/main/java/com/baeldung/hystrix/HystrixAsyncHttpCommand.java
@@ -0,0 +1,54 @@
+package com.baeldung.hystrix;
+
+import com.netflix.hystrix.HystrixCommand;
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import com.netflix.hystrix.HystrixCommandProperties;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.util.EntityUtils;
+
+import java.net.URI;
+import java.util.Collections;
+
+/**
+ * @author aiet
+ */
+public class HystrixAsyncHttpCommand extends HystrixCommand {
+
+ private URI uri;
+ private RequestConfig requestConfig;
+
+ HystrixAsyncHttpCommand(URI uri, int timeoutMillis) {
+ super(Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-async"))
+ .andCommandPropertiesDefaults(HystrixCommandProperties
+ .Setter()
+ .withExecutionTimeoutInMilliseconds(timeoutMillis)));
+ requestConfig = RequestConfig
+ .custom()
+ .setSocketTimeout(timeoutMillis)
+ .setConnectTimeout(timeoutMillis)
+ .setConnectionRequestTimeout(timeoutMillis)
+ .build();
+ this.uri = uri;
+ }
+
+ @Override
+ protected String run() throws Exception {
+ return EntityUtils.toString(HttpClientBuilder
+ .create()
+ .setDefaultRequestConfig(requestConfig)
+ .setDefaultHeaders(Collections.singleton(new BasicHeader("User-Agent", "Baeldung Blocking HttpClient")))
+ .build()
+ .execute(new HttpGet(uri))
+ .getEntity());
+ }
+
+ @Override
+ protected String getFallback() {
+ return "eugenp's async fallback profile";
+ }
+
+}
diff --git a/ratpack/src/main/java/com/baeldung/hystrix/HystrixReactiveHttpCommand.java b/ratpack/src/main/java/com/baeldung/hystrix/HystrixReactiveHttpCommand.java
new file mode 100644
index 0000000000..f9f85c705b
--- /dev/null
+++ b/ratpack/src/main/java/com/baeldung/hystrix/HystrixReactiveHttpCommand.java
@@ -0,0 +1,44 @@
+package com.baeldung.hystrix;
+
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import com.netflix.hystrix.HystrixCommandProperties;
+import com.netflix.hystrix.HystrixObservableCommand;
+import ratpack.http.client.HttpClient;
+import ratpack.rx.RxRatpack;
+import rx.Observable;
+
+import java.net.URI;
+
+/**
+ * @author aiet
+ */
+public class HystrixReactiveHttpCommand extends HystrixObservableCommand {
+
+ private HttpClient httpClient;
+ private URI uri;
+
+ HystrixReactiveHttpCommand(HttpClient httpClient, URI uri, int timeoutMillis) {
+ super(Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-reactive"))
+ .andCommandPropertiesDefaults(HystrixCommandProperties
+ .Setter()
+ .withExecutionTimeoutInMilliseconds(timeoutMillis)));
+ this.httpClient = httpClient;
+ this.uri = uri;
+ }
+
+ @Override
+ protected Observable construct() {
+ return RxRatpack.observe(httpClient
+ .get(uri, requestSpec -> requestSpec.headers(mutableHeaders -> mutableHeaders.add("User-Agent", "Baeldung HttpClient")))
+ .map(receivedResponse -> receivedResponse
+ .getBody()
+ .getText()));
+ }
+
+ @Override
+ protected Observable resumeWithFallback() {
+ return Observable.just("eugenp's reactive fallback profile");
+ }
+
+}
diff --git a/ratpack/src/main/java/com/baeldung/hystrix/HystrixSyncHttpCommand.java b/ratpack/src/main/java/com/baeldung/hystrix/HystrixSyncHttpCommand.java
new file mode 100644
index 0000000000..7c848331ca
--- /dev/null
+++ b/ratpack/src/main/java/com/baeldung/hystrix/HystrixSyncHttpCommand.java
@@ -0,0 +1,55 @@
+package com.baeldung.hystrix;
+
+import com.netflix.hystrix.HystrixCommand;
+import com.netflix.hystrix.HystrixCommandGroupKey;
+import com.netflix.hystrix.HystrixCommandProperties;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.util.EntityUtils;
+
+import java.net.URI;
+import java.util.Collections;
+
+/**
+ * @author aiet
+ */
+public class HystrixSyncHttpCommand extends HystrixCommand {
+
+ private URI uri;
+ private RequestConfig requestConfig;
+
+ HystrixSyncHttpCommand(URI uri, int timeoutMillis) {
+ super(Setter
+ .withGroupKey(HystrixCommandGroupKey.Factory.asKey("hystrix-ratpack-sync"))
+ .andCommandPropertiesDefaults(HystrixCommandProperties
+ .Setter()
+ .withExecutionTimeoutInMilliseconds(timeoutMillis)));
+ requestConfig = RequestConfig
+ .custom()
+ .setSocketTimeout(timeoutMillis)
+ .setConnectTimeout(timeoutMillis)
+ .setConnectionRequestTimeout(timeoutMillis)
+ .build();
+ this.uri = uri;
+ }
+
+ @Override
+ protected String run() throws Exception {
+ HttpGet request = new HttpGet(uri);
+ return EntityUtils.toString(HttpClientBuilder
+ .create()
+ .setDefaultRequestConfig(requestConfig)
+ .setDefaultHeaders(Collections.singleton(new BasicHeader("User-Agent", "Baeldung Blocking HttpClient")))
+ .build()
+ .execute(request)
+ .getEntity());
+ }
+
+ @Override
+ protected String getFallback() {
+ return "eugenp's sync fallback profile";
+ }
+
+}
diff --git a/ratpack/src/main/java/com/baeldung/hystrix/RatpackHystrixApp.java b/ratpack/src/main/java/com/baeldung/hystrix/RatpackHystrixApp.java
new file mode 100644
index 0000000000..1e4724bd96
--- /dev/null
+++ b/ratpack/src/main/java/com/baeldung/hystrix/RatpackHystrixApp.java
@@ -0,0 +1,30 @@
+package com.baeldung.hystrix;
+
+import ratpack.guice.Guice;
+import ratpack.http.client.HttpClient;
+import ratpack.hystrix.HystrixMetricsEventStreamHandler;
+import ratpack.hystrix.HystrixModule;
+import ratpack.server.RatpackServer;
+
+import java.net.URI;
+
+public class RatpackHystrixApp {
+
+ public static void main(String[] args) throws Exception {
+ final int timeout = Integer.valueOf(System.getProperty("ratpack.hystrix.timeout"));
+ final URI eugenGithubProfileUri = new URI("https://api.github.com/users/eugenp");
+
+ RatpackServer.start(server -> server
+ .registry(Guice.registry(bindingsSpec -> bindingsSpec.module(new HystrixModule().sse())))
+ .handlers(chain -> chain
+ .get("rx", ctx -> new HystrixReactiveHttpCommand(ctx.get(HttpClient.class), eugenGithubProfileUri, timeout)
+ .toObservable()
+ .subscribe(ctx::render))
+ .get("async", ctx -> ctx.render(new HystrixAsyncHttpCommand(eugenGithubProfileUri, timeout)
+ .queue()
+ .get()))
+ .get("sync", ctx -> ctx.render(new HystrixSyncHttpCommand(eugenGithubProfileUri, timeout).execute()))
+ .get("hystrix", new HystrixMetricsEventStreamHandler())));
+
+ }
+}
diff --git a/ratpack/src/test/java/com/baeldung/hystrix/RatpackHystrixAppFallbackLiveTest.java b/ratpack/src/test/java/com/baeldung/hystrix/RatpackHystrixAppFallbackLiveTest.java
new file mode 100644
index 0000000000..25287a5cbd
--- /dev/null
+++ b/ratpack/src/test/java/com/baeldung/hystrix/RatpackHystrixAppFallbackLiveTest.java
@@ -0,0 +1,50 @@
+package com.baeldung.hystrix;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import ratpack.test.MainClassApplicationUnderTest;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author aiet
+ */
+public class RatpackHystrixAppFallbackLiveTest {
+
+ static MainClassApplicationUnderTest appUnderTest;
+
+ @BeforeClass
+ public static void setup() {
+ System.setProperty("ratpack.hystrix.timeout", "10");
+ appUnderTest = new MainClassApplicationUnderTest(RatpackHystrixApp.class);
+ }
+
+ @Test
+ public void whenFetchReactive_thenGotFallbackProfile() {
+ assertThat(appUnderTest
+ .getHttpClient()
+ .getText("rx"), containsString("reactive fallback profile"));
+ }
+
+ @Test
+ public void whenFetchAsync_thenGotFallbackProfile() {
+ assertThat(appUnderTest
+ .getHttpClient()
+ .getText("async"), containsString("async fallback profile"));
+ }
+
+ @Test
+ public void whenFetchSync_thenGotFallbackProfile() {
+ assertThat(appUnderTest
+ .getHttpClient()
+ .getText("sync"), containsString("sync fallback profile"));
+ }
+
+ @AfterClass
+ public static void clean() {
+ appUnderTest.close();
+ }
+
+}
diff --git a/ratpack/src/test/java/com/baeldung/hystrix/RatpackHystrixAppLiveTest.java b/ratpack/src/test/java/com/baeldung/hystrix/RatpackHystrixAppLiveTest.java
new file mode 100644
index 0000000000..843ef68e13
--- /dev/null
+++ b/ratpack/src/test/java/com/baeldung/hystrix/RatpackHystrixAppLiveTest.java
@@ -0,0 +1,50 @@
+package com.baeldung.hystrix;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import ratpack.test.MainClassApplicationUnderTest;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author aiet
+ */
+public class RatpackHystrixAppLiveTest {
+
+ static MainClassApplicationUnderTest appUnderTest;
+
+ @BeforeClass
+ public static void setup() {
+ System.setProperty("ratpack.hystrix.timeout", "5000");
+ appUnderTest = new MainClassApplicationUnderTest(RatpackHystrixApp.class);
+ }
+
+ @Test
+ public void whenFetchReactive_thenGotEugenProfile() {
+ assertThat(appUnderTest
+ .getHttpClient()
+ .getText("rx"), containsString("www.baeldung.com"));
+ }
+
+ @Test
+ public void whenFetchAsync_thenGotEugenProfile() {
+ assertThat(appUnderTest
+ .getHttpClient()
+ .getText("async"), containsString("www.baeldung.com"));
+ }
+
+ @Test
+ public void whenFetchSync_thenGotEugenProfile() {
+ assertThat(appUnderTest
+ .getHttpClient()
+ .getText("sync"), containsString("www.baeldung.com"));
+ }
+
+ @AfterClass
+ public static void clean() {
+ appUnderTest.close();
+ }
+
+}
diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml
index 0cf7df86cd..9d44de64a3 100644
--- a/spring-boot/pom.xml
+++ b/spring-boot/pom.xml
@@ -40,6 +40,22 @@
spring-boot-starter-security
+
+ com.graphql-java
+ graphql-spring-boot-starter
+ 3.6.0
+
+
+ com.graphql-java
+ graphiql-spring-boot-starter
+ 3.6.0
+
+
+ com.graphql-java
+ graphql-java-tools
+ 3.2.0
+
+
org.springframework.boot
spring-boot-starter-tomcat
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/Author.java b/spring-boot/src/main/java/com/baeldung/graphql/Author.java
new file mode 100644
index 0000000000..11e927c564
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/Author.java
@@ -0,0 +1,31 @@
+package com.baeldung.graphql;
+
+public class Author {
+ private String id;
+ private String name;
+ private String thumbnail;
+
+ 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 getThumbnail() {
+ return thumbnail;
+ }
+
+ public void setThumbnail(String thumbnail) {
+ this.thumbnail = thumbnail;
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/AuthorDao.java b/spring-boot/src/main/java/com/baeldung/graphql/AuthorDao.java
new file mode 100644
index 0000000000..522732faeb
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/AuthorDao.java
@@ -0,0 +1,18 @@
+package com.baeldung.graphql;
+
+import java.util.List;
+import java.util.Optional;
+
+public class AuthorDao {
+ private List authors;
+
+ public AuthorDao(List authors) {
+ this.authors = authors;
+ }
+
+ public Optional getAuthor(String id) {
+ return authors.stream()
+ .filter(author -> id.equals(author.getId()))
+ .findFirst();
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/AuthorResolver.java b/spring-boot/src/main/java/com/baeldung/graphql/AuthorResolver.java
new file mode 100644
index 0000000000..982c6cebc1
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/AuthorResolver.java
@@ -0,0 +1,17 @@
+package com.baeldung.graphql;
+
+import java.util.List;
+
+import com.coxautodev.graphql.tools.GraphQLResolver;
+
+public class AuthorResolver implements GraphQLResolver {
+ private PostDao postDao;
+
+ public AuthorResolver(PostDao postDao) {
+ this.postDao = postDao;
+ }
+
+ public List getPosts(Author author) {
+ return postDao.getAuthorPosts(author.getId());
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/GraphqlConfiguration.java b/spring-boot/src/main/java/com/baeldung/graphql/GraphqlConfiguration.java
new file mode 100644
index 0000000000..a7a864cf96
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/GraphqlConfiguration.java
@@ -0,0 +1,59 @@
+package com.baeldung.graphql;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+public class GraphqlConfiguration {
+ @Bean
+ public PostDao postDao() {
+ List posts = new ArrayList<>();
+ for (int postId = 0; postId < 10; ++postId) {
+ for (int authorId = 0; authorId < 10; ++authorId) {
+ Post post = new Post();
+ post.setId("Post" + authorId + postId);
+ post.setTitle("Post " + authorId + ":" + postId);
+ post.setText("Post " + postId + " + by author " + authorId);
+ post.setAuthorId("Author" + authorId);
+ posts.add(post);
+ }
+ }
+ return new PostDao(posts);
+ }
+
+ @Bean
+ public AuthorDao authorDao() {
+ List authors = new ArrayList<>();
+ for (int authorId = 0; authorId < 10; ++authorId) {
+ Author author = new Author();
+ author.setId("Author" + authorId);
+ author.setName("Author " + authorId);
+ author.setThumbnail("http://example.com/authors/" + authorId);
+ authors.add(author);
+ }
+ return new AuthorDao(authors);
+ }
+
+ @Bean
+ public PostResolver postResolver(AuthorDao authorDao) {
+ return new PostResolver(authorDao);
+ }
+
+ @Bean
+ public AuthorResolver authorResolver(PostDao postDao) {
+ return new AuthorResolver(postDao);
+ }
+
+ @Bean
+ public Query query(PostDao postDao) {
+ return new Query(postDao);
+ }
+
+ @Bean
+ public Mutation mutation(PostDao postDao) {
+ return new Mutation(postDao);
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/Mutation.java b/spring-boot/src/main/java/com/baeldung/graphql/Mutation.java
new file mode 100644
index 0000000000..0e16e3c8b7
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/Mutation.java
@@ -0,0 +1,25 @@
+package com.baeldung.graphql;
+
+import java.util.UUID;
+
+import com.coxautodev.graphql.tools.GraphQLMutationResolver;
+
+public class Mutation implements GraphQLMutationResolver {
+ private PostDao postDao;
+
+ public Mutation(PostDao postDao) {
+ this.postDao = postDao;
+ }
+
+ public Post writePost(String title, String text, String category, String author) {
+ Post post = new Post();
+ post.setId(UUID.randomUUID().toString());
+ post.setTitle(title);
+ post.setText(text);
+ post.setCategory(category);
+ post.setAuthorId(author);
+ postDao.savePost(post);
+
+ return post;
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/Post.java b/spring-boot/src/main/java/com/baeldung/graphql/Post.java
new file mode 100644
index 0000000000..14d3084841
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/Post.java
@@ -0,0 +1,49 @@
+package com.baeldung.graphql;
+
+public class Post {
+ private String id;
+ private String title;
+ private String text;
+ private String category;
+ private String authorId;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getText() {
+ return text;
+ }
+
+ public void setText(String text) {
+ this.text = text;
+ }
+
+ public String getCategory() {
+ return category;
+ }
+
+ public void setCategory(String category) {
+ this.category = category;
+ }
+
+ public String getAuthorId() {
+ return authorId;
+ }
+
+ public void setAuthorId(String authorId) {
+ this.authorId = authorId;
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/PostDao.java b/spring-boot/src/main/java/com/baeldung/graphql/PostDao.java
new file mode 100644
index 0000000000..f8d243ee3a
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/PostDao.java
@@ -0,0 +1,29 @@
+package com.baeldung.graphql;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+public class PostDao {
+ private List posts;
+
+ public PostDao(List posts) {
+ this.posts = posts;
+ }
+
+ public List getRecentPosts(int count, int offset) {
+ return posts.stream()
+ .skip(offset)
+ .limit(count)
+ .collect(Collectors.toList());
+ }
+
+ public List getAuthorPosts(String author) {
+ return posts.stream()
+ .filter(post -> author.equals(post.getAuthorId()))
+ .collect(Collectors.toList());
+ }
+
+ public void savePost(Post post) {
+ posts.add(0, post);
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/PostResolver.java b/spring-boot/src/main/java/com/baeldung/graphql/PostResolver.java
new file mode 100644
index 0000000000..dbfde330ea
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/PostResolver.java
@@ -0,0 +1,17 @@
+package com.baeldung.graphql;
+
+import java.util.Optional;
+
+import com.coxautodev.graphql.tools.GraphQLResolver;
+
+public class PostResolver implements GraphQLResolver {
+ private AuthorDao authorDao;
+
+ public PostResolver(AuthorDao authorDao) {
+ this.authorDao = authorDao;
+ }
+
+ public Optional getAuthor(Post post) {
+ return authorDao.getAuthor(post.getAuthorId());
+ }
+}
diff --git a/spring-boot/src/main/java/com/baeldung/graphql/Query.java b/spring-boot/src/main/java/com/baeldung/graphql/Query.java
new file mode 100644
index 0000000000..7bb625798c
--- /dev/null
+++ b/spring-boot/src/main/java/com/baeldung/graphql/Query.java
@@ -0,0 +1,17 @@
+package com.baeldung.graphql;
+
+import java.util.List;
+
+import com.coxautodev.graphql.tools.GraphQLQueryResolver;
+
+public class Query implements GraphQLQueryResolver {
+ private PostDao postDao;
+
+ public Query(PostDao postDao) {
+ this.postDao = postDao;
+ }
+
+ public List recentPosts(int count, int offset) {
+ return postDao.getRecentPosts(count, offset);
+ }
+}
diff --git a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java
index 2d83b650ec..5de4134739 100644
--- a/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java
+++ b/spring-boot/src/main/java/org/baeldung/boot/DemoApplication.java
@@ -1,11 +1,14 @@
package org.baeldung.boot;
+import com.baeldung.graphql.GraphqlConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.baeldung.autoconfiguration.MySQLAutoconfiguration;
+import org.springframework.context.annotation.Import;
@SpringBootApplication(exclude=MySQLAutoconfiguration.class)
+@Import(GraphqlConfiguration.class)
public class DemoApplication {
public static void main(String[] args) {
diff --git a/spring-boot/src/main/resources/graphql/blog.graphqls b/spring-boot/src/main/resources/graphql/blog.graphqls
new file mode 100644
index 0000000000..aa0c8757e9
--- /dev/null
+++ b/spring-boot/src/main/resources/graphql/blog.graphqls
@@ -0,0 +1,24 @@
+type Post {
+ id: ID!
+ title: String!
+ text: String!
+ category: String
+ author: Author
+}
+
+type Author {
+ id: ID!
+ name: String!
+ thumbnail: String
+ posts: [Post]!
+}
+
+# The Root Query for the application
+type Query {
+ recentPosts(count: Int, offset: Int): [Post]!
+}
+
+# The Root Mutation for the application
+type Mutation {
+ writePost(title: String!, text: String!, category: String, author: String!) : Post!
+}
diff --git a/spring-hibernate5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationXMLConfigMainIntegrationTest.java b/spring-hibernate5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java
similarity index 50%
rename from spring-hibernate5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationXMLConfigMainIntegrationTest.java
rename to spring-hibernate5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java
index 5308134fac..2ec1246961 100644
--- a/spring-hibernate5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationXMLConfigMainIntegrationTest.java
+++ b/spring-hibernate5/src/test/java/com/baeldung/hibernate/manytomany/HibernateManyToManyAnnotationMainIntegrationTest.java
@@ -12,17 +12,16 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+
import com.baeldung.hibernate.manytomany.util.HibernateUtil;
import com.baeldung.hibernate.manytomany.model.Employee;
import com.baeldung.hibernate.manytomany.model.Project;
-
-public class HibernateManyToManyAnnotationXMLConfigMainIntegrationTest {
+public class HibernateManyToManyAnnotationMainIntegrationTest {
private static SessionFactory sessionFactory;
private Session session;
-
@BeforeClass
public static void beforeTests() {
sessionFactory = HibernateUtil.getSessionFactory();
@@ -34,45 +33,39 @@ public class HibernateManyToManyAnnotationXMLConfigMainIntegrationTest {
session.beginTransaction();
}
-
@Test
- public void givenSession_checkIfDatabaseIsPopulated() {
- Employee employee1 = new Employee("Peter", "Oven");
+ public void givenData_whenInsert_thenCreatesMtoMrelationship() {
+ String[] employeeData = { "Peter Oven", "Allan Norman" };
+ String[] projectData = { "IT Project", "Networking Project" };
Set projects = new HashSet();
- projects = employee1.getProjects();
- int noProjects = projects.size();
- assertEquals(0,noProjects);
- Project project1 = new Project("IT Project");
- assertNotNull(project1);
- projects.add(project1);
- Project project2 = new Project("Networking Project");
- assertNotNull(project2);
- projects.add(project2);
- employee1.setProjects(projects);
- assertNotNull(employee1);
- Employee employee2 = new Employee("Allan", "Norman");
- employee2.setProjects(projects);
- assertNotNull(employee2);
-
- session.persist(employee1);
- session.persist(employee2);
- session.getTransaction().commit();
- session.close();
- session = sessionFactory.openSession();
- session.beginTransaction();
- @SuppressWarnings("unchecked")
- List projectList = session.createQuery("FROM Project").list();
- assertNotNull(projectList);
+ for (String proj : projectData) {
+ projects.add(new Project(proj));
+ }
+
+ for (String emp : employeeData) {
+ Employee employee = new Employee(emp.split(" ")[0], emp.split(" ")[1]);
+ assertEquals(0, employee.getProjects().size());
+ employee.setProjects(projects);
+ assertNotNull(employee);
+ session.persist(employee);
+ }
+ }
+
+ @Test
+ public void givenSession_whenRead_thenReturnsMtoMdata() {
@SuppressWarnings("unchecked")
List employeeList = session.createQuery("FROM Employee").list();
assertNotNull(employeeList);
+ for(Employee employee : employeeList) {
+ assertNotNull(employee.getProjects());
+ }
}
-
@After
public void tearDown() {
- session.getTransaction().commit();
+ session.getTransaction()
+ .commit();
session.close();
}
diff --git a/spring-mvc-kotlin/pom.xml b/spring-mvc-kotlin/pom.xml
index 087f02fc68..5375ecae7c 100644
--- a/spring-mvc-kotlin/pom.xml
+++ b/spring-mvc-kotlin/pom.xml
@@ -23,11 +23,6 @@
kotlin-stdlib-jre8
1.1.4
-
- org.jetbrains.kotlin
- kotlin-reflect
- 1.1.4
-
org.springframework
diff --git a/spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp b/spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp
index bdb6716889..3f68f128bc 100644
--- a/spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp
+++ b/spring-mvc-kotlin/src/main/webapp/WEB-INF/view/welcome.jsp
@@ -2,6 +2,6 @@
Welcome
- This is the body of the welcome view 2
+ This is the body of the welcome view