-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for jMolecules' Association type.
We no recognize properties of type org.jmolecules.ddd.types.Association as associations in our PersistentProperty model. Also, we now register JMolecules Converter implementations for Association and Identifier in CustomConversions so that they can persisted like their embedded primitive value out of the box. Fixes #2315.
- Loading branch information
Showing
9 changed files
with
146 additions
and
9 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
69 changes: 69 additions & 0 deletions
69
src/main/java/org/springframework/data/convert/JMoleculesConverters.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,69 @@ | ||
/* | ||
* Copyright 2021 the original author or authors. | ||
* | ||
* 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 at | ||
* | ||
* https://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.springframework.data.convert; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import org.jmolecules.spring.AssociationToPrimitivesConverter; | ||
import org.jmolecules.spring.IdentifierToPrimitivesConverter; | ||
import org.jmolecules.spring.PrimitivesToAssociationConverter; | ||
import org.jmolecules.spring.PrimitivesToIdentifierConverter; | ||
import org.springframework.core.convert.ConversionService; | ||
import org.springframework.core.convert.support.DefaultConversionService; | ||
import org.springframework.util.ClassUtils; | ||
|
||
/** | ||
* Registers jMolecules converter implementations with {@link CustomConversions} if the former is on the classpath. | ||
* | ||
* @author Oliver Drotbohm | ||
* @since 2.5 | ||
*/ | ||
public class JMoleculesConverters { | ||
|
||
private static final boolean JMOLECULES_PRESENT = ClassUtils.isPresent( | ||
"org.jmolecules.spring.IdentifierToPrimitivesConverter", | ||
JMoleculesConverters.class.getClassLoader()); | ||
|
||
/** | ||
* Returns all jMolecules-specific converters to be registered. | ||
* | ||
* @return will never be {@literal null}. | ||
*/ | ||
public static Collection<Object> getConvertersToRegister() { | ||
|
||
if (!JMOLECULES_PRESENT) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
List<Object> converters = new ArrayList<>(); | ||
|
||
Supplier<ConversionService> conversionService = () -> DefaultConversionService.getSharedInstance(); | ||
|
||
IdentifierToPrimitivesConverter toPrimitives = new IdentifierToPrimitivesConverter(conversionService); | ||
PrimitivesToIdentifierConverter toIdentifier = new PrimitivesToIdentifierConverter(conversionService); | ||
|
||
converters.add(toPrimitives); | ||
converters.add(toIdentifier); | ||
converters.add(new AssociationToPrimitivesConverter<>(toPrimitives)); | ||
converters.add(new PrimitivesToAssociationConverter<>(toIdentifier)); | ||
|
||
return converters; | ||
} | ||
} |
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