aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Reusing the record number 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 "Reusing the record number" Watch "Reusing the record number" New topic
Author

Reusing the record number

Marc Marechal
Greenhorn

Joined: Apr 15, 2005
Posts: 17
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

Joined: Jan 06, 2009
Posts: 175
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.


Java5 Tutorials | Java6 Tutorials | HTML/CSS Tutorials | JavaScript and jQuery Tutorials
mohamed sulibi
Ranch Hand

Joined: Sep 04, 2005
Posts: 169
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

Joined: Apr 15, 2005
Posts: 17
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

Joined: Sep 04, 2005
Posts: 169
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

Joined: Jan 06, 2009
Posts: 175
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

Joined: Apr 15, 2005
Posts: 17
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

Joined: Jan 06, 2009
Posts: 175
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

Joined: Jul 24, 2008
Posts: 81
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.


SCJP 5.0, SCWCD 5.0, SCBCD 5.0, SCJD, SCEA in progress
www.ulisespulido.com
mohamed sulibi
Ranch Hand

Joined: Sep 04, 2005
Posts: 169
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

Joined: Jul 24, 2008
Posts: 81
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

Joined: Apr 15, 2005
Posts: 17
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

Joined: Sep 04, 2005
Posts: 169
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

Joined: Oct 07, 2004
Posts: 158
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


Oracle Certified Master Java SE6 Developer(SCJD),
OCE JEE 6 JSP and Servlets Developer.
Marc Maréchal
Greenhorn

Joined: Jan 08, 2005
Posts: 10
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


Marc Marechal
MCSE, CCNP, SCJP 5.0, SCBCD 5.0 (Beta), SCJD 6.0
Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Posts: 158
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.


SCJP 1.4 100%
SCJD 99.5%
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reusing the record number