Now using batch transactions

This commit is contained in:
Doug Blank 2015-05-23 10:07:57 -04:00
parent d69f8a6d3c
commit 8be61709b8

View File

@ -495,16 +495,14 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
return None return None
def transaction_commit(self, txn): def transaction_commit(self, txn):
## FIXME self.dbapi.commit()
pass
def get_undodb(self): def get_undodb(self):
## FIXME ## FIXME
return None return None
def transaction_abort(self, txn): def transaction_abort(self, txn):
## FIXME self.dbapi.rollback()
pass
@staticmethod @staticmethod
def _validated_id_prefix(val, default): def _validated_id_prefix(val, default):
@ -1248,25 +1246,25 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_person(self, person, trans, change_time=None): def commit_person(self, person, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if person.handle in self.person_map:
if person.handle in self.person_map: emit = "person-update"
emit = "person-update" self.dbapi.execute("""UPDATE person SET gramps_id = ?,
self.dbapi.execute("""UPDATE person SET gramps_id = ?, order_by = ?,
order_by = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [person.gramps_id,
[person.gramps_id, self._order_by_person_key(person),
self._order_by_person_key(person), pickle.dumps(person.serialize()),
pickle.dumps(person.serialize()), person.handle])
person.handle]) else:
else: emit = "person-add"
emit = "person-add" self.dbapi.execute("""insert into person(handle, order_by, gramps_id, blob)
self.dbapi.execute("""insert into person(handle, order_by, gramps_id, blob) values(?, ?, ?, ?);""",
values(?, ?, ?, ?);""", [person.handle,
[person.handle, self._order_by_person_key(person),
self._order_by_person_key(person), person.gramps_id,
person.gramps_id, pickle.dumps(person.serialize())])
pickle.dumps(person.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1274,20 +1272,20 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_family(self, family, trans, change_time=None): def commit_family(self, family, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if family.handle in self.family_map:
if family.handle in self.family_map: emit = "family-update"
emit = "family-update" self.dbapi.execute("""UPDATE family SET gramps_id = ?,
self.dbapi.execute("""UPDATE family SET gramps_id = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [family.gramps_id,
[family.gramps_id, pickle.dumps(family.serialize()),
pickle.dumps(family.serialize()), family.handle])
family.handle]) else:
else: emit = "family-add"
emit = "family-add" self.dbapi.execute("insert into family values(?, ?, ?);",
self.dbapi.execute("insert into family values(?, ?, ?);", [family.handle, family.gramps_id,
[family.handle, family.gramps_id, pickle.dumps(family.serialize())])
pickle.dumps(family.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1295,24 +1293,24 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_citation(self, citation, trans, change_time=None): def commit_citation(self, citation, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if citation.handle in self.citation_map:
if citation.handle in self.citation_map: emit = "citation-update"
emit = "citation-update" self.dbapi.execute("""UPDATE citation SET gramps_id = ?,
self.dbapi.execute("""UPDATE citation SET gramps_id = ?, order_by = ?,
order_by = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [citation.gramps_id,
[citation.gramps_id, self._order_by_citation_key(citation),
self._order_by_citation_key(citation), pickle.dumps(citation.serialize()),
pickle.dumps(citation.serialize()), citation.handle])
citation.handle]) else:
else: emit = "citation-add"
emit = "citation-add" self.dbapi.execute("insert into citation values(?, ?, ?, ?);",
self.dbapi.execute("insert into citation values(?, ?, ?, ?);", [citation.handle,
[citation.handle, self._order_by_citation_key(citation),
self._order_by_citation_key(citation), citation.gramps_id,
citation.gramps_id, pickle.dumps(citation.serialize())])
pickle.dumps(citation.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1320,24 +1318,24 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_source(self, source, trans, change_time=None): def commit_source(self, source, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if source.handle in self.source_map:
if source.handle in self.source_map: emit = "source-update"
emit = "source-update" self.dbapi.execute("""UPDATE source SET gramps_id = ?,
self.dbapi.execute("""UPDATE source SET gramps_id = ?, order_by = ?,
order_by = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [source.gramps_id,
[source.gramps_id, self._order_by_source_key(source),
self._order_by_source_key(source), pickle.dumps(source.serialize()),
pickle.dumps(source.serialize()), source.handle])
source.handle]) else:
else: emit = "source-add"
emit = "source-add" self.dbapi.execute("insert into source values(?, ?, ?, ?);",
self.dbapi.execute("insert into source values(?, ?, ?, ?);", [source.handle,
[source.handle, self._order_by_source_key(source),
self._order_by_source_key(source), source.gramps_id,
source.gramps_id, pickle.dumps(source.serialize())])
pickle.dumps(source.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1345,19 +1343,19 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_repository(self, repository, trans, change_time=None): def commit_repository(self, repository, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if repository.handle in self.repository_map:
if repository.handle in self.repository_map: emit = "repository-update"
emit = "repository-update" self.dbapi.execute("""UPDATE repository SET gramps_id = ?,
self.dbapi.execute("""UPDATE repository SET gramps_id = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [repository.gramps_id,
[repository.gramps_id, pickle.dumps(repository.serialize()),
pickle.dumps(repository.serialize()), repository.handle])
repository.handle]) else:
else: emit = "repository-add"
emit = "repository-add" self.dbapi.execute("insert into repository values(?, ?, ?);",
self.dbapi.execute("insert into repository values(?, ?, ?);", [repository.handle, repository.gramps_id, pickle.dumps(repository.serialize())])
[repository.handle, repository.gramps_id, pickle.dumps(repository.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1365,19 +1363,19 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_note(self, note, trans, change_time=None): def commit_note(self, note, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if note.handle in self.note_map:
if note.handle in self.note_map: emit = "note-update"
emit = "note-update" self.dbapi.execute("""UPDATE note SET gramps_id = ?,
self.dbapi.execute("""UPDATE note SET gramps_id = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [note.gramps_id,
[note.gramps_id, pickle.dumps(note.serialize()),
pickle.dumps(note.serialize()), note.handle])
note.handle]) else:
else: emit = "note-add"
emit = "note-add" self.dbapi.execute("insert into note values(?, ?, ?);",
self.dbapi.execute("insert into note values(?, ?, ?);", [note.handle, note.gramps_id, pickle.dumps(note.serialize())])
[note.handle, note.gramps_id, pickle.dumps(note.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1385,24 +1383,24 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_place(self, place, trans, change_time=None): def commit_place(self, place, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if place.handle in self.place_map:
if place.handle in self.place_map: emit = "place-update"
emit = "place-update" self.dbapi.execute("""UPDATE place SET gramps_id = ?,
self.dbapi.execute("""UPDATE place SET gramps_id = ?, order_by = ?,
order_by = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [place.gramps_id,
[place.gramps_id, self._order_by_place_key(place),
self._order_by_place_key(place), pickle.dumps(place.serialize()),
pickle.dumps(place.serialize()), place.handle])
place.handle]) else:
else: emit = "place-add"
emit = "place-add" self.dbapi.execute("insert into place values(?, ?, ?, ?);",
self.dbapi.execute("insert into place values(?, ?, ?, ?);", [place.handle,
[place.handle, self._order_by_place_key(place),
self._order_by_place_key(place), place.gramps_id,
place.gramps_id, pickle.dumps(place.serialize())])
pickle.dumps(place.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1410,21 +1408,21 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_event(self, event, trans, change_time=None): def commit_event(self, event, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if event.handle in self.event_map:
if event.handle in self.event_map: emit = "event-update"
emit = "event-update" self.dbapi.execute("""UPDATE event SET gramps_id = ?,
self.dbapi.execute("""UPDATE event SET gramps_id = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [event.gramps_id,
[event.gramps_id, pickle.dumps(event.serialize()),
pickle.dumps(event.serialize()), event.handle])
event.handle]) else:
else: emit = "event-add"
emit = "event-add" self.dbapi.execute("insert into event values(?, ?, ?);",
self.dbapi.execute("insert into event values(?, ?, ?);", [event.handle,
[event.handle, event.gramps_id,
event.gramps_id, pickle.dumps(event.serialize())])
pickle.dumps(event.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1432,21 +1430,21 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_tag(self, tag, trans, change_time=None): def commit_tag(self, tag, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if tag.handle in self.tag_map:
if tag.handle in self.tag_map: emit = "tag-update"
emit = "tag-update" self.dbapi.execute("""UPDATE tag SET blob = ?,
self.dbapi.execute("""UPDATE tag SET blob = ?, order_by = ?
order_by = ? WHERE handle = ?;""",
WHERE handle = ?;""", [pickle.dumps(tag.serialize()),
[pickle.dumps(tag.serialize()), self._order_by_tag_key(tag),
self._order_by_tag_key(tag), tag.handle])
tag.handle]) else:
else: emit = "tag-add"
emit = "tag-add" self.dbapi.execute("insert into tag values(?, ?, ?);",
self.dbapi.execute("insert into tag values(?, ?, ?);", [tag.handle,
[tag.handle, self._order_by_tag_key(tag),
self._order_by_tag_key(tag), pickle.dumps(tag.serialize())])
pickle.dumps(tag.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit:
@ -1454,24 +1452,24 @@ class DBAPI(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def commit_media_object(self, media, trans, change_time=None): def commit_media_object(self, media, trans, change_time=None):
emit = None emit = None
if True or not trans.batch: if media.handle in self.media_map:
if media.handle in self.media_map: emit = "media-update"
emit = "media-update" self.dbapi.execute("""UPDATE media SET gramps_id = ?,
self.dbapi.execute("""UPDATE media SET gramps_id = ?, order_by = ?,
order_by = ?, blob = ?
blob = ? WHERE handle = ?;""",
WHERE handle = ?;""", [media.gramps_id,
[media.gramps_id, self._order_by_media_key(media),
self._order_by_media_key(media), pickle.dumps(media.serialize()),
pickle.dumps(media.serialize()), media.handle])
media.handle]) else:
else: emit = "media-add"
emit = "media-add" self.dbapi.execute("insert into media values(?, ?, ?, ?);",
self.dbapi.execute("insert into media values(?, ?, ?, ?);", [media.handle,
[media.handle, self._order_by_media_key(media),
self._order_by_media_key(media), media.gramps_id,
media.gramps_id, pickle.dumps(media.serialize())])
pickle.dumps(media.serialize())]) if not trans.batch:
self.dbapi.commit() self.dbapi.commit()
# Emit after added: # Emit after added:
if emit: if emit: