Added db.get_transaction_class to connect db and txn; refactored _tables metadata

This commit is contained in:
Doug Blank 2013-11-10 15:07:14 -05:00
parent 94dbcc5ac7
commit b0517d0ee4
4 changed files with 204 additions and 65 deletions

View File

@ -61,6 +61,18 @@ class DbReadBase(object):
""" """
self.basedb = self self.basedb = self
self.__feature = {} # {"feature": VALUE, ...} self.__feature = {} # {"feature": VALUE, ...}
self._tables = {
"Citation": {},
"Event": {},
"Family": {},
"Media": {},
"Note": {},
"Person": {},
"Place": {},
"Repository": {},
"Source": {},
"Tag": {},
}
def get_feature(self, feature): def get_feature(self, feature):
""" """

View File

@ -107,92 +107,109 @@ class DictionaryDb(DbWriteBase, DbReadBase):
""" """
A Gramps Database Backend. This replicates the grampsdb functions. A Gramps Database Backend. This replicates the grampsdb functions.
""" """
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
DbReadBase.__init__(self) DbReadBase.__init__(self)
DbWriteBase.__init__(self) DbWriteBase.__init__(self)
self._tables = { self._tables['Person'].update(
'Person': {
{
"handle_func": self.get_person_from_handle, "handle_func": self.get_person_from_handle,
"gramps_id_func": self.get_person_from_gramps_id, "gramps_id_func": self.get_person_from_gramps_id,
"class_func": Person, "class_func": Person,
"cursor_func": self.get_person_cursor, "cursor_func": self.get_person_cursor,
"handles_func": self.get_person_handles, "handles_func": self.get_person_handles,
}, "add_func": self.add_person,
'Family': "commit_func": self.commit_person,
{ })
self._tables['Family'].update(
{
"handle_func": self.get_family_from_handle, "handle_func": self.get_family_from_handle,
"gramps_id_func": self.get_family_from_gramps_id, "gramps_id_func": self.get_family_from_gramps_id,
"class_func": Family, "class_func": Family,
"cursor_func": self.get_family_cursor, "cursor_func": self.get_family_cursor,
"handles_func": self.get_family_handles, "handles_func": self.get_family_handles,
}, "add_func": self.add_family,
'Source': "commit_func": self.commit_family,
{ })
self._tables['Source'].update(
{
"handle_func": self.get_source_from_handle, "handle_func": self.get_source_from_handle,
"gramps_id_func": self.get_source_from_gramps_id, "gramps_id_func": self.get_source_from_gramps_id,
"class_func": Source, "class_func": Source,
"cursor_func": self.get_source_cursor, "cursor_func": self.get_source_cursor,
"handles_func": self.get_source_handles, "handles_func": self.get_source_handles,
}, "add_func": self.add_source,
'Citation': "commit_func": self.commit_source,
{ })
self._tables['Citation'].update(
{
"handle_func": self.get_citation_from_handle, "handle_func": self.get_citation_from_handle,
"gramps_id_func": self.get_citation_from_gramps_id, "gramps_id_func": self.get_citation_from_gramps_id,
"class_func": Citation, "class_func": Citation,
"cursor_func": self.get_citation_cursor, "cursor_func": self.get_citation_cursor,
"handles_func": self.get_citation_handles, "handles_func": self.get_citation_handles,
}, "add_func": self.add_citation,
'Event': "commit_func": self.commit_citation,
{ })
self._tables['Event'].update(
{
"handle_func": self.get_event_from_handle, "handle_func": self.get_event_from_handle,
"gramps_id_func": self.get_event_from_gramps_id, "gramps_id_func": self.get_event_from_gramps_id,
"class_func": Event, "class_func": Event,
"cursor_func": self.get_event_cursor, "cursor_func": self.get_event_cursor,
"handles_func": self.get_event_handles, "handles_func": self.get_event_handles,
}, "add_func": self.add_event,
'Media': "commit_func": self.commit_event,
{ })
self._tables['Media'].update(
{
"handle_func": self.get_object_from_handle, "handle_func": self.get_object_from_handle,
"gramps_id_func": self.get_object_from_gramps_id, "gramps_id_func": self.get_object_from_gramps_id,
"class_func": MediaObject, "class_func": MediaObject,
"cursor_func": self.get_media_cursor, "cursor_func": self.get_media_cursor,
"handles_func": self.get_media_object_handles, "handles_func": self.get_media_object_handles,
}, "add_func": self.add_object,
'Place': "commit_func": self.commit_media_object,
{ })
self._tables['Place'].update(
{
"handle_func": self.get_place_from_handle, "handle_func": self.get_place_from_handle,
"gramps_id_func": self.get_place_from_gramps_id, "gramps_id_func": self.get_place_from_gramps_id,
"class_func": Place, "class_func": Place,
"cursor_func": self.get_place_cursor, "cursor_func": self.get_place_cursor,
"handles_func": self.get_place_handles, "handles_func": self.get_place_handles,
}, "add_func": self.add_place,
'Repository': "commit_func": self.commit_place,
{ })
self._tables['Repository'].update(
{
"handle_func": self.get_repository_from_handle, "handle_func": self.get_repository_from_handle,
"gramps_id_func": self.get_repository_from_gramps_id, "gramps_id_func": self.get_repository_from_gramps_id,
"class_func": Repository, "class_func": Repository,
"cursor_func": self.get_repository_cursor, "cursor_func": self.get_repository_cursor,
"handles_func": self.get_repository_handles, "handles_func": self.get_repository_handles,
}, "add_func": self.add_repository,
'Note': "commit_func": self.commit_repository,
{ })
self._tables['Note'].update(
{
"handle_func": self.get_note_from_handle, "handle_func": self.get_note_from_handle,
"gramps_id_func": self.get_note_from_gramps_id, "gramps_id_func": self.get_note_from_gramps_id,
"class_func": Note, "class_func": Note,
"cursor_func": self.get_note_cursor, "cursor_func": self.get_note_cursor,
"handles_func": self.get_note_handles, "handles_func": self.get_note_handles,
}, "add_func": self.add_note,
'Tag': "commit_func": self.commit_note,
{ })
self._tables['Tag'].update(
{
"handle_func": self.get_tag_from_handle, "handle_func": self.get_tag_from_handle,
"gramps_id_func": None, "gramps_id_func": None,
"class_func": Tag, "class_func": Tag,
"cursor_func": self.get_tag_cursor, "cursor_func": self.get_tag_cursor,
"handles_func": self.get_tag_handles, "handles_func": self.get_tag_handles,
}, "add_func": self.add_tag,
} "commit_func": self.commit_tag,
})
# skip GEDCOM cross-ref check for now: # skip GEDCOM cross-ref check for now:
self.set_feature("skip-check-xref", True) self.set_feature("skip-check-xref", True)
self.set_feature("skip-import-additions", True) self.set_feature("skip-import-additions", True)
@ -968,3 +985,9 @@ class DictionaryDb(DbWriteBase, DbReadBase):
for (handle, data) in cursor(): for (handle, data) in cursor():
map = getattr(self, "%s_map" % key.lower()) map = getattr(self, "%s_map" % key.lower())
map[handle] = class_.create(data) map[handle] = class_.create(data)
def get_transaction_class(self):
"""
Get the transaction class associated with this database backend.
"""
return DictionaryTxn

View File

@ -293,88 +293,86 @@ class DbBsddbRead(DbReadBase, Callback):
""" """
DbReadBase.__init__(self) DbReadBase.__init__(self)
Callback.__init__(self) Callback.__init__(self)
self._tables = { self._tables['Person'].update(
'Person': {
{
"handle_func": self.get_person_from_handle, "handle_func": self.get_person_from_handle,
"gramps_id_func": self.get_person_from_gramps_id, "gramps_id_func": self.get_person_from_gramps_id,
"class_func": Person, "class_func": Person,
"cursor_func": self.get_person_cursor, "cursor_func": self.get_person_cursor,
"handles_func": self.get_person_handles, "handles_func": self.get_person_handles,
}, })
'Family': self._tables['Family'].update(
{ {
"handle_func": self.get_family_from_handle, "handle_func": self.get_family_from_handle,
"gramps_id_func": self.get_family_from_gramps_id, "gramps_id_func": self.get_family_from_gramps_id,
"class_func": Family, "class_func": Family,
"cursor_func": self.get_family_cursor, "cursor_func": self.get_family_cursor,
"handles_func": self.get_family_handles, "handles_func": self.get_family_handles,
}, })
'Source': self._tables['Source'].update(
{ {
"handle_func": self.get_source_from_handle, "handle_func": self.get_source_from_handle,
"gramps_id_func": self.get_source_from_gramps_id, "gramps_id_func": self.get_source_from_gramps_id,
"class_func": Source, "class_func": Source,
"cursor_func": self.get_source_cursor, "cursor_func": self.get_source_cursor,
"handles_func": self.get_source_handles, "handles_func": self.get_source_handles,
}, })
'Citation': self._tables['Citation'].update(
{ {
"handle_func": self.get_citation_from_handle, "handle_func": self.get_citation_from_handle,
"gramps_id_func": self.get_citation_from_gramps_id, "gramps_id_func": self.get_citation_from_gramps_id,
"class_func": Citation, "class_func": Citation,
"cursor_func": self.get_citation_cursor, "cursor_func": self.get_citation_cursor,
"handles_func": self.get_citation_handles, "handles_func": self.get_citation_handles,
}, })
'Event': self._tables['Event'].update(
{ {
"handle_func": self.get_event_from_handle, "handle_func": self.get_event_from_handle,
"gramps_id_func": self.get_event_from_gramps_id, "gramps_id_func": self.get_event_from_gramps_id,
"class_func": Event, "class_func": Event,
"cursor_func": self.get_event_cursor, "cursor_func": self.get_event_cursor,
"handles_func": self.get_event_handles, "handles_func": self.get_event_handles,
}, })
'Media': self._tables['Media'].update(
{ {
"handle_func": self.get_object_from_handle, "handle_func": self.get_object_from_handle,
"gramps_id_func": self.get_object_from_gramps_id, "gramps_id_func": self.get_object_from_gramps_id,
"class_func": MediaObject, "class_func": MediaObject,
"cursor_func": self.get_media_cursor, "cursor_func": self.get_media_cursor,
"handles_func": self.get_media_object_handles, "handles_func": self.get_media_object_handles,
}, })
'Place': self._tables['Place'].update(
{ {
"handle_func": self.get_place_from_handle, "handle_func": self.get_place_from_handle,
"gramps_id_func": self.get_place_from_gramps_id, "gramps_id_func": self.get_place_from_gramps_id,
"class_func": Place, "class_func": Place,
"cursor_func": self.get_place_cursor, "cursor_func": self.get_place_cursor,
"handles_func": self.get_place_handles, "handles_func": self.get_place_handles,
}, })
'Repository': self._tables['Repository'].update(
{ {
"handle_func": self.get_repository_from_handle, "handle_func": self.get_repository_from_handle,
"gramps_id_func": self.get_repository_from_gramps_id, "gramps_id_func": self.get_repository_from_gramps_id,
"class_func": Repository, "class_func": Repository,
"cursor_func": self.get_repository_cursor, "cursor_func": self.get_repository_cursor,
"handles_func": self.get_repository_handles, "handles_func": self.get_repository_handles,
}, })
'Note': self._tables['Note'].update(
{ {
"handle_func": self.get_note_from_handle, "handle_func": self.get_note_from_handle,
"gramps_id_func": self.get_note_from_gramps_id, "gramps_id_func": self.get_note_from_gramps_id,
"class_func": Note, "class_func": Note,
"cursor_func": self.get_note_cursor, "cursor_func": self.get_note_cursor,
"handles_func": self.get_note_handles, "handles_func": self.get_note_handles,
}, })
'Tag': self._tables['Tag'].update(
{ {
"handle_func": self.get_tag_from_handle, "handle_func": self.get_tag_from_handle,
"gramps_id_func": None, "gramps_id_func": None,
"class_func": Tag, "class_func": Tag,
"cursor_func": self.get_tag_cursor, "cursor_func": self.get_tag_cursor,
"handles_func": self.get_tag_handles, "handles_func": self.get_tag_handles,
}, })
}
self.set_person_id_prefix('I%04d') self.set_person_id_prefix('I%04d')
self.set_object_id_prefix('O%04d') self.set_object_id_prefix('O%04d')

View File

@ -285,6 +285,107 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
DbBsddbRead.__init__(self) DbBsddbRead.__init__(self)
DbWriteBase.__init__(self) DbWriteBase.__init__(self)
#UpdateCallback.__init__(self) #UpdateCallback.__init__(self)
self._tables['Person'].update(
{
"handle_func": self.get_person_from_handle,
"gramps_id_func": self.get_person_from_gramps_id,
"class_func": Person,
"cursor_func": self.get_person_cursor,
"handles_func": self.get_person_handles,
"add_func": self.add_person,
"commit_func": self.commit_person,
})
self._tables['Family'].update(
{
"handle_func": self.get_family_from_handle,
"gramps_id_func": self.get_family_from_gramps_id,
"class_func": Family,
"cursor_func": self.get_family_cursor,
"handles_func": self.get_family_handles,
"add_func": self.add_family,
"commit_func": self.commit_family,
})
self._tables['Source'].update(
{
"handle_func": self.get_source_from_handle,
"gramps_id_func": self.get_source_from_gramps_id,
"class_func": Source,
"cursor_func": self.get_source_cursor,
"handles_func": self.get_source_handles,
"add_func": self.add_source,
"commit_func": self.commit_source,
})
self._tables['Citation'].update(
{
"handle_func": self.get_citation_from_handle,
"gramps_id_func": self.get_citation_from_gramps_id,
"class_func": Citation,
"cursor_func": self.get_citation_cursor,
"handles_func": self.get_citation_handles,
"add_func": self.add_citation,
"commit_func": self.commit_citation,
})
self._tables['Event'].update(
{
"handle_func": self.get_event_from_handle,
"gramps_id_func": self.get_event_from_gramps_id,
"class_func": Event,
"cursor_func": self.get_event_cursor,
"handles_func": self.get_event_handles,
"add_func": self.add_event,
"commit_func": self.commit_event,
})
self._tables['Media'].update(
{
"handle_func": self.get_object_from_handle,
"gramps_id_func": self.get_object_from_gramps_id,
"class_func": MediaObject,
"cursor_func": self.get_media_cursor,
"handles_func": self.get_media_object_handles,
"add_func": self.add_object,
"commit_func": self.commit_media_object,
})
self._tables['Place'].update(
{
"handle_func": self.get_place_from_handle,
"gramps_id_func": self.get_place_from_gramps_id,
"class_func": Place,
"cursor_func": self.get_place_cursor,
"handles_func": self.get_place_handles,
"add_func": self.add_place,
"commit_func": self.commit_place,
})
self._tables['Repository'].update(
{
"handle_func": self.get_repository_from_handle,
"gramps_id_func": self.get_repository_from_gramps_id,
"class_func": Repository,
"cursor_func": self.get_repository_cursor,
"handles_func": self.get_repository_handles,
"add_func": self.add_repository,
"commit_func": self.commit_repository,
})
self._tables['Note'].update(
{
"handle_func": self.get_note_from_handle,
"gramps_id_func": self.get_note_from_gramps_id,
"class_func": Note,
"cursor_func": self.get_note_cursor,
"handles_func": self.get_note_handles,
"add_func": self.add_note,
"commit_func": self.commit_note,
})
self._tables['Tag'].update(
{
"handle_func": self.get_tag_from_handle,
"gramps_id_func": None,
"class_func": Tag,
"cursor_func": self.get_tag_cursor,
"handles_func": self.get_tag_handles,
"add_func": self.add_tag,
"commit_func": self.commit_tag,
})
self.secondary_connected = False self.secondary_connected = False
self.has_changed = False self.has_changed = False
self.brief_name = None self.brief_name = None
@ -2312,6 +2413,11 @@ class DbBsddb(DbBsddbRead, DbWriteBase, UpdateCallback):
""" """
return self.brief_name return self.brief_name
def get_transaction_class(self):
"""
Get the transaction class associated with this database backend.
"""
return DbTxn
def _mkname(path, name): def _mkname(path, name):
return os.path.join(path, name + DBEXT) return os.path.join(path, name + DBEXT)