diff --git a/lib/src/test/java/net/truej/sql/compiler/DtoGeneratorTest.java b/lib/src/test/java/net/truej/sql/compiler/DtoGeneratorTest.java deleted file mode 100644 index d77db18..0000000 --- a/lib/src/test/java/net/truej/sql/compiler/DtoGeneratorTest.java +++ /dev/null @@ -1,120 +0,0 @@ -package net.truej.sql.compiler; - -import net.truej.sql.compiler.GLangParser.*; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; - -public class DtoGeneratorTest { -// -// @Test void oneField() { -// var out = new StatementGenerator.Out(new StringBuilder()); -// -// DtoGenerator.generate(out, new GroupedType("A", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.String"), "f1") -// ))); -// -// Assertions.assertEquals( -// """ -// -// public static class A { -// @NotNull public final java.lang.String f1; -// -// public A( -// java.lang.String f1 -// ) { -// this.f1 = f1; -// } -// -// @Override public boolean equals(Object other) { -// return this == other || ( -// other instanceof A o && -// java.util.Objects.equals(this.f1, o.f1) -// ); -// } -// -// @Override public int hashCode() { -// int h = 1; -// h = h * 59 + java.util.Objects.hashCode(this.f1); -// return h; -// } -// }""", out.buffer.toString() -// ); -// } -// -// @Test void manyFields() { -// -// var out = new StatementGenerator.Out(new StringBuilder()); -// -// DtoGenerator.generate(out, new GroupedType("A", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.String"), "f1"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "float"), "f2"), -// new Field( -// new GroupedType("B", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "float"), "f4") -// )), -// "f3" -// ) -// ))); -// -// Assertions.assertEquals( -// """ -// -// public static class B { -// @NotNull public final float f4; -// -// public B( -// float f4 -// ) { -// this.f4 = f4; -// } -// -// @Override public boolean equals(Object other) { -// return this == other || ( -// other instanceof B o && -// java.util.Objects.equals(this.f4, o.f4) -// ); -// } -// -// @Override public int hashCode() { -// int h = 1; -// h = h * 59 + java.util.Objects.hashCode(this.f4); -// return h; -// } -// } -// public static class A { -// @NotNull public final java.lang.String f1; -// @NotNull public final float f2; -// public final List f3; -// -// public A( -// java.lang.String f1, -// float f2, -// List f3 -// ) { -// this.f1 = f1; -// this.f2 = f2; -// this.f3 = f3; -// } -// -// @Override public boolean equals(Object other) { -// return this == other || ( -// other instanceof A o && -// java.util.Objects.equals(this.f1, o.f1) && -// java.util.Objects.equals(this.f2, o.f2) && -// java.util.Objects.equals(this.f3, o.f3) -// ); -// } -// -// @Override public int hashCode() { -// int h = 1; -// h = h * 59 + java.util.Objects.hashCode(this.f1); -// h = h * 59 + java.util.Objects.hashCode(this.f2); -// h = h * 59 + java.util.Objects.hashCode(this.f3); -// return h; -// } -// }""", out.buffer.toString() -// ); -// } -} diff --git a/lib/src/test/java/net/truej/sql/compiler/FloatArrayRW.java b/lib/src/test/java/net/truej/sql/compiler/FloatArrayRW.java index a3a7c9f..cdc6496 100644 --- a/lib/src/test/java/net/truej/sql/compiler/FloatArrayRW.java +++ b/lib/src/test/java/net/truej/sql/compiler/FloatArrayRW.java @@ -3,8 +3,8 @@ import java.sql.*; public class FloatArrayRW extends GenericArrayRw { - @Override - float[] convert(Array array) throws SQLException { + + @Override float[] convert(Array array) throws SQLException { var sa = (Float[]) array.getArray(); var result = new float[sa.length]; for (var i = 0; i < sa.length; i++) diff --git a/lib/src/test/java/net/truej/sql/compiler/GLangParserTest.java b/lib/src/test/java/net/truej/sql/compiler/GLangParserTest.java index c5f01ee..538936e 100644 --- a/lib/src/test/java/net/truej/sql/compiler/GLangParserTest.java +++ b/lib/src/test/java/net/truej/sql/compiler/GLangParserTest.java @@ -31,20 +31,4 @@ void assertLex(String input, Lexeme... lexemes) { assertLex("a\\ \\ b", new Text("a b"), new End()); assertLex("a\\ \\ b", new Text("a "), new Text(" b"), new End()); } - - @Test void parseDotLangTest() { -// Assertions.assertEquals( -// parseGroups(""), List.of() -// ); -// Assertions.assertEquals( -// parseGroups("axxx"), List.of("axxx") -// ); -// Assertions.assertEquals( -// parseGroups("axxx.y"), List.of("axxx", "y") -// ); -// Assertions.assertEquals( -// parseGroups("axxx.b.c"), List.of("axxx", "b", "c") -// ); - //DotLangParser.parseFields(":t json t.b\\.c.d"); - } } diff --git a/lib/src/test/java/net/truej/sql/compiler/MapperGeneratorTest.java b/lib/src/test/java/net/truej/sql/compiler/MapperGeneratorTest.java deleted file mode 100644 index 761d992..0000000 --- a/lib/src/test/java/net/truej/sql/compiler/MapperGeneratorTest.java +++ /dev/null @@ -1,210 +0,0 @@ -package net.truej.sql.compiler; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static net.truej.sql.compiler.GLangParser.*; - -public class MapperGeneratorTest { -// -// @Test void single() { -// var out = new StatementGenerator.Out(new StringBuilder()); -// -// MapperGenerator.generate(out, new GroupedType( -// "Bill", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.Long"), "id"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.String"), "currency"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.math.BigDecimal"), "amount") -// )), null, t -> switch (t) { -// case "java.lang.String" -> "StringReadWrite"; -// case "java.lang.Long" -> "LongReadWrite"; -// case "java.math.BigDecimal" -> "BigDecimalReadWrite"; -// default -> throw new RuntimeException("not implemented"); -// }); -// -// Assertions.assertEquals(""" -// -// var mapped = Stream.iterate( -// rs, t -> { -// try { -// return t.next(); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }, t -> t -// ).map(t -> { -// try { -// return -// new Bill ( -// EvenSoNullPointerException.check(new LongReadWrite().get(rs, 1)), -// EvenSoNullPointerException.check(new StringReadWrite().get(rs, 2)), -// EvenSoNullPointerException.check(new BigDecimalReadWrite().get(rs, 3)) -// ); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }) -// ; -// """, -// out.buffer.toString() -// ); -// } -// -// @Test void grouped() { -// var out = new StatementGenerator.Out(new StringBuilder()); -// -// MapperGenerator.generate(out, new GroupedType( -// "Clinic", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.Long"), "id"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.String"), "name"), -// new Field( -// new GroupedType("List", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NULLABLE, "java.lang.String"), null) -// )), -// "addresses" -// ), -// new Field( -// new GroupedType("Doctor", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.Long"), "id"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.String"), "name") -// )), -// "doctors" -// ), -// new Field( -// new GroupedType("Patient", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.Long"), "id"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.String"), "name"), -// new Field( -// new GroupedType("Bill", List.of( -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.Long"), "id"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.lang.String"), "currency"), -// new Field(new ScalarType(NullMode.EXACTLY_NOT_NULL, "java.math.BigDecimal"), "money") -// )), -// "bills" -// ) -// )), -// "patients" -// ) -// )), null, t -> switch (t) { -// case "java.lang.String" -> "StringReadWrite"; -// case "java.lang.Long" -> "LongReadWrite"; -// case "java.math.BigDecimal" -> "BigDecimalReadWrite"; -// default -> throw new RuntimeException("not implemented"); -// }); -// -// Assertions.assertEquals(""" -// record Row( -// java.lang.Long c1, -// java.lang.String c2, -// java.lang.String c3, -// java.lang.Long c4, -// java.lang.String c5, -// java.lang.Long c6, -// java.lang.String c7, -// java.lang.Long c8, -// java.lang.String c9, -// java.math.BigDecimal c10 -// ) {} -// record G1( -// java.lang.Long c1, -// java.lang.String c2 -// ) {} -// record G2( -// java.lang.Long c6, -// java.lang.String c7 -// ) {} -// -// -// var mapped = Stream.iterate( -// rs, t -> { -// try { -// return t.next(); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }, t -> t -// ).map(t -> { -// try { -// return -// new Row ( -// new LongReadWrite().get(rs, 1), -// new StringReadWrite().get(rs, 2), -// new StringReadWrite().get(rs, 3), -// new LongReadWrite().get(rs, 4), -// new StringReadWrite().get(rs, 5), -// new LongReadWrite().get(rs, 6), -// new StringReadWrite().get(rs, 7), -// new LongReadWrite().get(rs, 8), -// new StringReadWrite().get(rs, 9), -// new BigDecimalReadWrite().get(rs, 10) -// ); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }) -// .collect( -// java.util.stream.Collectors.groupingBy( -// r -> new G1( -// r.c1, -// r.c2 -// ), java.util.LinkedHashMap::new, Collectors.toList() -// ) -// ).entrySet().stream() -// .filter(g1 -> -// java.util.Objects.nonNull(g1.getKey().c1) || -// java.util.Objects.nonNull(g1.getKey().c2) -// ).map(g1 -> -// new Clinic( -// EvenSoNullPointerException.check(g1.getKey().c1), -// EvenSoNullPointerException.check(g1.getKey().c2), -// g1.getValue().stream().filter(r -> -// java.util.Objects.nonNull(r.c3) -// ).map(r -> -// r.c3 -// ).distinct().toList(), -// g1.getValue().stream().filter(r -> -// java.util.Objects.nonNull(r.c4) || -// java.util.Objects.nonNull(r.c5) -// ).map(r -> -// new Doctor( -// EvenSoNullPointerException.check(r.c4), -// EvenSoNullPointerException.check(r.c5) -// ) -// ).distinct().toList(), -// g1.getValue().stream().collect( -// java.util.stream.Collectors.groupingBy( -// r -> new G2( -// r.c6, -// r.c7 -// ), java.util.LinkedHashMap::new, Collectors.toList() -// ) -// ).entrySet().stream() -// .filter(g2 -> -// java.util.Objects.nonNull(g2.getKey().c6) || -// java.util.Objects.nonNull(g2.getKey().c7) -// ).map(g2 -> -// new Patient( -// EvenSoNullPointerException.check(g2.getKey().c6), -// EvenSoNullPointerException.check(g2.getKey().c7), -// g2.getValue().stream().filter(r -> -// java.util.Objects.nonNull(r.c8) || -// java.util.Objects.nonNull(r.c9) || -// java.util.Objects.nonNull(r.c10) -// ).map(r -> -// new Bill( -// EvenSoNullPointerException.check(r.c8), -// EvenSoNullPointerException.check(r.c9), -// EvenSoNullPointerException.check(r.c10) -// ) -// ).distinct().toList() -// ) -// ).toList() -// ) -// ); -// """, -// out.buffer.toString() -// ); -// } -} diff --git a/lib/src/test/java/net/truej/sql/compiler/StatementGeneratorTest.java b/lib/src/test/java/net/truej/sql/compiler/StatementGeneratorTest.java deleted file mode 100644 index 9f46dc6..0000000 --- a/lib/src/test/java/net/truej/sql/compiler/StatementGeneratorTest.java +++ /dev/null @@ -1,217 +0,0 @@ -package net.truej.sql.compiler; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Disabled; -import org.junit.jupiter.api.Test; - -import java.util.List; - -import static net.truej.sql.compiler.GLangParser.*; -import static net.truej.sql.compiler.StatementGenerator.*; - -//@Disabled -public class StatementGeneratorTest { -// @Test void batch() { -// Assertions.assertEquals( -// """ -// -// public static class User { -// public final java.lang.Long id; -// @Nullable public final java.lang.String name; -// -// public User( -// java.lang.Long id, -// java.lang.String name -// ) { -// this.id = id; -// this.name = name; -// } -// -// @Override public boolean equals(Object other) { -// return this == other || ( -// other instanceof User o && -// java.util.Objects.equals(this.id, o.id) && -// java.util.Objects.equals(this.name, o.name) -// ); -// } -// -// @Override public int hashCode() { -// int h = 1; -// h = h * 59 + java.util.Objects.hashCode(this.id); -// h = h * 59 + java.util.Objects.hashCode(this.name); -// return h; -// } -// } -// public static -// List fetchList__line12__( -// List batch, -// Function pe1, -// TypeReadWrite prw1, -// ConnectionW source -// ) throws E1 { -// var query = ""\" -// select id, name from users where id = ? -// ""\"; -// \s -// try { -// var connection = source.w(); -// try (var stmt = connection.prepareStatement(query)) { -// \s -// for (var element : batch) { -// var p1 = pe1.get(element); -// prw1.set(stmt, 1, p1); -// stmt.addBatch(); -// } -// \s -// var updateCount = stmt.executeLargeBatch(); -// \s -// var rs = stmt.getResultSet(); -// \s -// \s -// var mapped = Stream.iterate( -// rs, t -> { -// try { -// return t.next(); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }, t -> t -// ).map(t -> { -// try { -// return -// new User ( -// EvenSoNullPointerException.check(new LongReadWrite().get(rs, 1)), -// new StringReadWrite().get(rs, 2) -// ); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }) -// ; -// return mapped.toList(); -// \s -// } -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// } -// """, -// generate( -// t -> switch (t) { -// case "java.lang.String" -> "StringReadWrite"; -// case "java.lang.Long" -> "LongReadWrite"; -// default -> throw new RuntimeException("not implemented"); -// }, -// 12, -// SourceMode.CONNECTION, -// new BatchedQuery(null, null, List.of( -// new InvocationsFinder.TextPart("select id, name from users where id = "), -// new InvocationsFinder.InParameter(null), -// new InvocationsFinder.TextPart("") -// )), -// new AsDefault(), -// new FetchList( -// new GroupedType( -// "User", List.of( -// new Field(new ScalarType(NullMode.DEFAULT_NOT_NULL, "java.lang.Long"), "id"), -// new Field(new ScalarType(NullMode.EXACTLY_NULLABLE, "java.lang.String"), "name") -// )) -// ), -// true, -// false -// ) -// ); -// } -// -// @Test void singleUnfold() { -// Assertions.assertEquals( -// """ -// public static -// UpdateResult> fetchList__line12__( -// P1 p1, -// TypeReadWrite prw1, -// List> p2, -// TypeReadWrite prw2a1, -// TypeReadWrite prw2a2, -// DataSourceW source -// ) { -// var buffer = new StringBuilder(); -// \s -// buffer.append(""\" -// select name from users where id = ""\"); -// buffer.append(" ? "); -// buffer.append(""\" -// and (name, age) in (""\"); -// for (var i = 0; i < p2.size(); i++) { -// buffer.append(" (?, ?) "); -// if (i != p2.size() - 1) -// buffer.append(", "); -// } -// buffer.append(""\" -// )""\"); -// \s -// var query = buffer.toString(); -// \s -// try (var connection = source.w().getConnection()) { -// try (var stmt = connection.prepareStatement(query)) { -// \s -// var n = 0; -// prw1.set(stmt, ++n, p1); -// \s -// for (var element : p2) { -// prw2a1.set(stmt, ++n, element.a1()); -// prw2a2.set(stmt, ++n, element.a2()); -// } -// \s -// stmt.execute(); -// \s -// var rs = stmt.getResultSet(); -// \s -// \s -// var mapped = Stream.iterate( -// rs, t -> { -// try { -// return t.next(); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }, t -> t -// ).map(t -> { -// try { -// return -// EvenSoNullPointerException.check(new StringReadWrite().get(rs, 1)); -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// }) -// ; -// return new UpdateResult<>(stmt.getLargeUpdateCount(), mapped.toList()); -// \s -// } -// } catch (SQLException e) { -// throw source.mapException(e); -// } -// } -// """, -// generate( -// t -> switch (t) { -// case "java.lang.String" -> "StringReadWrite"; -// default -> throw new RuntimeException("not implemented"); -// }, -// 12, -// SourceMode.DATASOURCE, -// new SingleQuery(List.of( -// new InvocationsFinder.TextPart("select name from users where id = "), -// new InvocationsFinder.InParameter(null), -// new InvocationsFinder.TextPart("and (name, age) in ("), -// new InvocationsFinder.UnfoldParameter(null, null), -// new InvocationsFinder.TextPart(")") -// )), -// new AsDefault(), -// new FetchList(new ScalarType(NullMode.DEFAULT_NOT_NULL, "java.lang.String")), -// false, -// true -// ) -// ); -// } -}