1 4 package info.magnolia.cms.util; 5 6 import info.magnolia.cms.core.ItemType; 7 import info.magnolia.cms.core.search.Query; 8 import info.magnolia.cms.core.search.QueryManager; 9 import info.magnolia.cms.core.search.QueryResult; 10 import info.magnolia.context.MgnlContext; 11 12 import java.util.ArrayList ; 13 import java.util.Collection ; 14 import java.util.Collections ; 15 16 import org.slf4j.Logger; 17 import org.slf4j.LoggerFactory; 18 19 20 26 public class QueryUtil { 27 private static Logger log = LoggerFactory.getLogger(QueryUtil.class); 28 29 35 public static Collection query(String repository, String statement){ 36 return query(repository,statement, Query.SQL); 37 } 38 39 46 public static Collection query(String repository, String statement, String language){ 47 return query(repository,statement,language, ItemType.NT_BASE); 48 } 49 50 58 public static Collection query(String repository, String statement, String language, String returnItemType){ 59 try { 60 QueryManager qm = MgnlContext.getQueryManager(repository); 61 Query query= qm.createQuery(statement, language); 62 QueryResult result = query.execute(); 63 return result.getContent(returnItemType); 64 } 65 catch (Exception e) { 66 log.error("can't query, will return empty collection", e); 67 } 68 69 return Collections.EMPTY_LIST; 70 } 71 72 } 73 | Popular Tags |