public static String adHocSQLStringFromPlannedStatement ( AdHocPlannedStatement statement , Object [ ] userparams ) { final int MAX_PARAM_LINE_CHARS = 120 ; StringBuilder sb = new StringBuilder ( ) ; String sql = new String ( statement . sql , Charsets . UTF_8 ) ; sb . append ( sql ) ; Object [ ] params = paramsForStatement ( statement , userparams ) ; // convert params to strings of a certain max length for ( int i = 0 ; i < params . length ; i ++ ) { Object param = params [ i ] ; String paramLineStr = String . format ( " Param %d: %s" , i , param . toString ( ) ) ; // trim param line if it's silly long if ( paramLineStr . length ( ) > MAX_PARAM_LINE_CHARS ) { paramLineStr = paramLineStr . substring ( 0 , MAX_PARAM_LINE_CHARS - 3 ) ; paramLineStr += "..." ; } sb . append ( ' ' ) . append ( paramLineStr ) ; } return sb . toString ( ) ; }
Get a string containing a SQL statement and any parameters for a given AdHocPlannedStatement . Used for debugging and logging .