public class ReportWorker extends AbstractPatternWorker implements ReportConstants
PatternEngine
with a set of
user-defined functions and variables for manually and/or automatically
creating categories, adding matches as well as functions to generate both
summary and detailed reports.Modifier and Type | Class and Description |
---|---|
class |
ReportWorker.Library
Provides a service for defining and matching conditions on a manual
basis (see
ReportWorker.Library.addMatchCategory(long, java.lang.String, int) and ReportWorker.Library.addMatch(long, boolean, java.lang.String, java.lang.String) ) and/or on
an automated basis (see ReportWorker.Library.addMatchMultiplexed(long, boolean, java.lang.String, int) ). |
Modifier and Type | Field and Description |
---|---|
private boolean |
analyzed
Flag indicating whether database table has been analyzed
|
private java.sql.Connection |
connection
Database connection
|
private static java.lang.String |
dbPass
Default database password.
|
private java.lang.String |
dbURL
Database URL
|
private static java.lang.String |
dbUser
Default database user.
|
private static java.lang.String |
EXT_CACHE
File name extension for a preprocessed source file.
|
private java.util.Map<java.lang.String,java.lang.Long> |
file2ID
Filename to ID mappings
|
private java.util.Map<java.lang.Long,java.lang.String> |
id2File
ID to filename mappings
|
private static java.util.Map<java.lang.String,java.lang.Integer> |
levelConstants
Stores summary report data to build a master index of reports.
|
static java.lang.String |
MASTER_INDEX_CACHE
Cache file for master index and categories data.
|
private AstManager |
mgr
Quick access to the registry for AST ID and filename lookups.
|
private static java.lang.String |
NOTE_SRCFILE
Key for the source file annotation in a root AST.
|
private static java.lang.String |
REL_PREFIX
Prefix for a relative file path.
|
private java.sql.PreparedStatement |
stmtAllStatsQueryByRpt
Database match and file all stats by report query statement
|
private java.sql.PreparedStatement |
stmtAstMapInsert
Database ast_map insert statement.
|
private java.sql.PreparedStatement |
stmtDelRptStats
Database delete stats by report statement
|
private java.sql.PreparedStatement |
stmtFidByFilename
Database file id from file name query statement.
|
private java.sql.PreparedStatement |
stmtFileFltDelete
Database file_filter delete statement.
|
private java.sql.PreparedStatement |
stmtFileFltInsert
Database file_filter insert statement.
|
private java.sql.PreparedStatement |
stmtFileInsert
Database file insert statement.
|
private java.sql.PreparedStatement |
stmtFileQuery
Database file ids query statement.
|
private java.sql.PreparedStatement |
stmtFltPrfInsert
Database filter_profile insert statement.
|
private java.sql.PreparedStatement |
stmtFltPrfUpdate
Database filter_profile update statement.
|
private java.sql.PreparedStatement |
stmtMatchCatInsert
Database match category insert statement.
|
private java.sql.PreparedStatement |
stmtMatchInsert
Database match insert statement.
|
private java.sql.PreparedStatement |
stmtMatchQueryByStat
Database match query for records by match category.
|
private java.sql.PreparedStatement |
stmtReportInsert
Database report insert statement.
|
private java.sql.PreparedStatement |
stmtRptCellInsert
Database report_cell insert statement.
|
private java.sql.PreparedStatement |
stmtRptColInsert
Database report_column insert statement.
|
private java.sql.PreparedStatement |
stmtRptStatsInsert
Database report_stats insert statement.
|
private java.sql.PreparedStatement |
stmtRptTagInsert
Database report_tag insert statement.
|
private java.sql.PreparedStatement |
stmtSrcLineInsert
Database source_line insert statement.
|
private java.sql.PreparedStatement |
stmtStatsQueryByRpt
Database match and file stats by report query statement
|
private java.sql.PreparedStatement |
stmtTagInsert
Database tag insert statement.
|
private static java.util.Map<java.lang.String,java.lang.Long> |
tags
Stores all tags used in the master index of reports.
|
resolver
CVT_LVL_BASIC, CVT_LVL_FULL, CVT_LVL_FULL_RESTR, CVT_LVL_MASK, CVT_LVL_NONE, CVT_LVL_PARTIAL, LVL_UNKNOWN, RT_LVL_BASIC, RT_LVL_FULL, RT_LVL_FULL_RESTR, RT_LVL_MASK, RT_LVL_NONE, RT_LVL_PARTIAL, RT_LVL_STUB, RT_LVL_UNTESTED, SORT_ALL, SORT_NONE, SORT_NOT_LAST, SRC_CODE_BASE, SRC_CODE_CACHE, SRC_SCHEMA, SRC_UNKNOWN
Constructor and Description |
---|
ReportWorker()
Default constructor which calls the super-class constructor, registers
its libraries and initializes its instance members.
|
ReportWorker(java.sql.Connection connection)
Constructor which accepts an externally provided database connection.
|
Modifier and Type | Method and Description |
---|---|
private void |
analyzeDatabase()
Creates an index on the cid and fid columns for the match table,
and runs analyze on the database.
|
private void |
closeConnection()
Close the current connection
|
private void |
createDatabaseTables()
Opens a connection to the H2 database (in the ./rptdb/rptdb file) and creates all needed
database tables and indices.
|
private void |
openConnection(boolean safe)
Open a new connection to the report database (if one already opened,
it will close it first).
|
private void |
prepareStatements(java.sql.Connection provided,
boolean safeConnection)
Create all prepared statements needed to run reports.
|
java.lang.Object |
resolveConstant(java.lang.String constant)
This method is called each time the pattern engine needs to resolve
a string constant into a numeric, boolean, or string literal value.
|
long |
saveFilterProfile(FilterProfile profile,
FileFilter[] filters)
Save a file filter profile in the report database
|
long |
saveReport(ReportDefinition rpt,
boolean databaseMode,
boolean processTags)
Save a report definition in the report database.
|
finish, getCopy, getLibrary, getSource, initialize, registerTree, setLibrary, visitAst
public static final java.lang.String MASTER_INDEX_CACHE
private static final java.lang.String NOTE_SRCFILE
private static final java.lang.String EXT_CACHE
private static final java.lang.String REL_PREFIX
private static java.util.Map<java.lang.String,java.lang.Long> tags
private static java.lang.String dbUser
private static java.lang.String dbPass
private static java.util.Map<java.lang.String,java.lang.Integer> levelConstants
private java.lang.String dbURL
private AstManager mgr
private java.util.Map<java.lang.String,java.lang.Long> file2ID
private java.util.Map<java.lang.Long,java.lang.String> id2File
private java.sql.Connection connection
private java.sql.PreparedStatement stmtFileInsert
private java.sql.PreparedStatement stmtAstMapInsert
private java.sql.PreparedStatement stmtSrcLineInsert
private java.sql.PreparedStatement stmtTagInsert
private java.sql.PreparedStatement stmtReportInsert
private java.sql.PreparedStatement stmtRptTagInsert
private java.sql.PreparedStatement stmtRptColInsert
private java.sql.PreparedStatement stmtRptCellInsert
private java.sql.PreparedStatement stmtRptStatsInsert
private java.sql.PreparedStatement stmtMatchInsert
private java.sql.PreparedStatement stmtMatchQueryByStat
private java.sql.PreparedStatement stmtMatchCatInsert
private java.sql.PreparedStatement stmtFltPrfInsert
private java.sql.PreparedStatement stmtFltPrfUpdate
private java.sql.PreparedStatement stmtFileFltInsert
private java.sql.PreparedStatement stmtFileFltDelete
private java.sql.PreparedStatement stmtFileQuery
private java.sql.PreparedStatement stmtFidByFilename
private java.sql.PreparedStatement stmtAllStatsQueryByRpt
private java.sql.PreparedStatement stmtStatsQueryByRpt
private java.sql.PreparedStatement stmtDelRptStats
private boolean analyzed
public ReportWorker() throws AstException
AstException
- if the AST manager has not been initialized.public ReportWorker(java.sql.Connection connection)
connection
- Database connection.public long saveReport(ReportDefinition rpt, boolean databaseMode, boolean processTags) throws java.sql.SQLException
rpt
- Report definition to be saved.databaseMode
- True
if this is a schema report; false
if a code report.processTags
- True
to process report category tags; else false
.java.sql.SQLException
- if there is any database error.public long saveFilterProfile(FilterProfile profile, FileFilter[] filters) throws java.sql.SQLException
profile
- The profile to save. If this profile already has a valid primary key ID, update
the existing profile record and replace all associated file filters; otherwise,
insert a new profile record and insert all associated file filters.filters
- The filters associated with the profile.java.sql.SQLException
- if there is any database error.java.lang.RuntimeException
- if the filter profile record could not be updated or inserted.public java.lang.Object resolveConstant(java.lang.String constant)
resolveConstant
in interface PatternWorker
resolveConstant
in class AbstractPatternWorker
constant
- A case-insensitive support level name to be resolved to a bitmask.Integer
value associated with the given constant
or null
if there is no matching constant.private void createDatabaseTables()
java.lang.RuntimeException
- if there were errors during database creation.private void prepareStatements(java.sql.Connection provided, boolean safeConnection)
provided
- Optional database connection. If not provided, a new connection will be opened.safeConnection
- If provided
is null
, true
to include logging, transaction
logging, and locking in the connection parameters for a newly opened database
connection; false
to omit these parameters. Ignored if an external
connection is provided.private void openConnection(boolean safe)
safe
- true
to include logging, transaction logging, and locking in the connection
parameters; false
to omit these parameters.java.lang.RuntimeException
- if new connection could not be established.private void closeConnection()
java.lang.RuntimeException
- if connection could not be closed.private void analyzeDatabase()
java.lang.RuntimeException
- if there were errors during index creation or
analyze.