]> source.dussan.org Git - vaadin-framework.git/commitdiff
feat: Add better API to configure maximum allowed rows (#12466) (#12471)
authorAnna Koskinen <Ansku@users.noreply.github.com>
Thu, 4 Nov 2021 06:26:03 +0000 (08:26 +0200)
committerGitHub <noreply@github.com>
Thu, 4 Nov 2021 06:26:03 +0000 (08:26 +0200)
Co-authored-by: Olli Tietäväinen <ollit@vaadin.com>
Co-authored-by: Tatu Lund <tatu@vaadin.com>
Co-authored-by: Olli Tietäväinen <ollit@vaadin.com>
server/src/main/java/com/vaadin/data/provider/DataCommunicator.java
server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java

index 8d974c85d38ca681b375d900702fa63925527fbe..097cef622dbf78d61818217af798a7f59424d620 100644 (file)
@@ -60,7 +60,7 @@ import elemental.json.JsonObject;
 public class DataCommunicator<T> extends AbstractExtension {
 
     private Registration dataProviderUpdateRegistration;
-    private static final int MAXIMUM_ALLOWED_ROWS = 500;
+    private int maximumAllowedRows = 500;
 
     /**
      * Simple implementation of collection data provider communication. All data
@@ -316,14 +316,24 @@ public class DataCommunicator<T> extends AbstractExtension {
     }
 
     /**
-     * Set the maximum allowed rows to be fetched in one query.
+     * Get the maximum allowed rows to be fetched in one query.
      * 
      * @return Maximum allowed rows for one query.
      * @since 8.14.1
      */
     protected int getMaximumAllowedRows() {
-        return MAXIMUM_ALLOWED_ROWS;
-    }    
+        return maximumAllowedRows;
+    }
+
+    /**
+     * Set the maximum allowed rows to be fetched in one query.
+     * 
+     * @param maximumAllowedRows Maximum allowed rows for one query.
+     * @since
+     */
+    public void setMaximumAllowedRows(int maximumAllowedRows) {
+        this.maximumAllowedRows = maximumAllowedRows;
+    }
 
     /**
      * Triggered when rows have been dropped from the client side cache.
index ed681f298d7839079cfb674abc4e76334db3f1bc..fda867eeef1c54e5edce50ab62ac7aad8ba41ce3 100644 (file)
@@ -322,4 +322,12 @@ public class DataCommunicatorTest {
         communicator.onRequestRows(0, communicator.getMaximumAllowedRows() + 10,
                 0, 0);
     }
+
+    @Test
+    public void requestTooMuchRowsOverride() {
+        TestDataCommunicator communicator = new TestDataCommunicator();
+        int maxRows = communicator.getMaximumAllowedRows();
+        communicator.setMaximumAllowedRows(maxRows + 100);
+        communicator.onRequestRows(0, maxRows + 10, 0, 0);
+    }
 }