I'm trying to write an app that connects directly to the database and uses hibernate to access the database contents. The app is single thread, swing based, directly connected to the database, that is, the usual rich client.
Now, what is the suggested pattern for this kind of app? Consider the following example: I want to model into the database something that looks alike a file system, so I have the File and Folder classes.
Every file has 1 parent folder.
Every folder has 0/1 parent folder, the subfolders and files.
The folder has to be managed as a proxy of itself, and the two collections of subfolders and files are lazy, otherwise I end up loading the whole filesystem in memory at the first data access.
The user interface is a classic explorer like interface, so I have a tree view for the folders and a listview that lists the contents of the current folder. Nodes in the treeview are created lazily, when the user expands a folder.
There are commands to rename, move and delete files (and also to import new files into the database)
What kind of session management do you suggest? If I close the session after each request, I end up with a DAO request and session open/close each time the users moves around, plus the code will be quite ugly.
If I use a single session, would not the session cache grow continuously? The alternative is to evict objects from the cache, but with what rules? Instead of a DAO that closes the connection, a DAO that evicts the cache after every operation? And if I choose this road, wouldn't this cause problems with updating collections (in particular, the ones mapped with the cascade - delete orphan rule)?
Sorry for the long post, but I don't know how to approach this and it seems that most of the people around are developing web apps.
|