Skip to content

Commit

Permalink
Fix data-processor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
radovanradic committed Feb 27, 2025
1 parent 34835eb commit 513988e
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
import java.util.regex.Matcher;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -2127,6 +2128,17 @@ protected void traversePersistentProperties(PersistentEntity persistentEntity, B
PersistentEntityUtils.traversePersistentProperties(persistentEntity, consumer);
}

/**
* Traverses persistent properties.
*
* @param persistentEntity The persistent entity
* @param skipAssociationPredicate Logic for skipping association while traversin properties
* @param consumer The function to invoke on every property
*/
protected void traversePersistentProperties(PersistentEntity persistentEntity, Predicate<Association> skipAssociationPredicate, BiConsumer<List<Association>, PersistentProperty> consumer) {
PersistentEntityUtils.traversePersistentProperties(persistentEntity, skipAssociationPredicate, consumer);
}

/**
* Traverses persistent properties.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public void selectAllColumns(AnnotationMetadata annotationMetadata, PersistentEn
boolean escape = shouldEscape(entity);
NamingStrategy namingStrategy = getNamingStrategy(entity);
int length = sb.length();
traversePersistentProperties(entity, (associations, property)
traversePersistentProperties(entity, Association::isSingleEnded, (associations, property)
-> appendProperty(sb, associations, property, namingStrategy, alias, escape));
int newLength = sb.length();
if (newLength == length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CriteriaSpec extends AbstractCriteriaSpec {
String query = getSqlQuery(criteriaQuery)

expect:
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)))'''
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)))'''
}

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

expect:
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)))'''
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)))'''
}

void "test function projection 3"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ interface MyRepository {
def encoded = encoder.buildQuery(AnnotationMetadata.EMPTY_METADATA, q)

expect:
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` = ?)'
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` = ?)'

}

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

expect:
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` = ?)'
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` = ?)'

}

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

expect:
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" = ?)'

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" = ?)'
}


void "test encode to-one join - unsupported outer join throws exception for H2 Dialect"() {
given:
PersistentEntity entity = PersistentEntity.of(Book)
Expand Down Expand Up @@ -567,9 +565,9 @@ interface MyRepository {
'SELECT shipment_."sp_country",shipment_."sp_city",shipment_."field" FROM "Shipment1" shipment_ WHERE (shipment_."sp_country" = ?)',
'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"',
'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" = ?)',
'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" = ?)',
'SELECT uidx."uuid",uidx."name",uidx."xyz",uidx."embedded_child_embedded_child2_id",uidx."nullable_value" FROM "uuid_entity" uidx WHERE (uidx."uuid" = ?)',
'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" = ?)',
'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" = ?)',
'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" = ?)',
'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" = ?)',
'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\'))'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ interface BookRepository extends GenericRepository<Book, Long> {
when:
def deleteReturningCustomMethod = repository.findPossibleMethods("deleteReturning").findFirst().get()
then:
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("id" = ?) RETURNING "id","author_id","genre_id","title","total_pages","publisher_id","last_updated"'
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("id" = ?) RETURNING "id","title","total_pages","last_updated"'
getDataResultType(deleteReturningCustomMethod) == "io.micronaut.data.tck.entities.Book"
getParameterPropertyPaths(deleteReturningCustomMethod) == ["id"] as String[]
getDataInterceptor(deleteReturningCustomMethod) == "io.micronaut.data.intercept.DeleteOneInterceptor"
Expand Down Expand Up @@ -338,7 +338,7 @@ interface BookRepository extends GenericRepository<Book, Long> {
when:
def deleteReturningCustomMethod = repository.findPossibleMethods("deleteReturning").findFirst().get()
then:
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("author_id" = ?) RETURNING "id","author_id","genre_id","title","total_pages","publisher_id","last_updated"'
getQuery(deleteReturningCustomMethod) == 'DELETE FROM "book" WHERE ("author_id" = ?) RETURNING "id","title","total_pages","last_updated"'
getParameterPropertyPaths(deleteReturningCustomMethod) == ["author.id"] as String[]
getDataResultType(deleteReturningCustomMethod) == "io.micronaut.data.tck.entities.Book"
getDataInterceptor(deleteReturningCustomMethod) == "io.micronaut.data.intercept.DeleteReturningManyInterceptor"
Expand All @@ -364,7 +364,7 @@ interface BookRepository extends GenericRepository<Book, Long> {
when:
def deleteReturningMethod = repository.findPossibleMethods("deleteReturning").findFirst().get()
then:
getQuery(deleteReturningMethod) == 'DELETE FROM "book" WHERE ("id" IN (?)) RETURNING "id","author_id","genre_id","title","total_pages","publisher_id","last_updated"'
getQuery(deleteReturningMethod) == 'DELETE FROM "book" WHERE ("id" IN (?)) RETURNING "id","title","total_pages","last_updated"'
getParameterPropertyPaths(deleteReturningMethod) == ["id"] as String[]
getDataResultType(deleteReturningMethod) == "io.micronaut.data.tck.entities.Book"
getDataInterceptor(deleteReturningMethod) == "io.micronaut.data.intercept.DeleteAllReturningInterceptor"
Expand Down
Loading

0 comments on commit 513988e

Please sign in to comment.