- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
在我的数据库中,我有一个包含 code
列的 zip
表。用户可以上传邮政编码列表,我需要找出哪些已经在数据库中。目前,我使用以下 Hibernate 查询 (HQL) 执行此操作:
select zip.code from Zip zip
where zip.code in (:zipCodes)
:zipCodes
参数的值为用户上传的编码列表。但是,在我使用的 Hibernate 版本中有 a bug这限制了此类列表参数的大小,有时我们会超过此限制。
所以我需要找到另一种方法来确定哪些(可能很长)邮政编码列表已经在数据库中。以下是我考虑过的几个选项
使用 SQL 而不是 HQL 重写查询。虽然这会避免 Hibernate 错误,但我怀疑如果需要检查 30,000 个邮政编码,性能会很糟糕。
将邮政编码列表拆分为一系列子列表,并对每个子列表执行单独的查询。同样,这将避免 Hibernate 错误,但性能可能仍然很糟糕
使用临时表,即将要检查的邮政编码插入临时表,然后将其连接到 zip
表。看起来这个解决方案的查询部分应该执行得相当好,但是临时表的创建和最多 30,000 行的插入不会。但也许我没有以正确的方式去做,这就是我在伪 Java 代码中的想法
/**
* Indicates which of the Zip codes are already in the database
*
* @param zipCodes the zip codes to check
* @return the codes that already exist in the database
* @throws IllegalArgumentException if the list is null or empty
*/
List<Zip> validateZipCodes(List<String> zipCodes) {
try {
// start transaction
// execute the following SQL
CREATE TEMPORARY TABLE zip_tmp
(code VARCHAR(255) NOT NULL)
ON COMMIT DELETE ROWS;
// create SQL string that will insert data into zip_tmp
StringBuilder insertSql = new StringBuilder()
for (String code : zipCodes) {
insertSql.append("INSERT INTO zip_tmp (code) VALUES (" + code + ");")
}
// execute insertSql to insert data into zip_tmp
// now run the following query and return the result
SELECT z.*
FROM zip z
JOIN zip_tmp zt ON z.code = zt.code
} finally {
// rollback transaction so that temporary table is removed to ensure
// that concurrent invocations of this method operate do not interfere
// with each other
}
}
有没有比上面的伪代码更有效的方法来实现它,或者还有其他我没有想到的解决方案?我正在使用 Postgres 数据库。
最佳答案
将数据库中的所有邮政编码加载到列表中。并在用户输入的邮政编码列表上执行 removeAll(databaseList)
。
问题解决了!
关于java - 在没有巨大列表参数的情况下重写 Hibernate 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13798868/
我习惯于使用 Apache 服务器,所以当启用 mod_rewrite 时,我可以创建一个 htaccess 文件并使用 URL 重写。 这是我的 htaccess 文件: RewriteEngine
我正在尝试编写一个 mixin 来修改输出的父选择器。这个想法是,在调用 mixin 的情况下,父选择器需要对其进行字符串替换。我有大部分工作,但我不知道如何吞下 & . .test { @inc
我有一个本地目录(上传)和一个 S3 桶设置。 当用户上传图片时,文件存储在本地目录:/uploads/member_id/image_name30 分钟后,系统将文件上传到 S3 使用相同的路径:s
我正在尝试使用以下内容重写代理页面的正文链接: sub_filter http://proxied.page.come http://local.page.com; sub_filte
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 1年前关闭。 Improve this questi
我尝试在我的 JSF 应用程序中使用“重写”(http://ocpsoft.org/rewrite/)。 一切都很好,我已经创建了规则: .addRule(Join.path("/profile/{p
我可以在 AEM 中大致看到两种 URL 重写方法: /etc/map/http(s)下的Sling映射(sling:Mapping) 使用链接重写器/TransformerFactory 重写 UR
我有一个 onclick 函数,我想将 anchor 添加到 href 值。我不想更改 URL,因为我需要该网站仍然可以为没有 javascript 的人/出于 SEO 目的而运行。所以这是我尝试使用
我必须在 UILabel 中显示货币和价格。在一个标签中,但使用不同的字体大小。现在看起来像这样: ...我这样做是重写drawTextInRect:,如下所示: - (void)drawTextIn
我正在尝试使用以下内容进行重定向: RewriteRule ^reviews/area/Santa-Barbara%2F$"/reviews/area/santa-barbara" [R=301,NC
我使用 FOSUserBundle 并且我想覆盖他的 registerAction Controller 。我阅读了与覆盖 FOSUserBundle Controller 相关的文档,但它不起作用。
我正在尝试让 URL 重写在我的网站上运行。这是我的 .htaccess 的内容: RewriteEngine On RewriteRule ^blog/?$ index.php?page=blog
好吧,这让我发疯了......我正在尝试像这样重写我的网址: Now: http://www.somedomain.com/Somepage.aspx http://www.somedomain.co
final方法不能在子类中重写。但凭借 Scala 的魔力,这似乎是可能的。 考虑以下示例: trait Test { final def doIt(s: String): String = s
我有一个类似下面的查询: Select ser.key From dbo.Enrlmt ser Where ser.wd >= @FromDate AND ser.wd ser.wd
我是 nginx 的新手,只是想做一些我认为应该很简单的事情。如果我这样做:- curl http://localhost:8008/12345678 我希望返回 index.html 页面。但是我得
我们的一位客户创建了一个二维码,其中 url 中包含一个空格。 我将如何编写处理此问题的 nginx 重定向? 在字符串中使用诸如“%20”之类的东西的几次尝试似乎会导致 nginx 出错或使 con
我正在尝试覆盖 appendChild 方法,以便我可以控制动态创建的元素并在插入页面之前根据需要修改它们。我尝试了这个示例代码,只是为了看看它是否可以完成: var f = Element.prot
我目前正在使用以下功能,当用户单击某处以确定是否隐藏下拉菜单(在 react 中)。一切正常,但当我单击正文时,它会记录以下内容。 我尝试重写它几次,但我找不到解决这个问题的方法。 Uncaught
我正在开发一个 Spring Integration/Boot 应用程序。我使用多文档 application.yml (src/main/resources/application.yml) 来设置
我是一名优秀的程序员,十分优秀!