+ @Deprecated
+ protected void updateInfo(MetaData meta) throws IOException {
+ throw new IOException(
+ "This method is not supported in a CacheLibrary, please use updateMetaCache");
+ }
+
+ // relplace the meta in Metas by Meta, add it if needed
+ // return TRUE = added
+ private boolean updateMetaCache(List<MetaData> metas, MetaData meta) {
+ if (meta != null && metas != null) {
+ boolean changed = false;
+ for (int i = 0; i < metas.size(); i++) {
+ if (metas.get(i).getLuid().equals(meta.getLuid())) {
+ metas.set(i, meta);
+ changed = true;
+ }
+ }
+
+ if (!changed) {
+ metas.add(meta);
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ protected void invalidateInfo(String luid) {
+ if (luid == null) {
+ metasReal = null;
+ metasMixed = null;
+ } else {
+ invalidateInfo(metasReal, luid);
+ invalidateInfo(metasMixed, luid);
+ }
+
+ cacheLib.invalidateInfo(luid);
+ lib.invalidateInfo(luid);
+ }
+
+ // luid cannot be null
+ private void invalidateInfo(List<MetaData> metas, String luid) {
+ if (metas != null) {
+ for (int i = 0; i < metas.size(); i++) {
+ if (metas.get(i).getLuid().equals(luid)) {
+ metas.remove(i--);
+ }
+ }
+ }
+ }
+
+ @Override
+ public synchronized Story save(Story story, String luid, Progress pg) throws IOException {
+ Progress pgLib = new Progress();
+ Progress pgCacheLib = new Progress();
+
+ if (pg == null) {
+ pg = new Progress();
+ }
+
+ pg.setMinMax(0, 2);
+ pg.addProgress(pgLib, 1);
+ pg.addProgress(pgCacheLib, 1);
+
+ story = lib.save(story, luid, pgLib);
+ updateMetaCache(metasReal, story.getMeta());
+
+ story = cacheLib.save(story, story.getMeta().getLuid(), pgCacheLib);
+ updateMetaCache(metasMixed, story.getMeta());
+