Inefficient EhCache Performance

前端 未结 1 1927
梦如初夏
梦如初夏 2020-12-07 05:49

Using thoses JPA properties

props.put( \"hibernate.cache.use_query_cache\", \"true\" );
props.put( \"hibernate.cache.use_second_level_cache\", \"true\" );
p         


        
相关标签:
1条回答
  • 2020-12-07 06:16

    Recursive version Full working

    Class org.hibernate.type.AbstractType

    public int getHashCode(Object x) {      
            if (x instanceof Object[]){
                int result = 1;
                for (Object element : (Object[]) x)
                    result = 31 * result + (element == null ? 0 : getHashCode(element));
                return result;
            }
            return x.hashCode();
        }
    

    AND

    public static boolean arraysEquals(Object[] a, Object[] a2) {
                if (a==a2)
                    return true;
                if (a==null || a2==null)
                    return false;
    
                int length = a.length;
                if (a2.length != length)
                    return false;
    
                for (int i=0; i<length; i++) {
                    Object o1 = a[i];
                    Object o2 = a2[i];
                    if (o1==null){
                        if (o2!=null)                   
                            return false;
                    }else{
                        if (o2==null)
                            return false;
                        if (o1 instanceof Object[]){
                            if (!(o2 instanceof Object[]))
                                return false;
                            else
                                if (!arraysEquals( (Object[]) o1, (Object[]) o2))
                                    return false;
                        }else
                            if (!o1.equals(o2))
                                return false;
                    }                           
                }
                return true;
        }
        public static boolean equals(final Object x, final Object y) {
            if (x!=null && x instanceof Object[] && y!=null && y instanceof Object[] )
                return arraysEquals((Object[])x, (Object[])y);
            return x == y || ( x != null && y != null && x.equals( y ) );
        }
    
    0 讨论(0)
提交回复
热议问题