#include <dbType.h>
Public Types | |
enum | Mapping { , MAPPING_OBJECT } |
Mapping type used for the current type. More... | |
Public Member Functions | |
void | init (const Type &type) |
Initializes the DbType instnace. | |
void | postInit () |
Second phase of the initialization routine. | |
DatabaseObject * | loadDatabaseObject (Connection &conn, const KeyValues &keyVals, bool wait, bool lock) |
Loads a database object by sending multiple select statements to load data from tables its attributes are mapped into. | |
DatabaseObject * | loadDatabaseObject (Cursor &cur) |
Loads a database object from an open cursor. | |
OidObject * | loadOidObject (Connection &conn, const OidType &oid, bool wait, bool lock) |
Loads an OidObject by selecting from its associated simple view. | |
void | deleteOidObject (Connection &conn, const OidType &oid) |
Deletes an OidObject of specified OID from the underlying database. | |
void | deleteDatabaseObject (Connection &conn, const KeyValues &keyVals) |
Deletes an OidObject of specified identity from the underlying database. | |
void | updateObject (Connection &conn, DatabaseObject &obj) |
Updates persistent copy. | |
void | insertObject (Connection &conn, DatabaseObject &obj) |
Inserts a persistent object into a database. | |
KeyValues | getKeyValuesForObject (const DatabaseObject &obj) const |
Creates a KeyValues instance from attribute values in the object obj. | |
const Type & | getType () const |
Returns the Type associated with this DbType. | |
const AllParentsList & | getAllParents () const |
Returns a list of persistent parent classes (even indirect) that have a corresponding database table. | |
const AllParentsSet & | getAllParentsSet () const |
Returns a set of persistent parent classes (even indirect) that have a corresponding database table. | |
const PersistentAttributesList & | getAllPersistentAttributes () const |
Returns union of the getPersistentAttributes() and getInheritedAttributes() lists. | |
const KeyAttributesSet & | getKeyAttributes () const |
list of key attributes that are inherited or declared in the current class. | |
const PersistentAttributesList & | getPersistentAttributes () const |
Returns a list of persistent attributes declared in the current class. | |
const PersistentAttributesList & | getInheritedAttributes () const |
List of persistent attributes (retrieved from PersistentAttributes) inherited from all persistent ancestors. | |
bool | isOidManaged () const |
Returns true if the type is descendant of an OidObject (or is OidObject), false otherwise. | |
MappingStrategy & | getMappingStrategy () const |
Returns the current mapping strategy. | |
ObjectMappingStrategy & | getObjectMappingStrategy () const |
Returns ObjectMappingStrategy if ADT (object) mapping is used. | |
ORMappingStrategy & | getORMappingStrategy () const |
Returns ORMappingStrategy if horizontal, vertical or filtered mapping is used. |
This class 'wraps' persistent Type-s (descendants of DatabaeObject) and provides O/R mapping services for them.
It implements the table-level part of the mapping algorithm described in the Thesis. Attribute-level part is implemented in ObjectMappingStrategy and ORMappingStrategy classes.
When one of the CRUD methods of DbType is invoked, the program iterates through the inheritance hierarchy of the related class type according to the algorithm and calls the ObjectMappingStrategy or ORMappingStrategy to perform the attribute-level operations. The strategies in turn call the database drivers' ObjectStatementsFeature or ORStatementsFeature to generate SQL statements that will be executed.
void iopc::DbType::init | ( | const Type & | type | ) |
Initializes the DbType instnace.
Checks associated type metadata and object model and pre-generated required lists that are used during the mapping algorithm execution.
void iopc::DbType::postInit | ( | ) |
Second phase of the initialization routine.
Executed after all DbType-s have finished the first phase (init())
DatabaseObject * iopc::DbType::loadDatabaseObject | ( | Connection & | conn, | |
const KeyValues & | keyVals, | |||
bool | wait, | |||
bool | lock | |||
) |
Loads a database object by sending multiple select statements to load data from tables its attributes are mapped into.
Doesn't use simple views. Usable even for OidObject-s if we don't want to use the associated simple view.
conn | Connection from which to load the database object | |
keyVals | Key values describing identity of the object to be loaded | |
wait | Specifies whether the operation should wait for database locks to be unlocked. | |
lock | Specifies whether the persistent copy should be locked in DB exlusively when loaded. |
DatabaseObject * iopc::DbType::loadDatabaseObject | ( | Cursor & | cur | ) |
Loads a database object from an open cursor.
The data to be fetched are expected to correspond to the getAllPersistentAttributes() list. Fetches exactly one row.
cur | Cursof from which to load the data |
OidObject * iopc::DbType::loadOidObject | ( | Connection & | conn, | |
const OidType & | oid, | |||
bool | wait, | |||
bool | lock | |||
) |
Loads an OidObject by selecting from its associated simple view.
If lock = true is specified, the call is delegated to loadDatabaseObject(conn, keyVals, wait, lock) as the data need to be locked in all underlying tables. (-> sends multiple SELECT FOR UPDATE or similar statements)
conn | Connection from which to load the database object | |
oid | OID of the object to be loaded | |
wait | Specifies whether the operation should wait for database locks to be unlocked. | |
lock | Specifies whether the persistent copy should be locked in DB exlusively when loaded. |
void iopc::DbType::deleteOidObject | ( | Connection & | conn, | |
const OidType & | oid | |||
) |
Deletes an OidObject of specified OID from the underlying database.
conn | Connection used to delete the object | |
oid | OID of the object to delete |
void iopc::DbType::deleteDatabaseObject | ( | Connection & | conn, | |
const KeyValues & | keyVals | |||
) |
Deletes an OidObject of specified identity from the underlying database.
conn | Connection used to delete the object | |
keyVals | Key values that identify of the object to delete |
void iopc::DbType::updateObject | ( | Connection & | conn, | |
DatabaseObject & | obj | |||
) |
Updates persistent copy.
Updates DatabaseObject-s as well as OidObject-s
conn | Connection used for the update | |
obj | Local copy that is used to update the persistent copy in the database. |
void iopc::DbType::insertObject | ( | Connection & | conn, | |
DatabaseObject & | obj | |||
) |
Inserts a persistent object into a database.
Updates DatabaseObject-s as well as OidObject-s
conn | Connection used for the DB operation. | |
obj | Persistent objects that is inserted into the database |
KeyValues iopc::DbType::getKeyValuesForObject | ( | const DatabaseObject & | obj | ) | const |
const AllParentsList& iopc::DbType::getAllParents | ( | ) | const [inline] |
Returns a list of persistent parent classes (even indirect) that have a corresponding database table.
This includes only classes that use horizontal or vertical mapping. Classes that use filtered mapping do not have any associated database table as their columns are inserted into one of their ancestors. Because ADT-mapped classes are handled in a different way, they are not inserted into this list either. The list represents tables that will be accessed when performing a CRUD operation on an instance of the current class. Only one database operation is needed to modify database data belonging to an instance of any class in an ADT-mapped class subgraph.
The list is created by level-order walking through the parent hierarchy starting with parents of the current class first. If the process encounters a horizontally-mapped class, its parents are not processed (because horizontally-mapped classes store all, even inherited attributes into one table). If the current class derives from OidObject, and if OidObject does not use ADT mapping, OidObject is also appended to this list.
const AllParentsSet& iopc::DbType::getAllParentsSet | ( | ) | const [inline] |
Returns a set of persistent parent classes (even indirect) that have a corresponding database table.
Same functionality as getAllParents(), but a set instead of vector is returned
const KeyAttributesSet& iopc::DbType::getKeyAttributes | ( | ) | const [inline] |
list of key attributes that are inherited or declared in the current class.
If the current class derives from OidObject, the OID attribute is included in the list. A class cannot re-define key attributes if they were already defined in one of its ancestors.
const PersistentAttributesList& iopc::DbType::getPersistentAttributes | ( | ) | const [inline] |
Returns a list of persistent attributes declared in the current class.
Developers may declare some of the class attributes as transient. Transient attributes are ignored by the persistence layer.
MappingStrategy& iopc::DbType::getMappingStrategy | ( | ) | const [inline] |
Returns the current mapping strategy.
ObjectMappingStrategy & iopc::DbType::getObjectMappingStrategy | ( | ) | const |
Returns ObjectMappingStrategy if ADT (object) mapping is used.
IopcIncorrectUsageException | if other mapping type is used |
ORMappingStrategy & iopc::DbType::getORMappingStrategy | ( | ) | const |
Returns ORMappingStrategy if horizontal, vertical or filtered mapping is used.
IopcIncorrectUsageException | if other mapping type is used |