Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

[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.
 
What's brown and sticky? ... a stick. Or a tiny ad.
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic