rdbModel::Assertion Class Reference

#include <Assertion.h>

List of all members.

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)
OperatorgetOperator () const
const std::stringgetPrecompiled () const
bool getToBe () const
bool getOld () const
const std::stringgetName () const
void setName (const std::string &name)
bool verify (Row &old, Row &toBe) const

Private Attributes

Operatorm_op
 The heart of an Assertion is an Operator.
Tablem_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


Detailed Description

Assertions are used in at least two ways: 1. As part of a table description. The assertion describes a condition which should be evaluated upon a particular event, such as when a new element is to be inserted. Such assertions stick around for the life of the application instance. If the assertion is checked often, a pre-compiled version (dependent on the type of connection) can save some time. 2. As a WHERE clause in a client-institued UPDATE or SELECT. These are only around long enough to do the UPDATE or SELECT.

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.


Constructor & Destructor Documentation

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();};

rdbModel::Assertion::Assertion ( const Assertion orig,
Row toBe 
)

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 (  ) 

Definition at line 31 of file Assertion.cxx.

References m_keepOp, and m_op.

00031                         {
00032     if (!m_keepOp) delete m_op;
00033   }


Member Function Documentation

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]

Definition at line 207 of file Assertion.h.

References m_name.

00207 {return m_name;}

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().

00205 {return m_op->getOld();}

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]

Definition at line 197 of file Assertion.h.

References m_compiled.

00197 {return m_compiled;}

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().

00201 {return m_op->getToBe();}

void rdbModel::Assertion::setName ( const std::string name  )  [inline]

Definition at line 208 of file Assertion.h.

References m_name.

00208 {m_name = name;}

bool rdbModel::Assertion::verify ( Row old,
Row toBe 
) const

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   }


Member Data Documentation

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]

Definition at line 221 of file Assertion.h.

Referenced by verify().

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().


Generated on Tue Nov 29 23:36:36 2016 for BOSS_7.0.2 by  doxygen 1.4.7