40 public static function get(
RDBMapper $mapper, $id=self::NO_CACHE) {
42 $cacheSection = self::getCacheSection($mapper->
getType());
43 $cacheId = self::getCacheId($id);
44 if ($id == self::NO_CACHE || !$cache->exists($cacheSection, $cacheId)) {
48 $selectStmt = $cache->get($cacheSection, $cacheId);
61 $this->_type = $mapper->
getType();
78 return $this->_id == self::NO_CACHE ?
false :
79 $cache->exists(self::getCacheSection($this->_type), self::getCacheId($this->_id));
88 $this->_meta[$key] = $value;
97 if (isset($this->_meta[$key])) {
98 return $this->_meta[$key];
109 $columnPart = $this->_parts[self::COLUMNS];
110 $orderPart = $this->_parts[self::ORDER];
111 $limitCount = $this->_parts[self::LIMIT_COUNT];
112 $limitOffset = $this->_parts[self::LIMIT_OFFSET];
113 $this->_parts[self::COLUMNS] = self::$_partsInit[self::COLUMNS];
114 $this->_parts[self::ORDER] = self::$_partsInit[self::ORDER];
115 $this->_parts[self::LIMIT_COUNT] = self::$_partsInit[self::LIMIT_COUNT];
116 $this->_parts[self::LIMIT_OFFSET] = self::$_partsInit[self::LIMIT_OFFSET];
120 $stmt = $this->getAdapter()->prepare($this->
assemble(
'count'));
121 $stmt->execute($this->getBind());
122 $row = $stmt->fetch();
123 $nRows = $row[
'nRows'];
126 $this->_parts[self::COLUMNS] = $columnPart;
127 $this->_parts[self::ORDER] = $orderPart;
128 $this->_parts[self::LIMIT_COUNT] = $limitCount;
129 $this->_parts[self::LIMIT_OFFSET] = $limitOffset;
138 if ($this->_id != self::NO_CACHE) {
140 $cache->put(self::getCacheSection($this->_type), self::getCacheId($this->_id), $this);
148 if (!isset($this->_cachedSql[$cacheKey])) {
149 $sql = parent::assemble();
150 $this->_cachedSql[$cacheKey] = $sql;
152 return $this->_cachedSql[$cacheKey];
158 public function query($fetchMode = null, $bind = array()) {
159 $stmt = $this->getAdapter()->prepare($this->
assemble(
'select'));
160 $stmt->execute($this->getBind());
170 return self::CACHE_KEY.
'/'.$type;
187 return array(
'_id',
'_type',
'_meta',
'_cachedSql',
'_parts');
192 $mapper = $persistenceFacade->getMapper($this->_type);
__sleep()
Serialization handlers.
static COUNT()
Get the COUNT(*) expression.
getMeta($key)
Get customt meta value.
query($fetchMode=null, $bind=array())
RDBMapper maps objects of one type to a relational database schema.
getConnection()
Get the database connection.
setMeta($key, $value)
Add customt meta value.
static getInstance($name, $dynamicConfiguration=array())
getType()
Get the entity type that this mapper handles.
__construct(RDBMapper $mapper, $id=self::NO_CACHE)
Constructor.
isCached()
Check if the statement is cached already.
save()
Put the statement into the cache.
getType()
Get the entity type associated with the statement.
static getCacheSection($type)
Get the cache section.
getRowCount()
Execute a count query and return the row count.
static getCacheId($id)
Get the compressed cache id from the id.