Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
In ClassPropertyHolder, I have the following code that is performed during construction...
protected Map<String, AttributeConversionInfo> buildAttributeConversionInfoMap(XClass entityXClass) {
final HashMap<String, AttributeConversionInfo> map = new HashMap<String, AttributeConversionInfo>();
collectAttributeConversionInfo( map, entityXClass );
return map;
}
protected void collectAttributeConversionInfo(Map<String, AttributeConversionInfo> infoMap, XClass xClass) {
if ( xClass == null ) {
// typically indicates we have reached the end of the inheritance hierarchy
return;
}
// collect superclass info first
collectAttributeConversionInfo( infoMap, xClass.getSuperclass() );
final boolean canContainConvert = xClass.isAnnotationPresent( javax.persistence.Entity.class )
|| xClass.isAnnotationPresent( javax.persistence.MappedSuperclass.class )
|| xClass.isAnnotationPresent( javax.persistence.Embeddable.class );
if ( ! canContainConvert ) {
return;
}
final List<AttributeConversionInfo> localConvertInfo = new ArrayList<AttributeConversionInfo>();
{
final Convert convertAnnotation = xClass.getAnnotation( Convert.class );
if ( convertAnnotation != null ) {
final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, xClass );
localConvertInfo.add( info );
if ( StringHelper.isEmpty( info.getAttributeName() ) ) {
throw new IllegalStateException( "Convert placed on Entity/MappedSuperclass must define attributeName" );
}
infoMap.put( info.getAttributeName(), info );
}
}
{
final Converts convertsAnnotation = xClass.getAnnotation( Converts.class );
if ( convertsAnnotation != null ) {
for ( Convert convertAnnotation : convertsAnnotation.value() ) {
final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, xClass );
localConvertInfo.add( info );
if ( StringHelper.isEmpty( info.getAttributeName() ) ) {
throw new IllegalStateException( "Convert placed on Entity/MappedSuperclass must define attributeName" );
}
infoMap.put( info.getAttributeName(), info );
}
}
}
// XClass.getDeclaredProperties() requires we pass in "property"/"field" to indicate whether to look
// on getters or fields. Not sure we know that info at the moment. But this would let us fully map
// out the non-auto-applied conversions, if we could figure this out
// xClass.getDeclaredProperties( "" )
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.