@@ -515,6 +515,30 @@ public void throwsExceptionWhenInvalidNumberOfParameterIsGiven() throws Exceptio
515
515
r2dbcQuery .createQuery (getAccessor (queryMethod , new Object [0 ]));
516
516
}
517
517
518
+ @ Test
519
+ public void createsQueryWithLimitToFindEntitiesByStringAttribute () throws Exception {
520
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findTop3ByFirstName" , String .class );
521
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
522
+ dataAccessStrategy );
523
+ RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] { "John" });
524
+ BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
525
+ String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE
526
+ + " WHERE " + TABLE + ".first_name = :firstName LIMIT 3" ;
527
+ assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
528
+ }
529
+
530
+ @ Test
531
+ public void createsQueryToFindFirstEntityByStringAttribute () throws Exception {
532
+ R2dbcQueryMethod queryMethod = getQueryMethod ("findFirstByFirstName" , String .class );
533
+ PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery (queryMethod , databaseClient , r2dbcConverter ,
534
+ dataAccessStrategy );
535
+ RelationalParametersParameterAccessor accessor = getAccessor (queryMethod , new Object [] { "John" });
536
+ BindableQuery bindableQuery = r2dbcQuery .createQuery (accessor );
537
+ String expectedSql = "SELECT " + ALL_FIELDS + " FROM " + TABLE
538
+ + " WHERE " + TABLE + ".first_name = :firstName LIMIT 1" ;
539
+ assertThat (bindableQuery .get ()).isEqualTo (expectedSql );
540
+ }
541
+
518
542
private R2dbcQueryMethod getQueryMethod (String methodName , Class <?>... parameterTypes ) throws Exception {
519
543
Method method = UserRepository .class .getMethod (methodName , parameterTypes );
520
544
return new R2dbcQueryMethod (method , new DefaultRepositoryMetadata (UserRepository .class ),
@@ -587,6 +611,10 @@ private interface UserRepository extends Repository<User, Long> {
587
611
Flux <User > findAllById (Collection <Long > ids );
588
612
589
613
Flux <User > findAllByIdIsEmpty ();
614
+
615
+ Flux <User > findTop3ByFirstName (String firstName );
616
+
617
+ Mono <User > findFirstByFirstName (String firstName );
590
618
}
591
619
592
620
@ Table ("users" )
0 commit comments