Reference‎ > ‎

The recompute utility

Sometimes the data in your database may not obey the rules you have defined in your logic classes. There could be several reasons for this:
  • you may have changed the rules
  • the data may have been changed independently (e.g. SQL update)
  • there may have been a bug in the rules

Regardless of why, you need to be able to detect this situation, and to fix it. ABL provides the recompute utility for this purpose.

Getting the recompute utility

Recompute is available as a separate package. You can download it from the current download page.

Recompute has dependencies that are essentially the same as any ABL application:

 Library Comments
 autobizlogic version 2.0a or later
 ablrecompute version 2.0a or later
 ant version 1.7 or later
 hibernate version 3.6.0 or later, along with all required libraries
 slf4j version 1.6.0 or later
 log4j version 1.2 or later
 groovy version 1.8.x
 commons-logging version 1.1.1
 commons-beanutils version 1.8 or later
 commons-jexl version 2.1 or later

Running recompute

Before running Recompute, you'll need to make sure that your Java class path includes the required libraries (as listed above), as well as the JDBC driver(s), your logic classes, and your bean classes (if relevant).

Recompute can run in one of three modes:
  • scan simply checks the database and creates a report listing all errors. No data is changed in the database.
  • plan checks the database and generates a report showing the HQL statements that would need to be run to fix the problems. No data is changed in the database.
  • fix actually fixes all possible errors in the database.

Running Recompute can be done in three ways:


The Recompute utility will write a report file outlining what it has found out and/or what it has done. The only time it will not write a report file is if has not found any errors.

In scan mode, you will almost always want to use the xml output format. The report will outline what errors have been found, along with a sample of the incorrect data (up to 100 rows per error).

A sample XSL stylesheet is provided to format this XML report into an HTML page. You can use it in an Ant script as follows:
<target name="formatReport">
<xslt in=".../RecomputeReport.xml" out=".../RecomputeReport.html">
       <file file=".../XmlReport.xsl" />

In plan mode, you will typically use either the xml output format or the sql output format. The sql output format shows what HQL statements would have to be run in order to fix the data.

In fix mode, you will also use either the xml output format or the sql output format.

If you prefer to have your own formatting for the report, you can create a class that implements the com.autobizlogic.recompute.format.ReportFormatter interface, and pass that class' name to the Recompute utility.

Special recompute annotations

There are two special annotations that will influence the execution of recompute.

Formulas can be skipped during recompute with the following parameter:

@Formula(value="price + tax", skipDuringRecompute = true)
public void deriveTotal() { }

By default, formulas are not skipped during recompute. If you need a formula to be skipped, you need to specify the skipDuringRecompute parameter.

Actions (including EarlyActions and CommitActions) are normally not invoked during recompute. You can change this behavior with the following:

public void myAction() {
    // Do something here

Note that actions will be invoked only in fix mode. This is because actions can often affect the state of the database, or of some other system, and that's of course desirable only if you really mean to fix the data.

Recompute listener

When the recompute utility executes, it can notify a listener class of its progress, and the listener can also affect how the utility executes.

To create a recompute listener, you need to implement the com.autobizlogic.recompute.RecomputeListener interface. In many cases, you'll want to subclass com.autobizlogic.recompute.EmptyRecomputeListener, which implements the full interface, but doesn't actually do anything, and then override whichever methods you're interested in.

Once you have a recompute listener class, you can specify it to the recompute utility by using the parameter appropriate for your invocation method.