Originally posted by Paula Decker:
I call Data.close() from my gui controller to close the database if I'm in standalone mode. I call Data.close() from the server.close() method. Both the standalone client and the server use an instance of Data to make all calls to the database. I don't really like using the static but it should work. I was wondering if I should add it because close() is not in the DBAccess interface. What do you think?
I would use the following design:
(-> for reference; => for method call)
server->FileManager->file handle
server->DB (instantiate Data from FileManager)
FileManager has a constructor using the data file path, and provides access to the underlying data file.
server.close()
=>shuts down server so no more client request will be handled
=>FileManager.close()=>close file and release file handle
The GUI controller follows similar
pattern.
This allows use of DB interface instead of the Data class.
This would not need to depend on finalize() to close file. Finalize() is called on garbage collection. There is no guarantee VM calls finalize() on each and every object on VM shut down.
Note that server.close() should make sure no
thread is writing to the data file while calling FileManager.close(). Otherwise, you may risk corrupting the data file.
Hope this helps.