aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes about B&S database file 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 "about B&S database file" Watch "about B&S database file" New topic
Author

about B&S database file

Jimmy Chen
Ranch Hand

Joined: Apr 11, 2005
Posts: 54
I'm just going on with my assigment.I have a question about the database.

In B&S project, all date is recorded in a ".db" file.

I'm just wondering, do I need to read out all the records from the database file and save it in a vector when the program is running? Or access the database file each time when I want to read/write/update the record?

I think everytime when I want to save the record to database file, I have to rewrite the whole database file.So, when the program is running, I should keep all records and their status in a collection(e.g. vector) until I want to save them. Is it reasonable?

thanks in advance!
Surya De
Greenhorn

Joined: Nov 06, 2005
Posts: 28
Hello Yu,

I faced a similar question as well and my take on this topic is this...that you should read and store the data in a collection, easier to creat your tablemodel, etc etc from there. And also consider that when you implement RMI or Sockets to simulate the networking part of your assignment, the thing to consider is that it would be requiring a huge overhead if you were writing reading updating to and from the network connection all the time unless you just have one collection object like a cache that stores all the records that you can then manipulate and so on.

However while on this topic, for example the read method which reads a specified record from the db file how are we to prove to the examiner that the method is in fact actually reading the specified record from the file and not from the collection cache itself? I am kind of confused. I dont know how to address this problem.

Surya
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Yu,
I'm just wondering, do I need to read out all the records from the database file and save it in a [collection] when the program is running? Or access the database file each time when I want to read/write/update the record?
You can do either - I have seen candidates get excellent scores using either option. If you search in this forum for "database cache" you will find many discussions on caching data.

I think everytime when I want to save the record to database file, I have to rewrite the whole database file.
Have you looked at the java.io.RandomAccessFile can do for you?

You mentioned Vectors twice in your original posting. Vectors are EVIL (well, perhaps that is a bit strong, but I have to say that in case Jim Yingst is listening ). Seriously though, I don't think Vectors should be used normally. Vectors are synchronized collections, and unless you actually want that synchronized behaviour, you will get a performance loss by using them. Even if you do want that synchronized behaviour, I would still stay clear of Vectors, simply because the next person to review your code (the assessor in this code) will be second guessing whether you really wanted a synchronized collection or whether you grabbed the wrong collection. Now you can make that explicit by writing implementation comments next to your definition of the collection, or (IMHO) you could rethink what sort of a collection you want, then use the synchronizedXxxx method of java.util.Collections to make it explicit in the code that the collection should be synchronized. For example, if you wanted to use a synchronized Map, you could call the java.util.Collections.synchronizedMap(Map<K,V> m) method to give you a synchronized Map.

Regards, Andrew


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

Joined: Apr 11, 2005
Posts: 54
Thanks very much Surya and Andrew.

Your answers are really very helpful to me!

Andrew, I still have one question to make sure
As your said I can select accessing the database file each time when I want to read/write/update the record without any cache(collection)?
woo sung
Greenhorn

Joined: Dec 09, 2005
Posts: 6
Hi. andrew.
First of all, i am not English speaker. I might make many miskates in wirting. sorry.
secondly, I am reading your great book and analysing code in db package.
It is bit hard to understand cleary beause of my lack of ability of english and java skill.

my question is that
In your book, DvdFileAccess is degined as singlton. when it created, getDvdlist(true) is called to store all Dvd data in List<DVD>.

and persisteDvd method is called when addDvd and modifyDvd is called.

In persistedDvd method, Is .db file changed? or is List<DVD> changed? or both.

If my program stored all Dvd data in List<DVD> and I changed data in that, when should i change the .db file? (i.e when server is down or as soon as possible when data is changed)
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hi woo,

i think it's a better idea if you start your question in an own thread... that's so much easier for the people reading it ;-)

many greetings,
jan
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Yu,
As your said I can select accessing the database file each time when I want to read/write/update the record without any cache(collection)?
Sorry for the delay in responding, I have been down at the beach with no internet acccess for the past few days. But to answer your question, it is up to you.

You can write your program without any cache. In this case you would have to access the physical file for every read and write of a record.

Alternatively, you can write your program to make use of a cache, in which case any reads and searches would only need to access the cache - you would only need to access the physical file for write operations (create & update).

Regards, Andrew
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11525
    
100

Hi Woo,
First of all, i am not English speaker. I might make many miskates in wirting. sorry.
No problems - glad to have you with us.
my question is that
In your book, DvdFileAccess is degined as singlton. when it created, getDvdlist(true) is called to store all Dvd data in List<DVD>.

and persisteDvd method is called when addDvd and modifyDvd is called.

In persistedDvd method, Is .db file changed? or is List<DVD> changed? or both.
We don't implement a cache of records in our project - what we have is a cache of record keys (the UPC numbers) and their location in the file. This cache of keys is only updated whenever a record is created or deleted.

For any change to the data (create / update / delete) we update the db file.

If we had implemented a cache, then both the file and the cache have to be updated on any change to the data. The find(), getDvd() and getDvds() methods would all retrieve data from the cache, so the cache would have to be updated. However we would want to ensure that we do not loose data if the system were to crash, so the db file would also be updated.

If my program stored all Dvd data in List<DVD> and I changed data in that, when should i change the .db file? (i.e when server is down or as soon as possible when data is changed)
I would recommend updating the data file at the time the record is changed - see my earlier comments on why this is.

Regards, Andrew
Jimmy Chen
Ranch Hand

Joined: Apr 11, 2005
Posts: 54
hi Andrew, you are really a warmhearted saver!

I got it and I will not be hesitated to give your more questions

thanks again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: about B&S database file