public static Object toBasicType ( String value , String type ) throws SQLException { // Early return from first "if" condition that evaluates to true if ( value == null ) { return null ; } if ( type == null || type . equals ( String . class . getName ( ) ) ) { return value ; } if ( type . equals ( Integer . class . getName ( ) ) || type . equals ( int . class . getName ( ) ) ) { try { return Integer . valueOf ( value ) ; } catch ( NumberFormatException e ) { throwSQLException ( e , "Integer" , value ) ; } } if ( type . equals ( Float . class . getName ( ) ) || type . equals ( float . class . getName ( ) ) ) { try { return Float . valueOf ( value ) ; } catch ( NumberFormatException e ) { throwSQLException ( e , "Float" , value ) ; } } if ( type . equals ( Long . class . getName ( ) ) || type . equals ( long . class . getName ( ) ) ) { try { return Long . valueOf ( value ) ; } catch ( NumberFormatException e ) { throwSQLException ( e , "Long" , value ) ; } } if ( type . equals ( Double . class . getName ( ) ) || type . equals ( double . class . getName ( ) ) ) { try { return Double . valueOf ( value ) ; } catch ( NumberFormatException e ) { throwSQLException ( e , "Double" , value ) ; } } if ( type . equals ( Character . class . getName ( ) ) || type . equals ( char . class . getName ( ) ) ) { if ( value . length ( ) != 1 ) { throw new SQLException ( "Invalid Character value: " + value ) ; } return value . charAt ( 0 ) ; } if ( type . equals ( Byte . class . getName ( ) ) || type . equals ( byte . class . getName ( ) ) ) { try { return Byte . valueOf ( value ) ; } catch ( NumberFormatException e ) { throwSQLException ( e , "Byte" , value ) ; } } if ( type . equals ( Short . class . getName ( ) ) || type . equals ( short . class . getName ( ) ) ) { try { return Short . valueOf ( value ) ; } catch ( NumberFormatException e ) { throwSQLException ( e , "Short" , value ) ; } } // Will be "false" if not in correct format... if ( type . equals ( Boolean . class . getName ( ) ) || type . equals ( boolean . class . getName ( ) ) ) { return Boolean . valueOf ( value ) ; } throw new SQLException ( "Unrecognized property type: " + type ) ; }
Transforms the given value to an instance of the given type .