blueshoes php application framework and cms            core_storage
[ class tree: core_storage ] [ index: core_storage ] [ all elements ]

Class: Bs_OoDb

Source Location: /core/storage/oodb/Bs_OoDb.class.php

Class Overview

Bs_Object
   |
   --Bs_OoDbBasics
      |
      --Bs_OoDb

A B S T R A C T [*1] Object Bs_OoDb.class.php


Author(s):

Version:

  • 4.0.$Revision: 1.2 $

Copyright:

  • blueshoes.org

Methods


Child classes:

Bs_OoDbForMySql
*********************************************************************** Imlementation of the abstract class Bs_OoDb in MySQL.

Inherited Variables

Inherited Methods

Class: Bs_OoDbBasics

Bs_OoDbBasics::Bs_OoDbBasics()
Constructor During the process of storing '$this' is cloned (copied), reset and reused.
Bs_OoDbBasics::errorDump()
Bs_OoDbBasics::flattenObjArray()
Wrapper for function _flattenObjArray()
Bs_OoDbBasics::forceSave()
If 'forceSave' is set to TRUE the "md5 autodetect modification" will not be used and the data will always be stored.
Bs_OoDbBasics::getError_Delete()
Bs_OoDbBasics::getError_Persist()
Bs_OoDbBasics::getError_Unpersist()
Bs_OoDbBasics::getFieldNames()
I sometimes need all varNames that will have a filed in the underlying storage
Bs_OoDbBasics::getID()
Get the objects sorage ID.
Bs_OoDbBasics::getPersistTag()
Status info is set in the $_persistTag -hash. For exsample the ID of the object when it's fetched from the storage. The $_persistTag is dependent on the scope. (See header info: Scope) Thus the ID may differ from one scope to the other.
Bs_OoDbBasics::getScope()
(See header info: Scope) Get the scope; the area to store the data.
Bs_OoDbBasics::setHardScope()
(See header info: Scope) Set a 'strong'-scope. That is: the passed object will be stored with the given scope.
Bs_OoDbBasics::setID()
Set the objects sorage ID.
Bs_OoDbBasics::_getStreamFields()
I sometimes need all the streamNames from the PersistProperty
Bs_OoDbBasics::_setError_Delete()
Bs_OoDbBasics::_setError_Fetch()
Bs_OoDbBasics::_setError_Store()

Class: Bs_Object

Bs_Object::Bs_Object()
Bs_Object::getErrors()
Basic error handling: Get *all* errors as string array from the global Bs_Error-error stack.
Bs_Object::getLastError()
Basic error handling: Get last error string from the global Bs_Error-error stack.
Bs_Object::getLastErrors()
Basic error handling: Get last errors string array from the global Bs_Error-error stack sinc last call of getLastErrors().
Bs_Object::persist()
Persists this object by serializing it and saving it to a file with unique name.
Bs_Object::setError()
Basic error handling: Push an error string on the global Bs_Error-error stack.
Bs_Object::toHtml()
Dumps the content of this object to a string using PHP's var_dump().
Bs_Object::toString()
Dumps the content of this object to a string using PHP's var_dump().
Bs_Object::unpersist()
Fetches an object that was persisted with persist()

Class Details

[line 50]
A B S T R A C T [*1] Object Bs_OoDb.class.php

This object is the abstract layer for OoDb. It holds the basic fuctions for storing(persisting) / unpersisting(fetching) and deleting objects and sub-objects (='has-a'-relatated objects). To makes use of this object, you must extend it to a DB-specific object like Bs_OoDbForMySql.class.php.

OoDb is the abriviation for "Object Oriented Database"

NOTE: This object is based on Bs_OoDbBasics.class.php that is used as a function library. See the header text there if you don't find the info in this header text.




Tags:

access:  public
version:  4.0.$Revision: 1.2 $
status:  deprecated USE Bs_SimpleObjPersister
copyright:  blueshoes.org
author:  Sam Blum <at blueshoes dot org>


[ Top ]


Class Methods


constructor Bs_OoDb [line 54]

Bs_OoDb Bs_OoDb( )

Constuctor.



[ Top ]

method commit [line 900]

void commit( )



Overridden in child classes as:

Bs_OoDbForMySql::commit()

[ Top ]

method deleteAllObjectRelation [line 876]

void deleteAllObjectRelation( )



Overridden in child classes as:

Bs_OoDbForMySql::deleteAllObjectRelation()

[ Top ]

method deleteObjectData [line 868]

void deleteObjectData( )



Overridden in child classes as:

Bs_OoDbForMySql::deleteObjectData()
To prevent deadlocks, always start deleting with the main clearInHouse-Table

[ Top ]

method deleteObjectRelation [line 872]

void deleteObjectRelation( )



Overridden in child classes as:

Bs_OoDbForMySql::deleteObjectRelation()

[ Top ]

method fetchCihChildren [line 884]

void fetchCihChildren( )



Overridden in child classes as:

Bs_OoDbForMySql::fetchCihChildren()
NOTE catches exception 'No such table in db' and returns empty array.

[ Top ]

method fetchCihParents [line 888]

void fetchCihParents( )



Overridden in child classes as:

Bs_OoDbForMySql::fetchCihParents()
NOTE catches exception 'No such table in db' and returns empty array.

[ Top ]

method fetchObjectData [line 860]

void fetchObjectData( )



Overridden in child classes as:

Bs_OoDbForMySql::fetchObjectData()

[ Top ]

method getStorageScope [line 852]

void getStorageScope( )



Overridden in child classes as:

Bs_OoDbForMySql::getStorageScope()

[ Top ]

method oQuery [line 815]

void &oQuery( mixed $className, mixed $completeQuery, [mixed $scope = ''])

It's sufficent that the query only selects the ID $className and result of query must match! $scope and scope of query must match! * --sb OPTIMISATION : Gather all the records at once, instanciate 1 object and duplicate it times rec-number.

* Init each object with rec-data. Pass the list of objects to routine to fetch the chield objects.




[ Top ]

method persist [line 304]

FALSE persist( object &$obj, [$scope $scope = ''], [$firstCall $firstCall = TRUE])

Persist a object 1) Check if the object passed ($obj) has already been stored. If so, return ID.

This happens evertime a object is referenced by 2 or more vars that have to be persisted. 2) Get the data to be persisted. If we have sub-objects try to start 'Transactions'. 3) First store the 'lonely'-data of the object but only if we detect changes or 'forceSave' is TRUE. 4) Now start saving the sub-objects. Every sub-object saved is noted in the $clearInHouseData hash 5) With the $clearInHouseData all cih-storage tables are updated. 6) Commit if all went well

NOTE I: All exceptions and errors are catched and stored in the error array. See getError_Persist()




Tags:

return:  on fatal error. 0 if no data is to be stored otherwise ID>0 on successfull insert.
access:  public


Overrides Bs_Object::persist() (Persists this object by serializing it and saving it to a file with unique name.)

Parameters:

object   &$obj   the object you want to persist
$scope   $scope   string (opt) Sorage area. E.g. the dbName for a underlying SQL-db. See header in Bs_OoDbBasics.class.php
$firstCall   $firstCall   boolean (opt) Used internaly for recursive calls to unpersist().

[ Top ]

method queryFetch [line 864]

void queryFetch( )



Overridden in child classes as:

Bs_OoDbForMySql::queryFetch()
Get rec-array of any complete query

[ Top ]

method rollback [line 903]

void rollback( )



Overridden in child classes as:

Bs_OoDbForMySql::rollback()

[ Top ]

method softDelete [line 75]

FALSE &softDelete( mixed $class, [mixed $classID = -1], [mixed $scope = ''], [mixed $firstCall = TRUE])

Only delete the object (and chield-objects) if no strong references point to it.

We will also try to softDelete the chield-objects unless it's a 'readOnly' ref.

PARAMETERS: $class [string|object]: May be either a className (string) or an object. If it's an object, the className will be fetched trough "get_class($class)" $classID [int] : If $classID > 0, it's expected to be an ID. If $classID < 0, (default) it means: Take ID from passed object: $class using the $_persistTag. $scope string : Sorage area. E.g. the dbName for a underlying SQL-db. See header in Bs_OoDbBasics.class.php $firstCall boolean : Used internaly for recursive calls to softDelete(). No transaction handling ???!




Tags:

return:  if faital error, TURE on success OR array() of strong-rel pointing the object.


[ Top ]

method startTransaction [line 897]

void startTransaction( )

Optional: Overload transaction functions if underlying storage provides them.



Overridden in child classes as:

Bs_OoDbForMySql::startTransaction()

[ Top ]

method storeClearInHouse [line 880]

void storeClearInHouse( )



Overridden in child classes as:

Bs_OoDbForMySql::storeClearInHouse()

[ Top ]

method storeObjectData [line 856]

void storeObjectData( )



Overridden in child classes as:

Bs_OoDbForMySql::storeObjectData()
Store the passed $lonelyList-data (=objdect data) in the table.

[ Top ]

method unpersist [line 575]

NULL &unpersist( &$class $class, [$query $query = -1], [$scope $scope = ''], [$firstCall $firstCall = TRUE])

Unpersist a object - Dramatic dynamic :-) 1) IF className is passed, instanceiate an object(suppressing any missing parameter warnings) ELSE use passed object assuming it's the right class (read on to see what is the *right* class).

The object become to $pObjToPersist 2) IF $query is a positive number >0, we assumed it's the ID of the object-data of the underlying storage. By default it's (-1). That means: use the ID of the $pObjToPersist. If the ID turns out to be 0 or if the object-data is not found return NULL. This may happen quite often. E.g. if we have a weak reference to an object and it was deleted in the mean time. 3) Now fetch the object-data (='lonely'-data) calling fetchObjectData()) and passing the $query. /+°+°+°+° more to come +°+°+°+/ 4) Transform the object-data into the metaData. We skip unknown names; that means varName of the record fileds must match varNames or streamNames from the _ooDbProperty. 5) Merge (reasseble) the metaData with the object. Now all 'lonely'- and 'stream'-data are set. 6) Momorize that this object has already been fetched. 7) Fetch the main clearInHouse records from $pObjToPersist where all object-relations are stored 8) Go through each clearInHouse record by calling the _unpersistObject() function. Collect any error, but woun't interrupt. 'weak'-reference and missing object-data is not an error. 9) If the object was not found return NULL. If all sub-objects where unpersisted successfully return the object otherwise return FALSE.

NOTE I: Calls to _unpersistObject() will do some preparing stuff and then call this function to unpersist the sub-object. It is an intended indirect recursive call. NOTE II: All exceptions and errors are catched and stored in the error array. See getError_Unpersist()

PARAMETERS: $class [string|object]: May be either a className (string) or an object that will be filled with the data. If it's a classname, we will try to instanciate a object with "new $class()". $query [string|int|rs]: A $query is passed 1:1 to the underlying soragehandler. It can be anything the soragehandler can use to identify the object in the database. E.g. If the underlying soragehandler is a SQL-db the query can be an ID, SQL-string or even a record-set. If $query > 0, it's expected to be an ID. If $query < 0, (default) it means: Take ID from passed $class using the $_persistTag. If $query == 0, or ID ends up to be <=0 return NULL; don't fetch any data from storage." $scope string : Sorage area. E.g. the dbName for a underlying SQL-db. See header in Bs_OoDbBasics.class.php $firstCall boolean : Used internaly for recursive calls to unpersist(). RETURN:

  1. : found no data at all in the underlying storage.
FALSE : Fatal error. Coundn't create the object at all. object: When ever possible an object is returned. *BUT* errors may have happend. To see if errors occured check if getError_Unpersist() returns FALSE. * --sb OPTIMISATION : Gather all the chield-objects of the same type. Analze 1 and den fetch the data in * 1 query.




Tags:

return:  :no obj data found / object: all I.O. / FALSE: had errors.
access:  public


Overrides Bs_Object::unpersist() (Fetches an object that was persisted with persist())

Parameters:

&$class   $class   mixed see above
$query   $query   mixed see above
$scope   $scope   string see above
$firstCall   $firstCall   boolean see above

[ Top ]


Documentation generated on Mon, 29 Dec 2003 21:12:25 +0100 by phpDocumentor 1.2.3