Merge remote-tracking branch 'upstream/master'

This commit is contained in:
anuragkumawat 2022-03-17 15:50:07 +05:30
commit ce5d2c38a1
144 changed files with 1602 additions and 382 deletions

View File

@ -83,4 +83,4 @@
<olingo.version>2.0.11</olingo.version>
</properties>
</project>
</project>

View File

@ -34,6 +34,28 @@
</dependency>
</dependencies>
<build>
<finalName>core-java-9-new-features</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>https://repository.apache.org/snapshots/</url>
</pluginRepository>
</pluginRepositories>
<profiles>
<profile>
<id>incubator-features</id>
@ -126,28 +148,6 @@
</profile>
</profiles>
<build>
<finalName>core-java-9-new-features</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>apache.snapshots</id>
<url>https://repository.apache.org/snapshots/</url>
</pluginRepository>
</pluginRepositories>
<properties>
<rxjava.version>3.0.0</rxjava.version>
<awaitility.version>4.0.2</awaitility.version>

View File

@ -5,3 +5,4 @@
- [Start Two Threads at the Exact Same Time in Java](https://www.baeldung.com/java-start-two-threads-at-same-time)
- [Volatile Variables and Thread Safety](https://www.baeldung.com/java-volatile-variables-thread-safety)
- [Producer-Consumer Problem With Example in Java](https://www.baeldung.com/java-producer-consumer-problem)
- [Acquire a Lock by a Key in Java](https://www.baeldung.com/java-acquire-lock-by-key)

View File

@ -0,0 +1,51 @@
package com.baeldung.producerconsumer;
public class Consumer implements Runnable {
private final DataQueue dataQueue;
private volatile boolean runFlag;
public Consumer(DataQueue dataQueue) {
this.dataQueue = dataQueue;
runFlag = true;
}
@Override
public void run() {
consume();
}
public void consume() {
while (runFlag) {
Message message;
if (dataQueue.isEmpty()) {
try {
dataQueue.waitOnEmpty();
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
if (!runFlag) {
break;
}
message = dataQueue.remove();
dataQueue.notifyAllForFull();
useMessage(message);
}
System.out.println("Consumer Stopped");
}
private void useMessage(Message message) {
if (message != null) {
System.out.printf("[%s] Consuming Message. Id: %d, Data: %f\n", Thread.currentThread().getName(), message.getId(), message.getData());
//Sleeping on random time to make it realistic
ThreadUtil.sleep((long) (message.getData() * 100));
}
}
public void stop() {
runFlag = false;
dataQueue.notifyAllForEmpty();
}
}

View File

@ -0,0 +1,59 @@
package com.baeldung.producerconsumer;
import java.util.LinkedList;
import java.util.Queue;
public class DataQueue {
private final Queue<Message> queue = new LinkedList<>();
private final int maxSize;
private final Object FULL_QUEUE = new Object();
private final Object EMPTY_QUEUE = new Object();
DataQueue(int maxSize) {
this.maxSize = maxSize;
}
public boolean isFull() {
return queue.size() == maxSize;
}
public boolean isEmpty() {
return queue.isEmpty();
}
public void waitOnFull() throws InterruptedException {
synchronized (FULL_QUEUE) {
FULL_QUEUE.wait();
}
}
public void waitOnEmpty() throws InterruptedException {
synchronized (EMPTY_QUEUE) {
EMPTY_QUEUE.wait();
}
}
public void notifyAllForFull() {
synchronized (FULL_QUEUE) {
FULL_QUEUE.notifyAll();
}
}
public void notifyAllForEmpty() {
synchronized (EMPTY_QUEUE) {
EMPTY_QUEUE.notifyAll();
}
}
public void add(Message message) {
synchronized (queue) {
queue.add(message);
}
}
public Message remove() {
synchronized (queue) {
return queue.poll();
}
}
}

View File

@ -0,0 +1,27 @@
package com.baeldung.producerconsumer;
public class Message {
private int id;
private double data;
public Message(int id, double data) {
this.id = id;
this.data = data;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getData() {
return data;
}
public void setData(double data) {
this.data = data;
}
}

View File

@ -0,0 +1,53 @@
package com.baeldung.producerconsumer;
public class Producer implements Runnable {
private final DataQueue dataQueue;
private volatile boolean runFlag;
private static int idSequence = 0;
public Producer(DataQueue dataQueue) {
this.dataQueue = dataQueue;
runFlag = true;
}
@Override
public void run() {
produce();
}
public void produce() {
while (runFlag) {
Message message = generateMessage();
while (dataQueue.isFull()) {
try {
dataQueue.waitOnFull();
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
}
if (!runFlag) {
break;
}
dataQueue.add(message);
dataQueue.notifyAllForEmpty();
}
System.out.println("Producer Stopped");
}
private Message generateMessage() {
Message message = new Message(++idSequence, Math.random());
System.out.printf("[%s] Generated Message. Id: %d, Data: %f\n", Thread.currentThread().getName(), message.getId(), message.getData());
//Sleeping on random time to make it realistic
ThreadUtil.sleep((long) (message.getData() * 100));
return message;
}
public void stop() {
runFlag = false;
dataQueue.notifyAllForFull();
}
}

View File

@ -0,0 +1,69 @@
package com.baeldung.producerconsumer;
import java.util.ArrayList;
import java.util.List;
import static com.baeldung.producerconsumer.ThreadUtil.*;
public class ProducerConsumerDemonstrator {
private static final int MAX_QUEUE_CAPACITY = 5;
public static void demoSingleProducerAndSingleConsumer() {
DataQueue dataQueue = new DataQueue(MAX_QUEUE_CAPACITY);
Producer producer = new Producer(dataQueue);
Thread producerThread = new Thread(producer);
Consumer consumer = new Consumer(dataQueue);
Thread consumerThread = new Thread(consumer);
producerThread.start();
consumerThread.start();
List<Thread> threads = new ArrayList<>();
threads.add(producerThread);
threads.add(consumerThread);
// let threads run for two seconds
sleep(2000);
// Stop threads
producer.stop();
consumer.stop();
waitForAllThreadsToComplete(threads);
}
public static void demoMultipleProducersAndMultipleConsumers() {
DataQueue dataQueue = new DataQueue(MAX_QUEUE_CAPACITY);
int producerCount = 3;
int consumerCount = 3;
List<Thread> threads = new ArrayList<>();
Producer producer = new Producer(dataQueue);
for(int i = 0; i < producerCount; i++) {
Thread producerThread = new Thread(producer);
producerThread.start();
threads.add(producerThread);
}
Consumer consumer = new Consumer(dataQueue);
for(int i = 0; i < consumerCount; i++) {
Thread consumerThread = new Thread(consumer);
consumerThread.start();
threads.add(consumerThread);
}
// let threads run for two seconds
sleep(2000);
// Stop threads
producer.stop();
consumer.stop();
waitForAllThreadsToComplete(threads);
}
public static void main(String[] args) {
demoSingleProducerAndSingleConsumer();
demoMultipleProducersAndMultipleConsumers();
}
}

View File

@ -0,0 +1,60 @@
package com.baeldung.producerconsumer;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingDeque;
import static com.baeldung.producerconsumer.ThreadUtil.sleep;
public class SimpleProducerConsumerDemonstrator {
BlockingQueue<Double> blockingQueue = new LinkedBlockingDeque<>(5);
private void produce() {
while (true) {
double value = generateValue();
try {
blockingQueue.put(value);
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
System.out.printf("[%s] Value produced: %f\n", Thread.currentThread().getName(), value);
}
}
private void consume() {
while (true) {
Double value;
try {
value = blockingQueue.take();
} catch (InterruptedException e) {
e.printStackTrace();
break;
}
// Consume value
System.out.printf("[%s] Value consumed: %f\n", Thread.currentThread().getName(), value);
}
}
private double generateValue() {
return Math.random();
}
private void runProducerConsumer() {
for (int i = 0; i < 2; i++) {
Thread producerThread = new Thread(this::produce);
producerThread.start();
}
for (int i = 0; i < 3; i++) {
Thread consumerThread = new Thread(this::consume);
consumerThread.start();
}
}
public static void main(String[] args) {
SimpleProducerConsumerDemonstrator simpleProducerConsumerDemonstrator = new SimpleProducerConsumerDemonstrator();
simpleProducerConsumerDemonstrator.runProducerConsumer();
sleep(2000);
System.exit(0);
}
}

View File

@ -0,0 +1,24 @@
package com.baeldung.producerconsumer;
import java.util.List;
public class ThreadUtil {
public static void waitForAllThreadsToComplete(List<Thread> threads) {
for(Thread thread: threads) {
try {
thread.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public static void sleep(long interval) {
try {
// Wait for some time to demonstrate threads
Thread.sleep(interval);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}

View File

@ -24,4 +24,4 @@
</resources>
</build>
</project>
</project>

View File

@ -25,7 +25,6 @@
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>com.darwinsys</groupId>
<artifactId>hirondelle-date4j</artifactId>

View File

@ -2,3 +2,4 @@
- [Java ArrayIndexOutOfBoundsException](https://www.baeldung.com/java-arrayindexoutofboundsexception)
- [Java Missing Return Statement](https://www.baeldung.com/java-missing-return-statement)
- [Convert long to int Type in Java](https://www.baeldung.com/java-convert-long-to-int)

View File

@ -259,7 +259,7 @@
</plugins>
</build>
</profile>
</profiles>
<properties>

View File

@ -64,13 +64,6 @@
</dependency>
</dependencies>
<properties>
<javaassist.version>3.27.0-GA</javaassist.version>
<sun.tools.version>1.8.0</sun.tools.version>
<jol-core.version>0.10</jol-core.version>
<asm.version>8.0.1</asm.version>
<bcel.version>6.5.0</bcel.version>
</properties>
<profiles>
<!-- java instrumentation profiles to build jars -->
<profile>
@ -181,4 +174,12 @@
</profile>
</profiles>
<properties>
<javaassist.version>3.27.0-GA</javaassist.version>
<sun.tools.version>1.8.0</sun.tools.version>
<jol-core.version>0.10</jol-core.version>
<asm.version>8.0.1</asm.version>
<bcel.version>6.5.0</bcel.version>
</properties>
</project>

View File

@ -10,3 +10,4 @@ This module contains articles about core features in the Java language
- [Tiered Compilation in JVM](https://www.baeldung.com/jvm-tiered-compilation)
- [Fixing the “Declared package does not match the expected package” Error](https://www.baeldung.com/java-declared-expected-package-error)
- [Chaining Constructors in Java](https://www.baeldung.com/java-chain-constructors)
- [Difference Between POJO, JavaBeans, DTO and VO](https://www.baeldung.com/java-pojo-javabeans-dto-vo)

View File

@ -0,0 +1,48 @@
package com.baeldung.employee;
import java.io.Serializable;
import java.time.LocalDate;
public class EmployeeBean implements Serializable {
private static final long serialVersionUID = -3760445487636086034L;
private String firstName;
private String lastName;
private LocalDate startDate;
public EmployeeBean() {
}
public EmployeeBean(String firstName, String lastName, LocalDate startDate) {
this.firstName = firstName;
this.lastName = lastName;
this.startDate = startDate;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.employee;
import java.time.LocalDate;
public class EmployeeDTO {
private String firstName;
private String lastName;
private LocalDate startDate;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
}

View File

@ -0,0 +1,49 @@
package com.baeldung.employee;
import java.time.LocalDate;
import java.util.Objects;
public class EmployeePOJO {
private String firstName;
private String lastName;
private LocalDate startDate;
public EmployeePOJO(String firstName, String lastName, LocalDate startDate) {
this.firstName = firstName;
this.lastName = lastName;
this.startDate = startDate;
}
public String name() {
return this.firstName + " " + this.lastName;
}
public LocalDate getStart() {
return this.startDate;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public LocalDate getStartDate() {
return startDate;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
}

View File

@ -0,0 +1,40 @@
package com.baeldung.employee;
import java.time.LocalDate;
import java.util.Objects;
public class EmployeeVO {
private String firstName;
private String lastName;
private LocalDate startDate;
public EmployeeVO(String firstName, String lastName, LocalDate startDate) {
this.firstName = firstName;
this.lastName = lastName;
this.startDate = startDate;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public LocalDate getStartDate() {
return startDate;
}
@Override
public boolean equals(Object obj) {
return Objects.equals(firstName, this.firstName)
&& Objects.equals(lastName, this.lastName)
&& Objects.equals(startDate, this.startDate);
}
@Override
public int hashCode() {
return Objects.hash(firstName, lastName, startDate);
}
}

View File

@ -64,7 +64,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -54,4 +54,5 @@
<validator.version>1.7</validator.version>
<apache-commons-lang3.version>3.12.0</apache-commons-lang3.version>
</properties>
</project>

View File

@ -69,7 +69,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>

View File

@ -137,4 +137,4 @@
</dependencies>
</dependencyManagement>
</project>
</project>

View File

@ -1,13 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.baeldung.dddmodules.infrastructure</groupId>
<artifactId>infrastructure</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<parent>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -13,7 +12,6 @@
<groupId>com.baeldung.dddmodules</groupId>
<artifactId>ddd-modules</artifactId>
<version>1.0</version>
<relativePath>../</relativePath>
</parent>
<dependencies>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -14,7 +13,6 @@
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>
<modules>
@ -70,10 +68,8 @@
<properties>
<source.version>9</source.version>
<target.version>9</target.version>
<compiler.plugin.version>3.8.1</compiler.plugin.version>
<appmodules.version>1.0</appmodules.version>
</properties>
</project>
</project>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -13,7 +12,6 @@
<groupId>com.baeldung.dddmodules</groupId>
<artifactId>ddd-modules</artifactId>
<version>1.0</version>
<relativePath>../</relativePath>
</parent>
<build>

View File

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -13,7 +12,6 @@
<groupId>com.baeldung.dddmodules</groupId>
<artifactId>ddd-modules</artifactId>
<version>1.0</version>
<relativePath>../</relativePath>
</parent>
<dependencies>

View File

@ -15,6 +15,14 @@
<version>1.0.0-SNAPSHOT</version>
</parent>
<repositories>
<repository>
<id>osgeo-release</id>
<name>OSGeo Repository</name>
<url>https://repo.osgeo.org/repository/release/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.geotools</groupId>
@ -33,14 +41,6 @@
</dependency>
</dependencies>
<repositories>
<repository>
<id>osgeo-release</id>
<name>OSGeo Repository</name>
<url>https://repo.osgeo.org/repository/release/</url>
</repository>
</repositories>
<properties>
<geotools.version>15.2</geotools.version>
<geotools-swing.version>15.2</geotools-swing.version>

View File

@ -33,26 +33,22 @@
<artifactId>spring-boot-starter</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>2.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.netflix.graphql.dgs.codegen</groupId>
<artifactId>graphql-dgs-codegen-client-core</artifactId>
<version>5.1.14</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>com.netflix.graphql.dgs</groupId>
<artifactId>graphql-dgs-spring-boot-starter</artifactId>
@ -88,4 +84,4 @@
</plugins>
</build>
</project>
</project>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>httpclient-2</artifactId>
<version>0.1-SNAPSHOT</version>

3
jakarta-ee/README.md Normal file
View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [Introduction to Jakarta EE MVC / Eclipse Krazo](https://www.baeldung.com/java-ee-mvc-eclipse-krazo)

View File

@ -22,7 +22,6 @@
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>

View File

@ -4,3 +4,4 @@
- [Understanding the & 0xff Value in Java](https://www.baeldung.com/java-and-0xff)
- [Determine if an Integers Square Root Is an Integer in Java](https://www.baeldung.com/java-find-if-square-root-is-integer)
- [Guide to Java BigInteger](https://www.baeldung.com/java-biginteger)
- [Automorphic Numbers in Java](https://www.baeldung.com/java-automorphic-numbers)

View File

@ -0,0 +1,31 @@
package com.baeldung.automorphicnumber;
public class AutomorphicNumber {
public static void main(String[] args) {
System.out.println(isAutomorphicUsingLoop(76));
System.out.println(isAutomorphicUsingMath(76));
}
public static boolean isAutomorphicUsingMath(int number) {
int square = number * number;
int numberOfDigits = (int) Math.floor(Math.log10(number) + 1);
int lastDigits = (int) (square % (Math.pow(10, numberOfDigits)));
return number == lastDigits;
}
public static boolean isAutomorphicUsingLoop(int number) {
int square = number * number;
while (number > 0) {
if (number % 10 != square % 10) {
return false;
}
number /= 10;
square /= 10;
}
return true;
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.automorphicnumber;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
public class AutomorphicNumberUnitTest {
@Test
void givenANumber_whenPassed_thenShouldDetermineAutomorphicOrNot() {
int number1 = 76; // automorphic
int number2 = 16; // not automorphic
assertTrue(AutomorphicNumber.isAutomorphicUsingLoop(number1));
assertFalse(AutomorphicNumber.isAutomorphicUsingLoop(number2));
assertTrue(AutomorphicNumber.isAutomorphicUsingMath(number1));
assertFalse(AutomorphicNumber.isAutomorphicUsingMath(number2));
}
}

View File

@ -57,4 +57,5 @@
<org.apache.httpcomponents.version>4.5.13</org.apache.httpcomponents.version>
<javax.servlet-api.version>4.0.1</javax.servlet-api.version>
</properties>
</project>
</project>

View File

@ -37,35 +37,13 @@
</dependencies>
<!-- uncomment in order to enable Hibernate Validator Anotation Processor -->
<!--
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<fork>true</fork>
<compilerArgs>
<arg>-Averbose=true</arg>
<arg>-AmethodConstraintsSupported=true</arg>
<arg>-AdiagnosticKind=ERROR</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>${hibernate-validator.ap.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
-->
<!-- <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version> <configuration> <source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target> <fork>true</fork> <compilerArgs> <arg>-Averbose=true</arg>
<arg>-AmethodConstraintsSupported=true</arg> <arg>-AdiagnosticKind=ERROR</arg> </compilerArgs> <annotationProcessorPaths>
<path> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator-annotation-processor</artifactId>
<version>${hibernate-validator.ap.version}</version> </path> </annotationProcessorPaths> </configuration>
</plugin> </plugins> </build> -->
<properties>
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
@ -77,4 +55,4 @@
<org.springframework.version>5.0.2.RELEASE</org.springframework.version>
</properties>
</project>
</project>

View File

@ -15,7 +15,7 @@
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencyManagement>
<dependencies>
<dependency>

View File

@ -11,7 +11,6 @@
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<repositories>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>libraries-concurrency</artifactId>
<name>libraries-concurrency</name>
@ -78,5 +78,5 @@
<properties>
<quasar.version>0.8.0</quasar.version>
</properties>
</project>

View File

@ -22,4 +22,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@ -62,18 +62,9 @@
<verbose>false</verbose>
</configuration>
</execution>
<!-- This is for delomboking also your tests sources.
<execution>
<id>test-delombok</id>
<phase>generate-test-sources</phase>
<goals>
<goal>testDelombok</goal>
</goals>
<configuration>
<verbose>false</verbose>
</configuration>
</execution>
-->
<!-- This is for delomboking also your tests sources. <execution> <id>test-delombok</id>
<phase>generate-test-sources</phase> <goals> <goal>testDelombok</goal> </goals> <configuration> <verbose>false</verbose>
</configuration> </execution> -->
</executions>
</plugin>
</plugins>

View File

@ -1,22 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-classifier-example-consumer</artifactId>
<parent>
<artifactId>maven-classifier</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-classifier-example-consumer</artifactId>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.baeldung</groupId>
@ -29,13 +23,14 @@
<version>0.0.1-SNAPSHOT</version>
<classifier>arbitrary</classifier>
</dependency>
<!-- For example purpose not building as it requires both JDK 8 and 11 executables on the build machine -->
<!-- <dependency>-->
<!-- <groupId>com.baeldung</groupId>-->
<!-- <artifactId>maven-classifier-example-provider</artifactId>-->
<!-- <version>0.0.1-SNAPSHOT</version>-->
<!-- <classifier>jdk11</classifier>-->
<!-- </dependency>-->
<!-- For example purpose not building as it requires both JDK 8 and 11 executables on the build
machine -->
<!-- <dependency> -->
<!-- <groupId>com.baeldung</groupId> -->
<!-- <artifactId>maven-classifier-example-provider</artifactId> -->
<!-- <version>0.0.1-SNAPSHOT</version> -->
<!-- <classifier>jdk11</classifier> -->
<!-- </dependency> -->
<dependency>
<groupId>com.baeldung</groupId>
<artifactId>maven-classifier-example-provider</artifactId>
@ -50,4 +45,9 @@
</dependency>
</dependencies>
</project>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>

View File

@ -1,9 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-classifier-example-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<artifactId>maven-classifier</artifactId>
@ -11,15 +12,6 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>maven-classifier-example-provider</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- <jdk.11.executable.path></jdk.11.executable.path>-->
</properties>
<build>
<plugins>
<plugin>
@ -39,21 +31,22 @@
<fork>true</fork>
</configuration>
</execution>
<!-- For example purpose not building as it requires both JDK 8 and 11 executables on the build machine -->
<!-- <execution>-->
<!-- <id>JDK 11</id>-->
<!-- <phase>compile</phase>-->
<!-- <goals>-->
<!-- <goal>compile</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <fork>true</fork>-->
<!-- <outputDirectory>${project.build.outputDirectory}_jdk11</outputDirectory>-->
<!-- <executable>${jdk.11.executable.path}</executable>-->
<!-- <source>8</source>-->
<!-- <target>11</target>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- For example purpose not building as it requires both JDK 8 and 11 executables
on the build machine -->
<!-- <execution> -->
<!-- <id>JDK 11</id> -->
<!-- <phase>compile</phase> -->
<!-- <goals> -->
<!-- <goal>compile</goal> -->
<!-- </goals> -->
<!-- <configuration> -->
<!-- <fork>true</fork> -->
<!-- <outputDirectory>${project.build.outputDirectory}_jdk11</outputDirectory> -->
<!-- <executable>${jdk.11.executable.path}</executable> -->
<!-- <source>8</source> -->
<!-- <target>11</target> -->
<!-- </configuration> -->
<!-- </execution> -->
</executions>
</plugin>
<plugin>
@ -76,18 +69,19 @@
<goal>test-jar</goal>
</goals>
</execution>
<!-- For example purpose not building as it requires both JDK 8 and 11 executables on the build machine -->
<!-- <execution>-->
<!-- <id>default-package-jdk11</id>-->
<!-- <phase>package</phase>-->
<!-- <goals>-->
<!-- <goal>jar</goal>-->
<!-- </goals>-->
<!-- <configuration>-->
<!-- <classesDirectory>${project.build.outputDirectory}_jdk11</classesDirectory>-->
<!-- <classifier>jdk11</classifier>-->
<!-- </configuration>-->
<!-- </execution>-->
<!-- For example purpose not building as it requires both JDK 8 and 11 executables
on the build machine -->
<!-- <execution> -->
<!-- <id>default-package-jdk11</id> -->
<!-- <phase>package</phase> -->
<!-- <goals> -->
<!-- <goal>jar</goal> -->
<!-- </goals> -->
<!-- <configuration> -->
<!-- <classesDirectory>${project.build.outputDirectory}_jdk11</classesDirectory> -->
<!-- <classifier>jdk11</classifier> -->
<!-- </configuration> -->
<!-- </execution> -->
</executions>
</plugin>
<plugin>
@ -119,4 +113,11 @@
</plugin>
</plugins>
</build>
</project>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<!-- <jdk.11.executable.path></jdk.11.executable.path> -->
</properties>
</project>

View File

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-classifier</artifactId>
<packaging>pom</packaging>
<version>0.0.1-SNAPSHOT</version>
@ -24,4 +23,4 @@
<maven.compiler.target>8</maven.compiler.target>
</properties>
</project>
</project>

View File

@ -3,9 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<name>copy-rename-maven-plugin</name>
<parent>

View File

@ -3,9 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<name>maven-antrun-plugin</name>
<parent>

View File

@ -3,9 +3,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<name>maven-resources-plugin</name>
<parent>

View File

@ -6,8 +6,8 @@
<groupId>com.baeldung</groupId>
<artifactId>maven-generate-war</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>maven-generate-war</name>
<packaging>war</packaging>
<description>Spring boot project to demonstrate war file generation</description>
<parent>

View File

@ -4,13 +4,12 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-dependency</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>maven-simple</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencyManagement>

View File

@ -3,14 +3,24 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>core</artifactId>
<name>core</name>
<parent>
<artifactId>parent-project</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
</parent>
</project>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-core.version}</version>
</dependency>
</dependencies>
<properties>
<spring-core.version>4.3.30.RELEASE</spring-core.version>
</properties>
</project>

View File

@ -4,6 +4,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>parent-project</artifactId>
<version>1.0-SNAPSHOT</version>
<name>parent-project</name>
<packaging>pom</packaging>
@ -18,4 +19,18 @@
<module>service</module>
<module>webapp</module>
</modules>
</project>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-core.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<properties>
<spring-core.version>5.3.16</spring-core.version>
</properties>
</project>

View File

@ -3,14 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>service</artifactId>
<name>service</name>
<parent>
<artifactId>parent-project</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
</parent>
</project>
</project>

View File

@ -3,14 +3,31 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.baeldung</groupId>
<artifactId>webapp</artifactId>
<name>webapp</name>
<packaging>war</packaging>
<parent>
<artifactId>parent-project</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
</parent>
</project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>${maven-war-plugin.version}</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven-war-plugin.version>3.3.2</maven-war-plugin.version>
</properties>
</project>

View File

@ -92,4 +92,4 @@
<metrics-aspectj.version>1.1.0</metrics-aspectj.version>
</properties>
</project>
</project>

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>netty</artifactId>
<version>0.0.1-SNAPSHOT</version>
@ -11,20 +12,18 @@
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>${netty.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>org.conscrypt</groupId>
<artifactId>conscrypt-openjdk-uber</artifactId>
<version>${conscrypt-openjdk-uber.version}</version>
</dependency>
</dependencies>
<properties>

View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [Using Nginx as a Forward Proxy](https://www.baeldung.com/nginx-forward-proxy)

View File

@ -16,6 +16,25 @@
<module>wire-tap</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>${log4j2.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
@ -39,25 +58,6 @@
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>${camel.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-bom</artifactId>
<version>${log4j2.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
@ -70,7 +70,7 @@
<properties>
<camel.version>3.7.4</camel.version>
<spring-boot.version>2.2.2.RELEASE</spring-boot.version>
<log4j2.version>2.17.1</log4j2.version>
<log4j2.version>2.17.1</log4j2.version>
</properties>
</project>

View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [Building a web app Using Fauna and Spring for Your First web Agency Client](https://www.baeldung.com/faunadb-spring-web-app)

View File

@ -54,22 +54,22 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${javax.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${javax.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
</dependencies>
<properties>

View File

@ -77,4 +77,4 @@
<netty-transport-version>4.1.71.Final</netty-transport-version>
</properties>
</project>
</project>

View File

@ -0,0 +1,5 @@
.classpath
.project
.settings
target
build

View File

@ -0,0 +1,5 @@
## MongoDB
This module contains articles about MongoDB in Java.

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>java-mongodb-2</artifactId>
<version>1.0-SNAPSHOT</version>
<name>java-mongodb-2</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>persistence-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>de.flapdoodle.embedmongo</groupId>
<artifactId>de.flapdoodle.embedmongo</artifactId>
<version>${flapdoodle.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>${mongo.version}</version>
</dependency>
<dependency>
<groupId>dev.morphia.morphia</groupId>
<artifactId>core</artifactId>
<version>${morphia.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<version>1.16.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.16.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<mongo.version>3.12.1</mongo.version>
<flapdoodle.version>1.11</flapdoodle.version>
<morphia.version>1.5.3</morphia.version>
</properties>
</project>

View File

@ -0,0 +1,54 @@
package com.baeldung.mongo.update;
import org.bson.Document;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
import com.mongodb.client.result.UpdateResult;
public class PustSetOperation {
private static MongoClient mongoClient;
private static String testCollectionName;
private static String databaseName;
public static void setUp() {
if (mongoClient == null) {
mongoClient = new MongoClient("localhost", 27017);
}
databaseName = "baeldung";
testCollectionName = "marks";
}
public static void pushSetSolution() {
MongoDatabase database = mongoClient.getDatabase(databaseName);
MongoCollection<Document> collection = database.getCollection(testCollectionName);
Document subjectData = new Document().append("subjectId", 126)
.append("subjectName", "Java Programming")
.append("marks", 70);
UpdateResult updateQueryResult = collection.updateOne(Filters.eq("studentId", 1023), Updates.combine(Updates.set("totalMarks", 170), Updates.push("subjectDetails", subjectData)));
System.out.println("updateQueryResult:- " + updateQueryResult);
}
public static void main(String args[]) {
//
// Connect to cluster (default is localhost:27017)
//
setUp();
//
// Push document into the array and set a field
//
pushSetSolution();
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="STDOUT" />
</root>
</configuration>

View File

@ -0,0 +1,53 @@
package com.baeldung.update;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import org.bson.Document;
import org.junit.BeforeClass;
import org.junit.Test;
import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import com.mongodb.client.model.Updates;
import com.mongodb.client.result.UpdateResult;
public class PustSetOperationLiveTest {
private static MongoClient mongoClient;
private static MongoDatabase db;
private static MongoCollection<Document> collection;
@BeforeClass
public static void setup() {
if (mongoClient == null) {
mongoClient = new MongoClient("localhost", 27017);
db = mongoClient.getDatabase("baeldung");
collection = db.getCollection("marks");
collection.insertOne(Document.parse("{\n" + " \"studentId\": 1023,\n" + " \"studentName\":\"James Broad\",\n" + " \"joiningYear\":\"2018\",\n" + " \"totalMarks\":100,\n" + " \"subjectDetails\":[\n"
+ " {\n" + " \"subjectId\":123,\n" + " \"subjectName\":\"Operating Systems Concepts\",\n" + " \"marks\":4,\n" + " },\n" + " {\n"
+ " \"subjectId\":124,\n" + " \"subjectName\":\"Numerical Analysis\",\n" + " \"marks\":60\n" + " }\n" + " ]\n" + " }"));
}
}
@Test
public void givenMarksCollection_whenPushSetOperation_thenCheckingForDocument() {
Document subjectData = new Document().append("subjectId", 126)
.append("subjectName", "Java Programming")
.append("marks", 70);
UpdateResult updateQueryResult = collection.updateOne(Filters.eq("studentId", 1023), Updates.combine(Updates.set("totalMarks", 170), Updates.push("subjectDetails", subjectData)));
Document studentDetail = collection.find(Filters.eq("studentId", 1023))
.first();
assertNotNull(studentDetail);
assertFalse(studentDetail.isEmpty());
}
}

View File

@ -14,3 +14,7 @@ This module contains articles about MongoDB in Java.
- [How to Check Field Existence in MongoDB?](https://www.baeldung.com/mongodb-check-field-exists)
- [Get Last Inserted Document ID in MongoDB With Java Driver](https://www.baeldung.com/java-mongodb-last-inserted-id)
- [Update Multiple Fields in a MongoDB Document](https://www.baeldung.com/mongodb-update-multiple-fields)
- [Update Documents in MongoDB](https://www.baeldung.com/mongodb-update-documents)
- [Check Collection Existence in MongoDB](https://www.baeldung.com/java-check-collection-existence-mongodb)
- [Case Insensitive Sorting in MongoDB](https://www.baeldung.com/java-mongodb-case-insensitive-sorting)
- [Push and Set Operations in Same MongoDB Update](https://www.baeldung.com/java-mongodb-push-set)

View File

@ -30,6 +30,18 @@
<artifactId>core</artifactId>
<version>${morphia.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<version>1.16.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<version>1.16.3</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>

View File

@ -0,0 +1,108 @@
package com.baeldung.ordering.caseinsensitive;
import com.mongodb.MongoClient;
import com.mongodb.client.*;
import com.mongodb.client.model.Collation;
import com.mongodb.client.model.Projections;
import com.mongodb.client.model.Sorts;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static com.mongodb.client.model.Aggregates.project;
import static com.mongodb.client.model.Aggregates.sort;
import static com.mongodb.client.model.Sorts.ascending;
import static org.junit.Assert.assertEquals;
@Testcontainers
class CaseInsensitiveOrderingLiveTest {
private static MongoCollection<Document> userCollections;
@Container
private static final MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:4.0.10"));
@BeforeAll
private static void setup() {
MongoClient mongoClient = new MongoClient(mongoDBContainer.getContainerIpAddress(), mongoDBContainer.getMappedPort(27017));
MongoDatabase database = mongoClient.getDatabase("test");
userCollections = database.getCollection("users");
List<Document> list = new ArrayList<>();
list.add(Document.parse("{'name': 'ben', surname: 'ThisField' }"));
list.add(Document.parse("{'name': 'aen', surname: 'Does' }"));
list.add(Document.parse("{'name': 'Ben', surname: 'Not' }"));
list.add(Document.parse("{'name': 'cen', surname: 'Matter' }"));
list.add(Document.parse("{'name': 'Aen', surname: 'Really' }"));
list.add(Document.parse("{'name': 'Cen', surname: 'TrustMe' }"));
userCollections.insertMany(list);
}
@Test
void givenMongoCollection_whenUsingFindWithSort_caseIsConsideredByDefault() {
FindIterable<Document> nameDoc = userCollections.find().sort(ascending("name"));
MongoCursor<Document> cursor = nameDoc.cursor();
List<String> expectedNamesOrdering = Arrays.asList("Aen", "Ben", "Cen", "aen", "ben", "cen");
List<String> actualNamesOrdering = new ArrayList<>();
while (cursor.hasNext()) {
Document document = cursor.next();
actualNamesOrdering.add(document.get("name").toString());
}
assertEquals(expectedNamesOrdering, actualNamesOrdering);
}
@Test
void givenMongoCollection_whenUsingFindWithSortAndCollation_caseIsNotConsidered() {
FindIterable<Document> nameDoc = userCollections.find().sort(ascending("name"))
.collation(Collation.builder().locale("en").build());
MongoCursor<Document> cursor = nameDoc.cursor();
List<String> expectedNamesOrdering = Arrays.asList("aen", "Aen", "ben", "Ben", "cen", "Cen");
List<String> actualNamesOrdering = new ArrayList<>();
while (cursor.hasNext()) {
Document document = cursor.next();
actualNamesOrdering.add(document.get("name").toString());
}
assertEquals(expectedNamesOrdering, actualNamesOrdering);
}
@Test
void givenMongoCollection_whenUsingFindWithSortAndAggregate_caseIsNotConsidered() {
Bson projectBson = project(
Projections.fields(
Projections.include("name", "surname"),
Projections.computed("lowerName", Projections.computed("$toLower", "$name"))));
AggregateIterable<Document> nameDoc = userCollections.aggregate(
Arrays.asList(projectBson,
sort(Sorts.ascending("lowerName"))));
MongoCursor<Document> cursor = nameDoc.cursor();
List<String> expectedNamesOrdering = Arrays.asList("aen", "Aen", "ben", "Ben", "cen", "Cen");
List<String> actualNamesOrdering = new ArrayList<>();
while (cursor.hasNext()) {
Document document = cursor.next();
actualNamesOrdering.add(document.get("name").toString());
}
assertEquals(expectedNamesOrdering, actualNamesOrdering);
}
}

View File

@ -43,6 +43,7 @@
<module>java-jpa-2</module> <!-- long running -->
<module>java-jpa-3</module>
<module>java-mongodb</module> <!-- long running -->
<module>java-mongodb-2</module> <!-- long running -->
<module>jnosql</module> <!-- long running -->
<module>jooq</module>
<module>jpa-hibernate-cascade-type</module>
@ -104,4 +105,4 @@
<postgresql.version>42.2.20</postgresql.version>
</properties>
</project>
</project>

View File

@ -36,4 +36,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@ -19,6 +19,7 @@ public class TodoDatasourceConfiguration {
@Bean
@Primary
@ConfigurationProperties("spring.datasource.todos.hikari")
public DataSource todosDataSource() {
return todosDataSourceProperties()
.initializeDataSourceBuilder()

View File

@ -3,6 +3,7 @@ spring.datasource.todos.url=jdbc:h2:mem:todos
spring.datasource.todos.username=sa
spring.datasource.todos.password=null
spring.datasource.todos.driverClassName=org.h2.Driver
spring.datasource.todos.hikari.connectionTimeout=44444
spring.datasource.topics.url=jdbc:h2:mem:topics
spring.datasource.topics.username=sa
spring.datasource.topics.password=null

View File

@ -29,4 +29,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@ -107,22 +107,22 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${javax.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${javax.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${com.sun.xml.version}</version>
</dependency>
</dependencies>
<properties>

View File

@ -1206,6 +1206,7 @@
<module>wicket</module>
<module>wildfly</module>
<module>xml</module>
<module>xml-2</module>
<module>xstream</module>
</modules>

View File

@ -23,4 +23,4 @@
</dependency>
</dependencies>
</project>
</project>

View File

@ -10,9 +10,8 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>reactive-systems</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@ -10,9 +10,8 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>reactive-systems</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@ -10,8 +10,9 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
<artifactId>parent-boot-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<modules>

View File

@ -10,9 +10,8 @@
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-boot-2</artifactId>
<artifactId>reactive-systems</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@ -13,7 +13,7 @@
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencyManagement>
<dependencies>
<dependency>

View File

@ -41,4 +41,5 @@
<properties>
<reactor-spring.version>1.0.1.RELEASE</reactor-spring.version>
</properties>
</project>

View File

@ -16,7 +16,7 @@
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-1</relativePath>
</parent>
<dependencyManagement>
<dependencies>
<dependency>

View File

@ -0,0 +1 @@
/output/

View File

@ -44,6 +44,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
@ -57,6 +63,9 @@
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.baeldung.camel.boot.testing.GreetingsFileSpringApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>

View File

@ -0,0 +1,19 @@
package com.baeldung.camel.boot.testing;
import org.apache.camel.builder.RouteBuilder;
import org.springframework.stereotype.Component;
@Component
public class GreetingsFileRouter extends RouteBuilder {
@Override
public void configure() throws Exception {
from("direct:start")
.routeId("greetings-route")
.setBody(constant("Hello Baeldung Readers!"))
.to("file:output");
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.camel.boot.testing;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class GreetingsFileSpringApplication {
public static void main(String[] args) {
SpringApplication.run(GreetingsFileSpringApplication.class, args);
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.camel.boot.testing;
import org.apache.camel.EndpointInject;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.spring.junit5.CamelSpringBootTest;
import org.apache.camel.test.spring.junit5.MockEndpoints;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
@CamelSpringBootTest
@MockEndpoints("file:output")
class GreetingsFileRouterUnitTest {
@Autowired
private ProducerTemplate template;
@EndpointInject("mock:file:output")
private MockEndpoint mock;
@Test
void whenSendBody_thenGreetingReceivedSuccessfully() throws InterruptedException {
mock.expectedBodiesReceived("Hello Baeldung Readers!");
template.sendBody("direct:start", null);
mock.assertIsSatisfied();
}
}

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-multiple-datasources</artifactId>
<version>0.1.0-SNAPSHOT</version>
@ -55,4 +55,4 @@
<spring-boot.version>2.6.3</spring-boot.version>
</properties>
</project>
</project>

View File

@ -0,0 +1,3 @@
### Relevant Articles:
- [Set List of Objects in Swagger API Response](https://www.baeldung.com/java-swagger-set-list-response)

View File

@ -0,0 +1,13 @@
package com.baeldung.swaggerresponseapi;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SwaggerResponseApiApplication {
public static void main(String[] args) {
SpringApplication.run(SwaggerResponseApiApplication.class, args);
}
}

View File

@ -0,0 +1,38 @@
package com.baeldung.swaggerresponseapi.controller;
import com.baeldung.swaggerresponseapi.model.Product;
import com.baeldung.swaggerresponseapi.service.ProductService;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
public class ProductController {
private final ProductService productService;
public ProductController(ProductService productService) {
this.productService = productService;
}
@PostMapping("/create")
public Product addProduct(@RequestBody Product product) {
return productService.addProducts(product);
}
@ApiResponses(value = { @ApiResponse(content = { @Content(mediaType = "application/json",
array = @ArraySchema(schema = @Schema(implementation = Product.class))) }) })
@GetMapping("/products")
public List<Product> getProductsList() {
return productService.getProductsList();
}
}

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