javax.persistence.Converter Java Examples

The following examples show how to use javax.persistence.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: ClassFileArchiveEntryHandler.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ClassDescriptor toClassDescriptor(ClassFile classFile, ArchiveEntry entry) {
	ClassDescriptor.Categorization categorization = ClassDescriptor.Categorization.OTHER;;

	final AnnotationsAttribute visibleAnnotations = (AnnotationsAttribute) classFile.getAttribute( AnnotationsAttribute.visibleTag );
	if ( visibleAnnotations != null ) {
		if ( visibleAnnotations.getAnnotation( Entity.class.getName() ) != null
				|| visibleAnnotations.getAnnotation( MappedSuperclass.class.getName() ) != null
				|| visibleAnnotations.getAnnotation( Embeddable.class.getName() ) != null ) {
			categorization = ClassDescriptor.Categorization.MODEL;
		}
		else if ( visibleAnnotations.getAnnotation( Converter.class.getName() ) != null ) {
			categorization = ClassDescriptor.Categorization.CONVERTER;
		}
	}

	return new ClassDescriptorImpl( classFile.getName(), categorization, entry.getStreamAccess() );
}
 
Example #2
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 #3
Source File: AnnotationMetadataSourceProcessorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void categorizeAnnotatedClass(Class annotatedClass, AttributeConverterManager attributeConverterManager) {
	final XClass xClass = reflectionManager.toXClass( annotatedClass );
	// categorize it, based on assumption it does not fall into multiple categories
	if ( xClass.isAnnotationPresent( Converter.class ) ) {
		//noinspection unchecked
		attributeConverterManager.addAttributeConverter( annotatedClass );
	}
	else if ( xClass.isAnnotationPresent( Entity.class )
			|| xClass.isAnnotationPresent( MappedSuperclass.class ) ) {
		xClasses.add( xClass );
	}
	else if ( xClass.isAnnotationPresent( Embeddable.class ) ) {
		xClasses.add( xClass );
	}
	else {
		log.debugf( "Encountered a non-categorized annotated class [%s]; ignoring", annotatedClass.getName() );
	}
}
 
Example #4
Source File: AbstractVKeyProcessor.java    From nomulus with Apache License 2.0 5 votes vote down vote up
private JavaFile createJavaFile(
    String packageName, String converterClassName, TypeMirror entityTypeMirror) {
  TypeName entityType = ClassName.get(entityTypeMirror);

  ParameterizedTypeName attributeConverter =
      ParameterizedTypeName.get(
          ClassName.get("google.registry.persistence.converter", "VKeyConverter"),
          entityType,
          ClassName.get(getSqlColumnType()));

  MethodSpec getAttributeClass =
      MethodSpec.methodBuilder("getAttributeClass")
          .addAnnotation(Override.class)
          .addModifiers(Modifier.PROTECTED)
          .returns(
              ParameterizedTypeName.get(
                  ClassName.get(Class.class), ClassName.get(entityTypeMirror)))
          .addStatement("return $T.class", entityType)
          .build();

  TypeSpec vKeyConverter =
      TypeSpec.classBuilder(converterClassName)
          .addAnnotation(
              AnnotationSpec.builder(ClassName.get(Converter.class))
                  .addMember("autoApply", "true")
                  .build())
          .addModifiers(Modifier.FINAL)
          .superclass(attributeConverter)
          .addMethod(getAttributeClass)
          .build();

  return JavaFile.builder(packageName, vKeyConverter).build();
}
 
Example #5
Source File: EclipselinkStaticWeaveMojo.java    From eclipselink-maven-plugin with Apache License 2.0 5 votes vote down vote up
private Set<String> findEntities(String[] allBasePackages, final URL[] classPath)
{
    final Set<String> result = new TreeSet<>();

    try (final ScanResult scanResult = new ClassGraph().whitelistPackages(allBasePackages).enableAnnotationInfo().overrideClasspath((Object[]) classPath).scan())
    {
        result.addAll(extract(scanResult, Entity.class));
        result.addAll(extract(scanResult, MappedSuperclass.class));
        result.addAll(extract(scanResult, Embeddable.class));
        result.addAll(extract(scanResult, Converter.class));
    }
    return result;
}
 
Example #6
Source File: CandidateComponentsIndexerTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void persistenceConverter() {
	testSingleComponent(SampleConverter.class, Converter.class);
}
 
Example #7
Source File: CandidateComponentsIndexerTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void persistenceConverter() {
	testSingleComponent(SampleConverter.class, Converter.class);
}
 
Example #8
Source File: ConverterScanner.java    From minnal with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean match(Class<?> clazz) {
	return clazz.isAnnotationPresent(Converter.class);
}
 
Example #9
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 );
}