Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
64f0428e00
|
@ -31,3 +31,5 @@ spring-openid/src/main/resources/application.properties
|
|||
.recommenders/
|
||||
/spring-hibernate4/nbproject/
|
||||
spring-security-openid/src/main/resources/application.properties
|
||||
|
||||
spring-all/*.log
|
||||
|
|
|
@ -5,3 +5,4 @@
|
|||
- [Ant Colony Optimization](http://www.baeldung.com/java-ant-colony-optimization)
|
||||
- [Validating Input With Finite Automata in Java](http://www.baeldung.com/finite-automata-java)
|
||||
- [Introduction to Jenetics Library](http://www.baeldung.com/jenetics)
|
||||
- [Check If a Number Is Prime in Java](http://www.baeldung.com/java-prime-numbers)
|
||||
|
|
|
@ -3,8 +3,10 @@ package com.baeldung.cxf.aegis;
|
|||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.lang.reflect.Type;
|
||||
|
@ -90,4 +92,12 @@ public class BaeldungTest {
|
|||
xmlReader.close();
|
||||
return courseRepo;
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup(){
|
||||
File testFile = new File(fileName);
|
||||
if (testFile.exists()) {
|
||||
testFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -54,6 +54,12 @@
|
|||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -24,6 +24,12 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
|
|
@ -28,11 +28,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
|
@ -78,6 +73,10 @@
|
|||
<groupId>org.apache.avalon.framework</groupId>
|
||||
<artifactId>avalon-framework-impl</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
@ -90,6 +89,12 @@
|
|||
<groupId>avalon-framework</groupId>
|
||||
<artifactId>avalon-framework-impl</artifactId>
|
||||
<version>${avalon-framework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -42,6 +42,12 @@
|
|||
<groupId>org.jxls</groupId>
|
||||
<artifactId>jxls-jexcel</artifactId>
|
||||
<version>${jexcel.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.After;
|
||||
|
||||
public class JExcelTest {
|
||||
|
||||
|
@ -53,4 +54,11 @@ public class JExcelTest {
|
|||
.get(1));
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup(){
|
||||
File testFile = new File(fileLocation);
|
||||
if (testFile.exists()) {
|
||||
testFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,6 +16,7 @@ import static org.junit.Assert.assertTrue;
|
|||
|
||||
import org.junit.Test;
|
||||
import org.junit.Before;
|
||||
import org.junit.After;
|
||||
|
||||
public class ExcelTest {
|
||||
|
||||
|
@ -50,4 +51,11 @@ public class ExcelTest {
|
|||
.get(1));
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup(){
|
||||
File testFile = new File(fileLocation);
|
||||
if (testFile.exists()) {
|
||||
testFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
|
@ -19,6 +19,12 @@
|
|||
<groupId>org.apache.thrift</groupId>
|
||||
<artifactId>libthrift</artifactId>
|
||||
<version>${thrift.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.velocity</groupId>
|
||||
<artifactId>velocity-tools</artifactId>
|
||||
<version>${velocity-tools-version}</version>
|
||||
<version>${velocity-tools-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
|
@ -55,6 +55,12 @@
|
|||
<artifactId>httpclient</artifactId>
|
||||
<version>${org.apache.httpcomponents.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>4.3.4.RELEASE</version>
|
||||
<version>4.3.4.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cglib</groupId>
|
||||
|
|
12
aws/pom.xml
12
aws/pom.xml
|
@ -19,12 +19,24 @@
|
|||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-core</artifactId>
|
||||
<version>${aws-lambda-java-core.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.amazonaws</groupId>
|
||||
<artifactId>aws-lambda-java-events</artifactId>
|
||||
<version>${aws-lambda-java-events.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -12,6 +12,12 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
|
|
@ -12,3 +12,4 @@
|
|||
- [Spring Security – Redirect to the Previous URL After Login](http://www.baeldung.com/spring-security-redirect-login)
|
||||
- [Java 9 Process API Improvements](http://www.baeldung.com/java-9-process-api)
|
||||
- [Introduction to Java 9 StackWalking API](http://www.baeldung.com/java-9-stackwalking-api)
|
||||
- [Introduction to Project Jigsaw](http://www.baeldung.com/project-jigsaw-java-modularity)
|
||||
|
|
|
@ -92,3 +92,9 @@
|
|||
- [Removing all nulls from a List in Java](http://www.baeldung.com/java-remove-nulls-from-list)
|
||||
- [Removing all duplicates from a List in Java](http://www.baeldung.com/java-remove-duplicates-from-list)
|
||||
- [An Introduction to ThreadLocal in Java](http://www.baeldung.com/java-threadlocal)
|
||||
- [Using Math.pow in Java](http://www.baeldung.com/java-math-pow)
|
||||
- [Converting Strings to Enums in Java](http://www.baeldung.com/java-string-to-enum)
|
||||
- [Flattening Nested Collections in Java](http://www.baeldung.com/java-flatten-nested-collections)
|
||||
- [Quick Guide to the Java StringTokenizer](http://www.baeldung.com/java-stringtokenizer)
|
||||
- [JVM Log Forging](http://www.baeldung.com/jvm-log-forging)
|
||||
- [Guide to sun.misc.Unsafe](http://www.baeldung.com/java-unsafe)
|
||||
|
|
|
@ -92,11 +92,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
@ -176,6 +171,12 @@
|
|||
<groupId>org.owasp.esapi</groupId>
|
||||
<artifactId>esapi</artifactId>
|
||||
<version>2.1.0.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package com.baeldung.transferqueue;
|
||||
|
||||
import java.util.concurrent.TransferQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Consumer implements Runnable {
|
||||
private final TransferQueue<String> transferQueue;
|
||||
private final String name;
|
||||
private final int numberOfMessagesToConsume;
|
||||
public final AtomicInteger numberOfConsumedMessages = new AtomicInteger();
|
||||
|
||||
public Consumer(TransferQueue<String> transferQueue, String name, int numberOfMessagesToConsume) {
|
||||
this.transferQueue = transferQueue;
|
||||
this.name = name;
|
||||
this.numberOfMessagesToConsume = numberOfMessagesToConsume;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < numberOfMessagesToConsume; i++) {
|
||||
try {
|
||||
System.out.println("Consumer: " + name + " is waiting to take element...");
|
||||
String element = transferQueue.take();
|
||||
longProcessing(element);
|
||||
System.out.println("Consumer: " + name + " received element: " + element);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void longProcessing(String element) throws InterruptedException {
|
||||
numberOfConsumedMessages.incrementAndGet();
|
||||
Thread.sleep(500);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.baeldung.transferqueue;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TransferQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class Producer implements Runnable {
|
||||
private final TransferQueue<String> transferQueue;
|
||||
private final String name;
|
||||
private final Integer numberOfMessagesToProduce;
|
||||
public final AtomicInteger numberOfProducedMessages = new AtomicInteger();
|
||||
|
||||
public Producer(TransferQueue<String> transferQueue, String name, Integer numberOfMessagesToProduce) {
|
||||
this.transferQueue = transferQueue;
|
||||
this.name = name;
|
||||
this.numberOfMessagesToProduce = numberOfMessagesToProduce;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < numberOfMessagesToProduce; i++) {
|
||||
try {
|
||||
System.out.println("Producer: " + name + " is waiting to transfer...");
|
||||
boolean added = transferQueue.tryTransfer("A" + i, 4000, TimeUnit.MILLISECONDS);
|
||||
if (!added) {
|
||||
System.out.println("can not add an element due to the timeout");
|
||||
} else {
|
||||
numberOfProducedMessages.incrementAndGet();
|
||||
System.out.println("Producer: " + name + " transferred element: A" + i);
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
package com.baeldung.synchronousqueue;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class SynchronousQueueTest {
|
||||
|
||||
@Test
|
||||
public void givenTwoThreads_whenWantToExchangeUsingLockGuardedVariable_thenItSucceed() throws InterruptedException {
|
||||
//given
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
AtomicInteger sharedState = new AtomicInteger();
|
||||
CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
|
||||
Runnable producer = () -> {
|
||||
Integer producedElement = ThreadLocalRandom.current().nextInt();
|
||||
System.out.println("Saving an element: " + producedElement + " to the exchange point");
|
||||
sharedState.set(producedElement);
|
||||
countDownLatch.countDown();
|
||||
};
|
||||
|
||||
Runnable consumer = () -> {
|
||||
try {
|
||||
countDownLatch.await();
|
||||
Integer consumedElement = sharedState.get();
|
||||
System.out.println("consumed an element: " + consumedElement + " from the exchange point");
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
//when
|
||||
executor.execute(producer);
|
||||
executor.execute(consumer);
|
||||
|
||||
//then
|
||||
executor.awaitTermination(500, TimeUnit.MILLISECONDS);
|
||||
executor.shutdown();
|
||||
assertEquals(countDownLatch.getCount(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTwoThreads_whenWantToExchangeUsingSynchronousQueue_thenItSucceed() throws InterruptedException {
|
||||
//given
|
||||
ExecutorService executor = Executors.newFixedThreadPool(2);
|
||||
final SynchronousQueue<Integer> queue = new SynchronousQueue<>();
|
||||
|
||||
Runnable producer = () -> {
|
||||
Integer producedElement = ThreadLocalRandom.current().nextInt();
|
||||
try {
|
||||
System.out.println("Saving an element: " + producedElement + " to the exchange point");
|
||||
queue.put(producedElement);
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
Runnable consumer = () -> {
|
||||
try {
|
||||
Integer consumedElement = queue.take();
|
||||
System.out.println("consumed an element: " + consumedElement + " from the exchange point");
|
||||
} catch (InterruptedException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
};
|
||||
|
||||
//when
|
||||
executor.execute(producer);
|
||||
executor.execute(consumer);
|
||||
|
||||
//then
|
||||
executor.awaitTermination(500, TimeUnit.MILLISECONDS);
|
||||
executor.shutdown();
|
||||
assertEquals(queue.size(), 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package com.baeldung.transferqueue;
|
||||
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class TransferQueueTest {
|
||||
|
||||
@Test
|
||||
public void givenTransferQueue_whenUseMultipleConsumersAndMultipleProducers_thenShouldProcessAllMessages() throws InterruptedException {
|
||||
//given
|
||||
TransferQueue<String> transferQueue = new LinkedTransferQueue<>();
|
||||
ExecutorService exService = Executors.newFixedThreadPool(3);
|
||||
Producer producer1 = new Producer(transferQueue, "1", 3);
|
||||
Producer producer2 = new Producer(transferQueue, "2", 3);
|
||||
Consumer consumer1 = new Consumer(transferQueue, "1", 3);
|
||||
Consumer consumer2 = new Consumer(transferQueue, "2", 3);
|
||||
|
||||
//when
|
||||
exService.execute(producer1);
|
||||
exService.execute(producer2);
|
||||
exService.execute(consumer1);
|
||||
exService.execute(consumer2);
|
||||
|
||||
//then
|
||||
exService.awaitTermination(10_000, TimeUnit.MILLISECONDS);
|
||||
exService.shutdown();
|
||||
|
||||
assertEquals(producer1.numberOfProducedMessages.intValue(), 3);
|
||||
assertEquals(producer2.numberOfProducedMessages.intValue(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTransferQueue_whenUseOneConsumerAndOneProducer_thenShouldProcessAllMessages() throws InterruptedException {
|
||||
//given
|
||||
TransferQueue<String> transferQueue = new LinkedTransferQueue<>();
|
||||
ExecutorService exService = Executors.newFixedThreadPool(2);
|
||||
Producer producer = new Producer(transferQueue, "1", 3);
|
||||
Consumer consumer = new Consumer(transferQueue, "1", 3);
|
||||
|
||||
//when
|
||||
exService.execute(producer);
|
||||
exService.execute(consumer);
|
||||
|
||||
//then
|
||||
exService.awaitTermination(5000, TimeUnit.MILLISECONDS);
|
||||
exService.shutdown();
|
||||
|
||||
assertEquals(producer.numberOfProducedMessages.intValue(), 3);
|
||||
assertEquals(consumer.numberOfConsumedMessages.intValue(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenTransferQueue_whenUseOneProducerAndNoConsumers_thenShouldFailWithTimeout() throws InterruptedException {
|
||||
//given
|
||||
TransferQueue<String> transferQueue = new LinkedTransferQueue<>();
|
||||
ExecutorService exService = Executors.newFixedThreadPool(2);
|
||||
Producer producer = new Producer(transferQueue, "1", 3);
|
||||
|
||||
//when
|
||||
exService.execute(producer);
|
||||
|
||||
//then
|
||||
exService.awaitTermination(5000, TimeUnit.MILLISECONDS);
|
||||
exService.shutdown();
|
||||
|
||||
assertEquals(producer.numberOfProducedMessages.intValue(), 0);
|
||||
}
|
||||
}
|
|
@ -6,12 +6,14 @@ import java.io.FileNotFoundException;
|
|||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class FileNotFoundExceptionUnitTest {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(FileNotFoundExceptionUnitTest.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(FileNotFoundExceptionUnitTest.class);
|
||||
|
||||
private String fileName = Double.toString(Math.random());
|
||||
|
||||
|
|
|
@ -22,11 +22,23 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring-framework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context-support</artifactId>
|
||||
<version>${spring-framework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Logging with SLF4J & LogBack -->
|
||||
|
@ -46,11 +58,6 @@
|
|||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Test-Scoped Dependencies -->
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Cucumber and Scenario Outline](http://www.baeldung.com/cucumber-scenario-outline)
|
|
@ -201,12 +201,6 @@
|
|||
<artifactId>querydsl-jpa</artifactId>
|
||||
<version>${querydsl.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -40,11 +40,6 @@
|
|||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<feign.version>9.4.0</feign.version>
|
||||
<slf4j.version>1.7.21</slf4j.version>
|
||||
<log4j.version>2.7</log4j.version>
|
||||
<lombok.version>1.16.12</lombok.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
|
@ -52,16 +51,6 @@
|
|||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<version>${log4j.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="WARN">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36}:%n[+] %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
|
||||
<Loggers>
|
||||
<Root level="debug">
|
||||
<AppenderRef ref="Console"/>
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock)
|
|
@ -76,11 +76,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
## Relevant articles:
|
||||
### Relevant articles:
|
||||
- [New Stream, Comparator and Collector Functionality in Guava 21](http://www.baeldung.com/guava-21-new)
|
||||
|
|
|
@ -155,11 +155,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -28,6 +28,12 @@
|
|||
<groupId>org.apache.hbase</groupId>
|
||||
<artifactId>hbase-client</artifactId>
|
||||
<version>${hbase.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.hbase</groupId>
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
<?xml version="1.0"?>
|
||||
<project
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>hibernate5</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>hibernate5</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<!-- Maven plugins -->
|
||||
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>5.2.9.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>1.4.194</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<finalName>hibernate5</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven-compiler-plugin.version}</version>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,30 @@
|
|||
package com.baeldung.hibernate;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
|
||||
import com.baeldung.hibernate.pojo.Supplier;
|
||||
|
||||
/**
|
||||
* Hello world!
|
||||
*
|
||||
*/
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
// NOTE: this is just for boostrap testing for multitenancy.
|
||||
System.out.println("Checking the system.");
|
||||
SessionFactory sessionFactory = HibernateMultiTenantUtil.getSessionFactory();
|
||||
Session currentSession = sessionFactory.withOptions().tenantIdentifier("h2db1").openSession();
|
||||
Transaction transaction = currentSession.getTransaction();
|
||||
transaction.begin();
|
||||
currentSession.createCriteria(Supplier.class).list().stream().forEach(System.out::println);
|
||||
transaction.commit();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package com.baeldung.hibernate;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.engine.jdbc.connections.spi.AbstractMultiTenantConnectionProvider;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
|
||||
public class ConfigurableMultiTenantConnectionProvider extends AbstractMultiTenantConnectionProvider {
|
||||
|
||||
private final Map<String, ConnectionProvider> connectionProviderMap =
|
||||
new HashMap<>();
|
||||
|
||||
|
||||
public ConfigurableMultiTenantConnectionProvider(
|
||||
Map<String, ConnectionProvider> connectionProviderMap) {
|
||||
this.connectionProviderMap.putAll( connectionProviderMap );
|
||||
}
|
||||
@Override
|
||||
protected ConnectionProvider getAnyConnectionProvider() {
|
||||
System.out.println("Any");
|
||||
return connectionProviderMap.values().iterator().next();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ConnectionProvider selectConnectionProvider(String tenantIdentifier) {
|
||||
System.out.println("Specific");
|
||||
return connectionProviderMap.get( tenantIdentifier );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection(String tenantIdentifier) throws SQLException {
|
||||
Connection connection = super.getConnection(tenantIdentifier);
|
||||
// uncomment to see option 2 for SCHEMA strategy.
|
||||
//connection.createStatement().execute("SET SCHEMA '" + tenantIdentifier + "'");
|
||||
return connection;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
package com.baeldung.hibernate;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.Metadata;
|
||||
import org.hibernate.boot.MetadataSources;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
import org.hibernate.cfg.Environment;
|
||||
import org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl;
|
||||
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import com.baeldung.hibernate.pojo.Supplier;
|
||||
|
||||
public class HibernateMultiTenantUtil {
|
||||
private static SessionFactory sessionFactory;
|
||||
private static Map<String, ConnectionProvider> connectionProviderMap = new HashMap<>();
|
||||
private static final String[] tenantDBNames = { "mydb1","mydb2"};
|
||||
|
||||
public static SessionFactory getSessionFactory() throws UnsupportedTenancyException {
|
||||
if (sessionFactory == null) {
|
||||
Configuration configuration = new Configuration().configure();
|
||||
ServiceRegistry serviceRegistry = configureServiceRegistry(configuration);
|
||||
sessionFactory = makeSessionFactory (serviceRegistry);
|
||||
// sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
||||
|
||||
|
||||
}
|
||||
return sessionFactory;
|
||||
}
|
||||
|
||||
private static SessionFactory makeSessionFactory(ServiceRegistry serviceRegistry) {
|
||||
MetadataSources metadataSources = new MetadataSources( serviceRegistry );
|
||||
for(Class annotatedClasses : getAnnotatedClasses()) {
|
||||
metadataSources.addAnnotatedClass( annotatedClasses );
|
||||
}
|
||||
|
||||
Metadata metadata = metadataSources.buildMetadata();
|
||||
return metadata.getSessionFactoryBuilder().build();
|
||||
|
||||
}
|
||||
|
||||
private static Class<?>[] getAnnotatedClasses() {
|
||||
return new Class<?>[] {
|
||||
Supplier.class
|
||||
};
|
||||
}
|
||||
|
||||
private static ServiceRegistry configureServiceRegistry(Configuration configuration) throws UnsupportedTenancyException {
|
||||
Properties properties = configuration.getProperties();
|
||||
|
||||
connectionProviderMap = setUpConnectionProviders(properties, tenantDBNames);
|
||||
properties.put(AvailableSettings.MULTI_TENANT_CONNECTION_PROVIDER, new ConfigurableMultiTenantConnectionProvider(connectionProviderMap));
|
||||
|
||||
return new StandardServiceRegistryBuilder().applySettings(properties).build();
|
||||
}
|
||||
|
||||
private static Map<String, ConnectionProvider> setUpConnectionProviders(Properties properties, String[] tenantNames) throws UnsupportedTenancyException {
|
||||
Map<String, ConnectionProvider> providerMap = new HashMap<>();
|
||||
for (String tenant : tenantNames) {
|
||||
DriverManagerConnectionProviderImpl connectionProvider = new DriverManagerConnectionProviderImpl();
|
||||
|
||||
String tenantStrategy = properties.getProperty("hibernate.multiTenancy");
|
||||
System.out.println("Strategy:"+tenantStrategy);
|
||||
properties.put(Environment.URL, tenantUrl(properties.getProperty(Environment.URL), tenant, tenantStrategy));
|
||||
System.out.println("URL:"+properties.getProperty(Environment.URL));
|
||||
connectionProvider.configure(properties);
|
||||
System.out.println("Tenant:"+tenant);
|
||||
providerMap.put(tenant, connectionProvider);
|
||||
|
||||
}
|
||||
System.out.println("Added connections for:");
|
||||
providerMap.keySet().stream().forEach(System.out::println);
|
||||
return providerMap;
|
||||
}
|
||||
|
||||
private static Object tenantUrl(String originalUrl, String tenant, String tenantStrategy) throws UnsupportedTenancyException {
|
||||
if (tenantStrategy.toUpperCase().equals("DATABASE")) {
|
||||
return originalUrl.replace(DEFAULT_DB_NAME, tenant);
|
||||
} else if (tenantStrategy.toUpperCase().equals("SCHEMA")) {
|
||||
return originalUrl + String.format(SCHEMA_TOKEN, tenant);
|
||||
} else {
|
||||
throw new UnsupportedTenancyException("Not yet supported");
|
||||
}
|
||||
}
|
||||
|
||||
public static final String SCHEMA_TOKEN = ";INIT=CREATE SCHEMA IF NOT EXISTS %1$s\\;SET SCHEMA %1$s";
|
||||
public static final String DEFAULT_DB_NAME = "mydb1";
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.hibernate;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.cfg.Configuration;
|
||||
|
||||
public class HibernateUtil {
|
||||
|
||||
private static final SessionFactory sessionFactory;
|
||||
|
||||
static {
|
||||
try {
|
||||
Configuration configuration = new Configuration().configure();
|
||||
sessionFactory = configuration.buildSessionFactory();
|
||||
|
||||
} catch (Throwable ex) {
|
||||
System.err.println("Initial SessionFactory creation failed." + ex);
|
||||
throw new ExceptionInInitializerError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
return sessionFactory;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package com.baeldung.hibernate;
|
||||
|
||||
public class UnsupportedTenancyException extends Exception {
|
||||
public UnsupportedTenancyException (String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
package com.baeldung.hibernate.pojo;
|
||||
// Generated Feb 9, 2017 11:31:36 AM by Hibernate Tools 5.1.0.Final
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
|
||||
|
||||
/**
|
||||
* Suppliers generated by hbm2java
|
||||
*/
|
||||
@Entity(name = "Supplier")
|
||||
@Table(name ="Supplier")
|
||||
public class Supplier implements java.io.Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer id;
|
||||
private String name;
|
||||
private String country;
|
||||
|
||||
public Supplier() {
|
||||
}
|
||||
|
||||
public Supplier(String name, String country) {
|
||||
this.name = name;
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return this.country;
|
||||
}
|
||||
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new StringBuffer().append("[").append(id).append(",").append(name).append(",").append(country).append("]").toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return name.equals(((Supplier) obj).getName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE hibernate-configuration PUBLIC
|
||||
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
|
||||
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
|
||||
<property name="hibernate.connection.url">jdbc:h2:mem:mydb1;DB_CLOSE_DELAY=-1</property>
|
||||
<property name="hibernate.connection.username">sa</property>
|
||||
<property name="connection.password"/>
|
||||
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
|
||||
<property name="hibernate.multiTenancy">DATABASE</property>
|
||||
</session-factory>
|
||||
</hibernate-configuration>
|
|
@ -0,0 +1,73 @@
|
|||
package com.baeldung.hibernate;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.Transaction;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.hibernate.pojo.Supplier;
|
||||
|
||||
|
||||
public class MultiTenantHibernateTest {
|
||||
@Test
|
||||
public void givenDBMode_whenFetchingSuppliers_thenComparingFromDbs () {
|
||||
SessionFactory sessionFactory;
|
||||
try {
|
||||
sessionFactory = HibernateMultiTenantUtil.getSessionFactory();
|
||||
|
||||
Session db1Session = sessionFactory
|
||||
.withOptions().tenantIdentifier("mydb1").openSession();
|
||||
|
||||
initDb1(db1Session);
|
||||
|
||||
Transaction transaction = db1Session.getTransaction();
|
||||
transaction.begin();
|
||||
Supplier supplierFromDB1 = (Supplier)db1Session.createCriteria(Supplier.class).list().get(0);
|
||||
transaction.commit();
|
||||
|
||||
Session db2Session = sessionFactory
|
||||
.withOptions().tenantIdentifier("mydb2").openSession();
|
||||
|
||||
initDb2(db2Session);
|
||||
db2Session.getTransaction().begin();
|
||||
Supplier supplierFromDB2 = (Supplier) db2Session.createCriteria(Supplier.class).list().get(0);
|
||||
db2Session.getTransaction().commit();
|
||||
|
||||
System.out.println(supplierFromDB1);
|
||||
System.out.println(supplierFromDB2);
|
||||
|
||||
assertNotEquals(supplierFromDB1, supplierFromDB2);
|
||||
} catch (UnsupportedTenancyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initDb1(Session db1Session) {
|
||||
System.out.println("Init DB1");
|
||||
Transaction transaction = db1Session.getTransaction();
|
||||
transaction.begin();
|
||||
db1Session.createSQLQuery("DROP ALL OBJECTS").executeUpdate();
|
||||
db1Session.createSQLQuery("create table Supplier (id integer generated by default as identity, country varchar(255), name varchar(255), primary key (id))").executeUpdate();
|
||||
db1Session.createSQLQuery("insert into Supplier (id, country, name) values (null, 'John', 'USA')").executeUpdate();
|
||||
transaction.commit();
|
||||
}
|
||||
|
||||
private void initDb2(Session db2Session) {
|
||||
System.out.println("Init DB2");
|
||||
Transaction transaction = db2Session.getTransaction();
|
||||
transaction.begin();
|
||||
db2Session.createSQLQuery("DROP ALL OBJECTS").executeUpdate();
|
||||
db2Session.createSQLQuery("create table Supplier (id integer generated by default as identity, country varchar(255), name varchar(255), primary key (id))").executeUpdate();
|
||||
db2Session.createSQLQuery("insert into Supplier (id, country, name) values (null, 'Miller', 'UK')").executeUpdate();
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
|
@ -41,6 +41,12 @@
|
|||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>fluent-hc</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -59,6 +65,12 @@
|
|||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpasyncclient</artifactId>
|
||||
<version>${httpasyncclient.version}</version> <!-- 4.0.2 --> <!-- 4.1-beta1 -->
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- logging -->
|
||||
|
@ -80,11 +92,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
|
|
|
@ -56,6 +56,12 @@
|
|||
<groupId>com.netflix.hystrix</groupId>
|
||||
<artifactId>hystrix-core</artifactId>
|
||||
<version>${hystrix-core.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.netflix.hystrix</groupId>
|
||||
|
|
|
@ -17,11 +17,23 @@
|
|||
<groupId>net.imagej</groupId>
|
||||
<artifactId>ij</artifactId>
|
||||
<version>${ij.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openimaj</groupId>
|
||||
<artifactId>core-image</artifactId>
|
||||
<version>${core-image.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -27,3 +27,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [Guide to @JsonFormat in Jackson](http://www.baeldung.com/jackson-jsonformat)
|
||||
- [A Guide to Optional with Jackson](http://www.baeldung.com/jackson-optional)
|
||||
- [Map Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-map)
|
||||
- [Jackson Streaming API](http://www.baeldung.com/jackson-streaming-api)
|
||||
|
|
|
@ -154,11 +154,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
@ -49,11 +49,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
- [Introduction to Javaslang](http://www.baeldung.com/javaslang)
|
||||
- [Guide to Try in Javaslang](http://www.baeldung.com/javaslang-try)
|
||||
- [Guide to Pattern Matching in Javaslang](http://www.baeldung.com/javaslang-pattern-matching)
|
||||
- [Property Testing Example With Javaslang](http://www.baeldung.com/javaslang-property-testing)
|
||||
|
|
|
@ -49,6 +49,12 @@
|
|||
<artifactId>httpclient</artifactId>
|
||||
<version>${org.apache.httpcomponents.version}</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
|
|
@ -135,6 +135,9 @@
|
|||
</sources>
|
||||
<outputDirectory>${basedir}/src/main/java</outputDirectory>
|
||||
<clearOutputDir>false</clearOutputDir>
|
||||
<noGeneratedHeaderComments>true</noGeneratedHeaderComments>
|
||||
<extension>true</extension>
|
||||
<generateEpisode>false</generateEpisode>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
|
||||
package com.baeldung.jaxb.gen;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRegistry;
|
||||
|
||||
|
||||
/**
|
||||
* This object contains factory methods for each
|
||||
* Java content interface and Java element interface
|
||||
* generated in the com.baeldung.jaxb.gen package.
|
||||
* <p>An ObjectFactory allows you to programatically
|
||||
* construct new instances of the Java representation
|
||||
* for XML content. The Java representation of XML
|
||||
* content can consist of schema derived interfaces
|
||||
* and classes representing the binding of schema
|
||||
* type definitions, element declarations and model
|
||||
* groups. Factory methods for each of these are
|
||||
* provided in this class.
|
||||
*
|
||||
*/
|
||||
@XmlRegistry
|
||||
public class ObjectFactory {
|
||||
|
||||
|
||||
/**
|
||||
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.jaxb.gen
|
||||
*
|
||||
*/
|
||||
public ObjectFactory() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link UserRequest }
|
||||
*
|
||||
*/
|
||||
public UserRequest createUserRequest() {
|
||||
return new UserRequest();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an instance of {@link UserResponse }
|
||||
*
|
||||
*/
|
||||
public UserResponse createUserResponse() {
|
||||
return new UserResponse();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
|
||||
package com.baeldung.jaxb.gen;
|
||||
|
||||
import java.io.Serializable;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for UserRequest complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="UserRequest">
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/>
|
||||
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "UserRequest", propOrder = {
|
||||
"id",
|
||||
"name"
|
||||
})
|
||||
@XmlRootElement(name = "userRequest")
|
||||
public class UserRequest
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = -1L;
|
||||
protected int id;
|
||||
@XmlElement(required = true)
|
||||
protected String name;
|
||||
|
||||
/**
|
||||
* Gets the value of the id property.
|
||||
*
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the id property.
|
||||
*
|
||||
*/
|
||||
public void setId(int value) {
|
||||
this.id = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the name property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the name property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,149 @@
|
|||
|
||||
package com.baeldung.jaxb.gen;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Calendar;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlSchemaType;
|
||||
import javax.xml.bind.annotation.XmlType;
|
||||
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
|
||||
import org.w3._2001.xmlschema.Adapter1;
|
||||
|
||||
|
||||
/**
|
||||
* <p>Java class for UserResponse complex type.
|
||||
*
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="UserResponse">
|
||||
* <complexContent>
|
||||
* <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
|
||||
* <sequence>
|
||||
* <element name="id" type="{http://www.w3.org/2001/XMLSchema}int"/>
|
||||
* <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* <element name="gender" type="{http://www.w3.org/2001/XMLSchema}string"/>
|
||||
* <element name="created" type="{http://www.w3.org/2001/XMLSchema}dateTime"/>
|
||||
* </sequence>
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
* </pre>
|
||||
*
|
||||
*
|
||||
*/
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "UserResponse", propOrder = {
|
||||
"id",
|
||||
"name",
|
||||
"gender",
|
||||
"created"
|
||||
})
|
||||
@XmlRootElement(name = "userResponse")
|
||||
public class UserResponse
|
||||
implements Serializable
|
||||
{
|
||||
|
||||
private final static long serialVersionUID = -1L;
|
||||
protected int id;
|
||||
@XmlElement(required = true)
|
||||
protected String name;
|
||||
@XmlElement(required = true)
|
||||
protected String gender;
|
||||
@XmlElement(required = true, type = String.class)
|
||||
@XmlJavaTypeAdapter(Adapter1 .class)
|
||||
@XmlSchemaType(name = "dateTime")
|
||||
protected Calendar created;
|
||||
|
||||
/**
|
||||
* Gets the value of the id property.
|
||||
*
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the id property.
|
||||
*
|
||||
*/
|
||||
public void setId(int value) {
|
||||
this.id = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the name property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the name property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setName(String value) {
|
||||
this.name = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the gender property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getGender() {
|
||||
return gender;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the gender property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setGender(String value) {
|
||||
this.gender = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the created property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public Calendar getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the created property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setCreated(Calendar value) {
|
||||
this.created = value;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
@javax.xml.bind.annotation.XmlSchema(namespace = "http://www.baeldung.com/jaxb/gen", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
|
||||
package com.baeldung.jaxb.gen;
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
package org.w3._2001.xmlschema;
|
||||
|
||||
import java.util.Calendar;
|
||||
import javax.xml.bind.annotation.adapters.XmlAdapter;
|
||||
|
||||
public class Adapter1
|
||||
extends XmlAdapter<String, Calendar>
|
||||
{
|
||||
|
||||
|
||||
public Calendar unmarshal(String value) {
|
||||
return (javax.xml.bind.DatatypeConverter.parseDateTime(value));
|
||||
}
|
||||
|
||||
public String marshal(Calendar value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
return (javax.xml.bind.DatatypeConverter.printDateTime(value));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
### Relevant Articles:
|
||||
- [Scheduling in Java EE](http://www.baeldung.com/scheduling-in-java-enterprise-edition)
|
||||
- [JSON Processing in Java EE 7](http://www.baeldung.com/jee7-json)
|
||||
- [Converters, Listeners and Validators in Java EE 7](http://www.baeldung.com/java-ee7-converter-listener-validator)
|
||||
|
|
|
@ -1,3 +1,8 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Intro to JHipster](http://www.baeldung.com/jhipster)
|
||||
|
||||
|
||||
# baeldung
|
||||
This application was generated using JHipster 4.0.8, you can find documentation and help at [https://jhipster.github.io/documentation-archive/v4.0.8](https://jhipster.github.io/documentation-archive/v4.0.8).
|
||||
|
||||
|
|
11
jsf/pom.xml
11
jsf/pom.xml
|
@ -65,6 +65,12 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
|
@ -92,11 +98,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
|
|
|
@ -11,6 +11,12 @@
|
|||
<groupId>org.everit.json</groupId>
|
||||
<artifactId>org.everit.json.schema</artifactId>
|
||||
<version>${everit.json.schema.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant articles
|
||||
|
||||
- [A Guide to the Java Web Start](http://www.baeldung.com/java-web-start)
|
|
@ -1,3 +1,10 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Guide to Reactive Microservices Using Lagom Framework](http://www.baeldung.com/lagom-reactive-microservices)
|
||||
|
||||
|
||||
|
||||
|
||||
Steps to setup from scratch
|
||||
|
||||
1) Create sbt build file "build.sbt"
|
|
@ -7,6 +7,8 @@
|
|||
- [Introduction to Javassist](http://www.baeldung.com/javassist)
|
||||
- [Embedded Jetty Server in Java](http://www.baeldung.com/jetty-embedded)
|
||||
- [Introduction to Apache Flink with Java](http://www.baeldung.com/apache-flink)
|
||||
- [Introduction to JSONassert](http://www.baeldung.com/jsonassert)
|
||||
- [Intro to JaVer](http://www.baeldung.com/javers)
|
||||
|
||||
|
||||
The libraries module contains examples related to small libraries that are relatively easy to use and does not require any separate module of its own.
|
||||
|
|
|
@ -111,6 +111,12 @@
|
|||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
@ -130,7 +136,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
<version>${httpclient.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
@ -141,11 +147,23 @@
|
|||
<groupId>org.apache.flink</groupId>
|
||||
<artifactId>flink-core</artifactId>
|
||||
<version>${flink.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.flink</groupId>
|
||||
<artifactId>flink-java</artifactId>
|
||||
<version>${flink.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.flink</groupId>
|
||||
|
@ -153,6 +171,11 @@
|
|||
<version>${flink.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-math3</artifactId>
|
||||
<version>3.6.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.baeldung.commons.math;
|
||||
|
||||
import org.apache.commons.math3.fraction.Fraction;
|
||||
import org.apache.commons.math3.fraction.FractionFormat;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
|
@ -13,7 +13,7 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${springframework.version}</version>
|
||||
<version>${springframework.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-dbcp2</artifactId>
|
||||
<version>${commons-dbcp2.version}</version>
|
||||
<version>${commons-dbcp2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- This is used for testing only. -->
|
||||
|
|
|
@ -32,6 +32,12 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${springframework.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
*.class
|
||||
|
||||
.settings
|
||||
.project
|
||||
*.log
|
||||
|
||||
#folders#
|
||||
/target
|
||||
/src/main/webapp/WEB-INF/classes
|
||||
*/META-INF/*
|
||||
/testdb1
|
||||
|
||||
# Packaged files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
|
@ -3,7 +3,6 @@ package com.baeldung.mybatis.utils;
|
|||
import com.baeldung.mybatis.mapper.AddressMapper;
|
||||
import com.baeldung.mybatis.mapper.PersonMapper;
|
||||
import org.apache.ibatis.datasource.pooled.PooledDataSource;
|
||||
import org.apache.ibatis.io.Resources;
|
||||
import org.apache.ibatis.jdbc.SQL;
|
||||
import org.apache.ibatis.mapping.Environment;
|
||||
import org.apache.ibatis.session.Configuration;
|
||||
|
@ -12,8 +11,6 @@ import org.apache.ibatis.session.SqlSessionFactoryBuilder;
|
|||
import org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class MyBatisUtil {
|
||||
public static final String DRIVER = "org.apache.derby.jdbc.EmbeddedDriver";
|
||||
|
|
|
@ -1,145 +0,0 @@
|
|||
package com.baeldung.mybatis.mapper;
|
||||
|
||||
import com.baeldung.mybatis.model.Address;
|
||||
import com.baeldung.mybatis.model.Person;
|
||||
import com.baeldung.mybatis.utils.MyBatisUtil;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
public class PersonMapperTest {
|
||||
|
||||
SqlSession session;
|
||||
|
||||
@Before
|
||||
public void setup() throws SQLException {
|
||||
|
||||
session = MyBatisUtil.buildqlSessionFactory().openSession();
|
||||
createTables(session);
|
||||
|
||||
}
|
||||
|
||||
private void createTables(SqlSession session) throws SQLException {
|
||||
|
||||
String createPersonTable = "create table person (" + "personId integer not null generated always as"
|
||||
+ " identity (start with 1, increment by 1), " + "name varchar(30) not null, "
|
||||
+ "constraint primary_key_person primary key (personId))";
|
||||
|
||||
String createAddressTable = "create table address (" + "addressId integer not null generated always as"
|
||||
+ " identity (start with 1, increment by 1), " + "streetAddress varchar(300), personId integer, "
|
||||
+ "constraint primary_key_address primary key (addressId))";
|
||||
|
||||
String alterTable = "ALTER TABLE "
|
||||
+ " address ADD CONSTRAINT fk_person FOREIGN KEY (personId) REFERENCES person (personId)";
|
||||
|
||||
session.getConnection().createStatement().execute(createPersonTable);
|
||||
session.getConnection().createStatement().execute(createAddressTable);
|
||||
session.getConnection().createStatement().execute(alterTable);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPersonAdressSaved_ThenPersonAddressCanBeQueried() {
|
||||
Person person = new Person("Baljeet S");
|
||||
Address address = new Address("Pune");
|
||||
PersonMapper personMapper = session.getMapper(PersonMapper.class);
|
||||
Integer id = personMapper.save(person);
|
||||
address.setPersonId(id);
|
||||
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
|
||||
addressMapper.saveAddress(address);
|
||||
|
||||
Person returnedPerson = personMapper.getPersonById(id);
|
||||
assertEquals("Baljeet S", returnedPerson.getName());
|
||||
assertEquals("Pune", returnedPerson.getAddresses().get(0).getStreetAddress());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPersonSaved_ThenPersonCanBeQueried() {
|
||||
Person person = new Person("Baljeet S");
|
||||
Address address = new Address("Pune");
|
||||
PersonMapper personMapper = session.getMapper(PersonMapper.class);
|
||||
Integer id = personMapper.save(person);
|
||||
address.setPersonId(id);
|
||||
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
|
||||
addressMapper.saveAddress(address);
|
||||
|
||||
Person returnedPerson = personMapper.getPerson(id);
|
||||
assertEquals("Baljeet S", returnedPerson.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPersonUpdated_ThenPersonIsChanged() {
|
||||
Person person = new Person("Baljeet S");
|
||||
Address address = new Address("Pune");
|
||||
PersonMapper personMapper = session.getMapper(PersonMapper.class);
|
||||
Integer id = personMapper.save(person);
|
||||
address.setPersonId(id);
|
||||
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
|
||||
addressMapper.saveAddress(address);
|
||||
|
||||
personMapper.updatePerson(new Person(id, "Baljeet1"));
|
||||
Person returnedPerson = personMapper.getPerson(id);
|
||||
assertEquals("Baljeet1", returnedPerson.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPersoSaved_ThenMapIsReturned() {
|
||||
Person person = new Person("Baljeet S");
|
||||
Address address = new Address("Pune");
|
||||
PersonMapper personMapper = session.getMapper(PersonMapper.class);
|
||||
Integer id = personMapper.save(person);
|
||||
address.setPersonId(id);
|
||||
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
|
||||
addressMapper.saveAddress(address);
|
||||
|
||||
Map<Integer, Person> returnedPerson = personMapper.getAllPerson();
|
||||
assertEquals(1, returnedPerson.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPersonSearched_ThenResultIsReturned() {
|
||||
Person person = new Person("Baljeet S");
|
||||
Address address = new Address("Pune");
|
||||
PersonMapper personMapper = session.getMapper(PersonMapper.class);
|
||||
Integer id = personMapper.save(person);
|
||||
address.setPersonId(id);
|
||||
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
|
||||
addressMapper.saveAddress(address);
|
||||
|
||||
Person returnedPerson = personMapper.getPersonByName("Baljeet S");
|
||||
assertEquals("Baljeet S", returnedPerson.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddressSearched_ThenResultIsReturned() {
|
||||
Person person = new Person("Baljeet S");
|
||||
Address address = new Address("Pune");
|
||||
PersonMapper personMapper = session.getMapper(PersonMapper.class);
|
||||
Integer id = personMapper.save(person);
|
||||
address.setPersonId(id);
|
||||
AddressMapper addressMapper = session.getMapper(AddressMapper.class);
|
||||
Integer addressId = addressMapper.saveAddress(address);
|
||||
Address returnedAddress = addressMapper.getAddresses(addressId);
|
||||
|
||||
assertEquals("Pune", returnedAddress.getStreetAddress());
|
||||
}
|
||||
|
||||
@After
|
||||
public void cleanup() throws SQLException {
|
||||
session.getConnection().createStatement().execute("drop table address");
|
||||
session.getConnection().createStatement().execute("drop table person");
|
||||
|
||||
session.close();
|
||||
|
||||
}
|
||||
|
||||
}
|
12
pdf/pom.xml
12
pdf/pom.xml
|
@ -37,11 +37,23 @@
|
|||
<groupId>org.apache.pdfbox</groupId>
|
||||
<artifactId>pdfbox-tools</artifactId>
|
||||
<version>${pdfbox-tools.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sf.cssbox</groupId>
|
||||
<artifactId>pdf2dom</artifactId>
|
||||
<version>${pdf2dom.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.itextpdf</groupId>
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -226,7 +226,7 @@
|
|||
<version>1.6.0</version>
|
||||
<configuration>
|
||||
<executable>maven</executable>
|
||||
|
||||
<module>hibernate5</module>
|
||||
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
@ -253,4 +253,4 @@
|
|||
</extension>-->
|
||||
</extensions>
|
||||
</build>
|
||||
</project>
|
||||
</project>
|
|
@ -91,6 +91,12 @@
|
|||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<version>${spring.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Introduction to Ratpack](http://www.baeldung.com/ratpack)
|
||||
- [Ratpack Google Guice Integration](http://www.baeldung.com/ratpack-google-guice)
|
||||
|
|
|
@ -71,12 +71,6 @@
|
|||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>${commons-logging.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
|
@ -151,6 +145,12 @@
|
|||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -184,6 +184,12 @@
|
|||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>json-schema-core</artifactId>
|
||||
<version>${json-schema-core.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
@ -282,7 +288,6 @@
|
|||
|
||||
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<commons-logging.version>1.2</commons-logging.version>
|
||||
<commons-collections.version>3.2.2</commons-collections.version>
|
||||
|
||||
<httpcore.version>4.4.5</httpcore.version>
|
||||
|
|
|
@ -9,3 +9,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/)
|
||||
- [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock)
|
||||
- [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing)
|
||||
- [Testing a REST API with JBehave](http://www.baeldung.com/jbehave-rest-testing)
|
||||
|
|
|
@ -35,6 +35,12 @@
|
|||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${httpclient.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
|
@ -69,11 +75,6 @@
|
|||
<version>${org.slf4j.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
|
|
|
@ -6,3 +6,4 @@
|
|||
### Relevant Articles:
|
||||
- [A Guide to RESTEasy](http://www.baeldung.com/resteasy-tutorial)
|
||||
- [RESTEasy Client API](http://www.baeldung.com/resteasy-client-tutorial)
|
||||
- [CORS in JAX-RS](http://www.baeldung.com/cors-in-jax-rs)
|
||||
|
|
|
@ -67,6 +67,12 @@
|
|||
<groupId>org.jboss.resteasy</groupId>
|
||||
<artifactId>resteasy-servlet-initializer</artifactId>
|
||||
<version>${resteasy.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
|
|
@ -56,6 +56,12 @@
|
|||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>${selenium-java.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Full-text Search with Solr](http://www.baeldung.com/full-text-search-with-solr)
|
|
@ -20,11 +20,6 @@
|
|||
<artifactId>solr-solrj</artifactId>
|
||||
<version>6.4.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.16</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
|
|
@ -6,3 +6,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
### Relevant Articles
|
||||
|
||||
- [Concurrent Test Execution in Spring 5](http://www.baeldung.com/spring-5-concurrent-tests)
|
||||
- [Introduction to the Functional Web Framework in Spring 5](http://www.baeldung.com/spring-5-functional-web)
|
||||
|
|
|
@ -12,6 +12,12 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -20,3 +20,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
|
|||
- [A Guide to the Spring Task Scheduler](http://www.baeldung.com/spring-task-scheduler)
|
||||
- [Guide to Spring Retry](http://www.baeldung.com/spring-retry)
|
||||
- [Custom Scope in Spring](http://www.baeldung.com/spring-custom-scope)
|
||||
- [New in Guava 21 common.util.concurrent](http://www.baeldung.com/guava-21-util-concurrent)
|
||||
- [A CLI with Spring Shell](http://www.baeldung.com/spring-shell-cli)
|
||||
- [JasperReports with Spring](http://www.baeldung.com/spring-jasper)
|
||||
|
|
|
@ -25,6 +25,12 @@
|
|||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
|
@ -111,6 +117,12 @@
|
|||
<groupId>net.sf.jasperreports</groupId>
|
||||
<artifactId>jasperreports</artifactId>
|
||||
<version>${jasperreports.version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<groupId>commons-logging</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- logging -->
|
||||
|
@ -129,10 +141,6 @@
|
|||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
|
||||
|
|
|
@ -2,14 +2,16 @@ package org.baeldung.scopes;
|
|||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class ScopesController {
|
||||
public static final Logger LOG = Logger.getLogger(ScopesController.class);
|
||||
public static final Logger LOG = LoggerFactory.getLogger(ScopesController.class);
|
||||
|
||||
@Resource(name = "requestMessage")
|
||||
HelloMessageGenerator requestMessage;
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.baeldung.startup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -11,7 +13,7 @@ import javax.annotation.PostConstruct;
|
|||
@Scope(value = "prototype")
|
||||
public class AllStrategiesExampleBean implements InitializingBean {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(AllStrategiesExampleBean.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(AllStrategiesExampleBean.class);
|
||||
|
||||
public AllStrategiesExampleBean() {
|
||||
LOG.info("Constructor");
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
package org.baeldung.startup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.context.event.ContextRefreshedEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class EventListenerExampleBean {
|
||||
private static final Logger LOG = Logger.getLogger(EventListenerExampleBean.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EventListenerExampleBean.class);
|
||||
|
||||
public static int counter;
|
||||
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
package org.baeldung.startup;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Component
|
||||
@Scope(value = "prototype")
|
||||
public class InitMethodExampleBean {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(InitMethodExampleBean.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InitMethodExampleBean.class);
|
||||
|
||||
@Autowired
|
||||
private Environment environment;
|
||||
|
||||
public void init() {
|
||||
LOG.info(Arrays.asList(environment.getDefaultProfiles()));
|
||||
LOG.info("Env Default Profiles", Arrays.asList(environment.getDefaultProfiles()));
|
||||
}
|
||||
}
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue