#include <Assertion.h>
Public Member Functions | |
Assertion (Operator *op=0, Table *myTable=0, bool keepOp=false) | |
Assertion (const Assertion *orig, Row *toBe) | |
~Assertion () | |
Visitor::VisitorState | accept (Visitor *v) |
Operator * | getOperator () const |
const std::string & | getPrecompiled () const |
bool | getToBe () const |
bool | getOld () const |
const std::string & | getName () const |
void | setName (const std::string &name) |
bool | verify (Row &old, Row &toBe) const |
Private Attributes | |
Operator * | m_op |
The heart of an Assertion is an Operator. | |
Table * | m_myTable |
bool | m_keepOp |
std::string | m_name |
Assertions have names so that they can be referenced elsewhere. | |
std::string | m_compiled |
Classes | |
class | Operator |
The bulk of the information comprising an assertion is kept in a tree whose nodes are "operations". An operation may be either a comparison ( =, <=, etc. and also "is null") or an operation which has child operations: OR, AND, NOT, for all, there exists, hence a node is a leaf node iff it's a comparison.
Once an operation has been incorporated into an Assertion or into another operation, it is 'owned' by this parent. Deleting the parent will cause its children to be deleted. Hence applications building assertions out of operators should never delete those operators.
Definition at line 56 of file Assertion.h.
rdbModel::Assertion::Assertion | ( | Operator * | op = 0 , |
|
Table * | myTable = 0 , |
|||
bool | keepOp = false | |||
) | [inline] |
Normally, operator associated with the assertion will be deleted when the assertion itself is deleted, but this won't happen if keepOp is set to true.
Definition at line 180 of file Assertion.h.
References m_compiled, and m_name.
00180 : 00181 m_op(op), m_myTable(myTable), m_keepOp(keepOp) 00182 { m_compiled.clear(); m_name.clear();};
Copy original assertion, but, wherever a colRef is a "toBe", substitute with value from toBe row. toBe is not const because we may need to sort it.
Definition at line 23 of file Assertion.cxx.
References m_op, and rdbModel::Row::rowSort().
00024 : m_op(0), m_myTable(orig->m_myTable), m_keepOp(false), m_name(""), 00025 m_compiled("") { 00026 toBe->rowSort(); 00027 m_op = new Assertion::Operator(orig->m_op, toBe); 00028 00029 }
rdbModel::Assertion::~Assertion | ( | ) |
Visitor::VisitorState rdbModel::Assertion::accept | ( | Visitor * | v | ) |
Definition at line 344 of file Assertion.cxx.
References v, rdbModel::Visitor::VBRANCHDONE, and rdbModel::Visitor::VCONTINUE.
00344 { 00345 Visitor::VisitorState state = v->visitAssertion(this); 00346 if (state == Visitor::VBRANCHDONE) return Visitor::VCONTINUE; 00347 return state; 00348 }
const std::string& rdbModel::Assertion::getName | ( | ) | const [inline] |
bool rdbModel::Assertion::getOld | ( | ) | const [inline] |
Returns true if associated operator or descendant refers to existing row
Definition at line 205 of file Assertion.h.
References rdbModel::Assertion::Operator::getOld(), and m_op.
Referenced by verify().
Operator* rdbModel::Assertion::getOperator | ( | ) | const [inline] |
Definition at line 195 of file Assertion.h.
References m_op.
Referenced by rdbModel::MysqlConnection::compileAssertion().
00195 {return m_op;}
const std::string& rdbModel::Assertion::getPrecompiled | ( | ) | const [inline] |
bool rdbModel::Assertion::getToBe | ( | ) | const [inline] |
True if associated operator or descendant refers to future row (in which case can't call MySql::compileAssertion)
Definition at line 201 of file Assertion.h.
References rdbModel::Assertion::Operator::getToBe(), and m_op.
Referenced by verify().
void rdbModel::Assertion::setName | ( | const std::string & | name | ) | [inline] |
verify checks if assertion (which may refer to one or both of an old row and a proposed row) holds for these arguments. Caller is responsible for fetching old row fields out of dbs if necessary May throw RdbException
Definition at line 350 of file Assertion.cxx.
References getOld(), getToBe(), m_myTable, m_op, rdbModel::Row::rowSort(), and rdbModel::Assertion::Operator::verify().
Referenced by rdbModel::Table::insertLatest(), rdbModel::Table::insertRow(), and main().
00350 { 00351 00352 if (getOld() ) { // will actually use old vector, so sort 00353 old.rowSort(); 00354 } 00355 if (getToBe() ) { // will actually use toBe vector, so sort 00356 toBe.rowSort(); 00357 } 00358 return m_op->verify(old, toBe, m_myTable); 00359 }
std::string rdbModel::Assertion::m_compiled [private] |
Let's hope that, independent of connection type, std::string is a reasonable choice for "compiled" form of the assertion
Definition at line 230 of file Assertion.h.
Referenced by Assertion(), and getPrecompiled().
bool rdbModel::Assertion::m_keepOp [private] |
m_keepOp indicates whether or not we're responsible for cleaning up resources
Definition at line 224 of file Assertion.h.
Referenced by ~Assertion().
Table* rdbModel::Assertion::m_myTable [private] |
std::string rdbModel::Assertion::m_name [private] |
Assertions have names so that they can be referenced elsewhere.
Definition at line 226 of file Assertion.h.
Referenced by Assertion(), getName(), and setName().
Operator* rdbModel::Assertion::m_op [private] |
The heart of an Assertion is an Operator.
Definition at line 220 of file Assertion.h.
Referenced by Assertion(), getOld(), getOperator(), getToBe(), verify(), and ~Assertion().