有什么办法可以将OrmLite与Postgres hstore一起使用? [英] Is there any way to use OrmLite with Postgres hstores?

查看:112
本文介绍了有什么办法可以将OrmLite与Postgres hstore一起使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们当前正在使用PostgreSQL数据库和OrmLite。现在,我们有一个使用 Postgres hstore 的用例,但是可以无法找到通过OrmLite访问该表的任何方法。我宁愿避免只为选择并插入该表而打开一个单独的数据库连接,但我看不到任何其他选项。

We're currently using a PostgreSQL database and OrmLite. We now have a use case for using an Postgres hstore, but can't find any way of accessing that table through OrmLite. I'd prefer to avoid opening a separate database connection just to select and insert to that one table, but I'm not seeing any other options.

至少我想要一个OrmLite正在使用的现有连接的句柄,以便可以重用它来构建一个准备好的语句,但是我还没有找到获取 java.sql.Connection 从OrmLite ConnectionSource 开始。

我看到OrmLite具有 JdbcCompiledStatement ,但这只是 PreparedStatement的包装,并要求将 PreparedStatement 传递给构造函数。 (不知道用例是什么。)

At the very least I'd like a handle to the existing connection OrmLite is using so I can reuse it to build a prepared statement, but I haven't found a way to get a java.sql.Connection starting from an OrmLite ConnectionSource. I see that OrmLite has a JdbcCompiledStatement, but that's just a wrapper around a PreparedStatement and requires the PreparedStatement to be passed in to the constructor. (Not sure what the use case for that is.)

我尝试使用 DatabaseConnection.compileStatement(...),但这需要了解所使用的字段类型,而OrmLite似乎不知道hstore是什么。

I've tried to use DatabaseConnection.compileStatement(...), but that requires knowledge of the field types being used and OrmLite doesn't seem to know what an hstore is.

我尝试使用 updateRaw(),但是该功能仅存在于我没有的OrmLite岛上,因为我将链接到该表的表具有OrmLite无法识别的字段类型。有什么方法可以让通用的dao发出原始查询吗?

I've tried to use updateRaw(), but that function only exists on an OrmLite dao that I don't have because the table I would link the dao to has a field type OrmLite doesn't recognize. Is there some way to get a generic dao to issue raw queries?

我知道hstore是特定于数据库的,OrmLite可能不支持它,但是我会真的很想找到一种使用不受支持的字段而不是不受支持的查询来往数据库中传输数据的方法。

I get that hstores are database specific and probably won't be supported by OrmLite, but I'd really like to find a way to transfer data to and from the database using unsupported fields instead of just unsupported queries.

推荐答案


至少我想要一个OrmLite正在使用的现有连接的句柄,以便我可以重用它来构建一个准备好的语句...

At the very least I'd like a handle to the existing connection OrmLite is using so I can reuse it to build a prepared statement...

确定,这很容易。如@jsight所述,用于JDBC的 ORMLite ConnectionSource JdbcConnectionSource 。当您使用 connectionSource.getReadOnlyConnection()从该类获得连接时,您将获得一个 DatabaseConnection JdbcDatabaseConnection 并可以强制转换为它。有一个 JdbcDatabaseConnection.getInternalConnection() 方法,该方法返回关联的 java.sql.Connection

Ok, that's pretty easy. As @jsight mentioned, the ORMLite ConnectionSource for JDBC is JdbcConnectionSource. When you get a connection from that class using connectionSource.getReadOnlyConnection(), you will get a DatabaseConnection that is really a JdbcDatabaseConnection and can be cast to it. There is a JdbcDatabaseConnection.getInternalConnection() method which returns the associated java.sql.Connection.


我尝试使用updateRaw(),但是该函数仅存在于我没有的OrmLite dao上...

I've tried to use updateRaw(), but that function only exists on an OrmLite dao that I don't have ...

您确实可以使用任何DAO类对任何表执行原始函数。将其视为DAO对象表的非结构化更新很方便。但是,如果您有任何DAO,则可以在任何其他表上执行原始更新。

You really can use any DAO class to perform a raw function on any table. It is convenient to think of it as being an unstructured update to an DAO object's table. But if you have any DAO, you can perform a raw update on any other table.


找到了一种方法,可以将数据往返于数据库使用不受支持的字段,而不只是不受支持的查询

find a way to transfer data to and from the database using unsupported fields instead of just unsupported queries

如果您使用不受支持的字段,那么您将不得不原始语句- SELECT UPDATE 。如果您编辑帖子以显示您尝试过的原始语句,那么我可以提供更具体的帮助。

If you are using unsupported fields, then you are going to have to do it as a raw statement -- either SELECT or UPDATE. If you edit your post to show the raw statement you've tried, I can help more specifically.

这篇关于有什么办法可以将OrmLite与Postgres hstore一起使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆