HSQLDB equivalent of H2 automatic mixed mode
Is there one? Apparently开发者_Python百科 not. The H2 automatic mixed mode is described here.
Revival for further reference.
As stated by @fredt, as far as I know, there is no official magic parameter to achieve mixed mode. Still, you can always start a server programmatically using a Server object so that other process are able to connect to your database.
I discovery a trick to accomplish something pretty close to mixed mode. In order to do that you will need to set the remote_open
property to true
and connect using this form of URL.
The idea here is doing something like this:
- Try connecting to the server using the kind of URL stated above.
- If you can't connect it means the server haven't been started, so go ahead and start the server programmatically.
- When you connect again, one of three things will happen.
- If no database file exists, one will be created in the specified file path and the server will start serving it from the URL alias.
- If the database file exists and it isn't being served, the server will open the file from the specified path and start serving it.
- If the database file exists and it is being served, the server will simply return a connection.
I'm not sure if it is safe to use that kind of pattern when you plan to spawn a lot of short lived processes (particularly I haven't dive into HSQLDB code to check how it handles database / creation / opening for multiple simultaneous requests when remote_open
is set). Still, I've been using this kind of pattern to share development databases between Web Applications for a while and never ran into a single database corruption problem.
The main limitation here is that when the application acting as a server is closed, open connections will stop working and throw Exceptions... Which is not an Issue for my development environment, here this will generally only means one or two broken requests until another server is started and the connection pool detects and renews its connections.
No HSQLDB does not support such a mode.
精彩评论