Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: URLyBird: how to start with data access

 
Hans ter Wal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My first time in this forum howdy all!!
I've just started with my 1.2.3 version of the URLyBIRD assignment. I've started reading the forum for hints tips an ideas. But there are so many things to concider, I'm almost afraid of starting of the wrong way, but today I finally opened eclipse and started with the data access layer.
I'm just putting the data access in one class right now, till it works and refactoring it as i go along.
What I was thinking was that the "server"controller class, creates one instance of the Data class. The constructor of the Data-Class opens a RA file object for file access. (and somewhere the server class calls a close for the RA file object)
What i'm still not certain of is how to access the data section of the data file.
First of you have to get to the data section of the db.file
What would be the correct way?
1.

or...
2.


I've someone could give me a push in the right direction,

Regards,
Hans
[Andrew: broke up long lines so that this displays without requiring horizontal scrolling]
[ November 13, 2003: Message edited by: Andrew Monkhouse ]
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Hans,
Welcome to JavaRanch.
Personal thoughts: your first solution is not very extensible if you ever need to add an extra field, or change the size of a field (or even work with a totally different database that has the same meta schema). In that respect, your second solution is much better.
But I would probably only want to read the schema once - once you have read it the first time, you can store the size of the schema and then just skip it for future reads.
I would also consider refactoring your two constructors - one could call the other. It won't make much difference with what you have now, but it might make a difference if you want to do much more in the constructors.
Regards, Andrew
 
Hans ter Wal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Thanx welcome and the reply.
I went for option 2
Regards,
Hans
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, if you Data class performs a lot of other operations such as locking,
unlocking, deletes, search, find,....You may want a helper class to perform
all of the actual opening, and reading of the DB file. Then have
a variable in the Data class that refers to your helper class. Your Data
class can still write to the DB file but it gets an instance of the DB file
from the helper. When the Data class needs all of the records, it asks
the helper class, when it needs to know the length of a field it asks the helper class...and so on. Your helper class will more than likely be a singleton because I am assuming your assignment deals with only one file
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic