Skip to content

Commit

Permalink
renamed classes
Browse files Browse the repository at this point in the history
* SqliteAdapter --> SqliteCacheAdapter
* DevNullAdapter --> DevNullCacheAdapter
  • Loading branch information
janpieper committed Feb 8, 2015
1 parent e49df59 commit 933c932
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 78 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ Easy to use cache library written in Qt/C++
#include <QCoreApplication>
#include <QDebug>

#include "sqliteadapter.hpp"
#include "sqlitecacheadapter.hpp"

using namespace Bidstack;
using namespace Bidstack::Cache;

int main(int argc, char *argv[]) {
QCoreApplication app(argc, argv);

Cache::SqliteAdapter *cache = new Cache::SqliteAdapter("cache.sqlite");
SqliteCacheAdapter *cache = new SqliteCacheAdapter("cache.sqlite");

qDebug() << "Has 'key_a'? -" << (cache->has("key_a") ? "yes" : "no");
qDebug() << "Has 'key_b'? -" << (cache->has("key_b") ? "yes" : "no");
Expand Down
7 changes: 0 additions & 7 deletions abstractadapter.cpp

This file was deleted.

7 changes: 7 additions & 0 deletions abstractcacheadapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "abstractcacheadapter.hpp"

using namespace Bidstack::Cache;

AbstractCacheAdapter::AbstractCacheAdapter(QObject *parent) : QObject(parent) {

}
8 changes: 4 additions & 4 deletions abstractadapter.hpp → abstractcacheadapter.hpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#ifndef BIDSTACK_CACHE_ABSTRACTADAPTER_HPP
#define BIDSTACK_CACHE_ABSTRACTADAPTER_HPP
#ifndef BIDSTACK_CACHE_ABSTRACTCACHEADAPTER_HPP
#define BIDSTACK_CACHE_ABSTRACTCACHEADAPTER_HPP

#include <QObject>

namespace Bidstack {
namespace Cache {

class AbstractAdapter : public QObject {
class AbstractCacheAdapter : public QObject {
Q_OBJECT

public:
AbstractAdapter(QObject *parent = 0);
AbstractCacheAdapter(QObject *parent = 0);

public:
virtual bool store(QString key, QString data) =0;
Expand Down
43 changes: 0 additions & 43 deletions devnulladapter.cpp

This file was deleted.

43 changes: 43 additions & 0 deletions devnullcacheadapter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "devnullcacheadapter.hpp"

using namespace Bidstack::Cache;

DevNullCacheAdapter::DevNullCacheAdapter(QObject *parent) : AbstractCacheAdapter(parent) {

}

bool DevNullCacheAdapter::store(QString key, QString data) {
return store(key, data, 0);
}

bool DevNullCacheAdapter::store(QString key, QString data, int ttl) {
Q_UNUSED(key);
Q_UNUSED(data);
Q_UNUSED(ttl);
return true;
}

bool DevNullCacheAdapter::has(QString key) {
Q_UNUSED(key);
return false;
}

bool DevNullCacheAdapter::remove(QString key) {
Q_UNUSED(key);
return true;
}

bool DevNullCacheAdapter::clear() {
return true;
}

QString DevNullCacheAdapter::fetch(QString key) {
Q_UNUSED(key);
return "";
}

QString DevNullCacheAdapter::fetch(QString key, QString defaultValue) {
Q_UNUSED(key);
Q_UNUSED(defaultValue);
return defaultValue;
}
10 changes: 5 additions & 5 deletions devnulladapter.hpp → devnullcacheadapter.hpp
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#ifndef BIDSTACK_CACHE_DEVNULLADAPTER_HPP
#define BIDSTACK_CACHE_DEVNULLADAPTER_HPP
#ifndef BIDSTACK_CACHE_DEVNULLCACHEADAPTER_HPP
#define BIDSTACK_CACHE_DEVNULLCACHEADAPTER_HPP

#include <QObject>

#include "abstractadapter.hpp"
#include "abstractcacheadapter.hpp"

namespace Bidstack {
namespace Cache {

class DevNullAdapter : public AbstractAdapter {
class DevNullCacheAdapter : public AbstractCacheAdapter {
Q_OBJECT

public:
DevNullAdapter(QObject *parent = 0);
DevNullCacheAdapter(QObject *parent = 0);

public:
bool store(QString key, QString data);
Expand Down
22 changes: 11 additions & 11 deletions sqliteadapter.cpp → sqlitecacheadapter.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include "sqliteadapter.hpp"
#include "sqlitecacheadapter.hpp"

#include <QDateTime>

using namespace Bidstack::Cache;

SqliteAdapter::SqliteAdapter(QString filename, QObject *parent) : AbstractAdapter(parent) {
SqliteCacheAdapter::SqliteCacheAdapter(QString filename, QObject *parent) : AbstractCacheAdapter(parent) {
if (!init(filename)) {
throw "Could not initialize database connection!";
}
}

bool SqliteAdapter::init(QString filename) {
bool SqliteCacheAdapter::init(QString filename) {
m_connection = QSqlDatabase::addDatabase("QSQLITE", "bidstack-cache");
m_connection.setDatabaseName(filename);

Expand All @@ -31,11 +31,11 @@ bool SqliteAdapter::init(QString filename) {
return !stmt.lastError().isValid();
}

bool SqliteAdapter::store(QString key, QString data) {
bool SqliteCacheAdapter::store(QString key, QString data) {
return store(key, data, 0);
}

bool SqliteAdapter::store(QString key, QString data, int ttl) {
bool SqliteCacheAdapter::store(QString key, QString data, int ttl) {
const QString sql =
"INSERT OR REPLACE INTO cache (key, data, expires_at) "
"VALUES (:key, :data, :expires_at)";
Expand All @@ -50,11 +50,11 @@ bool SqliteAdapter::store(QString key, QString data, int ttl) {
return !stmt.lastError().isValid();
}

bool SqliteAdapter::has(QString key) {
bool SqliteCacheAdapter::has(QString key) {
return !fetch(key).isEmpty();
}

bool SqliteAdapter::remove(QString key) {
bool SqliteCacheAdapter::remove(QString key) {
const QString sql = "DELETE FROM cache WHERE key = :key";

QSqlQuery stmt(m_connection);
Expand All @@ -65,7 +65,7 @@ bool SqliteAdapter::remove(QString key) {
return !stmt.lastError().isValid();
}

bool SqliteAdapter::clear() {
bool SqliteCacheAdapter::clear() {
const QString sql = "DELETE FROM cache";

QSqlQuery stmt(m_connection);
Expand All @@ -75,7 +75,7 @@ bool SqliteAdapter::clear() {
return !stmt.lastError().isValid();
}

QString SqliteAdapter::fetch(QString key) {
QString SqliteCacheAdapter::fetch(QString key) {
const QString sql = "SELECT expires_at, data FROM cache WHERE key = :key";

QSqlQuery stmt(m_connection);
Expand All @@ -98,10 +98,10 @@ QString SqliteAdapter::fetch(QString key) {
return "";
}

QString SqliteAdapter::fetch(QString key, QString defaultValue) {
QString SqliteCacheAdapter::fetch(QString key, QString defaultValue) {
return has(key) ? fetch(key) : defaultValue;
}

uint SqliteAdapter::now() {
uint SqliteCacheAdapter::now() {
return QDateTime::currentDateTime().toTime_t();
}
10 changes: 5 additions & 5 deletions sqliteadapter.hpp → sqlitecacheadapter.hpp
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
#ifndef BIDSTACK_CACHE_SQLITEADAPTER_HPP
#define BIDSTACK_CACHE_SQLITEADAPTER_HPP
#ifndef BIDSTACK_CACHE_SQLITECACHEADAPTER_HPP
#define BIDSTACK_CACHE_SQLITECACHEADAPTER_HPP

#include <QObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QSqlError>
#include <QDebug>

#include "abstractadapter.hpp"
#include "abstractcacheadapter.hpp"

namespace Bidstack {
namespace Cache {

class SqliteAdapter : public AbstractAdapter {
class SqliteCacheAdapter : public AbstractCacheAdapter {
Q_OBJECT

public:
SqliteAdapter(QString filename, QObject *parent = 0);
SqliteCacheAdapter(QString filename, QObject *parent = 0);

public:
bool store(QString key, QString data);
Expand Down

0 comments on commit 933c932

Please sign in to comment.