• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URLyBird (1.3.1) Data Class - Singleton or not

 
Steve Baranski
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello - I have got the DB, server and configuration portions of the assignment squared away...working diligently on my third Swing UI ever. Every time I think I have the Data piece put to bed, something else concerns me.

As people who read the FAQ know, my version of the assignment does NOT use cookies. So I'm trying to use unique Data instances to fulfill the requirements.

Just because the instances are unique, it doesn't mean the stored data has to be. This is what I have below to suit that (NB: NIO was not forbidden in my assignment).



The problem I have is this - since Data.java (or the DBMain implementor) is supposed to be generic enough to read multiple DBs in the lovely format provided by Sun :roll: , how do I accommodate the case of multiple logical tables being read by Data...

Presumably an additional table would have a different file, and therefore a different magic cookie (metadata). Making those static seems to be a "no go" for that, since problems would arise when caching records to conserve on IO and managing locked records. I think a composite key (DB & record #) is overkill!

Am I overthinking this? Is the assignment suggestion "You may assume that at any moment, at most one program is accessing the database file" enough to surmise that only one file (i.e., a logical table in the DB) will be accessed at a given time? Then the static fields would remain consistent...

Please note that I tried to use discretion with what I've included here - it's not exactly what I have.... I would appreciate any thoughts and/or feedback.

Cheers,
Steve
 
Martin Sturzenhecker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Steve,

I don't think the magic cookie will change in the metadata. The magic cookie value identifies a file as a valid data file that adheres to the format specified in your assignment.

For this reason I assume the data file structure is the same for all data files.

You are right, the database server should support several data files, so a singleton is not the most useful here.

My db server uses a map of data instances, the keys being the data file names, the values being data instances. I think is called a "Multiton", but I'm not sure this is either the correct name nor such a pattern is widely known (a web search will yield some ruby modul).

regards,
-martin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic