Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Gaps in JTable for deleted records?

 
Bably Das
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Roel De Nijs
Sheriff
Posts: 10603
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
Matthew Workman
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think your database should return deleted records.
 
Bably Das
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10603
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10603
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 71
Eclipse IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Bably Das
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 10603
143
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic