符合条件的记录总数.

@param array|string|int $con 条件.
@param string           $id  用于count的字段,默认为*.

@return int 记数.
519081
public final function count($con, $id = null) {
        if ($con && !is_array($con)) {
            $con = [$this->primaryKeys[0] => $con];
        }
        $sql = $this->select();
        $sql->where($con);

        return $sql->count('*');
    }
1144404
public function getLastVersionNumber($con = null)
    {
        $v = ChildIndexEngineIndexVersionQuery::create()
            ->filterByIndexEngineIndex($this)
            ->orderByVersion('desc')
            ->findOne($con);
        if (!$v) {
            return 0;
        }

        return $v->getVersion();
    }
667243
public function countPermissionsRelatedById(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collPermissionsRelatedByIdPartial && !$this->isNew();
        if (null === $this->collPermissionsRelatedById || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collPermissionsRelatedById) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getPermissionsRelatedById());
            }

            $query = ChildPermissionQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByPermissionRelatedByParentId($this)
                ->count($con);
        }

        return count($this->collPermissionsRelatedById);
    }
638649
public function countMultiples(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collMultiplesPartial && !$this->isNew();
        if (null === $this->collMultiples || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collMultiples) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getMultiples());
            }

            $query = ChildSkillQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByMultipleOf($this)
                ->count($con);
        }

        return count($this->collMultiples);
    }
798085
public function getBy($field, $cond = UNDEFINED, $value = UNDEFINED)
    {
        $data = $this->data;
        $id = $this->id;

        $this->tryLoadBy($field, $cond, $value);
        $row = $this->data;

        $this->data = $data;
        $this->id = $id;

        return $row;
    }
985720
public function countObjects(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collObjectsPartial && !$this->isNew();
        if (null === $this->collObjects || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collObjects) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getObjects());
            }

            $query = ChildObjectQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySport($this)
                ->count($con);
        }

        return count($this->collObjects);
    }
1301831
public function countRecords(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collRecordsPartial && !$this->isNew();
        if (null === $this->collRecords || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collRecords) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getRecords());
            }

            $query = RecordQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByPlayer($this)
                ->count($con);
        }

        return count($this->collRecords);
    }
857252
protected final function save($data, $con = null, $cb = null) {
        if (!$con) {
            return $this->insert($data, $cb);
        } else if ($this->exist($con)) {//存在即修改
            return $this->update($data, $con, $cb);
        } else {
            return $this->insert($data, $cb);
        }
    }
369649
public function deleteByStringId(string $id, string $key = null): int
    {
        return $this->deleteByKey($id, $key);
    }
682953
public function countC2Ms(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collC2MsPartial && !$this->isNew();
        if (null === $this->collC2Ms || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collC2Ms) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getC2Ms());
            }

            $query = ChildC2MQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByCategory($this)
                ->count($con);
        }

        return count($this->collC2Ms);
    }
1327084
public function getShare(string $id, array $params = [])
    {
        if (isset($this->_objects[$id]) && !empty($this->_objects[$id])) {
            return $this->_objects[$id];
        } elseif (!isset($this->_definitions[$id])) {
            throw new \Exception('You have requested a non-existent id: ' . $id);
        } else {
            if ($this->has($id)) {
                $definition = $this->_definitions[$id];
            } else {
                throw new \Exception('获取的' . $id . '不存在');
            }

            $object = null;
            if (!empty($params)) {
                $definition['params'] = (array)$params;
            }
            if(is_string($definition)) {
                $class = $definition;
                $type = self::TYPE_DEFINITION_STRING;
            }else{
                $class = $definition['class'];
                $params = empty($definition['params']) ? [] : $definition['params'];
                $type = $definition['type'];
            }

            if ($type == self::TYPE_DEFINITION_CALLBACK) {
                $object = call_user_func($class, $params);

            } elseif ($type == self::TYPE_DEFINITION_OBJ) {
                $object = $class;

            } elseif ($type == self::TYPE_DEFINITION_STRING) {
                if (!class_exists($class)) {
                    throw new \Exception('类：' . $class . '不存在!');
                }

                $object = $this->build($class, $params);

            } else {
                throw new \Exception('Unexpected object definition type: ' . gettype($class));
            }
            $this->_objects[$id] = $object;
            return $object;
            //            return $this->get($id, $params);
        }
    }
132779
public function incr($id)
    {
        $params = [':id' => $id];
        $statement = 'UPDATE kv_store SET kv_value = kv_value + 1 WHERE kv_id = :id';
        return $this->sqlPeristence->exec($statement, $params);
    }
540214
public function del($table, $cond=null)
	{
		$ds = $this->ds();
		$cond = SqlHelper::parse_cond($ds, $cond);
		$table = SqlHelper::qtable($table);
		
		$sql = "DELETE FROM {$table} " . (empty($cond) ? '' : "WHERE {$cond}");
		
		$result = Sql::write($ds, Sql::MODE_WRITE_DELETE, [
				$sql
			]);
		return $result;
	}
605697
public function countCategories(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collCategoriesPartial && !$this->isNew();
        if (null === $this->collCategories || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collCategories) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getCategories());
            }

            $query = ChildCategoryQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterBySource($this)
                ->count($con);
        }

        return count($this->collCategories);
    }
1141912
public function get($id)
    {
        if(!is_string($id))
        {
            throw new ContainerException('id is not a string value');
        }
        if('' === $id)
        {
            throw new ContainerException('id can not be a empty string value');
        }
        
        // 实现传递实例化参数
        $params = func_get_args();
        array_shift($params);
        // 单例中有数据，且无实例化参数时直接返回单例
        if(isset($this->singletonObjects[$id]) && !isset($params[0]))
        {
            return $this->singletonObjects[$id];
        }
        $data = $this->beanParser->getData();
        
        if(isset($data[$id]))
        {
            $object = BeanFactory::newInstance($data[$id]['className'], ...$params);
        }
        else if(class_exists($id))
        {
            $object = BeanFactory::newInstance($id, ...$params);
        }
        else
        {
            throw new ContainerException(sprintf('%s not found', $id));
        }

        // 传参实例化强制不使用单例
        if([] === $params && isset($data[$id]['instanceType']) && $data[$id]['instanceType'] === Bean::INSTANCE_TYPE_SINGLETON)
        {
            $this->singletonObjects[$id] = $object;
        }
        return $object;
    }
317239
public function countCustomerCustomerGroups(Criteria $criteria = null, $distinct = false, ConnectionInterface $con = null)
    {
        $partial = $this->collCustomerCustomerGroupsPartial && !$this->isNew();
        if (null === $this->collCustomerCustomerGroups || null !== $criteria || $partial) {
            if ($this->isNew() && null === $this->collCustomerCustomerGroups) {
                return 0;
            }

            if ($partial && !$criteria) {
                return count($this->getCustomerCustomerGroups());
            }

            $query = ChildCustomerCustomerGroupQuery::create(null, $criteria);
            if ($distinct) {
                $query->distinct();
            }

            return $query
                ->filterByCustomerGroup($this)
                ->count($con);
        }

        return count($this->collCustomerCustomerGroups);
    }
782597
public function getData($con, $query)
    {
        $result = $con->query($query);
        return $result->fetch_all(MYSQLI_ASSOC);
    }