use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class UntypedRecordableEventDescriptorComponentBuilderTest method setUp.
@Before
public void setUp() throws Exception {
queryManager = mocker.registerMockComponent(QueryManager.class);
modelBridge = mocker.registerMockComponent(ModelBridge.class);
documentReferenceResolver = mocker.registerMockComponent(DocumentReferenceResolver.class);
authorizationManager = mocker.registerMockComponent(AuthorizationManager.class);
Query query = mock(Query.class);
when(queryManager.createQuery(any(), any())).thenReturn(query);
when(query.execute()).thenReturn(Arrays.asList("e1", "e2", "e3"));
event1 = mock(DocumentReference.class);
event2 = mock(DocumentReference.class);
event3 = mock(DocumentReference.class);
when(this.documentReferenceResolver.resolve("e1")).thenReturn(event1);
when(this.documentReferenceResolver.resolve("e2")).thenReturn(event2);
when(this.documentReferenceResolver.resolve("e3")).thenReturn(event3);
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class DocumentTreeNode method getChildrenQuery.
private Query getChildrenQuery(DocumentReference parentReference) throws QueryException {
List<String> constraints = new ArrayList<String>();
constraints.add("doc.translation = 0");
constraints.add("(doc.parent in (:absoluteRef, :localRef) or (doc.space = :space and doc.parent = :relativeRef))");
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("space", this.localEntityReferenceSerializer.serialize(parentReference.getParent()));
parameters.put("absoluteRef", this.defaultEntityReferenceSerializer.serialize(parentReference));
parameters.put("localRef", this.localEntityReferenceSerializer.serialize(parentReference));
parameters.put("relativeRef", this.compactEntityReferenceSerializer.serialize(parentReference, parentReference.getParent()));
Query query = this.documentQueryHelper.getQuery(constraints, parameters, getProperties());
query.setWiki(parentReference.getWikiReference().getName());
return query;
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class WikiTreeNode method getChildCount.
@Override
protected int getChildCount(WikiReference wikiReference) throws QueryException {
Query query = getChildrenQuery(wikiReference);
query.addFilter(this.countQueryFilter);
return ((Long) query.execute().get(0)).intValue();
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class WikiTreeNode method getChildrenQuery.
private Query getChildrenQuery(WikiReference parentReference) throws QueryException {
// In Oracle the empty parent is actually null.
Query query = this.documentQueryHelper.getQuery(Arrays.asList("(doc.parent = '' or doc.parent is null)", "doc.translation = 0"), Collections.<String, Object>emptyMap(), getProperties());
query.setWiki(parentReference.getName());
return query;
}
use of org.xwiki.query.Query in project xwiki-platform by xwiki.
the class SpaceTreeNode method getChildDocumentsCount.
protected int getChildDocumentsCount(SpaceReference spaceReference, List<String> constraints, Map<String, Object> parameters) throws QueryException {
constraints.add("doc.translation = 0");
constraints.add("doc.space = :space");
parameters.put("space", this.localEntityReferenceSerializer.serialize(spaceReference));
Query query = this.queryManager.createQuery(whereClause(constraints), Query.HQL);
query.addFilter(this.countQueryFilter);
if (Boolean.TRUE.equals(getProperties().get("filterHiddenDocuments"))) {
query.addFilter(this.hiddenDocumentQueryFilter);
}
query.setWiki(spaceReference.getWikiReference().getName());
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
query.bindValue(entry.getKey(), entry.getValue());
}
return ((Long) query.execute().get(0)).intValue();
}
Aggregations