Duh...

  | @Name("searchService")
  | public class SearchService
  | {
  |    @In(create=true)
  |    private EntityManager entityManager;
  |    
  |    private String m_searchPattern;
  |    
  |    @SuppressWarnings("unchecked")
  |    @Factory("searchResults")
  |    @Restrict("#{s:hasRole('user')}") // Forces check that user is logged in 
  
  |    public List<InfoDigest> getSearchResults()
  |    {
  |       if(m_searchPattern == null)
  |       {
  |          return null;
  |       }
  |       /* TODO replace with proper search */
  |      return entityManager.createQuery("select i from MockData i where 
lower(i.name) like :searchPattern or lower(i.digest) like :searchPattern order 
by i.name")
  |            .setParameter( "searchPattern", getSqlSearchPattern() )
  |            .setMaxResults(100)
  |            .getResultList();
  |    }
  |    
  |    /**
  |     * Turn a typical search patter using * for wildcard, and ? for single 
character
  |     * into the SQL versions (% and _) of the same. Also addes SQL wildcard 
in the beginning and end
  |     */
  |    private String getSqlSearchPattern()
  |    {
  |       return m_searchPattern == null ? "" : '%' + 
m_searchPattern.toLowerCase().replace('*', '%').replace('?', '_') + '%';
  |    }
  | 
  |    public String getSearchPattern()
  |    {
  |       return m_searchPattern;
  |    }
  | 
  |    public void setSearchPattern(String searchPattern)
  |    {
  |       m_searchPattern = searchPattern;
  |    }
  | }
  | 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4031847#4031847

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4031847
_______________________________________________
jboss-user mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/jboss-user

Reply via email to