Class QueryStatement
java.lang.Object
com.mcpdbwizard.pub.StatementParameters2
com.mcpdbwizard.pub.DmlStatement
com.mcpdbwizard.pub.QueryStatement
- All Implemented Interfaces:
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
Copyright 2003-2026 ATB Consultancy Services Ltd (formerly Orinda Software Ltd, Dublin, Ireland)
- Since:
- 2.0.1477: execute() will now attempt to reparse if the first attempt at execution fails
- Version:
- 7
- Author:
- devteam@mcpdbwizard.com
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intVariable to store Buffer Size for file access.static final intConstant for caching data for the life of the class.static final intConstant for not caching data.static final intDefault value for how many different queries we can cache...static final intDefault value for how many rows returned by a query we actually use...protected booleanVariable to store boolean flag that indicates whether created files should be deletes when the JVM exits.protected booleanVariable to store boolean flag that indicates whether we should turn LOBs into files or not.protected FileVariable to store temporary directory for downloaded files.protected StringThe Prefix for downloaded files containing BLOB, CLOB and BFILE dataprotected StringThe Suffix for downloaded files containing BLOB, CLOB and BFILE dataprotected booleanboolean flag that specifies whether lobs such as CLOBS, BLOBS and BFILES and LONG columns will be kept as byte arrays.Fields inherited from class com.mcpdbwizard.pub.StatementParameters2
inputParameterFilesizeArray, inputParameterSetArray, parameterArray, parameterOpaqueTypeNameArray, parameterTypeArray -
Constructor Summary
ConstructorsConstructorDescriptionQueryStatement(String statementSqlText, LogInterface theLog) Create a DML Statement object.QueryStatement(String statementSqlText, LogInterface theLog, Connection theConnection) Create a DML Statement object and give it a connection -
Method Summary
Modifier and TypeMethodDescriptionvoidClear the cache.execute()Execute the statement and return a ReadOnlyRowSetintGet current file io buffer sizeintReturn the number of queries currently in the cache.longReturn counter containing number of errors.longReturn counter containing number of executions.longReturn counter containing time spent executing statement in milliseconds.booleanGet keepFiles flagbooleanGet keepLobsReturn an up to date signature of the query parameters.longReturn counter containing number of parses.longReturn counter containing time spent parsing in milliseconds.longReturn counter containing number of releases.longReturn counter containing time spent retrieving data in milliseconds.Get temporary directoryGet the prefix used for generating temporary filesGet the suffix used for generating temporary filesbooleanGet keepLobsprotected voidIncrement variable used to keep track of retrieval time - used to implement StatsInterfaceintpurgeExpiredCacheEntries(int howManyMilliseconds) Remove entries that are too old from the cacheintpurgeUnderusedCacheEntries(int minAcceptableReuses, int howManyMilliseconds) Remove entries that have not been reused from the cachevoidReset all stats counters to 0.voidsetBufferSize(int bufferSize) Set new file io buffer sizevoidsetCacheRows(int newCacheRows) Specify how many results will be cached.voidsetCacheSeconds(int newCacheSeconds) Specify how long results will be cached.voidsetKeepFiles(boolean keepFiles) Set keepFilesvoidsetKeepLobs(boolean keepLobs) Set keepLobsvoidsetQueryRows(int newQueryRows) Specify how many rows can be brought backvoidsetTempDir(File tempFileDir) Set temporary directoryvoidsetTempFilePrefix(String tempFilePrefix) Set the prefix used for generating temporary filesvoidsetTempFileSuffix(String tempFileSuffix) Set the suffix used for generating temporary filesvoidsetUseByteArraysForLongsAndLOBS(boolean useByteArraysForLongsAndLOBS) SetUseByteArraysForLongsAndLOBSprotected voidStart timer used to keep track of parse and execution time - used to implement StatsInterfaceMethods inherited from class com.mcpdbwizard.pub.DmlStatement
connectionIsUsable, createPreparedStatement, freeConnection, getUnderlyingStatement, hasResources, releaseResources, setConnection, testConnectionMethods inherited from class com.mcpdbwizard.pub.StatementParameters2
bindParameters, checkBuild, checkRange, checkSet, clearParameters, getParam, getParamCount, getParameters, getSignature, setNativeBooleanParam, 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, setParam, setParam, setParam, setParam, setParam, setPlSqlIndexArrayParam, setPlSqlTableArrayParam, setVectorBinaryParam, setVectorSparseParamMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.mcpdbwizard.pub.OracleResourceUser
hasResources, releaseResources
-
Field Details
-
DEFAULT_QUERY_ROWS
public static final int DEFAULT_QUERY_ROWSDefault value for how many rows returned by a query we actually use...- See Also:
-
DEFAULT_QUERIES_CACHED
public static final int DEFAULT_QUERIES_CACHEDDefault value for how many different queries we can cache...- See Also:
-
CACHE_FOREVER
public static final int CACHE_FOREVERConstant for caching data for the life of the class. Usage:setCacheSeconds(CACHE_FOREVER);- See Also:
-
CACHE_NEVER
public static final int CACHE_NEVERConstant for not caching data. Usage:setCacheSeconds(CACHE_NEVER);- See Also:
-
bufferSize
protected int bufferSizeVariable to store Buffer Size for file access. -
keepFiles
protected boolean keepFilesVariable to store boolean flag that indicates whether created files should be deletes when the JVM exits. -
keepLobs
protected boolean keepLobsVariable to store boolean flag that indicates whether we should turn LOBs into files or not. -
useByteArraysForLongsAndLOBS
protected boolean useByteArraysForLongsAndLOBSboolean flag that specifies whether lobs such as CLOBS, BLOBS and BFILES and LONG columns will be kept as byte arrays. This only works if keepFiles == false.- Since:
- 5.0.2314
-
tempFileDir
Variable to store temporary directory for downloaded files. If you are downloading lots of files you will want to change this to an application specific directory -
tempFilePrefix
The Prefix for downloaded files containing BLOB, CLOB and BFILE data -
tempFileSuffix
The Suffix for downloaded files containing BLOB, CLOB and BFILE data
-
-
Constructor Details
-
QueryStatement
Create a DML Statement object and give it a connection -
QueryStatement
Create a DML Statement object.
-
-
Method Details
-
setCacheSeconds
public void setCacheSeconds(int newCacheSeconds) Specify how long results will be cached.Setting this to a non-zero value turns caching on.
- Parameters:
newCacheSeconds-
-
setCacheRows
public void setCacheRows(int newCacheRows) Specify how many results will be cached.By default this is DEFAULT_QUERIES_CACHED.
- Parameters:
newCacheRows-
-
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:
newQueryRows-
-
execute
Execute the statement and return a ReadOnlyRowSetIf 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:
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:
minAcceptableReuses- How many times an entry must have been used to avoid deletion.howManyMilliseconds- The maximum amount of time to be spent removing entries.- Returns:
- int How many entries were removed.
-
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.
-
setBufferSize
public void setBufferSize(int bufferSize) Set new file io buffer size- Parameters:
bufferSize- A new Buffersize in bytes.
-
getKeepFiles
public boolean getKeepFiles()Get keepFiles flag- Returns:
- int
trueif temporary files are kept after the JVM exits. intfalseif temporary files are deleted after the JVM exits.
-
setKeepFiles
public void setKeepFiles(boolean keepFiles) Set keepFiles- Parameters:
keepFiles- Keep generated files after JVM exits
-
getTempDir
-
setTempDir
Set temporary directory- Parameters:
tempFileDir- a new Temporary Directory- Throws:
CSException- if the directory is not viable- Since:
- 2.0.879
-
getTempFilePrefix
Get the prefix used for generating temporary files -
setTempFilePrefix
Set the prefix used for generating temporary files -
getTempFileSuffix
Get the suffix used for generating temporary files -
setTempFileSuffix
Set the suffix used for generating temporary files -
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
-
setKeepLobs
public void setKeepLobs(boolean keepLobs) Set keepLobs- Parameters:
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:
- 5.0.2314
-
setUseByteArraysForLongsAndLOBS
public void setUseByteArraysForLongsAndLOBS(boolean useByteArraysForLongsAndLOBS) SetUseByteArraysForLongsAndLOBS- Parameters:
useByteArraysForLongsAndLOBS- flag that specifies whether lobs such as CLOBS, BLOBS and BFILES and LONG columns will be kept as byte arrays- Since:
- 5.0.2314
-
resetStatsCounters
public void resetStatsCounters()Reset all stats counters to 0. Used to implement StatsInterface- Specified by:
resetStatsCountersin interfaceStatsInterface- See Also:
-
getParses
public long getParses()Return counter containing number of parses. Used to implement StatsInterface- Specified by:
getParsesin interfaceStatsInterface- Returns:
- long The number of times this statement was parsed.
- See Also:
-
getParseTime
public long getParseTime()Return counter containing time spent parsing in milliseconds. Used to implement StatsInterface- Specified by:
getParseTimein interfaceStatsInterface- Returns:
- long The length of time this statement has spent parsing in milliseconds
- See Also:
-
getExecutions
public long getExecutions()Return counter containing number of executions. Used to implement StatsInterface- Specified by:
getExecutionsin interfaceStatsInterface- Returns:
- long The number of times this statement was executed.
- See Also:
-
getExecutionTime
public long getExecutionTime()Return counter containing time spent executing statement in milliseconds. Used to implement StatsInterface- Specified by:
getExecutionTimein interfaceStatsInterface- Returns:
- long The length of time this statement has spent executing in milliseconds
- See Also:
-
getRetrievalTime
public long getRetrievalTime()Return counter containing time spent retrieving data in milliseconds. Used to implement StatsInterface- Specified by:
getRetrievalTimein interfaceStatsInterface- Returns:
- long The length of time this statement has spent executing in milliseconds
- See Also:
-
getReleases
public long getReleases()Return counter containing number of releases. Used to implement StatsInterface- Specified by:
getReleasesin interfaceStatsInterface- Returns:
- long The number of times this statement was released.
- See Also:
-
getErrors
public long getErrors()Return counter containing number of errors. Used to implement StatsInterface- Specified by:
getErrorsin interfaceStatsInterface- Returns:
- long The number of times an error was generated.
- See Also:
-
startStatsTimer
protected void startStatsTimer()Start timer used to keep track of parse and execution time - used to implement StatsInterface- See Also:
-
incRetrieveTime
protected void incRetrieveTime()Increment variable used to keep track of retrieval time - used to implement StatsInterface- See Also:
-