Java Code Examples for javax.persistence.Convert#converter()

The following examples show how to use javax.persistence.Convert#converter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccessibleProperty.java    From warpdb with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: AttributeConversionInfo.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public AttributeConversionInfo(Convert convertAnnotation, XAnnotatedElement xAnnotatedElement) {
	this(
			convertAnnotation.converter(),
			convertAnnotation.disableConversion(),
			convertAnnotation.attributeName(),
			xAnnotatedElement
	);
}