BIND 10 trac1061, updated. 29f8206c55da69ea889ee4bd012f28c28ba90fe4 [trac1061] Doxygen comments for database classes
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Jul 28 13:43:31 UTC 2011
The branch, trac1061 has been updated
via 29f8206c55da69ea889ee4bd012f28c28ba90fe4 (commit)
via 03c00dfe4e92b1ff0d434da7218ef16a1f3a5202 (commit)
from 0d2c284222839ff21401cecb7cb567cb0cc04127 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 29f8206c55da69ea889ee4bd012f28c28ba90fe4
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Jul 28 15:42:45 2011 +0200
[trac1061] Doxygen comments for database classes
commit 03c00dfe4e92b1ff0d434da7218ef16a1f3a5202
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Jul 28 13:47:17 2011 +0200
[trac1061] Interface of the database connection and client
It will look something like this, hopefully. Let's see if it works.
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/Makefile.am | 1 +
src/lib/datasrc/client.h | 2 +
src/lib/datasrc/{logger.cc => database.cc} | 4 +-
src/lib/datasrc/database.h | 174 ++++++++++++++++++++++++++++
4 files changed, 178 insertions(+), 3 deletions(-)
copy src/lib/datasrc/{logger.cc => database.cc} (92%)
create mode 100644 src/lib/datasrc/database.h
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/Makefile.am b/src/lib/datasrc/Makefile.am
index 261baae..eecd26a 100644
--- a/src/lib/datasrc/Makefile.am
+++ b/src/lib/datasrc/Makefile.am
@@ -22,6 +22,7 @@ libdatasrc_la_SOURCES += zone.h
libdatasrc_la_SOURCES += result.h
libdatasrc_la_SOURCES += logger.h logger.cc
libdatasrc_la_SOURCES += client.h
+libdatasrc_la_SOURCES += database.h database.cc
nodist_libdatasrc_la_SOURCES = datasrc_messages.h datasrc_messages.cc
libdatasrc_la_LIBADD = $(top_builddir)/src/lib/exceptions/libexceptions.la
diff --git a/src/lib/datasrc/client.h b/src/lib/datasrc/client.h
index a830f00..9fe6519 100644
--- a/src/lib/datasrc/client.h
+++ b/src/lib/datasrc/client.h
@@ -15,6 +15,8 @@
#ifndef __DATA_SOURCE_CLIENT_H
#define __DATA_SOURCE_CLIENT_H 1
+#include <boost/noncopyable.hpp>
+
#include <datasrc/zone.h>
namespace isc {
diff --git a/src/lib/datasrc/database.cc b/src/lib/datasrc/database.cc
new file mode 100644
index 0000000..71014d2
--- /dev/null
+++ b/src/lib/datasrc/database.cc
@@ -0,0 +1,21 @@
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#include <datasrc/database.h>
+
+namespace isc {
+namespace datasrc {
+
+}
+}
diff --git a/src/lib/datasrc/database.h b/src/lib/datasrc/database.h
new file mode 100644
index 0000000..e949ec3
--- /dev/null
+++ b/src/lib/datasrc/database.h
@@ -0,0 +1,174 @@
+// Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef __DATABASE_DATASRC_H
+#define __DATABASE_DATASRC_H
+
+#include <datasrc/client.h>
+
+namespace isc {
+namespace datasrc {
+
+/**
+ * \brief Abstract connection to 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
+ * manner. The methods are meant to be low-level, without much or any knowledge
+ * about DNS and should be possible to translate directly to queries.
+ *
+ * On the other hand, how the communication with database is done and in what
+ * schema (in case of relational/SQL database) is up to the concrete classes.
+ *
+ * This class is non-copyable, as copying connections to database makes little
+ * sense and will not be needed.
+ *
+ * \todo Is it true this does not need to be copied? For example the zone
+ * iterator might need it's own copy. But a virtual clone() method might
+ * 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.
+ */
+class DatabaseConnection : boost::noncopyable {
+public:
+ /**
+ * \brief Destructor
+ *
+ * It is empty, but needs a virtual one, since we will use the derived
+ * classes in polymorphic way.
+ */
+ virtual ~ DatabaseConnection() { }
+ /**
+ * \brief Retrieve a zone identifier
+ *
+ * This method looks up a zone for the given name in the database. It
+ * should match only exact zone name (eg. name is equal to the zone's
+ * apex), as the DatabaseClient will loop trough the labels itself and
+ * find the most suitable zone.
+ *
+ * It is not specified if and what implementation of this method may throw,
+ * so code should expect anything.
+ *
+ * \param name The name of the zone's apex to be looked up.
+ * \return The first part of the result indicates if a matching zone
+ * 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
+ * an opaque handle.
+ */
+ virtual std::pair<bool, int> getZone(const isc::dns::Name& name) const;
+};
+
+/**
+ * \brief Concrete data source client oriented at database backends.
+ *
+ * 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
+ * if necessary and validates data from the database, allowing the
+ * DatabaseConnection 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.
+ */
+class DatabaseClient : public DataSourceClient {
+public:
+ /**
+ * \brief Constructor
+ *
+ * It initializes the client with a connection.
+ *
+ * It throws isc::InvalidParameter if connection 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
+ * delete it when itself deleted.
+ */
+ DatabaseClient(const std::auto_ptr<DatabaseConnection>& connection);
+ /**
+ * \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.
+ *
+ * Application should not come directly in contact with this class
+ * (it should handle it trough generic ZoneFinder pointer), therefore
+ * it could be completely hidden in the .cc file. But it is provided
+ * to allow testing and for rare cases when a database needs slightly
+ * different handling, so it can be subclassed.
+ *
+ * Methods directly corresponds to the ones in ZoneFinder.
+ */
+ class Finder : public ZoneFinder {
+ public:
+ /**
+ * \brief Constructor
+ *
+ * \param connection The connection (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.
+ */
+ Finder(DatabaseConnection& connection, int zone_id);
+ virtual const isc::dns::Name& getOrigin() const;
+ virtual const isc::dns::RRClass& getClass() const;
+ virtual FindResult find(const isc::dns::Name& name,
+ const isc::dns::RRType& type,
+ isc::dns::RRsetList* target = NULL,
+ const FindOptions options = FIND_DEFAULT)
+ const = 0;
+ private:
+ DatabaseConnection& connection_;
+ const int zone_id_;
+ };
+ /**
+ * \brief Find a zone in the database
+ *
+ * This queries connection'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.
+ */
+ virtual FindResult findZone(const isc::dns::Name& name) const;
+private:
+ /// \brief Our connection.
+ const std::auto_ptr<DatabaseConnection> connection_;
+};
+
+}
+}
+
+#endif
More information about the bind10-changes
mailing list