From 4b6821c5ae734d2d80cc4bd31229a390caef0068 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Fri, 10 Jun 2016 01:08:05 +0000 Subject: [PATCH] bug 57840: move XSSFTable cache from XSSFWorkbook to XSSFEvaluationWorkbook where staleness is less likely to cause problems for users git-svn-id: https://svn.apache.org/repos/asf/poi/branches/xssf_structured_references@1747616 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/xssf/usermodel/XSSFWorkbook.java | 45 +++++-------------- 1 file changed, 10 insertions(+), 35 deletions(-) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 622979d167..1dcb3c42f2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -2263,48 +2263,23 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { return SpreadsheetVersion.EXCEL2007; } - /* - * TODO: data tables are stored at the workbook level in XSSF, but are bound to a single sheet. - * The current code structure has them hanging off XSSFSheet, but formulas reference them - * only by name (names are global, and case insensitive). - * This map stores names as lower case for case-insensitive lookups. - * - * FIXME: Caching tables by name here for fast formula lookup means the map is out of date if - * a table is renamed or added/removed to a sheet after the map is created. - * - * Perhaps tables can be managed similar to PivotTable references above? - */ - Map _tableCache = null; - private Map getTableCache() { - if ( _tableCache != null ) { - return _tableCache; - } - // FIXME: use org.apache.commons.collections.map.CaseInsensitiveMap - _tableCache = new HashMap(); - - if (sheets != null) { - for (XSSFSheet sheet : sheets) { - for (XSSFTable tbl : sheet.getTables()) { - String lname = tbl.getName().toLowerCase(Locale.ROOT); - _tableCache.put(lname, tbl); - } - } - } - return _tableCache; - } - /** * Returns the data table with the given name (case insensitive). - * Tables are cached for performance (formula evaluation looks them up by name repeatedly). - * After the first table lookup, adding or removing a table from the document structure will cause trouble. - * This is meant to be used on documents whose structure is essentially static at the point formulas are evaluated. * * @param name the data table name (case-insensitive) * @return The Data table in the workbook named name, or null if no table is named name. * @since 3.15 beta 2 */ public XSSFTable getTable(String name) { - String lname = name.toLowerCase(Locale.ROOT); - return getTableCache().get(lname); + if (sheets != null) { + for (XSSFSheet sheet : sheets) { + for (XSSFTable tbl : sheet.getTables()) { + if (name.equalsIgnoreCase(tbl.getName())) { + return tbl; + } + } + } + } + return null; } } -- 2.39.5