If you're looking for a drop-in solution for Java you can try jsup, which is a java library to store and fetch simple user preferences in SQL databases.
I am the author of jsup and write a lot of small applications/tools. I have often found the need to support user preferences and didn't find a suitable library that worked with different SQL databases, so I went ahead and created jsup.
It works with a variety of common SQL database types and is simple to get started with:
Injector injector = Guice.createInjector(
new AbstractModule() {
@Override
protected void configure() {
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:h2:mem:testdb");
HikariDataSource dataSource = new HikariDataSource(config);
// Be sure to specify the correct dialect.
bind(Key.get(SQLDialect.class, UserPreferencesModule.UserPreferences.class)).toInstance(SQLDialect.H2);
bind(Key.get(DataSource.class, UserPreferencesModule.UserPreferences.class)).toInstance(dataSource);
}
},
new UserPreferencesModule());
UserPreferencesDb userPreferencesDb = injector.getInstance(UserPreferencesDb.class);
UserPreferencesAnalytics userPreferencesAnalytics = injector.getInstance(UserPreferencesAnalytics.class);
userPreferencesDb.setString("some-user", "ui", "theme", "default");
userPreferencesDb.setString("some-user", "ui", "display.timestamp.timezone", "UTC");
userPreferencesDb.addToSet("some-user", "app", "favorite.projects", ImmutableSet.of("prj1", "prj2"));
userPreferencesDb.setBoolean("some-user", "app", "email.on.failure", true);
System.out.println(userPreferencesDb.getString("some-user", "ui", "theme"));
System.out.println(userPreferencesDb.getString("some-user", "ui", "display.timestamp.timezone"));
System.out.println(userPreferencesDb.getSet("some-user", "app", "favorite.projects"));
System.out.println(userPreferencesDb.getBoolean("some-user", "app", "email.on.failure"));
System.out.println(userPreferencesAnalytics.getStringCategories());
System.out.println(userPreferencesAnalytics.getBooleanPreferencesByUser("app", "email.on.failure"));
In addition to a DB interface to store and fetch preferences, there is an analytics interface to get stats or make integration with other tools easier.
There are examples and more documentation on the GitHub page. If there are things you'd like added please open a ticket.