From: koutsoub Date: Thu, 3 Feb 2011 15:14:26 +0000 (+0200) Subject: initial caching support X-Git-Tag: pithos/v0.7.8~323^2~14^2~22^2~63 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/56c1ca4ba07c6b7361709b73de8e9e8ee801878d initial caching support --- diff --git a/src/gr/ebs/gss/client/CellTreeViewModel.java b/src/gr/ebs/gss/client/CellTreeViewModel.java index 6c747fe..35aee38 100644 --- a/src/gr/ebs/gss/client/CellTreeViewModel.java +++ b/src/gr/ebs/gss/client/CellTreeViewModel.java @@ -61,6 +61,7 @@ import com.google.gwt.safehtml.client.SafeHtmlTemplates; import com.google.gwt.safehtml.shared.SafeHtml; import com.google.gwt.safehtml.shared.SafeHtmlBuilder; import com.google.gwt.user.client.DeferredCommand; +import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.AbstractImagePrototype; import com.google.gwt.view.client.AsyncDataProvider; import com.google.gwt.view.client.HasData; @@ -77,6 +78,7 @@ import com.google.gwt.view.client.TreeViewModel; */ public class CellTreeViewModel implements TreeViewModel{ private final ListDataProvider rootNodes = new ListDataProvider(); + private Map folderCache=new HashMap(); final Images images; SingleSelectionModel selectionModel; Map mymap = new HashMap(); @@ -353,7 +355,8 @@ public class CellTreeViewModel implements TreeViewModel{ @Override public void onComplete() { FolderResource rootResource = getResult(); - ((MyFolderResource)value).getResource().setFiles(rootResource.getFiles()); + //((MyFolderResource)value).getResource().setFiles(rootResource.getFiles()); + ((MyFolderResource)value).setResource(rootResource); if(GSS.get().getTreeView().getSelection().getUri().equals(value.getUri())) selectionModel.setSelected(value, true); GWT.log("UPDATYING"); @@ -441,20 +444,27 @@ public class CellTreeViewModel implements TreeViewModel{ public void setRestResource(RestResource restResource) { this.restResource = restResource; } - + List res =null; public void refresh(final RefreshHandler refresh){ GWT.log("******************************************"); GWT.log("[REFRESHING]:"+restResource.getUri()); GWT.log("******************************************"); - GetCommand gf = new GetCommand(FolderResource.class, restResource.getUri(), null) { + FolderResource cache = null; + if(!((RestResourceWrapper)restResource).getResource().isNeedsExpanding()) + cache = ((RestResourceWrapper)restResource).getResource(); + GetCommand gf = new GetCommand(FolderResource.class, restResource.getUri(),cache ) { @Override public void onComplete() { if(restResource instanceof RestResourceWrapper) ((RestResourceWrapper)restResource).setResource(getResult());//restResource = getResult(); - - //if(CellTreeView.this.mymap.get(restResource.getUri())!=null) - //CellTreeView.this.mymap.get(restResource.getUri()).setRestResource(restResource); + ((RestResourceWrapper)restResource).getResource().setNeedsExpanding(false); + Window.alert(""+usedCachedVersion()); + if(usedCachedVersion()&&res!=null){ + updateRowCount(res.size(), true); + updateRowData(0,res); + return; + } String[] folderPaths = null; if(resourceClass.equals(MyFolderResource.class)) folderPaths=((MyFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {}); @@ -471,11 +481,11 @@ public class CellTreeViewModel implements TreeViewModel{ else if(resourceClass.equals(OthersFolderResource.class)) folderPaths=((OthersFolderResource) restResource).getResource().getSubfolderPaths().toArray(new String[] {}); MultipleGetCommand gf2 = new MultipleGetCommand(FolderResource.class, - folderPaths, null) { + folderPaths, ((RestResourceWrapper)restResource).getResource().getCache()) { @Override public void onComplete() { - List res = new ArrayList(); + res = new ArrayList(); for(FolderResource r : getResult()){ if(r.isDeleted()){ @@ -491,6 +501,7 @@ public class CellTreeViewModel implements TreeViewModel{ else if(resourceClass.equals(OthersFolderResource.class)) res.add(new OthersFolderResource(r)); } + ((RestResourceWrapper)restResource).getResource().setFolders(getResult()); updateRowCount(res.size(), true); updateRowData(0,res); if(refresh!=null) @@ -515,6 +526,7 @@ public class CellTreeViewModel implements TreeViewModel{ @Override public void onError(Throwable t) { + GWT.log("Error fetching root folder", t); GSS.get().displayError("Unable to fetch root folder"); } diff --git a/src/gr/ebs/gss/client/rest/GetCommand.java b/src/gr/ebs/gss/client/rest/GetCommand.java index e6ea225..761b827 100644 --- a/src/gr/ebs/gss/client/rest/GetCommand.java +++ b/src/gr/ebs/gss/client/rest/GetCommand.java @@ -165,13 +165,14 @@ public abstract class GetCommand extends RestCommand{ public void handleError(Request request, Throwable _exception) { result = null; complete = true; + exception = _exception; if(_exception instanceof RestException) if(((RestException)_exception).getHttpStatusCode() == 304 && cached != null){ GWT.log("Using cache:"+cached.getUri(), null); handleSuccess(cached); return; } - exception = _exception; + } @Override @@ -320,4 +321,12 @@ public abstract class GetCommand extends RestCommand{ public void setCached(T theCached) { this.cached = theCached; } + + public boolean usedCachedVersion(){ + if(exception !=null && exception instanceof RestException) + if(((RestException)exception).getHttpStatusCode() == 304){ + return true; + } + return false; + } }