public void assignField ( ConnectionSource connectionSource , Object data , Object val , boolean parentObject , ObjectCache objectCache ) throws SQLException { if ( logger . isLevelEnabled ( Level . TRACE ) ) { logger . trace ( "assiging from data {}, val {}: {}" , ( data == null ? "null" : data . getClass ( ) ) , ( val == null ? "null" : val . getClass ( ) ) , val ) ; } // if this is a foreign object then val is the foreign object's id val if ( foreignRefField != null && val != null ) { // get the current field value which is the foreign-id Object foreignRef = extractJavaFieldValue ( data ) ; /* * See if we don't need to create a new foreign object. If we are refreshing and the id field has not * changed then there is no need to create a new foreign object and maybe lose previously refreshed field * information. */ if ( foreignRef != null && foreignRef . equals ( val ) ) { return ; } // awhitlock: raised as OrmLite issue: bug #122 Object cachedVal ; ObjectCache foreignCache = foreignDao . getObjectCache ( ) ; if ( foreignCache == null ) { cachedVal = null ; } else { cachedVal = foreignCache . get ( getType ( ) , val ) ; } if ( cachedVal != null ) { val = cachedVal ; } else if ( ! parentObject ) { // the value we are to assign to our field is now the foreign object itself val = createForeignObject ( connectionSource , val , objectCache ) ; } } if ( fieldSetMethod == null ) { try { field . set ( data , val ) ; } catch ( IllegalArgumentException e ) { if ( val == null ) { throw SqlExceptionUtil . create ( "Could not assign object '" + val + "' to field " + this , e ) ; } else { throw SqlExceptionUtil . create ( "Could not assign object '" + val + "' of type " + val . getClass ( ) + " to field " + this , e ) ; } } catch ( IllegalAccessException e ) { throw SqlExceptionUtil . create ( "Could not assign object '" + val + "' of type " + val . getClass ( ) + "' to field " + this , e ) ; } } else { try { fieldSetMethod . invoke ( data , val ) ; } catch ( Exception e ) { throw SqlExceptionUtil . create ( "Could not call " + fieldSetMethod + " on object with '" + val + "' for " + this , e ) ; } } }
Assign to the data object the val corresponding to the fieldType .