Search in sources :

Example 1 with Query

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);
}
Also used : DocumentReferenceResolver(org.xwiki.model.reference.DocumentReferenceResolver) Query(org.xwiki.query.Query) QueryManager(org.xwiki.query.QueryManager) AuthorizationManager(org.xwiki.security.authorization.AuthorizationManager) DocumentReference(org.xwiki.model.reference.DocumentReference) Before(org.junit.Before)

Example 2 with Query

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;
}
Also used : Query(org.xwiki.query.Query) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList)

Example 3 with 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();
}
Also used : Query(org.xwiki.query.Query)

Example 4 with Query

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;
}
Also used : Query(org.xwiki.query.Query)

Example 5 with 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();
}
Also used : Query(org.xwiki.query.Query) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Query (org.xwiki.query.Query)129 DocumentReference (org.xwiki.model.reference.DocumentReference)41 Test (org.junit.Test)39 QueryException (org.xwiki.query.QueryException)36 ArrayList (java.util.ArrayList)29 XWikiException (com.xpn.xwiki.XWikiException)18 QueryFilter (org.xwiki.query.QueryFilter)18 QueryManager (org.xwiki.query.QueryManager)18 XWikiContext (com.xpn.xwiki.XWikiContext)15 HashMap (java.util.HashMap)14 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)12 Map (java.util.Map)11 List (java.util.List)9 Before (org.junit.Before)9 SecureQuery (org.xwiki.query.SecureQuery)9 XWiki (com.xpn.xwiki.XWiki)8 BaseObject (com.xpn.xwiki.objects.BaseObject)8 SQLQuery (org.hibernate.SQLQuery)8 WikiReference (org.xwiki.model.reference.WikiReference)8 WrappingQuery (org.xwiki.query.WrappingQuery)8