poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From one...@apache.org
Subject svn commit: r1751836 - in /poi/trunk: src/java/org/apache/poi/hssf/usermodel/ src/java/org/apache/poi/ss/formula/ src/java/org/apache/poi/ss/formula/eval/forked/ src/ooxml/java/org/apache/poi/xssf/streaming/ src/ooxml/java/org/apache/poi/xssf/usermodel...
Date Thu, 07 Jul 2016 22:22:10 GMT
Author: onealj
Date: Thu Jul  7 22:22:10 2016
New Revision: 1751836

URL: http://svn.apache.org/viewvc?rev=1751836&view=rev
Log:
bug 59814: clear evaluation workbook and evaluation sheet caches. Patch from Greg Woolsey.

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationSheet.java
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java
    poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationSheet.java
    poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java
    poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
    poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationSheet.java
    poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java
    poi/trunk/test-data/spreadsheet/StructuredReferences.xlsx

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationSheet.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationSheet.java Thu Jul  7 22:22:10
2016
@@ -45,4 +45,8 @@ final class HSSFEvaluationSheet implemen
 		}
 		return new HSSFEvaluationCell(cell, this);
 	}
+	
+	public void clearAllCachedResultValues() {
+	    // nothing to do
+	}
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFEvaluationWorkbook.java Thu Jul 
7 22:22:10 2016
@@ -64,6 +64,10 @@ public final class HSSFEvaluationWorkboo
         _iBook = book.getWorkbook();
     }
     
+    public void clearAllCachedResultValues() {
+        // nothing to do
+    }
+    
     @Override
     public HSSFName createName() {
         return _uBook.createName();

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationSheet.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationSheet.java Thu Jul  7 22:22:10
2016
@@ -30,4 +30,12 @@ public interface EvaluationSheet {
 	 * @return <code>null</code> if there is no cell at the specified coordinates
 	 */
 	EvaluationCell getCell(int rowIndex, int columnIndex);
+	
+    /**
+     * Propagated from {@link EvaluationWorkbook#clearAllCachedResultValues()} to clear locally
cached data.
+     * 
+     * @see WorkbookEvaluator#clearAllCachedResultValues()
+     * @see EvaluationWorkbook#clearAllCachedResultValues()
+     */
+    public void clearAllCachedResultValues();
 }

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/EvaluationWorkbook.java Thu Jul  7 22:22:10
2016
@@ -73,6 +73,13 @@ public interface EvaluationWorkbook {
     String resolveNameXText(NameXPtg ptg);
     Ptg[] getFormulaTokens(EvaluationCell cell);
     UDFFinder getUDFFinder();
+    
+    /**
+     * Propagated from {@link WorkbookEvaluator#clearAllCachedResultValues()} to clear locally
cached data.
+     * Implementations must call the same method on all referenced {@link EvaluationSheet}
instances, as well as clearing local caches.
+     * @see WorkbookEvaluator#clearAllCachedResultValues()
+     */
+    public void clearAllCachedResultValues();
 
     class ExternalSheet {
         private final String _workbookName;

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/WorkbookEvaluator.java Thu Jul  7 22:22:10
2016
@@ -208,6 +208,7 @@ public final class WorkbookEvaluator {
     public void clearAllCachedResultValues() {
         _cache.clear();
         _sheetIndexesBySheet.clear();
+        _workbook.clearAllCachedResultValues();
     }
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationSheet.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationSheet.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationSheet.java Thu
Jul  7 22:22:10 2016
@@ -101,6 +101,14 @@ final class ForkedEvaluationSheet implem
 		return mewb.getSheetIndex(_masterSheet);
 	}
 
+	/* (non-Javadoc)
+	 * leave the map alone, if it needs resetting, reusing this class is probably a bad idea.
+	 * @see org.apache.poi.ss.formula.EvaluationSheet#clearAllCachedResultValues()
+	 */
+	public void clearAllCachedResultValues() {
+	    _masterSheet.clearAllCachedResultValues();
+	}
+	
 	private static final class RowColKey implements Comparable<RowColKey>{
 		private final int _rowIndex;
 		private final int _columnIndex;

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
(original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/eval/forked/ForkedEvaluationWorkbook.java
Thu Jul  7 22:22:10 2016
@@ -136,4 +136,12 @@ final class ForkedEvaluationWorkbook imp
     public UDFFinder getUDFFinder(){
         return _masterBook.getUDFFinder();
     }
+    
+    /* (non-Javadoc)
+     * leave the map alone, if it needs resetting, reusing this class is probably a bad idea.
+     * @see org.apache.poi.ss.formula.EvaluationSheet#clearAllCachedResultValues()
+     */
+    public void clearAllCachedResultValues() {
+        _masterBook.clearAllCachedResultValues();
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFEvaluationSheet.java Thu Jul
 7 22:22:10 2016
@@ -47,4 +47,8 @@ final class SXSSFEvaluationSheet impleme
         }
         return new SXSSFEvaluationCell(cell, this);
     }
+    
+    public void clearAllCachedResultValues() {
+        // nothing to do
+    }
 }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java
(original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFEvaluationWorkbook.java
Thu Jul  7 22:22:10 2016
@@ -56,6 +56,10 @@ public abstract class BaseXSSFEvaluation
         _uBook = book;
     }
 
+    public void clearAllCachedResultValues() {
+        _tableCache = null;
+    }
+    
     private int convertFromExternalSheetIndex(int externSheetIndex) {
         return externSheetIndex;
     }

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java Thu Jul
 7 22:22:10 2016
@@ -41,6 +41,10 @@ final class XSSFEvaluationSheet implemen
         return _xs;
     }
 
+    public void clearAllCachedResultValues() {
+        _cellCache = null;
+    }
+    
     public EvaluationCell getCell(int rowIndex, int columnIndex) {
         // cache for performance: ~30% speedup due to caching
         if (_cellCache == null) {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationWorkbook.java Thu
Jul  7 22:22:10 2016
@@ -40,6 +40,11 @@ public final class XSSFEvaluationWorkboo
         super(book);
     }
 
+    public void clearAllCachedResultValues() {
+        super.clearAllCachedResultValues();
+        _sheetCache = null;
+    }
+    
     @Override
     public int getSheetIndex(EvaluationSheet evalSheet) {
         XSSFSheet sheet = ((XSSFEvaluationSheet)evalSheet).getXSSFSheet();

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java
(original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java
Thu Jul  7 22:22:10 2016
@@ -18,17 +18,22 @@
 package org.apache.poi.ss.formula;
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellType;
 import org.apache.poi.ss.usermodel.CellValue;
 import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Table;
+import org.apache.poi.ss.util.AreaReference;
+import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
+import org.apache.poi.xssf.usermodel.XSSFSheet;
+import org.apache.poi.xssf.usermodel.XSSFTable;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.junit.Test;
 
@@ -63,8 +68,40 @@ public class TestStructuredReferences {
         try {
             
             final FormulaEvaluator eval = new XSSFFormulaEvaluator(wb);
-            confirm(eval, wb.getSheet("Table").getRow(5).getCell(0), 49);
-            confirm(eval, wb.getSheet("Formulas").getRow(0).getCell(0), 209);
+            final XSSFSheet tableSheet = wb.getSheet("Table");
+            final XSSFSheet formulaSheet = wb.getSheet("Formulas");
+
+            confirm(eval, tableSheet.getRow(5).getCell(0), 49);
+            confirm(eval, formulaSheet.getRow(0).getCell(0), 209);
+            confirm(eval, formulaSheet.getRow(1).getCell(0), "one");
+            
+            // test changing a table value, to see if the caches are properly cleared
+            // Issue 59814
+            
+            // this test passes before the fix for 59814
+            tableSheet.getRow(1).getCell(1).setCellValue("ONEA");
+            confirm(eval, formulaSheet.getRow(1).getCell(0), "ONEA");
+            
+            // test adding a row to a table, issue 59814
+            Row newRow = tableSheet.getRow(7);
+            if (newRow == null) newRow = tableSheet.createRow(7);
+            newRow.createCell(0, CellType.FORMULA).setCellFormula("\\_Prime.1[[#This Row],[@Number]]*\\_Prime.1[[#This
Row],[@Number]]");
+            newRow.createCell(1, CellType.STRING).setCellValue("thirteen");
+            newRow.createCell(2, CellType.NUMERIC).setCellValue(13);
+            
+            // update Table
+            final XSSFTable table = wb.getTable("\\_Prime.1");
+            final AreaReference newArea = new AreaReference(table.getStartCellReference(),
new CellReference(table.getEndRowIndex() + 1, table.getEndColIndex()));
+            String newAreaStr = newArea.formatAsString();
+            table.getCTTable().setRef(newAreaStr);
+            table.getCTTable().getAutoFilter().setRef(newAreaStr);
+            table.updateHeaders();
+            table.updateReferences();
+
+            // these fail before the fix for 59814
+            confirm(eval, tableSheet.getRow(7).getCell(0), 13*13);
+            confirm(eval, formulaSheet.getRow(0).getCell(0), 209 + 13*13);
+
         } finally {
             wb.close();
         }
@@ -78,4 +115,13 @@ public class TestStructuredReferences {
         }
         assertEquals(expectedResult, cv.getNumberValue(), 0.0);
     }
+
+    private static void confirm(FormulaEvaluator fe, Cell cell, String expectedResult) {
+        fe.clearAllCachedResultValues();
+        CellValue cv = fe.evaluate(cell);
+        if (cv.getCellType() != CellType.STRING) {
+            fail("expected String cell type but got " + cv.formatAsString());
+        }
+        assertEquals(expectedResult, cv.getStringValue());
+    }
 }

Modified: poi/trunk/test-data/spreadsheet/StructuredReferences.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/StructuredReferences.xlsx?rev=1751836&r1=1751835&r2=1751836&view=diff
==============================================================================
Binary files - no diff available.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message