This discussion is archived
3 Replies Latest reply: Nov 29, 2012 9:08 AM by rp0428 RSS

How to abstract configuration data

meandmycode Newbie
Currently Being Moderated
Hi,

We have two different resources of data xml and a database. Data from there is used to configure our system. We use java se ( version 7).

In the code we want to be able and access this configuration data ( independently of where it is stored) using something like:

Configuration.getInstance().getString(<HERE we can to use a constant name>);

Any ideas of how we can implement some kind of layer in between to be able to access it like above ( or a similair way).
Is there articles about this?

br,

//mike
  • 1. Re: How to abstract configuration data
    gimbal2 Guru
    Currently Being Moderated
    Do you want the configuration to be system-wide, or bound to the user that is logged in?

    In any case the standard JDK Preferences class may be what you're looking for.
  • 2. Re: How to abstract configuration data
    meandmycode Newbie
    Currently Being Moderated
    Hi,

    I am looking for a system wide configuration. How can I load data from a database using Properties?

    br,

    //mike
  • 3. Re: How to abstract configuration data
    rp0428 Guru
    Currently Being Moderated
    >
    I am looking for a system wide configuration. How can I load data from a database using Properties?
    >
    You don't - you would use JDBC to connect to the database when your app starts and select the properties and values from a database table. Then you could iterate the result set that is returned and load the values into a Properties instance if you like.

    Of course the chicken and egg problem is that your app need a minmal set of properties to know how to connect to the database. Those properties could be passed on the command line to make that part 'system-wide'.

    The whole idea begs the question of whether you really want your application dependent on the availability of the database in order to even run. If the app needs that database for proper operation of other functionality then that isn't a problem.

    Again, everyone would be better able to help if you gave an actual example of the types of configuration properties you are talking about.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points