Browse Source

feat: Add better API to configure maximum allowed rows (#12466)

* feat: Add better API to configure maximum allowed rows

* Add unit test

Co-authored-by: Olli Tietäväinen <ollit@vaadin.com>
tags/8.15.0
Tatu Lund 2 years ago
parent
commit
b62869bfb1
No account linked to committer's email address

+ 14
- 4
server/src/main/java/com/vaadin/data/provider/DataCommunicator.java View File

public class DataCommunicator<T> extends AbstractExtension { public class DataCommunicator<T> extends AbstractExtension {


private Registration dataProviderUpdateRegistration; private Registration dataProviderUpdateRegistration;
private static final int MAXIMUM_ALLOWED_ROWS = 500;
private int maximumAllowedRows = 500;


/** /**
* Simple implementation of collection data provider communication. All data * Simple implementation of collection data provider communication. All data
} }


/** /**
* 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. * @return Maximum allowed rows for one query.
* @since 8.14.1 * @since 8.14.1
*/ */
protected int getMaximumAllowedRows() { 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. * Triggered when rows have been dropped from the client side cache.

+ 8
- 0
server/src/test/java/com/vaadin/data/provider/DataCommunicatorTest.java View File

communicator.onRequestRows(0, communicator.getMaximumAllowedRows() + 10, communicator.onRequestRows(0, communicator.getMaximumAllowedRows() + 10,
0, 0); 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);
}
} }

Loading…
Cancel
Save