@@ -77,8 +77,6 @@ class PartTreeR2dbcQueryUnitTests {
77
77
".age" , ".active" };
78
78
private static final String [] ALL_FIELDS_ARRAY_PREFIXED = Arrays .stream (ALL_FIELDS_ARRAY ).map (f -> TABLE + f )
79
79
.toArray (String []::new );
80
- private static final String ALL_FIELDS = String .join (", " , ALL_FIELDS_ARRAY_PREFIXED );
81
- private static final String DISTINCT = "DISTINCT" ;
82
80
83
81
@ Mock ConnectionFactory connectionFactory ;
84
82
@ Mock R2dbcConverter r2dbcConverter ;
@@ -698,6 +696,32 @@ void createsQueryForCountProjection() throws Exception {
698
696
.where (TABLE + ".first_name = $1" );
699
697
}
700
698
699
+ @ Test // GH-773
700
+ void createsQueryWithoutIdForCountProjection () throws Exception {
701
+
702
+ R2dbcQueryMethod queryMethod = getQueryMethod (WithoutIdRepository .class , "countByFirstName" , String .class );
703
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , operations , r2dbcConverter , dataAccessStrategy );
704
+ PreparedOperation <?> query = createQuery (queryMethod , r2dbcQuery , "John" );
705
+
706
+ PreparedOperationAssert .assertThat (query ) //
707
+ .selects ("COUNT(1)" ) //
708
+ .from (TABLE ) //
709
+ .where (TABLE + ".first_name = $1" );
710
+ }
711
+
712
+ @ Test // GH-773
713
+ void createsQueryWithoutIdForExistsProjection () throws Exception {
714
+
715
+ R2dbcQueryMethod queryMethod = getQueryMethod (WithoutIdRepository .class , "existsByFirstName" , String .class );
716
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , operations , r2dbcConverter , dataAccessStrategy );
717
+ PreparedOperation <?> query = createQuery (queryMethod , r2dbcQuery , "John" );
718
+
719
+ PreparedOperationAssert .assertThat (query ) //
720
+ .selects ("1" ) //
721
+ .from (TABLE ) //
722
+ .where (TABLE + ".first_name = $1 LIMIT 1" );
723
+ }
724
+
701
725
private PreparedOperation <?> createQuery (R2dbcQueryMethod queryMethod , PartTreeR2dbcQuery r2dbcQuery ,
702
726
Object ... parameters ) {
703
727
return createQuery (r2dbcQuery , getAccessor (queryMethod , parameters ));
@@ -709,8 +733,13 @@ private PreparedOperation<?> createQuery(PartTreeR2dbcQuery r2dbcQuery,
709
733
}
710
734
711
735
private R2dbcQueryMethod getQueryMethod (String methodName , Class <?>... parameterTypes ) throws Exception {
712
- Method method = UserRepository .class .getMethod (methodName , parameterTypes );
713
- return new R2dbcQueryMethod (method , new DefaultRepositoryMetadata (UserRepository .class ),
736
+ return getQueryMethod (UserRepository .class , methodName , parameterTypes );
737
+ }
738
+
739
+ private R2dbcQueryMethod getQueryMethod (Class <?> repository , String methodName , Class <?>... parameterTypes )
740
+ throws Exception {
741
+ Method method = repository .getMethod (methodName , parameterTypes );
742
+ return new R2dbcQueryMethod (method , new DefaultRepositoryMetadata (repository ),
714
743
new SpelAwareProxyProjectionFactory (), mappingContext );
715
744
}
716
745
@@ -887,6 +916,13 @@ interface UserRepository extends Repository<User, Long> {
887
916
Mono <Long > countByFirstName (String firstName );
888
917
}
889
918
919
+ interface WithoutIdRepository extends Repository <WithoutId , Long > {
920
+
921
+ Mono <Boolean > existsByFirstName (String firstName );
922
+
923
+ Mono <Long > countByFirstName (String firstName );
924
+ }
925
+
890
926
@ Table ("users" )
891
927
@ Data
892
928
private static class User {
@@ -899,6 +935,13 @@ private static class User {
899
935
private Boolean active ;
900
936
}
901
937
938
+ @ Table ("users" )
939
+ @ Data
940
+ private static class WithoutId {
941
+
942
+ private String firstName ;
943
+ }
944
+
902
945
interface UserProjection {
903
946
904
947
String getFirstName ();
0 commit comments