109
return x.hashCode();
}
@Override
public Object nullSafeGet(ResultSet rs,
String[] names,
SharedSessionContractImplementor session,
Object owner)
throws HibernateException, SQLException
{
Object obj = null;
byte[] bytes = rs.getBytes(names[0]);
if (bytes != null && !rs.wasNull()) {
try {
obj = MAPPER.readValue(bytes, HashMap.class);
} catch (IOException e) {
throw new HibernateException(
"unable to read object from result set", e);
}
} else {
try {
String content = rs.getString(names[0]);
if (content != null && !rs.wasNull()) {
obj = MAPPER.readValue(content, HashMap.class);
}
} catch (IOException e) {
throw new HibernateException(
"unable to read object from result set", e);
}
}
return obj;
}
@Override
public void nullSafeSet( PreparedStatement st,
Object value, int index,
SharedSessionContractImplementor session)
throws HibernateException, SQLException
{
if (value == null) {
st.setNull(index, Types.OTHER);
} else {
try {
st.setObject(index, MAPPER.writeValueAsString(value), Types.OTHER);
} catch (JsonProcessingException e) {
e.printStackTrace();
}
}
}
@Override
public Object deepCopy(Object value) throws HibernateException {
if (value == null) {
return null;
}
if (!(value instanceof Map)) {
return null;
}
Map<String, Object> resultMap = new HashMap<>();
Map<?, ?> tempMap = (Map<?, ?>) value;
tempMap.forEach((key, val) -> resultMap.put((String) key, val));
return resultMap;
}
@Override
public boolean isMutable() {
return false;
}
@Override