|
|
|
File: C:/usr/local/lib/php/blueshoes-4.2/core/storage/oodb/Bs_OoDb.class.php
BlueShoes Application Framework - storage/oodb
@status experimental
Bs_OoDb
Bs_Object | +-- Bs_OoDbBasics | +-- Bs_OoDb
**********************************************************************
|
public class Bs_OoDb extends Bs_OoDbBasics
**********************************************************************
A B S T R A C T [*1] Object Bs_OoDb.class.phpThis object is the abstract layer for OoDb. It holds the basicfuctions for storing(persisting) / unpersisting(fetching) and deleting objectsand sub-objects (='has-a'-relatated objects).To makes use of this object, you must extend it to a DB-specific objectlike 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.No NULLStrong referencing only in same scopeconstructor probles during init E.gfunction Pizza($name='') { // <- Use a default !if (isSet($name)) $this->caption_p = $name; // <- OR check if set !}
| Authors | |
| Version | 4.0.$Revision: 1.1.1.1 $ |
| Copyright | blueshoes.org |
|
| |
|
Direct known subclasses: Bs_OoDbForMySql
|
|
Methods inherited from Bs_OoDbBasics |
| bs_oodbbasics, _setobject, &_getoodbproperty, _preparetopersistdata, _reassembleobjectmetadata, getid, setid, getscope, sethardscope, forcesave, &getpersisttag, _memorizeobjstored, _isobjalreadystored, _unmemorizeobjstored, _memorizeobjfetched, &_getobjalreadyfetched, _unmemorizeobjfetched, &_calcmd5fingerprint, &_flattenobjarray, &flattenobjarray, &_getstreamfields, &getfieldnames, _seterror_store, &geterror_persist, _flattenobjarray, _seterror_fetch, _seterror_delete, &geterror_unpersist, &geterror_delete, &errordump |
|
Methods inherited from Bs_Object |
| isex, isexception, tostring, tohtml, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean |
|
|
|
Private Method Summary |
| array |
&softDelete( $class, integer $classID, string $scope, string $firstCall)Only delete the object (and chield-objects) if no strong references point to it. |
| void |
_unpersistObject(string &$varName, string &$className, int $objID, string $scope, [ string $hashKey ])Use the passed paramters to instanciate an object |
| void |
&oQuery( $className, $completeQuery, string $scope)It's sufficent that the query only selects the ID |
| void |
startTransaction()Optional: |
| void |
Pizza(string $name)Warning: documentation is missing. |
| void |
&_delete( $chieldClass, $chieldID)Warning: documentation is missing. |
| void |
getStorageScope()Warning: documentation is missing. |
| void |
storeObjectData()Warning: documentation is missing. |
| void |
fetchObjectData()Warning: documentation is missing. |
| void |
queryFetch()Warning: documentation is missing. |
| void |
deleteObjectData()Warning: documentation is missing. |
| void |
deleteObjectRelation()Warning: documentation is missing. |
| void |
deleteAllObjectRelation()Warning: documentation is missing. |
| void |
storeClearInHouse()Warning: documentation is missing. |
| void |
fetchCihChildren()Warning: documentation is missing. |
| void |
fetchCihParents()Warning: documentation is missing. |
| void |
commit()Warning: documentation is missing. |
| void |
rollback()Warning: documentation is missing. |
|
Fields inherited from Bs_OoDbBasics |
| $pmetadata, $pdatahaschanged, $pobjputinstorage, $pobjfetchedfromstorage, $perrorstore, $pobjtopersist, $pobjname, $pdefaultscope, $pstorageautocreate, $pinfolist, $perrorfetch, $perrordelete |
|
Private Constant Summary |
| BS_OODB_VERSION |
>>4.0.$x$<< |
Warning: documentation is missing. |
|
Public Method Details |
Bs_OoDb |
|
public void Bs_OoDb( )
|
| |
Constuctor.
|
| Returns |
void |
|
persist |
|
public void persist( object [unknown] &$obj, [ string $scope, string $firstCall ] )
|
| |
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 hash5) With the $clearInHouseData all cih-storage tables are updated.6) Commit if all went wellNOTE I: All exceptions and errors are catched and stored in the error array. See getError_Persist()
Warning: documentation is missing.
|
| Parameter |
|
| object [unknown] |
&$obj |
|
|
the object you want to persist |
|
|
| string |
$scope |
= >>''<< |
|
(opt) Sorage area. E.g. the dbName for a underlying SQL-db. See header in Bs_OoDbBasics.class.php |
|
|
| string |
$firstCall |
= >>TRUE<< |
|
(opt) Used internaly for recursive calls to unpersist(). |
|
| Returns |
void |
| See Also |
unpersist() |
|
&unpersist |
|
public object [unknown] &unpersist( mixed $class, [ mixed $query, string $scope, string $firstCall ] )
|
| |
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 $pObjToPersist2) 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 therecord 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 stored8) 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 tounpersist 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 befilled with the data. If it's a classname, we will try to instanciatea object with "new $class()".$query [string|int|rs]: A $query is passed 1:1 to the underlying soragehandler. It can be anythingthe 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:0 : 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.
|
| Parameter |
|
|
|
| mixed |
$query |
= >>-1<< |
|
above |
|
|
| string |
$scope |
= >>''<< |
|
above |
|
|
| string |
$firstCall |
= >>TRUE<< |
|
above |
|
| Returns |
object [unknown] : all I.O. / FALSE: had errors. |
|
|
Private Method Details |
&softDelete |
|
private array &softDelete( $class, integer $classID, string $scope, string $firstCall )
|
| |
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 ???!
|
| Parameter |
|
|
$class |
|
|
Warning: documentation is missing. |
|
|
| integer |
$classID |
|
|
Warning: documentation is missing. |
|
|
| string |
$scope |
|
|
Warning: documentation is missing. |
|
|
| string |
$firstCall |
|
|
Warning: documentation is missing. |
|
| Returns |
array () of strong-rel pointing the object.
* |
|
_unpersistObject |
|
private void _unpersistObject( string &$varName, string &$className, int $objID, string $scope, [ string $hashKey ] )
|
| |
Use the passed paramters to instanciate an object
It attaches the objects and objectArrays directly in $pObjToPersist.NOTE I: This fuction works together wich unpersist(). It is an intended indirect recursive callto unpersist objects and sub-object.NOTE II: All exceptions and errors are catched and stored in the error array. See getError_Unpersist()
|
| Parameter |
|
| string |
&$varName |
|
|
varName to use |
|
|
| string |
&$className |
|
|
class to instanciate |
|
|
| int |
$objID |
|
|
ID of the object in the underlying storage |
|
|
| string |
$scope |
|
|
storage area. (See header for more info) |
|
|
| string |
$hashKey |
= >>NULL<< |
|
NOT empty() we assume a objectArray otherwise a object. See text above. |
|
| Returns |
void |
|
&oQuery |
|
private void &oQuery( $className, $completeQuery, string $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.*
|
| Parameter |
|
|
$className |
|
|
Warning: documentation is missing. |
|
|
|
$completeQuery |
|
|
Warning: documentation is missing. |
|
|
| string |
$scope |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
|
startTransaction |
|
private void startTransaction( )
|
| |
Optional:
Overload transaction functions if underlying storage provides them.
|
| Returns |
void |
|
Pizza |
|
private void Pizza( string $name )
|
| |
Warning: documentation is missing.
|
| Parameter |
|
| string |
$name |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
|
&_delete |
|
private void &_delete( $chieldClass, $chieldID )
|
| |
Warning: documentation is missing.
|
| Parameter |
|
|
$chieldClass |
|
|
Warning: documentation is missing. |
|
|
|
$chieldID |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
|
getStorageScope |
|
private void getStorageScope( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
storeObjectData |
|
private void storeObjectData( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
fetchObjectData |
|
private void fetchObjectData( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
queryFetch |
|
private void queryFetch( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
deleteObjectData |
|
private void deleteObjectData( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
deleteObjectRelation |
|
private void deleteObjectRelation( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
deleteAllObjectRelation |
|
private void deleteAllObjectRelation( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
storeClearInHouse |
|
private void storeClearInHouse( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
fetchCihChildren |
|
private void fetchCihChildren( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
fetchCihParents |
|
private void fetchCihParents( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
commit |
|
private void commit( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
rollback |
|
private void rollback( )
|
| |
Warning: documentation is missing.
|
| Returns |
void |
|
|
Private Constant Details |
BS_OODB_VERSION
define( BS_OODB_VERSION, >>4.0.$x$<< )
Case: default: case sensitive
|
|
|
|
|
|
| PHPDoc 1.0beta |