• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Properties File to set database path

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All

I am using the singleton pattern for my DatabaseAccess class.

I want to be able to pass the database path and filename to the DatabaseAccess class when it is first created however I DO NOT want to have to pass the database path and filename as parameters in my DatabaseAccess.getInstance() call as I feel this would be confusing and ugly.

Would it be acceptable to pass the database path and filename to my DatabaseAccess class using the suncertify.properties file or do you think this is a bad idea ie:

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Ok may be I am just addicted to using the system properties more than I should, but i find using them is an easy way to communicate this kind of constat (mostly unchanged) values as follows:

System.getProperties().setProperty(property_name, property_value);
&
String value = System.getProperties().getProperty(property_name);
 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

personally, I pass the filename as parameter in getInstance...

I'm would be against using the suncertify.properties for that... which would be very ugly to me...
It also means your application wouldn't work without this file.
I feel it is a trick to go around Object Oriented..

I defined :
- getInstance(String file), throwing IllegalArgumentException if someone tries to create another instance..
- getInstance() for subsequent use.

Regards,
Alex
 
Simon O'Brien
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies.

Alex, you said that you ....


I defined :
- getInstance(String file), throwing IllegalArgumentException if someone tries to create another instance..
- getInstance() for subsequent use.



I was thinking of doing this but my worry was that having a getInstance(String file) would be confusing as it implies that it is possible to get another instance using a different database file.

I was going to create a 'PropertiesManager' which would create the suncertify.properties property file if it doesn't exist when a 'getProperty' or 'setProperty' is called. So a example flow for the database would be ...

1) Network Client UI Starts
2) Network Client UI calls 'PropertyManager.getProperty("DB_FILE_LOC")' to try and get saved database file location
3) Property manager cant find suncertify.properties so it creates it
4) 'PropertyManager.getProperty("DB_FILE_LOC")' returns "" as the property doesn't exist
5) User has to enter database file location into the Network Client UI
6) User presses 'Start/OK'
7) Network Client UI calls 'PropertyManager.setProperty("DB_FILE_LOC", dbFileLocValue)' to set saved database file location

What do you think?

Thanks again.

Simon
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

In my assignment, it says

"Your programs must not require use of command line property specifications. All configuration must be done via a GUI, and must be persistent between runs of the program. Such configuration information must be stored in a file called suncertify.properties which must be located in the current working directory."

So let's say I start up the app in "server" mode, and this server allows to choose a db file to run which I then save in my suncertify.properties. If I run the app again, do I use that same db file and not ask the user which database file to use ?

Right now, I'm implementing it such that every time the app is ran in Alone mode or Server mode, it asks the user to choose a db file to use. If this is right, why would I need to save the db file path in the suncertify.properties ?

Thanks

Bao
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Simon O'Brien:
Thanks for the replies.
I was thinking of doing this but my worry was that having a getInstance(String file) would be confusing as it implies that it is possible to get another instance using a different database file.



If this method is called again, I throw a runtime exception, the method without argument must be used. I don't know how much it's a good approach however.

I personally don't like the idea of using properties to communicate this information.
[ January 08, 2008: Message edited by: Alex Belisle Turcot ]
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by bao do:
Hello,
So let's say I start up the app in "server" mode, and this server allows to choose a db file to run which I then save in my suncertify.properties. If I run the app again, do I use that same db file and not ask the user which database file to use ?



For me, I automatically populate the fields in the user interface with the data from the property file. The user is still free to select another database, but if he wishes to keep the same, he only clicks ok.

Similar to how Internet Explorer populates web pages with your username/pwd, but then you still need to click OK or can choose to enter a different user/pwd.

Regards,
Alex
[ January 08, 2008: Message edited by: Alex Belisle Turcot ]
 
bao do
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"For me, I automatically populate the fields in the user interface with the data from the property file. The user is still free to select another database, but if he wishes to keep the same, he only clicks ok."

I understand your point, but the requirement states "configuration must be persistent between runs of programs", so it seems to mean that everytime they run the app, it must uses the same db file. Your way would allow users to choose another db file which goes against the requirement. Is it not ?
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I don't agree, I use a singleton, so If I automatically open the database, it means that the user will NEVER be able to connect another database.

Unless, I guess, if the Data singleton is not linked to the database file.

Since the last used information are automatically populated, I feel it's being consistent.

What other people think ?

Regards,
Alex
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by bao do:
"the requirement states "configuration must be persistent between runs of programs", so it seems to mean that everytime they run the app, it must uses the same db file.



Doesn't it mean "everytime they run the app, what was selected as configuration in the previous run should still be in the file for the next run"? It's a bit different from what you're saying.
 
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic