From 9b8d2312848b2016f0e495a0128d2c2e723cc6c7 Mon Sep 17 00:00:00 2001
From: Michael Hoennig
Date: Tue, 2 Apr 2024 13:23:18 +0200
Subject: [PATCH] fixing issues from code-review
---
build.gradle | 1 -
.../hsadminng/mapper/PostgresArray.java | 58 -------------------
2 files changed, 59 deletions(-)
delete mode 100644 src/main/java/net/hostsharing/hsadminng/mapper/PostgresArray.java
diff --git a/build.gradle b/build.gradle
index a11d9493..88c59050 100644
--- a/build.gradle
+++ b/build.gradle
@@ -62,7 +62,6 @@ dependencies {
implementation 'org.springdoc:springdoc-openapi:2.4.0'
implementation 'org.postgresql:postgresql:42.7.3'
implementation 'org.liquibase:liquibase-core:4.27.0'
- //implementation 'com.vladmihalcea:hibernate-types-60:2.21.1'
implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.7.3'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.0'
implementation 'org.openapitools:jackson-databind-nullable:0.2.6'
diff --git a/src/main/java/net/hostsharing/hsadminng/mapper/PostgresArray.java b/src/main/java/net/hostsharing/hsadminng/mapper/PostgresArray.java
deleted file mode 100644
index e1e1d056..00000000
--- a/src/main/java/net/hostsharing/hsadminng/mapper/PostgresArray.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package net.hostsharing.hsadminng.mapper;
-
-import lombok.experimental.UtilityClass;
-import org.postgresql.util.PGtokenizer;
-
-import java.lang.reflect.Array;
-import java.nio.charset.StandardCharsets;
-import java.util.function.Function;
-
-@UtilityClass
-public class PostgresArray {
-
- /**
- * Converts a byte[], as returned for a Postgres-array by native queries, to a Java array.
- *
- * This example code worked with Hibernate 5 (Spring Boot 3.0.x):
- *
- * return (UUID[]) em.createNativeQuery("select currentSubjectsUuids() as uuids", UUID[].class).getSingleResult();
- *
- *
- *
- * With Hibernate 6 (Spring Boot 3.1.x), this utility method can be used like such:
- *
- * final byte[] result = (byte[]) em.createNativeQuery("select * from currentSubjectsUuids() as uuids", UUID[].class)
- * .getSingleResult();
- * return fromPostgresArray(result, UUID.class, UUID::fromString);
- *
- *
- *
- * @param pgArray the byte[] returned by a native query containing as rendered for a Postgres array
- * @param elementClass the class of a single element of the Java array to be returned
- * @param itemParser converts a string element to the specified elementClass
- * @return a Java array containing the data from pgArray
- * @param type of a single element of the Java array
- */
- public static T[] fromPostgresArray(final byte[] pgArray, final Class elementClass, final Function itemParser) {
- final var pgArrayLiteral = new String(pgArray, StandardCharsets.UTF_8);
- if (pgArrayLiteral.length() == 2) {
- return newGenericArray(elementClass, 0);
- }
- final PGtokenizer tokenizer = new PGtokenizer(pgArrayLiteral.substring(1, pgArrayLiteral.length()-1), ',');
- tokenizer.remove("\"", "\"");
- final T[] array = newGenericArray(elementClass, tokenizer.getSize()); // Create a new array of the specified type and length
- for ( int n = 0; n < tokenizer.getSize(); ++n ) {
- final String token = tokenizer.getToken(n);
- if ( !"NULL".equals(token) ) {
- array[n] = itemParser.apply(token.trim().replace("\\\"", "\""));
- }
- }
- return array;
- }
-
- @SuppressWarnings("unchecked")
- private static T[] newGenericArray(final Class elementClass, final int length) {
- return (T[]) Array.newInstance(elementClass, length);
- }
-
-}