• 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

How to set database file's name into a singleton Data class.

 
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all.
My Data class is a singleton, there is a private constructor with one parameter and getInstance() method as following code:



In Sun's instructions, a user can put a database file's name via a GUI. When my application gets the database name, how can I push it into Data class, because my constructor can not be invoked direcly.

Thank you.
Surasak Lee
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An idea would be to always read the properties from the suncertify.properties file for your Data class to find the database.

UI updates the properties file and then the data class is constructed from the properties file.

I don't know if this will help you but it's an idea =)

Perogi.
 
Surasak Leenapongpanit
Ranch Hand
Posts: 341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please anyone help me.

Surasak Lee
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Surasak,

Perogi gave a good solution. Instead of just asking for more help, perhaps you could say what you see as being wrong with the solution given?

Alternative: have a setter method which sets the database name. Any attempts to get the instance of your Data class before the name is set will fail (with a suitable exception).

Another alternative: have the filename passed in as a parameter of the get instance method. That will have the added benefit of making it easy to change your Data class to a Multiton (instead of a Singleton) later.

Regards, Andrew
reply
    Bookmark Topic Watch Topic
  • New Topic