* src/GrampsDb/_GrampsBSDDB.py: Use txn-capable metadata.
svn: r7154
This commit is contained in:
parent
b4a6202a31
commit
58cc43816c
@ -1,4 +1,5 @@
|
|||||||
2006-08-11 Alex Roitman <shura@gramps-project.org>
|
2006-08-11 Alex Roitman <shura@gramps-project.org>
|
||||||
|
* src/GrampsDb/_GrampsBSDDB.py: Use txn-capable metadata.
|
||||||
* src/Editors/_EditFamily.py: Use cPickle.
|
* src/Editors/_EditFamily.py: Use cPickle.
|
||||||
|
|
||||||
2006-08-10 Don Allingham <don@gramps-project.org>
|
2006-08-10 Don Allingham <don@gramps-project.org>
|
||||||
|
@ -271,14 +271,39 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
def get_reference_map_referenced_cursor(self):
|
def get_reference_map_referenced_cursor(self):
|
||||||
return GrampsBSDDBDupCursor(self.reference_map_referenced_map,self.txn)
|
return GrampsBSDDBDupCursor(self.reference_map_referenced_map,self.txn)
|
||||||
|
|
||||||
|
# These are overriding the GrampsDbBase's methods of saving metadata
|
||||||
|
# because we now have txn-capable metadata table
|
||||||
|
def set_default_person_handle(self, handle):
|
||||||
|
"""sets the default Person to the passed instance"""
|
||||||
|
if not self.readonly:
|
||||||
|
the_txn = self.env.txn_begin()
|
||||||
|
self.metadata.put('default',str(handle),txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
|
def get_default_person(self):
|
||||||
|
"""returns the default Person of the database"""
|
||||||
|
person = self.get_person_from_handle(self.get_default_handle())
|
||||||
|
if person:
|
||||||
|
return person
|
||||||
|
elif (self.metadata) and (not self.readonly):
|
||||||
|
the_txn = self.env.txn_begin()
|
||||||
|
self.metadata.put('default',None,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _set_column_order(self, col_list, name):
|
||||||
|
if self.metadata and not self.readonly:
|
||||||
|
the_txn = self.env.txn_begin()
|
||||||
|
self.metadata.put(name,col_list,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
def version_supported(self):
|
def version_supported(self):
|
||||||
return (self.metadata.get('version',0) <= _DBVERSION and
|
dbversion = self.metadata.get('version',default=0)
|
||||||
self.metadata.get('version',0) >= _MINVERSION)
|
return ((dbversion <= _DBVERSION) and (dbversion >= _MINVERSION))
|
||||||
|
|
||||||
def need_upgrade(self):
|
def need_upgrade(self):
|
||||||
return not self.readonly \
|
dbversion = self.metadata.get('version',default=0)
|
||||||
and self.metadata.get('version',0) < _DBVERSION
|
return not self.readonly and dbversion < _DBVERSION
|
||||||
|
|
||||||
def load(self,name,callback,mode="w"):
|
def load(self,name,callback,mode="w"):
|
||||||
if self.db_is_open:
|
if self.db_is_open:
|
||||||
@ -319,7 +344,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
self.env.txn_checkpoint()
|
self.env.txn_checkpoint()
|
||||||
|
|
||||||
callback(25)
|
callback(25)
|
||||||
self.metadata = self.open_table(self.full_name,"meta",no_txn=True)
|
self.metadata = self.open_table(self.full_name,"meta")
|
||||||
|
|
||||||
# If we cannot work with this DB version,
|
# If we cannot work with this DB version,
|
||||||
# it makes no sense to go further
|
# it makes no sense to go further
|
||||||
@ -339,14 +364,16 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
|
|
||||||
self._load_metadata()
|
self._load_metadata()
|
||||||
|
|
||||||
gstats = self.metadata.get('gender_stats')
|
gstats = self.metadata.get('gender_stats',default=[])
|
||||||
|
|
||||||
if not self.readonly:
|
if not self.readonly:
|
||||||
|
the_txn = self.env.txn_begin()
|
||||||
if gstats == None:
|
if gstats == None:
|
||||||
self.metadata['version'] = _DBVERSION
|
self.metadata.put('version',_DBVERSION,txn=the_txn)
|
||||||
elif not self.metadata.has_key('version'):
|
elif not self.metadata.has_key('version'):
|
||||||
self.metadata['version'] = 0
|
self.metadata.put('version',0,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
self.genderStats = GenderStats(gstats)
|
self.genderStats = GenderStats(gstats)
|
||||||
|
|
||||||
# Here we take care of any changes in the tables related to new code.
|
# Here we take care of any changes in the tables related to new code.
|
||||||
@ -383,7 +410,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
|
|
||||||
def _load_metadata(self):
|
def _load_metadata(self):
|
||||||
# name display formats
|
# name display formats
|
||||||
self.name_formats = self.metadata.get('name_formats',[])
|
self.name_formats = self.metadata.get('name_formats',default=[])
|
||||||
# upgrade formats if they were saved in the old way
|
# upgrade formats if they were saved in the old way
|
||||||
for format_ix in range(len(self.name_formats)):
|
for format_ix in range(len(self.name_formats)):
|
||||||
format = self.name_formats[format_ix]
|
format = self.name_formats[format_ix]
|
||||||
@ -391,27 +418,43 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
format = format + (True,)
|
format = format + (True,)
|
||||||
self.name_formats[format_ix] = format
|
self.name_formats[format_ix] = format
|
||||||
# bookmarks
|
# bookmarks
|
||||||
self.bookmarks = self.metadata.get('bookmarks',[])
|
self.bookmarks = self.metadata.get('bookmarks',default=[])
|
||||||
self.family_bookmarks = self.metadata.get('family_bookmarks',[])
|
self.family_bookmarks = self.metadata.get('family_bookmarks',
|
||||||
self.event_bookmarks = self.metadata.get('event_bookmarks',[])
|
default=[])
|
||||||
self.source_bookmarks = self.metadata.get('source_bookmarks',[])
|
self.event_bookmarks = self.metadata.get('event_bookmarks',
|
||||||
self.repo_bookmarks = self.metadata.get('repo_bookmarks',[])
|
default=[])
|
||||||
self.media_bookmarks = self.metadata.get('media_bookmarks',[])
|
self.source_bookmarks = self.metadata.get('source_bookmarks',
|
||||||
self.place_bookmarks = self.metadata.get('place_bookmarks',[])
|
default=[])
|
||||||
|
self.repo_bookmarks = self.metadata.get('repo_bookmarks',
|
||||||
|
default=[])
|
||||||
|
self.media_bookmarks = self.metadata.get('media_bookmarks',
|
||||||
|
default=[])
|
||||||
|
self.place_bookmarks = self.metadata.get('place_bookmarks',
|
||||||
|
default=[])
|
||||||
# Custom type values
|
# Custom type values
|
||||||
self.family_event_names = set(self.metadata.get('fevent_names',[]))
|
self.family_event_names = set(self.metadata.get('fevent_names',
|
||||||
self.individual_event_names = set(self.metadata.get('pevent_names',[]))
|
default=[]))
|
||||||
self.family_attributes = set(self.metadata.get('fattr_names',[]))
|
self.individual_event_names = set(self.metadata.get('pevent_names',
|
||||||
self.individual_attributes = set(self.metadata.get('pattr_names',[]))
|
default=[]))
|
||||||
self.marker_names = set(self.metadata.get('marker_names',[]))
|
self.family_attributes = set(self.metadata.get('fattr_names',
|
||||||
self.child_ref_types = set(self.metadata.get('child_refs',[]))
|
default=[]))
|
||||||
self.family_rel_types = set(self.metadata.get('family_rels',[]))
|
self.individual_attributes = set(self.metadata.get('pattr_names',
|
||||||
self.event_role_names = set(self.metadata.get('event_roles',[]))
|
default=[]))
|
||||||
self.name_types = set(self.metadata.get('name_types',[]))
|
self.marker_names = set(self.metadata.get('marker_names',default=[]))
|
||||||
self.repository_types = set(self.metadata.get('repo_types',[]))
|
self.child_ref_types = set(self.metadata.get('child_refs',
|
||||||
self.source_media_types = set(self.metadata.get('sm_types',[]))
|
default=[]))
|
||||||
self.url_types = set(self.metadata.get('url_types',[]))
|
self.family_rel_types = set(self.metadata.get('family_rels',
|
||||||
self.media_attributes = set(self.metadata.get('mattr_names',[]))
|
default=[]))
|
||||||
|
self.event_role_names = set(self.metadata.get('event_roles',
|
||||||
|
default=[]))
|
||||||
|
self.name_types = set(self.metadata.get('name_types',default=[]))
|
||||||
|
self.repository_types = set(self.metadata.get('repo_types',
|
||||||
|
default=[]))
|
||||||
|
self.source_media_types = set(self.metadata.get('sm_types',
|
||||||
|
default=[]))
|
||||||
|
self.url_types = set(self.metadata.get('url_types',default=[]))
|
||||||
|
self.media_attributes = set(self.metadata.get('mattr_names',
|
||||||
|
default=[]))
|
||||||
|
|
||||||
def connect_secondary(self):
|
def connect_secondary(self):
|
||||||
"""
|
"""
|
||||||
@ -826,32 +869,54 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
|
|
||||||
def _close_metadata(self):
|
def _close_metadata(self):
|
||||||
if not self.readonly:
|
if not self.readonly:
|
||||||
|
the_txn = self.env.txn_begin()
|
||||||
|
|
||||||
# name display formats
|
# name display formats
|
||||||
self.metadata['name_formats'] = self.name_formats
|
self.metadata.put('name_formats',self.name_formats,txn=the_txn)
|
||||||
# bookmarks
|
# bookmarks
|
||||||
self.metadata['bookmarks'] = self.bookmarks
|
self.metadata.put('bookmarks',self.bookmarks,txn=the_txn)
|
||||||
self.metadata['family_bookmarks'] = self.family_bookmarks
|
self.metadata.put('family_bookmarks',self.family_bookmarks,
|
||||||
self.metadata['event_bookmarks'] = self.event_bookmarks
|
txn=the_txn)
|
||||||
self.metadata['source_bookmarks'] = self.source_bookmarks
|
self.metadata.put('event_bookmarks',self.event_bookmarks,
|
||||||
self.metadata['place_bookmarks'] = self.place_bookmarks
|
txn=the_txn)
|
||||||
self.metadata['repo_bookmarks'] = self.repo_bookmarks
|
self.metadata.put('source_bookmarks',self.source_bookmarks,
|
||||||
self.metadata['media_bookmarks'] = self.media_bookmarks
|
txn=the_txn)
|
||||||
|
self.metadata.put('place_bookmarks',self.place_bookmarks,
|
||||||
|
txn=the_txn)
|
||||||
|
self.metadata.put('repo_bookmarks',self.repo_bookmarks,txn=the_txn)
|
||||||
|
self.metadata.put('media_bookmarks',self.media_bookmarks,
|
||||||
|
txn=the_txn)
|
||||||
# gender stats
|
# gender stats
|
||||||
self.metadata['gender_stats'] = self.genderStats.save_stats()
|
self.metadata.put('gender_stats',self.genderStats.save_stats(),
|
||||||
|
txn=the_txn)
|
||||||
# Custom type values
|
# Custom type values
|
||||||
self.metadata['fevent_names'] = list(self.family_event_names)
|
self.metadata.put('fevent_names',list(self.family_event_names),
|
||||||
self.metadata['pevent_names'] = list(self.individual_event_names)
|
txn=the_txn)
|
||||||
self.metadata['fattr_names'] = list(self.family_attributes)
|
self.metadata.put('pevent_names',list(self.individual_event_names),
|
||||||
self.metadata['pattr_names'] = list(self.individual_attributes)
|
txn=the_txn)
|
||||||
self.metadata['marker_names'] = list(self.marker_names)
|
self.metadata.put('fattr_names',list(self.family_attributes),
|
||||||
self.metadata['child_refs'] = list(self.child_ref_types)
|
txn=the_txn)
|
||||||
self.metadata['family_rels'] = list(self.family_rel_types)
|
self.metadata.put('pattr_names',list(self.individual_attributes),
|
||||||
self.metadata['event_roles'] = list(self.event_role_names)
|
txn=the_txn)
|
||||||
self.metadata['name_types'] = list(self.name_types)
|
self.metadata.put('marker_names',list(self.marker_names),
|
||||||
self.metadata['repo_types'] = list(self.repository_types)
|
txn=the_txn)
|
||||||
self.metadata['sm_types'] = list(self.source_media_types)
|
self.metadata.put('child_refs',list(self.child_ref_types),
|
||||||
self.metadata['url_types'] = list(self.url_types)
|
txn=the_txn)
|
||||||
self.metadata['mattr_names'] = list(self.media_attributes)
|
self.metadata.put('family_rels',list(self.family_rel_types),
|
||||||
|
txn=the_txn)
|
||||||
|
self.metadata.put('event_roles',list(self.event_role_names),
|
||||||
|
txn=the_txn)
|
||||||
|
self.metadata.put('name_types',list(self.name_types),
|
||||||
|
txn=the_txn)
|
||||||
|
self.metadata.put('repo_types',list(self.repository_types),
|
||||||
|
txn=the_txn)
|
||||||
|
self.metadata.put('sm_types',list(self.source_media_types),
|
||||||
|
txn=the_txn)
|
||||||
|
self.metadata.put('url_types',list(self.url_types),
|
||||||
|
txn=the_txn)
|
||||||
|
self.metadata.put('mattr_names',list(self.media_attributes),
|
||||||
|
txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
self.metadata.close()
|
self.metadata.close()
|
||||||
|
|
||||||
@ -1290,7 +1355,7 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
"None", "Birth", "Adopted", "Stepchild",
|
"None", "Birth", "Adopted", "Stepchild",
|
||||||
"Sponsored", "Foster", "Unknown", "Other", ]
|
"Sponsored", "Foster", "Unknown", "Other", ]
|
||||||
|
|
||||||
version = self.metadata.get('version',_MINVERSION)
|
version = self.metadata.get('version',default=_MINVERSION)
|
||||||
t = time.time()
|
t = time.time()
|
||||||
if version < 6:
|
if version < 6:
|
||||||
self.gramps_upgrade_6()
|
self.gramps_upgrade_6()
|
||||||
@ -1300,8 +1365,6 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
self.gramps_upgrade_8()
|
self.gramps_upgrade_8()
|
||||||
if version < 9:
|
if version < 9:
|
||||||
self.gramps_upgrade_9()
|
self.gramps_upgrade_9()
|
||||||
# self.metadata.put('version',_DBVERSION)
|
|
||||||
# self.metadata.sync()
|
|
||||||
print "Upgrade time:", int(time.time()-t), "seconds"
|
print "Upgrade time:", int(time.time()-t), "seconds"
|
||||||
|
|
||||||
def gramps_upgrade_6(self):
|
def gramps_upgrade_6(self):
|
||||||
@ -1311,8 +1374,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
if val[1] != 6:
|
if val[1] != 6:
|
||||||
order.append(val)
|
order.append(val)
|
||||||
self.set_media_column_order(order)
|
self.set_media_column_order(order)
|
||||||
self.metadata.put('version',6)
|
the_txn = self.env.txn_begin()
|
||||||
self.metadata.sync()
|
self.metadata.put('version',6,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
def gramps_upgrade_7(self):
|
def gramps_upgrade_7(self):
|
||||||
print "Upgrading to DB version 7"
|
print "Upgrading to DB version 7"
|
||||||
@ -1326,8 +1390,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
self.genderStats.count_person(p)
|
self.genderStats.count_person(p)
|
||||||
data = cursor.next()
|
data = cursor.next()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
self.metadata.put('version',7)
|
the_txn = self.env.txn_begin()
|
||||||
self.metadata.sync()
|
self.metadata.put('version',7,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
def gramps_upgrade_8(self):
|
def gramps_upgrade_8(self):
|
||||||
print "Upgrading to DB version 8"
|
print "Upgrading to DB version 8"
|
||||||
@ -1356,8 +1421,9 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
self.family_event_names.add(event.name)
|
self.family_event_names.add(event.name)
|
||||||
data = cursor.next()
|
data = cursor.next()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
self.metadata.put('version',7)
|
the_txn = self.env.txn_begin()
|
||||||
self.metadata.sync()
|
self.metadata.put('version',8,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
def gramps_upgrade_9(self):
|
def gramps_upgrade_9(self):
|
||||||
print "Upgrading to DB version 9 -- this may take a while"
|
print "Upgrading to DB version 9 -- this may take a while"
|
||||||
@ -1373,9 +1439,11 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
for name in (PERSON_COL_KEY,CHILD_COL_KEY,PLACE_COL_KEY,SOURCE_COL_KEY,
|
for name in (PERSON_COL_KEY,CHILD_COL_KEY,PLACE_COL_KEY,SOURCE_COL_KEY,
|
||||||
MEDIA_COL_KEY,EVENT_COL_KEY,FAMILY_COL_KEY):
|
MEDIA_COL_KEY,EVENT_COL_KEY,FAMILY_COL_KEY):
|
||||||
try:
|
try:
|
||||||
self.metadata.delete(name)
|
the_txn = self.env.txn_begin()
|
||||||
|
self.metadata.delete(name,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
the_txn.abort()
|
||||||
|
|
||||||
# Then we remove the surname secondary index table
|
# Then we remove the surname secondary index table
|
||||||
# because its format changed from HASH to DUPSORTed BTREE.
|
# because its format changed from HASH to DUPSORTed BTREE.
|
||||||
@ -1397,11 +1465,13 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
### Now we're ready to proceed with the normal upgrade.
|
### Now we're ready to proceed with the normal upgrade.
|
||||||
# First, make sure the stored default person handle is str, not unicode
|
# First, make sure the stored default person handle is str, not unicode
|
||||||
try:
|
try:
|
||||||
handle = self.metadata['default']
|
the_txn = self.env.txn_begin()
|
||||||
self.metadata['default'] = str(handle)
|
handle = self.metadata.get('default',txn=the_txn)
|
||||||
|
self.metadata.put('default',str(handle),txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# default person was not stored in database
|
# default person was not stored in database
|
||||||
pass
|
the_txn.abort()
|
||||||
|
|
||||||
# The rest of the upgrade deals with real data, not metadata
|
# The rest of the upgrade deals with real data, not metadata
|
||||||
# so starting (batch) transaction here.
|
# so starting (batch) transaction here.
|
||||||
@ -1706,8 +1776,12 @@ class GrampsBSDDB(GrampsDbBase,UpdateCallback):
|
|||||||
self.transaction_commit(trans,"Upgrade to DB version 9")
|
self.transaction_commit(trans,"Upgrade to DB version 9")
|
||||||
# Close secodnary index
|
# Close secodnary index
|
||||||
self.reference_map_primary_map.close()
|
self.reference_map_primary_map.close()
|
||||||
self.metadata.put('version',9)
|
|
||||||
self.metadata.sync()
|
# Separate transaction to save metadata
|
||||||
|
the_txn = self.env.txn_begin()
|
||||||
|
self.metadata.put('version',9,txn=the_txn)
|
||||||
|
the_txn.commit()
|
||||||
|
|
||||||
print "Done upgrading to DB version 9"
|
print "Done upgrading to DB version 9"
|
||||||
|
|
||||||
class BdbTransaction(Transaction):
|
class BdbTransaction(Transaction):
|
||||||
|
Loading…
Reference in New Issue
Block a user