• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data layer design.

 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Analysing the DB Interface (I have URLBird 1.1.3) I was confused about the recNo and where to store it. I decided to implement it with caching and I would like to discuss this:

1. I have Data class that implements DB interface.

2. Then I have a DataSchema class. It reads my database file with RandomAccessFile, checks the magic cookies and reads all information from start of file and Schema descriptions.

3. I have a class Record represents one booking records. I will save here the recNo.

4. I have also one class Database. This class will initialize DataSchema and with some information from DataSchema all records will be read from the database file with RandomAccessFile and for all records set the recNo, and will cache all record (Record) in ArrayList (private static).

The Database will be saved in the Data (private static) and Data will work with it. By updating of one record the ArrayList from the Database and the database file will be updated.

How do you think is it a good way to have one extra class (Database) to save all information from the database file. Or should I cache the record in Data ?

What do you think about it?
Thanks for your help and advices.
Lena
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Lena! Good to see a compatriot taking the exam.

----

Analysing the DB Interface (I have URLBird 1.1.3) I was confused about the recNo and where to store it. I decided to implement it with caching and I would like to discuss this:

1. I have Data class that implements DB interface.

----

That's the required Data class. Not much to be changed there. However, should you need to extend the DB interface to implement an extra method, it turns out it is allowed.

----

2. Then I have a DataSchema class. It reads my database file with RandomAccessFile, checks the magic cookies and reads all information from start of file and Schema descriptions.

----

That's exactly the way I implemented mine, also. It is good and not overly complex.

----

3. I have a class Record represents one booking records. I will save here the recNo.

----

This in my view is overdoing the requirements; sufficient is the Map of recNo's and record String[]'s for your data transport, and an ArrayList with sequential record String[]'s (null denoting a deleted record) to map to the database file.

----

4. I have also one class Database. This class will initialize DataSchema and with some information from DataSchema all records will be read from the database file with RandomAccessFile and for all records set the recNo, and will cache all record (Record) in ArrayList (private static).

----

Sounds good. This will allow you to handle changes in the database file (when the client will select a different one) better than if keeping all the data in the Data class.

----


The Database will be saved in the Data (private static) and Data will work with it. By updating of one record the ArrayList from the Database and the database file will be updated.

----

This is also a good consideration for the extra class, in my view.

----

How do you think is it a good way to have one extra class (Database) to save all information from the database file. Or should I cache the record in Data ?

----

I think that keeping it as simple as possible is the key. It does not necessarily mean as few classes as possible, because sometimes it is simpler to have an extra class with clearly defined functionality than to put all the functionality into the Data class.


What do you think about it?
Thanks for your help and advices.

----

I think this is a good idea.
[ February 21, 2005: Message edited by: Anton Golovin ]
 
dennis du
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-------------------------------------------------------------------------
How do you think is it a good way to have one extra class (Database) to save all information from the database file. Or should I cache the record in Data ?
-------------------------------------------------------------------------
Except this and the recNO,my structure is the same as yours.

I implements your database class in Data class.
And I save the recNo in ArrayList(cache) not in Record class.

That's all!
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Anton,
Thanks a lot for your replay. I am very happy to see a compatriot too!

This in my view is overdoing the requirements; sufficient is the Map of recNo's and record String[]'s for your data transport, and an ArrayList with sequential record String[]'s (null denoting a deleted record) to map to the database file.


As I understand you correctly you create one Map with recNo as a key and a String array with records information as value. Than you created one ArrayList where you save all this String arrays.
Is ArrayList a cache for your database file?
But I couldn�t understand how do you map these two storages?
Do you use the values from Map or from ArrayList to display the information in your JTable? And then if the CSR select one record in the table how do you find the record number from your Map?
Sorry for my curiosity
And "ogromnoje spasibo" (engl: Thank you very much)!
 
Olena Golub
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dennis,

Thanks you for your reply.
And I save the recNo in ArrayList(cache) not in Record class.

Do you save in ArrayList only recNo? Or how do you map it with your records from the table?
 
joe lin
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Olena,
And then if the CSR select one record in the table how do you find the record number from your Map?


i think you can also send the record number to the CSR,then when the CSR select one record ,he/she will send back the record number to you,so you
can find the record number from your map.does it right?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic