mirror of https://github.com/apache/openjpa.git
OPENJPA-2348: Cache calculated hashcode in OpenJPAId.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@1452884 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8c23eb3f48
commit
1e2b753afa
|
@ -29,16 +29,17 @@ import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap;
|
||||||
* @author Steve Kim
|
* @author Steve Kim
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public abstract class OpenJPAId
|
public abstract class OpenJPAId implements Comparable, Serializable {
|
||||||
implements Comparable, Serializable {
|
|
||||||
public static final char TYPE_VALUE_SEP = '-';
|
public static final char TYPE_VALUE_SEP = '-';
|
||||||
|
|
||||||
// cache the types' generated hash codes
|
// cache the types' generated hash codes
|
||||||
private static ConcurrentReferenceHashMap _typeCache =
|
private static ConcurrentReferenceHashMap _typeCache =
|
||||||
new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD);
|
new ConcurrentReferenceHashMap(ReferenceMap.WEAK, ReferenceMap.HARD);
|
||||||
|
|
||||||
protected Class type;
|
protected Class<?> type;
|
||||||
protected boolean subs = true;
|
protected boolean subs = true;
|
||||||
|
private int _hc = -1;
|
||||||
|
|
||||||
// type hash is based on the least-derived non-object class so that
|
// type hash is based on the least-derived non-object class so that
|
||||||
// user-given ids with non-exact types match ids with exact types
|
// user-given ids with non-exact types match ids with exact types
|
||||||
|
@ -106,22 +107,27 @@ public abstract class OpenJPAId
|
||||||
* so that it doesn't have to be generated each time.
|
* so that it doesn't have to be generated each time.
|
||||||
*/
|
*/
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
if (_typeHash == 0) {
|
if (_hc == -1) {
|
||||||
Integer typeHashInt = (Integer) _typeCache.get(type);
|
if (_typeHash == 0 && type != null) {
|
||||||
if (typeHashInt == null) {
|
Integer typeHashInt = (Integer) _typeCache.get(type);
|
||||||
Class base = type;
|
if (typeHashInt == null) {
|
||||||
Class superclass = base.getSuperclass();
|
Class base = type;
|
||||||
while (superclass != null && superclass != Object.class) {
|
Class superclass = base.getSuperclass();
|
||||||
base = base.getSuperclass();
|
while (superclass != null && superclass != Object.class) {
|
||||||
superclass = base.getSuperclass();
|
base = base.getSuperclass();
|
||||||
|
superclass = base.getSuperclass();
|
||||||
|
}
|
||||||
|
_typeHash = base.getName().hashCode();
|
||||||
|
_typeCache.put(type, Integer.valueOf(_typeHash));
|
||||||
|
} else {
|
||||||
|
_typeHash = typeHashInt.intValue();
|
||||||
}
|
}
|
||||||
_typeHash = base.getName().hashCode();
|
_hc = _typeHash ^ idHash();
|
||||||
_typeCache.put(type, Integer.valueOf(_typeHash));
|
|
||||||
} else {
|
} else {
|
||||||
_typeHash = typeHashInt.intValue();
|
_hc = idHash();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return _typeHash ^ idHash();
|
return _hc;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
|
|
Loading…
Reference in New Issue