• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to lock the whole database file?

 
Alberto Ivo
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In the interface provided by Sun, I have the methods:

void lock (int recNo)
unlock(int recNo)
isLocked(int recNo)

This is for lock just 1 record, nothing more.. but how can I lock the whole database so I can shutdown app without any problems?

thanks very much!!!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alberto,

In this thread you find some suggestions for your problem

Kind regards,
Roel
 
Alberto Ivo
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks!!!
 
Paul Anilprem
Enthuware Software Support
Ranch Hand
Posts: 3817
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three options -
1. Have your lock/unlock methods implement the functionality to lock the whole database ( say, lock(-1) locks the db). This is simple, you just need to maintain a flag "dblocked" before locking any row. In your shutdown hook, you can call this method and then exit.

2. Depends on how many instances of DBMainImpl/DBAccessImpl do you have. If you have a single instance, you can have a synchronized shutdown() method that closes the file. If you have multiple instances (each refering to the same instance of the class that does file operations), you can still have the shutdown method, and have that method call shutdown on the file wrapper object. In your shutdown hook, you can call dbmainimpl.shutdown() and then exit.

3. Ignore this aspect altogether in code but explain in choices.txt that you don't believe server will be forcibly shutdown when clients are connect. Not too convincing but acceptable. Several candidates who passed took this approach.

 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might even want to look into Transaction isolation levels. Each level locks elements of the database in a different way, to help avoid various common problems associated with updating and reading from a database:

TRANSACTION_READ_UNCOMMITED
TRANSACTION_READ_COMMITED Avoids dirty reads
TRANSACTION_REPEATABLE_READ Avoids Non repeatable reads
TRANSACTION_SERIALIZABLE Avoids Phontom reads

-Cameron McKenzie
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic