Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Lambda2sql (lambda) -> "sql"
Convert Java 8 lambdas to SQL statements.

For example, the following Predicate<Person>:
```
```jshelllanguage
person -> person.getAge() < 100 && person.getHeight() > 200
```

Expand All @@ -22,12 +22,12 @@ See [Lambda2SqlTest](https://github.com/ajermakovics/lambda2sql/blob/master/src/
Usage
---------

```
Lambda2Sql.init(); // initialize on program start, before predicates are created

Predicate<Person> predicate = person -> person.getAge() < 100 && person.getHeight() > 200;
```jshelllanguage
int age = 100;
int height = 200;
SqlPredicate<Person> predicate = person -> person.getAge() < age && person.getHeight() > height;

String sql = Lambda2Sql.toSql( predicate ); // age < 100 AND height > 200
String sql = Lambda2Sql.toSql(predicate); // age < 100 AND height > 200
```


Expand All @@ -36,12 +36,12 @@ How it works

It uses [JaQue](https://github.com/TrigerSoft/jaque) to build an expression tree for a lambda. The expression tree is then traversed and converted to a SQL statement.

Under the hood JaQue depends on the following system property:
`jdk.internal.lambda.dumpProxyClasses`
Under the hood, JaQue depends on the system property `jdk.internal.lambda.dumpProxyClasses`, if the lambda expression is not serialized:
See [https://bugs.openjdk.java.net/browse/JDK-8023524](https://bugs.openjdk.java.net/browse/JDK-8023524).

When the property is enabled, JVM generated classes for lambdas are saved to disk. JaQue then uses [ASM](http://asm.ow2.org/) to read the .class files and creates expression trees.

Since the interface [`SqlPredicate<T>`](https://github.com/ajermakovics/lambda2sql/blob/master/src/main/java/lambda2sql/SqlPredicate.java) is automatically serialized, there is no need to set this property.

Limitations
---------
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'maven'

sourceCompatibility = 1.9
targetCompatibility = 1.9
sourceCompatibility = 1.8
targetCompatibility = 1.8

version = '0.1'
group = "ajermakovics"
Expand All @@ -15,7 +15,7 @@ repositories {
}

dependencies {
compile 'com.trigersoft:jaque:2.1.3'
compile 'com.trigersoft:jaque:2.1.4'
testCompile group: 'junit', name: 'junit', version: '4.+'
}

Expand Down
4 changes: 1 addition & 3 deletions src/test/java/lambda2sql/Lambda2SqlTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public void testMultipleLogicalOps() {
@Test
public void testWithVariables() {
String name = "Donald";
//Datatype must be "Integer" for now. This is due to a bug in the JaQue library and author has been notified.
//As soon as the bug is fixed, the test will be updated.
Integer age = 80;
int age = 80;
assertEqual("name = 'Donald' AND age > 80", person -> person.getName() == name && person.getAge() > age);
}

Expand Down
9 changes: 5 additions & 4 deletions src/test/java/lambda2sql/Person.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package lambda2sql;

public interface Person {
String getName();

public String getName();
public int getAge();
public int getHeight();
public boolean isActive();
int getAge();

int getHeight();

boolean isActive();
}