From d2d6a1fbacb03aa0e5a18ecb0e0f970cd2b47577 Mon Sep 17 00:00:00 2001 From: Collin Alpert Date: Wed, 20 Nov 2019 20:55:50 +0100 Subject: [PATCH] Upgraded to Java 13 --- README.MD | 4 +- pom.xml | 10 ++--- .../collinalpert/lambda2sql/Lambda2Sql.java | 2 +- .../collinalpert/lambda2sql/SqlVisitor.java | 37 +++++++++++-------- .../lambda2sql/test/Lambda2SqlTest.java | 1 - 5 files changed, 29 insertions(+), 25 deletions(-) diff --git a/README.MD b/README.MD index 7294484..af76ef0 100644 --- a/README.MD +++ b/README.MD @@ -1,7 +1,7 @@ Lambda2sql (lambda) -> "sql" ========== -**Please note:** This is a Java 10 library so make sure you have at least Java 10 installed when using it. +**Please note:** This is a Java 13 library so make sure you have at least Java 10 installed when using it. Convert Java 8 lambdas to SQL statements. @@ -64,7 +64,7 @@ You can include the Maven dependency: com.github.collinalpert lambda2sql - 2.1.4 + 2.2 ``` diff --git a/pom.xml b/pom.xml index 3848bbc..1fca07c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.github.collinalpert lambda2sql - 2.1.4 + 2.2 jar lambda2sql @@ -49,7 +49,7 @@ - 10 + 13 ${java-version} ${java-version} ${java-version} @@ -58,9 +58,9 @@ - com.trigersoft - jaque - 2.4.4 + com.github.collinalpert + expressions + 2.5 diff --git a/src/main/java/com/github/collinalpert/lambda2sql/Lambda2Sql.java b/src/main/java/com/github/collinalpert/lambda2sql/Lambda2Sql.java index d345b09..2db7950 100644 --- a/src/main/java/com/github/collinalpert/lambda2sql/Lambda2Sql.java +++ b/src/main/java/com/github/collinalpert/lambda2sql/Lambda2Sql.java @@ -1,7 +1,7 @@ package com.github.collinalpert.lambda2sql; +import com.github.collinalpert.expressions.expression.LambdaExpression; import com.github.collinalpert.lambda2sql.functions.SerializedFunctionalInterface; -import com.trigersoft.jaque.expression.LambdaExpression; /** * A utility class for converting java lambdas to SQL. diff --git a/src/main/java/com/github/collinalpert/lambda2sql/SqlVisitor.java b/src/main/java/com/github/collinalpert/lambda2sql/SqlVisitor.java index 5473723..1b6d513 100755 --- a/src/main/java/com/github/collinalpert/lambda2sql/SqlVisitor.java +++ b/src/main/java/com/github/collinalpert/lambda2sql/SqlVisitor.java @@ -1,17 +1,17 @@ package com.github.collinalpert.lambda2sql; +import com.github.collinalpert.expressions.expression.BinaryExpression; +import com.github.collinalpert.expressions.expression.ConstantExpression; +import com.github.collinalpert.expressions.expression.DelegateExpression; +import com.github.collinalpert.expressions.expression.Expression; +import com.github.collinalpert.expressions.expression.ExpressionType; +import com.github.collinalpert.expressions.expression.ExpressionVisitor; +import com.github.collinalpert.expressions.expression.InvocationExpression; +import com.github.collinalpert.expressions.expression.LambdaExpression; +import com.github.collinalpert.expressions.expression.MemberExpression; +import com.github.collinalpert.expressions.expression.ParameterExpression; +import com.github.collinalpert.expressions.expression.UnaryExpression; import com.github.collinalpert.lambda2sql.functions.TriFunction; -import com.trigersoft.jaque.expression.BinaryExpression; -import com.trigersoft.jaque.expression.ConstantExpression; -import com.trigersoft.jaque.expression.DelegateExpression; -import com.trigersoft.jaque.expression.Expression; -import com.trigersoft.jaque.expression.ExpressionType; -import com.trigersoft.jaque.expression.ExpressionVisitor; -import com.trigersoft.jaque.expression.InvocationExpression; -import com.trigersoft.jaque.expression.LambdaExpression; -import com.trigersoft.jaque.expression.MemberExpression; -import com.trigersoft.jaque.expression.ParameterExpression; -import com.trigersoft.jaque.expression.UnaryExpression; import java.lang.reflect.Member; import java.time.LocalDate; @@ -130,7 +130,9 @@ public StringBuilder visit(BinaryExpression e) { boolean quote = e != this.body && e.getExpressionType() == ExpressionType.LogicalOr; - if (quote) sb.append('('); + if (quote) { + sb.append('('); + } e.getFirst().accept(this); @@ -138,7 +140,9 @@ public StringBuilder visit(BinaryExpression e) { e.getSecond().accept(this); - if (quote) sb.append(')'); + if (quote) { + sb.append(')'); + } return sb; } @@ -201,7 +205,7 @@ public StringBuilder visit(InvocationExpression e) { * @return A {@link StringBuilder} containing the body of the lambda expression. */ @Override - public StringBuilder visit(LambdaExpression e) { + public StringBuilder visit(LambdaExpression e) { if (this.body == null && e.getBody() instanceof BinaryExpression) { this.body = e.getBody(); } @@ -308,6 +312,7 @@ private StringBuilder listContains(Expression listAsArgument, Expression argumen List l = (List) arguments.pop().get(((ParameterExpression) listAsArgument).getIndex()).getValue(); var joiner = new StringJoiner(", ", "(", ")"); l.forEach(x -> joiner.add(x.toString())); + return argument.accept(new SqlVisitor(this.tableName, this.withBackticks, this.arguments)).append(negated ? " NOT" : "").append(" IN ").append(joiner.toString()); } @@ -316,11 +321,11 @@ private StringBuilder listContains(Expression listAsArgument, Expression argumen private StringBuilder doStringOperation(Expression member, Expression argument, boolean negated, Consumer modifier) { var valueBuilder = argument.accept(new SqlVisitor(this.tableName, this.withBackticks, this.arguments)); modifier.accept(valueBuilder); + return member.accept(new SqlVisitor(this.tableName, this.withBackticks, this.arguments)).append(negated ? " NOT" : "").append(" LIKE ").append(valueBuilder); } private String escapeString(String input) { - input = input.replace("\\", "\\\\").replace("'", "\\'"); - return input; + return input.replace("\\", "\\\\").replace("'", "\\'"); } } \ No newline at end of file diff --git a/src/test/java/com/github/collinalpert/lambda2sql/test/Lambda2SqlTest.java b/src/test/java/com/github/collinalpert/lambda2sql/test/Lambda2SqlTest.java index cfdd79b..353af29 100644 --- a/src/test/java/com/github/collinalpert/lambda2sql/test/Lambda2SqlTest.java +++ b/src/test/java/com/github/collinalpert/lambda2sql/test/Lambda2SqlTest.java @@ -3,7 +3,6 @@ import com.github.collinalpert.lambda2sql.Lambda2Sql; import com.github.collinalpert.lambda2sql.functions.SqlFunction; import com.github.collinalpert.lambda2sql.functions.SqlPredicate; -import com.trigersoft.jaque.expression.LambdaExpression; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test;