You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@causeway.apache.org by ah...@apache.org on 2025/03/20 09:41:43 UTC
(causeway) branch main updated: CAUSEWAY-3873: adds JavaNetURLConverter (auto applied)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/causeway.git
The following commit(s) were added to refs/heads/main by this push:
new 3a7afe7d63f CAUSEWAY-3873: adds JavaNetURLConverter (auto applied)
3a7afe7d63f is described below
commit 3a7afe7d63fcd5d832ef174ec0f39c8616d78eb2
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Mar 20 10:41:38 2025 +0100
CAUSEWAY-3873: adds JavaNetURLConverter (auto applied)
---
.../jpa/applib/types/BlobJpaEmbeddable.java | 6 +--
.../jpa/applib/types/ClobJpaEmbeddable.java | 6 +--
.../CausewayModulePersistenceJpaIntegration.java | 2 +
.../java/net/JavaNetURLConverter.java | 55 ++++++++++++++++++++++
4 files changed, 63 insertions(+), 6 deletions(-)
diff --git a/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/BlobJpaEmbeddable.java b/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/BlobJpaEmbeddable.java
index bc385dc0488..be4b335e9a3 100644
--- a/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/BlobJpaEmbeddable.java
+++ b/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/BlobJpaEmbeddable.java
@@ -88,9 +88,9 @@ public static BlobJpaEmbeddable fromBlob(final Blob blob) {
return null;
}
var blobJpaEmbeddable = new BlobJpaEmbeddable();
- blobJpaEmbeddable.bytes = blob.getBytes();
- blobJpaEmbeddable.mimeType = blob.getMimeType().toString();
- blobJpaEmbeddable.name = blob.getName();
+ blobJpaEmbeddable.bytes = blob.bytes();
+ blobJpaEmbeddable.mimeType = blob.mimeType().toString();
+ blobJpaEmbeddable.name = blob.name();
return blobJpaEmbeddable;
}
diff --git a/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/ClobJpaEmbeddable.java b/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/ClobJpaEmbeddable.java
index f9032b83f3a..cc45cccebac 100644
--- a/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/ClobJpaEmbeddable.java
+++ b/persistence/jpa/applib/src/main/java/org/apache/causeway/persistence/jpa/applib/types/ClobJpaEmbeddable.java
@@ -88,9 +88,9 @@ public static ClobJpaEmbeddable fromClob(final Clob clob) {
return null;
}
var clobJpaEmbeddable = new ClobJpaEmbeddable();
- clobJpaEmbeddable.chars = clob.getChars().toString();
- clobJpaEmbeddable.mimeType = clob.getMimeType().toString();
- clobJpaEmbeddable.name = clob.getName();
+ clobJpaEmbeddable.chars = clob.chars().toString();
+ clobJpaEmbeddable.mimeType = clob.mimeType().toString();
+ clobJpaEmbeddable.name = clob.name();
return clobJpaEmbeddable;
}
diff --git a/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java b/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java
index 64992220cae..17515670dd7 100644
--- a/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java
+++ b/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/CausewayModulePersistenceJpaIntegration.java
@@ -31,6 +31,7 @@
import org.apache.causeway.persistence.jpa.integration.typeconverters.applib.CausewayMarkupConverter;
import org.apache.causeway.persistence.jpa.integration.typeconverters.applib.CausewayPasswordConverter;
import org.apache.causeway.persistence.jpa.integration.typeconverters.java.awt.JavaAwtBufferedImageByteArrayConverter;
+import org.apache.causeway.persistence.jpa.integration.typeconverters.java.net.JavaNetURLConverter;
import org.apache.causeway.persistence.jpa.integration.typeconverters.java.time.OffsetDateTimeConverterForJpa;
import org.apache.causeway.persistence.jpa.integration.typeconverters.java.time.OffsetTimeConverterForJpa;
import org.apache.causeway.persistence.jpa.integration.typeconverters.java.time.ZonedDateTimeConverterForJpa;
@@ -68,6 +69,7 @@
CausewayInteractionDtoConverter.class,
CausewayOidDtoConverter.class,
JavaAwtBufferedImageByteArrayConverter.class,
+ JavaNetURLConverter.class,
JavaUtilLocaleConverter.class,
JavaUtilUuidConverter.class,
OffsetTimeConverterForJpa.class,
diff --git a/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/typeconverters/java/net/JavaNetURLConverter.java b/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/typeconverters/java/net/JavaNetURLConverter.java
new file mode 100644
index 00000000000..f74703b8862
--- /dev/null
+++ b/persistence/jpa/integration/src/main/java/org/apache/causeway/persistence/jpa/integration/typeconverters/java/net/JavaNetURLConverter.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.causeway.persistence.jpa.integration.typeconverters.java.net;
+
+import java.io.Serializable;
+import java.net.MalformedURLException;
+import java.net.URL;
+import jakarta.persistence.AttributeConverter;
+import jakarta.persistence.Converter;
+
+/**
+ * Maps an {@link URL} to a simple String column in the corresponding database table.
+ * <p>
+ * Without this conversion, JPA maps {@link Serializable} types to a byte array.
+ * @since 3.3 {@index}
+ */
+@Converter(autoApply = true)
+public class JavaNetURLConverter
+implements AttributeConverter<URL, String> {
+
+ @Override
+ public String convertToDatabaseColumn(final URL uuid) {
+ return uuid != null
+ ? uuid.toString()
+ : null;
+ }
+
+ @Override
+ public URL convertToEntityAttribute(final String datastoreValue) {
+ try {
+ return (datastoreValue != null)
+ ? new URL(datastoreValue)
+ : null;
+ } catch (MalformedURLException e) {
+ throw new IllegalArgumentException("Invalid URL format in database: " + datastoreValue, e);
+ }
+ }
+
+}