00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00021 final class NullDaoWorker extends BaseDaoWorker
00022 {
00024
00025 public function get(ObjectQuery $oq)
00026 {
00027 return $this->getByQuery($oq->toSelectQuery($this->dao));
00028 }
00029
00030 public function getById($id)
00031 {
00032 $query =
00033 $this->dao->makeSelectHead()->
00034 where(
00035 Expression::eq(
00036 DBField::create(
00037 $this->dao->getIdName(),
00038 $this->dao->getTable()
00039 ),
00040 $id
00041 )
00042 );
00043
00044 if ($object = $this->fetchObject($query))
00045 return $object;
00046 else
00047 throw new ObjectNotFoundException();
00048
00049 Assert::isUnreachable();
00050 }
00051
00052 public function getByLogic(LogicalObject $logic)
00053 {
00054 return
00055 $this->getByQuery(
00056 $this->dao->makeSelectHead()->where($logic)
00057 );
00058 }
00059
00060 public function getByQuery(SelectQuery $query)
00061 {
00062 if ($object = $this->fetchObject($query))
00063 return $object;
00064 else
00065 throw new ObjectNotFoundException();
00066
00067 Assert::isUnreachable();
00068 }
00069
00070 public function getCustom(SelectQuery $query)
00071 {
00072 if ($query->getLimit() > 1)
00073 throw new WrongArgumentException(
00074 'can not handle non-single row queries'
00075 );
00076
00077 $custom = DBPool::getByDao($this->dao)->queryRow($query);
00078
00079 if ($custom)
00080 return $this->cacheByQuery($query, $custom);
00081 else
00082 throw new ObjectNotFoundException();
00083
00084 Assert::isUnreachable();
00085 }
00087
00089
00090 public function getList(ObjectQuery $oq)
00091 {
00092 return $this->getListByQuery($oq->toSelectQuery($this->dao));
00093 }
00094
00095 public function getListByIds($ids)
00096 {
00097 return
00098 $this->getListByLogic(
00099 Expression::in($this->dao->getIdName(), $ids)
00100 );
00101 }
00102
00103 public function getListByQuery(SelectQuery $query)
00104 {
00105 if ($list = $this->fetchList($query))
00106 return $list;
00107 else
00108 throw new ObjectNotFoundException();
00109
00110 Assert::isUnreachable();
00111 }
00112
00113 public function getListByLogic(LogicalObject $logic)
00114 {
00115 return $this->getListByQuery($this->dao->makeSelectHead()->where($logic));
00116 }
00117
00118 public function getPlainList()
00119 {
00120 return $this->getListByQuery($this->dao->makeSelectHead());
00121 }
00123
00125
00126 public function getCustomList(
00127 SelectQuery $query, $expires = Cache::DO_NOT_CACHE
00128 )
00129 {
00130 if ($list = DBPool::getByDao($this->dao)->querySet($query))
00131 return $list;
00132 else
00133 throw new ObjectNotFoundException();
00134 }
00135
00136 public function getCustomRowList(
00137 SelectQuery $query, $expires = Cache::DO_NOT_CACHE
00138 )
00139 {
00140 if ($query->getFieldsCount() !== 1)
00141 throw new WrongArgumentException(
00142 'you should select only one row when using this method'
00143 );
00144
00145 if ($list = DBPool::getByDao($this->dao)->queryColumn($query))
00146 return $list;
00147 else
00148 throw new ObjectNotFoundException();
00149 }
00151
00153
00154 public function getCountedList(ObjectQuery $oq)
00155 {
00156 return $this->getQueryResult($oq->toSelectQuery($this->dao));
00157 }
00158
00159 public function getQueryResult(SelectQuery $query)
00160 {
00161 $list = $this->fetchList($query);
00162
00163 $count = clone $query;
00164
00165 $count =
00166 DBPool::getByDao($this->dao)->queryRow(
00167 $count->dropFields()->dropOrder()->limit(null, null)->
00168 get(SQLFunction::create('COUNT', '*')->setAlias('count'))
00169 );
00170
00171 $res = new QueryResult();
00172
00173 return
00174 $res->
00175 setList($list)->
00176 setCount($count['count'])->
00177 setQuery($query);
00178 }
00180
00182
00183 public function dropById($id)
00184 {
00185 return
00186 DBPool::getByDao($this->dao)->queryNull(
00187 OSQL::delete()->from($this->dao->getTable())->
00188 where(Expression::eq($this->dao->getIdName(), $id))
00189 );
00190 }
00191
00192 public function dropByIds( $ids)
00193 {
00194 return
00195 DBPool::getByDao($this->dao)->queryNull(
00196 OSQL::delete()->from($this->dao->getTable())->
00197 where(Expression::in($this->dao->getIdName(), $ids))
00198 );
00199 }
00201
00203
00204 public function cacheById(Identifiable $object)
00205 {
00206 return $object;
00207 }
00208
00209 public function cacheByQuery(
00210 SelectQuery $query, $object
00211 )
00212 {
00213 return $object;
00214 }
00215
00216 public function cacheListByQuery(SelectQuery $query, $array)
00217 {
00218 return $array;
00219 }
00221
00223
00224 public function uncacheById($id)
00225 {
00226 return true;
00227 }
00228
00229 public function uncacheByIds($ids)
00230 {
00231 return true;
00232 }
00233
00234 public function uncacheByQuery(SelectQuery $query)
00235 {
00236 return true;
00237 }
00238
00239 public function uncacheLists()
00240 {
00241 return true;
00242 }
00244
00246
00247 public function getCachedById($id)
00248 {
00249 return null;
00250 }
00251
00252 public function getCachedByQuery(SelectQuery $query)
00253 {
00254 return null;
00255 }
00257 }
00258 ?>