[limb-svn] r7018 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Thu May 15 15:53:30 MSD 2008
Author: serega
Date: 2008-05-15 15:53:30 +0400 (Thu, 15 May 2008)
New Revision: 7018
URL: http://fisheye.limb-project.com/changelog/limb/?cs=7018
Modified:
3.x/trunk/limb/active_record/src/lmbARRecordSetDecorator.class.php
3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php
3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
Log:
-- lmbActiveRecord :: __sleep() now returns all properties except _db_conn, _db_table and _db_meta_info. This allows to save a great amount of memory if active record is placed into some memory cache like memcache.
-- lmbActiveRecord :: __wakeup() restores _db_conn, _db_table, and _db_meta_info for object.
-- minor refactorings lmbARRecordSetDecorator
Modified: 3.x/trunk/limb/active_record/src/lmbARRecordSetDecorator.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARRecordSetDecorator.class.php 2008-05-13 12:26:48 UTC (rev 7017)
+++ 3.x/trunk/limb/active_record/src/lmbARRecordSetDecorator.class.php 2008-05-15 11:53:30 UTC (rev 7018)
@@ -34,35 +34,33 @@
if(!$record = parent :: current())
return null;
- return $this->_createObjectFromRecord($record);
+ return self :: createObjectFromRecord($record, $this->class_path, $this->conn);
}
- protected function _createObjectFromRecord($record)
+ static function createObjectFromRecord($record, $default_class_name, $conn)
{
- $object = $this->_createObject($record);
- $object->loadFromRecord($record);
- return $object;
- }
-
- protected function _createObject($record)
- {
if($path = $record->get(lmbActiveRecord :: getInheritanceField()))
{
- $class = end(lmbActiveRecord :: decodeInheritancePath($path));
- if(!class_exists($class))
- throw new lmbException("Class '$class' not found");
- return new $class(null, $this->conn);
+ $class_name = end(lmbActiveRecord :: decodeInheritancePath($path));
+ if(!class_exists($class_name))
+ throw new lmbException("Class '$class_name' not found");
}
else
- return lmbClassPath :: create($this->class_path, array(null, $this->conn));
- }
+ $class_name = $default_class_name;
+
+ $object = new $class_name(null, $conn);
+
+ $object->loadFromRecord($record);
+
+ return $object;
+ }
function at($pos)
{
if(!$record = parent :: at($pos))
return null;
- return $this->_createObjectFromRecord($record);
+ return self :: createObjectFromRecord($record, $this->class_path, $this->conn);
}
}
Modified: 3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php 2008-05-13 12:26:48 UTC (rev 7017)
+++ 3.x/trunk/limb/active_record/src/lmbARRecordSetJoinDecorator.class.php 2008-05-15 11:53:30 UTC (rev 7018)
@@ -83,25 +83,11 @@
}
}
- $related_object = $this->_createObject($fields, $relation_info['class']);
- $related_object->loadFromRecord($fields);
+ $related_object = lmbARRecordSetDecorator :: createObjectFromRecord($fields, $relation_info['class'], $this->conn);
$record->set($this->prefix . $relation_name, $related_object);
}
}
- protected function _createObject($record, $default_class_name)
- {
- if($path = $record->get(lmbActiveRecord :: getInheritanceField()))
- {
- $class = end(lmbActiveRecord :: decodeInheritancePath($path));
- if(!class_exists($class))
- throw new lmbException("Class '$class' not found");
- return new $class(null, $this->conn);
- }
- else
- return new $default_class_name(null, $this->conn);
- }
-
function at($pos)
{
if(!$record = parent :: at($pos))
Modified: 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2008-05-13 12:26:48 UTC (rev 7017)
+++ 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2008-05-15 11:53:30 UTC (rev 7018)
@@ -2164,6 +2164,28 @@
if(isset(self :: $_global_listeners[$type]))
lmbDelegate :: invokeAll(self :: $_global_listeners[$type], array($this));
}
+
+ function __wakeup()
+ {
+ $toolkit = lmbToolkit :: instance();
+ $this->_db_conn = $toolkit->getDbConnectionByDsn($this->_db_conn->dsn);
+
+ $this->_db_meta_info = $toolkit->getActiveRecordMetaInfo($this, $this->_db_conn);
+ $this->_db_table_fields = $this->_db_meta_info->getDbColumnsNames();
+
+ $this->_db_table = $this->_db_meta_info->getDbTable();
+ $this->_db_table->setPrimaryKeyName($this->_primary_key_name);
+ $this->_db_table_name = $this->_db_table->getTableName();
+ }
+
+ function __sleep()
+ {
+ $this->_db_conn_dsn = $this->_db_conn->getDsnString();
+
+ $vars = array_keys(get_object_vars($this));
+ $vars = array_diff($vars, array('_db_conn', '_db_table', '_db_meta_info'));
+ return $vars;
+ }
}
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php 2008-05-13 12:26:48 UTC (rev 7017)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbActiveRecordTest.class.php 2008-05-15 11:53:30 UTC (rev 7018)
@@ -488,7 +488,7 @@
$rs->next();
$this->assertEqual($object2->getId(), $rs->current()->getId());
}
-
+
function testFindAllWithCriteria()
{
$object1 = $this->creator->createOneTableObject();
More information about the limb-svn
mailing list