Commit e5ae1675 authored by Jelte Jansen's avatar Jelte Jansen
Browse files

[2541] Add addZone() to the abstract database accessor base class

parent 0ece8832
......@@ -177,6 +177,26 @@ public:
/// an opaque handle.
virtual std::pair<bool, int> getZone(const std::string& name) const = 0;
/// \brief Add a new zone to the database
///
/// This method creates a new (and empty) zone in the database.
/// If a zone with the given name exists already, its zone_id value is
/// returned. Otherwise it is created, and the newly created zone_id
/// is returned.
///
/// Given the above, implementations should first do a lookup for the
/// given zone, and return the id if it exists.
///
/// Callers must start a transaction before calling this method,
/// implementations may throw DataSourceError if this has not been done.
/// Callers should also expect DataSourceErrors for other potential
/// problems.
///
/// \param name The (fully qualified) domain name of the zone to add.
/// \return The internal zone id of the zone (whether is existed already
/// or was created by this call).
virtual int addZone(const std::string& name) = 0;
/// \brief This holds the internal context of ZoneIterator for databases
///
/// While the ZoneIterator implementation from DatabaseClient does all the
......
......@@ -617,7 +617,7 @@ SQLite3Accessor::getZone(const std::string& name) const {
}
int
SQLite3Accessor::addZone(const std::string& zone_name) {
SQLite3Accessor::addZone(const std::string& name) {
// Transaction should have been started by the caller
if (!dbparameters_->in_transaction) {
isc_throw(DataSourceError, "performing addZone on SQLite3 "
......@@ -626,19 +626,19 @@ SQLite3Accessor::addZone(const std::string& zone_name) {
// First check if the zone exists, if it does, do nothing and
// return false
std::pair<bool, int> getzone_result = getZone(zone_name);
std::pair<bool, int> getzone_result = getZone(name);
if (getzone_result.first) {
return (getzone_result.second);
}
StatementProcessor proc(*dbparameters_, ADD_ZONE, "add zone");
proc.bindText(1, zone_name.c_str(), SQLITE_TRANSIENT);
proc.bindText(1, name.c_str(), SQLITE_TRANSIENT);
proc.bindText(2, class_.c_str(), SQLITE_TRANSIENT);
proc.exec();
// There are tricks to getting this in one go, but it is safer
// to do a new lookup
getzone_result = getZone(zone_name);
getzone_result = getZone(name);
assert(getzone_result.first);
return (getzone_result.second);
}
......
......@@ -150,11 +150,11 @@ public:
* is an SQLite3 error when performing the
* queries.
*
* \param zone_name The origin name of the zone to add
* \param name The origin name of the zone to add
* \return the id of the zone (either an existing one if the zone exists
* already, or the id of the newly created zone).
*/
virtual int addZone(const std::string& zone_name);
virtual int addZone(const std::string& name);
/** \brief Look up all resource records for a name
*
......
......@@ -274,6 +274,11 @@ public:
}
}
virtual int addZone(const std::string&) {
isc_throw(isc::NotImplemented,
"This database datasource can't add zones");
}
virtual boost::shared_ptr<DatabaseAccessor> clone() {
// This accessor is stateless, so we can simply return a new instance.
return (boost::shared_ptr<DatabaseAccessor>(new NopAccessor));
......@@ -1780,7 +1785,7 @@ doFindAllTestResult(ZoneFinder& finder, const isc::dns::Name& name,
expected_name, result->rrset->getName());
}
// When asking for an RRset where RRs somehow have different TTLs, it should
// When asking for an RRset where RRs somehow have different TTLs, it should
// convert to the lowest one.
TEST_F(MockDatabaseClientTest, ttldiff) {
ZoneIteratorPtr it(this->client_->getIterator(Name("example.org")));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment