1 package org.hibernate.cache; 3 4 import java.io.Serializable ; 5 import java.util.HashMap ; 6 import java.util.HashSet ; 7 import java.util.Iterator ; 8 import java.util.Map ; 9 import java.util.Set ; 10 11 import org.hibernate.EntityMode; 12 import org.hibernate.engine.TypedValue; 13 import org.hibernate.impl.FilterImpl; 14 import org.hibernate.type.Type; 15 16 21 public final class FilterKey implements Serializable { 22 private String filterName; 23 private Map filterParameters = new HashMap (); 24 25 public FilterKey(String name, Map params, Map types, EntityMode entityMode) { 26 filterName = name; 27 Iterator iter = params.entrySet().iterator(); 28 while ( iter.hasNext() ) { 29 Map.Entry me = (Map.Entry ) iter.next(); 30 Type type = (Type) types.get( me.getKey() ); 31 filterParameters.put( me.getKey(), new TypedValue( type, me.getValue(), entityMode ) ); 32 } 33 } 34 35 public int hashCode() { 36 int result = 13; 37 result = 37 * result + filterName.hashCode(); 38 result = 37 * result + filterParameters.hashCode(); 39 return result; 40 } 41 42 public boolean equals(Object other) { 43 if ( !(other instanceof FilterKey) ) return false; 44 FilterKey that = (FilterKey) other; 45 if ( !that.filterName.equals(filterName) ) return false; 46 if ( !that.filterParameters.equals(filterParameters) ) return false; 47 return true; 48 } 49 50 public String toString() { 51 return "FilterKey[" + filterName + filterParameters + ']'; 52 } 53 54 public static Set createFilterKeys(Map enabledFilters, EntityMode entityMode) { 55 if ( enabledFilters.size()==0 ) return null; 56 Set result = new HashSet (); 57 Iterator iter = enabledFilters.values().iterator(); 58 while ( iter.hasNext() ) { 59 FilterImpl filter = (FilterImpl) iter.next(); 60 FilterKey key = new FilterKey( 61 filter.getName(), 62 filter.getParameters(), 63 filter.getParameterTypes(), 64 entityMode 65 ); 66 result.add(key); 67 } 68 return result; 69 } 70 } 71 | Popular Tags |