implement global lock by locking hands table
This commit is contained in:
		
							parent
							
								
									be61b2d253
								
							
						
					
					
						commit
						5b96769de3
					
				|  | @ -174,7 +174,7 @@ class fpdb: | |||
| 
 | ||||
|     def dia_load_profile(self, widget, data=None): | ||||
|         """Dialogue to select a file to load a profile from""" | ||||
|         self.obtain_global_lock() | ||||
|         if self.obtain_global_lock(): | ||||
|             chooser = gtk.FileChooserDialog(title="Please select a profile file to load", | ||||
|                     action=gtk.FILE_CHOOSER_ACTION_OPEN, | ||||
|                     buttons=(gtk.STOCK_CANCEL,gtk.RESPONSE_CANCEL,gtk.STOCK_OPEN,gtk.RESPONSE_OK)) | ||||
|  | @ -190,7 +190,7 @@ class fpdb: | |||
| 
 | ||||
|     def dia_recreate_tables(self, widget, data=None): | ||||
|         """Dialogue that asks user to confirm that he wants to delete and recreate the tables""" | ||||
|         self.obtain_global_lock() | ||||
|         if self.obtain_global_lock(): | ||||
|          | ||||
|             dia_confirm = gtk.MessageDialog(parent=None, flags=0, type=gtk.MESSAGE_WARNING, | ||||
|                     buttons=(gtk.BUTTONS_YES_NO), message_format="Confirm deleting and recreating tables") | ||||
|  | @ -203,6 +203,7 @@ class fpdb: | |||
|                 self.db.recreate_tables() | ||||
|             elif response == gtk.RESPONSE_NO: | ||||
|                 print 'User cancelled recreating tables' | ||||
|             self.release_global_lock() | ||||
|     #end def dia_recreate_tables | ||||
| 
 | ||||
|     def dia_regression_test(self, widget, data=None): | ||||
|  | @ -371,7 +372,14 @@ class fpdb: | |||
|     #end def not_implemented | ||||
| 
 | ||||
|     def obtain_global_lock(self): | ||||
|         print "todo: implement obtain_global_lock (users: pls ignore this)" | ||||
|         print "\nTaking global lock ..." | ||||
|         self.fdb_lock = fpdb_db.fpdb_db() | ||||
|         self.fdb_lock.connect(self.settings['db-backend'], | ||||
|                               self.settings['db-host'], | ||||
|                               self.settings['db-databaseName'], | ||||
|                               self.settings['db-user'],  | ||||
|                               self.settings['db-password']) | ||||
|         return fpdb_simple.get_global_lock(self.fdb_lock) | ||||
|     #end def obtain_global_lock | ||||
| 
 | ||||
|     def quit(self, widget): | ||||
|  | @ -382,7 +390,9 @@ class fpdb: | |||
|     #end def quit_cliecked | ||||
| 
 | ||||
|     def release_global_lock(self): | ||||
|         print "todo: implement release_global_lock" | ||||
|         self.fdb_lock.db.rollback() | ||||
|         self.fdb_lock.disconnect() | ||||
|         print "Global lock released." | ||||
|     #end def release_global_lock | ||||
| 
 | ||||
|     def tab_abbreviations(self, widget, data=None): | ||||
|  |  | |||
|  | @ -367,6 +367,27 @@ def analyzeDB(fdb): | |||
|     fdb.db.commit() | ||||
| #end def analyzeDB | ||||
| 
 | ||||
| def get_global_lock(fdb): | ||||
|     if fdb.backend == MYSQL_INNODB: | ||||
|         try: | ||||
|             fdb.cursor.execute( "lock tables Hands write" ) | ||||
|         except: | ||||
|             print "Error! failed to obtain global lock. Close all programs accessing " \ | ||||
|                   + "database (including fpdb) and try again (%s)." \ | ||||
|                   % ( str(sys.exc_value).rstrip('\n'), ) | ||||
|             return(False) | ||||
|     elif fdb.backend == PGSQL: | ||||
|         try: | ||||
|             fdb.cursor.execute( "lock table Hands in exclusive mode nowait" ) | ||||
|             #print "... after lock table, status =", fdb.cursor.statusmessage | ||||
|         except: | ||||
|             print "Error! failed to obtain global lock. Close all programs accessing " \ | ||||
|                   + "database (including fpdb) and try again (%s)." \ | ||||
|                   % ( str(sys.exc_value).rstrip('\n'), ) | ||||
|             return(False) | ||||
|     return(True)  | ||||
| 
 | ||||
| 
 | ||||
| class DuplicateError(Exception): | ||||
|     def __init__(self, value): | ||||
|         self.value = value | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user