Rather then iterating through theEnumValues each time nullSafeGet, would
it make more sence to sort the array one time durring the constructor,
so theEnumValues[i].ordinal()==i? My idea:
<code>
protected IntEnumUserType(Class<E> c, E[] e) {
this.clazz = c;
this.theEnumValues = (E[]) new Enum[e.length];
for(E value:e) {
e[value.ordinal()]=value;
}
}
public Object nullSafeGet(ResultSet resultSet, String[] names, Object
owner)
throws HibernateException, SQLException {
final int val = resultSet.getShort(names[0]);
if (!resultSet.wasNull() && 0<=val && val<theEnumValues.length)
return theEnumValues[val];
else
return null;
}
</code>
Or am I missing some gotcha? Seems like this could really speed up the
load, especially if you have a large number of enum constants. |