summaryrefslogtreecommitdiffstats
path: root/db
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-19 13:20:54 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-19 13:21:11 +0200
commit517e4ca5435106ab5304849248cbea4e9dffd4b0 (patch)
tree0f00076f012791b39c710994f695abf723546062 /db
parentbd35b98d2c130f058b182f726636ee971625823b (diff)
split up api class for easier testing and clearer code
Diffstat (limited to 'db')
-rw-r--r--db/feedmapper.php6
-rw-r--r--db/foldermapper.php6
-rw-r--r--db/itemmapper.php6
-rw-r--r--db/mapper.php13
-rw-r--r--db/mapperfactory.php16
-rw-r--r--db/postgres/itemmapper.php6
6 files changed, 28 insertions, 25 deletions
diff --git a/db/feedmapper.php b/db/feedmapper.php
index 4d88a4667..06267b19d 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -25,14 +25,14 @@
namespace OCA\News\Db;
-use \OCA\News\Core\API;
+use \OCA\News\Core\Db;
class FeedMapper extends Mapper implements IMapper {
- public function __construct(API $api) {
- parent::__construct($api, 'news_feeds');
+ public function __construct(Db $db) {
+ parent::__construct($db, 'news_feeds', '\OCA\News\Db\Feed');
}
diff --git a/db/foldermapper.php b/db/foldermapper.php
index d273ce159..f3bedd70e 100644
--- a/db/foldermapper.php
+++ b/db/foldermapper.php
@@ -25,13 +25,13 @@
namespace OCA\News\Db;
-use \OCA\News\Core\API;
+use \OCA\News\Core\Db;
class FolderMapper extends Mapper implements IMapper {
- public function __construct(API $api) {
- parent::__construct($api, 'news_folders');
+ public function __construct(Db $db) {
+ parent::__construct($db, 'news_folders', '\OCA\News\Db\Folder');
}
public function find($id, $userId){
diff --git a/db/itemmapper.php b/db/itemmapper.php
index aea0180d7..33b09e357 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -24,12 +24,12 @@
namespace OCA\News\Db;
-use \OCA\News\Core\API;
+use \OCA\News\Core\Db;
class ItemMapper extends Mapper implements IMapper {
- public function __construct(API $api){
- parent::__construct($api, 'news_items', '\OCA\News\Db\Item');
+ public function __construct(Db $db){
+ parent::__construct($db, 'news_items', '\OCA\News\Db\Item');
}
diff --git a/db/mapper.php b/db/mapper.php
index 42f1efa93..dae59a84e 100644
--- a/db/mapper.php
+++ b/db/mapper.php
@@ -26,7 +26,7 @@
namespace OCA\News\Db;
-use \OCA\News\Core\API;
+use \OCA\News\Core\Db;
/**
@@ -37,15 +37,16 @@ abstract class Mapper {
protected $tableName;
protected $entityClass;
+ private $db;
/**
- * @param API $api Instance of the API abstraction layer
+ * @param Db $db Instance of the Db abstraction layer
* @param string $tableName the name of the table. set this to allow entity
* @param string $entityClass the name of the entity that the sql should be
* mapped to queries without using sql
*/
- public function __construct(API $api, $tableName, $entityClass=null){
- $this->api = $api;
+ public function __construct(Db $db, $tableName, $entityClass=null){
+ $this->db = $db;
$this->tableName = '*PREFIX*' . $tableName;
// if not given set the entity name to the class without the mapper part
@@ -114,7 +115,7 @@ abstract class Mapper {
$this->execute($sql, $params);
- $entity->setId((int) $this->api->getInsertId($this->tableName));
+ $entity->setId((int) $this->db->getInsertId($this->tableName));
return $entity;
}
@@ -177,7 +178,7 @@ abstract class Mapper {
* @return \PDOStatement the database query result
*/
protected function execute($sql, array $params=array(), $limit=null, $offset=null){
- $query = $this->api->prepareQuery($sql, $limit, $offset);
+ $query = $this->db->prepareQuery($sql, $limit, $offset);
$index = 1; // bindParam is 1 indexed
foreach($params as $param) {
diff --git a/db/mapperfactory.php b/db/mapperfactory.php
index 564819356..178e62160 100644
--- a/db/mapperfactory.php
+++ b/db/mapperfactory.php
@@ -25,25 +25,27 @@
namespace OCA\News\Db;
-use \OCA\News\Core\API;
+use \OCA\News\Core\Settings;
+use \OCA\News\Core\Db;
class MapperFactory {
- private $api;
+ private $settings;
- public function __construct(API $api) {
- $this->api = $api;
+ public function __construct(Settings $settings, Db $db) {
+ $this->settings = $settings;
+ $this->db = $db;
}
public function getItemMapper() {
- switch($this->api->getSystemValue('dbtype')) {
+ switch($this->settings->getSystemValue('dbtype')) {
case 'pgsql':
- return new \OCA\News\Db\Postgres\ItemMapper($this->api);
+ return new \OCA\News\Db\Postgres\ItemMapper($this->db);
break;
default:
- return new ItemMapper($this->api);
+ return new ItemMapper($this->db);
break;
}
}
diff --git a/db/postgres/itemmapper.php b/db/postgres/itemmapper.php
index e24ea373d..d5395f008 100644
--- a/db/postgres/itemmapper.php
+++ b/db/postgres/itemmapper.php
@@ -24,7 +24,7 @@
namespace OCA\News\Db\Postgres;
-use \OCA\News\Core\API;
+use \OCA\News\Core\Db;
use \OCA\News\Db\DoesNotExistException;
use \OCA\News\Db\MultipleObjectsReturnedException;
use \OCA\News\Db\Mapper;
@@ -33,8 +33,8 @@ use \OCA\News\Db\StatusFlag;
class ItemMapper extends \OCA\News\Db\ItemMapper {
- public function __construct(API $api){
- parent::__construct($api);
+ public function __construct(Db $db){
+ parent::__construct($db, 'news_items', '\OCA\News\Db\Item');
}