我可以在JDO环境中直接执行SQL语句吗?

发布于 2024-09-05 06:47:42 字数 320 浏览 1 评论 0原文

我在 HSqlDb 之上使用 Datanucleus JDO。

我想执行以下SQL语句来告诉HsqlDb将写入延迟设置为0:
“SET WRITE_DELAY 0”

有没有办法可以从 JDO PersistenceManager 或 PersistenceManagerFactory 执行此操作?

旁注:我尝试使用以下连接 URL 修改 write_delay: jdbc:hsqldb:file:data/hsqldb/dbbench;write_delay=false

它不起作用。我调试了 HsqlDb 源,仍然可以看到写入延迟设置为 10 秒。

I am using Datanucleus JDO on top of HSqlDb.

I would like to execute the following SQL statement to tell HsqlDb to set the write delay to 0:
"SET WRITE_DELAY 0"

Is there a way I can do this from a JDO PersistenceManager or a PersistenceManagerFactory?

On a sidenote: I have tried to modify write_delay by using the following connection URL:
jdbc:hsqldb:file:data/hsqldb/dbbench;write_delay=false

It didn't work. I debugged the HsqlDb sources and I could still see the write delay being set to 10 seconds.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

半﹌身腐败 2024-09-12 06:47:42

我想我已经找到了一个适合我的解决方案:

public PersistenceManager getPersistenceManager() {
    PersistenceManager persistenceManager = 
        _persistenceManagerFactory.getPersistenceManager();
    JDOConnection dataStoreConnection = 
        persistenceManager.getDataStoreConnection();
    Object nativeConnection = dataStoreConnection.getNativeConnection();
    if(! (nativeConnection instanceof Connection) ){
        return persistenceManager;
    }

    Connection connection = (Connection) nativeConnection;
    try {
        Statement statement = connection.createStatement();
        statement.executeUpdate("SET WRITE_DELAY 0");
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return persistenceManager;
}

I think I have found a solution that will work for me:

public PersistenceManager getPersistenceManager() {
    PersistenceManager persistenceManager = 
        _persistenceManagerFactory.getPersistenceManager();
    JDOConnection dataStoreConnection = 
        persistenceManager.getDataStoreConnection();
    Object nativeConnection = dataStoreConnection.getNativeConnection();
    if(! (nativeConnection instanceof Connection) ){
        return persistenceManager;
    }

    Connection connection = (Connection) nativeConnection;
    try {
        Statement statement = connection.createStatement();
        statement.executeUpdate("SET WRITE_DELAY 0");
        statement.close();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return persistenceManager;
}
与他有关 2024-09-12 06:47:42

您可以编写一个启动脚本(本示例中为 dbbench.script),并将 SQL 放入其中。

请参阅:http://best-practice- software-engineering.ifs.tuwien.ac.at/technology/tech-hsqldb.html

You can write a startup script, dbbench.script in this example, and put the SQL in there.

See: http://best-practice-software-engineering.ifs.tuwien.ac.at/technology/tech-hsqldb.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文