private Single < SingleInsertionResult > insert ( String preparedSql , Object [ ] sqlParams ) { return Single . fromCallable ( ( ) -> { PreparedStatement statement = connection0 . prepareStatement ( preparedSql , PreparedStatement . RETURN_GENERATED_KEYS ) ; for ( int i = 0 ; i < sqlParams . length ; i ++ ) { statement . setObject ( i + 1 , sqlParams [ i ] ) ; } statement . execute ( ) ; ResultSet rs = statement . getGeneratedKeys ( ) ; Integer count = statement . getUpdateCount ( ) ; Long id ; if ( rs . next ( ) ) { id = rs . getLong ( 1 ) ; } else { //no id is generated id = null ; } rs . close ( ) ; statement . close ( ) ; return new SingleInsertionResult ( ) . setCount ( count ) . setId ( id ) . setPreparedSql ( preparedSql ) ; } ) ; }
Async single record insertion