This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
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

some questions regarding database?

 
s yucel
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
my assignment is going well. Bu some db points are confusing me.

1- In networked and standalone mode, the db file will be accessed. But in the assingment, there is not any clue about where this db file will reside?
I just wonder if it is under the working directory like properties file?
I assume the working directory is where we run the program using java.

2- I am using singleton pattern for Data.java, as the assignment says only one program will be accessing it. Am I right?

3- In the db interface, there is a cookie whic is generated by the lock method. How is this number generated?
And when updating a record, I should send the cookie parameter which was generated by the lock of the atomic operation?

4- My assignment shows the database file schema. I know how to use the data section as I will be playing on this section. But what about the first two section? I just wonder if I should use the two sections as well. If so how should I use them? The schema is as follows:

Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record

Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block

Data section.
Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information

End of file

any idea is highly appreciated.

Kind regards,

syucel
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
1- In networked and standalone mode, the db file will be accessed. But in the assingment, there is not any clue about where this db file will reside?
Correct. So you will have to provide some way for the user to tell the program where the db file is located. JFileChooser might help you.

I assume the working directory is where we run the program using java.
Correct. But this does not have to be the directory where the jar file is, nor does it have to be the directory where the db file is. They could both be in entirely different directories.

2- I am using singleton pattern for Data.java, as the assignment says only one program will be accessing it. Am I right?
I think you will find that the assignment says that only one program will be accessing the db file. This is a totally seperate issue from whether the Data class (or any other class) should be a singleton. My personal belief is that the Data class is not a good candidate for the singleton pattern, however due to the number of questions in this thread I wont discuss it here - perhaps you could open a separate thread to discuss just that item.

3- In the db interface, there is a cookie whic is generated by the lock method. How is this number generated?
How would you like it to be generated? What do you want your cookie to be - some number that is tied to the record (useful in debugging)? Or some number that is totally random (more secure)? Or some combination? Again, this is worth having a topic all on its own.

And when updating a record, I should send the cookie parameter which was generated by the lock of the atomic operation?
Yep.

4- My assignment shows the database file schema. I know how to use the data section as I will be playing on this section. But what about the first two section? I just wonder if I should use the two sections as well. If so how should I use them?
The fact that the meta-data and the schema exist is a good reason not to use the singleton pattern - can you think why this might be?

You probably want to use the magic cookie to verify that the file you are trying to read is indeed a data file.

You probably want to use the meta-data to read the schema and then use the schema to read the records. This is a better idea than hard coding the values for length of fields etc.

You might decide to store the schema and provide it to users of the Data class on request.

Regards, Andrew
 
hassan kalaldeh
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there ,


quote:
--------------------------------------------------------------------------------
3- In the db interface, there is a cookie whic is generated by the lock method. How is this number generated?
--------------------------------------------------------------------------------

How would you like it to be generated? What do you want your cookie to be - some number that is tied to the record (useful in debugging)? Or some number that is totally random (more secure)? Or some combination? Again, this is worth having a topic all on its own.


as for lock cookie , can u consider record number to be the cookie returned from Lock method ??

and by doing this , it will be easy to get a lock for that record
so guys , what do you think ??

Best Regards
Kalaldeh
 
Martin Sturzenhecker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi hassan,

as for lock cookie , can u consider record number to be the cookie returned from Lock method ??

and by doing this , it will be easy to get a lock for that record
so guys , what do you think ??


I do not think this is a good way to go, since an "evil" client using your database may try to guess lockIDs. A pattern like lockID = recordID will easily be guessed.

So while it is - of course - a valid choice, it quite obviously is not a secure (in the sense of not easy to guess) one.

martin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic