forked from Adobe-Consulting-Services/acs-aem-commons
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re Adobe-Consulting-Services#2760 remove CloseableQuery from API
- Loading branch information
Showing
29 changed files
with
328 additions
and
1,106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
bundle/src/main/java/com/adobe/acs/commons/cqsearch/QueryUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.adobe.acs.commons.cqsearch; | ||
|
||
import com.day.cq.search.Query; | ||
import org.apache.sling.api.resource.ResourceResolver; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
/** | ||
* Simple utility to use as an alternative to deprecated CloseableQuery in older versions of AEM. | ||
*/ | ||
public class QueryUtil { | ||
private static final Logger log = LoggerFactory.getLogger(QueryUtil.class); | ||
|
||
/** | ||
* Uses reflection to forcibly set the Query object's ResourceResolver to the provided. | ||
*/ | ||
public static void setResourceResolverOn(ResourceResolver resolver, Query query) { | ||
Class<? extends Query> clazz = query.getClass(); | ||
try { | ||
Field resourceResolverField = clazz.getDeclaredField("resourceResolver"); | ||
resourceResolverField.setAccessible(true); | ||
resourceResolverField.set(query, resolver); | ||
} catch (NoSuchFieldException | IllegalAccessException e) { | ||
log.debug("Could not set ResourceResolver on provided Query: {} => {}", | ||
e.getClass().getName(), e.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.