Skip to content

Commit

Permalink
Merge pull request #84 from zero88/feature/remove-lombok-in-jpa-ext
Browse files Browse the repository at this point in the history
Remove lombok in jpa-ext
  • Loading branch information
zero88 authored Mar 24, 2022
2 parents 611f5eb + bb46a95 commit 4cf64c8
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 36 deletions.
4 changes: 0 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,11 @@ subprojects {

dependencies {
compileOnly(UtilLibs.jetbrainsAnnotations)
compileOnly(UtilLibs.lombok)
annotationProcessor(UtilLibs.lombok)

testImplementation(TestLibs.junit5Api)
testImplementation(TestLibs.junit5Engine)
testImplementation(TestLibs.junit5Vintage)
testCompileOnly(UtilLibs.jetbrainsAnnotations)
testCompileOnly(UtilLibs.lombok)
testAnnotationProcessor(UtilLibs.lombok)
}

oss {
Expand Down
5 changes: 5 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ dependencies {
compileOnly(VertxLibs.codegen)
annotationProcessor(VertxLibs.codegen)

compileOnly(UtilLibs.lombok)
annotationProcessor(UtilLibs.lombok)

testImplementation(VertxLibs.sqlClient)
testCompileOnly(UtilLibs.lombok)
testAnnotationProcessor(UtilLibs.lombok)

testFixturesApi(project(":spi"))
testFixturesApi(LogLibs.logback)
Expand Down
3 changes: 3 additions & 0 deletions integtest/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,7 @@ dependencies {
testImplementation(VertxLibs.rx2)

testImplementation(LogLibs.logback)

testCompileOnly(UtilLibs.lombok)
testAnnotationProcessor(UtilLibs.lombok)
}
10 changes: 4 additions & 6 deletions jpa-ext/src/main/java/io/zero88/jpa/Direction.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
import java.util.Optional;
import java.util.stream.Stream;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
* Represents for {@code Sort Direction}.
*
* @since 1.0.0
*/
@Getter
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
public enum Direction implements Serializable {
/**
* {@code ASC} direction.
Expand All @@ -28,6 +22,8 @@ public enum Direction implements Serializable {

private final char symbol;

Direction(char symbol) {this.symbol = symbol;}

/**
* Parse direction.
*
Expand Down Expand Up @@ -57,4 +53,6 @@ public boolean isASC() {
public boolean isDESC() {
return DESC == this;
}

public char getSymbol() {return this.symbol;}
}
64 changes: 44 additions & 20 deletions jpa-ext/src/main/java/io/zero88/jpa/Order.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Map.Entry;
import java.util.Optional;

import org.jetbrains.annotations.NotNull;

import io.zero88.jpa.Order.OrderSerializer;

import com.fasterxml.jackson.annotation.JsonCreator;
Expand All @@ -15,40 +17,30 @@
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

/**
* Represents for Order.
*
* @since 1.0.0
*/
@Getter
@Accessors(fluent = true)
@ToString
@EqualsAndHashCode
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
@JsonSerialize(using = OrderSerializer.class)
public final class Order implements Serializable {

@NonNull
private final String property;
@NonNull
private final Direction direction;

private Order(@NotNull String property, @NotNull Direction direction) {
this.property = property;
this.direction = direction;
}

/**
* By asc order.
*
* @param property the property
* @return the order
* @since 1.0.0
*/
public static Order byASC(@NonNull String property) {
public static Order byASC(@NotNull String property) {
return by(property, Direction.ASC);
}

Expand All @@ -59,7 +51,7 @@ public static Order byASC(@NonNull String property) {
* @return the order
* @since 1.0.0
*/
public static Order byDESC(@NonNull String property) {
public static Order byDESC(@NotNull String property) {
return by(property, Direction.DESC);
}

Expand All @@ -71,7 +63,7 @@ public static Order byDESC(@NonNull String property) {
* @return the order
* @since 1.0.0
*/
public static Order by(@NonNull String property, Direction direction) {
public static Order by(@NotNull String property, Direction direction) {
return new Order(property, Optional.ofNullable(direction).orElse(Direction.ASC));
}

Expand All @@ -83,20 +75,52 @@ public static Order by(@NonNull String property, Direction direction) {
* @return the order
* @since 1.0.0
*/
public static Order by(@NonNull @JsonProperty("property") String property,
public static Order by(@NotNull @JsonProperty("property") String property,
@JsonProperty("direction") String direction) {
return by(property, Direction.parse(direction));
}

@JsonCreator
private static Order by(@NonNull Map<String, String> properties) {
private static Order by(@NotNull Map<String, String> properties) {
final Entry<String, String> val = properties.entrySet()
.stream()
.findFirst()
.orElseThrow(() -> new RuntimeException("Empty value"));
return by(val.getKey(), Direction.parse(val.getValue()));
}

public @NotNull String property() {return this.property;}

public @NotNull Direction direction() {return this.direction;}

public String toString() {
return this.direction.getSymbol() + this.property;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

Order order = (Order) o;

if (!property.equals(order.property)) {
return false;
}
return direction == order.direction;
}

@Override
public int hashCode() {
int result = property.hashCode();
result = 31 * result + direction.hashCode();
return result;
}

public static class OrderSerializer extends JsonSerializer<Order> {

@Override
Expand Down
4 changes: 2 additions & 2 deletions jpa-ext/src/main/java/io/zero88/jpa/Sortable.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.Serializable;
import java.util.Collection;

import lombok.NonNull;
import org.jetbrains.annotations.NotNull;

/**
* Sort option for queries.
Expand All @@ -18,7 +18,7 @@ public interface Sortable extends Serializable {
* @return the order collection
* @since 1.0.0
*/
@NonNull Collection<Order> orders();
@NotNull Collection<Order> orders();

/**
* Get order.
Expand Down
4 changes: 2 additions & 2 deletions jpa-ext/src/test/java/io/zero88/jpa/OrderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void test_serialize_and_deserialize_ASC_order() throws IOException {
Assertions.assertTrue(order.direction().isASC());
Assertions.assertFalse(order.direction().isDESC());
Assertions.assertEquals("xyz", order.property());
Assertions.assertEquals("Order(property=xyz, direction=ASC)", order.toString());
Assertions.assertEquals("+xyz", order.toString());

Assertions.assertEquals(orderJson, objectMapper.writeValueAsString(order));
Assertions.assertEquals(Order.by("xyz", ""), order);
Expand All @@ -41,7 +41,7 @@ public void test_serialize_and_deserialize_DESC_order() throws IOException {
Assertions.assertFalse(order.direction().isASC());
Assertions.assertTrue(order.direction().isDESC());
Assertions.assertEquals("abc", order.property());
Assertions.assertEquals("Order(property=abc, direction=DESC)", order.toString());
Assertions.assertEquals("-abc", order.toString());

Assertions.assertEquals(orderJson, objectMapper.writeValueAsString(order));
Assertions.assertEquals(Order.byDESC("abc"), order);
Expand Down
2 changes: 0 additions & 2 deletions rsql/core/src/main/java/io/zero88/rsql/QueryContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import org.jetbrains.annotations.NotNull;

import lombok.NonNull;

/**
* Represents for context when executing query in runtime
*
Expand Down
5 changes: 5 additions & 0 deletions spi/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ dependencies {
compileOnly(DatabaseLibs.hsqldb)
compileOnly(DatabaseLibs.sqlite)

compileOnly(UtilLibs.lombok)
annotationProcessor(UtilLibs.lombok)

testImplementation(testFixtures(project(":jooqx-core")))
testImplementation(VertxLibs.jdbc)
testImplementation(VertxLibs.pgsql)
testImplementation(VertxLibs.mysql)
testImplementation(VertxLibs.mssql)
testImplementation(VertxLibs.db2)

testCompileOnly(UtilLibs.lombok)
testAnnotationProcessor(UtilLibs.lombok)
}

0 comments on commit 4cf64c8

Please sign in to comment.