com.orindasoft.pub
Class QueryStatement

java.lang.Object
  extended by com.orindasoft.pub.StatementParameters2
      extended by com.orindasoft.pub.DmlStatement
          extended by com.orindasoft.pub.QueryStatement
All Implemented Interfaces:
OracleResourceUser, StatsInterface

public class QueryStatement
extends DmlStatement
implements OracleResourceUser, StatsInterface

A SELECT statement with caching.

This class implements a parameterized SQL statement with query result caching that continues to exist even if the connection it uses is withdrawn. It extends DMLStatement


(c) Copyright 2003 - 2012 Orinda Software Ltd

Since:
2.0.1477: execute() will now attempt to reparse if the first attempt at execution fails
Version:
6.0
Author:
Orinda Software

Field Summary
static int CACHE_FOREVER
          Constant for caching data for the life of the class.
static int CACHE_NEVER
          Constant for not caching data.
static int DEFAULT_QUERIES_CACHED
          Default value for how many different queries we can cache...
static int DEFAULT_QUERY_ROWS
          Default value for how many rows returned by a query we actually use...
 
Constructor Summary
QueryStatement(java.lang.String statementSqlText, LogInterface theLog)
          Create a DML Statement object.
QueryStatement(java.lang.String statementSqlText, LogInterface theLog, java.sql.Connection theConnection)
          Create a DML Statement object and give it a connection
 
Method Summary
 void clearCache()
          Clear the cache.
 ReadOnlyRowSet execute()
          Execute the statement and return a ReadOnlyRowSet If caching is in use the cache will be checked and a cached copy returned if possible.
 int getBufferSize()
          Get current file io buffer size
 int getCacheSize()
          Return the number of queries currently in the cache.
 long getErrors()
          Return counter containing number of errors.
 long getExecutions()
          Return counter containing number of executions.
 long getExecutionTime()
          Return counter containing time spent executing statement in milliseconds.
 boolean getKeepFiles()
          Get keepFiles flag
 boolean getKeepLobs()
          Get keepLobs
 java.lang.String getLatestQuerySignature()
          Return an up to date signature of the query parameters.
 long getParses()
          Return counter containing number of parses.
 long getParseTime()
          Return counter containing time spent parsing in milliseconds.
 long getReleases()
          Return counter containing number of releases.
 long getRetrievalTime()
          Return counter containing time spent retrieving data in milliseconds.
 java.io.File getTempDir()
          Get temporary directory
 java.lang.String getTempFilePrefix()
          Get the prefix used for generating temporary files
 java.lang.String getTempFileSuffix()
          Get the suffix used for generating temporary files
 boolean getUseByteArraysForLongsAndLOBS()
          Get keepLobs
 int purgeExpiredCacheEntries(int howManyMilliseconds)
          Remove entries that are too old from the cache
 int purgeUnderusedCacheEntries(int minAcceptableReuses, int howManyMilliseconds)
          Remove entries that have not been reused from the cache
 void resetStatsCounters()
          Reset all stats counters to 0.
 void setBufferSize(int bufferSize)
          Set new file io buffer size
 void setCacheRows(int newCacheRows)
          Specify how many results will be cached.
 void setCacheSeconds(int newCacheSeconds)
          Specify how long results will be cached.
 void setKeepFiles(boolean keepFiles)
          Set keepFiles
 void setKeepLobs(boolean keepLobs)
          Set keepLobs
 void setQueryRows(int newQueryRows)
          Specify how many rows can be brought back
 void setTempDir(java.io.File tempFileDir)
          Set temporary directory
 void setTempFilePrefix(java.lang.String tempFilePrefix)
          Set the prefix used for generating temporary files
 void setTempFileSuffix(java.lang.String tempFileSuffix)
          Set the suffix used for generating temporary files
 void setUseByteArraysForLongsAndLOBS(boolean useByteArraysForLongsAndLOBS)
          SetUseByteArraysForLongsAndLOBS
 
Methods inherited from class com.orindasoft.pub.DmlStatement
connectionIsUsable, freeConnection, getUnderlyingStatement, hasResources, releaseResources, setConnection
 
Methods inherited from class com.orindasoft.pub.StatementParameters2
bindParameters, checkBuild, checkSet, clearParameters, getParam, getParamCount, getParameters, getSignature, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setParam, setPlSqlTableArrayParam
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.orindasoft.pub.OracleResourceUser
hasResources, releaseResources
 

Field Detail

DEFAULT_QUERY_ROWS

public static final int DEFAULT_QUERY_ROWS
Default value for how many rows returned by a query we actually use...

See Also:
Constant Field Values

DEFAULT_QUERIES_CACHED

public static final int DEFAULT_QUERIES_CACHED
Default value for how many different queries we can cache...

See Also:
Constant Field Values

CACHE_FOREVER

public static final int CACHE_FOREVER
Constant for caching data for the life of the class. Usage: setCacheSeconds(CACHE_FOREVER);

See Also:
Constant Field Values

CACHE_NEVER

public static final int CACHE_NEVER
Constant for not caching data. Usage: setCacheSeconds(CACHE_NEVER);

See Also:
Constant Field Values
Constructor Detail

QueryStatement

public QueryStatement(java.lang.String statementSqlText,
                      LogInterface theLog,
                      java.sql.Connection theConnection)
Create a DML Statement object and give it a connection


QueryStatement

public QueryStatement(java.lang.String statementSqlText,
                      LogInterface theLog)
Create a DML Statement object.

Method Detail

setCacheSeconds

public void setCacheSeconds(int newCacheSeconds)
Specify how long results will be cached. Setting this to a non-zero value turns caching on.

Parameters:
int - newCacheSeconds

setCacheRows

public void setCacheRows(int newCacheRows)
Specify how many results will be cached. By default this is DEFAULT_QUERIES_CACHED.

Parameters:
int - newCacheSeconds

getCacheSize

public int getCacheSize()
Return the number of queries currently in the cache.


clearCache

public void clearCache()
Clear the cache.


setQueryRows

public void setQueryRows(int newQueryRows)
Specify how many rows can be brought back

Parameters:
int - newQueryRows

execute

public ReadOnlyRowSet execute()
                       throws CSException
Execute the statement and return a ReadOnlyRowSet If caching is in use the cache will be checked and a cached copy returned if possible.

Returns:
ReadOnlyRowSet The results from this query
Throws:
CSException
Since:
2.0.1477: execute() will now attempt to reparse if the first attempt at execution fails, 5.0.2314 'useByteArraysForLongsAndLOBS' added.

purgeExpiredCacheEntries

public int purgeExpiredCacheEntries(int howManyMilliseconds)
Remove entries that are too old from the cache

Parameters:
int - howManyMilliseconds The maximum amount of time to be spent removing entries.
Returns:
int How many entries were removed.

purgeUnderusedCacheEntries

public int purgeUnderusedCacheEntries(int minAcceptableReuses,
                                      int howManyMilliseconds)
Remove entries that have not been reused from the cache

Parameters:
int - minAcceptableReuses How many times an entry must have been used to avoid deletion.
int - howManyMilliseconds The maximum amount of time to be spent removing entries.
Returns:
int How many entries were removed.

getLatestQuerySignature

public java.lang.String getLatestQuerySignature()
Return an up to date signature of the query parameters.


getBufferSize

public int getBufferSize()
Get current file io buffer size

Returns:
int bufferSize Buffersize in bytes.

getKeepFiles

public boolean getKeepFiles()
Get keepFiles flag

Returns:
int true if temporary files are kept after the JVM exits.

getTempDir

public java.io.File getTempDir()
Get temporary directory


getTempFilePrefix

public java.lang.String getTempFilePrefix()
Get the prefix used for generating temporary files


getTempFileSuffix

public java.lang.String getTempFileSuffix()
Get the suffix used for generating temporary files


setBufferSize

public void setBufferSize(int bufferSize)
Set new file io buffer size

Parameters:
int - bufferSize A new Buffersize in bytes.

setKeepFiles

public void setKeepFiles(boolean keepFiles)
Set keepFiles

Parameters:
boolean - keepFiles Keep generated files after JVM exits

setKeepLobs

public void setKeepLobs(boolean keepLobs)
Set keepLobs

Parameters:
boolean - keepLobs Keep LOB objects such as CLOB, BLOB and BFILE as LOBS instead of turning them into files on retrieval.
Since:
2.0.1505

setUseByteArraysForLongsAndLOBS

public void setUseByteArraysForLongsAndLOBS(boolean useByteArraysForLongsAndLOBS)
SetUseByteArraysForLongsAndLOBS

Parameters:
boolean - useByteArraysForLongsAndLOBS flag that specifies whether lobs such as CLOBS, BLOBS and BFILES and LONG columns will be kept as byte arrays
Since:
JDBCWizard 5.0.2314

getKeepLobs

public boolean getKeepLobs()
Get keepLobs

Returns:
boolean keepLobs Keep LOB objects such as CLOB, BLOB and BFILE as LOBS instead of turning them into files on retrieval.
Since:
2.0.1505

getUseByteArraysForLongsAndLOBS

public boolean getUseByteArraysForLongsAndLOBS()
Get keepLobs

Returns:
boolean useByteArraysForLongsAndLOBS flag that specifies whether lobs such as CLOBS, BLOBS and BFILES and LONG columns will be kept as byte arrays
Since:
JDBCWizard 5.0.2314

setTempDir

public void setTempDir(java.io.File tempFileDir)
                throws CSException
Set temporary directory

Parameters:
java.io.File - tempFileDir a new Temporary Directory
Throws:
CSException - if the directory is not viable
Since:
2.0.879

setTempFilePrefix

public void setTempFilePrefix(java.lang.String tempFilePrefix)
Set the prefix used for generating temporary files


setTempFileSuffix

public void setTempFileSuffix(java.lang.String tempFileSuffix)
Set the suffix used for generating temporary files


resetStatsCounters

public void resetStatsCounters()
Reset all stats counters to 0. Used to implement StatsInterface

Specified by:
resetStatsCounters in interface StatsInterface
See Also:
See StatsInterface - a generic set of performance measuring methods

getParses

public long getParses()
Return counter containing number of parses. Used to implement StatsInterface

Specified by:
getParses in interface StatsInterface
Returns:
long The number of times this statement was parsed.
See Also:
See StatsInterface - a generic set of performance measuring methods

getParseTime

public long getParseTime()
Return counter containing time spent parsing in milliseconds. Used to implement StatsInterface

Specified by:
getParseTime in interface StatsInterface
Returns:
long The length of time this statement has spent parsing in milliseconds
See Also:
See StatsInterface - a generic set of performance measuring methods

getExecutions

public long getExecutions()
Return counter containing number of executions. Used to implement StatsInterface

Specified by:
getExecutions in interface StatsInterface
Returns:
long The number of times this statement was executed.
See Also:
See StatsInterface - a generic set of performance measuring methods

getExecutionTime

public long getExecutionTime()
Return counter containing time spent executing statement in milliseconds. Used to implement StatsInterface

Specified by:
getExecutionTime in interface StatsInterface
Returns:
long The length of time this statement has spent executing in milliseconds
See Also:
See StatsInterface - a generic set of performance measuring methods

getRetrievalTime

public long getRetrievalTime()
Return counter containing time spent retrieving data in milliseconds. Used to implement StatsInterface

Specified by:
getRetrievalTime in interface StatsInterface
Returns:
long The length of time this statement has spent executing in milliseconds
See Also:
See StatsInterface - a generic set of performance measuring methods

getReleases

public long getReleases()
Return counter containing number of releases. Used to implement StatsInterface

Specified by:
getReleases in interface StatsInterface
Returns:
long The number of times this statement was released.
See Also:
See StatsInterface - a generic set of performance measuring methods

getErrors

public long getErrors()
Return counter containing number of errors. Used to implement StatsInterface

Specified by:
getErrors in interface StatsInterface
Returns:
long The number of times an error was generated.
See Also:
See StatsInterface - a generic set of performance measuring methods


Copyright © Orinda Software Ltd 2012Logo