r1244 - in trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing: . actions/history model model/tab
Author: tchemit Date: 2008-02-26 00:57:11 +0000 (Tue, 26 Feb 2008) New Revision: 1244 Added: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/LoggableElementCache.java Removed: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementCache.java Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryDeleteAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryUnconnectAction.java trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/tab/ListTabModel.java Log: mise en place cache sur les loggableElement recuperes (todo a finir (capacite, interaction avec l'historique...) Copied: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/LoggableElementCache.java (from rev 1243, trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementCache.java) =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/LoggableElementCache.java (rev 0) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/LoggableElementCache.java 2008-02-26 00:57:11 UTC (rev 1244) @@ -0,0 +1,133 @@ +/* +* \#\#% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit, Gabriel Landais +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +* \#\#% */ +package fr.cemagref.simexplorer.is.ui.swing; + +import fr.cemagref.simexplorer.is.entities.data.LoggableElement; +import fr.cemagref.simexplorer.is.entities.metadata.Version; +import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; +import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; +import fr.cemagref.simexplorer.is.service.StorageService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * Un cache de LoggableElement. + * + * @author chemit + */ +public class LoggableElementCache { + + protected static Log log = LogFactory.getLog(LoggableElementCache.class); + //private static final int CAPACITY = 200; + + protected Map<String, List<LoggableElement>> cache; + + protected StorageService service; + + protected SimExplorerContext context; + + public LoggableElementCache(SimExplorerContext context, StorageService service) { + if (service == null) { + throw new NullPointerException("could not have a null service"); + } + if (context == null) { + throw new NullPointerException("could not have a null context"); + } + this.service = service; + this.context = context; + } + + public LoggableElement get(String uuid, Version version) { + + List<LoggableElement> list = null; + LoggableElement result = null; + + if (containsKey(uuid)) { + list = getCache().get(uuid); + for (LoggableElement entity : list) { + if (entity.getMetaData().getVersion().equals(version)) { + result = entity; + break; + } + } + } + if (result == null) { + // try to find it from service + try { + result = service.getLoggableElement(context.getToken(), uuid, version.toString()); + if (result != null) { + // save in cache + if (list == null) { + list = new ArrayList<LoggableElement>(); + } + list.add(result); + getCache().put(uuid, list); + log.info(this + " add " + uuid + " version " + version); + //TODO deal with capacity + } + } catch (SimExplorerException e) { + //TODO + throw new SimExplorerRuntimeException(e); + } + } + return result; + } + + @Override + public String toString() { + return super.toString() + " capacity (" + size() + ")"; + } + + public void remove(String uuid) { + if (containsKey(uuid)) { + getCache().get(uuid).clear(); + getCache().remove(uuid); + log.info(this + " remove " + uuid); + } + } + + public boolean isEmpty() { + return cache == null || cache.isEmpty(); + } + + public int size() { + return isEmpty() ? 0 : cache.size(); + } + + public boolean containsKey(String o) { + return cache != null && cache.containsKey(o); + } + + public void clear() { + if (cache != null) { + cache.clear(); + } + } + + protected Map<String, List<LoggableElement>> getCache() { + if (cache == null) { + cache = new TreeMap<String, List<LoggableElement>>(); + } + return cache; + } +} Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java 2008-02-26 00:35:04 UTC (rev 1243) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/SimExplorerContext.java 2008-02-26 00:57:11 UTC (rev 1244) @@ -31,7 +31,7 @@ import fr.cemagref.simexplorer.is.ui.swing.commandline.configs.SimExplorerAbstractConfigLocal; import fr.cemagref.simexplorer.is.ui.swing.commandline.configs.SimExplorerAbstractConfigMain; import fr.cemagref.simexplorer.is.ui.swing.commandline.configs.SimExplorerAbstractConfigRemote; -import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementCache; +import fr.cemagref.simexplorer.is.ui.swing.LoggableElementCache; import fr.cemagref.simexplorer.is.entities.metadata.Version; import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.entities.data.LoggableElement; @@ -194,7 +194,7 @@ } public LoggableElement getLoggableElement(boolean remote, String uuid, Version version) { - LoggableElementCache cache = getCache(remote); + LoggableElementCache cache = getLoggableElementCache(remote); LoggableElement result; result = cache.get(uuid, version); return result; @@ -263,7 +263,7 @@ } return service; } - public LoggableElementCache getCache(boolean remote) { + public LoggableElementCache getLoggableElementCache(boolean remote) { getStorageService(remote); LoggableElementCache cache; cache = remote?remoteCache:localCache; Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java 2008-02-26 00:35:04 UTC (rev 1243) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/StorageServiceHelper.java 2008-02-26 00:57:11 UTC (rev 1244) @@ -29,7 +29,7 @@ import fr.cemagref.simexplorer.is.exceptions.UnreachableServiceException; import fr.cemagref.simexplorer.is.service.StorageService; import fr.cemagref.simexplorer.is.storage.SortColumn; -import fr.cemagref.simexplorer.is.ui.swing.model.LoggableElementCache; +import fr.cemagref.simexplorer.is.ui.swing.LoggableElementCache; import java.io.BufferedInputStream; import java.io.File; Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryDeleteAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryDeleteAction.java 2008-02-26 00:35:04 UTC (rev 1243) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryDeleteAction.java 2008-02-26 00:57:11 UTC (rev 1244) @@ -85,6 +85,9 @@ } pos++; } + if (wasRemove) { + getContext().getLoggableElementCache(remote).remove(uuid); + } if (datas.isEmpty()) { // supprime la selection model.setCurrentIndex(null); Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryUnconnectAction.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryUnconnectAction.java 2008-02-26 00:35:04 UTC (rev 1243) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/actions/history/HistoryUnconnectAction.java 2008-02-26 00:57:11 UTC (rev 1244) @@ -54,6 +54,9 @@ it.remove(); } } + + // clear remote cache + getContext().getLoggableElementCache(true).clear(); if (datas.isEmpty()) { // pas de position model.setCurrentIndex(null); Deleted: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementCache.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementCache.java 2008-02-26 00:35:04 UTC (rev 1243) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/LoggableElementCache.java 2008-02-26 00:57:11 UTC (rev 1244) @@ -1,116 +0,0 @@ -/* -* \#\#% Copyright (C) 2007, 2008 Code Lutin, Tony Chemit, Gabriel Landais -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version 2 -* of the License, or (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* \#\#% */ -package fr.cemagref.simexplorer.is.ui.swing.model; - -import fr.cemagref.simexplorer.is.entities.data.LoggableElement; -import fr.cemagref.simexplorer.is.entities.metadata.Version; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerException; -import fr.cemagref.simexplorer.is.exceptions.SimExplorerRuntimeException; -import fr.cemagref.simexplorer.is.service.StorageService; -import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * Un cache de LoggableElement. - * - * @author chemit - */ -public class LoggableElementCache { - - //private static final int CAPACITY = 200; - - protected Map<String, List<LoggableElement>> cache; - - protected StorageService service; - - protected SimExplorerContext context; - - public LoggableElementCache(SimExplorerContext context, StorageService service) { - if (service==null) { - throw new NullPointerException("could not have a null service"); - } - if (context==null) { - throw new NullPointerException("could not have a null context"); - } - this.service = service; - this.context = context; - } - - public LoggableElement get(String uuid, Version version) { - - List<LoggableElement> list = null; - LoggableElement result = null; - - if (containsKey(uuid)) { - list = getCache().get(uuid); - for (LoggableElement entity : list) { - if (entity.getMetaData().getVersion().equals(version)) { - result = entity; - break; - } - } - } - if (result == null) { - // try to find it from service - try { - result = service.getLoggableElement(context.getToken(), uuid, version.toString()); - if (result != null) { - // save in cache - if (list == null) { - list = new ArrayList<LoggableElement>(); - } - list.add(result); - getCache().put(uuid, list); - } - } catch (SimExplorerException e) { - //TODO - throw new SimExplorerRuntimeException(e); - } - } - return result; - } - - public boolean isEmpty() { - return cache == null || cache.isEmpty(); - } - - public int size() { - return isEmpty() ? 0 : cache.size(); - } - - public boolean containsKey(String o) { - return cache != null && cache.containsKey(o); - } - - public void clear() { - if (cache != null) { - cache.clear(); - } - } - - protected Map<String, List<LoggableElement>> getCache() { - if (cache == null) { - cache = new TreeMap<String, List<LoggableElement>>(); - } - return cache; - } -} Modified: trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/tab/ListTabModel.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/tab/ListTabModel.java 2008-02-26 00:35:04 UTC (rev 1243) +++ trunk/simexplorer-is/simexplorer-is-swing/src/java/fr/cemagref/simexplorer/is/ui/swing/model/tab/ListTabModel.java 2008-02-26 00:57:11 UTC (rev 1244) @@ -21,7 +21,6 @@ import fr.cemagref.simexplorer.is.entities.metadata.MetaData; import fr.cemagref.simexplorer.is.storage.SortColumn; import fr.cemagref.simexplorer.is.ui.swing.SimExplorerContext; -import fr.cemagref.simexplorer.is.ui.swing.StorageServiceHelper; import jaxx.util.SimplePaginationEnum; import java.io.Serializable; @@ -74,7 +73,7 @@ reset(); // no selection at first load synch(remote, null, null); - // setdefault sizor from config + // set default sizor from config setWidth(remote ? context.getConfig().getRemoteSizor() : context.getConfig().getLocalSizor()); }
participants (1)
-
tchemit@users.labs.libre-entreprise.org