1

I'm creating an application where i store all the users settings into a MySQL server. But now i got like something when tableOption3 = id25 then the users theme is red. I already got 5 such tables. 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.

Do I have other options? And I keep wondering what happens if there would be 100 personal option to be loaded. Would the user notice this in loading speed.

Mark Davidson
  • 5,503
  • 5
  • 35
  • 54
Greg
  • 1,690
  • 4
  • 26
  • 52
  • have you considered using a NOSQL db? – nafas May 12 '15 at 13:09
  • 1
    If you want to load and save user preferences only on login/logout in desktop app you can keep it in one class then serialize it during logout and again deserialize during login. Its not that time cosuming imho you wont even notice loading 100 preferences – Ziker May 12 '15 at 13:12
  • I have no experience with NoSQL. But why would you prefer NOSQl in this case? – Greg May 12 '15 at 13:14
  • @ziker i will certainly look into this.We used this in class but I can simply create a class with all the user settings and store it into a database? – Greg May 12 '15 at 13:20
  • possible duplicate of [Best approach to save user preferences?](http://stackoverflow.com/questions/1079711/best-approach-to-save-user-preferences) – Ziker May 12 '15 at 13:25
  • 1
    this question should help you http://stackoverflow.com/questions/1079711/best-approach-to-save-user-preferences also @Fazovsky provided good answer – Ziker May 12 '15 at 13:26

2 Answers2

1

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.
I think that SQL databases are usually way to go, and having more then 100 personal options shouldn't degrade performance too much.

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, i.e.:

 USER_ID | PROPERTY | PROPERTY_VALUE
 1       | COLOR    | RED
 2       | COLOR    | BLUE
 1       | FONT_SIZE| 12
 2       | FONT_SIZE| 14
etc
FazoM
  • 4,777
  • 6
  • 43
  • 61
0

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.