|
1 | 1 | package dev.vml.es.acm.core.repo; |
2 | 2 |
|
3 | | -import dev.vml.es.acm.core.util.StreamUtils; |
| 3 | +import dev.vml.es.acm.core.util.JcrUtils; |
4 | 4 | import java.util.stream.Stream; |
5 | 5 | import javax.jcr.Node; |
| 6 | +import javax.jcr.RepositoryException; |
6 | 7 | import javax.jcr.Session; |
7 | 8 | import javax.jcr.query.Query; |
| 9 | +import javax.jcr.query.QueryManager; |
| 10 | +import javax.jcr.query.QueryResult; |
8 | 11 | import org.apache.commons.lang3.StringUtils; |
9 | 12 | import org.apache.jackrabbit.JcrConstants; |
10 | 13 | import org.apache.sling.api.resource.*; |
@@ -169,8 +172,21 @@ public Stream<RepoResource> query(String path, String nodeType, String where, St |
169 | 172 | } |
170 | 173 |
|
171 | 174 | public Stream<RepoResource> queryRaw(String sql) { |
172 | | - return StreamUtils.asStream(resourceResolver.findResources(sql, Query.JCR_SQL2)) |
173 | | - .map(r -> new RepoResource(this, r.getPath())); |
| 175 | + try { |
| 176 | + QueryManager queryManager = session.getWorkspace().getQueryManager(); |
| 177 | + Query query = queryManager.createQuery(sql, Query.JCR_SQL2); |
| 178 | + QueryResult result = query.execute(); |
| 179 | + |
| 180 | + return JcrUtils.asNodeStream(result.getNodes()).map(n -> { |
| 181 | + try { |
| 182 | + return new RepoResource(this, n.getPath()); |
| 183 | + } catch (RepositoryException e) { |
| 184 | + throw new RepoException(String.format("Cannot read node path from query result '%s'!", sql), e); |
| 185 | + } |
| 186 | + }); |
| 187 | + } catch (Exception e) { |
| 188 | + throw new RepoException(String.format("Cannot execute raw query '%s'!", sql), e); |
| 189 | + } |
174 | 190 | } |
175 | 191 |
|
176 | 192 | public boolean isCompositeNodeStore() { |
|
0 commit comments