protected ViewNavigator getNavigator() { final Map<String, Object> requestScope = getRequestScope(); final String key = "viewnav-" + this.toString(); if (!requestScope.containsKey(key)) { requestScope.put(key, getNewNavigator()); } nav_ = (ViewNavigator) requestScope.get(key); return nav_; }
@SuppressWarnings("unchecked") private Map<Integer, E> getCache() { Map<String, Object> cacheScope = FrameworkUtils.isFaces() ? FrameworkUtils.getRequestScope() : internalCacheScope_; String key = toString() + "_entrycache"; if (!cacheScope.containsKey(key)) { cacheScope.put(key, new HashMap<Integer, E>()); } return (Map<Integer, E>) cacheScope.get(key); }
protected ViewEntryCollection getEntries() { final Map<String, Object> requestScope = getRequestScope(); final String key = "viewentries-" + this.toString(); if (!requestScope.containsKey(key)) { View view = getView(); if (StringUtil.isNotEmpty(searchQuery_)) { if (getResortColumn() != null) { view.FTSearchSorted( searchQuery_, 0, getResortColumn(), isAscending(), false, false, false); } else { view.FTSearch(searchQuery_); } } if (category_ != null) { requestScope.put(key, view.getAllEntriesByKey(category_)); } else { requestScope.put(key, view.getAllEntries()); } } return (ViewEntryCollection) requestScope.get(key); }
/* ********************************************************************** * List methods ************************************************************************/ @Override @SuppressWarnings("deprecation") public E get(final int index) { if (invalid_) { return null; } Map<Integer, E> cache = getCache(); if (!cache.containsKey(index)) { try { if (searchQuery_ == null || searchQuery_.isEmpty()) { ViewNavigator nav = getNavigator(); // getNth is top-level only, so let's skip to what we need int lastFetchedIndex = 0; Map<String, Object> requestScope = getRequestScope(); String key = "lastFetchedIndex-" + toString(); if (requestScope.containsKey(key)) { lastFetchedIndex = (Integer) requestScope.get(key); } nav.skip(index - lastFetchedIndex); requestScope.put(key, index); try { // Try to get the current one, which may be null due to an as-yet-unsolved // "object has been removed or recycled" error. Check for that and switch to // our exception handler to retry ViewEntry entry = nav.getCurrent(); if (entry == null) { throw new NullPointerException(); } cache.put(index, createFromViewEntry(entry, columnInfo_)); } catch (NullPointerException npe) { // Then we've probably hit an "Object has been removed or recycled" on the nav if (reset_ < 10) { reset_++; clearCache(); return get(index); } System.out.println("=============================== NPE in DominoModelList"); System.out.println( "=============================== Current class: " + getClass().getName()); System.out.println("=============================== Type: " + getClazz().getName()); System.out.println("=============================== Desired index: " + index); System.out.println("=============================== Current cache: " + cache); System.out.println("=============================== Current reported size: " + size()); throw npe; } catch (RuntimeException re) { if (String.valueOf(re.getCause()).contains("Argument has been removed or recycled")) { if (reset_ < 10) { reset_++; clearCache(); return get(index); } } // Otherwise, throw it up throw re; } } else { ViewEntryCollection vec = getEntries(); cache.put(index, createFromViewEntry(vec.getNthEntry(index + 1), columnInfo_)); } } catch (Exception e) { throw e instanceof RuntimeException ? (RuntimeException) e : new RuntimeException(e); } } return cache.get(index); }