net.sf.farrago.util
Class FarragoUtil

java.lang.Object
  extended by net.sf.farrago.util.FarragoUtil

public abstract class FarragoUtil
extends Object

Miscellaneous static utilities that don't fit into other categories.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/util/FarragoUtil.java#23 $
Author:
John V. Sichi

Constructor Summary
FarragoUtil()
           
 
Method Summary
static int copyFromReaderToWriter(Reader reader, Writer writer)
          Copies everything from a Reader into a Writer.
static String exceptionToString(Throwable ex)
           
static String exceptionToString(Throwable ex, String sep)
          Converts any Throwable and its causes to a String.
static long getFennelMemoryUsage(String s)
          Estimates the memory used by the Fennel portion of a query plan by taking the memory used by the XMI representation of the plan and multiplying by a constant factor.
static int getStringMemoryUsage(String s)
          Calculates the memory used by a string's data (not including the String object itself).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FarragoUtil

public FarragoUtil()
Method Detail

getStringMemoryUsage

public static int getStringMemoryUsage(String s)
Calculates the memory used by a string's data (not including the String object itself). This represents the actual memory used by the Java Unicode representation, not an encoding.

Returns:
number of bytes used

getFennelMemoryUsage

public static long getFennelMemoryUsage(String s)
Estimates the memory used by the Fennel portion of a query plan by taking the memory used by the XMI representation of the plan and multiplying by a constant factor. That constant factor is estimated as 2, based on measurements correlating between the the XMI plan string length and the actual Fennel memory used to construct the Fennel stream graphs. The actual measured value was between .6 and .95 of the XMI plan size. Therefore, we use 1 as a conservative estimate. But since we've already accounted for half of the XMI plan memory in the cache entry associated with the SQL statement, we reduce by .5 to arrive at 1.5.

Parameters:
s - XMI string
Returns:
estimated memory usage

copyFromReaderToWriter

public static int copyFromReaderToWriter(Reader reader,
                                         Writer writer)
                                  throws IOException
Copies everything from a Reader into a Writer.

Parameters:
reader - source
writer - destination
Returns:
number of chars copied
Throws:
IOException

exceptionToString

public static String exceptionToString(Throwable ex)

exceptionToString

public static String exceptionToString(Throwable ex,
                                       String sep)
Converts any Throwable and its causes to a String.

Parameters:
ex - Throwable to be converted
sep - String the stack line separator
Returns:
ex as a String