wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Gaps in JTable for deleted records? 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 "Gaps in JTable for deleted records?" Watch "Gaps in JTable for deleted records?" New topic
Author

Gaps in JTable for deleted records?

Bably Das
Greenhorn

Joined: Sep 17, 2009
Posts: 28
Hello,

I just wanted to confirm if its alright to have gaps in the JTable for deleted records?

For eg, there might be a situation where I have in my map record with recordNos 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9 (Size is 10, starting with a zero "0" index)
and records 3, 5, and 7 have been deleted, therefore in the JTable only 7 records 0, 1, 2, 4, 6, 8, 9, will be displayed.

So in my case there is gap for the other records as in my cache I am making the Room object null and while writing back the deleted record to the database file I am filling the fields with spaces equal to field length apart from setting the flag to that of deleted. Is this alright?

Thanks
Bably Das


SCJP 1.5, SCJD (URLyBird 1.3.2)
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

How can a deleted record be in your JTable? When a record doesn't match the criteria its record number should not be returned in the array of matching records. So how can you have gaps at the client.

Your approach on the server, setting a Room object to null when deleted and writing all spaces with deleted flag set to true, is the one I used too (although i used a String[] instead of a Room object, because using a String[] makes my Data class more reusable)


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Matthew Workman
Greenhorn

Joined: Jul 01, 2010
Posts: 7
I don't think your database should return deleted records.
Bably Das
Greenhorn

Joined: Sep 17, 2009
Posts: 28
Thanks I have solved the problem by doing an additional check for spaces in all fields of a Room object apart from doing a check on it being a null object.
Simple JUnits were enough to solve the problem. I am sticking with a Room object as I find it easier to work with. Have justified about it in choices.txt, so I think that should be fine.

Cheers,
Bably Das
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

Bably Das wrote:doing an additional check for spaces in all fields of a Room object apart from doing a check on it being a null object.

How can a null object have spaces in all fields?
Bably Das
Greenhorn

Joined: Sep 17, 2009
Posts: 28
How can a null object have spaces in all fields?


This is exactly what I am doing -
While deleting a record in my Data class, I set the Room object to be null. While writing back the deleted record to the .db file in my DBFileAccess class, I write the length of the bytes for each field


After writing the bytes I again set the Room object back to null in the DBFileAccess class as I found out after I write the bytes the Room object is no longer null but has spaces for all the fields, hence I cannot reuse the recNo for creating a new record. Setting the Room object back to null makes it possible to reuse recordNos and while viewing a deleted record in the JTable I found that it contained spaces, hence the check on spaces.

I am really confused now as I thought I was doing the right thing

Thanks,
Bably Das


Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

I simply don't get how a room object that's null (because it is deleted) can contain all spaces for every field when you just write some spaces to the file
Allan Cheong
Ranch Hand

Joined: Nov 12, 2009
Posts: 71

My program writes directly to database file. If record flag is valid (not deleted), it will be retrieved. If it is deleted byte in flag bytes, it will not be retrieved. My delete method just writes the deleted bytes into the flag area.

HTH


SCJP6, SCJD, OCJWCD5
Bably Das
Greenhorn

Joined: Sep 17, 2009
Posts: 28
Thanks all for your replies.
I fixed the issue but realised that I had not posted back.
So a null Room object denotes a deleted a record in my cache. I write the deleted record with spaces for all its fields and the deleted flag set as I am reusing the deleted recNo to create a new record and needed a way to persist the deleted record back to the file.
While reading the database file I am converting the database record to a Room object as I prefer working with a Room object, I check for the valid/deleted flags and if a deleted record is found, it is just added to the cache as a null Room object. This way I no longer have spaces for a null Room object which was actually my mistake in implementation. Now I always have valid records in my business and GUI layer and hence no more gaps in the JTable.
I hope this approach is valid.

Regards,
Bably Das
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5131
    
  12

Bably Das wrote:This way I no longer have spaces for a null Room object which was actually my mistake in implementation. Now I always have valid records in my business and GUI layer and hence no more gaps in the JTable.
I hope this approach is valid.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Gaps in JTable for deleted records?
 
Similar Threads
Updating duplicate rows
Something i'm extremely confused on
URLyBird GUI MVC <-> Business Layer in a Thin Client and HashMap vs. ArrayList
JTable-Getting Data out to db
Problem with JTable