-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from ivoa/attrmaxgt1-27
publishing 0.5.7
- Loading branch information
Showing
27 changed files
with
814 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
runtime/java/src/main/java/org/ivoa/vodml/jpa/AttributeConverters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/* | ||
* Created on 7 Oct 2024 | ||
* Copyright 2024 Paul Harrison ([email protected]) | ||
* | ||
* Licensed 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 in file LICENSE | ||
*/ | ||
|
||
package org.ivoa.vodml.jpa; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import jakarta.persistence.AttributeConverter; | ||
|
||
/** | ||
* Attribute converters to convert lists to comma separated strings. | ||
* @author Paul Harrison ([email protected]) | ||
*/ | ||
public class AttributeConverters { | ||
|
||
private static final String SPLIT_CHAR = ";"; | ||
public static class StringListConverter implements AttributeConverter<List<String>, String> { | ||
|
||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see jakarta.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object) | ||
*/ | ||
@Override | ||
public String convertToDatabaseColumn(List<String> attribute) { | ||
return attribute != null ? String.join(SPLIT_CHAR, attribute) : ""; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see jakarta.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) | ||
*/ | ||
@Override | ||
public List<String> convertToEntityAttribute(String dbData) { | ||
return dbData != null ? Arrays.asList(dbData.split(SPLIT_CHAR)) : new ArrayList<String>() ; | ||
} | ||
|
||
} | ||
|
||
public static abstract class NumberListConverter <T> implements AttributeConverter<List<T>, String> { | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see jakarta.persistence.AttributeConverter#convertToDatabaseColumn(java.lang.Object) | ||
*/ | ||
@Override | ||
public String convertToDatabaseColumn(List<T> attribute) { | ||
|
||
if(attribute!= null) | ||
{ | ||
return attribute.stream().map(T::toString).collect(Collectors.joining (SPLIT_CHAR)); | ||
} | ||
else | ||
{ | ||
return ""; | ||
} | ||
} | ||
|
||
|
||
} | ||
public static class IntListConverter extends NumberListConverter<Integer> | ||
{ | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see jakarta.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) | ||
*/ | ||
@Override | ||
public List<Integer> convertToEntityAttribute(String dbData) { | ||
if (dbData != null) | ||
{ | ||
return Stream.of(dbData.split(SPLIT_CHAR)).map(Integer::parseInt).toList(); | ||
} | ||
else return new ArrayList<>(); | ||
|
||
} | ||
|
||
} | ||
public static class DoubleListConverter extends NumberListConverter<Double> | ||
{ | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see jakarta.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) | ||
*/ | ||
@Override | ||
public List<Double> convertToEntityAttribute(String dbData) { | ||
if (dbData != null) | ||
{ | ||
return Stream.of(dbData.split(SPLIT_CHAR)).map(Double::parseDouble).toList(); | ||
} | ||
else return new ArrayList<>(); | ||
|
||
} | ||
|
||
} | ||
public static class BooleanListConverter extends NumberListConverter<Boolean> | ||
{ | ||
|
||
/** | ||
* {@inheritDoc} | ||
* overrides @see jakarta.persistence.AttributeConverter#convertToEntityAttribute(java.lang.Object) | ||
*/ | ||
@Override | ||
public List<Boolean> convertToEntityAttribute(String dbData) { | ||
if (dbData != null) | ||
{ | ||
return Stream.of(dbData.split(SPLIT_CHAR)).map(Boolean::parseBoolean).toList(); | ||
} | ||
else return new ArrayList<>(); | ||
|
||
|
||
} | ||
|
||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.