public static ResultSet executeAdaptiveQuery ( Session session , Statement statement , int fetchSize ) { int remainingAdaptations = MAX_ADAPTATIONS ; while ( true ) { try { statement . setFetchSize ( fetchSize ) ; ResultSet resultSet = session . execute ( statement ) ; return new AdaptiveResultSet ( session , resultSet , remainingAdaptations ) ; } catch ( Throwable t ) { if ( isAdaptiveException ( t ) && -- remainingAdaptations != 0 && fetchSize > MIN_FETCH_SIZE ) { // Try again with half the fetch size fetchSize = Math . max ( fetchSize / 2 , MIN_FETCH_SIZE ) ; _log . debug ( "Repeating previous query with fetch size {} due to {}" , fetchSize , t . getMessage ( ) ) ; } else { throw Throwables . propagate ( t ) ; } } } }
Executes a query sychronously dynamically adjusting the fetch size down if necessary .