Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

IopcClassObjectImpl Class Reference

Class whose instances represent individual user's persistent classes. All object data manipulating methods are implemented there. More...

#include <iopcClassObjectImpl.h>

Inheritance diagram for IopcClassObjectImpl:

Inheritance graph
[legend]
Collaboration diagram for IopcClassObjectImpl:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 ~IopcClassObjectImpl ()
virtual bool isAttributePersistent (int attributeNumber)
virtual ProtoBasegetProtoBaseAdaptor ()
virtual void loadAttribute (int attributeNumber, IopcPersistentObject *object)
void loadObject (IopcPersistentObject *object)
int loadAttrGroup (int groupNo, IopcPersistentObject *object)
void insertObject (IopcPersistentObject *object)
void updateObject (IopcPersistentObject *object)
void deleteObject (IopcPersistentObject *object)
void deleteObject (Connection *connection, const OidType oid)
char * getSelectOidAndCidSqlStmt (const char *tables, const char *condition, const char *orderBy, LockingStrategy lockingStrategy, WaitingStrategy waitingStrategy)
int bindOidAndCid (Cursor *cursor)
OidType getCurrentObjectOid ()
void setCurrentObjectOid (const OidType oid)
IopcClassObjectImplgetCurrentObjectsClassObject ()
int getNextOid (Connection *connection, OidType &oid)
char * attributeNamesToColumnNames (char *statement)
void translateOrderByClause (char *(&src))
virtual void executeQuery (const QueRefProto &query, Connection *connection, ResultBase *result)
IopcPersistentObjectcreateInstance ()
RefBasecreateReference ()
OidType getClassID () const

Static Public Member Functions

int getClassIDForOid (const OidType oid, Connection *connection)

Protected Member Functions

int getWord (const char *str, const char *&begin, const char *&end)
int generateSqlStatements (DatabaseSqlStatements *sqlStatements, LockingStrategy lockingStrategy, WaitingStrategy waitingStrategy)
int generateLoadAttrGroupSqlStmts (DatabaseSqlStatements *sqlStatements, LockingStrategy lockingStrategy, WaitingStrategy waitingStrategy)
int generateLoadAttrGroupSqlStmt (int groupNo, DatabaseSqlStatements *sqlStatements, LockingStrategy lockingStrategy, WaitingStrategy waitingStrategy, CStdString &loadAttrGroupSql)
int generateInsertObjectSqlStmt (DatabaseSqlStatements *sqlStatements)
int initialize ()
void fillInsertUpdateTableList ()
void createInsertUpdateTableBitFields (InsertUpdateTableInfo &tableInfo)

Static Protected Member Functions

int generateStaticSqlStmts (DatabaseSqlStatements *sqlStatements)

Protected Attributes

CStdString className
IopcMappingType mappingType
TableInfodbTable
IopcClassObjectImpladdAttributesTo
AttrVector attributes
GroupVector groups
std::list< IopcClassObjectImpl * > children
std::list< IopcClassObjectImpl * > parents
OidType currentObjectOid
int currentObjectCid
IopcPersistentObject *(* createInstanceFnc )()
RefBase *(* createReferenceFnc )()
bool visited
IopcImportExportStructimportExportArray
int classID
CStdString polymorphicViewName
CStdString simpleViewName
InsertUpdateTableList insertUpdateTableList
LockingStrategy storedSqlStatementsLockingStrategy
WaitingStrategy storedSqlStatementsWaitingStrategy
IopcProtoBaseAdaptorprotoBaseAdaptor

Static Protected Attributes

CStdString selectNextOidSqlStatement
CStdString insertIntoMainTableSqlStatement
CStdString deleteObjectSqlStatement
CStdString oidWhereCondition
CStdString selectCidSqlStatement

Private Member Functions

 IopcClassObjectImpl ()

Detailed Description

Class whose instances represent individual user's persistent classes. All object data manipulating methods are implemented there.

For each class that is IopcPersistentObject ancestor there is one instance of IopcClassObjectImpl that represents it. The instance contains all the information about the persistent class - for example names and types of its attributes, list of class parents, information about class mapping and so on. These informations are set when creating the IopcClassObjectImpl object - in IopcClassObjectContainer::initializeUsingMetadataLoader().

Main purpose of this object is to provide functions for persistent objects' data manipulation. It contains functions that load attributes of persistent object from the database, update the object in database, delete it or insert a new persistent object into the database. Some other functions support executing queries on the persistent objects.

Persistent class attributes (attributes) are lexicographically ordered in this class - see AttrVector. This is needed because of performance reasons - when transferring data between persistent object and the database (importExportArray is used). See IopcImportExportStruct, IopcPersistentObject::iopcImportAttributes(), and IopcPersistentObject::iopcExportAttributes() for further info.

When loading persistent object's data from the database, class's simple view is used (simpleViewName). Simple view contains all instances of the represented class but not instances of its descendants. Class's polymorphic view (polymorphicViewName) contains all instances of a persistent class including instances of class's descendants. It is used when querying persistent objects.

Public methods of this class are called from IopcPersistentObject ancestors through interface IopcClassObject. The core of the IOPC library calles the methods through class's prototype - IopcProtoBaseAdaptor.

See also:
IopcClassObjectContainer, IopcProtoBaseAdaptor, IopcClassObject


Constructor & Destructor Documentation

IopcClassObjectImpl::IopcClassObjectImpl  )  [private]
 

Simple constructor.

IopcClassObjectImpl::~IopcClassObjectImpl  ) 
 

Destructor - destroys protoBaseAdaptor and dbTable if not NULL.


Member Function Documentation

virtual bool IopcClassObjectImpl::isAttributePersistent int  attributeNumber  )  [inline, virtual]
 

Is attribute with given number persistent?

Implements IopcClassObject.

virtual ProtoBase* IopcClassObjectImpl::getProtoBaseAdaptor  )  [inline, virtual]
 

Gets IopcProtoBaseAdaptor associated with this object.

Returns:
protoBaseAdaptor
See also:
IopcProtoBaseAdaptor

Implements IopcClassObject.

void IopcClassObjectImpl::loadAttribute int  attributeNumber,
IopcPersistentObject object
[virtual]
 

Loads attribute with given number together with all the attributes from the same group.

Calls loadAttrGroup() using correct parameters.

OID of object is used when queriing the data from the database.

Note:
Throws IopcExceptionUnexpected if loadAttrGroup() fails.
Parameters:
attributeNumber Number of the attribute.
object Object, whose attributes should be loaded and set.

Implements IopcClassObject.

void IopcClassObjectImpl::loadObject IopcPersistentObject object  ) 
 

Loads persistent object specified by currentObjectOid from the database.

object is assumed to be empty object of represented class. Initializes object (IopcPersistentObject::iopcInitObject()), marks it as clean (IopcPersistentObject::_MarkAsClean() and loads object's default fetch group using loadAttrGroup().

Note:
Throws IopcExceptionUnexpected if loadAttrGroup() fails.
Parameters:
object Object, whose attributes should be loaded and set.

int IopcClassObjectImpl::loadAttrGroup int  groupNo,
IopcPersistentObject object
 

Loads specified group of attributes of object specified by object's OID.

Note:
In some rare cases throws IopcExceptionUnexpected.
Parameters:
groupNo Number of group to load.
object The object.
Returns:
0 if OK, non-zero in case of error.

void IopcClassObjectImpl::insertObject IopcPersistentObject object  )  [virtual]
 

Inserts given object into the database.

Note:
Throws IopcExceptionUnexpected if some error occurs.

Implements IopcClassObject.

void IopcClassObjectImpl::updateObject IopcPersistentObject object  )  [virtual]
 

Updates given object in database.

Note:
Throws IopcExceptionUnexpected if some error occurs.

Implements IopcClassObject.

void IopcClassObjectImpl::deleteObject IopcPersistentObject object  )  [virtual]
 

Deletes given object from the database.

Gets object's OID and Connection and calls deleteObject(Connection *, const OidType).

Note:
Throws IopcExceptionUnexpected if some error occurs.

Implements IopcClassObject.

void IopcClassObjectImpl::deleteObject Connection connection,
const OidType  oid
 

Deletes object specified by OID from the database.

Deletes object from project's main table, deleting from the other tables is done in the database using cascade delete. Uses deleteObjectSqlStatement.

Parameters:
connection Connection object to be used.
oid OID of the object.
Note:
Throws IopcExceptionUnexpected if some error occurs.

int IopcClassObjectImpl::getClassIDForOid const OidType  oid,
Connection connection
[static]
 

Loads Class ID (CID) of object with OID oid from the database.

Project's main table is accessed, selectCidSqlStatement is used.

Note:
Throws IopcExceptionUnexpected if some error occurs.
Parameters:
oid OID of the object.
connection Connection object to be used.
Returns:
The Class ID.

char * IopcClassObjectImpl::getSelectOidAndCidSqlStmt const char *  tables,
const char *  condition,
const char *  orderBy,
LockingStrategy  lockingStrategy,
WaitingStrategy  waitingStrategy
 

Gets SELECT statement that selects objects' OID and CID according to given parameters.

This function is used when querying some objects from the database (see executeQuery()).

Uses DatabaseSqlStatements::generateWhereClauseStmtPart() and DatabaseSqlStatements::generateSelectSql(), the objects are queried using class's polymorphic view (polymorphicViewName).

Note:
Because of having parameters such as condition it isn't possible to prearrange the string to be returned.
Parameters:
tables List of tables / views to be added to FROM clause of the statement. The FROM clause always contains class's polymorphic view.
condition Condition(s) to be used in WHERE clause of the statement.
orderBy Optional ORDER BY clause (NULL in typical case).
lockingStrategy Locking strategy to be used.
waitingStrategy Waiting strategy to be used.
Returns:
The SELECT statement, NULL in case of error.

int IopcClassObjectImpl::bindOidAndCid Cursor cursor  ) 
 

Binds currentObjectOid and currentObjectCid as output parameters of query that is executed using cursor cursor.

Called from IopcProtoBaseAdaptor::_BindKeysAndClassIdentificatingAttributes().

Returns:
0 if OK, 1 in case of error.

OidType IopcClassObjectImpl::getCurrentObjectOid  )  [inline]
 

Returns OID of object received as a result of executing a query on this class object. The object could be later loaded using loadObject().

Returns:
currentObjectOid
See also:
bindOidAndCid(), executeQuery().

void IopcClassObjectImpl::setCurrentObjectOid const OidType  oid  )  [inline]
 

Sets OID of object that will be loaded by the next loadObject() call.

Returns:
currentObjectOid
See also:
getCurrentObjectOid()

IopcClassObjectImpl * IopcClassObjectImpl::getCurrentObjectsClassObject  ) 
 

Returns class object for object with OID currentObjectOid.

Uses currentObjectCid.

See also:
getCurrentObjectOid()

int IopcClassObjectImpl::getNextOid Connection connection,
OidType oid
 

Returns number that should be used as OID when adding new object into the database.

Executes selectNextOidSqlStatement using given connection and fetches received value.

Parameters:
connection The connection.
oid Result of the function - the OID.
Returns:
0 if OK, 1 in case of error.

char * IopcClassObjectImpl::attributeNamesToColumnNames char *  statement  ) 
 

Replaces attribute names in statement by column names, if class name is used when specifying an attribute (MyClass::attribute), removes it.

Called when executing user's query (see executeQuery()).

Note:
statement is freed in this function - it should be dynamically allocated (by malloc()).
Parameters:
statement Input string.
Returns:
Output string (allocated by malloc(), caller should free it after use).

void IopcClassObjectImpl::translateOrderByClause char *&  src  ) 
 

Translates given ORDER BY clause (of a SQL statement).

Note:
src must point to dynamically allocated string (by malloc()), the string will be freed and newly allocated string will be returned.
Parameters:
src Simplified SQL92 ORDER BY clause - see DatabaseSqlStatements::translateOrderByStatement() for details.

void IopcClassObjectImpl::executeQuery const QueRefProto query,
Connection connection,
ResultBase result
[virtual]
 

Executes given query, uses class's polymorphic view.

  • Sets various parameters of result (including the SQL statement).

Note:
Throws IopcExceptionUnexpected if ResultBase::Open() fails.
Parameters:
query The query.
connection Connection object to be used.
result Object that will receive query's results.

Implements IopcClassObject.

IopcPersistentObject * IopcClassObjectImpl::createInstance  ) 
 

Creates instance of class represented by this IopcClassObjectImpl.

Initializes createInstanceFnc using IopcClassFactory::getClass() if needed.

RefBase * IopcClassObjectImpl::createReference  ) 
 

Creates a new DBNULL reference to represented class.

Initializes createReferenceFnc using IopcClassFactory::getClass() if needed.

OidType IopcClassObjectImpl::getClassID  )  const [inline]
 

Returns Class ID (CID) of represented class.

int IopcClassObjectImpl::getWord const char *  str,
const char *&  begin,
const char *&  end
[protected]
 

Function used for SQL statement parsing.

Finds first word (identificator / number / keyword) in string str and returns beginning (begin) and end (end) of the word. Uses macro IS_SEPARATOR().

int IopcClassObjectImpl::generateSqlStatements DatabaseSqlStatements sqlStatements,
LockingStrategy  lockingStrategy,
WaitingStrategy  waitingStrategy
[protected]
 

Prepares all SQL statements that this class object needs. Called when initializing the class object (initialize()).

If initializing the first IopcClassObjectImpl instance, calls generateStaticSqlStmts().

Always calls generateLoadAttrGroupSqlStmts() and generateInsertObjectSqlStmt().

Note:
Strategies lockingStrategy and waitingStrategy are used when generating load SQL statements (generateLoadAttrGroupSqlStmts()). storedSqlStatementsLockingStrategy and storedSqlStatementsWaitingStrategy are set according to these values. These variables are used in loadAttrGroup() when deciding whether the pregenerated SQL statements can be used or not. See loadAttrGroup() for details.
Parameters:
sqlStatements Object used to generate the SQL statements.
lockingStrategy The locking strategy.
waitingStrategy The waiting strategy.
Returns:
0 if OK, 1 in case of error.

int IopcClassObjectImpl::generateStaticSqlStmts DatabaseSqlStatements sqlStatements  )  [static, protected]
 

Generates static SQL statements - i.e. the statements that are the same for all user's persistent classes.

Uses various functions from DatabaseSqlStatements interface.

The generated statements are stored in these attributes:

Parameters:
sqlStatements Object used to generate the SQL statements.
Returns:
0 if OK, 1 in case of error.

int IopcClassObjectImpl::generateLoadAttrGroupSqlStmts DatabaseSqlStatements sqlStatements,
LockingStrategy  lockingStrategy,
WaitingStrategy  waitingStrategy
[protected]
 

Generates SQL statements that load individual attribute groups from the database.

Iterates through groups, calls generateLoadAttrGroupSqlStmt() for each group, fills received strings into AttrGroup::selectStmt-s.

Parameters:
sqlStatements Object used to generate the SQL statements.
lockingStrategy Locking strategy to be used - see generateSqlStatements() for description.
waitingStrategy Waiting strategy to be used - see generateSqlStatements() for description.
Returns:
0 if OK, 1 in case of error.
See also:
AttrGroup, loadAttrGroup()

int IopcClassObjectImpl::generateLoadAttrGroupSqlStmt int  groupNo,
DatabaseSqlStatements sqlStatements,
LockingStrategy  lockingStrategy,
WaitingStrategy  waitingStrategy,
CStdString &  loadAttrGroupSql
[protected]
 

Generates SQL statement that loads given attribute group from the database.

Parameters:
groupNo Number of the group (i.e. position of the group in groups).
sqlStatements Object used to generate the SQL statements.
lockingStrategy Locking strategy to be used - see generateSqlStatements() for description.
waitingStrategy Waiting strategy to be used - see generateSqlStatements() for description.
loadAttrGroupSql Result of the function - the SQL statement.
Returns:
0 if OK, 1 in case of error.
See also:
AttrGroup, loadAttrGroup()

int IopcClassObjectImpl::generateInsertObjectSqlStmt DatabaseSqlStatements sqlStatements  )  [protected]
 

Generates SQL statement that inserts row into the table associated with the represented persistent class (dbTable's TableInfo::insertSqlStatement). If there's no associated table (i.e. dbTable is NULL), does nothing.

Note:
The SQL statement is used when inserting an instance of represented persistent class as well as when inserting some instance of class's ancestor, that contains some data that should be stored in this dbTable.
Returns:
0 if OK, 1 in case of error.
See also:
InsertUpdateTableInfo

int IopcClassObjectImpl::initialize  )  [protected]
 

Method called after IopcClassObjectContainer has filled metadata dependent values of this object.

Returns:
0 if OK, 1 otherwise.

void IopcClassObjectImpl::fillInsertUpdateTableList  )  [protected]
 

Initializes insertUpdateTableList.

Creates list of tables, into that some data from instances of the represented class should be put. For each of the tables calls createInsertUpdateTableBitFields().

See also:
InsertUpdateTableInfo

void IopcClassObjectImpl::createInsertUpdateTableBitFields InsertUpdateTableInfo tableInfo  )  [protected]
 

Initializes given InsertUpdateTableInfo struct.

Iterates through this class's attributes and attributes in tableInfo and initializes tableInfo's InsertUpdateTableInfo::attributesToSkip and InsertUpdateTableInfo::columnsToSkip.

See InsertUpdateTableInfo for further details.


Member Data Documentation

CStdString IopcClassObjectImpl::className [protected]
 

Name of the represented class.

IopcMappingType IopcClassObjectImpl::mappingType [protected]
 

What type of mapping the represented class uses?

TableInfo* IopcClassObjectImpl::dbTable [protected]
 

Information about the table associated with the represented class. NULL if no such table.

IopcClassObjectImpl* IopcClassObjectImpl::addAttributesTo [protected]
 

Class object that represents class in whose table attributes of class represented by this object should be stored. Used only if the represented class uses filtered mapping.

AttrVector IopcClassObjectImpl::attributes [protected]
 

Attributes of the represented class.

GroupVector IopcClassObjectImpl::groups [protected]
 

Attribute groups of the represented class.

std::list<IopcClassObjectImpl *> IopcClassObjectImpl::children [protected]
 

Class objects that represent parents of the represented class.

std::list<IopcClassObjectImpl *> IopcClassObjectImpl::parents [protected]
 

Class objects that represent children of the represented class.

OidType IopcClassObjectImpl::currentObjectOid [protected]
 

OID of object that is currently manipulated by the layer.

This attribute is bound by bindOidAndCid() when executing some query (executeQuery()). The value is used by loadObject().

int IopcClassObjectImpl::currentObjectCid [protected]
 

Class ID of the object with OID currentObjectOid.

See currentObjectOid for further details.

IopcPersistentObject*(* IopcClassObjectImpl::createInstanceFnc)() [protected]
 

Pointer to function that creates instances of the represented class.

See also:
createInstance()

RefBase*(* IopcClassObjectImpl::createReferenceFnc)() [protected]
 

Pointer to function that creates references to instances of the represented class.

See also:
createReference()

bool IopcClassObjectImpl::visited [protected]
 

Flag used in fillInsertUpdateTableList().

IopcImportExportStruct* IopcClassObjectImpl::importExportArray [protected]
 

Array used when transferring data between object's attributes and the database

See also:
IopcImportExportStruct, IopcPersistentObject::iopcImportAttributes(), IopcPersistentObject::iopcExportAttributes()

int IopcClassObjectImpl::classID [protected]
 

Class ID of the represented class.

See also:
IopcClassObjectContainer::loadClassIDs()

CStdString IopcClassObjectImpl::polymorphicViewName [protected]
 

Name of represented class's polymorphic view.

CStdString IopcClassObjectImpl::simpleViewName [protected]
 

Name of represented class's simple view.

InsertUpdateTableList IopcClassObjectImpl::insertUpdateTableList [protected]
 

Information about tables into which some data should be put when inserting instance of the represented class into the database or updating class's instance in the database.

See also:
InsertUpdateTableInfo

CStdString IopcClassObjectImpl::selectNextOidSqlStatement [static, protected]
 

SQL statement that selects OID for new object that is inserted into the database.

See also:
generateStaticSqlStmts(), getNextOid()

CStdString IopcClassObjectImpl::insertIntoMainTableSqlStatement [static, protected]
 

SQL statement that insert information about an object into project's main table. The inserted row contains two entries - object's Class ID and object's OID.

See also:
generateStaticSqlStmts(), insertObject()

CStdString IopcClassObjectImpl::deleteObjectSqlStatement [static, protected]
 

SQL statement that is used when deleting a persistent object from the database.

See also:
generateStaticSqlStmts(), deleteObject(Connection *, const OidType)

CStdString IopcClassObjectImpl::oidWhereCondition [static, protected]
 

Prepared WHERE clause used when generating UPDATE SQL commands in updateObject(). The WHERE clause looks like this

"WHERE OID = :oid"
. The OID will be bound into the SQL statement when using it.

See also:
generateStaticSqlStmts(), updateObject()

CStdString IopcClassObjectImpl::selectCidSqlStatement [static, protected]
 

SQL statement that selects object's Class ID for given OID. The statement queries project's main table.

See also:
generateStaticSqlStmts(), getClassIDForOid()

LockingStrategy IopcClassObjectImpl::storedSqlStatementsLockingStrategy [protected]
 

Locking strategy used when generating load attribute group SQL statements.

See generateSqlStatements() for further details.

WaitingStrategy IopcClassObjectImpl::storedSqlStatementsWaitingStrategy [protected]
 

Waiting strategy used when generating load attribute group SQL statements.

See generateSqlStatements() for further details.

IopcProtoBaseAdaptor* IopcClassObjectImpl::protoBaseAdaptor [protected]
 

IopcProtoBaseAdaptor asociated with this class object

See also:
IopcProtoBaseAdaptor


The documentation for this class was generated from the following files:
Generated on Wed Aug 11 22:35:34 2004 for IOPC by Doxygen 1.3.6