i-net Clear Reports

com.inet.report.cache
Class Cache

java.lang.Object
  extended by com.inet.report.cache.Cache
Direct Known Subclasses:
ExternalDBCache

public abstract class Cache
extends java.lang.Object

This class implements an Engine Data Cache. The typical usage is:


 Properties props = new Properties();
 props.put( "report", "report1.rpt" );
 props.put( "prompt0", "abc" );

 Cache cache = Cache.getCache();
 ReportCacheKey key = cache.getKey(props);
 cache.getPageAndWait( key, 12, 5 * 60 * 1000 );

 


Field Summary
static int TYPE_DATABASE
          Use a database as cache medium.
static int TYPE_EXTERNAL_DATABASE
          Use a database as cache medium.
static int TYPE_HARDDISK
          Use harddisk as cache medium.
static int TYPE_MEMORY
          Use memory as cache medium (default cache type).
 
Method Summary
 void addEngine(Engine engine, ReportCacheKey key)
          Save a rendered Engine in the cache.
 ReportCacheKey createKey(java.util.Properties props)
          This method is calling the method getKey() of the current EngineFactory only.
 ReportCacheKey createKey(java.util.Properties props, PropertiesChecker checker, java.lang.Object req)
          This method is calling the method getKey() of the current EngineFactory only.
 ReportCacheKey createKey(java.util.Properties props, PropertiesChecker checker, EngineFactory factory, java.lang.Object req)
          This method calls the method EngineFactory.getKey(Properties).
abstract  void delete(java.lang.String report)
          Delete all reports with the name from the cache.
abstract  void delete(ReportCacheKey key)
          Removes one report from the cache.
abstract  boolean exists(ReportCacheKey key)
          Verify if a ReportCacheKey exists in the cache.
static Cache getCache()
          Returns the singleton Cache instance.
static EngineFactory getEngineFactory()
          Get the current EngineFactory.
 java.lang.Throwable getFailureCause(ReportCacheKey key)
          Returns the cause for the failure of the report.
 ReportCacheKey getKey(java.util.Properties props)
          Create a ReportCacheKey and start rendering if report does not exist in the Cache.
 ReportCacheKey getKey(java.util.Properties props, PropertiesChecker checker, java.lang.Object req)
          Create a ReportCacheKey and start rendering if report does not exist in the Cache.
abstract  ReportCacheKey getKey(java.util.Properties props, PropertiesChecker checker, EngineFactory factory, java.lang.Object req)
          Create a ReportCacheKey and start rendering if report does not exist in the Cache.
 byte[] getPageAndWait(ReportCacheKey key, int page)
          The method returns the binary data of pages of a report.
abstract  byte[] getPageAndWait(ReportCacheKey key, int page, int timeout)
          The method returns the binary data of pages of a report.
 int getPageCountAndWait(ReportCacheKey key)
          Returns the total count of pages and blocks until the rendering is finished.
abstract  int getPageCountAndWait(ReportCacheKey key, int timeout)
          Returns the total count of pages and blocks until the rendering is finished.
abstract  ReportCacheKey[] getReports()
          Returns all reports that are currently listed in the Cache.
 int getTotalPageSizeAndWait(ReportCacheKey key)
          Returns the total size of all pages in bytes and blocks until the rendering is finished.
abstract  int getTotalPageSizeAndWait(ReportCacheKey key, int timeout)
          Returns the total size of all pages in bytes and blocks until the rendering is finished.
 int getType()
          Returns the defined Cache type.
 boolean isFailedReport(ReportCacheKey key)
          Returns whether the report was rendered without errors.
 boolean isFinishWrittenToStore(ReportCacheKey key)
          Asserts, whether the report is completly written into the store of the cache or not.
 boolean isFinished(ReportCacheKey key)
          Checks whether the rendering process is finished.
abstract  boolean isPageLimitExceeded(ReportCacheKey key)
          Check if the rendering of the report ran into a page limit.
 boolean isScheduleReport(ReportCacheKey key)
          Shows if the report is a schedule report.
static boolean isTypeSchedulerCache()
          This method indicates whether the cache stores reports come from i-net Scheduler only.
abstract  void lock(ReportCacheKey key)
          Lock the data in the cache and prevent it from modification.
 void resetCacheTimeout(ReportCacheKey key)
          Causes the timeout for the entry behind this key to be manually restarted.
static void setEngineFactory(EngineFactory engineFactory)
          You can override the default EngineFactory.
abstract  void setSchedule(ReportCacheKey key, boolean schedule)
          Defines a report in the Cache as a schedule report.
abstract  void unlock(ReportCacheKey key)
          Unlock the data in the cache.
 

Field Detail

TYPE_MEMORY

public static final int TYPE_MEMORY
Use memory as cache medium (default cache type).

Since:
6.0
See Also:
Constant Field Values

TYPE_DATABASE

public static final int TYPE_DATABASE
Use a database as cache medium. (i-net Clear Reports Plus only).

Since:
6.0
See Also:
Constant Field Values

TYPE_HARDDISK

public static final int TYPE_HARDDISK
Use harddisk as cache medium. (i-net Clear Reports Plus only).

Since:
6.0
See Also:
Constant Field Values

TYPE_EXTERNAL_DATABASE

public static final int TYPE_EXTERNAL_DATABASE
Use a database as cache medium. (i-net Clear Reports Plus only). The database connection must set from external.

Since:
7.5
See Also:
ExternalDBCache, Constant Field Values
Method Detail

getCache

public static Cache getCache()
Returns the singleton Cache instance.

Returns:
the current Cache

setEngineFactory

public static void setEngineFactory(EngineFactory engineFactory)
You can override the default EngineFactory. An EngineFactory you can use if you want to create or modify the Engine via RDC at runtime. The default implementation is loading a template from a *.rpt file.

Parameters:
engineFactory - the EngineFactory to set.
Throws:
java.lang.IllegalArgumentException - If the supplied EngineFactory is null.
See Also:
EngineFactory, getEngineFactory()

getEngineFactory

public static EngineFactory getEngineFactory()
Get the current EngineFactory.

Returns:
the EngineFactory currently set for the cache.
See Also:
EngineFactory, setEngineFactory(com.inet.report.cache.EngineFactory)

getKey

public ReportCacheKey getKey(java.util.Properties props)
                      throws ReportException
Create a ReportCacheKey and start rendering if report does not exist in the Cache. The Cache needs the ReportCacheKey to find the report in the Cache. If you are using the default EngineFactory, every property in Properties is used to make the ReportCacheKey. The default EngineFactory needs the parameter "report". To render the report in a special format e.g. "pdf", set the "export_fmt" property. The supported output formats are listed in the class Engine. Internal work:

Parameters:
props - The default Engine Factory need the parameter "report"
Returns:
a unique key for the report
Throws:
ReportException - e.g. if the reportfile does not exist
See Also:
setEngineFactory(EngineFactory), EngineFactory, ReportCacheKey, Engine

getKey

public ReportCacheKey getKey(java.util.Properties props,
                             PropertiesChecker checker,
                             java.lang.Object req)
                      throws ReportException
Create a ReportCacheKey and start rendering if report does not exist in the Cache. The Cache needs the ReportCacheKey, to find the report in the Cache. If you are using the default EngineFactory, every property in Properties is used to make the ReportCacheKey. The default EngineFactory needs the parameter "report". To render the report in a special format e.g. "pdf", set the "export_fmt" property. The supported output formats are listed in the class Engine. Internal work:

Parameters:
props - The default Engine Factory needs the parameter "report"
checker - an implementation of PropertiesChecker for validate the Properties. Can be null.
req - The HTTP servlet request, either null or HttpServletRequest
Returns:
a unique key for the report
Throws:
ReportException - e.g. if the reportfile does not exist
See Also:
setEngineFactory(EngineFactory), EngineFactory, ReportCacheKey, PropertiesChecker

getKey

public abstract ReportCacheKey getKey(java.util.Properties props,
                                      PropertiesChecker checker,
                                      EngineFactory factory,
                                      java.lang.Object req)
                               throws ReportException
Create a ReportCacheKey and start rendering if report does not exist in the Cache. The Cache needs the ReportCacheKey, to find the report in the Cache. If you are using the default EngineFactory, every property in Properties is used to make the ReportCacheKey. The default EngineFactory needs the parameter "report". To render the report in a special format e.g. "pdf", set the "export_fmt" property. The supported output formats are listed in the class Engine. Internal work: This method allows you to provide your own EngineFactory instance to be used instead of the system-wide instance set in setEngineFactory(EngineFactory).

Parameters:
props - The default Engine Factory needs the parameter "report"
checker - an implementation of PropertiesChecker for validate the Properties. Can be null.
factory - EngineFactory instance to use instead of the system-wide one set in setEngineFactory(EngineFactory).
req - The HTTP servlet request, either null or HttpServletRequest
Returns:
a unique key for the report
Throws:
ReportException - e.g. if the reportfile does not exist
Since:
9.2
See Also:
setEngineFactory(EngineFactory), EngineFactory, ReportCacheKey, PropertiesChecker

getPageAndWait

public final byte[] getPageAndWait(ReportCacheKey key,
                                   int page)
                            throws PageOutOfRangeException,
                                   KeyNotFoundException,
                                   ReportException
The method returns the binary data of pages of a report. Set the ReportCacheKey to define the report from that the data have to received ans set the page number to specify the page. How many pages a report has depends on the report and on the export format. The first page has index 1. The last page is the value return form getPageCountAndWait(ReportCacheKey, int)
If the page is not available yet then this method will wait until the page is available.

If executing the report failed because of an fatal error, this method will return a serialized Exception Object. The method Cache.isFailedReport(ReportCacheKey) will give the information whether report execution failed

Parameters:
key - the unique key to find the report in the Cache
page - the page number of the page, from which the binary data are returned. The first page has page number 1.
Returns:
the binary data for the Java Report Viewer or the bytes of the exported file (page). In case of a failed report the binary data contain a serialized Exception Object.
Throws:
PageOutOfRangeException - If the page is out of range after the report is finish rendered.
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
See Also:
getKey(Properties), getKey(Properties, PropertiesChecker, Object), getPageAndWait(ReportCacheKey, int, int), isFailedReport(ReportCacheKey)

getPageAndWait

public abstract byte[] getPageAndWait(ReportCacheKey key,
                                      int page,
                                      int timeout)
                               throws PageOutOfRangeException,
                                      KeyNotFoundException,
                                      ReportException
The method returns the binary data of pages of a report. Set the ReportCacheKey to define the report from that the data have to received ans set the page number to specify the page. How many pages a report has depends on the report and on the export format. The first page has index 1. The last page is the value return form getPageCountAndWait(ReportCacheKey, int)
If the page is not available yet then this method will wait until the page is available.

If executing the report failed because of an fatal error, this method will return a serialized Exception Object. The method Cache.isFailedReport(ReportCacheKey) will give the information whether report execution failed

Parameters:
key - the unique key to find the report in the Cache
page - the page number of the page, from which the binary data are returned. The first page has page number 1.
timeout - the maximum time that is wait in milli seconds, 0 means unlimited wait.
Returns:
the binary data for the Java Report Viewer or the bytes of the exported file (page). In case of a failed report the binary data contain a serialized Exception Object.
Throws:
PageOutOfRangeException - If the page is out of range after the report is finish rendered.
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
Since:
9.0
See Also:
getKey(Properties), getKey(Properties, PropertiesChecker, Object), isFailedReport(ReportCacheKey)

getPageCountAndWait

public final int getPageCountAndWait(ReportCacheKey key)
                              throws KeyNotFoundException,
                                     ReportException
Returns the total count of pages and blocks until the rendering is finished.

Parameters:
key - the key of the report
Returns:
the numbers of pages of a report
Throws:
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
See Also:
getPageAndWait(ReportCacheKey, int, int)

getPageCountAndWait

public abstract int getPageCountAndWait(ReportCacheKey key,
                                        int timeout)
                                 throws KeyNotFoundException,
                                        ReportException
Returns the total count of pages and blocks until the rendering is finished.

Parameters:
key - the key of the report
timeout - the maximum time that is wait in milli seconds, 0 means unlimited wait.
Returns:
the numbers of pages of a report
Throws:
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
Since:
9.0
See Also:
getPageAndWait(ReportCacheKey, int, int)

getTotalPageSizeAndWait

public final int getTotalPageSizeAndWait(ReportCacheKey key)
                                  throws KeyNotFoundException,
                                         ReportException
Returns the total size of all pages in bytes and blocks until the rendering is finished.

Parameters:
key - the key of the report
Returns:
the size of all pages from the report together
Throws:
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
See Also:
getPageAndWait(ReportCacheKey, int, int), getPageCountAndWait(ReportCacheKey, int)

getTotalPageSizeAndWait

public abstract int getTotalPageSizeAndWait(ReportCacheKey key,
                                            int timeout)
                                     throws KeyNotFoundException,
                                            ReportException
Returns the total size of all pages in bytes and blocks until the rendering is finished.

Parameters:
key - the key of the report
timeout - the maximum time that is wait in milli seconds, 0 means unlimited wait.
Returns:
the size of all pages from the report together
Throws:
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
Since:
9.0
See Also:
getPageAndWait(ReportCacheKey, int, int), getPageCountAndWait(ReportCacheKey,int)

isPageLimitExceeded

public abstract boolean isPageLimitExceeded(ReportCacheKey key)
                                     throws KeyNotFoundException,
                                            ReportException
Check if the rendering of the report ran into a page limit. This means does not all possible pages exist.

Parameters:
key - the key of the report
Returns:
true, if there is a limit and the report is finish
Throws:
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
Since:
10.0

lock

public abstract void lock(ReportCacheKey key)
                   throws KeyNotFoundException,
                          ReportException
Lock the data in the cache and prevent it from modification. This is required if you stream a document like *.pdf in multiple parts.

Parameters:
key - the key of the report
Throws:
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
See Also:
unlock(ReportCacheKey)

unlock

public abstract void unlock(ReportCacheKey key)
                     throws KeyNotFoundException,
                            ReportException
Unlock the data in the cache.

Parameters:
key - the key of the report
Throws:
KeyNotFoundException - If the key does not exist in the cache. This can occur if the key has received its timeout and was removed from the cache. You can change the cache timeout in the Cache Config Dialog.
ReportException - e.g. if using DBCache and something went wrong with database connection
See Also:
lock(ReportCacheKey), lock(ReportCacheKey)

addEngine

public void addEngine(Engine engine,
                      ReportCacheKey key)
               throws ReportException
Save a rendered Engine in the cache. This method can be used if you have created an Engine outside of the cache. A typical use is:
 Cache cache = Cache.getCache();
 ReportCacheKey key = cache.createKey(props);

 if(!cache.exists(key)){
   Engine engine = new Engine();
   engine.setReportName( props.get( "report" );
   engine.execute();
   cache.addEngine( engine, key );
 }

 cache.getPageAndWait( key, 12 );
 

Parameters:
engine - the executed engine
key - the key created for that report
Throws:
ReportException - e.g. if there already exists a report in the cache for the key. Possible solution is to call Cache.createKey() with an additional Property or call Cache.delete() with reportname.

exists

public abstract boolean exists(ReportCacheKey key)
Verify if a ReportCacheKey exists in the cache.

Parameters:
key - the key of the report
Returns:
true: the report exists in the cache.
false: the report does not exist in the cache
See Also:
getKey(Properties), getKey(Properties, PropertiesChecker, Object)

createKey

public ReportCacheKey createKey(java.util.Properties props)
                         throws ReportException
This method is calling the method getKey() of the current EngineFactory only. It is not starting a render job. The default Engine Factory needs the parameter "report"

Parameters:
props - Properties for the report
Returns:
the created key
Throws:
ReportException - will be thrown if no value for the key "report" can be found in Properties
See Also:
getKey(Properties, PropertiesChecker, Object), createKey(Properties, PropertiesChecker, Object), EngineFactory

createKey

public ReportCacheKey createKey(java.util.Properties props,
                                PropertiesChecker checker,
                                java.lang.Object req)
                         throws ReportException
This method is calling the method getKey() of the current EngineFactory only. It is not starting a render job. If the property "cache.clearOnRequest" is true, the cache will be cleared first.

Parameters:
props - Properties for the report
checker - an implementation of PropertiesChecker for validate the Properties. Can be null.
req - The HTTP servlet request, either null or HttpServletRequest
Returns:
the created key to use with the cache
Throws:
ReportException - If an error occured while checking the supplied properties by the PropertiesChecker or while creating the key in the EngineFactory of the cache.
Since:
7.0
See Also:
getKey(Properties, PropertiesChecker, Object), EngineFactory

createKey

public ReportCacheKey createKey(java.util.Properties props,
                                PropertiesChecker checker,
                                EngineFactory factory,
                                java.lang.Object req)
                         throws ReportException
This method calls the method EngineFactory.getKey(Properties). Note it does not start the render job yet. This method also gives you the opportunity to provide your own EngineFactory instead of the system-wide one set in setEngineFactory(EngineFactory).

Parameters:
props - Properties for the report
checker - an implementation of PropertiesChecker for validate the Properties. Can be null.
factory - EngineFactory instance to use (can be different than the system-wide one set in setEngineFactory(EngineFactory)
req - The HTTP servlet request, either null or HttpServletRequest
Returns:
the created key to use with the cache
Throws:
ReportException - If an error occured while checking the supplied properties by the PropertiesChecker or while creating the key in the EngineFactory of the cache.
Since:
9.2
See Also:
getKey(Properties, PropertiesChecker, Object), EngineFactory

delete

public abstract void delete(java.lang.String report)
                     throws ReportException
Delete all reports with the name from the cache. If one or more of the reports are locked the method will not return until it has deleted all of the reports. The deletion will be done sequentially, with no guaranteed ordering.

Parameters:
report - name of the report
Throws:
ReportException - e.g. if using DBCache and something went wrong with database connection

delete

public abstract void delete(ReportCacheKey key)
                     throws ReportException
Removes one report from the cache. If the key is locked, this method will not return until the key is unlocked.

Parameters:
key - The ReportCacheKey of the report.
Throws:
ReportException - e.g. if using DBCache and something went wrong with database connection
Since:
6.0
See Also:
lock(ReportCacheKey), unlock(ReportCacheKey)

isFinished

public boolean isFinished(ReportCacheKey key)
                   throws ReportException
Checks whether the rendering process is finished.
After rendering process is finished, all pages of the report are available.

Parameters:
key - This key is checked
Returns:
true if report is completely rendered.
false if report is not completely rendered.
Throws:
ReportException - e.g. if using DBCache and something went wrong with database connection
See Also:
isFinishWrittenToStore(ReportCacheKey), getPageAndWait(ReportCacheKey, int, int), getPageCountAndWait(ReportCacheKey, int), getTotalPageSizeAndWait(ReportCacheKey, int)

getReports

public abstract ReportCacheKey[] getReports()
                                     throws ReportException
Returns all reports that are currently listed in the Cache.

Returns:
all reports that are currently listed in the Cache.
Throws:
ReportException - If an error has occurred during cache request
Since:
6.0

isFinishWrittenToStore

public boolean isFinishWrittenToStore(ReportCacheKey key)
                               throws ReportException,
                                      KeyNotFoundException
Asserts, whether the report is completly written into the store of the cache or not.
This method is only relevant if you're using DatabaseCache or Harddiskcache. The MemoryCache
does not have a store.
It's only necessary to wait on true if you want to skip your application after writing a report in the cache.

Parameters:
key - The ReportCacheKey for the report
Returns:
true if the report for that key is completely written into the store or an error occur.
Throws:
KeyNotFoundException - will be thrown if no report for that key exists in the cache.
ReportException - e.g. if using DBCache and something went wrong with database connection
See Also:
isFinished(ReportCacheKey), isFailedReport(ReportCacheKey)

setSchedule

public abstract void setSchedule(ReportCacheKey key,
                                 boolean schedule)
                          throws ReportException
Defines a report in the Cache as a schedule report. A schedule report cannot be deleted until it is reset to being a non schedule report. Because of the Cache architecture setting this flag will not work safely if this report is in execution, the flag can be overwritten in the meantime. Call this method only for a finished executed and finished stored report. The best way to define a report as schedule report is call Cache.getKey() with the property "getscheduleinprocessreport=true".

Parameters:
schedule - To set or reset a report as schedule report.
key - The key belongs to the report.
Throws:
java.lang.UnsupportedOperationException - If the Cache is the MemoryCache. It is supported in the harddisk cache and database cache.
ReportException - If there is no respective report in the cache.
Since:
6.0
See Also:
getType()

isScheduleReport

public boolean isScheduleReport(ReportCacheKey key)
                         throws ReportException
Shows if the report is a schedule report.

Parameters:
key - The key belongs to the report.
Returns:
If the report is a schedule report.
Throws:
ReportException - If there is no respective report in the cache.
Since:
6.0

isFailedReport

public boolean isFailedReport(ReportCacheKey key)
                       throws ReportException
Returns whether the report was rendered without errors. Call this method after the report rendering has been finished.
If report execution failed, you can receive the exception object calling getFailureCause(ReportCacheKey).

Parameters:
key - The key belongs to the report.
Returns:
If the report was rendered without errors.
Throws:
ReportException - If there is no respective report in the cache.
Since:
6.0

getFailureCause

public java.lang.Throwable getFailureCause(ReportCacheKey key)
                                    throws ReportException
Returns the cause for the failure of the report. This method should be called after the report rendering has been finished. If the report execution failed this will return the cause for the failure. If the report execution finished without any error this will return null.

Parameters:
key - The key identifying the report.
Returns:
The failure cause of the report execution or null if the report rendered successfully.
Throws:
ReportException - If there is no respective report in the cache.
Since:
8.0

getType

public int getType()
Returns the defined Cache type. Possible return values are:
0 - Memory Cache
1 - Database Cache
2 - Harddisk Cache
3 - External Database Cache


The type of cache is defined in the configuration.
The parameter that define the cache type is cache.type

Returns:
the defined Cache type.
Since:
6.0
See Also:
TYPE_MEMORY, TYPE_DATABASE, TYPE_HARDDISK, TYPE_EXTERNAL_DATABASE, isTypeSchedulerCache()

isTypeSchedulerCache

public static boolean isTypeSchedulerCache()
This method indicates whether the cache stores reports come from i-net Scheduler only.
For more information about i-net Scheduler, please have a look at i-net Scheduler documentation

Returns:
whether the cache stores reports come from i-net Scheduler only.

resetCacheTimeout

public void resetCacheTimeout(ReportCacheKey key)
Causes the timeout for the entry behind this key to be manually restarted. This method should be used to communicate that the cache entry behind the given key is still needed and should not yet be removed from the cache.

If there is no entry associated with the given key, this will not restart creation of the entry.

Parameters:
key - Key of the entry whose cache timeout is to be reset.

i-net Clear Reports

Copyright © 1999-2011 by i-net software GmbH