Skip to content

Commit

Permalink
Upgraded to Java 13
Browse files Browse the repository at this point in the history
  • Loading branch information
CollinAlpert committed Nov 20, 2019
1 parent 28a7aaa commit d2d6a1f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
@@ -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.

Expand Down Expand Up @@ -64,7 +64,7 @@ You can include the Maven dependency:
<dependency>
<groupId>com.github.collinalpert</groupId>
<artifactId>lambda2sql</artifactId>
<version>2.1.4</version>
<version>2.2</version>
</dependency>
```

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.collinalpert</groupId>
<artifactId>lambda2sql</artifactId>
<version>2.1.4</version>
<version>2.2</version>
<packaging>jar</packaging>

<name>lambda2sql</name>
Expand Down Expand Up @@ -49,7 +49,7 @@
</distributionManagement>

<properties>
<java-version>10</java-version>
<java-version>13</java-version>
<jdk.version>${java-version}</jdk.version>
<maven.compiler.source>${java-version}</maven.compiler.source>
<maven.compiler.target>${java-version}</maven.compiler.target>
Expand All @@ -58,9 +58,9 @@

<dependencies>
<dependency>
<groupId>com.trigersoft</groupId>
<artifactId>jaque</artifactId>
<version>2.4.4</version>
<groupId>com.github.collinalpert</groupId>
<artifactId>expressions</artifactId>
<version>2.5</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
37 changes: 21 additions & 16 deletions src/main/java/com/github/collinalpert/lambda2sql/SqlVisitor.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -130,15 +130,19 @@ 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);

sb.append(' ').append(toSqlOperator(e.getExpressionType())).append(' ');

e.getSecond().accept(this);

if (quote) sb.append(')');
if (quote) {
sb.append(')');
}

return sb;
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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());
}

Expand All @@ -316,11 +321,11 @@ private StringBuilder listContains(Expression listAsArgument, Expression argumen
private StringBuilder doStringOperation(Expression member, Expression argument, boolean negated, Consumer<StringBuilder> 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("'", "\\'");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit d2d6a1f

Please sign in to comment.