From 535ce58f170e56a98611bb57f32b070845e959b7 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Sat, 25 Jun 2016 21:55:55 +0100 Subject: [PATCH] 9547: Rename more non-API database methods --- gramps/gen/db/base.py | 30 ----------------- .../database/bsddb_support/test/db_test.py | 4 --- .../bsddb_support/test/reference_map_test.py | 6 ++-- .../plugins/database/bsddb_support/write.py | 33 ++++++++++--------- gramps/plugins/database/dummydb.py | 16 --------- 5 files changed, 20 insertions(+), 69 deletions(-) diff --git a/gramps/gen/db/base.py b/gramps/gen/db/base.py index cca152769..2c69d5912 100644 --- a/gramps/gen/db/base.py +++ b/gramps/gen/db/base.py @@ -688,18 +688,6 @@ class DbReadBase: """ raise NotImplementedError - def get_reference_map_primary_cursor(self): - """ - Returns a reference to a cursor over the reference map primary map - """ - raise NotImplementedError - - def get_reference_map_referenced_cursor(self): - """ - Returns a reference to a cursor over the reference map referenced map - """ - raise NotImplementedError - def get_repo_bookmarks(self): """ Return the list of Repository handles in the bookmarks. @@ -1588,15 +1576,6 @@ class DbWriteBase(DbReadBase): """ raise NotImplementedError - def delete_primary_from_reference_map(self, handle, transaction): - """ - Called each time an object is removed from the database. - - This can be used by subclasses to update any additional index tables - that might need to be changed. - """ - raise NotImplementedError - def get_undodb(self): """ Return the database that keeps track of Undo/Redo operations. @@ -1758,15 +1737,6 @@ class DbWriteBase(DbReadBase): """ raise NotImplementedError - def update_reference_map(self, obj, transaction): - """ - Called each time an object is writen to the database. - - This can be used by subclasses to update any additional index tables - that might need to be changed. - """ - raise NotImplementedError - def write_version(self, name): """ Write version number for a newly created DB. diff --git a/gramps/plugins/database/bsddb_support/test/db_test.py b/gramps/plugins/database/bsddb_support/test/db_test.py index 33a49a1fd..ddd3262a7 100644 --- a/gramps/plugins/database/bsddb_support/test/db_test.py +++ b/gramps/plugins/database/bsddb_support/test/db_test.py @@ -102,8 +102,6 @@ class DbTest(unittest.TestCase): "get_raw_repository_data", "get_raw_source_data", "get_raw_tag_data", - "get_reference_map_primary_cursor", - "get_reference_map_referenced_cursor", "get_repo_bookmarks", "get_repository_cursor", "get_repository_from_gramps_id", @@ -196,7 +194,6 @@ class DbTest(unittest.TestCase): "commit_repository", "commit_source", "commit_tag", - "delete_primary_from_reference_map", "need_schema_upgrade", "rebuild_secondary", "reindex_reference_map", @@ -214,7 +211,6 @@ class DbTest(unittest.TestCase): "set_name_group_mapping", "transaction_begin", "transaction_commit", - "update_reference_map", "write_version", ] diff --git a/gramps/plugins/database/bsddb_support/test/reference_map_test.py b/gramps/plugins/database/bsddb_support/test/reference_map_test.py index b869fe189..e009a987e 100644 --- a/gramps/plugins/database/bsddb_support/test/reference_map_test.py +++ b/gramps/plugins/database/bsddb_support/test/reference_map_test.py @@ -126,8 +126,8 @@ class ReferenceMapTest(GrampsDbBaseTest): # unhook the reference_map update function so that we # can insert some records without the reference_map being updated. - update_method = self._db.update_reference_map - self._db.update_reference_map = lambda x,y,z: 1 + update_method = self._db._update_reference_map + self._db._update_reference_map = lambda x,y,z: 1 # Insert a person/source pair. citation = self._add_source() @@ -140,7 +140,7 @@ class ReferenceMapTest(GrampsDbBaseTest): "len(references) == %s " % str(len(references))) # Reinstate the reference_map method and reindex the database - self._db.update_reference_map = update_method + self._db._update_reference_map = update_method self._db.reindex_reference_map(cb) # Check that the reference now appears in the reference_map diff --git a/gramps/plugins/database/bsddb_support/write.py b/gramps/plugins/database/bsddb_support/write.py index 1cfd5311b..3fd84b959 100644 --- a/gramps/plugins/database/bsddb_support/write.py +++ b/gramps/plugins/database/bsddb_support/write.py @@ -483,7 +483,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): # the main index is unique, the others allow duplicate entries. @catch_db_error - def get_reference_map_primary_cursor(self): + def _get_reference_map_primary_cursor(self): """ Returns a reference to a cursor over the reference map primary map """ @@ -491,7 +491,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): self.txn) @catch_db_error - def get_reference_map_referenced_cursor(self): + def _get_reference_map_referenced_cursor(self): """ Returns a reference to a cursor over the reference map referenced map """ @@ -1188,7 +1188,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): handle = handle.encode('utf-8') # Use the secondary index to locate all the reference_map entries # that include a reference to the object we are looking for. - referenced_cur = self.get_reference_map_referenced_cursor() + referenced_cur = self._get_reference_map_referenced_cursor() try: ret = referenced_cur.set(handle) @@ -1224,12 +1224,12 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): referenced_cur.close() - def delete_primary_from_reference_map(self, handle, transaction, txn=None): + def _delete_primary_from_reference_map(self, handle, transaction, txn=None): """ Remove all references to the primary object from the reference_map. handle should be utf-8 """ - primary_cur = self.get_reference_map_primary_cursor() + primary_cur = self._get_reference_map_primary_cursor() try: ret = primary_cur.set(handle) @@ -1260,7 +1260,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): for main_key in remove_list: self.__remove_reference(main_key, transaction, txn) - def update_reference_map(self, obj, transaction, txn=None): + def _update_reference_map(self, obj, transaction, txn=None): """ If txn is given, then changes are written right away using txn. """ @@ -1269,7 +1269,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): # from the primary object 'obj' or any of its secondary objects. handle = obj.handle existing_references = set() - primary_cur = self.get_reference_map_primary_cursor() + primary_cur = self._get_reference_map_primary_cursor() try: if isinstance(handle, str): key = handle.encode('utf-8') @@ -1424,7 +1424,8 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): obj = class_func() obj.unserialize(val) with BSDDBTxn(self.env) as txn: - self.update_reference_map(obj, transaction, txn.txn) + self._update_reference_map(obj, + transaction, txn.txn) callback(5) @@ -1711,12 +1712,12 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): handle = handle.encode('utf-8') if transaction.batch: with BSDDBTxn(self.env, data_map) as txn: - self.delete_primary_from_reference_map(handle, transaction, + self._delete_primary_from_reference_map(handle, transaction, txn=txn.txn) txn.delete(handle) else: - self.delete_primary_from_reference_map(handle, transaction, - txn=self.txn) + self._delete_primary_from_reference_map(handle, transaction, + txn=self.txn) old_data = data_map.get(handle, txn=self.txn) data_map.delete(handle, txn=self.txn) transaction.add(key, TXNDEL, handle, old_data, None) @@ -1736,12 +1737,12 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): handle = handle.encode('utf-8') if transaction.batch: with BSDDBTxn(self.env, self.person_map) as txn: - self.delete_primary_from_reference_map(handle, transaction, - txn=txn.txn) + self._delete_primary_from_reference_map(handle, transaction, + txn=txn.txn) txn.delete(handle) else: - self.delete_primary_from_reference_map(handle, transaction, - txn=self.txn) + self._delete_primary_from_reference_map(handle, transaction, + txn=self.txn) self.person_map.delete(handle, txn=self.txn) transaction.add(PERSON_KEY, TXNDEL, handle, person.serialize(), None) @@ -1906,7 +1907,7 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback): if isinstance(handle, str): handle = handle.encode('utf-8') - self.update_reference_map(obj, transaction, self.txn) + self._update_reference_map(obj, transaction, self.txn) new_data = obj.serialize() old_data = None diff --git a/gramps/plugins/database/dummydb.py b/gramps/plugins/database/dummydb.py index 393a987f3..fd656b3cb 100644 --- a/gramps/plugins/database/dummydb.py +++ b/gramps/plugins/database/dummydb.py @@ -991,22 +991,6 @@ class DummyDb(M_A_M_B("NewBaseClass", (DbReadBase, Callback, object,), {})): LOG.warn("handle %s does not exist in the dummy database" % handle) raise HandleError('Handle %s not found' % handle.decode('utf-8')) - def get_reference_map_primary_cursor(self): - """ - Returns a reference to a cursor over the reference map primary map - """ - if not self.db_is_open: - LOG.warn("database is closed") - return [] - - def get_reference_map_referenced_cursor(self): - """ - Returns a reference to a cursor over the reference map referenced map - """ - if not self.db_is_open: - LOG.warn("database is closed") - return [] - def get_repo_bookmarks(self): """ Return the list of Repository handles in the bookmarks.