Class JdbcColumnPreferenceStorage
java.lang.Object
org.vaadin.addons.antlerflow.grid.columns.storage.ServerSideColumnPreferenceStorage
org.vaadin.addons.antlerflow.grid.columns.storage.JdbcColumnPreferenceStorage
- All Implemented Interfaces:
Serializable, ColumnPreferenceStorage
Stores preferences per user in a relational database through plain JDBC, so they follow the
user across browsers and devices. Works with any
DataSource (Spring Boot's pooled one
included) and any SQL database; no ORM is required.
Table (create it with your migrations from getCreateTableSql(), or call initializeSchema() once at startup):
CREATE TABLE af_grid_column_preference (
user_id VARCHAR(255) NOT NULL,
preference_key VARCHAR(255) NOT NULL,
preference_value VARCHAR(4000) NOT NULL,
PRIMARY KEY (user_id, preference_key)
)
preference_value holds one line per column, +id visible or -id
hidden. Create one instance per application (for example a Spring bean) and share it.
The data source is not serialized with the session. If sessions are serialized (clustering, session persistence), set the storage on the grid when the view is created; a deserialized instance logs a warning and keeps the default columns instead of failing.
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionJdbcColumnPreferenceStorage(DataSource dataSource, com.vaadin.flow.function.SerializableSupplier<String> userIdSupplier) Uses thedefault table.JdbcColumnPreferenceStorage(DataSource dataSource, com.vaadin.flow.function.SerializableSupplier<String> userIdSupplier, String tableName) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidDeletes the preference; a missing preference is not an error.Returns portable DDL for the preference table, for use in schema migrations.voidCreates the preference table when it does not exist.Reads the stored preference; empty when none is stored.protected voidInserts or replaces the preference.Methods inherited from class ServerSideColumnPreferenceStorage
clear, load, requestPrincipalName, save
-
Field Details
-
DEFAULT_TABLE_NAME
- See Also:
-
-
Constructor Details
-
JdbcColumnPreferenceStorage
public JdbcColumnPreferenceStorage(DataSource dataSource, com.vaadin.flow.function.SerializableSupplier<String> userIdSupplier) Uses thedefault table. -
JdbcColumnPreferenceStorage
public JdbcColumnPreferenceStorage(DataSource dataSource, com.vaadin.flow.function.SerializableSupplier<String> userIdSupplier, String tableName) - Parameters:
tableName- a table name, optionally schema-qualified (app.grid_prefs)- Throws:
IllegalArgumentException- if the table name is not a plain SQL identifier
-
-
Method Details
-
getTableName
-
getCreateTableSql
Returns portable DDL for the preference table, for use in schema migrations. -
initializeSchema
public void initializeSchema()Creates the preference table when it does not exist. Prefer schema migrations (Flyway, Liquibase) in production; this is a convenience for demos and simple deployments.- Throws:
ColumnPreferenceStorageException- if the database cannot be inspected or changed
-
read
Description copied from class:ServerSideColumnPreferenceStorageReads the stored preference; empty when none is stored.- Specified by:
readin classServerSideColumnPreferenceStorage
-
write
Description copied from class:ServerSideColumnPreferenceStorageInserts or replaces the preference.- Specified by:
writein classServerSideColumnPreferenceStorage
-
delete
Description copied from class:ServerSideColumnPreferenceStorageDeletes the preference; a missing preference is not an error.- Specified by:
deletein classServerSideColumnPreferenceStorage
-