Invalidate info for one luid instead of all
[fanfix.git] / src / be / nikiroo / fanfix / library / RemoteLibrary.java
index 10cc44de423db239067e7318a667d7dd1e2df468..326a488b1766a8fc9ddf5052dae8c8fdb32b11cc 100644 (file)
@@ -233,8 +233,7 @@ public class RemoteLibrary extends BasicLibrary {
                }.connect();
 
                // because the meta changed:
-               clearCache();
-               refresh(pgRefresh);
+               invalidateInfo(luidSaved[0]);
 
                MetaData meta = getInfo(luidSaved[0]);
                meta.setCover(story.getMeta().getCover());
@@ -357,8 +356,6 @@ public class RemoteLibrary extends BasicLibrary {
 
                                                rep = send(null);
                                        }
-
-                                       getInfo(luid).setSource(newSource);
                                }
 
                                @Override
@@ -398,8 +395,57 @@ public class RemoteLibrary extends BasicLibrary {
                }
        }
 
+       @Override
+       public synchronized MetaData getInfo(String luid) {
+               List<MetaData> metas = getMetasList(luid, null);
+               if (!metas.isEmpty()) {
+                       return metas.get(0);
+               }
+
+               return null;
+       }
+
        @Override
        protected List<MetaData> getMetas(Progress pg) {
+               return getMetasList("*", pg);
+       }
+
+       @Override
+       protected void invalidateInfo(String luid) {
+       }
+
+       // The following methods are only used by Save and Delete in BasicLibrary:
+
+       @Override
+       protected int getNextId() {
+               throw new java.lang.InternalError("Should not have been called");
+       }
+
+       @Override
+       protected void doDelete(String luid) throws IOException {
+               throw new java.lang.InternalError("Should not have been called");
+       }
+
+       @Override
+       protected Story doSave(Story story, Progress pg) throws IOException {
+               throw new java.lang.InternalError("Should not have been called");
+       }
+
+       //
+
+       /**
+        * Return the meta of the given story or a list of all known metas if the
+        * luid is "*".
+        * 
+        * @param luid
+        *            the luid of the story or *
+        * @param pg
+        *            the optional progress
+        * 
+        * 
+        * @return the metas
+        */
+       private List<MetaData> getMetasList(final String luid, Progress pg) {
                final Progress pgF = pg;
                final List<MetaData> metas = new ArrayList<MetaData>();
 
@@ -412,7 +458,7 @@ public class RemoteLibrary extends BasicLibrary {
                                                pg = new Progress();
                                        }
 
-                                       Object rep = send(new Object[] { md5, "GET_METADATA", "*" });
+                                       Object rep = send(new Object[] { md5, "GET_METADATA", luid });
 
                                        while (true) {
                                                if (!RemoteLibraryServer.updateProgress(pg, rep)) {
@@ -422,8 +468,12 @@ public class RemoteLibrary extends BasicLibrary {
                                                rep = send(null);
                                        }
 
-                                       for (MetaData meta : (MetaData[]) rep) {
-                                               metas.add(meta);
+                                       if (rep instanceof MetaData[]) {
+                                               for (MetaData meta : (MetaData[]) rep) {
+                                                       metas.add(meta);
+                                               }
+                                       } else if (rep != null) {
+                                               metas.add((MetaData) rep);
                                        }
                                }
 
@@ -438,25 +488,4 @@ public class RemoteLibrary extends BasicLibrary {
 
                return metas;
        }
-
-       @Override
-       protected void clearCache() {
-       }
-
-       // The following methods are only used by Save and Delete in BasicLibrary:
-
-       @Override
-       protected int getNextId() {
-               throw new java.lang.InternalError("Should not have been called");
-       }
-
-       @Override
-       protected void doDelete(String luid) throws IOException {
-               throw new java.lang.InternalError("Should not have been called");
-       }
-
-       @Override
-       protected Story doSave(Story story, Progress pg) throws IOException {
-               throw new java.lang.InternalError("Should not have been called");
-       }
 }