I am writing a small personal file-server with Play! and it's my first web application. What are the recommended practices for storing preferences that users can modify through a preference panel.
My first idea was to use a property file in the conf
directory, but I must be able to modify it during runtime. Is the conf
directory writable, whatever the deployment option ?
Are there built-in options for that or is there a better approach ?
As said by Kim Stebel, the usual solution is to use what you application already has, which is most of the time a database engine, being relational or not. That's because most of the time, user preferences come after some other data where already persisted.
But in your case, it seems that the file system is you persistence engine, and you don't seems to need transactions or excessively good read/write performance for the discussed feature, so I would keep that part the simplest possible until some other persistence engine is needed: I would just serialize user preference object to some text format (JSON or XML comes to mind) and save them in the filesystem: no mapping hell for now, no premature choice (and even the possibility to corrupt^W edit your user preference with your favorite text editor, directly on the server, yeah ;)
That being said, there is a ton of good framework for that job, in Scala or from the Java ecosystem.
For the XML mapping, I don't thing Scala native library is the best choice. It's easy to produce XML structure with it, but the mapping from XML to Scala object is at best horrible. XStream (http://x-stream.github.io/) is quite good for that, but you will have to use Java collection, or add your own (and that wasn't my idea of the 'most simple').
For JSON mapping, there is several really good libraries in Scala. Google and other stackoverflowers may have more details, but I know there is at least these two:
Hope it helps,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With