}
$k = $keys[0];
}
- $i = Memcached_DataObject::getcached($cls, $k, $v);
+ $i = self::getcached($cls, $k, $v);
if ($i === false) { // false == cache miss
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- $i = false;
- return $i;
- }
+ $i = new $cls;
$result = $i->get($k, $v);
if ($result) {
// Hit!
*
* @return array Array of objects, in order
*/
- function multiGet($cls, $keyCol, $keyVals, $skipNulls=true)
+ static function multiGetClass($cls, $keyCol, array $keyVals, $skipNulls=true)
{
- $result = self::pivotGet($cls, $keyCol, $keyVals);
+ $result = self::pivotGetClass($cls, $keyCol, $keyVals);
$values = array_values($result);
*
* @return array Array mapping $keyVals to objects, or null if not found
*/
- static function pivotGet($cls, $keyCol, $keyVals, $otherCols = array())
+ static function pivotGetClass($cls, $keyCol, array $keyVals, array $otherCols = array())
{
if (is_array($keyCol)) {
foreach ($keyVals as $keyVal) {
}
if (count($toFetch) > 0) {
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- // TRANS: Exception thrown when a program code class (%s) cannot be instantiated.
- throw new Exception(sprintf(_('Cannot instantiate class %s.'),$cls));
- }
+ $i = new $cls;
foreach ($otherCols as $otherKeyCol => $otherKeyVal) {
$i->$otherKeyCol = $otherKeyVal;
}
static function pkeyCols($cls)
{
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- // TRANS: Exception thrown when a program code class (%s) cannot be instantiated.
- throw new Exception(sprintf(_('Cannot instantiate class %s.'),$cls));
- }
+ $i = new $cls;
$types = $i->keyTypes();
ksort($types);
return $pkey;
}
- function listGet($cls, $keyCol, $keyVals)
+ static function listFindClass($cls, $keyCol, array $keyVals)
+ {
+ $i = new $cls;
+ $i->whereAddIn($keyCol, $keyVals, $i->columnType($keyCol));
+ if (!$i->find()) {
+ throw new NoResultException($i);
+ }
+
+ return $i;
+ }
+
+ static function listGetClass($cls, $keyCol, array $keyVals)
{
$pkeyMap = array_fill_keys($keyVals, array());
$result = array_fill_keys($keyVals, array());
}
if (count($allPkeys) > 0) {
- $keyResults = self::pivotGet($cls, $pkeyCols, $allPkeys);
+ $keyResults = self::pivotGetClass($cls, $pkeyCols, $allPkeys);
foreach ($pkeyMap as $keyVal => $pkeyList) {
foreach ($pkeyList as $pkeyVal) {
}
if (count($toFetch) > 0) {
- $i = DB_DataObject::factory($cls);
- if (empty($i)) {
- // TRANS: Exception thrown when a program code class (%s) cannot be instantiated.
- throw new Exception(sprintf(_('Cannot instantiate class %s.'),$cls));
- }
- $i->whereAddIn($keyCol, $toFetch, $i->columnType($keyCol));
- if ($i->find()) {
- sprintf("listGet() got {$i->N} results for class $cls key $keyCol");
+ try {
+ $i = self::listFindClass($cls, $keyCol, $toFetch);
+
while ($i->fetch()) {
$copy = clone($i);
$copy->encache();
}
$pkeyMap[$i->$keyCol][] = $pkeyVal;
}
+ } catch (NoResultException $e) {
+ // no results found for our keyVals, so we leave them as empty arrays
}
foreach ($toFetch as $keyVal) {
self::cacheSet(sprintf("%s:list-ids:%s:%s", strtolower($cls), $keyCol, $keyVal),
/**
* @todo FIXME: Should this return false on lookup fail to match getKV?
*/
- static function pkeyGetClass($cls, $kv)
+ static function pkeyGetClass($cls, array $kv)
{
$i = Memcached_DataObject::multicache($cls, $kv);
if ($i !== false) { // false == cache miss
return $i;
} else {
- $i = DB_DataObject::factory($cls);
- if (empty($i) || PEAR::isError($i)) {
- return false;
- }
+ $i = new $cls;
foreach ($kv as $k => $v) {
if (is_null($v)) {
// XXX: possible SQL injection...? Don't
return $ckeys;
}
- function multicache($cls, $kv)
+ static function multicache($cls, $kv)
{
ksort($kv);
$c = self::memcache();
function _connect()
{
- global $_DB_DATAOBJECT;
+ global $_DB_DATAOBJECT, $_PEAR;
$sum = $this->_getDbDsnMD5();
if (!empty($_DB_DATAOBJECT['CONNECTIONS'][$sum]) &&
- !PEAR::isError($_DB_DATAOBJECT['CONNECTIONS'][$sum])) {
+ !$_PEAR->isError($_DB_DATAOBJECT['CONNECTIONS'][$sum])) {
$exists = true;
} else {
$exists = false;