Forums Register Login

Reading the name of the fields from the database.

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Good night. Drive safely. Here's a tiny ad for the road:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 756 times.
Similar Threads
What is the best way to transmit the find criteria from View to Model and to Business
Reading the record from the database
NX:[URLyBird]Read and write record with fixed size
Database Schema / Facade Interface
JLS tips
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 23:35:30.