private Object populateEmbeddedObject ( SuperColumn sc , EntityMetadata m ) throws Exception { Field embeddedCollectionField = null ; Object embeddedObject = null ; String scName = PropertyAccessorFactory . STRING . fromBytes ( String . class , sc . getName ( ) ) ; String scNamePrefix = null ; // Get a name->field map for super-columns Map < String , Field > columnNameToFieldMap = new HashMap < String , Field > ( ) ; Map < String , Field > superColumnNameToFieldMap = new HashMap < String , Field > ( ) ; MetadataUtils . populateColumnAndSuperColumnMaps ( m , columnNameToFieldMap , superColumnNameToFieldMap , kunderaMetadata ) ; // If this super column is variable in number (name#sequence format) if ( scName . indexOf ( Constants . EMBEDDED_COLUMN_NAME_DELIMITER ) != - 1 ) { StringTokenizer st = new StringTokenizer ( scName , Constants . EMBEDDED_COLUMN_NAME_DELIMITER ) ; if ( st . hasMoreTokens ( ) ) { scNamePrefix = st . nextToken ( ) ; } embeddedCollectionField = superColumnNameToFieldMap . get ( scNamePrefix ) ; Class < ? > embeddedClass = PropertyAccessorHelper . getGenericClass ( embeddedCollectionField ) ; // must have a default no-argument constructor try { embeddedClass . getConstructor ( ) ; } catch ( NoSuchMethodException nsme ) { throw new PersistenceException ( embeddedClass . getName ( ) + " is @Embeddable and must have a default no-argument constructor." ) ; } embeddedObject = embeddedClass . newInstance ( ) ; for ( Column column : sc . getColumns ( ) ) { String name = PropertyAccessorFactory . STRING . fromBytes ( String . class , column . getName ( ) ) ; byte [ ] value = column . getValue ( ) ; if ( value == null ) { continue ; } Field columnField = columnNameToFieldMap . get ( name ) ; PropertyAccessorHelper . set ( embeddedObject , columnField , value ) ; } } else { Field superColumnField = superColumnNameToFieldMap . get ( scName ) ; Class superColumnClass = superColumnField . getType ( ) ; embeddedObject = superColumnClass . newInstance ( ) ; for ( Column column : sc . getColumns ( ) ) { String name = PropertyAccessorFactory . STRING . fromBytes ( String . class , column . getName ( ) ) ; byte [ ] value = column . getValue ( ) ; if ( value == null ) { continue ; } // set value of the field in the bean Field columnField = columnNameToFieldMap . get ( name ) ; PropertyAccessorHelper . set ( embeddedObject , columnField , value ) ; } } return embeddedObject ; }
Populate embedded object .