#include <BatchCommand.hh>
Inherited by fatalmind::oracle::OptimizedBatchCommand< CommandType >, and fatalmind::SQL::SQLBatchCommand< CommandType >.
Execution of commands stops in case an exception is thrown. BatchCommand's can also be nested.
Public Types | ||||
typedef CommandType | innercommand_t | |||
typedef list_t::const_iterator | const_iterator | |||
Public Member Functions | ||||
BatchCommand (bool cont=false) | ||||
Creates a new (empty) Batch of commands. | ||||
BatchCommand (const BatchCommand &) | ||||
virtual void | add (const CommandType &) | |||
Adds a command to the batch. | ||||
virtual void | execute (typename CommandType::pool_type::resource_t &) | |||
int | getError () | |||
Returns the number of the command which failed during execution. | ||||
const_iterator | getExecPosition () const | |||
returns the current execution position. | ||||
bool | doesContinue () const | |||
A Predicate if the continuation mode is enabled in this command. | ||||
const_iterator | end () const | |||
Returns an iterator beyond the last command in the batch. | ||||
const_iterator | begin () const | |||
Returns an interator to the first command in the batch. | ||||
bool | empty () const | |||
| ||||
virtual void | outputoperator (std::ostream &) const | |||
Static Public Attributes | ||||
static const int | NOT_STARTED = -1 | |||
static const int | NO_FURTHER_ERROR = -2 | |||
Protected Types | ||||
typedef gc_ptr < CommandType > | member_t | |||
typedef std::vector < member_t > | list_t | |||
typedef std::vector < int > | errors_t | |||
Protected Member Functions | ||||
virtual Clone * | DoClone () const | |||
member_t | getLast () const | |||
bool | wasStarted () const | |||
Protected Attributes | ||||
const_iterator | exec_pos | |||
errors_t | errors | |||
unsigned int | error_pos |
fatalmind::BatchCommand< CommandType >::BatchCommand | ( | bool | cont = false |
) | [inline] |
Creates a new (empty) Batch of commands.
The cont flag specifies if the continuation mode will be active for this batch.
Per default the batch can be executed several time and will always start from beginning (even in case a previous execution stoped because of an error).
In continuation mode repetative executons will continue the batch's execution after the position where the last execution stoped. This is useful to continue execution after an error. The command which caused the error will not be re-executed. If all batched commands were executed subsequent executions of the batch will do nothing.
When using the continuation mode it is required to execute the batch until it completed without error. Otherwise it is undefined which statements were acutally executed and which not.
see BatchCommand::getExecPosition() see BatchCommand::getError()
void fatalmind::BatchCommand< CommandType >::add | ( | const CommandType & | cmd | ) | [inline, virtual] |
Adds a command to the batch.
The command will be added to the end of the batch like push_back for vectros.
Please note that adding commands to an Batch is not allowed after the batch was executed(), not even if the execution aborted due to an exception.
Reimplemented in fatalmind::oracle::OptimizedBatchCommand< CommandType >.
int fatalmind::BatchCommand< CommandType >::getError | ( | ) | [inline] |
Returns the number of the command which failed during execution.
Can be used together with BatchCommand::begin() to obtain the command which failed:
int error = batchcommand.getError(); if (error >= 0) { Command& failed = *(batchcommand.begin() + error); }
In continuation mode (see BatchCommand::BatchCommand()) getError() will return all errors, one for every call. To fetch all errors use a structure like this:
while (b.getExecPosition() != b.end()) { try { p.execute(b); } catch (...) { // each unsuccessful execution will deliver one error p::Command::Base& failed = *(b.begin() + b.getError()); } }
The getError() method returns only the errors which already happend. After unsuccessful execution of a batch, it is guaranteed that getError() one error, after the next unsuccessful execution the next will be available.
You could also execute the batch first (until no error) and then fetch all failed commands.
>=0 | Index of a failed command | |
<0 | non-error conditions. Listed below | |
BatchCommand::NOT_STARTED | in case the execution was not yet started | |
BatchCommand::NO_FURTHER_ERROR | in case no further errors are available (yet) |
BatchCommand< CommandType >::const_iterator fatalmind::BatchCommand< CommandType >::getExecPosition | ( | ) | const [inline] |
returns the current execution position.
required to determine if the batch has been executed completley. if equals end() the batch was fully executed.
bool fatalmind::BatchCommand< CommandType >::doesContinue | ( | ) | const [inline] |
A Predicate if the continuation mode is enabled in this command.
true | If the continuation mode is enabled | |
false | otherwise |
BatchCommand< CommandType >::const_iterator fatalmind::BatchCommand< CommandType >::begin | ( | ) | const [inline] |
Returns an interator to the first command in the batch.
will equals to end() if the batch is empty.
bool fatalmind::BatchCommand< CommandType >::empty | ( | ) | const [inline] |
true | if the batch is empty. |
else | if there is at lease one command in the batch. |