File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Reusing the record number

 
Marc Marechal
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am doing B&S.
My delete method is :



I use the physical record numbers as the indexes of the records in the database file.
I would like to use logical record numbers associated to the physical record numbers, and only use the logical record numbers in the DBAccess interface.
The logical record numbers will be unique, never reused, automatically generated.
So in this case, the recNo parameter is a logical record number which will not be reused, but I will reuse the physical record number, in association with a new logical record number.
But I wonder if this violate the "making the record number and associated disk storage available for reuse."

Thanks,
Marc
 
Kevin Florish
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,

My intepretation of this part of the spec is as follows:

Contractor name and location are unique, so after a record has had the deletion flag set to 1, its still possible that a user of the system may wish to book this record, ie reuse it via a create.

 
mohamed sulibi
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

the implementation of delete or create is database wise not business wise so when we implement these methods we must not consider any business wise cases, and i don't know where you will save the logical record number, keep in mined you must not alter or add any column to existing database schema.


best regards.
Mohamed darim.
 
Marc Marechal
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your answers.

Kevin,
I think that when a record is marked as deleted, by its flag, it is available for reuse and will be overwritten when needed. So you can not think that it can be "undeleted" by changing its flag to available, since it could have been overriwritten in the meantime. And also it is your interpretation that name + location is a primary key for a record, but I have see it nowhere in the specification document.

Mohamed,
I intend not to alter the database format. The physical record numbers are the indexes of the records in the database file, and the logical record numbers will be stored in a map, in association with the physical record numbers. This map will be part of a Singleton class.

But my real question is :

In the Data interface, in the methods where the recNo parameter is used, I intend to use a logical record number in place of the physical record number. The logical record number will not be reused, but I will reuse the physical record number, in association with a new logical record number.

But in the specification document :

So in this case, the recNo parameter is a logical record number which will not be reused, but I will reuse the physical record number, in association with a new logical record number.
But I wonder if this violate the "making the record number [...] available for reuse", and thus, does this will give me an automatic failure ?

Thanks,
Marc
SCJP 5.0, SCBCD 5.0
 
mohamed sulibi
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

I would ask you a question where you want to save the logical record number when you save the record in the physical file.

regards.
 
Kevin Florish
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My reply was with regards to B&S assignment, forgot to menti0on that

Kevin,
I think that when a record is marked as deleted, by its flag, it is available for reuse and will be overwritten when needed. So you can not think that it can be "undeleted" by changing its flag to available, since it could have been overriwritten in the meantime. And also it is your interpretation that name + location is a primary key for a record, but I have see it nowhere in the specification document.


The record still exists whatever the deletion flag is set or not (we never actually delete any physical records). I refer to reuse as in the following case:

1) A user has deleted the record (deletion flag set to 1).
2) Another user creates a record with the same contractor name and location as 1 exising on the file with deletion flag set to deleted. In this scenario my understanding is that we reuse the record and reset the deletion flag, so it is visible in GUI etc.
 
Marc Marechal
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Mohamed,
I will save the logical record numbers in a map, the map itself being in a singleton class. I will not write the logical record numbers in any file.
But I just want an opinion wether or not my design should give me an automatic failure.

Thanks,
Marc
SCJP 5.0, SCBCD 5.0
 
Kevin Florish
Ranch Hand
Posts: 181
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally I am using a cached list of record numbers for faster access to the database although this is not required for the assignment.

I then use the record number from this list to lock on a map of contractors.

I then use the locked map to sync and update the actual physical file when required.
 
Ulises Pulido
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I am doing is to create a Queue containing all the deleted rows found in the file, this Queue is filled the first time when the class is getting loaded (using a private static method), when creating a file if the Queue is not empty I poll the row and create the new row using the value "polled" (Don't know if that word even exists) if there are no values I write the row at the end of the file, when deleting I push the value of the row getting deleted to the Queue this allows me to use it when creating a new record.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

actually i don't understand your design, but in any case if there are just one-to-one relation between physical and logical record number and also this relation exist during the run of the application and updated every time you add or delete or update any records and these logical record number will not effect any out side class using your class, i think in my opinion it is fine.

keep in mind the following statement "use of functionality provided by the core Java classes will be perferred to your own implementation of that functionality, unless there is a specific advantage to providing your own implementation".

so if you can implements your code in a way that is clear and will be readily understood by junior programmers, i think your implementation is fine and good,

by the way i don't understand your design and i am not a junior programmer.

regards.
 
Ulises Pulido
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohamed sulibi wrote:hi;

actually i don't understand your design, but in any case if there are just one-to-one relation between physical and logical record number and also this relation exist during the run of the application and updated every time you add or delete or update any records and these logical record number will not effect any out side class using your class, i think in my opinion it is fine.

keep in mind the following statement "use of functionality provided by the core Java classes will be perferred to your own implementation of that functionality, unless there is a specific advantage to providing your own implementation".

so if you can implements your code in a way that is clear and will be readily understood by junior programmers, i think your implementation is fine and good,

by the way i don't understand your design and i am not a junior programmer.

regards.


Ok what I used is one of the Java Classes



In a method that I named initializeCache that will only run once I search through the file looking for deleted and not deleted rows


With this I have my cached all the deleted and non-deleted records in their respective Object.

Now when creating a new record I call this method to get the physical record position



Where recordPosition returns the physical position on the file according to the logical record.

And finally when I delete a record I add that record number to the Queue
 
Marc Marechal
Greenhorn
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Mohamed,
In the specification document, in the methods of the Data interface, a parameter recNo is used.
But specifically in the Data#delete method :

Until now I have used the index of the record in the database file as the record number, the recNo parameter.
Then, when I delete a record, I mark the record as deleted in the database file, and I respect the required behavior :

But I would like to add a level of indirection : using a 'logical' record number associated with each 'physical' record number, aka the index of the record in the database file.
By using logical record indexes, when I delete a record, I use the logical record number as a key to find the physical record number. I mark the record as deleted in the database file, and I delete the mapping {logical record number, physical record number}.
All the logical record numbers I will use will be unique.
The logical record numbers will be the value given to the recNo parameters in the Data interface.
In this case, I wonder if the required behavior will be respected :

since I will never reuse the logical record number, the recNo parameter.
But I will make the physical record number, aka the index in the database file, of the deleted record available for reuse.

The real usefulness of this design is that I will update the logical record number when I will update a record.
The network clients having an old, invalid logical record number for a record will receive a RNFE if this network client try to update a record with this invalid logical record number.
Thus this will free me of updates crunch by multiple clients.

Since in the specification document it is stated :

Any methods that throw RecordNotFoundException should do so if a specified record does not exist or is marked as deleted in the database file

I suppose I am allowed to use RNFE for other purposes.

My asking is not if this will work or not, or how to do it, but your opinion : by not reusing the value of the recNo param associated with the record to delete in the

am I breaking the requirements in using such a design, and thus, does this will give me an automatic failure ?

I suppose I respect the requirements, since I make the deleted record and the physical record number available for reuse, but I am not sure of it.
 
mohamed sulibi
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi;

By using logical record indexes, when I delete a record, I use the logical record number as a key to find the physical record number


as i know you can find the location of the physical record number in simple math calculation ex : (( recNo * sizeOfRecord ) + startOfDataSection) = record position.

but if your implementation add cache to your data i will appreciate it

regards.
 
Liviu Carausu
Ranch Hand
Posts: 159
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marc,
can I ask you why do you want another level of indirection and do not use straight physical record numbers ?
It only makes your design more complicated....

Thanks,
Liviu
 
Marc Maréchal
Greenhorn
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liviu,

As I stated above, it is for the network client to know that they try to update or delete an already updated or deleted record. Thus in this case I would send a RecordNotFoundException, since the logical record number the client have for the record is no more associated with a physical record.

Marc
SCJP 5.0, SCBCD 5.0
 
Alecsandru Cocarla
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. I don't see why an already updated record could not be updated again. It's contrary to what a real database allows. And this is one of the main purposes of a database.

2. I did not follow your entire design, but I think, if you still want to use these logical recNos - can you think of any way of using these numbers in your business layer instead of database access? This way you could be sure that you don't brake the specified interface's contract.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic