added entity class to dbset

This commit is contained in:
wea_ondara
2022-07-15 21:18:57 +02:00
parent 5dae201bfb
commit 00b7fb2f45
6 changed files with 61 additions and 50 deletions

View File

@@ -4,16 +4,20 @@ import jef.expressions.Expression;
import jef.expressions.SelectExpression; import jef.expressions.SelectExpression;
import jef.expressions.TableExpression; import jef.expressions.TableExpression;
import jef.expressions.selectable.DatabaseSelectAllExpression; import jef.expressions.selectable.DatabaseSelectAllExpression;
import jef.serializable.SerializableObject;
import lombok.Getter;
import java.io.Serializable;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Spliterator; import java.util.Spliterator;
public class DBSet<T extends Serializable> implements Queryable<T> { public class DbSet<T extends SerializableObject> implements Queryable<T> {
@Getter
private final Class<T> clazz;
private final String table; private final String table;
public DBSet(String table) { public DbSet(Class<T> clazz, String table) {
this.clazz = clazz;
this.table = table; this.table = table;
} }
@@ -48,22 +52,22 @@ public class DBSet<T extends Serializable> implements Queryable<T> {
} }
@Override @Override
public DBSet<T> sequential() { public DbSet<T> sequential() {
return this; return this;
} }
@Override @Override
public DBSet<T> parallel() { public DbSet<T> parallel() {
return this; return this;
} }
@Override @Override
public DBSet<T> unordered() { public DbSet<T> unordered() {
return this; return this;
} }
@Override @Override
public DBSet<T> onClose(Runnable runnable) { public DbSet<T> onClose(Runnable runnable) {
return this; return this;
} }

View File

@@ -0,0 +1,6 @@
package jef.serializable;
import java.io.Serializable;
public class SerializableObject implements Serializable {
}

View File

@@ -1,6 +1,7 @@
package jef.operations; package jef.operations;
import jef.DBSet; import jef.DbSet;
import jef.serializable.SerializableObject;
import lombok.Getter; import lombok.Getter;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -14,7 +15,7 @@ public class FilterOpTest {
@Test @Test
public void testTrue() { public void testTrue() {
String act; String act;
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> true) .filter(e -> true)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE 1", act);
@@ -23,43 +24,43 @@ public class FilterOpTest {
@Test @Test
public void testCompareWithEntityMember() { public void testCompareWithEntityMember() {
String act; String act;
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i == 1) .filter(e -> e.i == 1)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i != 1) .filter(e -> e.i != 1)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` <> 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` <> 1", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i < 1) .filter(e -> e.i < 1)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` < 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` < 1", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i > 1) .filter(e -> e.i > 1)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` > 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` > 1", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i <= 1) .filter(e -> e.i <= 1)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` <= 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` <= 1", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i >= 1) .filter(e -> e.i >= 1)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` >= 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` >= 1", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i == 1337) .filter(e -> e.i == 1337)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337", act);
@@ -69,7 +70,7 @@ public class FilterOpTest {
public void testContainsWithEntityMember() { public void testContainsWithEntityMember() {
var s = List.of(1, 3); var s = List.of(1, 3);
String act; String act;
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> s.contains(e.i)) .filter(e -> s.contains(e.i))
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3)", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3)", act);
@@ -79,7 +80,7 @@ public class FilterOpTest {
public void testMultipleFilter() { public void testMultipleFilter() {
String act; String act;
var s = List.of(1, 3); var s = List.of(1, 3);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> s.contains(e.i)) .filter(e -> s.contains(e.i))
.filter(e -> e.i == 1337) .filter(e -> e.i == 1337)
.toString(); .toString();
@@ -90,31 +91,31 @@ public class FilterOpTest {
public void testComplexExpression() { public void testComplexExpression() {
String act; String act;
var s = List.of(1, 3); var s = List.of(1, 3);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> s.contains(e.i) && e.i == 1337) .filter(e -> s.contains(e.i) && e.i == 1337)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3) AND `a`.`i` = 1337", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3) AND `a`.`i` = 1337", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> s.contains(e.i) && e.i == 1337 && e.i == 420) .filter(e -> s.contains(e.i) && e.i == 1337 && e.i == 420)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3) AND `a`.`i` = 1337 AND `a`.`i` = 420", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3) AND `a`.`i` = 1337 AND `a`.`i` = 420", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i == 1337 || e.i != 420 || s.contains(e.i)) .filter(e -> e.i == 1337 || e.i != 420 || s.contains(e.i))
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337 OR `a`.`i` <> 420 OR `a`.`i` IN (1, 3)", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337 OR `a`.`i` <> 420 OR `a`.`i` IN (1, 3)", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i == 1337 || e.i == 420 || s.contains(e.i)) .filter(e -> e.i == 1337 || e.i == 420 || s.contains(e.i))
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337 OR `a`.`i` = 420 OR `a`.`i` IN (1, 3)", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337 OR `a`.`i` = 420 OR `a`.`i` IN (1, 3)", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i == 1337 || s.contains(e.i) || e.i == 420) .filter(e -> e.i == 1337 || s.contains(e.i) || e.i == 420)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337 OR `a`.`i` IN (1, 3) OR `a`.`i` = 420", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337 OR `a`.`i` IN (1, 3) OR `a`.`i` = 420", act);
@@ -124,13 +125,13 @@ public class FilterOpTest {
public void testComplexExpressionMixedAndOr() { public void testComplexExpressionMixedAndOr() {
String act; String act;
var s = List.of(1, 3); var s = List.of(1, 3);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> s.contains(e.i) && (e.i == 1337 || e.i == 420)) .filter(e -> s.contains(e.i) && (e.i == 1337 || e.i == 420))
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3) AND (`a`.`i` = 1337 OR `a`.`i` = 420)", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` IN (1, 3) AND (`a`.`i` = 1337 OR `a`.`i` = 420)", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> (e.i == 1337 || e.i == 420) && s.contains(e.i)) .filter(e -> (e.i == 1337 || e.i == 420) && s.contains(e.i))
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE (`a`.`i` = 1337 OR `a`.`i` = 420) AND `a`.`i` IN (1, 3)", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE (`a`.`i` = 1337 OR `a`.`i` = 420) AND `a`.`i` IN (1, 3)", act);
@@ -140,19 +141,19 @@ public class FilterOpTest {
public void testObject() { public void testObject() {
String act; String act;
var s = Arrays.asList(null, 4); var s = Arrays.asList(null, 4);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.o == null) .filter(e -> e.o == null)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`o` IS NULL", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`o` IS NULL", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.o != null) .filter(e -> e.o != null)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`o` IS NOT NULL", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`o` IS NOT NULL", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.o != null || s.contains(e.o)) .filter(e -> e.o != null || s.contains(e.o))
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`o` IS NOT NULL OR `a`.`o` IN (NULL, 4)", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`o` IS NOT NULL OR `a`.`o` IN (NULL, 4)", act);
@@ -162,19 +163,19 @@ public class FilterOpTest {
public void testFloatingPoint() { public void testFloatingPoint() {
String act; String act;
var s = Arrays.asList(null, 2); var s = Arrays.asList(null, 2);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.d == 3.14d) .filter(e -> e.d == 3.14d)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`d` = 3.14", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`d` = 3.14", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.f == 3.14f) .filter(e -> e.f == 3.14f)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`f` = 3.14", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`f` = 3.14", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.d != 1d || e.f != 1 || s.contains(e.d)) .filter(e -> e.d != 1d || e.f != 1 || s.contains(e.d))
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`d` <> 1 OR `a`.`f` <> 1 OR `a`.`d` IN (NULL, 2)", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`d` <> 1 OR `a`.`f` <> 1 OR `a`.`d` IN (NULL, 2)", act);
@@ -183,25 +184,25 @@ public class FilterOpTest {
@Test @Test
public void testIDFLConst() { public void testIDFLConst() {
String act; String act;
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.i == 0 || e.i == 1 || e.i == 2 || e.i == 3 || e.i == 4 || e.i == 5) .filter(e -> e.i == 0 || e.i == 1 || e.i == 2 || e.i == 3 || e.i == 4 || e.i == 5)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 0 OR `a`.`i` = 1 OR `a`.`i` = 2 OR `a`.`i` = 3 OR `a`.`i` = 4 OR `a`.`i` = 5", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 0 OR `a`.`i` = 1 OR `a`.`i` = 2 OR `a`.`i` = 3 OR `a`.`i` = 4 OR `a`.`i` = 5", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.d == 0D || e.d == 1D) .filter(e -> e.d == 0D || e.d == 1D)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`d` = 0 OR `a`.`d` = 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`d` = 0 OR `a`.`d` = 1", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.f == 0F || e.f == 1F || e.f == 2F) .filter(e -> e.f == 0F || e.f == 1F || e.f == 2F)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`f` = 0 OR `a`.`f` = 1 OR `a`.`f` = 2", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`f` = 0 OR `a`.`f` = 1 OR `a`.`f` = 2", act);
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.l == 0L || e.l == 1L) .filter(e -> e.l == 0L || e.l == 1L)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`l` = 0 OR `a`.`l` = 1", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`l` = 0 OR `a`.`l` = 1", act);
@@ -210,14 +211,14 @@ public class FilterOpTest {
@Test @Test
public void testMemberViaGetter() { public void testMemberViaGetter() {
String act; String act;
act = new DBSet<TestClass>("table1") act = new DbSet<>(TestClass.class, "table1")
.filter(e -> e.getI() == 1337) .filter(e -> e.getI() == 1337)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a WHERE `a`.`i` = 1337", act);
} }
@Getter @Getter
public static class TestClass implements Serializable { public static class TestClass extends SerializableObject {
public int i = 1; public int i = 1;
public Object o = new Object(); public Object o = new Object();
public double d; public double d;

View File

@@ -1,6 +1,6 @@
package jef.operations; package jef.operations;
import jef.DBSet; import jef.DbSet;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -8,25 +8,25 @@ public class LimitOpTest {
@Test @Test
public void test() { public void test() {
String act; String act;
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.limit(10).skip(5) .limit(10).skip(5)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a LIMIT 10 OFFSET 5", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a LIMIT 10 OFFSET 5", act);
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.skip(5).limit(10) .skip(5).limit(10)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a LIMIT 10 OFFSET 5", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a LIMIT 10 OFFSET 5", act);
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.skip(5) .skip(5)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a OFFSET 5", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a OFFSET 5", act);
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.limit(10) .limit(10)
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a LIMIT 10", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a LIMIT 10", act);

View File

@@ -1,6 +1,6 @@
package jef.operations; package jef.operations;
import jef.DBSet; import jef.DbSet;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
@@ -8,27 +8,27 @@ class SortOpTest {
@Test @Test
public void test() { public void test() {
String act; String act;
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.sorted(e -> e.getI()).thenSorted(e -> e.getD()).thenSorted(e -> e.getF()).thenSorted(e -> e.getL()).thenSorted(e -> e.getO()) .sorted(e -> e.getI()).thenSorted(e -> e.getD()).thenSorted(e -> e.getF()).thenSorted(e -> e.getL()).thenSorted(e -> e.getO())
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a ORDER BY `a`.`i` ASC, `a`.`d` ASC, `a`.`f` ASC, `a`.`l` ASC, `a`.`o` ASC", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a ORDER BY `a`.`i` ASC, `a`.`d` ASC, `a`.`f` ASC, `a`.`l` ASC, `a`.`o` ASC", act);
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.sortedDescending(e -> e.getI()).thenSortedDescending(e -> e.getD()).thenSortedDescending(e -> e.getF()) .sortedDescending(e -> e.getI()).thenSortedDescending(e -> e.getD()).thenSortedDescending(e -> e.getF())
/**/.thenSortedDescending(e -> e.getL()).thenSortedDescending(e -> e.getO()) /**/.thenSortedDescending(e -> e.getL()).thenSortedDescending(e -> e.getO())
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a ORDER BY `a`.`i` DESC, `a`.`d` DESC, `a`.`f` DESC, `a`.`l` DESC, `a`.`o` DESC", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a ORDER BY `a`.`i` DESC, `a`.`d` DESC, `a`.`f` DESC, `a`.`l` DESC, `a`.`o` DESC", act);
//alternating patterns //alternating patterns
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.sortedDescending(e -> e.getI()).thenSorted(e -> e.getD()).thenSortedDescending(e -> e.getF()).thenSorted(e -> e.getL()) .sortedDescending(e -> e.getI()).thenSorted(e -> e.getD()).thenSortedDescending(e -> e.getF()).thenSorted(e -> e.getL())
/**/.thenSortedDescending(e -> e.getO()) /**/.thenSortedDescending(e -> e.getO())
.toString(); .toString();
Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a ORDER BY `a`.`i` DESC, `a`.`d` ASC, `a`.`f` DESC, `a`.`l` ASC, `a`.`o` DESC", act); Assertions.assertEquals("SELECT * FROM (SELECT * FROM `table1`) a ORDER BY `a`.`i` DESC, `a`.`d` ASC, `a`.`f` DESC, `a`.`l` ASC, `a`.`o` DESC", act);
act = new DBSet<FilterOpTest.TestClass>("table1") act = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.sorted(e -> e.getI()).thenSortedDescending(e -> e.getD()).thenSorted(e -> e.getF()).thenSortedDescending(e -> e.getL()) .sorted(e -> e.getI()).thenSortedDescending(e -> e.getD()).thenSorted(e -> e.getF()).thenSortedDescending(e -> e.getL())
/**/.thenSorted(e -> e.getO()) /**/.thenSorted(e -> e.getO())
.toString(); .toString();

View File

@@ -1,6 +1,6 @@
package jef.visitors; package jef.visitors;
import jef.DBSet; import jef.DbSet;
import jef.Queryable; import jef.Queryable;
import jef.expressions.visitors.DebugExpressionVisitor; import jef.expressions.visitors.DebugExpressionVisitor;
import jef.operations.FilterOpTest; import jef.operations.FilterOpTest;
@@ -12,11 +12,11 @@ class DebugExpressionVisitorTest {
@Test @Test
public void test() { public void test() {
var s = List.of(1, 3); var s = List.of(1, 3);
Queryable<FilterOpTest.TestClass> q = new DBSet<FilterOpTest.TestClass>("table1") Queryable<FilterOpTest.TestClass> q = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.filter(e -> s.contains(e.i) && e.i == 1337 && e.i == 420); .filter(e -> s.contains(e.i) && e.i == 1337 && e.i == 420);
new DebugExpressionVisitor().visit(q.getExpression()); new DebugExpressionVisitor().visit(q.getExpression());
Queryable<FilterOpTest.TestClass> q2 = new DBSet<FilterOpTest.TestClass>("table1") Queryable<FilterOpTest.TestClass> q2 = new DbSet<>(FilterOpTest.TestClass.class, "table1")
.filter(e -> s.contains(e.i) || e.i == 1337); .filter(e -> s.contains(e.i) || e.i == 1337);
new DebugExpressionVisitor().visit(q2.getExpression()); new DebugExpressionVisitor().visit(q2.getExpression());
} }