具有动态日期比较的 JCR SQL2 查询

发布于 2024-12-25 23:27:59 字数 490 浏览 1 评论 0原文

我需要查询 jcr 存储库以查找日期属性(例如 jcr:created)早于特定日期的节点。

使用 SQL2,我像这样检查“jcr:created > date”(效果很好):

SELECT * FROM [nt:base] AS s WHERE s.[jcr:created] > CAST('2012-01-05T00:00:00.000Z' AS DATE)

现在是棘手的部分:

有一个附加属性,它声明必须动态添加到 jcr:created 日期的天数。

假设该属性包含 5(天),那么查询不应检查“jcr:created > date”,而应检查“(jcr:created + 5) > date”。包含属性值 10 的下一个节点应通过“(jcr:created + 10) > date”进行检查。

是否有任何智能/动态操作数可以做到这一点?由于该属性是特定于节点的,因此我无法将其静态添加到查询中,但它必须读取每个节点的属性。

I need to query the jcr repository to find nodes where a date property (e.g. jcr:created) is younger than a specific date.

Using SQL2, I do the check "jcr:created > date" like that (which works fine):

SELECT * FROM [nt:base] AS s WHERE s.[jcr:created] > CAST('2012-01-05T00:00:00.000Z' AS DATE)

Now the tricky part:

There's an additional property which declares a number of days which have to be added to the jcr:created date dynamically.

Let's say the property contains 5 (days) then the query should not check "jcr:created > date" but rather "(jcr:created + 5) > date". The next node containing the property value 10 should be checked by "(jcr:created + 10) > date".

Is there any intelligent / dynamic operand which could do that? As the property is node specific I cannot add it statically to the query but it has to read it of each node.

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

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

发布评论

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

评论(3

失退 2025-01-01 23:27:59

Jackrabbit 目前不支持此类动态约束。

我相信目前最好的解决方案是使用固定日期约束运行查询,然后自己显式过滤结果。

另一种解决方案是预先计算“jcr:created + extratime”值并将其存储在附加属性中。此类计算可以位于首先创建/更新节点的代码中,也可以将其放置在观察侦听器中,这样无论节点如何修改,它都会被触发。

Jackrabbit doesn't currently support such dynamic constraints.

I believe the best solution for now is to run the query with a fixed date constraint and then explicitly filter the results by yourself.

An alternative solution would be to precompute the "jcr:created + extratime" value and store it in an additional property. Such computation could either be located in the code that creates/updates the nodes in the first place, or you could place it in an observation listener so it'll get triggered regardless of how the node is being modified.

瑾兮 2025-01-01 23:27:59

我需要查找过去 12 小时内创建的文档,

但我很难在 CAST 函数中获取有效日期,粘贴给可能需要它的其他人。

SimpleDateFormat dateFromat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
cal.setTime(cal.getTime());
cal.add(Calendar.HOUR, -12);

String queryString = "SELECT * FROM [nt:base] AS s WHERE "
            + "ISDESCENDANTNODE([/content/en/documents/]) "
            + "and s.[jcr:created] >= CAST('"+dateFromat.format(cal.getTime())+"' AS DATE)";

I had a need to find documents created in last 12 hours

I had a hard time how to get a valid date in the CAST function, Pasting for others who may need it.

SimpleDateFormat dateFromat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
cal.setTime(cal.getTime());
cal.add(Calendar.HOUR, -12);

String queryString = "SELECT * FROM [nt:base] AS s WHERE "
            + "ISDESCENDANTNODE([/content/en/documents/]) "
            + "and s.[jcr:created] >= CAST('"+dateFromat.format(cal.getTime())+"' AS DATE)";
浅语花开 2025-01-01 23:27:59

我在那里找到了收据:
test.sql2.txt

测试列表。我的查询如下所示:

SELECT * FROM [nt:base] where [jcr:created] > cast('+2012-01-01T00:00:00.000Z' as date)

强制转换字符串内的所有内容都需要: +yyyy-MM-ddT00:00:00.000Z

I found the receipe there:
test.sql2.txt

A list of test. My query look like:

SELECT * FROM [nt:base] where [jcr:created] > cast('+2012-01-01T00:00:00.000Z' as date)

Everything inside the cast string is require: +yyyy-MM-ddT00:00:00.000Z

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