Java Code Examples for javax.persistence.Converter#autoApply()

The following examples show how to use javax.persistence.Converter#autoApply() . 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: AbstractConverterDescriptor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private AutoApplicableConverterDescriptor resolveAutoApplicableDescriptor(
		Class<? extends AttributeConverter> converterClass,
		Boolean forceAutoApply) {
	final boolean autoApply;

	if ( forceAutoApply != null ) {
		// if the caller explicitly specified whether to auto-apply, honor that
		autoApply = forceAutoApply;
	}
	else {
		// otherwise, look at the converter's @Converter annotation
		final Converter annotation = converterClass.getAnnotation( Converter.class );
		autoApply = annotation != null && annotation.autoApply();
	}

	return autoApply
			? new AutoApplicableConverterDescriptorStandardImpl( this )
			: AutoApplicableConverterDescriptorBypassedImpl.INSTANCE;
}
 
Example 2
Source File: AttributeConverterDefinition.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Build an AttributeConverterDefinition from an AttributeConverter instance.  The
 * converter is searched for a {@link Converter} annotation	 to determine whether it should
 * be treated as auto-apply.  If the annotation is present, {@link Converter#autoApply()} is
 * used to make that determination.  If the annotation is not present, {@code false} is assumed.
 *
 * @param attributeConverter The AttributeConverter instance
 *
 * @return The constructed definition
 */
public static AttributeConverterDefinition from(AttributeConverter attributeConverter) {
	boolean autoApply = false;
	Converter converterAnnotation = attributeConverter.getClass().getAnnotation( Converter.class );
	if ( converterAnnotation != null ) {
		autoApply = converterAnnotation.autoApply();
	}

	return new AttributeConverterDefinition( attributeConverter, autoApply );
}