Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Database implementation of java.util.prefs.Preferences?

819 views
Skip to first unread message

Marcin

unread,
Sep 19, 2012, 4:51:03 PM9/19/12
to
Hello

I have a Java program that uses java.util.prefs.Preferences to store
configuration data. Everything is OK if one user works on one computer
but if one user can use many computers the data is not shared between
workstations and "environment" is different dependent on which computer
user is logged in. I think I can store the same data in database because
application uses connection to database for other purposes. Do you know
any implementation of abstract class java.util.prefs.Preferences that
uses SQL to store the configuration data? I cannot google anything
interesting...

Regards,
Mar

markspace

unread,
Sep 19, 2012, 6:28:22 PM9/19/12
to
I would kind of doubt there is one. In a situation like this, I would
consider using Preferences::exportSubtree() and
Preferences::importPreferences() to read and write to a blob in a
database.

I'd think carefully about it first though, as something about it feels
like a mismatch for a preferences module in general.



John B. Matthews

unread,
Sep 19, 2012, 8:59:51 PM9/19/12
to
"There are two separate trees of preference nodes, one for user
preferences and one for system preferences." Instead of SQL, just start
from systemRoot() for shared preferences.

<http://docs.oracle.com/javase/7/docs/api/java/util/prefs/Preferences.html>

--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>

markspace

unread,
Sep 19, 2012, 10:07:53 PM9/19/12
to
On 9/19/2012 5:59 PM, John B. Matthews wrote:
> In article <k3dgu8$k1h$1...@dont-email.me>, markspace <-@.> wrote:
>
>> On 9/19/2012 1:51 PM, Marcin wrote:
>>> if one user can use many computers the data is not
>>> shared between workstations and "environment" is different
>>> dependent on which computer user is logged in.
>
> Instead of SQL, just start
> from systemRoot() for shared preferences.
>

System = one computer. The op wants to share user configurations
between multiple computers. Using systemRoot won't help because it's
limited to a single system.



John B. Matthews

unread,
Sep 20, 2012, 12:20:24 PM9/20/12
to
D'oh, I misunderstood the question; thanks for clarifying. I wonder if a
javax.jnlp.PersistenceService might be useful in this context.

<http://pscode.org/jws/api.html#ps>
<http://docs.oracle.com/javase/7/docs/jre/api/javaws/jnlp/javax/jnlp/Pers
istenceService.html>
<http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersg
uide/examples.html>

Roedy Green

unread,
Sep 21, 2012, 10:12:48 AM9/21/12
to
On Wed, 19 Sep 2012 22:51:03 +0200, Marcin <nom...@nospam.com> wrote,
quoted or indirectly quoted someone who said :

> Do you know
>any implementation of abstract class java.util.prefs.Preferences that
>uses SQL to store the configuration data?

On windows, it uses the registry. on Linux it has a little database.

see http://mindprod.com/jgloss/preferences.html
--
Roedy Green Canadian Mind Products http://mindprod.com
The iPhone 5 is a low end Rolex.


Daniel Pitts

unread,
Sep 21, 2012, 1:19:13 PM9/21/12
to
If you need to store preferences across computers,
java.util.prefs.Preferences is not the class to do it with.
java.util.prefs.Preferences was basically meant to be a Java interface
into the Windows Registry (with a more system-independent back-end).
You will want to create your own way of persisting user preferences
which involves storing them on some server somewhere. You could put it
into the same database as your application's domain database, though it
isn't a good excuse that "I'm already connecting to it."

It may be a better implementation to have a separate Preferences
database, or web-service, or whatever makes sense in your
environment(s). Personally, I like the "web-service" approach, but that
is 80% of what I do on a daily basis, so my preference (no pun intended)
is biased.

John B. Matthews

unread,
Sep 21, 2012, 9:10:18 PM9/21/12
to
In article <ldto581bsn26ok3c4...@4ax.com>,
Roedy Green <see_w...@mindprod.com.invalid> wrote:

> On Wed, 19 Sep 2012 22:51:03 +0200, Marcin <nom...@nospam.com> wrote,
> quoted or indirectly quoted someone who said :
>
> > Do you know any implementation of abstract class
> > java.util.prefs.Preferences that uses SQL to store the
> > configuration data?
>
> On windows, it uses the registry. on Linux it has a little database.
>
> see http://mindprod.com/jgloss/preferences.html

Given a declaration such as this:

Preferences p = Preferences
.userRoot().node("org").node("gcs").node("RobotChase");

Mac OS X uses a single XML file for the leaf node:

~/Library/Preferences/org.gcs.robotchase.plist

<http://www.apple.com/DTDs/PropertyList-1.0.dtd>

In contrast, linux uses a directory sub-tree that reflects the node
structure:

~/.java.userPrefs/org/gcs/RobotChase/prefs.xml

<http://java.sun/dtd/preferences.dtd>

Given the disparate implementations, it's a pretty good abstraction.
0 new messages