From: Javen O'Neal Date: Fri, 10 Jun 2016 01:08:05 +0000 (+0000) Subject: bug 57840: move XSSFTable cache from XSSFWorkbook to XSSFEvaluationWorkbook where... X-Git-Tag: REL_3_15_BETA2~183^2~11 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4b6821c5ae734d2d80cc4bd31229a390caef0068;p=poi.git 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 --- 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; } }