public T getAsObject ( ) { try { T modelClassObj = modelClazz . newInstance ( ) ; Set < String > columnNameSet = mFieldMap . keySet ( ) ; for ( String columnName : columnNameSet ) { D6ModelClassFieldInfo fieldInfo = mFieldMap . get ( columnName ) ; final Field field = fieldInfo . field ; final Object value = fieldInfo . value ; if ( value != null ) { // try to set 'null' if available try { field . set ( modelClassObj , null ) ; } catch ( Exception e ) { } try { field . set ( modelClassObj , value ) ; } catch ( IllegalAccessException e ) { // handling this exception for field.set(o, value); loge ( "#getAsObject" , e ) ; } catch ( IllegalArgumentException e ) { // e.printStackTrace(); final String name = field . getName ( ) ; final Class < ? > type = field . getType ( ) ; String msg = "The value of '" + columnName + "'=" + value + "(" + value . getClass ( ) + ") couldn't set to variable '" + name + "'(" + type + ")" ; loge ( "#getAsObject " + msg ) ; } } else { // value is null // check is this column CompositType like MySQL's Geometry final List < Object > compositObjValues = fieldInfo . valuesForSpecialType ; if ( field . getType ( ) == org . riversun . d6 . model . Geometry . class ) { if ( compositObjValues != null && compositObjValues . size ( ) > 1 ) { final org . riversun . d6 . model . Geometry newGeometryObj = new org . riversun . d6 . model . Geometry ( ) ; newGeometryObj . x = ( Double ) compositObjValues . get ( 0 ) ; newGeometryObj . y = ( Double ) compositObjValues . get ( 1 ) ; field . set ( modelClassObj , newGeometryObj ) ; } } } } return modelClassObj ; } catch ( IllegalAccessException e ) { throw new D6RuntimeException ( e ) ; } catch ( InstantiationException e ) { throw new D6RuntimeException ( "Cannot instanciate model object from '" + modelClazz . getName ( ) + "' If you declare '" + modelClazz . getName ( ) + "' as inner class, please make it static." ) ; } }
Get the model object populated with the value of the DB search results