[英]Best way to save personal user settings who are used on java desktop application app and website
I'm creating an application where i store all the users settings into a MySQL server. 我正在创建一个应用程序,其中将所有用户设置存储到MySQL服务器中。 But now i got like something when tableOption3 = id25 then the users theme is red.
但是现在,当tableOption3 = id25时,我得到了类似的东西,那么用户主题为红色。 I already got 5 such tables.
我已经有5张这样的桌子。 And it going to get alot bigger.
而且它会变得更大。 The user can use an mobile application that saves the personal settings for the website and java application and visa versa.
用户可以使用移动应用程序保存网站和Java应用程序的个人设置,反之亦然。
Do I have other options? 我还有其他选择吗? And I keep wondering what happens if there would be 100 personal option to be loaded.
我一直想知道如果要加载100个个人选项会发生什么情况。 Would the user notice this in loading speed.
用户是否会在加载速度中注意到这一点。
You have to save these personal user settings somewhere and you will always want to use some sort of datastore, like: SQL databases
, NOSQL
, flat files. 您必须将这些个人用户设置保存在某处,并且您将始终想要使用某种数据存储,例如:
SQL databases
, NOSQL
,平面文件。
I think that SQL databases are usually way to go, and having more then 100 personal options shouldn't degrade performance too much. 我认为SQL数据库通常是可行的方法,拥有100个以上的个人选项应该不会降低性能。
But my advice will be to avoid having multiple tables. 但是我的建议是避免有多个表。 You can achieve desired effect, with all properties stored for all users, by having
just one table
, ie: 您
just one table
,即可为所有用户存储所有属性,从而达到预期的效果,即:
USER_ID | PROPERTY | PROPERTY_VALUE
1 | COLOR | RED
2 | COLOR | BLUE
1 | FONT_SIZE| 12
2 | FONT_SIZE| 14
etc
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. 如果您正在寻找Java的嵌入式解决方案,可以尝试jsup ,它是一个Java库,用于在SQL数据库中存储和获取简单的用户首选项。
I am the author of jsup and write a lot of small applications/tools. 我是jsup的作者,并编写了许多小型应用程序/工具。 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.
我经常发现需要支持用户首选项,并且找不到适合于不同SQL数据库的合适的库,因此我继续创建jsup。
It works with a variety of common SQL database types and is simple to get started with: 它可以与多种常见的SQL数据库类型一起使用,并且很容易上手:
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. GitHub页面上有示例和更多文档。 If there are things you'd like added please open a ticket.
如果您想添加一些东西,请打开一张票。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.