protected int saveObject ( int tid , String v ) throws SQLException { final String objectsIdColumn = ( dbConnection . isPostgresql ( ) ? OBJECTS_ID_COLUMN_POSTGRESQL : OBJECTS_ID_COLUMN ) ; PreparedStatement ps = getPreparedStatement ( OBJECTS_SQL , new String [ ] { objectsIdColumn } ) ; ResultSet rs = null ; if ( v == null ) { throw new InvalidArgument ( "object value cannot be null" ) ; } try { v = new String ( v . getBytes ( ) , "UTF-8" ) ; } catch ( UnsupportedEncodingException e ) { throw new RuntimeException ( "utf-8 unsupported" , e ) ; } try { // Insert into objects_text if we are over MAX_VARCHAR_LENGTH Integer objectsTextId = null ; if ( v . length ( ) > MAX_VARCHAR_LENGTH ) { final String objectsTextColumn = ( dbConnection . isPostgresql ( ) ? OBJECTS_TEXT_COLUMN_POSTGRESQL : OBJECTS_TEXT_COLUMN ) ; PreparedStatement otps = getPreparedStatement ( OBJECTS_TEXT_SQL , new String [ ] { objectsTextColumn } ) ; ResultSet otrs = null ; StringReader sr = null ; try { sr = new StringReader ( v ) ; otps . setClob ( 1 , sr , v . length ( ) ) ; otps . execute ( ) ; otrs = otps . getGeneratedKeys ( ) ; if ( otrs . next ( ) ) { objectsTextId = otrs . getInt ( 1 ) ; } } finally { close ( otrs ) ; if ( sr != null ) { sr . close ( ) ; } } } // FIXME Hardcoding objects_type to 1? ps . setInt ( 1 , 1 ) ; if ( objectsTextId == null ) { // insert value into objects table ps . setString ( 2 , v ) ; ps . setNull ( 3 , Types . INTEGER ) ; } else { ps . setNull ( 2 , Types . VARCHAR ) ; ps . setInt ( 3 , objectsTextId ) ; } ps . execute ( ) ; rs = ps . getGeneratedKeys ( ) ; int oid ; if ( rs . next ( ) ) { oid = rs . getInt ( 1 ) ; } else { throw new IllegalStateException ( "object insert failed." ) ; } return oid ; } finally { close ( rs ) ; } }
Saves an entry to the object table .