Class Information
Package: com.onepg.bat
Class Name: AbstractDbAccessBatch (Abstract Class)
Description
Base class for database access batch processing.
- Base class for batch processing that includes database connections.
- Automatically handles database connection acquisition and closing.
- Provides common processing (logging, exception handling, etc.) for each batch.
- Subclasses define specific batch processing by implementing the
doExecutemethod. - When a subclass calls the
callMainmethod of this class from themainmethod, thedoExecutemethod is executed. - Arguments to the subclass
mainmethod are assumed to be passed as-is to thecallMainmethod in URL parameter format. - Arguments in URL parameter format are converted to map format and passed to the
doExecutemethod as anIoItemsinstance. - When an error occurs in the subclass
doExecutemethod, it is assumed to throw an Exception. - The return value of the
callMainmethod on successful completion is 0. - The return value of the
callMainmethod when an Exception is thrown in thedoExecutemethod is 1.
[Implementation Example] public class ExampleBatch extends AbstractDbAccessBatch {
public static void main(String[] args) {
System.exit((new ExampleBatch()).callMain(args));
}
Constants and Variables
traceCode
protected String traceCode
Trace code.
logger
protected LogWriter logger
Log writer.
Method List
doExecute (Abstract Method)
protected void doExecute(IoItems args)
Main processing.
- Subclasses implement specific batch processing.
Parameters
| Name | Type | Description |
|---|---|---|
args |
IoItems |
arguments |
callMain
protected int callMain(String[] args)
Invokes main processing.
- Converts arguments from URL parameter format to map format, executes log start processing, and then calls the
doExecutemethod. - Accepts multiple arguments as an array to handle length limitations per command line argument.
- The converted arguments are passed to the
doExecutemethod as anIoItemsinstance. - If an Exception is thrown in the
doExecutemethod, the processing is considered to have terminated abnormally. - Commits when the processing completes successfully.
- Rolls back when the processing terminates abnormally. (The rollback itself is performed by
Connection#close()) - Always closes the database connection after processing ends.
Parameters
| Name | Type | Description |
|---|---|---|
args |
String[] |
arguments |
Return Value
int - 0 on successful completion, 1 on abnormal termination
getDbConn
protected Connection getDbConn()
Retrieves database connection.
- Returns the current database connection.
- The connection is valid only within the
callMainmethod.
Return Value
Connection - the database connection