From fc90db2b3037a7d73b6d7809e0c2dc08413278d1 Mon Sep 17 00:00:00 2001 From: babyfish-ct Date: Wed, 1 Jun 2022 01:16:50 +0800 Subject: [PATCH] Better API --- example/jimmer-core/build.gradle | 6 +- .../org/babyfish/jimmer/example/core/App.java | 12 +- example/jimmer-sql-graphql/build.gradle | 6 +- example/jimmer-sql/build.gradle | 6 +- project/build.gradle.kts | 2 +- .../org/babyfish/jimmer/sql/Associations.java | 28 +- .../org/babyfish/jimmer/sql/Entities.java | 15 + .../association/loader/ListLoaderImpl.java | 5 + .../loader/ReferenceLoaderImpl.java | 5 + .../babyfish/jimmer/sql/ast/Expression.java | 4 - .../sql/ast/impl/ExpressionImplementor.java | 10 - .../ast/impl/mutation/AssociationsImpl.java | 19 +- .../sql/ast/impl/mutation/EntitiesImpl.java | 101 ++++- .../jimmer/sql/common/AbstractQueryTest.java | 17 +- .../jimmer/sql/fetcher/RecursiveTest.java | 6 +- .../jimmer/sql/fetcher/SingleTest.java | 4 +- .../sql/mutation/AssociationMutationTest.java | 8 +- .../sql/query/AssociationLoaderTest.java | 92 ++--- .../babyfish/jimmer/sql/query/EntityTest.java | 348 ++++++++++++++++++ .../jimmer/sql/query/InverseJoinTest.java | 5 +- .../babyfish/jimmer/sql/query/JoinTest.java | 9 +- .../jimmer/sql/query/SubQueryTest.java | 5 +- 22 files changed, 600 insertions(+), 113 deletions(-) create mode 100644 project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/EntityTest.java diff --git a/example/jimmer-core/build.gradle b/example/jimmer-core/build.gradle index f9a6fd1af9..9987cf64d4 100644 --- a/example/jimmer-core/build.gradle +++ b/example/jimmer-core/build.gradle @@ -3,7 +3,7 @@ plugins { } group 'org.babyfish.jimmer.example.core' -version '0.0.19' +version '0.0.20' repositories { mavenCentral() @@ -11,8 +11,8 @@ repositories { dependencies { - implementation 'org.babyfish.jimmer:jimmer-core:0.0.19' - annotationProcessor 'org.babyfish.jimmer:jimmer-apt:0.0.19' + implementation 'org.babyfish.jimmer:jimmer-core:0.0.20' + annotationProcessor 'org.babyfish.jimmer:jimmer-apt:0.0.20' implementation 'javax.validation:validation-api:2.0.1.Final' } diff --git a/example/jimmer-core/src/main/java/org/babyfish/jimmer/example/core/App.java b/example/jimmer-core/src/main/java/org/babyfish/jimmer/example/core/App.java index f121f468f6..2c884d37e0 100644 --- a/example/jimmer-core/src/main/java/org/babyfish/jimmer/example/core/App.java +++ b/example/jimmer-core/src/main/java/org/babyfish/jimmer/example/core/App.java @@ -46,7 +46,7 @@ private static void bookDemo() { private static void treeNodeDemo() { - // 第一步,从头构建全新的数据 + // First step, create new object from scratch TreeNode treeNode = TreeNodeDraft.$.produce(root -> { root.setName("Root").addIntoChildNodes(food -> { food @@ -65,14 +65,14 @@ private static void treeNodeDemo() { }); }); - // 第二步,基于现有数据对象,做某些“变更”,创建新的数据对象。 + // Second step, make some "changes" based on the existing object to get a new object. TreeNode newTreeNode = TreeNodeDraft.$.produce( - // highlight-next-line - treeNode, // 现有的数据对象 + treeNode, // existing object root -> { root - .childNodes(true).get(0) - .childNodes(true).get(0) + .childNodes(true).get(0) // Food + .childNodes(true).get(0) // Drink + .childNodes(true).get(0) // Coco Cola .setName("Coco Cola plus"); } ); diff --git a/example/jimmer-sql-graphql/build.gradle b/example/jimmer-sql-graphql/build.gradle index a390f47a24..0b454b1bd9 100644 --- a/example/jimmer-sql-graphql/build.gradle +++ b/example/jimmer-sql-graphql/build.gradle @@ -5,7 +5,7 @@ plugins { } group = 'org.babyfish.jimmer.sql.example' -version = '0.0.19' +version = '0.0.20' sourceCompatibility = '1.8' repositories { @@ -14,8 +14,8 @@ repositories { dependencies { - implementation 'org.babyfish.jimmer:jimmer-sql:0.0.19' - annotationProcessor 'org.babyfish.jimmer:jimmer-apt:0.0.19' + implementation 'org.babyfish.jimmer:jimmer-sql:0.0.20' + annotationProcessor 'org.babyfish.jimmer:jimmer-apt:0.0.20' implementation 'org.springframework.boot:spring-boot-starter-graphql' implementation 'org.springframework.boot:spring-boot-starter-web' diff --git a/example/jimmer-sql/build.gradle b/example/jimmer-sql/build.gradle index 72dbd9458e..ad59781ddd 100644 --- a/example/jimmer-sql/build.gradle +++ b/example/jimmer-sql/build.gradle @@ -6,7 +6,7 @@ plugins { } group 'org.babyfish.jimmer.example.sql' -version '0.0.19' +version '0.0.20' repositories { mavenCentral() @@ -14,8 +14,8 @@ repositories { dependencies { - implementation 'org.babyfish.jimmer:jimmer-sql:0.0.19' - annotationProcessor 'org.babyfish.jimmer:jimmer-apt:0.0.19' + implementation 'org.babyfish.jimmer:jimmer-sql:0.0.20' + annotationProcessor 'org.babyfish.jimmer:jimmer-apt:0.0.20' implementation 'org.springframework.boot:spring-boot-starter' implementation 'org.springframework.shell:spring-shell-starter:2.0.1.RELEASE' diff --git a/project/build.gradle.kts b/project/build.gradle.kts index 8f873f6a80..97198852a6 100644 --- a/project/build.gradle.kts +++ b/project/build.gradle.kts @@ -1,4 +1,4 @@ allprojects { group = "org.babyfish.jimmer" - version = "0.0.19" + version = "0.0.20" } \ No newline at end of file diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Associations.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Associations.java index 63fc643ebb..e422e78dcc 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Associations.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Associations.java @@ -10,17 +10,29 @@ public interface Associations { Associations reverse(); + default int save(Object sourceId, Object targetId) { + return saveCommand(sourceId, targetId).execute(); + } + + default int batchSave(Collection sourceIds, Collection targetIds) { + return batchSaveCommand(sourceIds, targetIds).execute(); + } + + default int batchSave(Collection> idPairs) { + return batchSaveCommand(idPairs).execute(); + } + AssociationSaveCommand saveCommand( Object sourceId, Object targetId ); - AssociationSaveCommand saveCommand( + AssociationSaveCommand batchSaveCommand( Collection sourceIds, Collection targetIds ); - AssociationSaveCommand saveCommand( + AssociationSaveCommand batchSaveCommand( Collection> idPairs ); @@ -28,17 +40,17 @@ default int delete(Object sourceId, Object targetId) { return deleteCommand(sourceId, targetId).execute(); } - default int delete(Collection sourceIds, Collection targetIds) { - return deleteCommand(sourceIds, targetIds).execute(); + default int batchDelete(Collection sourceIds, Collection targetIds) { + return batchDeleteCommand(sourceIds, targetIds).execute(); } - default int delete(Collection> idPairs) { - return deleteCommand(idPairs).execute(); + default int batchDelete(Collection> idPairs) { + return batchDeleteCommand(idPairs).execute(); } Executable deleteCommand(Object sourceId, Object targetId); - Executable deleteCommand(Collection sourceIds, Collection targetIds); + Executable batchDeleteCommand(Collection sourceIds, Collection targetIds); - Executable deleteCommand(Collection> idPairs); + Executable batchDeleteCommand(Collection> idPairs); } diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Entities.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Entities.java index 71978433a0..caa1d34c6e 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Entities.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/Entities.java @@ -1,11 +1,26 @@ package org.babyfish.jimmer.sql; import org.babyfish.jimmer.sql.ast.mutation.*; +import org.babyfish.jimmer.sql.fetcher.Fetcher; import java.util.Collection; +import java.util.List; +import java.util.Map; public interface Entities { + E findById(Class entityType, Object id); + + List findByIds(Class entityType, Collection ids); + + Map findMapByIds(Class entityType, Collection ids); + + E findById(Fetcher fetcher, Object id); + + List findByIds(Fetcher fetcher, Collection ids); + + Map findMapByIds(Fetcher fetcher, Collection ids); + default SimpleSaveResult save(E entity) { return saveCommand(entity).execute(); } diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ListLoaderImpl.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ListLoaderImpl.java index b94fafc421..fe38afe7f0 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ListLoaderImpl.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ListLoaderImpl.java @@ -29,6 +29,11 @@ public ListLoaderImpl(SqlClient sqlClient, ImmutableProp prop, BiConsumer> loadCommand(S source, int limit, int offset) { + if (source instanceof Collection) { + throw new IllegalArgumentException( + "source cannot be collection, do you want to call 'batchLoadCommand'?" + ); + } return new SingleCommand<>( sqlClient, prop, diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ReferenceLoaderImpl.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ReferenceLoaderImpl.java index 23707b5627..98b10cf3bd 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ReferenceLoaderImpl.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/association/loader/ReferenceLoaderImpl.java @@ -32,6 +32,11 @@ public ReferenceLoaderImpl( @Override public Executable loadCommand(S source) { + if (source instanceof Collection) { + throw new IllegalArgumentException( + "source cannot be collection, do you want to call 'batchLoadCommand'?" + ); + } return new SingleCommand<>( sqlClient, prop, diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/Expression.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/Expression.java index a30b71651d..23825f51bd 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/Expression.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/Expression.java @@ -23,12 +23,8 @@ public interface Expression extends Selection { Predicate in(Collection values); - Predicate in(T ... values); - Predicate notIn(Collection values); - Predicate notIn(T ... values); - Predicate in(TypedSubQuery subQuery); Predicate notIn(TypedSubQuery subQuery); diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/ExpressionImplementor.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/ExpressionImplementor.java index 6cc8d64326..8afa3a3b8b 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/ExpressionImplementor.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/ExpressionImplementor.java @@ -74,21 +74,11 @@ default Predicate in(Collection values) { return new InCollectionPredicate(this, values, false); } - @Override - default Predicate in(T ... values) { - return in(Arrays.asList(values)); - } - @Override default Predicate notIn(Collection values) { return new InCollectionPredicate(this, values, true); } - @Override - default Predicate notIn(T ... values) { - return notIn(Arrays.asList(values)); - } - @Override default Predicate in(TypedSubQuery subQuery) { return new InSubQueryPredicate(this, subQuery, false); diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/AssociationsImpl.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/AssociationsImpl.java index 9e7f1b48a4..0a7de7f027 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/AssociationsImpl.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/AssociationsImpl.java @@ -34,20 +34,25 @@ public Associations reverse() { @Override public AssociationSaveCommand saveCommand(Object sourceId, Object targetId) { + if (sourceId instanceof Collection || targetId instanceof Collection) { + throw new IllegalArgumentException( + "sourceId or targetId cannot be collection, do you want to call 'batchSaveCommand'?" + ); + } return new AssociationSaveCommandImpl( saveExecutable(validateAndZip(sourceId, targetId)) ); } @Override - public AssociationSaveCommand saveCommand(Collection sourceIds, Collection targetIds) { + public AssociationSaveCommand batchSaveCommand(Collection sourceIds, Collection targetIds) { return new AssociationSaveCommandImpl( saveExecutable(validateAndZip(sourceIds, targetIds)) ); } @Override - public AssociationSaveCommand saveCommand(Collection> idPairs) { + public AssociationSaveCommand batchSaveCommand(Collection> idPairs) { return new AssociationSaveCommandImpl( saveExecutable(validate(idPairs)) ); @@ -55,16 +60,21 @@ public AssociationSaveCommand saveCommand(Collection> idP @Override public Executable deleteCommand(Object sourceId, Object targetId) { + if (sourceId instanceof Collection || targetId instanceof Collection) { + throw new IllegalArgumentException( + "sourceId or targetId cannot be collection, do you want to call 'batchDeleteCommand'?" + ); + } return deleteExecutable(validateAndZip(sourceId, targetId)); } @Override - public Executable deleteCommand(Collection sourceIds, Collection targetIds) { + public Executable batchDeleteCommand(Collection sourceIds, Collection targetIds) { return deleteExecutable(validateAndZip(sourceIds, targetIds)); } @Override - public Executable deleteCommand(Collection> idPairs) { + public Executable batchDeleteCommand(Collection> idPairs) { return deleteExecutable(validate(idPairs)); } @@ -88,6 +98,7 @@ private Executable deleteExecutable(Collection> ); } + @SuppressWarnings("unchecked") private static Collection> validateAndZip(Object sourceId, Object targetId) { return Collections.singleton( new Tuple2<>( diff --git a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/EntitiesImpl.java b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/EntitiesImpl.java index a204907155..c8ee5ac2e9 100644 --- a/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/EntitiesImpl.java +++ b/project/jimmer-sql/src/main/java/org/babyfish/jimmer/sql/ast/impl/mutation/EntitiesImpl.java @@ -1,13 +1,24 @@ package org.babyfish.jimmer.sql.ast.impl.mutation; import org.babyfish.jimmer.meta.ImmutableType; +import org.babyfish.jimmer.runtime.ImmutableSpi; import org.babyfish.jimmer.sql.Entities; import org.babyfish.jimmer.sql.SqlClient; +import org.babyfish.jimmer.sql.ast.Expression; +import org.babyfish.jimmer.sql.ast.Selection; +import org.babyfish.jimmer.sql.ast.impl.query.Queries; +import org.babyfish.jimmer.sql.ast.impl.table.TableImplementor; import org.babyfish.jimmer.sql.ast.mutation.BatchEntitySaveCommand; import org.babyfish.jimmer.sql.ast.mutation.DeleteCommand; import org.babyfish.jimmer.sql.ast.mutation.SimpleEntitySaveCommand; +import org.babyfish.jimmer.sql.ast.query.TypedRootQuery; +import org.babyfish.jimmer.sql.ast.table.Table; +import org.babyfish.jimmer.sql.fetcher.Fetcher; import java.util.*; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.stream.Collectors; public class EntitiesImpl implements Entities { @@ -17,8 +28,96 @@ public EntitiesImpl(SqlClient sqlClient) { this.sqlClient = sqlClient; } + @Override + public E findById(Class entityType, Object id) { + if (id instanceof Collection) { + throw new IllegalArgumentException( + "id cannot be collection, do you want to call 'findByIds'?" + ); + } + List rows = findByIds(entityType, null, Collections.singleton(id)); + return rows.isEmpty() ? null : rows.get(0); + } + + @Override + public List findByIds(Class entityType, Collection ids) { + return findByIds(entityType, null, ids); + } + + @SuppressWarnings("unchecked") + @Override + public Map findMapByIds(Class entityType, Collection ids) { + String idPropName = ImmutableType.get(entityType).getIdProp().getName(); + return this.findByIds(entityType, null, ids).stream().collect( + Collectors.toMap( + it -> (ID)((ImmutableSpi) it).__get(idPropName), + Function.identity(), + (a, b) -> { throw new IllegalStateException("Objects with same id"); }, + LinkedHashMap::new + ) + ); + } + + @Override + public E findById(Fetcher fetcher, Object id) { + if (id instanceof Collection) { + throw new IllegalArgumentException( + "id cannot be collection, do you want to call 'findByIds'?" + ); + } + List rows = findByIds(fetcher.getJavaClass(), fetcher, Collections.singleton(id)); + return rows.isEmpty() ? null : rows.get(0); + } + + @Override + public List findByIds(Fetcher fetcher, Collection ids) { + return findByIds(fetcher.getJavaClass(), fetcher, ids); + } + + @SuppressWarnings("unchecked") + @Override + public Map findMapByIds(Fetcher fetcher, Collection ids) { + String idPropName = ImmutableType.get(fetcher.getJavaClass()).getIdProp().getName(); + return this.findByIds(fetcher.getJavaClass(), fetcher, ids).stream().collect( + Collectors.toMap( + it -> (ID)((ImmutableSpi) it).__get(idPropName), + Function.identity(), + (a, b) -> { throw new IllegalStateException("Objects with same id"); }, + LinkedHashMap::new + ) + ); + } + + @SuppressWarnings("unchecked") + private List findByIds( + Class entityType, + Fetcher fetcher, + Collection ids + ) { + if (ids.isEmpty()) { + return Collections.emptyList(); + } + ImmutableType immutableType = ImmutableType.get(entityType); + return Queries + .createQuery( + sqlClient, immutableType, (q, table) -> { + Expression idProp = table.get(immutableType.getIdProp().getName()); + if (ids.size() == 1) { + q.where(idProp.eq(ids.iterator().next())); + } else { + q.where(idProp.in((Collection) ids)); + } + return q.select(((Table) table).fetch(fetcher)); + } + ) + .execute(); + } + @Override public SimpleEntitySaveCommand saveCommand(E entity) { + if (entity instanceof Collection) { + throw new IllegalArgumentException("entity cannot be collection, do you want to call 'batchSaveCommand'?"); + } return new SimpleEntitySaveCommandImpl<>(sqlClient, entity); } @@ -33,7 +132,7 @@ public DeleteCommand deleteCommand( Object id ) { if (id instanceof Collection) { - throw new IllegalArgumentException("id is collection, do you want to call batchDeleteCommand?"); + throw new IllegalArgumentException("id cannot be collection, do you want to call 'batchDeleteCommand'?"); } return batchDeleteCommand(entityType, Collections.singleton(id)); } diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/common/AbstractQueryTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/common/AbstractQueryTest.java index 3fe723140f..f2a68f04d2 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/common/AbstractQueryTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/common/AbstractQueryTest.java @@ -3,7 +3,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.babyfish.jimmer.jackson.ImmutableModule; -import org.babyfish.jimmer.lang.NewChain; import org.babyfish.jimmer.meta.ImmutableProp; import org.babyfish.jimmer.runtime.ImmutableSpi; import org.babyfish.jimmer.sql.ast.Executable; @@ -45,16 +44,28 @@ protected void executeAndExpect( ); } - protected void callAnyAndExpect( + protected void anyAndExpect( Executable executable, Consumer> block + ) { + connectAndExpect(executable::execute, block); + } + + protected void connectAndExpect( + Function func, + Consumer> block ) { clearExecutions(); rows = null; maxStatementIndex = -1; jdbc(con -> { if (rows == null) { - rows = Collections.singletonList(executable.execute(con)); + Object result = func.apply(con); + if (result instanceof List) { + rows = (List) result; + } else { + rows = Collections.singletonList(result); + } } }); block.accept(new QueryTestContext<>(0)); diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/RecursiveTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/RecursiveTest.java index 010166bdc7..7347561264 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/RecursiveTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/RecursiveTest.java @@ -5,6 +5,8 @@ import org.babyfish.jimmer.sql.model.TreeNodeTable; import org.junit.jupiter.api.Test; +import java.util.Arrays; + public class RecursiveTest extends AbstractQueryTest { @Test @@ -476,7 +478,7 @@ public void findNullTerminal() { executeAndExpect( getSqlClient().createQuery(TreeNodeTable.class, (q, treeNode) -> { q.where( - treeNode.id().in(12L, 13L, 14L, 16L, 17L) + treeNode.id().in(Arrays.asList(12L, 13L, 14L, 16L, 17L)) ); q.orderBy(treeNode.id()); return q.select( @@ -530,7 +532,7 @@ public void findNullTerminalWithoutChildFetcher() { executeAndExpect( getSqlClient().createQuery(TreeNodeTable.class, (q, treeNode) -> { q.where( - treeNode.id().in(12L, 13L, 14L, 16L, 17L) + treeNode.id().in(Arrays.asList(12L, 13L, 14L, 16L, 17L)) ); q.orderBy(treeNode.id()); return q.select( diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/SingleTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/SingleTest.java index 431a133a86..81c28d4bbb 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/SingleTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/fetcher/SingleTest.java @@ -6,6 +6,8 @@ import org.babyfish.jimmer.sql.model.*; import org.junit.jupiter.api.Test; +import java.util.Arrays; + public class SingleTest extends AbstractQueryTest { @Test @@ -131,7 +133,7 @@ public void testManyToMany() { public void testInverseManyToMany() { executeAndExpect( getSqlClient().createQuery(AuthorTable.class, (q, author) -> { - q.where(author.id().in(borisId, sammerId)); + q.where(author.id().in(Arrays.asList(borisId, sammerId))); q.orderBy(author.firstName()); return q.select( author.fetch( diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/mutation/AssociationMutationTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/mutation/AssociationMutationTest.java index 0aee925208..5a30ec8aaa 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/mutation/AssociationMutationTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/mutation/AssociationMutationTest.java @@ -39,7 +39,7 @@ public void testInsert() { executeAndExpectRowCount( getSqlClient().getAssociations( BookTableEx.class, BookTableEx::authors - ).saveCommand( + ).batchSaveCommand( Arrays.asList( new Tuple2<>(learningGraphQLId1, alexId), new Tuple2<>(learningGraphQLId2, borisId), @@ -76,7 +76,7 @@ public void testDelete() { executeAndExpectRowCount( getSqlClient().getAssociations( BookTableEx.class, BookTableEx::authors - ).deleteCommand( + ).batchDeleteCommand( Arrays.asList(learningGraphQLId1, learningGraphQLId2, learningGraphQLId3), Arrays.asList(alexId, alexId, borisId) ), @@ -124,7 +124,7 @@ public void testInverseInsert() { executeAndExpectRowCount( getSqlClient().getAssociations( AuthorTableEx.class, AuthorTableEx::books - ).saveCommand( + ).batchSaveCommand( Arrays.asList( new Tuple2<>(alexId, learningGraphQLId1), new Tuple2<>(borisId, learningGraphQLId2), @@ -161,7 +161,7 @@ public void testInverseDelete() { executeAndExpectRowCount( getSqlClient().getAssociations( AuthorTableEx.class, AuthorTableEx::books - ).deleteCommand( + ).batchDeleteCommand( Arrays.asList(alexId, alexId, borisId), Arrays.asList(learningGraphQLId1, learningGraphQLId2, learningGraphQLId3) ), diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/AssociationLoaderTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/AssociationLoaderTest.java index bf700f364c..4ce2d14190 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/AssociationLoaderTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/AssociationLoaderTest.java @@ -14,7 +14,7 @@ public class AssociationLoaderTest extends AbstractQueryTest { @Test public void loadManyToOne() { - callAnyAndExpect( + anyAndExpect( getSqlClient() .getReferenceLoader(BookTable.class, BookTable::store) .loadCommand( @@ -49,7 +49,7 @@ public void loadManyToOne() { @Test public void batchLoadManyToOne() { - callAnyAndExpect( + anyAndExpect( getSqlClient() .getReferenceLoader(BookTable.class, BookTable::store) .batchLoadCommand( @@ -109,7 +109,7 @@ public void batchLoadManyToOne() { @Test public void testLoadOneToMany() { - callAnyAndExpect( + anyAndExpect( getSqlClient() .getListLoader( BookStoreTableEx.class, @@ -134,37 +134,31 @@ public void testLoadOneToMany() { "limit ?" ); ctx.variables(manningId, 2); - ctx.rows(rows -> { - Assertions.assertEquals(1, rows.size()); - String childList1Text = - "[" + - "--->{" + - "--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + - "--->--->\"name\":\"GraphQL in Action\"," + - "--->--->\"edition\":3," + - "--->--->\"price\":80.00," + - "--->--->\"store\":{\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"}" + - "--->}, " + - "--->{" + - "--->--->\"id\":\"e37a8344-73bb-4b23-ba76-82eac11f03e6\"," + - "--->--->\"name\":\"GraphQL in Action\"," + - "--->--->\"edition\":2," + - "--->--->\"price\":81.00," + - "--->--->\"store\":{\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"}" + - "--->}" + - "]"; - Assertions.assertEquals( - childList1Text.replace("--->", ""), - rows.get(0).toString() - ); - }); + ctx.rows( + "[" + + "--->{" + + "--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + + "--->--->\"name\":\"GraphQL in Action\"," + + "--->--->\"edition\":3," + + "--->--->\"price\":80.00," + + "--->--->\"store\":{\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"}" + + "--->}," + + "--->{" + + "--->--->\"id\":\"e37a8344-73bb-4b23-ba76-82eac11f03e6\"," + + "--->--->\"name\":\"GraphQL in Action\"," + + "--->--->\"edition\":2," + + "--->--->\"price\":81.00," + + "--->--->\"store\":{\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"}" + + "--->}" + + "]" + ); } ); } @Test public void testBatchLoadOneToMany() { - callAnyAndExpect( + anyAndExpect( getSqlClient() .getListLoader( BookStoreTableEx.class, @@ -220,7 +214,7 @@ public void testBatchLoadOneToMany() { @Test public void loadManyToMany() { - callAnyAndExpect( + anyAndExpect( getSqlClient() .getListLoader( BookTableEx.class, @@ -239,35 +233,29 @@ public void loadManyToMany() { "where tb_1_.BOOK_ID = ?" ); ctx.variables(learningGraphQLId3); - ctx.rows(rows -> { - Assertions.assertEquals(1, rows.size()); - String authorListText = - "[" + - "--->{" + - "--->--->\"id\":\"1e93da94-af84-44f4-82d1-d8a9fd52ea94\"," + - "--->--->\"firstName\":\"Alex\"," + - "--->--->\"lastName\":\"Banks\"," + - "--->--->\"gender\":\"MALE\"" + - "--->}, " + - "--->{" + - "--->--->\"id\":\"fd6bb6cf-336d-416c-8005-1ae11a6694b5\"," + - "--->--->\"firstName\":\"Eve\"," + - "--->--->\"lastName\":\"Procello\"," + - "--->--->\"gender\":\"MALE\"" + - "--->}" + - "]"; - Assertions.assertEquals( - authorListText.replace("--->", ""), - rows.get(0).toString() - ); - }); + ctx.rows( + "[" + + "--->{" + + "--->--->\"id\":\"1e93da94-af84-44f4-82d1-d8a9fd52ea94\"," + + "--->--->\"firstName\":\"Alex\"," + + "--->--->\"lastName\":\"Banks\"," + + "--->--->\"gender\":\"MALE\"" + + "--->}," + + "--->{" + + "--->--->\"id\":\"fd6bb6cf-336d-416c-8005-1ae11a6694b5\"," + + "--->--->\"firstName\":\"Eve\"," + + "--->--->\"lastName\":\"Procello\"," + + "--->--->\"gender\":\"MALE\"" + + "--->}" + + "]" + ); } ); } @Test public void batchLoadManyToMany() { - callAnyAndExpect( + anyAndExpect( getSqlClient() .getListLoader( BookTableEx.class, diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/EntityTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/EntityTest.java new file mode 100644 index 0000000000..09d10fd3f8 --- /dev/null +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/EntityTest.java @@ -0,0 +1,348 @@ +package org.babyfish.jimmer.sql.query; + +import org.babyfish.jimmer.sql.SqlClient; +import org.babyfish.jimmer.sql.common.AbstractQueryTest; +import org.babyfish.jimmer.sql.model.AuthorFetcher; +import org.babyfish.jimmer.sql.model.Book; +import static org.babyfish.jimmer.sql.common.Constants.*; + +import org.babyfish.jimmer.sql.model.BookFetcher; +import org.babyfish.jimmer.sql.model.BookStoreFetcher; +import org.babyfish.jimmer.sql.runtime.ConnectionManager; +import org.junit.jupiter.api.Test; + +import java.sql.Connection; +import java.util.Arrays; +import java.util.function.Function; + +public class EntityTest extends AbstractQueryTest { + + @Test + public void testFindById() { + connectAndExpect( + con -> getSqlClient(con) + .getEntities() + .findById(Book.class, graphQLInActionId3), + ctx -> { + ctx.sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION, tb_1_.PRICE, tb_1_.STORE_ID " + + "from BOOK as tb_1_ " + + "where tb_1_.ID = ?" + ).variables(graphQLInActionId3); + ctx.rows( + "[" + + "--->{" + + "--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + + "--->--->\"name\":\"GraphQL in Action\"," + + "--->--->\"edition\":3," + + "--->--->\"price\":80.00," + + "--->--->\"store\":{\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"}" + + "--->}" + + "]" + ); + }); + } + + @Test + public void testFindByIds() { + connectAndExpect( + con -> getSqlClient(con) + .getEntities() + .findByIds( + Book.class, + Arrays.asList( + graphQLInActionId3, + effectiveTypeScriptId3 + ) + ), + ctx -> { + ctx.sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION, tb_1_.PRICE, tb_1_.STORE_ID " + + "from BOOK as tb_1_ " + + "where tb_1_.ID in (?, ?)" + ).variables(graphQLInActionId3, effectiveTypeScriptId3); + ctx.rows( + "[" + + "--->{" + + "--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + + "--->--->\"name\":\"GraphQL in Action\"," + + "--->--->\"edition\":3," + + "--->--->\"price\":80.00," + + "--->--->\"store\":{\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"}" + + "--->},{" + + "--->--->\"id\":\"9eded40f-6d2e-41de-b4e7-33a28b11c8b6\"," + + "--->--->\"name\":\"Effective TypeScript\"," + + "--->--->\"edition\":3," + + "--->--->\"price\":88.00," + + "--->--->\"store\":{\"id\":\"d38c10da-6be8-4924-b9b9-5e81899612a0\"}" + + "--->}" + + "]" + ); + }); + } + + @Test + public void testFindMapByIds() { + connectAndExpect( + con -> getSqlClient(con) + .getEntities() + .findMapByIds( + Book.class, + Arrays.asList( + graphQLInActionId3, + effectiveTypeScriptId3 + ) + ), + ctx -> { + ctx.sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION, tb_1_.PRICE, tb_1_.STORE_ID " + + "from BOOK as tb_1_ " + + "where tb_1_.ID in (?, ?)" + ).variables(graphQLInActionId3, effectiveTypeScriptId3); + ctx.rows( + "[" + + "--->{" + + "--->--->\"780bdf07-05af-48bf-9be9-f8c65236fecc\":{" + + "--->--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + + "--->--->--->\"name\":\"GraphQL in Action\"," + + "--->--->--->\"edition\":3," + + "--->--->--->\"price\":80.00," + + "--->--->--->\"store\":{\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"}" + + "--->--->}," + + "--->--->\"9eded40f-6d2e-41de-b4e7-33a28b11c8b6\":{" + + "--->--->--->\"id\":\"9eded40f-6d2e-41de-b4e7-33a28b11c8b6\"," + + "--->--->--->\"name\":\"Effective TypeScript\"," + + "--->--->--->\"edition\":3," + + "--->--->--->\"price\":88.00," + + "--->--->--->\"store\":{\"id\":\"d38c10da-6be8-4924-b9b9-5e81899612a0\"}" + + "--->--->}" + + "--->}" + + "]" + ); + }); + } + + @Test + public void testFindByFetcherId() { + connectAndExpect( + con -> getSqlClient(con) + .getEntities() + .findById( + BookFetcher.$.allScalarFields() + .store(BookStoreFetcher.$.allScalarFields()) + .authors(AuthorFetcher.$.allScalarFields()), + graphQLInActionId3 + ), + ctx -> { + ctx.sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION, tb_1_.PRICE, tb_1_.STORE_ID " + + "from BOOK as tb_1_ " + + "where tb_1_.ID = ?" + ).variables(graphQLInActionId3); + ctx.statement(1).sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.WEBSITE, tb_1_.VERSION " + + "from BOOK_STORE as tb_1_ " + + "where tb_1_.ID in (?)" + ).variables(manningId); + ctx.statement(2).sql( + "select tb_1_.BOOK_ID, " + + "tb_1_.AUTHOR_ID, tb_3_.FIRST_NAME, tb_3_.LAST_NAME, tb_3_.GENDER " + + "from BOOK_AUTHOR_MAPPING as tb_1_ " + + "inner join AUTHOR as tb_3_ " + + "on tb_1_.AUTHOR_ID = tb_3_.ID " + + "where tb_1_.BOOK_ID in (?)" + ).variables(graphQLInActionId3); + ctx.rows( + "[" + + "--->{" + + "--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + + "--->--->\"name\":\"GraphQL in Action\"," + + "--->--->\"edition\":3," + + "--->--->\"price\":80.00," + + "--->--->\"store\":{" + + "--->--->--->\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"," + + "--->--->--->\"name\":\"MANNING\"," + + "--->--->--->\"website\":null," + + "--->--->--->\"version\":0" + + "--->--->}," + + "--->--->\"authors\":[" + + "--->--->--->{" + + "--->--->--->--->\"id\":\"eb4963fd-5223-43e8-b06b-81e6172ee7ae\"," + + "--->--->--->--->\"firstName\":\"Samer\"," + + "--->--->--->--->\"lastName\":\"Buna\"," + + "--->--->--->--->\"gender\":\"MALE\"" + + "--->--->--->}" + + "--->--->]" + + "--->}" + + "]" + ); + }); + } + + @Test + public void testFindByFetcherIds() { + connectAndExpect( + con -> getSqlClient(con) + .getEntities() + .findByIds( + BookFetcher.$.allScalarFields() + .store(BookStoreFetcher.$.allScalarFields()) + .authors(AuthorFetcher.$.allScalarFields()), + Arrays.asList(graphQLInActionId3, effectiveTypeScriptId3) + ), + ctx -> { + ctx.sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION, tb_1_.PRICE, tb_1_.STORE_ID " + + "from BOOK as tb_1_ " + + "where tb_1_.ID in (?, ?)" + ).variables(graphQLInActionId3, effectiveTypeScriptId3); + ctx.statement(1).sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.WEBSITE, tb_1_.VERSION " + + "from BOOK_STORE as tb_1_ " + + "where tb_1_.ID in (?, ?)" + ).variables(manningId, oreillyId); + ctx.statement(2).sql( + "select tb_1_.BOOK_ID, " + + "tb_1_.AUTHOR_ID, tb_3_.FIRST_NAME, tb_3_.LAST_NAME, tb_3_.GENDER " + + "from BOOK_AUTHOR_MAPPING as tb_1_ " + + "inner join AUTHOR as tb_3_ " + + "on tb_1_.AUTHOR_ID = tb_3_.ID " + + "where tb_1_.BOOK_ID in (?, ?)" + ).variables(graphQLInActionId3, effectiveTypeScriptId3); + ctx.rows( + "[" + + "--->{" + + "--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + + "--->--->\"name\":\"GraphQL in Action\"," + + "--->--->\"edition\":3," + + "--->--->\"price\":80.00," + + "--->--->\"store\":{" + + "--->--->--->\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"," + + "--->--->--->\"name\":\"MANNING\"," + + "--->--->--->\"website\":null," + + "--->--->--->\"version\":0" + + "--->--->}," + + "--->--->\"authors\":[" + + "--->--->--->{" + + "--->--->--->--->\"id\":\"eb4963fd-5223-43e8-b06b-81e6172ee7ae\"," + + "--->--->--->--->\"firstName\":\"Samer\"," + + "--->--->--->--->\"lastName\":\"Buna\"," + + "--->--->--->--->\"gender\":\"MALE\"" + + "--->--->--->}" + + "--->--->]" + + "--->}," + + "--->{" + + "--->--->\"id\":\"9eded40f-6d2e-41de-b4e7-33a28b11c8b6\"," + + "--->--->\"name\":\"Effective TypeScript\"," + + "--->--->\"edition\":3," + + "--->--->\"price\":88.00," + + "--->--->\"store\":{" + + "--->--->--->\"id\":\"d38c10da-6be8-4924-b9b9-5e81899612a0\"," + + "--->--->--->\"name\":\"O'REILLY\"," + + "--->--->--->\"website\":null," + + "--->--->--->\"version\":0" + + "--->--->}," + + "--->--->\"authors\":[" + + "--->--->--->{" + + "--->--->--->--->\"id\":\"c14665c8-c689-4ac7-b8cc-6f065b8d835d\"," + + "--->--->--->--->\"firstName\":\"Dan\"," + + "--->--->--->--->\"lastName\":\"Vanderkam\"," + + "--->--->--->--->\"gender\":\"MALE\"" + + "--->--->--->}" + + "--->--->]" + + "--->}" + + "]" + ); + }); + } + + @Test + public void testFindMapByFetcherIds() { + connectAndExpect( + con -> getSqlClient(con) + .getEntities() + .findMapByIds( + BookFetcher.$.allScalarFields() + .store(BookStoreFetcher.$.allScalarFields()) + .authors(AuthorFetcher.$.allScalarFields()), + Arrays.asList(graphQLInActionId3, effectiveTypeScriptId3) + ), + ctx -> { + ctx.sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.EDITION, tb_1_.PRICE, tb_1_.STORE_ID " + + "from BOOK as tb_1_ " + + "where tb_1_.ID in (?, ?)" + ).variables(graphQLInActionId3, effectiveTypeScriptId3); + ctx.statement(1).sql( + "select tb_1_.ID, tb_1_.NAME, tb_1_.WEBSITE, tb_1_.VERSION " + + "from BOOK_STORE as tb_1_ " + + "where tb_1_.ID in (?, ?)" + ).variables(manningId, oreillyId); + ctx.statement(2).sql( + "select tb_1_.BOOK_ID, " + + "tb_1_.AUTHOR_ID, tb_3_.FIRST_NAME, tb_3_.LAST_NAME, tb_3_.GENDER " + + "from BOOK_AUTHOR_MAPPING as tb_1_ " + + "inner join AUTHOR as tb_3_ " + + "on tb_1_.AUTHOR_ID = tb_3_.ID " + + "where tb_1_.BOOK_ID in (?, ?)" + ).variables(graphQLInActionId3, effectiveTypeScriptId3); + ctx.rows( + "[" + + "--->{" + + "--->--->\"780bdf07-05af-48bf-9be9-f8c65236fecc\":{" + + "--->--->--->\"id\":\"780bdf07-05af-48bf-9be9-f8c65236fecc\"," + + "--->--->--->\"name\":\"GraphQL in Action\"," + + "--->--->--->\"edition\":3," + + "--->--->--->\"price\":80.00," + + "--->--->--->\"store\":{" + + "--->--->--->--->\"id\":\"2fa3955e-3e83-49b9-902e-0465c109c779\"," + + "--->--->--->--->\"name\":\"MANNING\"," + + "--->--->--->--->\"website\":null," + + "--->--->--->--->\"version\":0" + + "--->--->--->}," + + "--->--->--->\"authors\":[" + + "--->--->--->--->{" + + "--->--->--->--->--->\"id\":\"eb4963fd-5223-43e8-b06b-81e6172ee7ae\"," + + "--->--->--->--->--->\"firstName\":\"Samer\"," + + "--->--->--->--->--->\"lastName\":\"Buna\"," + + "--->--->--->--->--->\"gender\":\"MALE\"" + + "--->--->--->--->}" + + "--->--->--->]" + + "--->--->}," + + "--->--->\"9eded40f-6d2e-41de-b4e7-33a28b11c8b6\":{" + + "--->--->--->\"id\":\"9eded40f-6d2e-41de-b4e7-33a28b11c8b6\"," + + "--->--->--->\"name\":\"Effective TypeScript\"," + + "--->--->--->\"edition\":3," + + "--->--->--->\"price\":88.00," + + "--->--->--->\"store\":{" + + "--->--->--->--->\"id\":\"d38c10da-6be8-4924-b9b9-5e81899612a0\"," + + "--->--->--->--->\"name\":\"O'REILLY\"," + + "--->--->--->--->\"website\":null," + + "--->--->--->--->\"version\":0" + + "--->--->--->}," + + "--->--->--->\"authors\":[" + + "--->--->--->--->{" + + "--->--->--->--->--->\"id\":\"c14665c8-c689-4ac7-b8cc-6f065b8d835d\"," + + "--->--->--->--->--->\"firstName\":\"Dan\"," + + "--->--->--->--->--->\"lastName\":\"Vanderkam\"," + + "--->--->--->--->--->\"gender\":\"MALE\"" + + "--->--->--->--->}" + + "--->--->--->]" + + "--->--->}" + + "--->}" + + "]" + ); + }); + } + + private SqlClient getSqlClient(Connection con) { + return getSqlClient(builder -> { + builder.setConnectionManager(new ConnectionManager() { + @Override + public R execute(Function block) { + return block.apply(con); + } + }); + }); + } +} diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/InverseJoinTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/InverseJoinTest.java index 114a27c2c6..6d54903e5c 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/InverseJoinTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/InverseJoinTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test; import javax.persistence.criteria.JoinType; +import java.util.Arrays; public class InverseJoinTest extends AbstractQueryTest { @@ -69,7 +70,7 @@ public void testInverseHalfJoinOnInverseProp() { book .inverseJoin(AuthorTableEx.class, AuthorTableEx::books) .id() - .in(alexId, danId) + .in(Arrays.asList(alexId, danId)) ); return q.select(Expression.constant(1)); }), @@ -93,7 +94,7 @@ public void testInverseHalfJoinOnNormalProp() { author .inverseJoin(BookTableEx.class, BookTableEx::authors) .id() - .in(learningGraphQLId1, learningGraphQLId2) + .in(Arrays.asList(learningGraphQLId1, learningGraphQLId2)) ); return q.select(Expression.constant(1)); }), diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/JoinTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/JoinTest.java index 8df1fa82b3..81596ce31f 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/JoinTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/JoinTest.java @@ -8,6 +8,7 @@ import javax.persistence.criteria.JoinType; import java.math.BigDecimal; +import java.util.Arrays; public class JoinTest extends AbstractQueryTest { @@ -108,7 +109,7 @@ public void testUnnecessaryJoin() { executeAndExpect( getSqlClient().createQuery(BookTable.class, (q, book) -> { q.where( - book.store().id().in(oreillyId, manningId) + book.store().id().in(Arrays.asList(oreillyId, manningId)) ); return q.select(Expression.constant(1)); }), @@ -128,7 +129,7 @@ public void testHalfJoin() { q.where( book.join("authors") .id() - .in(alexId, borisId) + .in(Arrays.asList(alexId, borisId)) ); return q.select(Expression.constant(1)); }), @@ -152,7 +153,7 @@ public void testHalfInverseJoin() { author .join("books") .id() - .in(learningGraphQLId1, learningGraphQLId2) + .in(Arrays.asList(learningGraphQLId1, learningGraphQLId2)) ); return q.select(Expression.constant(1)); }), @@ -176,7 +177,7 @@ public void testOneToManyCannotBeOptimized() { store .join("books") .id() - .in(learningGraphQLId1, learningGraphQLId2) + .in(Arrays.asList(learningGraphQLId1, learningGraphQLId2)) ); return q.select(Expression.constant(1)); }), diff --git a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/SubQueryTest.java b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/SubQueryTest.java index 878e8632b5..18ea15b9fb 100644 --- a/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/SubQueryTest.java +++ b/project/jimmer-sql/src/test/java/org/babyfish/jimmer/sql/query/SubQueryTest.java @@ -8,6 +8,7 @@ import org.junit.jupiter.api.Test; import java.math.BigDecimal; +import java.util.Arrays; public class SubQueryTest extends AbstractQueryTest { @@ -204,7 +205,7 @@ public void testSubQueryWithAny() { q.where( book.id().eq( q.createSubQuery(AuthorTableEx.class, (sq, author) -> { - sq.where(author.firstName().in("Alex", "Bill")); + sq.where(author.firstName().in(Arrays.asList("Alex", "Bill"))); return sq.select(author.books().id()); }).any() ) @@ -234,7 +235,7 @@ public void testSubQueryWithAll() { q.where( book.id().eq( q.createSubQuery(AuthorTableEx.class, (sq, author) -> { - sq.where(author.firstName().in("Alex", "Bill")); + sq.where(author.firstName().in(Arrays.asList("Alex", "Bill"))); return sq.select(author.books().id()); }).all() )