wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX:database design Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX:database design" Watch "NX:database design" New topic
Author

NX:database design

lydie prevost
Ranch Hand

Joined: Mar 14, 2002
Posts: 32
I have a few questions about my database design:
I have this in my assignmnet ( as may be everybody here).
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:

So I begin to code my class Data.java :
Data.java implements DB
The read method in DB is pubic
I created 2 read methods in Data

and
[\CODE]
private String[] readRecord(int recNo)
throws RecordNotFoundException, FileNotFoundException, IOException {
String[] record = new String[nFields];
RandomAccessFile raf = new RandomAccessFile(dbName, "r");
raf.skipBytes(offset);
......
[/CODE]

one public which has the same signature as the one in DB and which call another read ( this one PRIVATE) which is the real one which does the read ( open file, read etc...)
And I have a DataAdaptater which call

I don't understand when they say
data access class
.
Does that mean that the "real" read method ( the one which really does the work) must be public?
I Should I have just one read method in Data ( obviously public to implements the one in DB).
2) Or I could all the public read methods in the adaptater level now called Data ( which implements DB)which methods of an oter class doing the real work?
My question is where do I say implemet DB
1) at the class which is going to daccess the data
2) at the adaptater level ? But I need a class to accesss the data!
and this time it does not implement DB
I am not sure if I am very clear
- Lydie
[ March 18, 2004: Message edited by: lydie prevost ]
Satish Avadhanam
Ranch Hand

Joined: Aug 12, 2003
Posts: 697
Originally posted by lydie prevost:
I have a few questions about my database design

I could'nt see any questions
Maybe you have to post them again.
lydie prevost
Ranch Hand

Joined: Mar 14, 2002
Posts: 32
Sorry I hit the return butter too quickly
I have edited it again
- Lydie
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Lydie,
If I understand what you said you have the following:


Originally posted by lydie prevost:

I don't understand when they say "data access class."
Does that mean that the "real" read method ( the one which really does the work) must be public?
I Should I have just one read method in Data ( obviously public to implements the one in DB).

I think they mean the Data class when they say "data access class." Yes, the "real" read method must be public. When you say Data implements DB you are obligated to provide all the methods specified in the DB interface, but it in no way restricts you from adding anything you want to add to the Data class.

2) Or I could all the public read methods in the adaptater level now called Data ( which implements DB)which methods of an oter class doing the real work?

Data is your data access class, but it can delegate anything you want to any other class you want. In the same way, the public read method must do what the DB interface claims it will do (that is, it should do what the method comment in the DB interface claims it will do), but your perfectly free to delegate that work to other methods such as your doing with the readRecord method. Not only is there nothing wrong with that , in fact it is highly advisable (often it is called refactoring) as it keeps the size of the method small and results in a very focused, easily understood method.

My question is where do I say implemet DB
1) at the class which is going to daccess the data
2) at the adaptater level ? But I need a class to accesss the data!
and this time it does not implement DB
I am not sure if I am very clear

I think you need to say that the Data class implements the DB interface. The Data class is your data access class. Of course, that does not mean the Data class cannot delegate the work to another class. For instance, all database file access may actually be done in a class called DataFile. Then the Data class would use methods from DataFile to do the things it's required to do by the DB interface. By the same token, your GUI client can call whatever adapter class you want. A some point the adapter class is going to be making calls on the Data class, so you are in effect using the Data class as your data access class.


Regards, George
SCJP, SCJD, SCWCD, SCBCD
 
wood burning stoves
 
subject: NX:database design
 
Similar Threads
(B&S)My Data.java and read() !
aonther problem surprised to me
NX: used RMI & Local in local Side
NX: Exception handling implementing the DBAccess
NX:About DBMain interface