Commit 8216d5db authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[1068] intermediate editorial cleanup: change database/db, etc to accessor

throughout the code (with fixing conflicts with the original implementation)
parent 1c834de9
......@@ -38,10 +38,10 @@ namespace isc {
namespace datasrc {
DatabaseClient::DatabaseClient(boost::shared_ptr<DatabaseAccessor>
database) :
database_(database)
accessor) :
accessor_(accessor)
{
if (database_.get() == NULL) {
if (!accessor_) {
isc_throw(isc::InvalidParameter,
"No database provided to DatabaseClient");
}
......@@ -49,21 +49,21 @@ DatabaseClient::DatabaseClient(boost::shared_ptr<DatabaseAccessor>
DataSourceClient::FindResult
DatabaseClient::findZone(const Name& name) const {
std::pair<bool, int> zone(database_->getZone(name));
std::pair<bool, int> zone(accessor_->getZone(name));
// Try exact first
if (zone.first) {
return (FindResult(result::SUCCESS,
ZoneFinderPtr(new Finder(database_,
ZoneFinderPtr(new Finder(accessor_,
zone.second, name))));
}
// Then super domains
// Start from 1, as 0 is covered above
for (size_t i(1); i < name.getLabelCount(); ++i) {
isc::dns::Name superdomain(name.split(i));
zone = database_->getZone(superdomain);
zone = accessor_->getZone(superdomain);
if (zone.first) {
return (FindResult(result::PARTIALMATCH,
ZoneFinderPtr(new Finder(database_,
ZoneFinderPtr(new Finder(accessor_,
zone.second,
superdomain))));
}
......@@ -72,10 +72,9 @@ DatabaseClient::findZone(const Name& name) const {
return (FindResult(result::NOTFOUND, ZoneFinderPtr()));
}
DatabaseClient::Finder::Finder(boost::shared_ptr<DatabaseAccessor>
database, int zone_id,
const isc::dns::Name& origin) :
database_(database),
DatabaseClient::Finder::Finder(boost::shared_ptr<DatabaseAccessor> accessor,
int zone_id, const isc::dns::Name& origin) :
accessor_(accessor),
zone_id_(zone_id),
origin_(origin)
{ }
......@@ -183,7 +182,7 @@ DatabaseClient::Finder::getRRset(const isc::dns::Name& name,
// Request the context
DatabaseAccessor::IteratorContextPtr
context(database_->getRecords(name, zone_id_));
context(accessor_->getRecords(name, zone_id_));
// It must not return NULL, that's a bug of the implementation
if (!context) {
isc_throw(isc::Unexpected, "Iterator context null at " +
......@@ -227,7 +226,7 @@ DatabaseClient::Finder::getRRset(const isc::dns::Name& name,
}
addOrCreate(result_rrset, name, getClass(), cur_type, cur_ttl,
columns[DatabaseAccessor::RDATA_COLUMN],
*database_);
*accessor_);
} else if (type != NULL && cur_type == *type) {
if (result_rrset &&
result_rrset->getType() == isc::dns::RRType::CNAME()) {
......@@ -240,7 +239,7 @@ DatabaseClient::Finder::getRRset(const isc::dns::Name& name,
}
addOrCreate(result_rrset, name, getClass(), cur_type, cur_ttl,
columns[DatabaseAccessor::RDATA_COLUMN],
*database_);
*accessor_);
} else if (want_cname && cur_type == isc::dns::RRType::CNAME()) {
// There should be no other data, so result_rrset should
// be empty.
......@@ -250,7 +249,7 @@ DatabaseClient::Finder::getRRset(const isc::dns::Name& name,
}
addOrCreate(result_rrset, name, getClass(), cur_type, cur_ttl,
columns[DatabaseAccessor::RDATA_COLUMN],
*database_);
*accessor_);
} else if (want_dname && cur_type == isc::dns::RRType::DNAME()) {
// There should be max one RR of DNAME present
if (result_rrset &&
......@@ -260,7 +259,7 @@ DatabaseClient::Finder::getRRset(const isc::dns::Name& name,
}
addOrCreate(result_rrset, name, getClass(), cur_type, cur_ttl,
columns[DatabaseAccessor::RDATA_COLUMN],
*database_);
*accessor_);
} else if (cur_type == isc::dns::RRType::RRSIG()) {
// If we get signatures before we get the actual data, we
// can't know which ones to keep and which to drop...
......@@ -306,7 +305,7 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
ZoneFinder::Result result_status = SUCCESS;
std::pair<bool, isc::dns::RRsetPtr> found;
logger.debug(DBG_TRACE_DETAILED, DATASRC_DATABASE_FIND_RECORDS)
.arg(database_->getDBName()).arg(name).arg(type);
.arg(accessor_->getDBName()).arg(name).arg(type);
// First, do we have any kind of delegation (NS/DNAME) here?
const Name origin(getOrigin());
......@@ -328,12 +327,12 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
if (result_rrset->getType() == isc::dns::RRType::NS()) {
LOG_DEBUG(logger, DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_DELEGATION).
arg(database_->getDBName()).arg(superdomain);
arg(accessor_->getDBName()).arg(superdomain);
result_status = DELEGATION;
} else {
LOG_DEBUG(logger, DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_DNAME).
arg(database_->getDBName()).arg(superdomain);
arg(accessor_->getDBName()).arg(superdomain);
result_status = DNAME;
}
// Don't search more
......@@ -352,7 +351,7 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
result_rrset->getType() == isc::dns::RRType::NS()) {
LOG_DEBUG(logger, DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_DELEGATION_EXACT).
arg(database_->getDBName()).arg(name);
arg(accessor_->getDBName()).arg(name);
result_status = DELEGATION;
} else if (result_rrset && type != isc::dns::RRType::CNAME() &&
result_rrset->getType() == isc::dns::RRType::CNAME()) {
......@@ -364,20 +363,20 @@ DatabaseClient::Finder::find(const isc::dns::Name& name,
if (records_found) {
logger.debug(DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_NXRRSET)
.arg(database_->getDBName()).arg(name)
.arg(accessor_->getDBName()).arg(name)
.arg(getClass()).arg(type);
result_status = NXRRSET;
} else {
logger.debug(DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_NXDOMAIN)
.arg(database_->getDBName()).arg(name)
.arg(accessor_->getDBName()).arg(name)
.arg(getClass()).arg(type);
result_status = NXDOMAIN;
}
} else {
logger.debug(DBG_TRACE_DETAILED,
DATASRC_DATABASE_FOUND_RRSET)
.arg(database_->getDBName()).arg(*result_rrset);
.arg(accessor_->getDBName()).arg(*result_rrset);
}
return (FindResult(result_status, result_rrset));
}
......@@ -472,7 +471,7 @@ private:
ZoneIteratorPtr
DatabaseClient::getIterator(const isc::dns::Name& name) const {
// Get the zone
std::pair<bool, int> zone(database_->getZone(name));
std::pair<bool, int> zone(accessor_->getZone(name));
if (!zone.first) {
// No such zone, can't continue
isc_throw(DataSourceError, "Zone " + name.toText() +
......@@ -481,7 +480,7 @@ DatabaseClient::getIterator(const isc::dns::Name& name) const {
}
// Request the context
DatabaseAccessor::IteratorContextPtr
context(database_->getAllRecords(zone.second));
context(accessor_->getAllRecords(zone.second));
// It must not return NULL, that's a bug of the implementation
if (context == DatabaseAccessor::IteratorContextPtr()) {
isc_throw(isc::Unexpected, "Iterator context null at " +
......
......@@ -361,18 +361,19 @@ public:
* applications shouldn't need it.
*/
int zone_id() const { return (zone_id_); }
/**
* \brief The database.
* \brief The database accessor.
*
* This function provides the database stored inside as
* This function provides the database accessor stored inside as
* passed to the constructor. This is meant for testing purposes and
* normal applications shouldn't need it.
*/
const DatabaseAccessor& database() const {
return (*database_);
const DatabaseAccessor& getAccessor() const {
return (*accessor_);
}
private:
boost::shared_ptr<DatabaseAccessor> database_;
boost::shared_ptr<DatabaseAccessor> accessor_;
const int zone_id_;
const isc::dns::Name origin_;
/**
......@@ -417,6 +418,7 @@ public:
bool want_dname,
bool want_ns);
};
/**
* \brief Find a zone in the database
*
......@@ -453,8 +455,8 @@ public:
virtual ZoneIteratorPtr getIterator(const isc::dns::Name& name) const;
private:
/// \brief Our database.
const boost::shared_ptr<DatabaseAccessor> database_;
/// \brief The accessor to our database.
const boost::shared_ptr<DatabaseAccessor> accessor_;
};
}
......
......@@ -119,7 +119,7 @@ private:
const char* const desc_;
};
SQLite3Database::SQLite3Database(const std::string& filename,
SQLite3Accessor::SQLite3Accessor(const std::string& filename,
const isc::dns::RRClass& rrclass) :
dbparameters_(new SQLite3Parameters),
class_(rrclass.toText()),
......@@ -224,7 +224,7 @@ checkAndSetupSchema(Initializer* initializer) {
}
void
SQLite3Database::open(const std::string& name) {
SQLite3Accessor::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 +241,7 @@ SQLite3Database::open(const std::string& name) {
initializer.move(dbparameters_.get());
}
SQLite3Database::~SQLite3Database() {
SQLite3Accessor::~SQLite3Accessor() {
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_SQLITE_DROPCONN);
if (dbparameters_->db_ != NULL) {
close();
......@@ -249,7 +249,7 @@ SQLite3Database::~SQLite3Database() {
}
void
SQLite3Database::close(void) {
SQLite3Accessor::close(void) {
LOG_DEBUG(logger, DBG_TRACE_BASIC, DATASRC_SQLITE_CONNCLOSE);
if (dbparameters_->db_ == NULL) {
isc_throw(DataSourceError,
......@@ -267,12 +267,12 @@ SQLite3Database::close(void) {
}
std::pair<bool, int>
SQLite3Database::getZone(const isc::dns::Name& name) const {
SQLite3Accessor::getZone(const isc::dns::Name& name) const {
return (getZone(name.toText()));
}
std::pair<bool, int>
SQLite3Database::getZone(const string& name) const {
SQLite3Accessor::getZone(const string& name) const {
int rc;
sqlite3_stmt* const stmt = dbparameters_->statements_[ZONE];
......@@ -338,31 +338,31 @@ convertToPlainChar(const unsigned char* ucp,
}
}
class SQLite3Database::Context : public DatabaseAccessor::IteratorContext {
class SQLite3Accessor::Context : public DatabaseAccessor::IteratorContext {
public:
// Construct an iterator for all records. When constructed this
// way, the getNext() call will copy all fields
Context(const boost::shared_ptr<const SQLite3Database>& database, int id) :
Context(const boost::shared_ptr<const SQLite3Accessor>& accessor, int id) :
iterator_type_(ITT_ALL),
database_(database),
accessor_(accessor),
statement_(NULL)
{
// We create the statement now and then just keep getting data from it
statement_ = prepare(database->dbparameters_->db_,
statement_ = prepare(accessor->dbparameters_->db_,
text_statements[ITERATE]);
bindZoneId(id);
}
// Construct an iterator for records with a specific name. When constructed
// this way, the getNext() call will copy all fields except name
Context(const boost::shared_ptr<const SQLite3Database>& database, int id,
Context(const boost::shared_ptr<const SQLite3Accessor>& accessor, int id,
const isc::dns::Name& name) :
iterator_type_(ITT_NAME),
database_(database),
accessor_(accessor),
statement_(NULL)
{
// We create the statement now and then just keep getting data from it
statement_ = prepare(database->dbparameters_->db_,
statement_ = prepare(accessor->dbparameters_->db_,
text_statements[ANY]);
bindZoneId(id);
bindName(name);
......@@ -385,7 +385,7 @@ public:
} else if (rc != SQLITE_DONE) {
isc_throw(DataSourceError,
"Unexpected failure in sqlite3_step: " <<
sqlite3_errmsg(database_->dbparameters_->db_));
sqlite3_errmsg(accessor_->dbparameters_->db_));
}
return (false);
}
......@@ -406,21 +406,21 @@ private:
void copyColumn(std::string (&data)[COLUMN_COUNT], int column) {
data[column] = convertToPlainChar(sqlite3_column_text(statement_,
column),
database_->dbparameters_.get());
accessor_->dbparameters_.get());
}
void bindZoneId(const int zone_id) {
if (sqlite3_bind_int(statement_, 1, zone_id) != SQLITE_OK) {
isc_throw(SQLite3Error, "Could not bind int " << zone_id <<
" to SQL statement: " <<
sqlite3_errmsg(database_->dbparameters_->db_));
sqlite3_errmsg(accessor_->dbparameters_->db_));
}
}
void bindName(const isc::dns::Name& name) {
if (sqlite3_bind_text(statement_, 2, name.toText().c_str(), -1,
SQLITE_TRANSIENT) != SQLITE_OK) {
const char* errmsg = sqlite3_errmsg(database_->dbparameters_->db_);
const char* errmsg = sqlite3_errmsg(accessor_->dbparameters_->db_);
sqlite3_finalize(statement_);
isc_throw(SQLite3Error, "Could not bind text '" << name <<
"' to SQL statement: " << errmsg);
......@@ -428,22 +428,22 @@ private:
}
const IteratorType iterator_type_;
boost::shared_ptr<const SQLite3Database> database_;
boost::shared_ptr<const SQLite3Accessor> accessor_;
sqlite3_stmt *statement_;
};
DatabaseAccessor::IteratorContextPtr
SQLite3Database::getRecords(const isc::dns::Name& name, int id) const {
SQLite3Accessor::getRecords(const isc::dns::Name& name, int id) const {
return (IteratorContextPtr(new Context(shared_from_this(), id, name)));
}
DatabaseAccessor::IteratorContextPtr
SQLite3Database::getAllRecords(int id) const {
SQLite3Accessor::getAllRecords(int id) const {
return (IteratorContextPtr(new Context(shared_from_this(), id)));
}
pair<bool, int>
SQLite3Database::startUpdateZone(const string& zone_name, const bool replace) {
SQLite3Accessor::startUpdateZone(const string& zone_name, const bool replace) {
if (dbparameters_->updating_zone) {
isc_throw(DataSourceError,
"duplicate zone update on SQLite3 data source");
......@@ -479,7 +479,7 @@ SQLite3Database::startUpdateZone(const string& zone_name, const bool replace) {
}
void
SQLite3Database::commitUpdateZone() {
SQLite3Accessor::commitUpdateZone() {
if (!dbparameters_->updating_zone) {
isc_throw(DataSourceError, "committing zone update on SQLite3 "
"data source without transaction");
......@@ -492,7 +492,7 @@ SQLite3Database::commitUpdateZone() {
}
void
SQLite3Database::rollbackUpdateZone() {
SQLite3Accessor::rollbackUpdateZone() {
if (!dbparameters_->updating_zone) {
isc_throw(DataSourceError, "rolling back zone update on SQLite3 "
"data source without transaction");
......@@ -531,7 +531,7 @@ doUpdate(SQLite3Parameters& dbparams, StatementID stmt_id,
}
void
SQLite3Database::addRecordToZone(const vector<string>& columns) {
SQLite3Accessor::addRecordToZone(const vector<string>& columns) {
if (!dbparameters_->updating_zone) {
isc_throw(DataSourceError, "adding record to SQLite3 "
"data source without transaction");
......@@ -545,7 +545,7 @@ SQLite3Database::addRecordToZone(const vector<string>& columns) {
}
void
SQLite3Database::deleteRecordInZone(const vector<string>& params) {
SQLite3Accessor::deleteRecordInZone(const vector<string>& params) {
if (!dbparameters_->updating_zone) {
isc_throw(DataSourceError, "deleting record in SQLite3 "
"data source without transaction");
......
......@@ -53,8 +53,8 @@ struct SQLite3Parameters;
* According to the design, it doesn't interpret the data in any way, it just
* provides unified access to the DB.
*/
class SQLite3Database : public DatabaseAccessor,
public boost::enable_shared_from_this<SQLite3Database> {
class SQLite3Accessor : public DatabaseAccessor,
public boost::enable_shared_from_this<SQLite3Accessor> {
public:
/**
* \brief Constructor
......@@ -69,14 +69,14 @@ public:
* file can contain multiple classes of data, single database can
* provide only one class).
*/
SQLite3Database(const std::string& filename,
SQLite3Accessor(const std::string& filename,
const isc::dns::RRClass& rrclass);
/**
* \brief Destructor
*
* Closes the database.
*/
~SQLite3Database();
~SQLite3Accessor();
/**
* \brief Look up a zone
......
......@@ -445,12 +445,12 @@ public:
* times per test.
*/
void createClient() {
current_database_ = new MockAccessor();
current_accessor_ = new MockAccessor();
client_.reset(new DatabaseClient(shared_ptr<DatabaseAccessor>(
current_database_)));
current_accessor_)));
}
// Will be deleted by client_, just keep the current value for comparison.
MockAccessor* current_database_;
MockAccessor* current_accessor_;
shared_ptr<DatabaseClient> client_;
const std::string database_name_;
......@@ -465,7 +465,7 @@ public:
ASSERT_NE(shared_ptr<DatabaseClient::Finder>(), finder) <<
"Wrong type of finder";
EXPECT_EQ(42, finder->zone_id());
EXPECT_EQ(current_database_, &finder->database());
EXPECT_EQ(current_accessor_, &finder->getAccessor());
}
shared_ptr<DatabaseClient::Finder> getFinder() {
......@@ -795,7 +795,6 @@ TEST_F(DatabaseClientTest, find) {
ZoneFinder::CNAME,
expected_rdatas_, expected_sig_rdatas_);
expected_rdatas_.clear();
expected_sig_rdatas_.clear();
expected_rdatas_.push_back("192.0.2.1");
......@@ -846,7 +845,6 @@ TEST_F(DatabaseClientTest, find) {
ZoneFinder::SUCCESS,
expected_rdatas_, expected_sig_rdatas_);
EXPECT_THROW(finder->find(isc::dns::Name("badcname1.example.org."),
isc::dns::RRType::A(),
NULL, ZoneFinder::FIND_DEFAULT),
......@@ -889,7 +887,6 @@ TEST_F(DatabaseClientTest, find) {
isc::dns::RRType::A(),
NULL, ZoneFinder::FIND_DEFAULT),
std::exception);
EXPECT_THROW(finder->find(isc::dns::Name("dsexception.in.getnext."),
isc::dns::RRType::A(),
NULL, ZoneFinder::FIND_DEFAULT),
......
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