Author: epbernard
Date: 2007-07-29 11:35:48 -0400 (Sun, 29 Jul 2007)
New Revision: 12847
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/annotations/FullTextFilterDef.java
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/FilterDef.java
trunk/HibernateExt/search/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
Log:
HSEARCH-58 ability to disable cacheper filter def
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/annotations/FullTextFilterDef.java
===================================================================
---
trunk/HibernateExt/search/src/java/org/hibernate/search/annotations/FullTextFilterDef.java 2007-07-29
15:12:47 UTC (rev 12846)
+++
trunk/HibernateExt/search/src/java/org/hibernate/search/annotations/FullTextFilterDef.java 2007-07-29
15:35:48 UTC (rev 12847)
@@ -32,4 +32,9 @@
*
*/
Class impl();
+
+ /**
+ * Enable caching for this filter (default true).
+ */
+ boolean cache() default true;
}
Modified: trunk/HibernateExt/search/src/java/org/hibernate/search/engine/FilterDef.java
===================================================================
---
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/FilterDef.java 2007-07-29
15:12:47 UTC (rev 12846)
+++
trunk/HibernateExt/search/src/java/org/hibernate/search/engine/FilterDef.java 2007-07-29
15:35:48 UTC (rev 12847)
@@ -17,6 +17,7 @@
private Method factoryMethod;
private Method keyMethod;
private Map<String, Method> setters = new HashMap<String, Method>();
+ private boolean cache;
public Class getImpl() {
return impl;
@@ -60,4 +61,12 @@
throw new SearchException( "Unable to set Filter parameter: " +
parameterName + " on filter class: " + this.impl, e );
}
}
+
+ public void setCache(boolean cache) {
+ this.cache = cache;
+ }
+
+ public boolean isCache() {
+ return cache;
+ }
}
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/impl/SearchFactoryImpl.java
===================================================================
---
trunk/HibernateExt/search/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2007-07-29
15:12:47 UTC (rev 12846)
+++
trunk/HibernateExt/search/src/java/org/hibernate/search/impl/SearchFactoryImpl.java 2007-07-29
15:35:48 UTC (rev 12847)
@@ -123,6 +123,7 @@
}
FilterDef filterDef = new FilterDef();
filterDef.setImpl( defAnn.impl() );
+ filterDef.setCache( defAnn.cache() );
try {
filterDef.getImpl().newInstance();
}
Modified:
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java
===================================================================
---
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-07-29
15:12:47 UTC (rev 12846)
+++
trunk/HibernateExt/search/src/java/org/hibernate/search/query/FullTextQueryImpl.java 2007-07-29
15:35:48 UTC (rev 12847)
@@ -288,42 +288,47 @@
for ( Map.Entry<String, Object> entry :
filterDefinition.getParameters().entrySet() ) {
def.invoke( entry.getKey(), instance, entry.getValue() );
}
- if ( def.getKeyMethod() == null && filterDefinition.getParameters().size()
> 0 ) {
+ if ( def.isCache() && def.getKeyMethod() == null &&
filterDefinition.getParameters().size() > 0 ) {
throw new SearchException("Filter with parameters and no @Key method: " +
filterDefinition.getName() );
}
- FilterKey key;
- if ( def.getKeyMethod() == null ) {
- key = new FilterKey( ) {
- public int hashCode() {
- return getImpl().hashCode();
- }
+ FilterKey key = null;
+ if ( def.isCache() ) {
+ if ( def.getKeyMethod() == null ) {
+ key = new FilterKey( ) {
+ public int hashCode() {
+ return getImpl().hashCode();
+ }
- public boolean equals(Object obj) {
- if ( ! ( obj instanceof FilterKey ) ) return false;
- FilterKey that = (FilterKey) obj;
- return this.getImpl().equals( that.getImpl() );
+ public boolean equals(Object obj) {
+ if ( ! ( obj instanceof FilterKey ) ) return false;
+ FilterKey that = (FilterKey) obj;
+ return this.getImpl().equals( that.getImpl() );
+ }
+ };
+ }
+ else {
+ try {
+ key = (FilterKey) def.getKeyMethod().invoke( instance );
}
- };
- }
- else {
- try {
- key = (FilterKey) def.getKeyMethod().invoke( instance );
+ catch (IllegalAccessException e) {
+ throw new SearchException("Unable to access @Key method: "
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
+ }
+ catch (InvocationTargetException e) {
+ throw new SearchException("Unable to access @Key method: "
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
+ }
+ catch (ClassCastException e) {
+ throw new SearchException("@Key method does not return FilterKey: "
+ + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
+ }
}
- catch (IllegalAccessException e) {
- throw new SearchException("Unable to access @Key method: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
- }
- catch (InvocationTargetException e) {
- throw new SearchException("Unable to access @Key method: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
- }
- catch (ClassCastException e) {
- throw new SearchException("@Key method does not return FilterKey: "
- + def.getImpl().getName() + "." + def.getKeyMethod().getName() );
- }
+ key.setImpl( def.getImpl() );
}
- key.setImpl( def.getImpl() );
- Filter filter = searchFactoryImplementor.getFilterCachingStrategy().getCachedFilter(
key );
+
+ Filter filter = def.isCache() ?
+ searchFactoryImplementor.getFilterCachingStrategy().getCachedFilter( key ) :
+ null;
if (filter == null) {
if ( def.getFactoryMethod() != null ) {
try {
@@ -351,7 +356,7 @@
+ def.getImpl().getName() + "." + def.getFactoryMethod().getName() );
}
}
- searchFactoryImplementor.getFilterCachingStrategy().addCachedFilter( key, filter );
+ if ( def.isCache() )
searchFactoryImplementor.getFilterCachingStrategy().addCachedFilter( key, filter );
}
chainedFilter.addFilter( filter );
}
Show replies by date