当前位置: 首页>>代码示例>>PHP>>正文


PHP Propel::isInstancePoolingEnabled方法代码示例

本文整理汇总了PHP中Propel\Runtime\Propel::isInstancePoolingEnabled方法的典型用法代码示例。如果您正苦于以下问题:PHP Propel::isInstancePoolingEnabled方法的具体用法?PHP Propel::isInstancePoolingEnabled怎么用?PHP Propel::isInstancePoolingEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Propel\Runtime\Propel的用法示例。


在下文中一共展示了Propel::isInstancePoolingEnabled方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getInstanceFromPool

 public static function getInstanceFromPool($key)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if (isset(self::$instances[$key])) {
             return self::$instances[$key];
         }
     }
     return null;
 }
开发者ID:malukenho,项目名称:Propel2,代码行数:9,代码来源:InstancePoolTrait.php

示例2: testInstancePoolingReenabled

 public function testInstancePoolingReenabled()
 {
     Propel::enableInstancePooling();
     $books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find($this->con);
     foreach ($books as $book) {
     }
     $this->assertTrue(Propel::isInstancePoolingEnabled());
     Propel::disableInstancePooling();
     $books = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book')->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find($this->con);
     foreach ($books as $book) {
     }
     $this->assertFalse(Propel::isInstancePoolingEnabled());
     Propel::enableInstancePooling();
 }
开发者ID:kalaspuffar,项目名称:php-orm-benchmark,代码行数:14,代码来源:OnDemandIteratorTest.php

示例3: testFormatterDoesNotReenableInstancePoolIfItWasInitiallyDisabled

 public function testFormatterDoesNotReenableInstancePoolIfItWasInitiallyDisabled()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     BookstoreDataPopulator::depopulate($con);
     Propel::disableInstancePooling();
     $stmt = $con->query('SELECT * FROM book');
     $formatter = new OnDemandFormatter();
     $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'));
     $this->assertFalse(Propel::isInstancePoolingEnabled());
     $books = $formatter->format($stmt);
     $this->assertFalse(Propel::isInstancePoolingEnabled());
     $books->getIterator()->closeCursor();
     $this->assertFalse(Propel::isInstancePoolingEnabled());
     Propel::enableInstancePooling();
 }
开发者ID:robin850,项目名称:Propel2,代码行数:15,代码来源:OnDemandFormatterTest.php

示例4: getInstanceFromPool

 public static function getInstanceFromPool($key)
 {
     $object = static::defaultGetInstanceFromPool($key);
     if (Propel::isInstancePoolingEnabled()) {
         if (empty($object) === true) {
             $object = GlobalCache::get(static::getPrefix() . $key);
         }
         if ($object === false) {
             $object = null;
         } else {
             static::defaultAddInstanceToPool($object, $key);
         }
     }
     return $object;
 }
开发者ID:benconnito,项目名称:kopper,代码行数:15,代码来源:CachedInstancePoolTrait.php

示例5: execute

 /**
  * Populate the database using all the Entity classes previously added.
  *
  * @param PropelPDO $con A Propel connection object
  *
  * @return array A list of the inserted PKs
  */
 public function execute($con = null)
 {
     if (null === $con) {
         $con = $this->getConnection();
     }
     $isInstancePoolingEnabled = Propel::isInstancePoolingEnabled();
     Propel::disableInstancePooling();
     $insertedEntities = array();
     $con->beginTransaction();
     foreach ($this->quantities as $class => $number) {
         for ($i = 0; $i < $number; $i++) {
             $insertedEntities[$class][] = $this->entities[$class]->execute($con, $insertedEntities);
         }
     }
     $con->commit();
     if ($isInstancePoolingEnabled) {
         Propel::enableInstancePooling();
     }
     return $insertedEntities;
 }
开发者ID:lyrasoft,项目名称:lyrasoft.github.io,代码行数:27,代码来源:Populator.php

示例6: removeInstanceFromPool

 /**
  * Removes an object from the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doDelete
  * methods in your stub classes -- you may need to explicitly remove objects
  * from the cache in order to prevent returning objects that no longer exist.
  *
  * @param mixed $value A \Diaporamas\Model\DiaporamaVersion object or a primary key value.
  */
 public static function removeInstanceFromPool($value)
 {
     if (Propel::isInstancePoolingEnabled() && null !== $value) {
         if (is_object($value) && $value instanceof \Diaporamas\Model\DiaporamaVersion) {
             $key = serialize(array((string) $value->getId(), (string) $value->getVersion()));
         } elseif (is_array($value) && count($value) === 2) {
             // assume we've been passed a primary key";
             $key = serialize(array((string) $value[0], (string) $value[1]));
         } elseif ($value instanceof Criteria) {
             self::$instances = [];
             return;
         } else {
             $e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or \\Diaporamas\\Model\\DiaporamaVersion object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true)));
             throw $e;
         }
         unset(self::$instances[$key]);
     }
 }
开发者ID:InformatiqueProg,项目名称:Diaporamas,代码行数:28,代码来源:DiaporamaVersionTableMap.php

示例7: testSetUp

 public function testSetUp()
 {
     $this->assertTrue(Propel::isInstancePoolingEnabled());
     $this->assertEquals(2, count($this->author->getBooks()));
     $this->assertEquals(2, $this->author->countBooks());
 }
开发者ID:robin850,项目名称:Propel2,代码行数:6,代码来源:PoisonedCacheBugTest.php

示例8: removeInstanceFromPool

 /**
  * Removes an object from the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doDelete
  * methods in your stub classes -- you may need to explicitly remove objects
  * from the cache in order to prevent returning objects that no longer exist.
  *
  * @param mixed $value A \App\Propel\VariationTypeI18n object or a primary key value.
  */
 public static function removeInstanceFromPool($value)
 {
     if (Propel::isInstancePoolingEnabled() && null !== $value) {
         if (is_object($value) && $value instanceof \App\Propel\VariationTypeI18n) {
             $key = serialize([null === $value->getVariationTypeId() || is_scalar($value->getVariationTypeId()) || is_callable([$value->getVariationTypeId(), '__toString']) ? (string) $value->getVariationTypeId() : $value->getVariationTypeId(), null === $value->getLocale() || is_scalar($value->getLocale()) || is_callable([$value->getLocale(), '__toString']) ? (string) $value->getLocale() : $value->getLocale()]);
         } elseif (is_array($value) && count($value) === 2) {
             // assume we've been passed a primary key";
             $key = serialize([null === $value[0] || is_scalar($value[0]) || is_callable([$value[0], '__toString']) ? (string) $value[0] : $value[0], null === $value[1] || is_scalar($value[1]) || is_callable([$value[1], '__toString']) ? (string) $value[1] : $value[1]]);
         } elseif ($value instanceof Criteria) {
             self::$instances = [];
             return;
         } else {
             $e = new PropelException("Invalid value passed to removeInstanceFromPool().  Expected primary key or \\App\\Propel\\VariationTypeI18n object; got " . (is_object($value) ? get_class($value) . ' object.' : var_export($value, true)));
             throw $e;
         }
         unset(self::$instances[$key]);
     }
 }
开发者ID:mtornero,项目名称:slowshop,代码行数:28,代码来源:VariationTypeI18nTableMap.php

示例9: populateRelation

 /**
  * Makes an additional query to populate the objects related to the collection objects
  * by a certain relation
  *
  * @param string              $relation Relation name (e.g. 'Book')
  * @param Criteria            $criteria Optional Criteria object to filter the related object collection
  * @param ConnectionInterface $con      Optional connection object
  *
  * @return ObjectCollection The list of related objects
  */
 public function populateRelation($relation, $criteria = null, $con = null)
 {
     if (!Propel::isInstancePoolingEnabled()) {
         throw new RuntimeException(__METHOD__ . ' needs instance pooling to be enabled prior to populating the collection');
     }
     $relationMap = $this->getFormatter()->getTableMap()->getRelation($relation);
     if ($this->isEmpty()) {
         // save a useless query and return an empty collection
         $coll = new ObjectCollection();
         $coll->setModel($relationMap->getRightTable()->getClassName());
         return $coll;
     }
     $symRelationMap = $relationMap->getSymmetricalRelation();
     $query = PropelQuery::from($relationMap->getRightTable()->getClassName());
     if (null !== $criteria) {
         $query->mergeWith($criteria);
     }
     // query the db for the related objects
     $filterMethod = 'filterBy' . $symRelationMap->getName();
     $relatedObjects = $query->{$filterMethod}($this)->find($con);
     if (RelationMap::ONE_TO_MANY === $relationMap->getType()) {
         // initialize the embedded collections of the main objects
         $relationName = $relationMap->getName();
         foreach ($this as $mainObj) {
             $mainObj->initRelation($relationName);
         }
         // associate the related objects to the main objects
         $getMethod = 'get' . $symRelationMap->getName();
         $addMethod = 'add' . $relationName;
         foreach ($relatedObjects as $object) {
             $mainObj = $object->{$getMethod}();
             // instance pool is used here to avoid a query
             $mainObj->{$addMethod}($object);
         }
     } elseif (RelationMap::MANY_TO_ONE === $relationMap->getType()) {
         // nothing to do; the instance pool will catch all calls to getRelatedObject()
         // and return the object in memory
     } else {
         throw new UnsupportedRelationException(__METHOD__ . ' does not support this relation type');
     }
     return $relatedObjects;
 }
开发者ID:malukenho,项目名称:Propel2,代码行数:52,代码来源:ObjectCollection.php

示例10: updateLoadedNodes

 /**
  * Reload all already loaded nodes to sync them with updated db
  *
  * @param      ChildCategory $prune        Object to prune from the update
  * @param      ConnectionInterface $con        Connection to use.
  */
 public static function updateLoadedNodes($prune = null, ConnectionInterface $con = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         $keys = array();
         /** @var $obj ChildCategory */
         foreach (CategoryTableMap::$instances as $obj) {
             if (!$prune || !$prune->equals($obj)) {
                 $keys[] = $obj->getPrimaryKey();
             }
         }
         if (!empty($keys)) {
             // We don't need to alter the object instance pool; we're just modifying these ones
             // already in the pool.
             $criteria = new Criteria(CategoryTableMap::DATABASE_NAME);
             $criteria->add(CategoryTableMap::COL_CATEGORY_ID, $keys, Criteria::IN);
             $dataFetcher = ChildCategoryQuery::create(null, $criteria)->setFormatter(ModelCriteria::FORMAT_STATEMENT)->find($con);
             while ($row = $dataFetcher->fetch()) {
                 $key = CategoryTableMap::getPrimaryKeyHashFromRow($row, 0);
                 /** @var $object ChildCategory */
                 if (null !== ($object = CategoryTableMap::getInstanceFromPool($key))) {
                     $object->setLeftValue($row[7]);
                     $object->setRightValue($row[8]);
                     $object->setLevel($row[9]);
                     $object->clearNestedSetChildren();
                 }
             }
             $dataFetcher->close();
         }
     }
 }
开发者ID:mtornero,项目名称:slowshop,代码行数:36,代码来源:CategoryQuery.php


注:本文中的Propel\Runtime\Propel::isInstancePoolingEnabled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。