[longomatch] Force the deletion of the project from the DB when updating it



commit a85b00eadcda9938e8e528786ff13ce6f9e3ef43
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Tue Oct 20 10:44:47 2009 +0200

    Force the deletion of the project from the DB when updating it
      When updating a project if we use the update method binding
      the current Project object to the one in the DB with the
      same filename, the update is successfull but all the childs
      of the stored project remains in the DB. Instead if we delete
      the project stored in the DB and we replace it with the updated
      one all the childs are deleted, and therefore the DB does not
      expand on each update

 LongoMatch/DB/DataBase.cs |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)
---
diff --git a/LongoMatch/DB/DataBase.cs b/LongoMatch/DB/DataBase.cs
index 209f710..42562a6 100644
--- a/LongoMatch/DB/DataBase.cs
+++ b/LongoMatch/DB/DataBase.cs
@@ -173,7 +173,7 @@ namespace LongoMatch.DB
 			lock(this.locker){
 				bool error = false;				
 				// Configure db4o to cascade on delete for each one of the objects stored in a Project
-				SetUpdateCascadeOptions();
+				SetDeleteCascadeOptions();
 				IObjectContainer db = Db4oFactory.OpenFile(file);
 				try	{
 					// We look for a project with the same filename
@@ -182,10 +182,9 @@ namespace LongoMatch.DB
 						query.Constrain(typeof(Project));
 						query.Descend("file").Descend("filePath").Constrain(previousFileName);
 						IObjectSet result = query.Execute();  
-						//Get the stored object ID and bind it to "offline" modified
+						//Get the stored project and replace it with the new one
 						Project fd = (Project)result.Next();
-						long id = db.Ext().GetID(fd);
-						db.Ext().Bind(project,id);
+						db.Delete(fd);						
 						// Add the updated project
 						db.Set(project);	
 						db.Commit();
@@ -203,16 +202,16 @@ namespace LongoMatch.DB
 		
 		public void UpdateProject(Project project){
 			lock(this.locker){
-				SetUpdateCascadeOptions();				
+				SetDeleteCascadeOptions();				
 				IObjectContainer db = Db4oFactory.OpenFile(file);
 				try	{				
 					IQuery query = db.Query();
 					query.Constrain(typeof(Project));
 					query.Descend("file").Descend("filePath").Constrain(project.File.FilePath);
 					IObjectSet result = query.Execute();  
+					//Get the stored project and replace it with the new one
 					Project fd = (Project)result.Next();
-					long id = db.Ext().GetID(fd);
-					db.Ext().Bind(project,id);
+					db.Delete(fd);	
 					db.Set(project);		
 					db.Commit();
 				}				



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]