下面列出了javax.persistence.Convert#converter ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@SuppressWarnings("unchecked")
private AttributeConverter<Object, Object> getConverter(AccessibleObject accessible) {
Convert converter = accessible.getAnnotation(Convert.class);
if (converter != null) {
Class<?> converterClass = converter.converter();
if (!AttributeConverter.class.isAssignableFrom(converterClass)) {
throw new RuntimeException(
"Converter class must be AttributeConverter rather than " + converterClass.getName());
}
try {
Constructor<?> cs = converterClass.getDeclaredConstructor();
cs.setAccessible(true);
return (AttributeConverter<Object, Object>) cs.newInstance();
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | SecurityException
| InvocationTargetException e) {
throw new RuntimeException("Cannot instantiate Converter: " + converterClass.getName(), e);
}
}
return null;
}
@SuppressWarnings("unchecked")
public AttributeConversionInfo(Convert convertAnnotation, XAnnotatedElement xAnnotatedElement) {
this(
convertAnnotation.converter(),
convertAnnotation.disableConversion(),
convertAnnotation.attributeName(),
xAnnotatedElement
);
}