Class DeepCloner
- java.lang.Object
- 
- org.keycloak.models.map.common.DeepCloner
 
- 
 public class DeepCloner extends Object Helper class for deep cloning and fine-grained instantiation per interface and deep copying their properties.This class is intended to be used by individual map storage implementations for copying over entities into their native implementations. For example, a MapClientEntityinterface could be implemented byMapClientEntityImpl(used by a file-based storage in this example) and anHotRodClientEntityImpl(for Infinispan). Say that the Infinispan is stacked on top of the file-based storage to provide caching layer. Upon first read, aMapClientEntityImplcould be obtained from file-based storage and passed to Infinispan layer for caching. Infinispan, regardless of the actual implementation, need to store theMapClientEntitydata in a form that can be processed and sent over the wire in Infinispan (say in anInfinispanClientEntityImpl). To achieve this, the Infinispan store has to clone the file entity values from theMapClientEntityImpltoInfinispanClientEntityImpl, i.e. it performs deep cloning, using this helper class.Broader context: In tree store, map storages are agnostic to their neighbours. Therefore each implementation can be provided with a record (a MapClientEntityinstance in the example above) originating from any other implementation. For a map storage to process the record (beyond read-only mode), it needs to be able to clone it into its own entity. Each of the storages thus can benefit from theDeepClonercapabilities.- Author:
- hmlnarik
 
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classDeepCloner.BuilderBuilder for theDeepClonerhelper class.static interfaceDeepCloner.Cloner<V>Function that clones properties fromoriginalobject to atargetobject and returns the cloned object (usually the same as thetarget).static interfaceDeepCloner.DelegateCreator<V>Function that instantiates a delegation object of typeVwith the given delegate providerstatic interfaceDeepCloner.EntityFieldDelegateCreator<V>Function that instantiates a delegation object of typeVwith the given per-field delegate providerstatic interfaceDeepCloner.RootMarker for interfaces that could be requested for instantiation and cloning.
 - 
Field SummaryFields Modifier and Type Field Description static DeepClonerDUMB_CLONER
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <V> VdeepClone(V from, V to)Deeply clones properties from thefrominstance to thetoinstance.<V> VdeepCloneNoId(V from, V to)Deeply clones properties from thefrominstance to thetoinstance excluding the ID field.<D,V extends D>
 Ddelegate(Class<V> delegateClass, DelegateProvider<D> delegateProvider)<D,V extends D>
 Ddelegate(V delegate, DelegateProvider<D> delegateProvider)<V> VemptyInstance(Class<V> instanceClass)<V> VentityFieldDelegate(Class<V> delegateClass, EntityFieldDelegate<V> delegateProvider)<V extends AbstractEntity>
 VentityFieldDelegate(V delegate, EntityFieldDelegate<V> delegateProvider)<V extends AbstractEntity>
 Vfrom(String newId, V from)Creates a new instance of the given type and copies its properties from thefrominstance<V> Vfrom(V from)Creates a new instance of the given type and copies its properties from thefrominstance<V> VnewInstance(Class<V> clazz)Creates a new instance of the given class or interface if the parameterless constructor for that type is known.<V> Class<? extends V>newInstanceType(Class<V> valueType)Returns a class type of an instance that would be instantiated bynewInstance(java.lang.Class)method.static <T> TwarnCloneNotSupported(T o)Issues warning in the logs and returns the input parametero
 
- 
- 
- 
Field Detail- 
DUMB_CLONERpublic static final DeepCloner DUMB_CLONER 
 
- 
 - 
Method Detail- 
delegatepublic <D,V extends D> D delegate(V delegate, DelegateProvider<D> delegateProvider)
 - 
delegatepublic <D,V extends D> D delegate(Class<V> delegateClass, DelegateProvider<D> delegateProvider) 
 - 
entityFieldDelegatepublic <V extends AbstractEntity> V entityFieldDelegate(V delegate, EntityFieldDelegate<V> delegateProvider) 
 - 
entityFieldDelegatepublic <V> V entityFieldDelegate(Class<V> delegateClass, EntityFieldDelegate<V> delegateProvider) 
 - 
emptyInstancepublic <V> V emptyInstance(Class<V> instanceClass) 
 - 
newInstancepublic <V> V newInstance(Class<V> clazz) Creates a new instance of the given class or interface if the parameterless constructor for that type is known.- Type Parameters:
- V- Type (class or a- @Rootinterface) to create a new instance
- Parameters:
- clazz- Type (class or a- @Rootinterface) to create a new instance
- Returns:
- A new instance
- Throws:
- IllegalStateException- When the constructor is not known.
 
 - 
newInstanceTypepublic <V> Class<? extends V> newInstanceType(Class<V> valueType) Returns a class type of an instance that would be instantiated bynewInstance(java.lang.Class)method.- Type Parameters:
- V- Type (class or a- @Rootinterface) to create a new instance
- Parameters:
- valueType- Type (class or a- @Rootinterface) to create a new instance
- Returns:
- See description
 
 - 
deepClonepublic <V> V deepClone(V from, V to)Deeply clones properties from thefrominstance to thetoinstance.- Type Parameters:
- V- Type (class or a- @Rootinterface) to clone the instance
- Parameters:
- from- Original instance
- to- Instance to copy the properties onto
- Returns:
- Instance which has all the properties same as the from. Preferably,tois returned. Howeverfromis returned if the cloner is not known and generic cloner is not available.
 
 - 
deepCloneNoIdpublic <V> V deepCloneNoId(V from, V to)Deeply clones properties from thefrominstance to thetoinstance excluding the ID field.- Type Parameters:
- V- Type (class or a- @Rootinterface) to clone the instance
- Parameters:
- from- Original instance
- to- Instance to copy the properties onto
- Returns:
- Instance which has all the properties same as the from. Preferably,tois returned. Howeverfromis returned if the cloner is not known and generic cloner is not available.
 
 - 
frompublic <V extends AbstractEntity> V from(String newId, V from) Creates a new instance of the given type and copies its properties from thefrominstance- Type Parameters:
- V- Type (class or a- @Rootinterface) to create a new instance and clone properties from
- Parameters:
- newId- ID of the new object
- from- Original instance
- Returns:
- Newly created instance or nulliffromisnull.
 
 - 
frompublic <V> V from(V from) Creates a new instance of the given type and copies its properties from thefrominstance- Type Parameters:
- V- Type (class or a- @Rootinterface) to create a new instance and clone properties from
- Parameters:
- from- Original instance
- Returns:
- Newly created instance or nulliffromisnull.
 
 - 
warnCloneNotSupportedpublic static <T> T warnCloneNotSupported(T o) Issues warning in the logs and returns the input parametero- Parameters:
- o-
- Returns:
- The oobject
 
 
- 
 
-