Skip to content

Commit

Permalink
Merge pull request #3 from marcopotok/release/2.0.0-alpha
Browse files Browse the repository at this point in the history
Release/2.0.0 alpha
  • Loading branch information
marcopotok authored Sep 3, 2022
2 parents d048fc8 + 8263071 commit a588578
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 127 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JPA Predicate Builder

A lightweight layer on top of Javax Persistence for easy query construction in Java.
A lightweight layer on top of JPA for easy query construction in Java.

# Project Description

Expand All @@ -15,9 +15,17 @@ Key features:
- remove duplicated joins
- easy fetch of related entities (prefetching)

## Versions and compatibility

The JPA APIs were originally exposed under the package `javax.persistence` replaced in 2019 by the Jakarta's package `jakarta.persistence`. The Predicate Builder supports both versions of JPA APIs with the following versions:
- **1.x.x**: Javax Persistence
- **2.x.x**: Jakarta Persistence



# How to install

To install it is enough to add the dependency to your pom file.
Just add the dependency to your pom file.

# How to use

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.marcopotok</groupId>
<artifactId>jpa-predicate-builder</artifactId>
<version>1.0.0-alpha-1</version>
<version>2.0.0-alpha</version>
<packaging>jar</packaging>

<name>io.github.marcopotok:jpa-predicate-builder</name>
Expand All @@ -24,9 +24,9 @@
</licenses>
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/marcopotok/jpb/Clause.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.marcopotok.jpb;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;

@FunctionalInterface
public interface Clause {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/marcopotok/jpb/ClauseComposition.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.io.Serializable;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Predicate;

class ClauseComposition {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Fetch;
import javax.persistence.criteria.FetchParent;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Root;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Fetch;
import jakarta.persistence.criteria.FetchParent;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.Root;

class DefaultPrefetchEngine implements PrefetchEngine {
private static final Pattern NESTED_ATTRIBUTES_MATCHER = Pattern.compile("^\\[(.*)]$");
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/github/marcopotok/jpb/Operator.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.marcopotok.jpb;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Predicate;

@FunctionalInterface
interface Operator<U> {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/marcopotok/jpb/PathProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import java.util.function.Function;

import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;

@FunctionalInterface
public interface PathProvider {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/io/github/marcopotok/jpb/PredicateBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Subquery;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.From;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Subquery;

public class PredicateBuilder<T> {

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/marcopotok/jpb/PredicateContext.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.marcopotok.jpb;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;

@FunctionalInterface
interface PredicateContext<T> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/marcopotok/jpb/PrefetchEngine.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.github.marcopotok.jpb;

import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Root;

public interface PrefetchEngine {
/**
Expand Down
93 changes: 74 additions & 19 deletions src/test/java/io/github/marcopotok/jpb/FakeCriteriaBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
import java.util.Map;
import java.util.Set;

import javax.persistence.Tuple;
import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaDelete;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.CriteriaUpdate;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.MapJoin;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.SetJoin;
import javax.persistence.criteria.Subquery;
import jakarta.persistence.Tuple;
import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.CompoundSelection;
import jakarta.persistence.criteria.CriteriaBuilder;
import jakarta.persistence.criteria.CriteriaDelete;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.CriteriaUpdate;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.ParameterExpression;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;
import jakarta.persistence.criteria.SetJoin;
import jakarta.persistence.criteria.Subquery;

class FakeCriteriaBuilder implements CriteriaBuilder {

Expand Down Expand Up @@ -333,6 +333,11 @@ public Predicate le(Expression<? extends Number> x, Number y) {
return null;
}

@Override
public Expression<Integer> sign(Expression<? extends Number> x) {
return null;
}

@Override
public <N extends Number> Expression<N> neg(Expression<N> x) {
return null;
Expand All @@ -343,6 +348,16 @@ public <N extends Number> Expression<N> abs(Expression<N> x) {
return null;
}

@Override
public <N extends Number> Expression<N> ceiling(Expression<N> x) {
return null;
}

@Override
public <N extends Number> Expression<N> floor(Expression<N> x) {
return null;
}

@Override
public <N extends Number> Expression<N> sum(Expression<? extends N> x, Expression<? extends N> y) {
return null;
Expand Down Expand Up @@ -423,6 +438,31 @@ public Expression<Double> sqrt(Expression<? extends Number> x) {
return null;
}

@Override
public Expression<Double> exp(Expression<? extends Number> x) {
return null;
}

@Override
public Expression<Double> ln(Expression<? extends Number> x) {
return null;
}

@Override
public Expression<Double> power(Expression<? extends Number> x, Expression<? extends Number> y) {
return null;
}

@Override
public Expression<Double> power(Expression<? extends Number> x, Number y) {
return null;
}

@Override
public <T extends Number> Expression<T> round(Expression<T> x, Integer n) {
return null;
}

@Override
public Expression<Long> toLong(Expression<? extends Number> number) {
return null;
Expand Down Expand Up @@ -693,6 +733,21 @@ public Expression<Time> currentTime() {
return null;
}

@Override
public Expression<LocalDate> localDate() {
return null;
}

@Override
public Expression<LocalDateTime> localDateTime() {
return null;
}

@Override
public Expression<LocalTime> localTime() {
return null;
}

@Override
public <T> In<T> in(Expression<? extends T> expression) {
return null;
Expand Down
32 changes: 16 additions & 16 deletions src/test/java/io/github/marcopotok/jpb/FakeCriteriaQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.criteria.AbstractQuery;
import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.CommonAbstractCriteria;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.MapJoin;
import javax.persistence.criteria.Order;
import javax.persistence.criteria.ParameterExpression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.SetJoin;
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.EntityType;
import jakarta.persistence.criteria.AbstractQuery;
import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.CommonAbstractCriteria;
import jakarta.persistence.criteria.CriteriaQuery;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Order;
import jakarta.persistence.criteria.ParameterExpression;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Root;
import jakarta.persistence.criteria.Selection;
import jakarta.persistence.criteria.SetJoin;
import jakarta.persistence.criteria.Subquery;
import jakarta.persistence.metamodel.EntityType;

class FakeCriteriaQuery implements CriteriaQuery<Object> {

Expand Down
12 changes: 6 additions & 6 deletions src/test/java/io/github/marcopotok/jpb/FakeFetch.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import java.util.Set;
import java.util.stream.Collectors;

import javax.persistence.criteria.Fetch;
import javax.persistence.criteria.FetchParent;
import javax.persistence.criteria.JoinType;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.SingularAttribute;
import jakarta.persistence.criteria.Fetch;
import jakarta.persistence.criteria.FetchParent;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.metamodel.Attribute;
import jakarta.persistence.metamodel.PluralAttribute;
import jakarta.persistence.metamodel.SingularAttribute;

final class FakeFetch<X, Y> implements Fetch<X, Y> {

Expand Down
40 changes: 20 additions & 20 deletions src/test/java/io/github/marcopotok/jpb/FakeJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
import java.util.Map;
import java.util.Set;

import javax.persistence.criteria.CollectionJoin;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Fetch;
import javax.persistence.criteria.From;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.ListJoin;
import javax.persistence.criteria.MapJoin;
import javax.persistence.criteria.Path;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Selection;
import javax.persistence.criteria.SetJoin;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.Bindable;
import javax.persistence.metamodel.CollectionAttribute;
import javax.persistence.metamodel.ListAttribute;
import javax.persistence.metamodel.MapAttribute;
import javax.persistence.metamodel.PluralAttribute;
import javax.persistence.metamodel.SetAttribute;
import javax.persistence.metamodel.SingularAttribute;
import jakarta.persistence.criteria.CollectionJoin;
import jakarta.persistence.criteria.Expression;
import jakarta.persistence.criteria.Fetch;
import jakarta.persistence.criteria.From;
import jakarta.persistence.criteria.Join;
import jakarta.persistence.criteria.JoinType;
import jakarta.persistence.criteria.ListJoin;
import jakarta.persistence.criteria.MapJoin;
import jakarta.persistence.criteria.Path;
import jakarta.persistence.criteria.Predicate;
import jakarta.persistence.criteria.Selection;
import jakarta.persistence.criteria.SetJoin;
import jakarta.persistence.metamodel.Attribute;
import jakarta.persistence.metamodel.Bindable;
import jakarta.persistence.metamodel.CollectionAttribute;
import jakarta.persistence.metamodel.ListAttribute;
import jakarta.persistence.metamodel.MapAttribute;
import jakarta.persistence.metamodel.PluralAttribute;
import jakarta.persistence.metamodel.SetAttribute;
import jakarta.persistence.metamodel.SingularAttribute;

class FakeJoin<X, Y> implements Join<X, Y> {

Expand Down
Loading

0 comments on commit a588578

Please sign in to comment.