Browse Source

Merge remote-tracking branch 'origin/trac1061' into HEAD

Conflicts:
	src/lib/datasrc/sqlite3_database.h
	src/lib/datasrc/tests/Makefile.am
	src/lib/datasrc/tests/database_unittest.cc
	src/lib/datasrc/tests/sqlite3_database_unittest.cc

To bring in renaming of DatabaseConnection and few other small changes.
Michal 'vorner' Vaner 13 years ago
parent
commit
d4867b8dd1

+ 1 - 1
src/lib/datasrc/Makefile.am

@@ -23,7 +23,7 @@ libdatasrc_la_SOURCES += result.h
 libdatasrc_la_SOURCES += logger.h logger.cc
 libdatasrc_la_SOURCES += client.h iterator.h
 libdatasrc_la_SOURCES += database.h database.cc
-libdatasrc_la_SOURCES += sqlite3_connection.h sqlite3_connection.cc
+libdatasrc_la_SOURCES += sqlite3_database.h sqlite3_database.cc
 nodist_libdatasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc
 
 libdatasrc_la_LIBADD = $(top_builddir)/src/lib/exceptions/libexceptions.la

+ 18 - 16
src/lib/datasrc/database.cc

@@ -29,31 +29,32 @@ using std::string;
 namespace isc {
 namespace datasrc {
 
-DatabaseClient::DatabaseClient(std::auto_ptr<DatabaseConnection> connection) :
-    connection_(connection)
+DatabaseClient::DatabaseClient(boost::shared_ptr<DatabaseAbstraction>
+                               database) :
+    database_(database)
 {
-    if (connection_.get() == NULL) {
+    if (database_.get() == NULL) {
         isc_throw(isc::InvalidParameter,
-                  "No connection provided to DatabaseClient");
+                  "No database provided to DatabaseClient");
     }
 }
 
 DataSourceClient::FindResult
 DatabaseClient::findZone(const Name& name) const {
-    std::pair<bool, int> zone(connection_->getZone(name));
+    std::pair<bool, int> zone(database_->getZone(name));
     // Try exact first
     if (zone.first) {
         return (FindResult(result::SUCCESS,
-                           ZoneFinderPtr(new Finder(*connection_,
+                           ZoneFinderPtr(new Finder(database_,
                                                     zone.second))));
     }
     // Than super domains
     // Start from 1, as 0 is covered above
     for (size_t i(1); i < name.getLabelCount(); ++i) {
-        zone = connection_->getZone(name.split(i));
+        zone = database_->getZone(name.split(i));
         if (zone.first) {
             return (FindResult(result::PARTIALMATCH,
-                               ZoneFinderPtr(new Finder(*connection_,
+                               ZoneFinderPtr(new Finder(database_,
                                                         zone.second))));
         }
     }
@@ -61,8 +62,9 @@ DatabaseClient::findZone(const Name& name) const {
     return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
 }
 
-DatabaseClient::Finder::Finder(DatabaseConnection& connection, int zone_id) :
-    connection_(connection),
+DatabaseClient::Finder::Finder(boost::shared_ptr<DatabaseAbstraction>
+                               database, int zone_id) :
+    database_(database),
     zone_id_(zone_id)
 { }
 
@@ -100,7 +102,7 @@ namespace {
  */
 class Iterator : public ZoneIterator {
 public:
-    Iterator(const DatabaseConnection::IteratorContextPtr& context,
+    Iterator(const DatabaseAbstraction::IteratorContextPtr& context,
              const RRClass& rrclass) :
         context_(context),
         class_(rrclass),
@@ -139,7 +141,7 @@ private:
         data_ready_ = context_->getNext(name_, rtype_, ttl_, rdata_);
     }
     // The context
-    const DatabaseConnection::IteratorContextPtr context_;
+    const DatabaseAbstraction::IteratorContextPtr context_;
     // Class of the zone
     RRClass class_;
     // Status
@@ -154,7 +156,7 @@ private:
 ZoneIteratorPtr
 DatabaseClient::getIterator(const isc::dns::Name& name) const {
     // Get the zone
-    std::pair<bool, int> zone(connection_->getZone(name));
+    std::pair<bool, int> zone(database_->getZone(name));
     if (!zone.first) {
         // No such zone, can't continue
         isc_throw(DataSourceError, "Zone " + name.toText() +
@@ -162,10 +164,10 @@ DatabaseClient::getIterator(const isc::dns::Name& name) const {
                   "in this data source");
     }
     // Request the context
-    DatabaseConnection::IteratorContextPtr
-        context(connection_->getIteratorContext(name, zone.second));
+    DatabaseAbstraction::IteratorContextPtr
+        context(database_->getIteratorContext(name, zone.second));
     // It must not return NULL, that's a bug of the implementation
-    if (context == DatabaseConnection::IteratorContextPtr()) {
+    if (context == DatabaseAbstraction::IteratorContextPtr()) {
         isc_throw(isc::Unexpected, "Iterator context null at " +
                   name.toText());
     }

+ 35 - 40
src/lib/datasrc/database.h

@@ -23,7 +23,7 @@ namespace isc {
 namespace datasrc {
 
 /**
- * \brief Abstract connection to database with DNS data
+ * \brief Abstraction of lowlevel database with DNS data
  *
  * This class is defines interface to databases. Each supported database
  * will provide methods for accessing the data stored there in a generic
@@ -41,10 +41,11 @@ namespace datasrc {
  *     be better for that than copy constructor.
  *
  * \note The same application may create multiple connections to the same
- *     database. If the database allows having multiple open queries at one
- *     connection, the connection class may share it.
+ *     database, having multiple instances of this class. If the database
+ *     allows having multiple open queries at one connection, the connection
+ *     class may share it.
  */
-class DatabaseConnection : boost::noncopyable {
+class DatabaseAbstraction : boost::noncopyable {
 public:
     /**
      * \brief Destructor
@@ -52,7 +53,7 @@ public:
      * It is empty, but needs a virtual one, since we will use the derived
      * classes in polymorphic way.
      */
-    virtual ~ DatabaseConnection() { }
+    virtual ~DatabaseAbstraction() { }
     /**
      * \brief Retrieve a zone identifier
      *
@@ -69,7 +70,7 @@ public:
      *     was found. In case it was, the second part is internal zone ID.
      *     This one will be passed to methods finding data in the zone.
      *     It is not required to keep them, in which case whatever might
-     *     be returned - the ID is only passed back to the connection as
+     *     be returned - the ID is only passed back to the database as
      *     an opaque handle.
      */
     virtual std::pair<bool, int> getZone(const isc::dns::Name& name) const = 0;
@@ -158,46 +159,36 @@ public:
  *
  * This class (together with corresponding versions of ZoneFinder,
  * ZoneIterator, etc.) translates high-level data source queries to
- * low-level calls on DatabaseConnection. It calls multiple queries
+ * low-level calls on DatabaseAbstraction. It calls multiple queries
  * if necessary and validates data from the database, allowing the
- * DatabaseConnection to be just simple translation to SQL/other
+ * DatabaseAbstraction to be just simple translation to SQL/other
  * queries to database.
  *
  * While it is possible to subclass it for specific database in case
  * of special needs, it is not expected to be needed. This should just
- * work as it is with whatever DatabaseConnection.
+ * work as it is with whatever DatabaseAbstraction.
  */
 class DatabaseClient : public DataSourceClient {
 public:
     /**
      * \brief Constructor
      *
-     * It initializes the client with a connection.
+     * It initializes the client with a database.
      *
-     * It throws isc::InvalidParameter if connection is NULL. It might throw
+     * \exception isc::InvalidParameter if database is NULL. It might throw
      * standard allocation exception as well, but doesn't throw anything else.
      *
-     * \note Some objects returned from methods of this class (like ZoneFinder)
-     *     hold references to the connection. As the lifetime of the connection
-     *     is bound to this object, the returned objects must not be used after
-     *     descruction of the DatabaseClient.
-     *
-     * \todo Should we use shared_ptr instead? On one side, we would get rid of
-     *     the restriction and maybe could easy up some shutdown scenarios with
-     *     multi-threaded applications, on the other hand it is more expensive
-     *     and looks generally unneeded.
-     *
-     * \param connection The connection to use to get data. As the parameter
-     *     suggests, the client takes ownership of the connection and will
+     * \param database The database to use to get data. As the parameter
+     *     suggests, the client takes ownership of the database and will
      *     delete it when itself deleted.
      */
-    DatabaseClient(std::auto_ptr<DatabaseConnection> connection);
+    DatabaseClient(boost::shared_ptr<DatabaseAbstraction> database);
     /**
      * \brief Corresponding ZoneFinder implementation
      *
      * The zone finder implementation for database data sources. Similarly
      * to the DatabaseClient, it translates the queries to methods of the
-     * connection.
+     * database.
      *
      * Application should not come directly in contact with this class
      * (it should handle it trough generic ZoneFinder pointer), therefore
@@ -212,13 +203,15 @@ public:
         /**
          * \brief Constructor
          *
-         * \param connection The connection (shared with DatabaseClient) to
+         * \param database The database (shared with DatabaseClient) to
          *     be used for queries (the one asked for ID before).
          * \param zone_id The zone ID which was returned from
-         *     DatabaseConnection::getZone and which will be passed to further
-         *     calls to the connection.
+         *     DatabaseAbstraction::getZone and which will be passed to further
+         *     calls to the database.
          */
-        Finder(DatabaseConnection& connection, int zone_id);
+        Finder(boost::shared_ptr<DatabaseAbstraction> database, int zone_id);
+        // The following three methods are just implementations of inherited
+        // ZoneFinder's pure virtual methods.
         virtual isc::dns::Name getOrigin() const;
         virtual isc::dns::RRClass getClass() const;
         virtual FindResult find(const isc::dns::Name& name,
@@ -235,30 +228,32 @@ public:
          */
         int zone_id() const { return (zone_id_); }
         /**
-         * \brief The database connection.
+         * \brief The database.
          *
-         * This function provides the database connection stored inside as
+         * This function provides the database stored inside as
          * passed to the constructor. This is meant for testing purposes and
          * normal applications shouldn't need it.
          */
-        const DatabaseConnection& connection() const {
-            return (connection_);
+        const DatabaseAbstraction& database() const {
+            return (*database_);
         }
     private:
-        DatabaseConnection& connection_;
+        boost::shared_ptr<DatabaseAbstraction> database_;
         const int zone_id_;
     };
     /**
      * \brief Find a zone in the database
      *
-     * This queries connection's getZone to find the best matching zone.
+     * This queries database's getZone to find the best matching zone.
      * It will propagate whatever exceptions are thrown from that method
      * (which is not restricted in any way).
      *
      * \param name Name of the zone or data contained there.
-     * \return Result containing the code and instance of Finder, if anything
-     *     is found. Applications should not rely on the specific class being
-     *     returned, though.
+     * \return FindResult containing the code and an instance of Finder, if
+     *     anything is found. However, application should not rely on the
+     *     ZoneFinder being instance of Finder (possible subclass of this class
+     *     may return something else and it may change in future versions), it
+     *     should use it as a ZoneFinder only.
      */
     virtual FindResult findZone(const isc::dns::Name& name) const;
     /**
@@ -280,8 +275,8 @@ public:
      */
     virtual ZoneIteratorPtr getIterator(const isc::dns::Name& name) const;
 private:
-    /// \brief Our connection.
-    const std::auto_ptr<DatabaseConnection> connection_;
+    /// \brief Our database.
+    const boost::shared_ptr<DatabaseAbstraction> database_;
 };
 
 }

+ 21 - 20
src/lib/datasrc/sqlite3_connection.cc

@@ -14,7 +14,7 @@
 
 #include <sqlite3.h>
 
-#include <datasrc/sqlite3_connection.h>
+#include <datasrc/sqlite3_database.h>
 #include <datasrc/logger.h>
 #include <datasrc/data_source.h>
 
@@ -44,19 +44,14 @@ struct SQLite3Parameters {
     */
 };
 
-SQLite3Connection::SQLite3Connection(const isc::data::ConstElementPtr&
-                                     config,
+SQLite3Database::SQLite3Database(const std::string& filename,
                                      const isc::dns::RRClass& rrclass) :
     dbparameters_(new SQLite3Parameters),
     class_(rrclass.toText())
 {
     LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_SQLITE_NEWCONN);
 
-    if (config && config->contains("database_file")) {
-        open(config->get("database_file")->stringValue());
-    } else {
-        isc_throw(DataSourceError, "No SQLite database file specified");
-    }
+    open(filename);
 }
 
 namespace {
@@ -224,7 +219,7 @@ checkAndSetupSchema(Initializer* initializer) {
 }
 
 void
-SQLite3Connection::open(const std::string& name) {
+SQLite3Database::open(const std::string& name) {
     LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_SQLITE_CONNOPEN).arg(name);
     if (dbparameters_->db_ != NULL) {
         // There shouldn't be a way to trigger this anyway
@@ -241,7 +236,7 @@ SQLite3Connection::open(const std::string& name) {
     initializer.move(dbparameters_);
 }
 
-SQLite3Connection::~ SQLite3Connection() {
+SQLite3Database::~SQLite3Database() {
     LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_SQLITE_DROPCONN);
     if (dbparameters_->db_ != NULL) {
         close();
@@ -250,7 +245,7 @@ SQLite3Connection::~ SQLite3Connection() {
 }
 
 void
-SQLite3Connection::close(void) {
+SQLite3Database::close(void) {
     LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_SQLITE_CONNCLOSE);
     if (dbparameters_->db_ == NULL) {
         isc_throw(DataSourceError,
@@ -292,9 +287,11 @@ SQLite3Connection::close(void) {
 }
 
 std::pair<bool, int>
-SQLite3Connection::getZone(const isc::dns::Name& name) const {
+SQLite3Database::getZone(const isc::dns::Name& name) const {
     int rc;
 
+    // Take the statement (simple SELECT id FROM zones WHERE...)
+    // and prepare it (bind the parameters to it)
     sqlite3_reset(dbparameters_->q_zone_);
     rc = sqlite3_bind_text(dbparameters_->q_zone_, 1, name.toText().c_str(),
                            -1, SQLITE_STATIC);
@@ -309,6 +306,7 @@ SQLite3Connection::getZone(const isc::dns::Name& name) const {
                   " to SQL statement (zone)");
     }
 
+    // Get the data there and see if it found anything
     rc = sqlite3_step(dbparameters_->q_zone_);
     std::pair<bool, int> result;
     if (rc == SQLITE_ROW) {
@@ -318,7 +316,9 @@ SQLite3Connection::getZone(const isc::dns::Name& name) const {
     } else {
         result = std::pair<bool, int>(false, 0);
     }
+    // Free resources
     sqlite3_reset(dbparameters_->q_zone_);
+
     return (result);
 }
 
@@ -332,14 +332,14 @@ getstr(const unsigned char* str) {
 
 }
 
-class SQLite3Connection::Context : public DatabaseConnection::IteratorContext {
+class SQLite3Database::Context : public DatabaseAbstraction::IteratorContext {
 public:
-    Context(boost::shared_ptr<const SQLite3Connection> connection, int id) :
-        connection_(connection),
+    Context(const boost::shared_ptr<const SQLite3Database>& database, int id) :
+        database_(database),
         statement(NULL)
     {
         // We create the statement now and then just keep getting data from it
-        statement = prepare(connection->dbparameters_->db_, q_iterate_str);
+        statement = prepare(database->dbparameters_->db_, q_iterate_str);
         if (sqlite3_bind_int(statement, 1, id) != SQLITE_OK) {
             isc_throw(SQLite3Error, "Could not bind " << id <<
                       " to SQL statement (iterate)");
@@ -359,17 +359,18 @@ public:
         return (false);
     }
     virtual ~Context() {
-        if (statement)
+        if (statement) {
             sqlite3_finalize(statement);
+        }
     }
 
 private:
-    boost::shared_ptr<const SQLite3Connection> connection_;
+    boost::shared_ptr<const SQLite3Database> database_;
     sqlite3_stmt *statement;
 };
 
-DatabaseConnection::IteratorContextPtr
-SQLite3Connection::getIteratorContext(const isc::dns::Name&, int id) const {
+DatabaseAbstraction::IteratorContextPtr
+SQLite3Database::getIteratorContext(const isc::dns::Name&, int id) const {
     return (IteratorContextPtr(new Context(shared_from_this(), id)));
 }
 

+ 13 - 19
src/lib/datasrc/sqlite3_connection.h

@@ -19,7 +19,6 @@
 #include <datasrc/database.h>
 
 #include <exceptions/exceptions.h>
-#include <cc/data.h>
 
 #include <boost/enable_shared_from_this.hpp>
 #include <string>
@@ -47,49 +46,44 @@ public:
 struct SQLite3Parameters;
 
 /**
- * \brief Concrete implementation of DatabaseConnection for SQLite3 databases
+ * \brief Concrete implementation of DatabaseAbstraction for SQLite3 databases
  *
  * This opens one database file with our schema and serves data from there.
  * According to the design, it doesn't interpret the data in any way, it just
  * provides unified access to the DB.
  */
-class SQLite3Connection : public DatabaseConnection,
-    public boost::enable_shared_from_this<SQLite3Connection> {
+class SQLite3Database : public DatabaseAbstraction,
+    public boost::enable_shared_from_this<SQLite3Database> {
 public:
     /**
      * \brief Constructor
      *
      * This opens the database and becomes ready to serve data from there.
      *
-     * This might throw SQLite3Error if the given database file doesn't work
-     * (it is broken, doesn't exist and can't be created, etc). It might throw
-     * DataSourceError if the provided config is invalid (it is missing the
-     * database_file element).
+     * \exception SQLite3Error will be thrown if the given database file
+     * doesn't work (it is broken, doesn't exist and can't be created, etc).
      *
-     * \param config The part of config describing which database file should
-     *     be used.
+     * \param filename The database file to be used.
      * \param rrclass Which class of data it should serve (while the database
-     *     can contain multiple classes of data, single connection can provide
-     *     only one class).
-     * \todo Should we pass the database filename instead of the config? It
-     *     might be cleaner if this class doesn't know anything about configs.
+     *     file can contain multiple classes of data, single database can
+     *     provide only one class).
      */
-    SQLite3Connection(const isc::data::ConstElementPtr& config,
-                      const isc::dns::RRClass& rrclass);
+    SQLite3Database(const std::string& filename,
+                    const isc::dns::RRClass& rrclass);
     /**
      * \brief Destructor
      *
      * Closes the database.
      */
-    ~ SQLite3Connection();
+    ~SQLite3Database();
     /**
      * \brief Look up a zone
      *
-     * This implements the getZone from DatabaseConnection and looks up a zone
+     * This implements the getZone from DatabaseAbstraction and looks up a zone
      * in the data. It looks for a zone with the exact given origin and class
      * passed to the constructor.
      *
-     * It may throw SQLite3Error if something about the database is broken.
+     * \exception SQLite3Error if something about the database is broken.
      *
      * \param name The name of zone to look up
      * \return The pair contains if the lookup was successful in the first

+ 1 - 1
src/lib/datasrc/tests/Makefile.am

@@ -29,7 +29,7 @@ run_unittests_SOURCES += zonetable_unittest.cc
 run_unittests_SOURCES += memory_datasrc_unittest.cc
 run_unittests_SOURCES += logger_unittest.cc
 run_unittests_SOURCES += database_unittest.cc
-run_unittests_SOURCES += sqlite3_connection_unittest.cc
+run_unittests_SOURCES += sqlite3_database_unittest.cc
 run_unittests_SOURCES += client_unittest.cc
 
 run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)

+ 15 - 15
src/lib/datasrc/tests/database_unittest.cc

@@ -33,7 +33,7 @@ namespace {
  * A connection with minimum implementation, keeping the original
  * "NotImplemented" methods.
  */
-class NopConnection : public DatabaseConnection {
+class NopAbstraction : public DatabaseAbstraction {
 public:
     virtual std::pair<bool, int> getZone(const Name& name) const {
         if (name == Name("example.org")) {
@@ -57,7 +57,7 @@ public:
  * It has the same getZone method as NopConnection, but it provides
  * implementation of the optional functionality.
  */
-class MockConnection : public NopConnection {
+class MockAbstraction : public NopAbstraction {
 private:
     class MockIteratorContext : public IteratorContext {
     private:
@@ -165,7 +165,7 @@ public:
 // This tests the default getIteratorContext behaviour, throwing NotImplemented
 TEST(DatabaseConnectionTest, getIteratorContext) {
     // The parameters don't matter
-    EXPECT_THROW(NopConnection().getIteratorContext(Name("."), 1),
+    EXPECT_THROW(NopAbstraction().getIteratorContext(Name("."), 1),
                  isc::NotImplemented);
 }
 
@@ -179,16 +179,16 @@ public:
      * times per test.
      */
     void createClient() {
-        current_connection_ = new MockConnection();
-        client_.reset(new DatabaseClient(auto_ptr<DatabaseConnection>(
-             current_connection_)));
+        current_database_ = new MockAbstraction();
+        client_.reset(new DatabaseClient(shared_ptr<DatabaseAbstraction>(
+             current_database_)));
     }
     // Will be deleted by client_, just keep the current value for comparison.
-    MockConnection* current_connection_;
-    auto_ptr<DatabaseClient> client_;
+    MockAbstraction* current_database_;
+    shared_ptr<DatabaseClient> client_;
     /**
      * Check the zone finder is a valid one and references the zone ID and
-     * connection available here.
+     * database available here.
      */
     void checkZoneFinder(const DataSourceClient::FindResult& zone) {
         ASSERT_NE(ZoneFinderPtr(), zone.zone_finder) << "No zone finder";
@@ -197,7 +197,7 @@ public:
         ASSERT_NE(shared_ptr<DatabaseClient::Finder>(), finder) <<
             "Wrong type of finder";
         EXPECT_EQ(42, finder->zone_id());
-        EXPECT_EQ(current_connection_, &finder->connection());
+        EXPECT_EQ(current_database_, &finder->database());
     }
 };
 
@@ -220,7 +220,7 @@ TEST_F(DatabaseClientTest, superZone) {
 }
 
 TEST_F(DatabaseClientTest, noConnException) {
-    EXPECT_THROW(DatabaseClient(auto_ptr<DatabaseConnection>()),
+    EXPECT_THROW(DatabaseClient(shared_ptr<DatabaseAbstraction>()),
                  isc::InvalidParameter);
 }
 
@@ -232,14 +232,14 @@ TEST_F(DatabaseClientTest, noZoneIterator) {
 // If the zone doesn't exist and iteration is not implemented, it still throws
 // the exception it doesn't exist
 TEST_F(DatabaseClientTest, noZoneNotImplementedIterator) {
-    EXPECT_THROW(DatabaseClient(auto_ptr<DatabaseConnection>(
-        new NopConnection())).getIterator(Name("example.com")),
+    EXPECT_THROW(DatabaseClient(boost::shared_ptr<DatabaseAbstraction>(
+        new NopAbstraction())).getIterator(Name("example.com")),
                  DataSourceError);
 }
 
 TEST_F(DatabaseClientTest, notImplementedIterator) {
-    EXPECT_THROW(DatabaseClient(auto_ptr<DatabaseConnection>(
-        new NopConnection())).getIterator(Name("example.org")),
+    EXPECT_THROW(DatabaseClient(shared_ptr<DatabaseAbstraction>(
+        new NopAbstraction())).getIterator(Name("example.org")),
                  isc::NotImplemented);
 }
 

+ 27 - 40
src/lib/datasrc/tests/sqlite3_connection_unittest.cc

@@ -12,7 +12,7 @@
 // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 // PERFORMANCE OF THIS SOFTWARE.
 
-#include <datasrc/sqlite3_connection.h>
+#include <datasrc/sqlite3_database.h>
 #include <datasrc/data_source.h>
 
 #include <dns/rrclass.h>
@@ -27,90 +27,77 @@ using isc::dns::Name;
 
 namespace {
 // Some test data
-ConstElementPtr SQLITE_DBFILE_EXAMPLE = Element::fromJSON(
-    "{ \"database_file\": \"" TEST_DATA_DIR "/test.sqlite3\"}");
-ConstElementPtr SQLITE_DBFILE_EXAMPLE2 = Element::fromJSON(
-    "{ \"database_file\": \"" TEST_DATA_DIR "/example2.com.sqlite3\"}");
-ConstElementPtr SQLITE_DBFILE_EXAMPLE_ROOT = Element::fromJSON(
-    "{ \"database_file\": \"" TEST_DATA_DIR "/test-root.sqlite3\"}");
-ConstElementPtr SQLITE_DBFILE_BROKENDB = Element::fromJSON(
-    "{ \"database_file\": \"" TEST_DATA_DIR "/brokendb.sqlite3\"}");
-ConstElementPtr SQLITE_DBFILE_MEMORY = Element::fromJSON(
-    "{ \"database_file\": \":memory:\"}");
+std::string SQLITE_DBFILE_EXAMPLE = TEST_DATA_DIR "/test.sqlite3";
+std::string SQLITE_DBFILE_EXAMPLE2 = TEST_DATA_DIR "/example2.com.sqlite3";
+std::string SQLITE_DBFILE_EXAMPLE_ROOT = TEST_DATA_DIR "/test-root.sqlite3";
+std::string SQLITE_DBFILE_BROKENDB = TEST_DATA_DIR "/brokendb.sqlite3";
+std::string SQLITE_DBFILE_MEMORY = ":memory:";
 
 // The following file must be non existent and must be non"creatable";
 // the sqlite3 library will try to create a new DB file if it doesn't exist,
 // so to test a failure case the create operation should also fail.
 // The "nodir", a non existent directory, is inserted for this purpose.
-ConstElementPtr SQLITE_DBFILE_NOTEXIST = Element::fromJSON(
-    "{ \"database_file\": \"" TEST_DATA_DIR "/nodir/notexist\"}");
+std::string SQLITE_DBFILE_NOTEXIST = TEST_DATA_DIR "/nodir/notexist";
 
 // Opening works (the content is tested in different tests)
 TEST(SQLite3Open, common) {
-    EXPECT_NO_THROW(SQLite3Connection conn(SQLITE_DBFILE_EXAMPLE,
-                                           RRClass::IN()));
-}
-
-// Missing config
-TEST(SQLite3Open, noConfig) {
-    EXPECT_THROW(SQLite3Connection conn(Element::fromJSON("{}"),
-                                                          RRClass::IN()),
-                 DataSourceError);
+    EXPECT_NO_THROW(SQLite3Database db(SQLITE_DBFILE_EXAMPLE,
+                                       RRClass::IN()));
 }
 
 // The file can't be opened
 TEST(SQLite3Open, notExist) {
-    EXPECT_THROW(SQLite3Connection conn(SQLITE_DBFILE_NOTEXIST,
-                                        RRClass::IN()), SQLite3Error);
+    EXPECT_THROW(SQLite3Database db(SQLITE_DBFILE_NOTEXIST,
+                                    RRClass::IN()), SQLite3Error);
 }
 
 // It rejects broken DB
 TEST(SQLite3Open, brokenDB) {
-    EXPECT_THROW(SQLite3Connection conn(SQLITE_DBFILE_BROKENDB,
-                                        RRClass::IN()), SQLite3Error);
+    EXPECT_THROW(SQLite3Database db(SQLITE_DBFILE_BROKENDB,
+                                    RRClass::IN()), SQLite3Error);
 }
 
 // Test we can create the schema on the fly
 TEST(SQLite3Open, memoryDB) {
-    EXPECT_NO_THROW(SQLite3Connection conn(SQLITE_DBFILE_MEMORY,
-                                           RRClass::IN()));
+    EXPECT_NO_THROW(SQLite3Database db(SQLITE_DBFILE_MEMORY,
+                                       RRClass::IN()));
 }
 
-// Test fixture for querying the connection
+// Test fixture for querying the db
 class SQLite3Conn : public ::testing::Test {
 public:
     SQLite3Conn() {
         initConn(SQLITE_DBFILE_EXAMPLE, RRClass::IN());
     }
     // So it can be re-created with different data
-    void initConn(const ConstElementPtr& config, const RRClass& rrclass) {
-        conn.reset(new SQLite3Connection(config, rrclass));
+    void initConn(const std::string& filename, const RRClass& rrclass) {
+        db.reset(new SQLite3Database(filename, rrclass));
     }
-    // The tested connection
-    boost::shared_ptr<SQLite3Connection> conn;
+    // The tested db
+    boost::shared_ptr<SQLite3Database> db;
 };
 
 // This zone exists in the data, so it should be found
 TEST_F(SQLite3Conn, getZone) {
-    std::pair<bool, int> result(conn->getZone(Name("example.com")));
+    std::pair<bool, int> result(db->getZone(Name("example.com")));
     EXPECT_TRUE(result.first);
     EXPECT_EQ(1, result.second);
 }
 
 // But it should find only the zone, nothing below it
 TEST_F(SQLite3Conn, subZone) {
-    EXPECT_FALSE(conn->getZone(Name("sub.example.com")).first);
+    EXPECT_FALSE(db->getZone(Name("sub.example.com")).first);
 }
 
 // This zone is not there at all
 TEST_F(SQLite3Conn, noZone) {
-    EXPECT_FALSE(conn->getZone(Name("example.org")).first);
+    EXPECT_FALSE(db->getZone(Name("example.org")).first);
 }
 
 // This zone is there, but in different class
 TEST_F(SQLite3Conn, noClass) {
     initConn(SQLITE_DBFILE_EXAMPLE, RRClass::CH());
-    EXPECT_FALSE(conn->getZone(Name("example.com")).first);
+    EXPECT_FALSE(db->getZone(Name("example.com")).first);
 }
 
 // This tests the iterator context
@@ -119,9 +106,9 @@ TEST_F(SQLite3Conn, iterator) {
     initConn(SQLITE_DBFILE_EXAMPLE2, RRClass::IN());
 
     // Get the iterator context
-    DatabaseConnection::IteratorContextPtr
-        context(conn->getIteratorContext(Name("example2.com"), 1));
-    ASSERT_NE(DatabaseConnection::IteratorContextPtr(),
+    DatabaseAbstraction::IteratorContextPtr
+        context(db->getIteratorContext(Name("example2.com"), 1));
+    ASSERT_NE(DatabaseAbstraction::IteratorContextPtr(),
               context);
 
     std::string name, rtype, data;