Package nl.knaw.dans.lib.dataverse
Class DatabaseApi
java.lang.Object
nl.knaw.dans.lib.dataverse.DatabaseApi
Optional API to perform direct database operations on the Dataverse database. Requires databaseUrl, databaseUser, and databasePassword in DataverseClientConfig.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final nl.knaw.dans.lib.dataverse.HttpClientWrapperprotected static final String -
Method Summary
Modifier and TypeMethodDescriptionprotected PathgetQueryParamsFromMetadataKeys(Map<String, String> metadataKeys) Creates a QueryContext for the provided SQL query.<T> QueryContext<T>Creates a QueryContext for the provided SQL query, using the provided mapper function to map each ResultSet row to an object of type T.inttruncateNotificationsForAllUsers(int numberOfRecordsToKeep) Truncate notifications for all users who currently have more than N notifications.inttruncateNotificationsForUser(int userId, int numberOfRecordsToKeep) Truncate notifications for a single user, keeping the newest N records.
-
Field Details
-
MDKEY_PARAM_NAME_PREFIX
- See Also:
-
httpClientWrapper
protected final nl.knaw.dans.lib.dataverse.HttpClientWrapper httpClientWrapper
-
-
Method Details
-
query
Creates a QueryContext for the provided SQL query. The QueryContext can be used to execute the query with different sets of parameters. Note that the connection used by the QueryContext is set to read-only mode, so this method is intended for executing read-only queries. It is generally not recommended to change the Dataverse database directly.- Parameters:
query- the SQL query to execute, which may contain parameter placeholders (e.g., "?") for use with prepared statements- Returns:
- a QueryContext for executing the provided SQL query with different sets of parameters
-
query
public <T> QueryContext<T> query(@NonNull @NonNull String query, @NonNull @NonNull Function<ResultSet, T> mapper) Creates a QueryContext for the provided SQL query, using the provided mapper function to map each ResultSet row to an object of type T. The QueryContext can be used to execute the query with different sets of parameters. Note that the connection used by the QueryContext is set to read-only mode, so this method is intended for executing read-only queries. It is generally not recommended to change the Dataverse database directly.- Type Parameters:
T- the type of objects to return in the list when executing the query with sets of parameters without providing a custom mapper- Parameters:
query- the SQL query to execute, which may contain parameter placeholders (e.g., "?") for use with prepared statementsmapper- a function that maps a ResultSet row to an object of type T, which will be used as the default mapper for the QueryContext. This mapper will be used when executing the query with sets of parameters without providing a custom mapper.- Returns:
- a QueryContext for executing the provided SQL query with different sets of parameters, using the provided mapper function to map ResultSet rows to objects of type T
-
truncateNotificationsForUser
Truncate notifications for a single user, keeping the newest N records.- Parameters:
userId- the user_id in the Dataverse database (numeric)numberOfRecordsToKeep- number of latest notifications to keep (must be >= 0)- Returns:
- number of deleted rows
- Throws:
SQLException- when database access fails
-
truncateNotificationsForAllUsers
Truncate notifications for all users who currently have more than N notifications. Keeps the newest N records per user.- Parameters:
numberOfRecordsToKeep- number of latest notifications to keep (must be >= 0)- Returns:
- total number of deleted rows across all users
- Throws:
SQLException- when database access fails
-
buildPath
-
getQueryParamsFromMetadataKeys
-