diff --git a/.github/badges/jacoco.svg b/.github/badges/jacoco.svg
index 4f41679..a90f0b0 100644
--- a/.github/badges/jacoco.svg
+++ b/.github/badges/jacoco.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/.github/workflows/ci-pipeline.yml b/.github/workflows/ci-pipeline.yml
index a32349a..323bae4 100644
--- a/.github/workflows/ci-pipeline.yml
+++ b/.github/workflows/ci-pipeline.yml
@@ -8,11 +8,10 @@ on:
jobs:
build:
-
runs-on: ubuntu-latest
-
steps:
- uses: actions/checkout@v2
+
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
@@ -48,3 +47,20 @@ jobs:
- name: Build Java Example Project with Maven
working-directory: ./examples/java-maven-h2
run: mvn -B package --file pom.xml
+
+ buildJava17:
+ runs-on: ubuntu-latest
+
+ steps:
+ - uses: actions/checkout@v2
+
+ - name: Set up JDK 17
+ uses: actions/setup-java@v3
+ with:
+ java-version: '17'
+ distribution: 'temurin'
+ cache: 'gradle'
+
+ - name: Build Java Example Spring Reactive
+ working-directory: ./examples/java-gradle-reactive
+ run: ./gradlew build
diff --git a/README.md b/README.md
index 86d6628..9ed0e48 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# Spring Jpa Magic Filter
[![CI Pipeline](https://github.com/verissimor/jpa-magic-filter/actions/workflows/ci-pipeline.yml/badge.svg)](https://github.com/verissimor/jpa-magic-filter/actions/workflows/ci-pipeline.yml)
-[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.verissimor.lib/jpa-magic-filter/badge.svg)](https://search.maven.org/artifact/io.github.verissimor.lib/jpa-magic-filter/0.0.10/jar)
+[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.verissimor.lib/jpa-magic-filter/badge.svg)](https://search.maven.org/artifact/io.github.verissimor.lib/jpa-magic-filter)
[![Coverage](.github/badges/jacoco.svg)](jacoco.svg)
[![License](https://img.shields.io/github/license/verissimor/jpa-magic-filter)](https://github.com/verissimor/jpa-magic-filter/blob/master/LICENSE)
@@ -53,14 +53,14 @@ MAVEN
io.github.verissimor.lib
jpa-magic-filter
- 0.0.10
+ 1.0.1
```
GRADLE
```kotlin
-implementation 'io.github.verissimor.lib:jpa-magic-filter:0.0.10'
+implementation 'io.github.verissimor.lib:jpa-magic-filter:1.0.1'
```
Enable it on your application:
diff --git a/build.gradle.kts b/build.gradle.kts
index 1dc2724..8114f98 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -19,7 +19,7 @@ plugins {
}
group = "io.github.verissimor.lib"
-version = System.getenv("RELEASE_VERSION") ?: "1.0.0-SNAPSHOT"
+version = System.getenv("RELEASE_VERSION") ?: "1.0.1-SNAPSHOT"
java {
sourceCompatibility = JavaVersion.VERSION_1_8
diff --git a/examples/java-gradle-reactive/.gitignore b/examples/java-gradle-reactive/.gitignore
new file mode 100644
index 0000000..c2065bc
--- /dev/null
+++ b/examples/java-gradle-reactive/.gitignore
@@ -0,0 +1,37 @@
+HELP.md
+.gradle
+build/
+!gradle/wrapper/gradle-wrapper.jar
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### STS ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+bin/
+!**/src/main/**/bin/
+!**/src/test/**/bin/
+
+### IntelliJ IDEA ###
+.idea
+*.iws
+*.iml
+*.ipr
+out/
+!**/src/main/**/out/
+!**/src/test/**/out/
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+
+### VS Code ###
+.vscode/
diff --git a/examples/java-gradle-reactive/build.gradle b/examples/java-gradle-reactive/build.gradle
new file mode 100644
index 0000000..316f840
--- /dev/null
+++ b/examples/java-gradle-reactive/build.gradle
@@ -0,0 +1,31 @@
+plugins {
+ id 'org.springframework.boot' version '2.7.3'
+ id 'io.spring.dependency-management' version '1.0.13.RELEASE'
+ id 'java'
+}
+
+group = 'io.github.verissimor.examples.reactive'
+version = '0.0.1-SNAPSHOT'
+sourceCompatibility = '17'
+
+repositories {
+ mavenCentral()
+ mavenLocal()
+}
+
+dependencies {
+ implementation 'io.github.verissimor.lib:jpa-magic-filter:1.0.0'
+
+ implementation 'org.springframework.boot:spring-boot-starter-data-r2dbc'
+ implementation 'org.springframework.boot:spring-boot-starter-webflux'
+ compileOnly 'org.projectlombok:lombok'
+ runtimeOnly 'com.h2database:h2'
+ runtimeOnly 'io.r2dbc:r2dbc-h2'
+ annotationProcessor 'org.projectlombok:lombok'
+ testImplementation 'org.springframework.boot:spring-boot-starter-test'
+ implementation 'io.projectreactor:reactor-test'
+}
+
+tasks.named('test') {
+ useJUnitPlatform()
+}
diff --git a/examples/java-gradle-reactive/gradle/wrapper/gradle-wrapper.jar b/examples/java-gradle-reactive/gradle/wrapper/gradle-wrapper.jar
new file mode 100644
index 0000000..249e583
Binary files /dev/null and b/examples/java-gradle-reactive/gradle/wrapper/gradle-wrapper.jar differ
diff --git a/examples/java-gradle-reactive/gradle/wrapper/gradle-wrapper.properties b/examples/java-gradle-reactive/gradle/wrapper/gradle-wrapper.properties
new file mode 100644
index 0000000..8049c68
--- /dev/null
+++ b/examples/java-gradle-reactive/gradle/wrapper/gradle-wrapper.properties
@@ -0,0 +1,5 @@
+distributionBase=GRADLE_USER_HOME
+distributionPath=wrapper/dists
+distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
+zipStoreBase=GRADLE_USER_HOME
+zipStorePath=wrapper/dists
diff --git a/examples/java-gradle-reactive/gradlew b/examples/java-gradle-reactive/gradlew
new file mode 100755
index 0000000..a69d9cb
--- /dev/null
+++ b/examples/java-gradle-reactive/gradlew
@@ -0,0 +1,240 @@
+#!/bin/sh
+
+#
+# Copyright © 2015-2021 the original authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# https://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+##############################################################################
+#
+# Gradle start up script for POSIX generated by Gradle.
+#
+# Important for running:
+#
+# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
+# noncompliant, but you have some other compliant shell such as ksh or
+# bash, then to run this script, type that shell name before the whole
+# command line, like:
+#
+# ksh Gradle
+#
+# Busybox and similar reduced shells will NOT work, because this script
+# requires all of these POSIX shell features:
+# * functions;
+# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
+# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
+# * compound commands having a testable exit status, especially «case»;
+# * various built-in commands including «command», «set», and «ulimit».
+#
+# Important for patching:
+#
+# (2) This script targets any POSIX shell, so it avoids extensions provided
+# by Bash, Ksh, etc; in particular arrays are avoided.
+#
+# The "traditional" practice of packing multiple parameters into a
+# space-separated string is a well documented source of bugs and security
+# problems, so this is (mostly) avoided, by progressively accumulating
+# options in "$@", and eventually passing that to Java.
+#
+# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
+# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
+# see the in-line comments for details.
+#
+# There are tweaks for specific operating systems such as AIX, CygWin,
+# Darwin, MinGW, and NonStop.
+#
+# (3) This script is generated from the Groovy template
+# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
+# within the Gradle project.
+#
+# You can find Gradle at https://github.com/gradle/gradle/.
+#
+##############################################################################
+
+# Attempt to set APP_HOME
+
+# Resolve links: $0 may be a link
+app_path=$0
+
+# Need this for daisy-chained symlinks.
+while
+ APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
+ [ -h "$app_path" ]
+do
+ ls=$( ls -ld "$app_path" )
+ link=${ls#*' -> '}
+ case $link in #(
+ /*) app_path=$link ;; #(
+ *) app_path=$APP_HOME$link ;;
+ esac
+done
+
+APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
+
+APP_NAME="Gradle"
+APP_BASE_NAME=${0##*/}
+
+# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
+
+# Use the maximum available, or set MAX_FD != -1 to use that value.
+MAX_FD=maximum
+
+warn () {
+ echo "$*"
+} >&2
+
+die () {
+ echo
+ echo "$*"
+ echo
+ exit 1
+} >&2
+
+# OS specific support (must be 'true' or 'false').
+cygwin=false
+msys=false
+darwin=false
+nonstop=false
+case "$( uname )" in #(
+ CYGWIN* ) cygwin=true ;; #(
+ Darwin* ) darwin=true ;; #(
+ MSYS* | MINGW* ) msys=true ;; #(
+ NONSTOP* ) nonstop=true ;;
+esac
+
+CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
+
+
+# Determine the Java command to use to start the JVM.
+if [ -n "$JAVA_HOME" ] ; then
+ if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
+ # IBM's JDK on AIX uses strange locations for the executables
+ JAVACMD=$JAVA_HOME/jre/sh/java
+ else
+ JAVACMD=$JAVA_HOME/bin/java
+ fi
+ if [ ! -x "$JAVACMD" ] ; then
+ die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+ fi
+else
+ JAVACMD=java
+ which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+
+Please set the JAVA_HOME variable in your environment to match the
+location of your Java installation."
+fi
+
+# Increase the maximum file descriptors if we can.
+if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
+ case $MAX_FD in #(
+ max*)
+ MAX_FD=$( ulimit -H -n ) ||
+ warn "Could not query maximum file descriptor limit"
+ esac
+ case $MAX_FD in #(
+ '' | soft) :;; #(
+ *)
+ ulimit -n "$MAX_FD" ||
+ warn "Could not set maximum file descriptor limit to $MAX_FD"
+ esac
+fi
+
+# Collect all arguments for the java command, stacking in reverse order:
+# * args from the command line
+# * the main class name
+# * -classpath
+# * -D...appname settings
+# * --module-path (only if needed)
+# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
+
+# For Cygwin or MSYS, switch paths to Windows format before running java
+if "$cygwin" || "$msys" ; then
+ APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
+ CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
+
+ JAVACMD=$( cygpath --unix "$JAVACMD" )
+
+ # Now convert the arguments - kludge to limit ourselves to /bin/sh
+ for arg do
+ if
+ case $arg in #(
+ -*) false ;; # don't mess with options #(
+ /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
+ [ -e "$t" ] ;; #(
+ *) false ;;
+ esac
+ then
+ arg=$( cygpath --path --ignore --mixed "$arg" )
+ fi
+ # Roll the args list around exactly as many times as the number of
+ # args, so each arg winds up back in the position where it started, but
+ # possibly modified.
+ #
+ # NB: a `for` loop captures its iteration list before it begins, so
+ # changing the positional parameters here affects neither the number of
+ # iterations, nor the values presented in `arg`.
+ shift # remove old arg
+ set -- "$@" "$arg" # push replacement arg
+ done
+fi
+
+# Collect all arguments for the java command;
+# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
+# shell script including quotes and variable substitutions, so put them in
+# double quotes to make sure that they get re-expanded; and
+# * put everything else in single quotes, so that it's not re-expanded.
+
+set -- \
+ "-Dorg.gradle.appname=$APP_BASE_NAME" \
+ -classpath "$CLASSPATH" \
+ org.gradle.wrapper.GradleWrapperMain \
+ "$@"
+
+# Stop when "xargs" is not available.
+if ! command -v xargs >/dev/null 2>&1
+then
+ die "xargs is not available"
+fi
+
+# Use "xargs" to parse quoted args.
+#
+# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
+#
+# In Bash we could simply go:
+#
+# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
+# set -- "${ARGS[@]}" "$@"
+#
+# but POSIX shell has neither arrays nor command substitution, so instead we
+# post-process each arg (as a line of input to sed) to backslash-escape any
+# character that might be a shell metacharacter, then use eval to reverse
+# that process (while maintaining the separation between arguments), and wrap
+# the whole thing up as a single "set" statement.
+#
+# This will of course break if any of these variables contains a newline or
+# an unmatched quote.
+#
+
+eval "set -- $(
+ printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
+ xargs -n1 |
+ sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
+ tr '\n' ' '
+ )" '"$@"'
+
+exec "$JAVACMD" "$@"
diff --git a/examples/java-gradle-reactive/gradlew.bat b/examples/java-gradle-reactive/gradlew.bat
new file mode 100644
index 0000000..f127cfd
--- /dev/null
+++ b/examples/java-gradle-reactive/gradlew.bat
@@ -0,0 +1,91 @@
+@rem
+@rem Copyright 2015 the original author or authors.
+@rem
+@rem Licensed under the Apache License, Version 2.0 (the "License");
+@rem you may not use this file except in compliance with the License.
+@rem You may obtain a copy of the License at
+@rem
+@rem https://www.apache.org/licenses/LICENSE-2.0
+@rem
+@rem Unless required by applicable law or agreed to in writing, software
+@rem distributed under the License is distributed on an "AS IS" BASIS,
+@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@rem See the License for the specific language governing permissions and
+@rem limitations under the License.
+@rem
+
+@if "%DEBUG%"=="" @echo off
+@rem ##########################################################################
+@rem
+@rem Gradle startup script for Windows
+@rem
+@rem ##########################################################################
+
+@rem Set local scope for the variables with windows NT shell
+if "%OS%"=="Windows_NT" setlocal
+
+set DIRNAME=%~dp0
+if "%DIRNAME%"=="" set DIRNAME=.
+set APP_BASE_NAME=%~n0
+set APP_HOME=%DIRNAME%
+
+@rem Resolve any "." and ".." in APP_HOME to make it shorter.
+for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
+
+@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
+set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
+
+@rem Find java.exe
+if defined JAVA_HOME goto findJavaFromJavaHome
+
+set JAVA_EXE=java.exe
+%JAVA_EXE% -version >NUL 2>&1
+if %ERRORLEVEL% equ 0 goto execute
+
+echo.
+echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:findJavaFromJavaHome
+set JAVA_HOME=%JAVA_HOME:"=%
+set JAVA_EXE=%JAVA_HOME%/bin/java.exe
+
+if exist "%JAVA_EXE%" goto execute
+
+echo.
+echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
+echo.
+echo Please set the JAVA_HOME variable in your environment to match the
+echo location of your Java installation.
+
+goto fail
+
+:execute
+@rem Setup the command line
+
+set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
+
+
+@rem Execute Gradle
+"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
+
+:end
+@rem End local scope for the variables with windows NT shell
+if %ERRORLEVEL% equ 0 goto mainEnd
+
+:fail
+rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
+rem the _cmd.exe /c_ return code!
+set EXIT_CODE=%ERRORLEVEL%
+if %EXIT_CODE% equ 0 set EXIT_CODE=1
+if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
+exit /b %EXIT_CODE%
+
+:mainEnd
+if "%OS%"=="Windows_NT" endlocal
+
+:omega
diff --git a/examples/java-gradle-reactive/settings.gradle b/examples/java-gradle-reactive/settings.gradle
new file mode 100644
index 0000000..6be6a5e
--- /dev/null
+++ b/examples/java-gradle-reactive/settings.gradle
@@ -0,0 +1 @@
+rootProject.name = 'java-gradle-reactive'
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/JavaGradleReactiveApplication.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/JavaGradleReactiveApplication.java
new file mode 100644
index 0000000..5ed8e4c
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/JavaGradleReactiveApplication.java
@@ -0,0 +1,116 @@
+package io.github.verissimor.examples.reactive.javagradlereactive;
+
+import io.github.verissimor.lib.r2dbcmagicfilter.EnableR2dbcMagicFilter;
+import io.r2dbc.spi.ConnectionFactory;
+import lombok.AllArgsConstructor;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.data.domain.Example;
+import org.springframework.data.domain.ExampleMatcher;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
+import org.springframework.data.relational.core.query.Query;
+import org.springframework.stereotype.Component;
+import org.springframework.stereotype.Service;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+import reactor.test.StepVerifier;
+
+import static org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers.endsWith;
+import static org.springframework.data.domain.ExampleMatcher.matching;
+import static org.springframework.data.relational.core.query.Criteria.where;
+
+@EnableR2dbcMagicFilter
+@SpringBootApplication
+public class JavaGradleReactiveApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(JavaGradleReactiveApplication.class, args);
+ }
+
+}
+//
+//@Component
+//@AllArgsConstructor
+//class Run implements ApplicationRunner {
+//
+// private final ConnectionFactory connectionFactory;
+//
+// @Override
+// public void run(ApplicationArguments args) throws Exception {
+//
+// R2dbcEntityTemplate template = new R2dbcEntityTemplate(connectionFactory);
+//
+// template.getDatabaseClient().sql("CREATE TABLE person" +
+// "(id serial primary key," +
+// "name VARCHAR(255)," +
+// "age INT)")
+// .fetch()
+// .rowsUpdated()
+// .as(StepVerifier::create)
+// .expectNextCount(1)
+// .verifyComplete();
+//
+// template.insert(Person.class)
+// .using(new Person(null, "Joe", 34))
+// .as(StepVerifier::create)
+// .expectNextCount(1)
+// .verifyComplete();
+//
+// template.select(Person.class)
+// .first()
+// .doOnNext(it -> System.out.println(it))
+// .as(StepVerifier::create)
+// .expectNextCount(1)
+// .verifyComplete();
+//
+// var p2 = template
+// .selectOne(Query.query(where("name").is("Joe")), Person.class)
+// .map((it) -> {
+// return it;
+// })
+// .block();
+//
+// System.out.println(p2);
+// }
+//}
+//
+//
+//@Service
+//@AllArgsConstructor
+//class Run2 implements ApplicationRunner {
+//
+// private final PersonRepository repository;
+//
+// @Override
+// public void run(ApplicationArguments args) throws Exception {
+// System.out.println("satrt");
+// Person employee = new Person();
+// employee.setName("Joe");
+// employee.setAge(34);
+//
+// ExampleMatcher matcher = matching()
+// .withMatcher("name", endsWith())
+// .withIncludeNullValues();
+// Example example = Example.of(employee, matcher);
+//
+// Flux employees = repository.findAll(example);
+// System.out.println(employees.blockFirst());
+// System.out.println("end 1");
+//
+// var page = Pageable.ofSize(10).withPage(0);
+// Mono> employees2 = repository.findAll(where("name").is("Joe"), page);
+// System.out.println(employees2.block());
+// System.out.println("end 2");
+//
+// }
+//}
+/*
+r2dbcTemplate.getDatabaseClient().sql("insert into city (name) values ('j')").fetch().all().collectList().block();
+r2dbcTemplate.getDatabaseClient().sql("select * from city").fetch().all().collectList().block();
+r2dbcTemplate.getDatabaseClient().sql("SELECT city.* FROM city").fetch().all().collectList().block();
+//cityRepository.findAll().collectList().block();
+* */
\ No newline at end of file
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/LoadDataRunner.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/LoadDataRunner.java
new file mode 100644
index 0000000..8a88393
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/LoadDataRunner.java
@@ -0,0 +1,61 @@
+package io.github.verissimor.examples.reactive.javagradlereactive;
+
+
+import io.github.verissimor.examples.reactive.javagradlereactive.entity.City;
+import io.github.verissimor.examples.reactive.javagradlereactive.entity.User;
+import io.github.verissimor.examples.reactive.javagradlereactive.repository.CityRepository;
+import io.github.verissimor.examples.reactive.javagradlereactive.repository.UserRepository;
+import lombok.AllArgsConstructor;
+import org.springframework.boot.ApplicationArguments;
+import org.springframework.boot.ApplicationRunner;
+import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
+import org.springframework.stereotype.Component;
+
+import static io.github.verissimor.examples.reactive.javagradlereactive.entity.Gender.FEMALE;
+import static io.github.verissimor.examples.reactive.javagradlereactive.entity.Gender.MALE;
+import static java.time.LocalDate.parse;
+
+//@Configuration
+//@AllArgsConstructor
+//class CreateDbRunner implements ApplicationRunner {
+//
+// private final R2dbcEntityTemplate r2dbcTemplate;
+//
+// @Override
+// public void run(ApplicationArguments args) throws Exception {
+// // avoid .block(), this is just for example
+// r2dbcTemplate.getDatabaseClient().sql("""
+// create table city (id bigint generated by default as identity, name varchar(255), primary key (id));
+// create table app_user (id bigint generated by default as identity, name varchar(255), age integer not null, gender varchar(255), city_id bigint, primary key (id));
+// alter table app_user add constraint FK_ foreign key (city_id) references city;
+// """).fetch().rowsUpdated().block();
+// }
+//}
+
+@Component
+@AllArgsConstructor
+class LoadDataRunner implements ApplicationRunner {
+
+ private final R2dbcEntityTemplate r2dbcTemplate;
+ private final UserRepository userRepository;
+ private final CityRepository cityRepository;
+
+ @Override
+ public void run(ApplicationArguments args) {
+
+ var city1 = cityRepository.save(new City(null, "New York")).block();
+ var city2 = cityRepository.save(new City(null, "London")).block();
+ var city3 = cityRepository.save(new City(null, "Paris")).block();
+ var city4 = cityRepository.save(new City(null, "Rio de Janeiro")).block();
+
+ userRepository.save(new User(null, "Matthew C. McAfee", 31, MALE, city1.getId(), parse("2000-01-01"))).block();
+ userRepository.save(new User(null, "Eleanor C. Moyer", 23, FEMALE, city1.getId(), parse("2000-02-05"))).block();
+ userRepository.save(new User(null, "Gloria D. Wells", 41, FEMALE, city1.getId(), parse("2000-05-16"))).block();
+ userRepository.save(new User(null, "Matthew Norton", 43, MALE, city2.getId(), parse("2000-03-12"))).block();
+ userRepository.save(new User(null, "Maddison Joyce", 66, FEMALE, city2.getId(), parse("2000-05-16"))).block();
+ userRepository.save(new User(null, "Xarles Foucault", 55, MALE, city3.getId(), parse("2000-07-22"))).block();
+ userRepository.save(new User(null, "Joy Rochefort", 19, FEMALE, city3.getId(), parse("2000-08-10"))).block();
+ userRepository.save(new User(null, "Erick Melo Rodrigues", 19, MALE, city4.getId(), parse("2000-10-30"))).block();
+ userRepository.save(new User(null, "Gloria Azevedo Melot", 35, FEMALE, city4.getId(), null)).block();
+ }
+}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/controller/UserController.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/controller/UserController.java
new file mode 100644
index 0000000..a9cb102
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/controller/UserController.java
@@ -0,0 +1,49 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.controller;
+
+import io.github.verissimor.examples.reactive.javagradlereactive.entity.User;
+import io.github.verissimor.examples.reactive.javagradlereactive.repository.UserRepository;
+import io.github.verissimor.lib.jpamagicfilter.domain.DbFeatures;
+import io.github.verissimor.lib.r2dbcmagicfilter.R2dbcMagicFilter;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.java.Log;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
+import org.springframework.data.relational.core.query.Criteria;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+import static org.springframework.data.relational.core.query.Query.query;
+
+@Log
+@RestController
+@RequestMapping("/api/users")
+@RequiredArgsConstructor
+public class UserController {
+
+ private final R2dbcEntityTemplate r2dbcTemplate;
+ private final UserRepository userRepository;
+
+ @GetMapping
+ Flux getUsers(R2dbcMagicFilter filter) {
+ Criteria criteria = filter.toCriteria(User.class, DbFeatures.NONE);
+ return userRepository.findAll(criteria.ignoreCase(true), User.class);
+ }
+
+ @GetMapping("/paged")
+ Mono> getUsersPaged(R2dbcMagicFilter filter, Pageable pageable) {
+ Criteria criteria = filter.toCriteria(User.class, DbFeatures.NONE);
+ return userRepository.findAll(criteria, pageable, User.class);
+ }
+
+ @GetMapping("/fluent")
+ Flux getUsersFluent(R2dbcMagicFilter filter, Pageable pageable) {
+ Criteria criteria = filter.toCriteria(User.class, DbFeatures.NONE);
+ return r2dbcTemplate.select(User.class)
+ .matching(query(criteria))
+ .all();
+ }
+}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/City.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/City.java
new file mode 100644
index 0000000..6cc819a
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/City.java
@@ -0,0 +1,17 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.Id;
+import org.springframework.lang.Nullable;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class City {
+ @Id
+ @Nullable
+ Long id;
+ String name;
+}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/Gender.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/Gender.java
new file mode 100644
index 0000000..b8c4193
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/Gender.java
@@ -0,0 +1,5 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.entity;
+
+public enum Gender {
+ FEMALE, MALE
+}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/User.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/User.java
new file mode 100644
index 0000000..036ef37
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/entity/User.java
@@ -0,0 +1,26 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.annotation.Id;
+import org.springframework.data.relational.core.mapping.Table;
+import org.springframework.lang.Nullable;
+
+import java.time.LocalDate;
+
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+@Table(name = "app_user")
+public class User {
+ @Id
+ @Nullable
+ Long id;
+ String name;
+ Integer age;
+ Gender gender;
+ Long cityId;
+ @Nullable
+ LocalDate createdDate;
+}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/CityRepository.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/CityRepository.java
new file mode 100644
index 0000000..c339c93
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/CityRepository.java
@@ -0,0 +1,7 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.repository;
+
+import io.github.verissimor.examples.reactive.javagradlereactive.entity.City;
+import org.springframework.data.repository.reactive.ReactiveCrudRepository;
+
+public interface CityRepository extends ReactiveCrudRepository {
+}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/R2dbcConfig.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/R2dbcConfig.java
new file mode 100644
index 0000000..7b18181
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/R2dbcConfig.java
@@ -0,0 +1,24 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.repository;
+
+import io.r2dbc.spi.ConnectionFactories;
+import io.r2dbc.spi.ConnectionFactory;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.data.r2dbc.config.AbstractR2dbcConfiguration;
+import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
+import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories;
+
+//@Configuration
+//@EnableR2dbcRepositories
+//public class R2dbcConfig extends AbstractR2dbcConfiguration {
+// @Override
+// public ConnectionFactory connectionFactory() {
+//// return ConnectionFactories.get("r2dbc:h2:mem:///test?options=DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;CASE_INSENSITIVE_IDENTIFIERS=TRUE");
+// return ConnectionFactories.get("r2dbc:h2:mem:///test?options=CASE_INSENSITIVE_IDENTIFIERS=TRUE");
+// }
+//
+// @Bean
+// public R2dbcEntityTemplate r2dbcTemplate() {
+// return new R2dbcEntityTemplate(connectionFactory());
+// }
+//}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/ReactiveSearchRepository.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/ReactiveSearchRepository.java
new file mode 100644
index 0000000..5649a32
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/ReactiveSearchRepository.java
@@ -0,0 +1,47 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.repository;
+
+
+import lombok.AllArgsConstructor;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageImpl;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.r2dbc.core.R2dbcEntityTemplate;
+import org.springframework.data.relational.core.query.Criteria;
+import reactor.core.publisher.Flux;
+import reactor.core.publisher.Mono;
+
+import java.io.Serializable;
+import java.lang.reflect.ParameterizedType;
+import java.util.List;
+
+import static org.springframework.data.relational.core.query.Query.query;
+
+interface ReactiveSearchRepository {
+ Flux findAll(Criteria criteria, Class domainType);
+
+ public Mono> findAll(Criteria criteria, Pageable pageable, Class domainType);
+}
+
+@AllArgsConstructor
+class ReactiveSearchRepositoryImpl implements ReactiveSearchRepository {
+
+ private final R2dbcEntityTemplate r2dbcTemplate;
+
+ public Flux findAll(Criteria criteria, Class domainType) {
+ return r2dbcTemplate.select(domainType)
+ .matching(query(criteria))
+ .all();
+ }
+
+ public Mono> findAll(Criteria criteria, Pageable pageable, Class domainType) {
+ Mono> list = r2dbcTemplate.select(domainType)
+ .matching(query(criteria).with(pageable))
+ .all()
+ .collectList();
+ Mono count = r2dbcTemplate.select(domainType)
+ .matching(query(criteria))
+ .count();
+ return Mono.zip(list, count)
+ .map(tuple -> new PageImpl<>(tuple.getT1(), pageable, tuple.getT2()));
+ }
+}
diff --git a/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/UserRepository.java b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/UserRepository.java
new file mode 100644
index 0000000..7355fac
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/java/io/github/verissimor/examples/reactive/javagradlereactive/repository/UserRepository.java
@@ -0,0 +1,9 @@
+package io.github.verissimor.examples.reactive.javagradlereactive.repository;
+
+import io.github.verissimor.examples.reactive.javagradlereactive.entity.User;
+import org.springframework.data.repository.reactive.ReactiveCrudRepository;
+
+public interface UserRepository extends ReactiveCrudRepository, ReactiveSearchRepository {
+
+}
+
diff --git a/examples/java-gradle-reactive/src/main/resources/application.yaml b/examples/java-gradle-reactive/src/main/resources/application.yaml
new file mode 100644
index 0000000..f297328
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/resources/application.yaml
@@ -0,0 +1,4 @@
+logging:
+ level:
+ org.springframework.r2dbc: DEBUG
+ io.github.verissimor.lib.r2dbcmagicfilter: DEBUG
diff --git a/examples/java-gradle-reactive/src/main/resources/schema.sql b/examples/java-gradle-reactive/src/main/resources/schema.sql
new file mode 100644
index 0000000..a5ac50b
--- /dev/null
+++ b/examples/java-gradle-reactive/src/main/resources/schema.sql
@@ -0,0 +1,20 @@
+create table city
+(
+ id bigint generated by default as identity,
+ name varchar(255),
+ primary key (id)
+);
+
+create table app_user
+(
+ id bigint generated by default as identity,
+ name varchar(255),
+ age integer not null,
+ gender varchar(255),
+ city_id bigint,
+ created_date date,
+ primary key (id)
+);
+
+alter table app_user
+ add constraint FK_app_user_city foreign key (city_id) references city;
diff --git a/examples/java-gradle-reactive/src/test/java/io/github/verissimor/examples/reactive/javagradlereactive/JavaGradleReactiveApplicationTests.java b/examples/java-gradle-reactive/src/test/java/io/github/verissimor/examples/reactive/javagradlereactive/JavaGradleReactiveApplicationTests.java
new file mode 100644
index 0000000..d8791b6
--- /dev/null
+++ b/examples/java-gradle-reactive/src/test/java/io/github/verissimor/examples/reactive/javagradlereactive/JavaGradleReactiveApplicationTests.java
@@ -0,0 +1,13 @@
+package io.github.verissimor.examples.reactive.javagradlereactive;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class JavaGradleReactiveApplicationTests {
+
+ @Test
+ void contextLoads() {
+ }
+
+}
diff --git a/examples/java-maven-h2/pom.xml b/examples/java-maven-h2/pom.xml
index 38c1260..02f6671 100644
--- a/examples/java-maven-h2/pom.xml
+++ b/examples/java-maven-h2/pom.xml
@@ -29,7 +29,7 @@
io.github.verissimor.lib
jpa-magic-filter
- 0.0.10
+ 1.0.0
diff --git a/examples/java-maven-h2/src/main/java/io/github/verissimor/examples/javamavenh2/controller/UserController.java b/examples/java-maven-h2/src/main/java/io/github/verissimor/examples/javamavenh2/controller/UserController.java
index ca5d678..cb71f28 100644
--- a/examples/java-maven-h2/src/main/java/io/github/verissimor/examples/javamavenh2/controller/UserController.java
+++ b/examples/java-maven-h2/src/main/java/io/github/verissimor/examples/javamavenh2/controller/UserController.java
@@ -5,6 +5,7 @@
import io.github.verissimor.examples.javamavenh2.entity.User;
import io.github.verissimor.examples.javamavenh2.repository.UserRepository;
import io.github.verissimor.lib.jpamagicfilter.MagicFilter;
+import io.github.verissimor.lib.jpamagicfilter.domain.DbFeatures;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
@@ -22,13 +23,13 @@ public class UserController {
@GetMapping
List getUsers(MagicFilter filter) {
- Specification specification = filter.toSpecification(User.class);
+ Specification specification = filter.toSpecification(User.class, DbFeatures.NONE);
return userRepository.findAll(specification);
}
@GetMapping("/paged")
Page getUsersPaged(MagicFilter filter, Pageable pageable) {
- Specification specification = filter.toSpecification(User.class);
+ Specification specification = filter.toSpecification(User.class, DbFeatures.NONE);
return userRepository.findAll(specification, pageable);
}
}
diff --git a/src/main/kotlin/io/github/verissimor/lib/jpamagicfilter/MagicFilter.kt b/src/main/kotlin/io/github/verissimor/lib/jpamagicfilter/MagicFilter.kt
index 38e0057..b36a9c7 100644
--- a/src/main/kotlin/io/github/verissimor/lib/jpamagicfilter/MagicFilter.kt
+++ b/src/main/kotlin/io/github/verissimor/lib/jpamagicfilter/MagicFilter.kt
@@ -11,7 +11,7 @@ class MagicFilter(
private val parameterMap: Map>
) {
- fun toSpecification(clazz: Class<*>, dbFeatures: DbFeatures = NONE): Specification = Specification { root, _, cb ->
+ fun toSpecification(clazz: Class<*>, dbFeatures: DbFeatures): Specification = Specification { root, _, cb ->
val parsed = PredicateParser.parsePredicates(parameterMap, clazz, root, cb, dbFeatures)
when (parameterMap.toSingleParameter(SEARCH_TYPE_PRM)) {
@@ -21,6 +21,8 @@ class MagicFilter(
}
}
+ fun toSpecification(clazz: Class<*>): Specification = toSpecification(clazz, NONE)
+
companion object {
const val SEARCH_TYPE_PRM = "searchType"
const val SEARCH_TYPE_AND = "and"
diff --git a/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcMagicFilter.kt b/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcMagicFilter.kt
index 210b250..48895e7 100644
--- a/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcMagicFilter.kt
+++ b/src/main/kotlin/io/github/verissimor/lib/r2dbcmagicfilter/R2dbcMagicFilter.kt
@@ -32,8 +32,10 @@ class R2dbcMagicFilter(
else -> error("Invalid searchType. Only allowed: and, or")
}
- log.info(criteria.toString())
+ log.debug(criteria.toString())
return criteria
}
+
+ fun toCriteria(clazz: Class<*>): Criteria = toCriteria(clazz, NONE)
}