gpt4 book ai didi

java - 是否可以将 HSQLDB 模式即时更改为只读?

转载 作者:太空宇宙 更新时间:2023-11-04 12:29:12 25 4
gpt4 key购买 nike

我在file: 模式下使用 HSQLBD。

(我对 HSQLDB 的使用显示在我的 other question 中)

我需要接收对 database.script 文件的多重访问。默认情况下,数据库使用选项 readonly=false 运行,以下是官方文档中的一些信息:

Readonly Databases

A file: catalog can be made readonly permanently, or it can be opened as readonly. To make the database readonly, the property, value pair, readonly=true can be added to the .properties file of the database. The SHUTDOWN command must be used to close the database before making this change.

It is also possible to open a normal database as readonly. For this, the property can be included in the URL of the first connection to the database.

With readonly databases, it is still possible to insert and delete rows in TEMP tables.

但我仍然没有真正理解,是否可以在不关闭服务器且不重新启动的情况下即时更改此选项?如果可能的话 - 你能给出一些小代码示例吗?

如果没有,是否有某种方法可以解锁 .script 文件并在不关闭服务器的情况下获得不同线程的访问权限?

最佳答案

您需要访问 HSQL 内部类。示例代码是为v2.3.3编写的,可能不适用于其他版本。

//import org.hsqldb.*;
//start server
Server.main(new String[]{"-database.0","file:s:/folder/dbname","-dbname.0","dbname","-no_system_exit","true"});

//set DB readonly
Database db = DatabaseManager.lookupDatabaseObject("file:", "s:/folder/dbname");
db.setReadOnly();
//alter connection to readonly
Session[] oa = db.sessionManager.getAllSessions();
for (int i = 0; i < oa.length; i++) {
if (oa[i].getDatabase() == db) {
try {
oa[i].setReadOnly(true);
oa[i].setReadOnlyDefault(true);
} catch (Exception e) {
//the connection is during transaction...
}
}
}
//the implementation of Database cannot turn to writable,
//close it...
db.close(Database.CLOSEMODE_COMPACT);

关于java - 是否可以将 HSQLDB 模式即时更改为只读?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38041004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com