Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Database problem in URLyBird 1.2.1

 
Xin Gang Sun
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm fighting with the Data class. At first, I use DataInputStream & DataOutputStream object to access the data file.

All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.


But it has a lot of troubles such as updating the data file. I must delete the file and rebuild it frequently. It is not efficient.
Now I hava a new idea. Can I use the java.io.RandomAccessFile object according to Sun's requirement?
Or anyone has a better idea to implement it?
 
Tahir Abbas
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I also used java.io.RandomAccessFile to deal with the database. In database first there is information about database e.g; magic cookie value, number of fields etc then the record data in database starts. Data file section in instruction file will be very useful for dealing with database. If you search on this forum you'll get many useful threads regarding your problem.
 
Xin Gang Sun
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! Using RandomAccessFile make the code clear. I can just apply my mind to the concurrency.
 
Anne Crace
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can just apply my mind to the concurrency.

Hello Xin,

I wouldn't worry about concurrency at this time. That is usually one of the last things you will do. Deal with reading the database first. You can use a synchronized block for your reads and writes but this is something that can easily be added later when you deal with locking. You need to do a little more than add a synchronized block to accomplish the locking, though! Lots of good information on this forum to help you with that when the time comes!
 
Georgiana Lungu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have seen this post and is targeting one of my actual problems too. So, my question is, may I use RandomAccessFile although my specification states:
"All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII. " ?
 
Roberto Perillo
Bartender
Posts: 2271
3
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Georgiana Lungu wrote:So, my question is, may I use RandomAccessFile...


Oh yes, absolutely. If you look at the RandomAccessFile API, you can verify that it implements DataInput and DataOutput interfaces, so it can be used to deal with the database file.
 
Georgiana Lungu
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, thank you for fast answer
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic