Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

[B&S]: Using a Singleton class to represent the file resource

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello fellow ranchers

I was hoping for some feedback on part of my design for the B&S project.

I'm aiming to create a singleton class to represent the file itself. I understand I must create a class sunceritfy.db.Data which implements suncertify.db.DBAccess. However, I want to have some sort of object representation of the file itself. In addition, I don't want to reopen and close the file for every Data instance. The name for this singleton is class ContractorDB.

Here's the main jist of what I am currently implementing:



Multiple instances of Data will be invoked, so I figured having a singleton resource will best suit my needs. As for record locking, I will have a static Vector used to keeps track of the locked Contractor records (no, I wouldn't lock the entire DB!).

Again, any feedback or questions would be appreciated.

Thank you!
[ December 26, 2004: Message edited by: Vincent Hernandez ]
 
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Vincent Hernandez:
Hello fellow ranchers

I was hoping for some feedback on part of my design for the B&S project.

I'm aiming to create a singleton class to represent the file itself. I understand I must create a class sunceritfy.db.Data which implements suncertify.db.DBAccess. However, I want to have some sort of object representation of the file itself. In addition, I don't want to reopen and close the file for every Data instance. The name for this singleton is class ContractorDB.

Here's the main jist of what I am currently implementing:



Multiple instances of Data will be invoked, so I figured having a singleton resource will best suit my needs. As for record locking, I will have a static Vector used to keeps track of the locked Contractor records (no, I wouldn't lock the entire DB!).

Again, any feedback or questions would be appreciated.

Thank you!

[ December 26, 2004: Message edited by: Vincent Hernandez ]



You're on the right track. The database table needs to be represented as a single object and will need to be thread safe. For this purpose you will need to synchronize on the file for short periods when doing a read or write. You will also need to provide the longer lived record locking that's specified in the requirements. The record locking is probably easier to implement if you use a HashMap rather than a Vector. The HashMap isn't synchronized, so you can control the synchronization yourself and the Map interface allows you to use the record number as a key.

I use a singleton for the database and multiple instances of the Data class to represent client access. There has been discussion of using a multiton for the database, but I believe this is unnecessarily complicated as there is only a single table required by this project.
reply
    Bookmark Topic Watch Topic
  • New Topic