Skip to content

Commit 1125b59

Browse files
committed
Using parameters in combination with higher level functions works now.
1 parent d8b25ca commit 1125b59

File tree

6 files changed

+11
-12
lines changed

6 files changed

+11
-12
lines changed

README.MD

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Features
4646

4747
Current version works with predicates, functions and supports the following operators: >, >=, <, <=, =, !=, &&, ||, !
4848

49-
Feel free to open an issue with any requests you might have.`
49+
Feel free to open an issue with any requests you might have.
5050

5151
Install
5252
-------
@@ -56,7 +56,7 @@ You can include the Maven dependency:
5656
<dependency>
5757
<groupId>com.github.collinalpert</groupId>
5858
<artifactId>lambda2sql</artifactId>
59-
<version>1.6.3</version>
59+
<version>1.6.4</version>
6060
</dependency>
6161
```
6262

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.github.collinalpert</groupId>
88
<artifactId>lambda2sql</artifactId>
9-
<version>1.6.3</version>
9+
<version>1.6.4</version>
1010
<packaging>jar</packaging>
1111

1212
<name>lambda2sql</name>

src/main/java/com/github/collinalpert/lambda2sql/Lambda2Sql.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public class Lambda2Sql {
1616
* Supported operators: {@code >,>=,<,<=,=,!=,&&,||,!}
1717
*
1818
* @param functionalInterface A {@link FunctionalInterface} lambda to convert.
19-
* @param prefix An optional prefix to proceed the column name.
20-
* Usually it is supposed to be used to reference the column name including the table name.
19+
* @param prefix An optional prefix to proceed the column name. Usually it is the table name.
2120
* @return A {@link String} describing the SQL where condition.
2221
*/
2322
public static String toSql(SerializedFunctionalInterface functionalInterface, String prefix) {

src/main/java/com/github/collinalpert/lambda2sql/ToSqlVisitor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class ToSqlVisitor implements ExpressionVisitor<StringBuilder> {
2525
private Expression body;
2626
private List<ConstantExpression> parameters;
2727

28-
public ToSqlVisitor(String prefix) {
28+
ToSqlVisitor(String prefix) {
2929
this.prefix = prefix;
3030
this.sb = new StringBuilder();
3131
this.parameters = new LinkedList<>();
@@ -102,7 +102,7 @@ public StringBuilder visit(ConstantExpression e) {
102102
public StringBuilder visit(InvocationExpression e) {
103103
e.getArguments()
104104
.stream()
105-
.filter(x -> x instanceof ConstantExpression)
105+
.filter(x -> x instanceof ConstantExpression && x.getResultType() != LambdaExpression.class)
106106
.map(ConstantExpression.class::cast)
107107
.forEach(parameters::add);
108108
return e.getTarget().accept(this);

src/test/java/com/github/collinalpert/lambda2sql/Lambda2SqlTest.java renamed to src/test/java/com/github/collinalpert/lambda2sql/test/Lambda2SqlTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package com.github.collinalpert.lambda2sql;
1+
package com.github.collinalpert.lambda2sql.test;
22

3+
import com.github.collinalpert.lambda2sql.Lambda2Sql;
34
import com.github.collinalpert.lambda2sql.functions.SqlFunction;
45
import com.github.collinalpert.lambda2sql.functions.SqlPredicate;
5-
import com.trigersoft.jaque.expression.LambdaExpression;
66
import org.junit.jupiter.api.Assertions;
77
import org.junit.jupiter.api.Test;
88

@@ -48,15 +48,15 @@ void testFunction() {
4848
void testMethodReferences() {
4949
SqlPredicate<Person> person = Person::isAdult;
5050
SqlPredicate<Person> personAnd = person.and(x -> true);
51-
LambdaExpression<SqlPredicate<Person>> lambda = LambdaExpression.parse(personAnd);
51+
assertPredicateEqual("person.isAdult AND true", personAnd);
5252
}
5353

5454
@Test
5555
void testGetById() {
5656
int id = 1;
5757
SqlPredicate<Person> personPredicate = person -> person.getId() == id;
5858
SqlPredicate<Person> personSqlPredicateAnd = personPredicate.and(x -> true);
59-
LambdaExpression<SqlPredicate<Person>> pred = LambdaExpression.parse(personSqlPredicateAnd);
59+
assertPredicateEqual("person.id = 1 AND true", personSqlPredicateAnd);
6060
}
6161

6262
private void assertPredicateEqual(String expectedSql, SqlPredicate<Person> p) {

src/test/java/com/github/collinalpert/lambda2sql/Person.java renamed to src/test/java/com/github/collinalpert/lambda2sql/test/Person.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.github.collinalpert.lambda2sql;
1+
package com.github.collinalpert.lambda2sql.test;
22

33
public interface Person {
44
long getId();

0 commit comments

Comments
 (0)