Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
+14
View File
@@ -0,0 +1,14 @@
## Performance Tests
This module contains articles about performance testing.
### Relevant Articles:
- [Performance of Java Mapping Frameworks](https://www.baeldung.com/java-performance-mapping-frameworks)
### Running
To run the performance benchmarks:
1: `mvn clean install`
2: `java -jar target/benchmarks.jar`
+196
View File
@@ -0,0 +1,196 @@
<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</groupId>
<artifactId>performance-tests</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>performance-tests</name>
<parent>
<artifactId>parent-modules</artifactId>
<groupId>com.baeldung</groupId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>ma.glasnost.orika</groupId>
<artifactId>orika-core</artifactId>
<version>${orika.version}</version>
</dependency>
<dependency>
<groupId>net.sf.dozer</groupId>
<artifactId>dozer</artifactId>
<version>${dozer.version}</version>
</dependency>
<dependency>
<groupId>io.craftsman</groupId>
<artifactId>dozer-jdk8-support</artifactId>
<version>${dozer-jdk8-support.version}</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-jdk8</artifactId>
<version>${mapstruct-jdk8.version}</version>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mapstruct/mapstruct-processor -->
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.2.0.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.modelmapper</groupId>
<artifactId>modelmapper</artifactId>
<version>${modelmapper.version}</version>
</dependency>
<dependency>
<groupId>com.googlecode.jmapper-framework</groupId>
<artifactId>jmapper-core</artifactId>
<version>${jmapper.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>${jmh.version}</version>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>${jmh.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!--
JMH version to use with this project.
-->
<jmh.version>1.21</jmh.version>
<orika.version>1.5.2</orika.version>
<dozer.version>5.5.1</dozer.version>
<dozer-jdk8-support.version>1.0.2</dozer-jdk8-support.version>
<mapstruct-jdk8.version>1.2.0.Final</mapstruct-jdk8.version>
<modelmapper.version>1.1.0</modelmapper.version>
<jmapper.version>1.6.0.1</jmapper.version>
<java.version>1.8</java.version>
<mapstruct-processor.version>1.2.0.Final</mapstruct-processor.version>
<jmh-core.version>1.21</jmh-core.version>
<jmh-generator.version>1.21</jmh-generator.version>
<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
<!--
Java source/target to use for compilation.
-->
<javac.target>1.8</javac.target>
<!--
Name of the benchmark Uber-JAR to generate.
-->
<uberjar.name>benchmarks</uberjar.name>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerVersion>${javac.target}</compilerVersion>
<source>${javac.target}</source>
<target>${javac.target}</target>
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>${mapstruct-processor.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${uberjar.name}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
</transformer>
</transformers>
<filters>
<filter>
<!--
Shading signed JARs will fail without this.
http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.1</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
</plugin>
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
@@ -0,0 +1,11 @@
package com.baeldung.performancetests;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
public interface Converter {
Order convert(SourceOrder sourceOrder);
DestinationCode convert(SourceCode sourceCode);
}
@@ -0,0 +1,163 @@
package com.baeldung.performancetests.benchmark;
import com.baeldung.performancetests.dozer.DozerConverter;
import com.baeldung.performancetests.jmapper.JMapperConverter;
import com.baeldung.performancetests.mapstruct.MapStructConverter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.destination.Order;
import com.baeldung.performancetests.model.source.AccountStatus;
import com.baeldung.performancetests.model.source.Address;
import com.baeldung.performancetests.model.source.DeliveryData;
import com.baeldung.performancetests.model.source.Discount;
import com.baeldung.performancetests.model.source.OrderStatus;
import com.baeldung.performancetests.model.source.PaymentType;
import com.baeldung.performancetests.model.source.Product;
import com.baeldung.performancetests.model.source.RefundPolicy;
import com.baeldung.performancetests.model.source.Review;
import com.baeldung.performancetests.model.source.Shop;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.source.User;
import com.baeldung.performancetests.modelmapper.ModelMapperConverter;
import com.baeldung.performancetests.orika.OrikaConverter;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Group;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.runner.RunnerException;
import java.io.IOException;
import java.math.BigDecimal;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
@Fork(value = 1, warmups = 5)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
@BenchmarkMode(Mode.All)
@Measurement(iterations = 5)
@State(Scope.Group)
public class MappingFrameworksPerformance {
private SourceOrder sourceOrder = null;
private SourceCode sourceCode = null;
private static final OrikaConverter ORIKA_CONVERTER = new OrikaConverter();
private static final JMapperConverter JMAPPER_CONVERTER = new JMapperConverter();
private static final ModelMapperConverter MODEL_MAPPER_CONVERTER = new ModelMapperConverter();
private static final DozerConverter DOZER_CONVERTER = new DozerConverter();
@Setup
public void setUp() {
User user = new User("John", "John@doe.com", AccountStatus.ACTIVE);
RefundPolicy refundPolicy = new RefundPolicy(true, 30, Collections
.singletonList("Refundable only if not used!"));
Product product = new Product(BigDecimal.valueOf(10.99),
100,
"Sample Product",
"Sample Product to be sold",
true,
refundPolicy
);
Discount discount = new Discount(Instant.now().toString(), Instant.now().toString(), BigDecimal.valueOf(5.99));
Address deliveryAddress = new Address("Washington Street 5", "New York", "55045", "USA");
DeliveryData deliveryData = new DeliveryData(deliveryAddress, true, "", 10);
Address shopAddress = new Address("Roosvelt Street 9", "Boston", "55042", "USA");
User reviewingUser = new User("John", "Johhny@John.com", AccountStatus.ACTIVE);
User negativeReviewingUser = new User("Carl", "Carl@Coral.com", AccountStatus.ACTIVE);
Review review = new Review(5, 5, 5, reviewingUser, "The best shop I've ever bought things in");
Review negativeReview = new Review(1, 1, 1, negativeReviewingUser, "I will never buy anything again here!");
List<Review> reviewList = new ArrayList<>();
reviewList.add(review);
reviewList.add(negativeReview);
Shop shop = new Shop("Super Shop", shopAddress, "www.super-shop.com", reviewList);
sourceOrder = new SourceOrder(OrderStatus.CONFIRMED,
Instant.now().toString(),
Instant.MAX.toString(),
PaymentType.TRANSFER,
discount,
deliveryData,
user,
Collections.singletonList(product),
shop,
1
);
sourceCode = new SourceCode("This is source code!");
}
public static void main(String[] args) throws IOException, RunnerException {
org.openjdk.jmh.Main.main(args);
}
@Benchmark
@Group("realLifeTest")
public Order orikaMapperRealLifeBenchmark() {
return ORIKA_CONVERTER.convert(sourceOrder);
}
@Benchmark
@Group("realLifeTest")
public Order jmapperRealLifeBenchmark() {
return JMAPPER_CONVERTER.convert(sourceOrder);
}
@Benchmark
@Group("realLifeTest")
public Order modelMapperRealLifeBenchmark() {
return MODEL_MAPPER_CONVERTER.convert(sourceOrder);
}
@Benchmark
@Group("realLifeTest")
public Order dozerMapperRealLifeBenchmark() {
return DOZER_CONVERTER.convert(sourceOrder);
}
@Benchmark
@Group("realLifeTest")
public Order mapStructRealLifeMapperBenchmark() {
return MapStructConverter.MAPPER.convert(sourceOrder);
}
@Benchmark
@Group("simpleTest")
public DestinationCode orikaMapperSimpleBenchmark() {
return ORIKA_CONVERTER.convert(sourceCode);
}
@Benchmark
@Group("simpleTest")
public DestinationCode jmapperSimpleBenchmark() {
return JMAPPER_CONVERTER.convert(sourceCode);
}
@Benchmark
@Group("simpleTest")
public DestinationCode modelMapperBenchmark() {
return MODEL_MAPPER_CONVERTER.convert(sourceCode);
}
@Benchmark
@Group("simpleTest")
public DestinationCode dozerMapperSimpleBenchmark() {
return DOZER_CONVERTER.convert(sourceCode);
}
@Benchmark
@Group("simpleTest")
public DestinationCode mapStructMapperSimpleBenchmark() {
return MapStructConverter.MAPPER.convert(sourceCode);
}
}
@@ -0,0 +1,29 @@
package com.baeldung.performancetests.dozer;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;
public class DozerConverter implements Converter {
private final Mapper mapper;
public DozerConverter() {
DozerBeanMapper mapper = new DozerBeanMapper();
mapper.addMapping(DozerConverter.class.getResourceAsStream("/dozer-mapping.xml"));
this.mapper = mapper;
}
@Override
public Order convert(SourceOrder sourceOrder) {
return mapper.map(sourceOrder,Order.class);
}
@Override
public DestinationCode convert(SourceCode sourceCode) {
return mapper.map(sourceCode, DestinationCode.class);
}
}
@@ -0,0 +1,30 @@
package com.baeldung.performancetests.jmapper;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import com.googlecode.jmapper.JMapper;
import com.googlecode.jmapper.api.JMapperAPI;
public class JMapperConverter implements Converter {
JMapper realLifeMapper;
JMapper simpleMapper;
public JMapperConverter() {
JMapperAPI api = new JMapperAPI().add(JMapperAPI.mappedClass(Order.class));
realLifeMapper = new JMapper(Order.class, SourceOrder.class, api);
JMapperAPI simpleApi = new JMapperAPI().add(JMapperAPI.mappedClass(DestinationCode.class));
simpleMapper = new JMapper(DestinationCode.class, SourceCode.class, simpleApi);
}
@Override
public Order convert(SourceOrder sourceOrder) {
return (Order) realLifeMapper.getDestination(sourceOrder);
}
@Override
public DestinationCode convert(SourceCode sourceCode) {
return (DestinationCode) simpleMapper.getDestination(sourceCode);
}
}
@@ -0,0 +1,22 @@
package com.baeldung.performancetests.mapstruct;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;
@Mapper
public interface MapStructConverter extends Converter {
MapStructConverter MAPPER = Mappers.getMapper(MapStructConverter.class);
@Mapping(source = "status", target = "orderStatus")
@Override
Order convert(SourceOrder sourceOrder);
@Override
DestinationCode convert(SourceCode sourceCode);
}
@@ -0,0 +1,5 @@
package com.baeldung.performancetests.model.destination;
public enum AccountStatus {
ACTIVE, NOT_ACTIVE, BANNED
}
@@ -0,0 +1,83 @@
package com.baeldung.performancetests.model.destination;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.util.Objects;
@JGlobalMap
public class Address {
private String street;
private String city;
private String postalCode;
public Address() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if(o.getClass() == com.baeldung.performancetests.model.source.Address.class) {
com.baeldung.performancetests.model.source.Address address =
(com.baeldung.performancetests.model.source.Address) o;
return Objects.equals(street, address.getStreet()) &&
Objects.equals(city, address.getCity()) &&
Objects.equals(postalCode, address.getPostalCode()) &&
Objects.equals(country, address.getCountry());
}
if(o.getClass() != getClass()) return false;
Address address = (Address) o;
return Objects.equals(street, address.street) &&
Objects.equals(city, address.city) &&
Objects.equals(postalCode, address.postalCode) &&
Objects.equals(country, address.country);
}
@Override
public int hashCode() {
return Objects.hash(street, city, postalCode, country);
}
private String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Address(String street, String city, String postalCode, String country) {
this.street = street;
this.city = city;
this.postalCode = postalCode;
this.country = country;
}
}
@@ -0,0 +1,83 @@
package com.baeldung.performancetests.model.destination;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapAccessor;
import java.util.Objects;
@JGlobalMap
public class DeliveryData {
private Address deliveryAddress;
@JMapAccessor(get = "isPrePaid", set = "setPrePaid")
private boolean isPrePaid;
private String trackingCode;
private int expectedDeliveryTimeInDays;
public DeliveryData() {
}
public Address getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(Address deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public boolean isPrePaid() {
return isPrePaid;
}
public void setPrePaid(boolean prePaid) {
isPrePaid = prePaid;
}
public String getTrackingCode() {
return trackingCode;
}
public void setTrackingCode(String trackingCode) {
this.trackingCode = trackingCode;
}
public int getExpectedDeliveryTimeInDays() {
return expectedDeliveryTimeInDays;
}
public void setExpectedDeliveryTimeInDays(int expectedDeliveryTimeInDays) {
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
public DeliveryData(Address deliveryAddress, boolean isPrePaid, String trackingCode, int expectedDeliveryTimeInDays) {
this.deliveryAddress = deliveryAddress;
this.isPrePaid = isPrePaid;
this.trackingCode = trackingCode;
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if(o.getClass() == com.baeldung.performancetests.model.source.DeliveryData.class) {
com.baeldung.performancetests.model.source.DeliveryData deliveryData =
(com.baeldung.performancetests.model.source.DeliveryData) o;
return isPrePaid == deliveryData.isPrePaid() &&
expectedDeliveryTimeInDays == deliveryData.getExpectedDeliveryTimeInDays() &&
Objects.equals(deliveryAddress, deliveryData.getDeliveryAddress()) &&
Objects.equals(trackingCode, deliveryData.getTrackingCode());
}
if (o.getClass() != getClass()) return false;
DeliveryData that = (DeliveryData) o;
return isPrePaid == that.isPrePaid &&
expectedDeliveryTimeInDays == that.expectedDeliveryTimeInDays &&
Objects.equals(deliveryAddress, that.deliveryAddress) &&
Objects.equals(trackingCode, that.trackingCode);
}
@Override
public int hashCode() {
return Objects.hash(deliveryAddress, isPrePaid, trackingCode, expectedDeliveryTimeInDays);
}
}
@@ -0,0 +1,23 @@
package com.baeldung.performancetests.model.destination;
import com.googlecode.jmapper.annotations.JMap;
public class DestinationCode {
@JMap
String code;
public DestinationCode(String code) {
this.code = code;
}
public DestinationCode() {
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}
@@ -0,0 +1,70 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.math.BigDecimal;
@JGlobalMap
public class Discount {
private String startTime;
private String endTime;
private BigDecimal discountPrice;
public Discount() {
}
public String getStartTime() {
return startTime;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.Discount.class) {
com.baeldung.performancetests.model.source.Discount discount =
(com.baeldung.performancetests.model.source.Discount) o;
return Objects.equal(startTime, discount.getStartTime()) &&
Objects.equal(endTime, discount.getEndTime()) &&
Objects.equal(discountPrice, discount.getDiscountPrice());
}
if(o.getClass() != getClass()) return false;
Discount discount = (Discount) o;
return Objects.equal(startTime, discount.startTime) &&
Objects.equal(endTime, discount.endTime) &&
Objects.equal(discountPrice, discount.discountPrice);
}
@Override
public int hashCode() {
return Objects.hashCode(startTime, endTime, discountPrice);
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public BigDecimal getDiscountPrice() {
return discountPrice;
}
public void setDiscountPrice(BigDecimal discountPrice) {
this.discountPrice = discountPrice;
}
public Discount(String startTime, String endTime, BigDecimal discountPrice) {
this.startTime = startTime;
this.endTime = endTime;
this.discountPrice = discountPrice;
}
}
@@ -0,0 +1,210 @@
package com.baeldung.performancetests.model.destination;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JMap;
import com.googlecode.jmapper.annotations.JMapConversion;
import java.util.List;
public class Order {
@JMap
private User orderingUser;
@JMap
private List<Product> orderedProducts;
@JMap("status")
private OrderStatus orderStatus;
@JMap
private String orderDate;
@JMap
private String orderFinishDate;
@JMap
private PaymentType paymentType;
@JMap
private Discount discount;
@JMap
private int orderId;
@JMap
private DeliveryData deliveryData;
@JMap
private Shop offeringShop;
public Order() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == SourceOrder.class) {
SourceOrder order =
(SourceOrder) o;
return Objects.equal(orderingUser, order.getOrderingUser()) &&
Objects.equal(orderedProducts, order.getOrderedProducts()) &&
orderStatus.ordinal() == order.getStatus().ordinal() &&
Objects.equal(orderDate, order.getOrderDate()) &&
Objects.equal(orderFinishDate, order.getOrderFinishDate()) &&
paymentType.ordinal() == order.getPaymentType().ordinal() &&
Objects.equal(discount, order.getDiscount()) &&
Objects.equal(deliveryData, order.getDeliveryData());
}
if (o.getClass() != getClass()) return false;
Order order = (Order) o;
return Objects.equal(orderingUser, order.orderingUser) &&
Objects.equal(orderedProducts, order.orderedProducts) &&
orderStatus == order.orderStatus &&
Objects.equal(orderDate, order.orderDate) &&
Objects.equal(orderFinishDate, order.orderFinishDate) &&
paymentType == order.paymentType &&
Objects.equal(discount, order.discount) &&
Objects.equal(deliveryData, order.deliveryData);
}
@Override
public int hashCode() {
return Objects.hashCode(orderingUser, orderedProducts, orderStatus, orderDate, orderFinishDate, paymentType, discount, deliveryData);
}
public User getOrderingUser() {
return orderingUser;
}
public void setOrderingUser(User orderingUser) {
this.orderingUser = orderingUser;
}
public List<Product> getOrderedProducts() {
return orderedProducts;
}
public void setOrderedProducts(List<Product> orderedProducts) {
this.orderedProducts = orderedProducts;
}
public OrderStatus getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(OrderStatus status) {
this.orderStatus = status;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public String getOrderFinishDate() {
return orderFinishDate;
}
public void setOrderFinishDate(String orderFinishDate) {
this.orderFinishDate = orderFinishDate;
}
public PaymentType getPaymentType() {
return paymentType;
}
public void setPaymentType(PaymentType paymentType) {
this.paymentType = paymentType;
}
public Discount getDiscount() {
return discount;
}
public void setDiscount(Discount discount) {
this.discount = discount;
}
public DeliveryData getDeliveryData() {
return deliveryData;
}
public void setDeliveryData(DeliveryData deliveryData) {
this.deliveryData = deliveryData;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public Order(User orderingUser, List<Product> orderedProducts, OrderStatus orderStatus, String orderDate, String orderFinishDate, PaymentType paymentType, Discount discount, int orderId, DeliveryData deliveryData, Shop offeringShop) {
this.orderingUser = orderingUser;
this.orderedProducts = orderedProducts;
this.orderStatus = orderStatus;
this.orderDate = orderDate;
this.orderFinishDate = orderFinishDate;
this.paymentType = paymentType;
this.discount = discount;
this.orderId = orderId;
this.deliveryData = deliveryData;
this.offeringShop = offeringShop;
}
public Shop getOfferingShop() {
return offeringShop;
}
public void setOfferingShop(Shop offeringShop) {
this.offeringShop = offeringShop;
}
@JMapConversion(from = "status", to = "orderStatus")
public OrderStatus conversion(com.baeldung.performancetests.model.source.OrderStatus status) {
OrderStatus orderStatus = null;
switch(status) {
case CREATED:
orderStatus = OrderStatus.CREATED;
break;
case FINISHED:
orderStatus = OrderStatus.FINISHED;
break;
case CONFIRMED:
orderStatus = OrderStatus.CONFIRMED;
break;
case COLLECTING:
orderStatus = OrderStatus.COLLECTING;
break;
case IN_TRANSPORT:
orderStatus = OrderStatus.IN_TRANSPORT;
break;
}
return orderStatus;
}
@JMapConversion(from = "paymentType", to = "paymentType")
public PaymentType conversion(com.baeldung.performancetests.model.source.PaymentType type) {
PaymentType paymentType = null;
switch(type) {
case CARD:
paymentType = PaymentType.CARD;
break;
case CASH:
paymentType = PaymentType.CASH;
break;
case TRANSFER:
paymentType = PaymentType.TRANSFER;
break;
}
return paymentType;
}
}
@@ -0,0 +1,5 @@
package com.baeldung.performancetests.model.destination;
public enum OrderStatus {
CREATED, CONFIRMED, COLLECTING, IN_TRANSPORT, FINISHED
}
@@ -0,0 +1,5 @@
package com.baeldung.performancetests.model.destination;
public enum PaymentType {
CASH, CARD, TRANSFER
}
@@ -0,0 +1,107 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.math.BigDecimal;
@JGlobalMap
public class Product {
private BigDecimal price;
private int quantity;
public Product() {
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public RefundPolicy getRefundPolicy() {
return refundPolicy;
}
public void setRefundPolicy(RefundPolicy refundPolicy) {
this.refundPolicy = refundPolicy;
}
private String name;
public Product(BigDecimal price, int quantity, String name, String description, boolean available, RefundPolicy refundPolicy) {
this.price = price;
this.quantity = quantity;
this.name = name;
this.description = description;
this.available = available;
this.refundPolicy = refundPolicy;
}
String description;
boolean available;
private RefundPolicy refundPolicy;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.Product.class) {
com.baeldung.performancetests.model.source.Product product =
(com.baeldung.performancetests.model.source.Product) o;
return quantity == product.getQuantity() &&
available == product.isAvailable() &&
Objects.equal(price, product.getPrice()) &&
Objects.equal(name, product.getName()) &&
Objects.equal(description, product.getDescription()) &&
Objects.equal(refundPolicy, product.getRefundPolicy());
}
if(o.getClass() != getClass()) return false;
Product product = (Product) o;
return quantity == product.quantity &&
available == product.available &&
Objects.equal(price, product.price) &&
Objects.equal(name, product.name) &&
Objects.equal(description, product.description) &&
Objects.equal(refundPolicy, product.refundPolicy);
}
@Override
public int hashCode() {
return Objects.hashCode(price, quantity, name, description, available, refundPolicy);
}
}
@@ -0,0 +1,72 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapAccessor;
import java.util.List;
@JGlobalMap
public class RefundPolicy {
@JMapAccessor(get = "isRefundable", set = "setRefundable")
private boolean isRefundable;
private int refundTimeInDays;
public RefundPolicy() {
}
public boolean isRefundable() {
return isRefundable;
}
public void setRefundable(boolean refundable) {
isRefundable = refundable;
}
public int getRefundTimeInDays() {
return refundTimeInDays;
}
public void setRefundTimeInDays(int refundTimeInDays) {
this.refundTimeInDays = refundTimeInDays;
}
public List<String> getNotes() {
return notes;
}
public void setNotes(List<String> notes) {
this.notes = notes;
}
public RefundPolicy(boolean isRefundable, int refundTimeInDays, List<String> notes) {
this.isRefundable = isRefundable;
this.refundTimeInDays = refundTimeInDays;
this.notes = notes;
}
private List<String> notes;
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.RefundPolicy.class) {
com.baeldung.performancetests.model.source.RefundPolicy that = (com.baeldung.performancetests.model.source.RefundPolicy) o;
return isRefundable == that.isRefundable() &&
refundTimeInDays == that.getRefundTimeInDays() &&
Objects.equal(notes, that.getNotes());
}
if (o.getClass() != getClass()) return false;
RefundPolicy that = (RefundPolicy) o;
return isRefundable == that.isRefundable &&
refundTimeInDays == that.refundTimeInDays &&
Objects.equal(notes, that.notes);
}
@Override
public int hashCode() {
return Objects.hashCode(isRefundable, refundTimeInDays, notes);
}
}
@@ -0,0 +1,67 @@
package com.baeldung.performancetests.model.destination;
import com.baeldung.performancetests.model.source.User;
import com.googlecode.jmapper.annotations.JGlobalMap;
@JGlobalMap
public class Review {
int shippingGrade;
int pricingGrade;
int serviceGrade;
User reviewingUser;
String note;
public int getShippingGrade() {
return shippingGrade;
}
public void setShippingGrade(int shippingGrade) {
this.shippingGrade = shippingGrade;
}
public int getPricingGrade() {
return pricingGrade;
}
public void setPricingGrade(int pricingGrade) {
this.pricingGrade = pricingGrade;
}
public int getServiceGrade() {
return serviceGrade;
}
public void setServiceGrade(int serviceGrade) {
this.serviceGrade = serviceGrade;
}
public User getReviewingUser() {
return reviewingUser;
}
public void setReviewingUser(User reviewingUser) {
this.reviewingUser = reviewingUser;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Review() {
}
public Review(int shippingGrade, int pricingGrade, int serviceGrade, User reviewingUser, String note) {
this.shippingGrade = shippingGrade;
this.pricingGrade = pricingGrade;
this.serviceGrade = serviceGrade;
this.reviewingUser = reviewingUser;
this.note = note;
}
}
@@ -0,0 +1,57 @@
package com.baeldung.performancetests.model.destination;
import com.baeldung.performancetests.model.source.Address;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.util.List;
@JGlobalMap
public class Shop {
private String shopName;
private Address shopAddres;
private String shopUrl;
private List<Review> reviews;
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public Address getShopAddres() {
return shopAddres;
}
public void setShopAddres(Address shopAddres) {
this.shopAddres = shopAddres;
}
public String getShopUrl() {
return shopUrl;
}
public void setShopUrl(String shopUrl) {
this.shopUrl = shopUrl;
}
public Shop() {
}
public List<Review> getReviews() {
return reviews;
}
public void setReviews(List<Review> reviews) {
this.reviews = reviews;
}
public Shop(String shopName, Address shopAddres, String shopUrl, List<Review> reviews) {
this.shopName = shopName;
this.shopAddres = shopAddres;
this.shopUrl = shopUrl;
this.reviews = reviews;
}
}
@@ -0,0 +1,87 @@
package com.baeldung.performancetests.model.destination;
import com.google.common.base.Objects;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapConversion;
@JGlobalMap
public class User {
private String username;
private String email;
private AccountStatus userAccountStatus;
public User(String username, String email, AccountStatus userAccountStatus) {
this.username = username;
this.email = email;
this.userAccountStatus = userAccountStatus;
}
public User() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public AccountStatus getUserAccountStatus() {
return userAccountStatus;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null) return false;
if (o.getClass() == com.baeldung.performancetests.model.source.User.class) {
com.baeldung.performancetests.model.source.User user =
(com.baeldung.performancetests.model.source.User) o;
return Objects.equal(username, user.getUsername()) &&
Objects.equal(email, user.getEmail()) &&
userAccountStatus.ordinal() == user.getUserAccountStatus().ordinal();
}
if (o.getClass() != getClass()) return false;
User user = (User) o;
return Objects.equal(username, user.username) &&
Objects.equal(email, user.email) &&
userAccountStatus == user.userAccountStatus;
}
@Override
public int hashCode() {
return Objects.hashCode(username, email, userAccountStatus);
}
public void setUserAccountStatus(AccountStatus userAccountStatus) {
this.userAccountStatus = userAccountStatus;
}
@JMapConversion(from = "userAccountStatus", to = "userAccountStatus")
public AccountStatus conversion(com.baeldung.performancetests.model.source.AccountStatus status) {
AccountStatus accountStatus = null;
switch(status) {
case ACTIVE:
accountStatus = AccountStatus.ACTIVE;
break;
case NOT_ACTIVE:
accountStatus = AccountStatus.NOT_ACTIVE;
break;
case BANNED:
accountStatus = AccountStatus.BANNED;
break;
}
return accountStatus;
}
}
@@ -0,0 +1,7 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public enum AccountStatus {
ACTIVE, NOT_ACTIVE, BANNED
}
@@ -0,0 +1,54 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public class Address {
private String street;
private String city;
private String postalCode;
public Address() {
}
private String country;
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPostalCode() {
return postalCode;
}
public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public Address(String street, String city, String postalCode, String country) {
this.street = street;
this.city = city;
this.postalCode = postalCode;
this.country = country;
}
}
@@ -0,0 +1,54 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapAccessor;
public class DeliveryData {
private Address deliveryAddress;
@JMapAccessor(get = "isPrePaid", set = "setPrePaid")
private boolean isPrePaid;
private String trackingCode;
private int expectedDeliveryTimeInDays;
public DeliveryData() {
}
public Address getDeliveryAddress() {
return deliveryAddress;
}
public void setDeliveryAddress(Address deliveryAddress) {
this.deliveryAddress = deliveryAddress;
}
public boolean isPrePaid() {
return isPrePaid;
}
public void setPrePaid(boolean prePaid) {
isPrePaid = prePaid;
}
public String getTrackingCode() {
return trackingCode;
}
public void setTrackingCode(String trackingCode) {
this.trackingCode = trackingCode;
}
public int getExpectedDeliveryTimeInDays() {
return expectedDeliveryTimeInDays;
}
public void setExpectedDeliveryTimeInDays(int expectedDeliveryTimeInDays) {
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
public DeliveryData(Address deliveryAddress, boolean isPrePaid, String trackingCode, int expectedDeliveryTimeInDays) {
this.deliveryAddress = deliveryAddress;
this.isPrePaid = isPrePaid;
this.trackingCode = trackingCode;
this.expectedDeliveryTimeInDays = expectedDeliveryTimeInDays;
}
}
@@ -0,0 +1,44 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.math.BigDecimal;
public class Discount {
private String startTime;
private String endTime;
private BigDecimal discountPrice;
public Discount() {
}
public String getStartTime() {
return startTime;
}
public void setStartTime(String startTime) {
this.startTime = startTime;
}
public String getEndTime() {
return endTime;
}
public void setEndTime(String endTime) {
this.endTime = endTime;
}
public BigDecimal getDiscountPrice() {
return discountPrice;
}
public void setDiscountPrice(BigDecimal discountPrice) {
this.discountPrice = discountPrice;
}
public Discount(String startTime, String endTime, BigDecimal discountPrice) {
this.startTime = startTime;
this.endTime = endTime;
this.discountPrice = discountPrice;
}
}
@@ -0,0 +1,7 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public enum OrderStatus {
CREATED, CONFIRMED, COLLECTING, IN_TRANSPORT, FINISHED
}
@@ -0,0 +1,7 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public enum PaymentType {
CASH, CARD, TRANSFER
}
@@ -0,0 +1,76 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
import java.math.BigDecimal;
public class Product {
private BigDecimal price;
private int quantity;
public Product() {
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isAvailable() {
return available;
}
public void setAvailable(boolean available) {
this.available = available;
}
public RefundPolicy getRefundPolicy() {
return refundPolicy;
}
public void setRefundPolicy(RefundPolicy refundPolicy) {
this.refundPolicy = refundPolicy;
}
private String name;
public Product(BigDecimal price, int quantity, String name, String description, boolean available, RefundPolicy refundPolicy) {
this.price = price;
this.quantity = quantity;
this.name = name;
this.description = description;
this.available = available;
this.refundPolicy = refundPolicy;
}
String description;
boolean available;
private RefundPolicy refundPolicy;
}
@@ -0,0 +1,48 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
import com.googlecode.jmapper.annotations.JMapAccessor;
import java.util.List;
public class RefundPolicy {
@JMapAccessor(get = "isRefundable", set = "setRefundable")
private boolean isRefundable;
private int refundTimeInDays;
public RefundPolicy() {
}
public boolean isRefundable() {
return isRefundable;
}
public void setRefundable(boolean refundable) {
isRefundable = refundable;
}
public int getRefundTimeInDays() {
return refundTimeInDays;
}
public void setRefundTimeInDays(int refundTimeInDays) {
this.refundTimeInDays = refundTimeInDays;
}
public List<String> getNotes() {
return notes;
}
public void setNotes(List<String> notes) {
this.notes = notes;
}
public RefundPolicy(boolean isRefundable, int refundTimeInDays, List<String> notes) {
this.isRefundable = isRefundable;
this.refundTimeInDays = refundTimeInDays;
this.notes = notes;
}
private List<String> notes;
}
@@ -0,0 +1,63 @@
package com.baeldung.performancetests.model.source;
public class Review {
int shippingGrade;
int pricingGrade;
int serviceGrade;
User reviewingUser;
String note;
public int getShippingGrade() {
return shippingGrade;
}
public void setShippingGrade(int shippingGrade) {
this.shippingGrade = shippingGrade;
}
public int getPricingGrade() {
return pricingGrade;
}
public void setPricingGrade(int pricingGrade) {
this.pricingGrade = pricingGrade;
}
public int getServiceGrade() {
return serviceGrade;
}
public void setServiceGrade(int serviceGrade) {
this.serviceGrade = serviceGrade;
}
public User getReviewingUser() {
return reviewingUser;
}
public void setReviewingUser(User reviewingUser) {
this.reviewingUser = reviewingUser;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public Review() {
}
public Review(int shippingGrade, int pricingGrade, int serviceGrade, User reviewingUser, String note) {
this.shippingGrade = shippingGrade;
this.pricingGrade = pricingGrade;
this.serviceGrade = serviceGrade;
this.reviewingUser = reviewingUser;
this.note = note;
}
}
@@ -0,0 +1,55 @@
package com.baeldung.performancetests.model.source;
import java.util.List;
public class Shop {
private String shopName;
private Address shopAddres;
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public Address getShopAddres() {
return shopAddres;
}
public void setShopAddres(Address shopAddres) {
this.shopAddres = shopAddres;
}
public Shop() {
}
public String getShopUrl() {
return shopUrl;
}
public void setShopUrl(String shopUrl) {
this.shopUrl = shopUrl;
}
public List<Review> getReviews() {
return reviews;
}
public void setReviews(List<Review> reviews) {
this.reviews = reviews;
}
public Shop(String shopName, Address shopAddres, String shopUrl, List<Review> reviews) {
this.shopName = shopName;
this.shopAddres = shopAddres;
this.shopUrl = shopUrl;
this.reviews = reviews;
}
private String shopUrl;
private List<Review> reviews;
}
@@ -0,0 +1,22 @@
package com.baeldung.performancetests.model.source;
public class SourceCode {
String code;
public SourceCode() {
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public SourceCode(String code) {
this.code = code;
}
}
@@ -0,0 +1,118 @@
package com.baeldung.performancetests.model.source;
import java.util.List;
public class SourceOrder {
private String orderFinishDate;
private PaymentType paymentType;
private Discount discount;
private DeliveryData deliveryData;
private User orderingUser;
private List<Product> orderedProducts;
private Shop offeringShop;
private int orderId;
private OrderStatus status;
private String orderDate;
public SourceOrder() {
}
public User getOrderingUser() {
return orderingUser;
}
public void setOrderingUser(User orderingUser) {
this.orderingUser = orderingUser;
}
public List<Product> getOrderedProducts() {
return orderedProducts;
}
public void setOrderedProducts(List<Product> orderedProducts) {
this.orderedProducts = orderedProducts;
}
public OrderStatus getStatus() {
return status;
}
public void setStatus(OrderStatus status) {
this.status = status;
}
public String getOrderDate() {
return orderDate;
}
public void setOrderDate(String orderDate) {
this.orderDate = orderDate;
}
public String getOrderFinishDate() {
return orderFinishDate;
}
public void setOrderFinishDate(String orderFinishDate) {
this.orderFinishDate = orderFinishDate;
}
public PaymentType getPaymentType() {
return paymentType;
}
public void setPaymentType(PaymentType paymentType) {
this.paymentType = paymentType;
}
public Discount getDiscount() {
return discount;
}
public void setDiscount(Discount discount) {
this.discount = discount;
}
public DeliveryData getDeliveryData() {
return deliveryData;
}
public void setDeliveryData(DeliveryData deliveryData) {
this.deliveryData = deliveryData;
}
public Shop getOfferingShop() {
return offeringShop;
}
public void setOfferingShop(Shop offeringShop) {
this.offeringShop = offeringShop;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public SourceOrder(OrderStatus status, String orderDate, String orderFinishDate, PaymentType paymentType, Discount discount, DeliveryData deliveryData, User orderingUser, List<Product> orderedProducts, Shop offeringShop, int orderId) {
this.status = status;
this.orderDate = orderDate;
this.orderFinishDate = orderFinishDate;
this.paymentType = paymentType;
this.discount = discount;
this.deliveryData = deliveryData;
this.orderingUser = orderingUser;
this.orderedProducts = orderedProducts;
this.offeringShop = offeringShop;
this.orderId = orderId;
}
}
@@ -0,0 +1,42 @@
package com.baeldung.performancetests.model.source;
import com.googlecode.jmapper.annotations.JGlobalMap;
public class User {
private String username;
private String email;
private AccountStatus userAccountStatus;
public User(String username, String email, AccountStatus userAccountStatus) {
this.username = username;
this.email = email;
this.userAccountStatus = userAccountStatus;
}
public User() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public AccountStatus getUserAccountStatus() {
return userAccountStatus;
}
public void setUserAccountStatus(AccountStatus userAccountStatus) {
this.userAccountStatus = userAccountStatus;
}
}
@@ -0,0 +1,26 @@
package com.baeldung.performancetests.modelmapper;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import org.modelmapper.ModelMapper;
public class ModelMapperConverter implements Converter {
private ModelMapper modelMapper;
public ModelMapperConverter() {
modelMapper = new ModelMapper();
}
@Override
public Order convert(SourceOrder sourceOrder) {
return modelMapper.map(sourceOrder, Order.class);
}
@Override
public DestinationCode convert(SourceCode sourceCode) {
return modelMapper.map(sourceCode, DestinationCode.class);
}
}
@@ -0,0 +1,31 @@
package com.baeldung.performancetests.orika;
import com.baeldung.performancetests.Converter;
import com.baeldung.performancetests.model.destination.DestinationCode;
import com.baeldung.performancetests.model.source.SourceCode;
import com.baeldung.performancetests.model.source.SourceOrder;
import com.baeldung.performancetests.model.destination.Order;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.impl.DefaultMapperFactory;
public class OrikaConverter implements Converter{
private MapperFacade mapperFacade;
public OrikaConverter() {
MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
mapperFactory.classMap(Order.class, SourceOrder.class).field("orderStatus", "status").byDefault().register();
mapperFacade = mapperFactory.getMapperFacade();
}
@Override
public Order convert(SourceOrder sourceOrder) {
return mapperFacade.map(sourceOrder, Order.class);
}
@Override
public DestinationCode convert(SourceCode sourceCode) {
return mapperFacade.map(sourceCode, DestinationCode.class);
}
}
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<configuration>
<stop-on-errors>true</stop-on-errors>
<date-format>MM/dd/yyyy HH:mm</date-format>
<wildcard>true</wildcard>
</configuration>
<mapping>
<class-a>com.baeldung.performancetests.model.source.SourceOrder</class-a>
<class-b>com.baeldung.performancetests.model.destination.Order</class-b>
<field>
<a>status</a>
<b>orderStatus</b>
</field>
</mapping>
<mapping>
<class-a>com.baeldung.performancetests.model.source.SourceCode</class-a>
<class-b>com.baeldung.performancetests.model.destination.DestinationCode</class-b>
</mapping>
</mappings>
@@ -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>
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<mappings xmlns="http://dozer.sourceforge.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://dozer.sourceforge.net
http://dozer.sourceforge.net/schema/beanmapping.xsd">
<configuration>
<stop-on-errors>true</stop-on-errors>
<date-format>MM/dd/yyyy HH:mm</date-format>
<wildcard>true</wildcard>
</configuration>
<mapping>
<class-a>com.baeldung.performancetests.model.source.SourceOrder</class-a>
<class-b>com.baeldung.performancetests.model.destination.Order</class-b>
<field>
<a>status</a>
<b>orderStatus</b>
</field>
</mapping>
</mappings>