From 316573fcbd4ab08481b1f688e48f5e5d8f05325a Mon Sep 17 00:00:00 2001 From: jthoreux Date: Thu, 25 Jul 2024 14:16:33 +0200 Subject: [PATCH] feat(null): upsert and onConflict. Fix bad syntax in queryParams For upserts Issues : - #3 Upsert does not really upsert - #8 add on_conflict for upsert --- .../querydsl/postgrest/PostgrestRestTemplate.java | 1 - .../querydsl/postgrest/PostgrestRepository.java | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/querydsl-postgrest-resttemplate-adapter/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRestTemplate.java b/querydsl-postgrest-resttemplate-adapter/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRestTemplate.java index 107342e..4a8dfb6 100644 --- a/querydsl-postgrest-resttemplate-adapter/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRestTemplate.java +++ b/querydsl-postgrest-resttemplate-adapter/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRestTemplate.java @@ -131,5 +131,4 @@ private URI getUri(String resource, Map> params) { return uriBuilder.build().encode().toUri(); } - } diff --git a/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRepository.java b/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRepository.java index f3c251c..592cbdc 100644 --- a/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRepository.java +++ b/querydsl-postgrest/src/main/java/fr/ouestfrance/querydsl/postgrest/PostgrestRepository.java @@ -133,11 +133,11 @@ public BulkResponse upsert(List values, BulkOptions options) { * @return map of query params for on conflict if annotation OnConflict is present otherwise empty map */ private Map> getUpsertQueryParams() { - return Optional.ofNullable(this.getClass().getAnnotation(OnConflict.class)) - .map(OnConflict::columnNames) - .map(Arrays::asList) - .map(onConflictList-> Map.of(ON_CONFLICT_QUERY_PARAMS, onConflictList)) - .orElse(Map.of()); + OnConflict onConflict = this.getClass().getAnnotation(OnConflict.class); + if (Objects.nonNull(onConflict)) { + return Map.of(ON_CONFLICT_QUERY_PARAMS, List.of(String.join(",", onConflict.columnNames()))); + } + return Collections.emptyMap(); } /**