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.
发布评论
评论(2)
复兴供进一步参考。
正如@fredt所说,据我所知,没有官方的魔法参数来实现混合模式。
不过,您始终可以使用 以编程方式启动服务器 href="http://hsqldb.org/doc/src/org/hsqldb/Server.html" rel="nofollow">Server 对象,以便其他进程能够连接到您的数据库。
我发现了一个技巧来完成一些非常接近混合模式的事情。为此,您需要将
remote_open
属性设置为true
并使用 这种 形式的 URL。这里的想法是做这样的事情:
我不确定当您计划生成许多短暂的进程时使用这种模式是否安全(特别是我还没有深入研究 HSQLDB 代码来检查它如何处理数据库/创建/打开多个同时请求当设置
remote_open
时)。尽管如此,我已经使用这种模式在 Web 应用程序之间共享开发数据库一段时间了,并且从未遇到过任何数据库损坏问题。这里的主要限制是,当充当服务器的应用程序关闭时,打开的连接将停止工作并抛出异常...这对于我的开发环境来说不是问题,这里这通常只意味着一个或两个中断的请求,直到另一个请求被中断。服务器启动,连接池检测并更新其连接。
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 totrue
and connect using this form of URL.The idea here is doing something like this:
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.
没有HSQLDB不支持这种模式。
No HSQLDB does not support such a mode.