/** * Builds according to the LikeFilter. * * @param filter the filter to build with. * @param searchContext the searchContext on which to build the filter. * @throws IllegalArgumentException if filter or searchContext is null. * @throws UnrecognizedFilterException if the filter cannot be handled by this * SearchFragmentBuilder. */ public void buildSearch(Filter filter, SearchContext searchContext) throws UnrecognizedFilterException { if (filter == null) { throw new IllegalArgumentException("The filter should not be null."); } if (searchContext == null) { throw new IllegalArgumentException("The searchContext should not be null."); } if (!(filter instanceof LikeFilter)) { throw new UnrecognizedFilterException( "The filter should be an LikeFilter, but a type of " + filter.getClass().getName() + ".", filter); } LikeFilter likeFilter = (LikeFilter) filter; StringBuffer buffer = searchContext.getSearchString(); // get the real name and append to buffer buffer.append(SearchBuilderHelper.getRealName(likeFilter.getName(), searchContext)); buffer.append(" LIKE ?"); // append the like string searchContext.getBindableParameters().add(buildFromLikeFilter(likeFilter)); // set the escape char which should be set into the like filter buffer.append(" ESCAPE ?"); searchContext.getBindableParameters().add(likeFilter.getEscapeCharacter() + ""); }
/** * Failure tests for the constructor <code> * HibernateSearchStrategy(SessionFactory sessionFactory, ClassAssociator fragmentBuilders)</code> * with the sessionFactory is null, IllegalArgumentException is expected. * * @throws Exception to JUnit */ public void testCtor3WithSessionFactoryNull() throws Exception { try { new HibernateSearchStrategy( (SessionFactory) null, SearchBuilderHelper.loadClassAssociator("HibernateSearchStrategy")); fail("IllegalArgumentException should be thrown"); } catch (IllegalArgumentException e) { // expected } }