• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

About parameter recNo in the assignment interface.

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all, I've implemented the DBAccess interface for a long time. May I ask a very silly question: what is the parameter recNo meaning in the DBAccess interface ?

1. The record's location in the db file. (I chose this to implement the DBAccess. Am I wrong?)
2. The order of the record in the db file.
3. Others?

Regards,

Pkinuk


 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

1. The record's location in the db file. (I chose this to implement the DBAccess. Am I wrong?)



I don't think you are wrong because I chose the same approach. Essentially, every time I come across a
record in the database file, I assign it a record number in my cache, and I store the record information.

2. The order of the record in the db file.



I'm not quite sure what you mean by this. If you are talking a sequential order, isn't this the same as option 1?

3. Others?



I'm not aware of any others, but if some developers found different ways to handling records, I'd like to see
their approach, but I think almost everyone will use approach 1.


Vlad
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pkinuk,

I just used 0, 1, 2,... as record numbers (because in the Java world almost everything is 0-based, I decided to start the record numbers also from 0).

So if you want to lock the 5th record (in the database file), you just call lock(4);

I wouldn't use the record's location in the database file (the offset in bytes: record 1 = 250, record 2 = 350, record 3 = 450, ...), because that is not really intuitive: if you call lock(250), it seems you are locking record 250 (or 251), but you are locking record x at an offset of 250 bytes

Maybe you can keep a close look on this thread as well, because it also handles about record numbers (and what to use).

Kind regards,
Roel
 
pkinuk Buler
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel De Nijs ,

I've decided to change the recNo to the sequence order number, the first record stats from 0, second is 1 and so on...
I've also caching the db file into a HashMap, and this procedure will only be run once when the Server starts successfully. Every time the user alters the record througth JTable will only modify the contents in the HashMap.

My question is: When can I save the contents stored in the HashMap into back to the db file? I know it will happen when the server is closed, but i don't know how to do it. Is it done by implementing a server close listener? I used RMI method.

Thank you in advance.
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi pkinuk,

I suggest you'll search the forum using "shutdown hook", "addShutdownHook",... It will give you a lot of inspiration

Kind regards,
Roel
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic