Skip to content

Commit 513988e

Browse files
committed
Fix data-processor tests
1 parent 34835eb commit 513988e

File tree

9 files changed

+49
-39
lines changed

9 files changed

+49
-39
lines changed

Diff for: data-model/src/main/java/io/micronaut/data/model/query/builder/AbstractSqlLikeQueryBuilder.java

+12
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import java.util.StringJoiner;
6767
import java.util.concurrent.atomic.AtomicInteger;
6868
import java.util.function.BiConsumer;
69+
import java.util.function.Predicate;
6970
import java.util.regex.Matcher;
7071
import java.util.stream.Collectors;
7172

@@ -2127,6 +2128,17 @@ protected void traversePersistentProperties(PersistentEntity persistentEntity, B
21272128
PersistentEntityUtils.traversePersistentProperties(persistentEntity, consumer);
21282129
}
21292130

2131+
/**
2132+
* Traverses persistent properties.
2133+
*
2134+
* @param persistentEntity The persistent entity
2135+
* @param skipAssociationPredicate Logic for skipping association while traversin properties
2136+
* @param consumer The function to invoke on every property
2137+
*/
2138+
protected void traversePersistentProperties(PersistentEntity persistentEntity, Predicate<Association> skipAssociationPredicate, BiConsumer<List<Association>, PersistentProperty> consumer) {
2139+
PersistentEntityUtils.traversePersistentProperties(persistentEntity, skipAssociationPredicate, consumer);
2140+
}
2141+
21302142
/**
21312143
* Traverses persistent properties.
21322144
*

Diff for: data-model/src/main/java/io/micronaut/data/model/query/builder/sql/SqlQueryBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ public void selectAllColumns(AnnotationMetadata annotationMetadata, PersistentEn
892892
boolean escape = shouldEscape(entity);
893893
NamingStrategy namingStrategy = getNamingStrategy(entity);
894894
int length = sb.length();
895-
traversePersistentProperties(entity, (associations, property)
895+
traversePersistentProperties(entity, Association::isSingleEnded, (associations, property)
896896
-> appendProperty(sb, associations, property, namingStrategy, alias, escape));
897897
int newLength = sb.length();
898898
if (newLength == length) {

Diff for: data-processor/src/test/groovy/io/micronaut/data/model/jpa/criteria/CriteriaSpec.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class CriteriaSpec extends AbstractCriteriaSpec {
9292
String query = getSqlQuery(criteriaQuery)
9393

9494
expect:
95-
query == '''SELECT book_."id",book_."author_id",book_."title",book_."total_pages",book_."last_updated" FROM "book" book_ WHERE (book_."id" IN (SELECT book_book_."id" FROM "book" book_book_ WHERE (book_book_."id" = 123)))'''
95+
query == '''SELECT book_."id",book_."title",book_."total_pages",book_."last_updated" FROM "book" book_ WHERE (book_."id" IN (SELECT book_book_."id" FROM "book" book_book_ WHERE (book_book_."id" = 123)))'''
9696
}
9797

9898
void "test subquery EQ"() {
@@ -110,7 +110,7 @@ class CriteriaSpec extends AbstractCriteriaSpec {
110110
String query = getSqlQuery(criteriaQuery)
111111

112112
expect:
113-
query == '''SELECT book_."id",book_."author_id",book_."title",book_."total_pages",book_."last_updated" FROM "book" book_ WHERE (book_."id" = (SELECT book_book_."id" FROM "book" book_book_ WHERE (book_book_."id" = 123)))'''
113+
query == '''SELECT book_."id",book_."title",book_."total_pages",book_."last_updated" FROM "book" book_ WHERE (book_."id" = (SELECT book_book_."id" FROM "book" book_book_ WHERE (book_book_."id" = 123)))'''
114114
}
115115

116116
void "test function projection 3"() {

Diff for: data-processor/src/test/groovy/io/micronaut/data/model/query/builder/SqlQueryBuilderSpec.groovy

+5-7
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ interface MyRepository {
227227
def encoded = encoder.buildQuery(AnnotationMetadata.EMPTY_METADATA, q)
228228

229229
expect:
230-
encoded.query == 'SELECT book_.`id`,book_.`author_id`,book_.`genre_id`,book_.`title`,book_.`total_pages`,book_.`publisher_id`,book_.`last_updated`,book_author_.`name` AS author_name,book_author_.`nick_name` AS author_nick_name FROM `book` book_ INNER JOIN `author` book_author_ ON book_.`author_id`=book_author_.`id` WHERE (book_.`id` = ?)'
230+
encoded.query == 'SELECT book_.`id`,book_.`title`,book_.`total_pages`,book_.`last_updated`,book_author_.`name` AS author_name,book_author_.`nick_name` AS author_nick_name FROM `book` book_ INNER JOIN `author` book_author_ ON book_.`author_id`=book_author_.`id` WHERE (book_.`id` = ?)'
231231

232232
}
233233

@@ -242,7 +242,7 @@ interface MyRepository {
242242
def encoded = encoder.buildQuery(AnnotationMetadata.EMPTY_METADATA, q)
243243

244244
expect:
245-
encoded.query == 'SELECT book_.`id`,book_.`author_id`,book_.`genre_id`,book_.`title`,book_.`total_pages`,book_.`publisher_id`,book_.`last_updated`,book_genre_.`genre_name` AS genre_genre_name,book_author_.`name` AS author_name,book_author_.`nick_name` AS author_nick_name FROM `book` book_ LEFT JOIN `genre` book_genre_ ON book_.`genre_id`=book_genre_.`id` INNER JOIN `author` book_author_ ON book_.`author_id`=book_author_.`id` WHERE (book_.`id` = ?)'
245+
encoded.query == 'SELECT book_.`id`,book_.`title`,book_.`total_pages`,book_.`last_updated`,book_genre_.`genre_name` AS genre_genre_name,book_author_.`name` AS author_name,book_author_.`nick_name` AS author_nick_name FROM `book` book_ LEFT JOIN `genre` book_genre_ ON book_.`genre_id`=book_genre_.`id` INNER JOIN `author` book_author_ ON book_.`author_id`=book_author_.`id` WHERE (book_.`id` = ?)'
246246

247247
}
248248

@@ -257,11 +257,9 @@ interface MyRepository {
257257
def encoded = encoder.buildQuery(AnnotationMetadata.EMPTY_METADATA, q)
258258

259259
expect:
260-
encoded.query == 'SELECT book_."id",book_."author_id",book_."genre_id",book_."title",book_."total_pages",book_."publisher_id",book_."last_updated",book_genre_."genre_name" AS genre_genre_name FROM "book" book_ FULL OUTER JOIN "genre" book_genre_ ON book_."genre_id"=book_genre_."id" FULL OUTER JOIN "author" book_author_ ON book_."author_id"=book_author_."id" WHERE (book_."id" = ?)'
261-
260+
encoded.query == 'SELECT book_."id",book_."title",book_."total_pages",book_."last_updated",book_genre_."genre_name" AS genre_genre_name FROM "book" book_ FULL OUTER JOIN "genre" book_genre_ ON book_."genre_id"=book_genre_."id" FULL OUTER JOIN "author" book_author_ ON book_."author_id"=book_author_."id" WHERE (book_."id" = ?)'
262261
}
263262

264-
265263
void "test encode to-one join - unsupported outer join throws exception for H2 Dialect"() {
266264
given:
267265
PersistentEntity entity = PersistentEntity.of(Book)
@@ -567,9 +565,9 @@ interface MyRepository {
567565
'SELECT shipment_."sp_country",shipment_."sp_city",shipment_."field" FROM "Shipment1" shipment_ WHERE (shipment_."sp_country" = ?)',
568566
'SELECT user_role_."id_user_id",user_role_."id_role_id" FROM "user_role_composite" user_role_ INNER JOIN "role_composite" user_role_id_role_ ON user_role_."id_role_id"=user_role_id_role_."id"',
569567
'SELECT user_role_."id_user_id",user_role_."id_role_id" FROM "user_role_composite" user_role_ INNER JOIN "user_composite" user_role_id_user_ ON user_role_."id_user_id"=user_role_id_user_."id" WHERE (user_role_."id_user_id" = ?)',
570-
'SELECT uidx."uuid",uidx."name",uidx."child_id",uidx."xyz",uidx."embedded_child_embedded_child2_id",uidx."nullable_value" FROM "uuid_entity" uidx WHERE (uidx."uuid" = ?)',
568+
'SELECT uidx."uuid",uidx."name",uidx."xyz",uidx."embedded_child_embedded_child2_id",uidx."nullable_value" FROM "uuid_entity" uidx WHERE (uidx."uuid" = ?)',
571569
'SELECT user_role_."id_user_id",user_role_."id_role_id" FROM "user_role_composite" user_role_ WHERE (user_role_."id_user_id" = ? AND user_role_."id_role_id" = ?)',
572-
'SELECT challenge_."id",challenge_."token",challenge_."authentication_id",challenge_authentication_device_."NAME" AS authentication_device_NAME,challenge_authentication_device_."USER_ID" AS authentication_device_USER_ID,challenge_authentication_device_user_."NAME" AS authentication_device_user_NAME,challenge_authentication_."DESCRIPTION" AS authentication_DESCRIPTION,challenge_authentication_."DEVICE_ID" AS authentication_DEVICE_ID FROM "challenge" challenge_ INNER JOIN "AUTHENTICATION" challenge_authentication_ ON challenge_."authentication_id"=challenge_authentication_."ID" INNER JOIN "DEVICE" challenge_authentication_device_ ON challenge_authentication_."DEVICE_ID"=challenge_authentication_device_."ID" INNER JOIN "USER" challenge_authentication_device_user_ ON challenge_authentication_device_."USER_ID"=challenge_authentication_device_user_."ID" WHERE (challenge_."id" = ?)',
570+
'SELECT challenge_."id",challenge_."token",challenge_authentication_device_."NAME" AS authentication_device_NAME,challenge_authentication_device_."USER_ID" AS authentication_device_USER_ID,challenge_authentication_device_user_."NAME" AS authentication_device_user_NAME,challenge_authentication_."DESCRIPTION" AS authentication_DESCRIPTION,challenge_authentication_."DEVICE_ID" AS authentication_DEVICE_ID FROM "challenge" challenge_ INNER JOIN "AUTHENTICATION" challenge_authentication_ ON challenge_."authentication_id"=challenge_authentication_."ID" INNER JOIN "DEVICE" challenge_authentication_device_ ON challenge_authentication_."DEVICE_ID"=challenge_authentication_device_."ID" INNER JOIN "USER" challenge_authentication_device_user_ ON challenge_authentication_device_."USER_ID"=challenge_authentication_device_user_."ID" WHERE (challenge_."id" = ?)',
573571
'SELECT user_role_id_role_."id",user_role_id_role_."name" FROM "user_role_composite" user_role_ INNER JOIN "role_composite" user_role_id_role_ ON user_role_."id_role_id"=user_role_id_role_."id" WHERE (user_role_."id_user_id" = ?)',
574572
'SELECT meal_."mid",meal_."current_blood_glucose",meal_."created_on",meal_."updated_on",meal_."actual",meal_foods_."fid" AS foods_fid,meal_foods_."key" AS foods_key,meal_foods_."carbohydrates" AS foods_carbohydrates,meal_foods_."portion_grams" AS foods_portion_grams,meal_foods_."created_on" AS foods_created_on,meal_foods_."updated_on" AS foods_updated_on,meal_foods_."fk_meal_id" AS foods_fk_meal_id,meal_foods_."fk_alt_meal" AS foods_fk_alt_meal,meal_foods_."loooooooooooooooooooooooooooooooooooooooooooooooooooooooong_name" AS ln,meal_foods_."fresh" AS foods_fresh FROM "meal" meal_ INNER JOIN "food" meal_foods_ ON meal_."mid"=meal_foods_."fk_meal_id" AND meal_foods_.fresh = \'Y\' WHERE (meal_."mid" = ? AND (meal_.actual = \'Y\'))'
575573
]

Diff for: data-processor/src/test/groovy/io/micronaut/data/processor/sql/BuildDeleteSpec.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ interface BookRepository extends GenericRepository<Book, Long> {
224224
when:
225225
def deleteReturningCustomMethod = repository.findPossibleMethods("deleteReturning").findFirst().get()
226226
then:
227-
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("id" = ?) RETURNING "id","author_id","genre_id","title","total_pages","publisher_id","last_updated"'
227+
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("id" = ?) RETURNING "id","title","total_pages","last_updated"'
228228
getDataResultType(deleteReturningCustomMethod) == "io.micronaut.data.tck.entities.Book"
229229
getParameterPropertyPaths(deleteReturningCustomMethod) == ["id"] as String[]
230230
getDataInterceptor(deleteReturningCustomMethod) == "io.micronaut.data.intercept.DeleteOneInterceptor"
@@ -338,7 +338,7 @@ interface BookRepository extends GenericRepository<Book, Long> {
338338
when:
339339
def deleteReturningCustomMethod = repository.findPossibleMethods("deleteReturning").findFirst().get()
340340
then:
341-
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("author_id" = ?) RETURNING "id","author_id","genre_id","title","total_pages","publisher_id","last_updated"'
341+
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("author_id" = ?) RETURNING "id","title","total_pages","last_updated"'
342342
getParameterPropertyPaths(deleteReturningCustomMethod) == ["author.id"] as String[]
343343
getDataResultType(deleteReturningCustomMethod) == "io.micronaut.data.tck.entities.Book"
344344
getDataInterceptor(deleteReturningCustomMethod) == "io.micronaut.data.intercept.DeleteReturningManyInterceptor"
@@ -364,7 +364,7 @@ interface BookRepository extends GenericRepository<Book, Long> {
364364
when:
365365
def deleteReturningMethod = repository.findPossibleMethods("deleteReturning").findFirst().get()
366366
then:
367-
getQuery(deleteReturningMethod) == 'DELETE FROM "book" WHERE ("id" IN (?)) RETURNING "id","author_id","genre_id","title","total_pages","publisher_id","last_updated"'
367+
getQuery(deleteReturningMethod) == 'DELETE FROM "book" WHERE ("id" IN (?)) RETURNING "id","title","total_pages","last_updated"'
368368
getParameterPropertyPaths(deleteReturningMethod) == ["id"] as String[]
369369
getDataResultType(deleteReturningMethod) == "io.micronaut.data.tck.entities.Book"
370370
getDataInterceptor(deleteReturningMethod) == "io.micronaut.data.intercept.DeleteAllReturningInterceptor"

0 commit comments

Comments
 (0)