GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Reading the name of the fields from the database. 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 "Reading the name of the fields from the database." Watch "Reading the name of the fields from the database." New topic
Author

Reading the name of the fields from the database.

Olena Golub
Ranch Hand

Joined: Jan 17, 2005
Posts: 113
Hello Everyone,

In my design there is one DataShema class, that contains the information and the structure of the database file. I read the database schema, the name of every field in the database during the initialisation of the DataShema class. This class is the Singleton.
It contains one static method:


My interface that specified all methods that will be remotely called by the client contains one method, that returns an array of the name for every field:


All business logic is implemented in the DataAdaptor class. This class implements the getHeaderNames():


I didn�t throw any exceptions during the call of the getHeaderNames, any IOException, because the names will be read only ones during the Initialisation. How do you think is this a good design? Or should I read the fields� names every time when I call the DataShema.getFieldsName() method?
Thanks a lot for your comments and help!
Regards,
Olena.


SCJP 1.4<br />SCJD 1.4 (in progress)
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11465
    
  94

Hi Olena
I didn’t throw any exceptions during the call of the getHeaderNames, any IOException, because the names will be read only ones during the Initialisation. How do you think is this a good design? Or should I read the fields’ names every time when I call the DataShema.getFieldsName() method?
My questions to you (which I suspect you already know the answer to) are: when can the field names change? and/or do you have any methods which will allow the field names to be changed.

If the field names cannot be changed, then it seems to be more efficient to cache them (as you are doing) rather than re-reading them each time someone calls the getFieldsName() method.

Just my opinion of course.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Olena,Andrew

I have also a DataScheme implementation.Here I read the file header on initialization(read in the contructor) and if there are problems(the file has a wrong cookie or its schema can not be interpret it) some exception raises.
For the rest I cache the scheme information because this are often used datas(and are not so big).
Now about the exception and the constructor - I know this is not a good technique but it keeps the code simple.Like alternative I can use an init method(and raise all the exception here) but I still think about.

If your DataScheme is a singleton and you access it via one of its "global point of access to it" can you change the scheme runtime ?
Let's say that you use data base A (with scheme A) and you try to change the database B (with scheme B, A != B).If your scheme is a singleton (only one instance) you can not use the database B - or you must create a singleton every time when you "choose" the database file.


Regards, Mihai


SCJP, SCJD, SCWCD, OCPJBCD
 
GeeCON Prague 2014
 
subject: Reading the name of the fields from the database.