[vlma-devel] commit: Ensure data coherency. (Adrien Grand )

git version control git at videolan.org
Sun Sep 14 17:01:19 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Sep 14 14:49:19 2008 +0200| [e6422508af889c5ec9975d85e32fc2e230263340] | committer: Adrien Grand 

Ensure data coherency.

When removing a server, remove associated files channels and when removing a
satellite, remove associated adapters.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=e6422508af889c5ec9975d85e32fc2e230263340
---

 .../java/org/videolan/vlma/dao/VLMaDaoImpl.java    |   23 ++++++++++++++++++++
 .../web/satellite/SatelliteRemoveController.java   |    4 ---
 2 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java b/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java
index ec70b69..08b031b 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java
@@ -27,6 +27,7 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Random;
@@ -202,6 +203,19 @@ public class VLMaDaoImpl implements VLMaDao {
         synchronized (satellites) {
             if (satellites.containsKey(id)) {
                 satellites.remove(id);
+                synchronized (servers) {
+                    for(Server server : servers.values()) {
+                        Iterator<Adapter> adapterIt = server.getAdapters().iterator();
+                        while(adapterIt.hasNext()) {
+                            Adapter adapter = adapterIt.next();
+                            if (adapter instanceof DVBSAdapter) {
+                                if(((DVBSAdapter)adapter).getSatellite().getId() == id) {
+                                    adapterIt.remove();
+                                }
+                            }
+                        }
+                    }
+                }
                 saveToDisk();
             } else {
                 throw new NotFoundException("Satellite " + satellite.getName() + " is not in the database.");
@@ -214,6 +228,15 @@ public class VLMaDaoImpl implements VLMaDao {
         synchronized (servers) {
             if (servers.containsKey(id)) {
                 servers.remove(id);
+                synchronized (medias) {
+                    for(Media media : medias.values()) {
+                        if(media instanceof FilesChannel) {
+                            if(((FilesChannel)media).getServer().getId() == id) {
+                                medias.remove(media.getId());
+                            }
+                        }
+                    }
+                }
                 saveToDisk();
             } else {
                 throw new NotFoundException("Server " + server.getName() + " is not in the database.");
diff --git a/vlma-webapp/src/main/java/org/videolan/vlma/web/satellite/SatelliteRemoveController.java b/vlma-webapp/src/main/java/org/videolan/vlma/web/satellite/SatelliteRemoveController.java
index 6fd34c5..9ec8933 100644
--- a/vlma-webapp/src/main/java/org/videolan/vlma/web/satellite/SatelliteRemoveController.java
+++ b/vlma-webapp/src/main/java/org/videolan/vlma/web/satellite/SatelliteRemoveController.java
@@ -56,10 +56,6 @@ public class SatelliteRemoveController extends SimpleFormController {
     protected Object formBackingObject(HttpServletRequest request) throws Exception {
         SatelliteAdd satellitesAdd = new SatelliteAdd();
         int id = Integer.parseInt(request.getParameter("satellite"));
-        Satellite satellite = data.getSatellite(id);
-        if (satellite != null) {
-            satellitesAdd.setName(satellite.getName());
-        }
         satellitesAdd.setId(id);
         return satellitesAdd;
     }



More information about the vlma-devel mailing list