Class 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

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 Details

    • 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:
    • DEFAULT_QUERIES_CACHED

      public static final int DEFAULT_QUERIES_CACHED
      Default value for how many different queries we can cache...
      See Also:
    • CACHE_FOREVER

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

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

      protected int bufferSize
      Variable to store Buffer Size for file access.
    • keepFiles

      protected boolean keepFiles
      Variable to store boolean flag that indicates whether created files should be deletes when the JVM exits.
    • keepLobs

      protected boolean keepLobs
      Variable to store boolean flag that indicates whether we should turn LOBs into files or not.
    • useByteArraysForLongsAndLOBS

      protected boolean useByteArraysForLongsAndLOBS
      boolean 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

      protected File 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

      protected String tempFilePrefix
      The Prefix for downloaded files containing BLOB, CLOB and BFILE data
    • tempFileSuffix

      protected String tempFileSuffix
      The Suffix for downloaded files containing BLOB, CLOB and BFILE data
  • Constructor Details

    • QueryStatement

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

      public QueryStatement(String statementSqlText, LogInterface theLog)
      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

      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:
      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

      public 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.
    • 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 true if temporary files are kept after the JVM exits. int false if 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

      public File getTempDir()
      Get temporary directory
      Returns:
      the temporary directory
    • setTempDir

      public void setTempDir(File tempFileDir) throws CSException
      Set temporary directory
      Parameters:
      tempFileDir - a new Temporary Directory
      Throws:
      CSException - if the directory is not viable
      Since:
      2.0.879
    • getTempFilePrefix

      public String getTempFilePrefix()
      Get the prefix used for generating temporary files
    • setTempFilePrefix

      public void setTempFilePrefix(String tempFilePrefix)
      Set the prefix used for generating temporary files
    • getTempFileSuffix

      public String getTempFileSuffix()
      Get the suffix used for generating temporary files
    • setTempFileSuffix

      public void setTempFileSuffix(String tempFileSuffix)
      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:
      resetStatsCounters in interface StatsInterface
      See Also:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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:
    • 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: