Class GenericExporter

java.lang.Object
com.querydsl.codegen.GenericExporter

public class GenericExporter extends Object
GenericExporter provides query type serialization logic for cases where APT annotation processors can't be used. GenericExporter scans the classpath for classes annotated with specified annotations in specific packages and mirrors them into Querydsl expression types.

Example with Querydsl annotations:

 
 GenericExporter exporter = new GenericExporter();
 exporter.setTargetFolder(new File("target/generated-sources/java"));
 exporter.export(com.example.domain.Entity.class.getPackage());
 

Example with JPA annotations:

 
 GenericExporter exporter = new GenericExporter();
 exporter.setKeywords(Keywords.JPA);
 exporter.setEntityAnnotation(Entity.class);
 exporter.setEmbeddableAnnotation(Embeddable.class);
 exporter.setEmbeddedAnnotation(Embedded.class);
 exporter.setSupertypeAnnotation(MappedSuperclass.class);
 exporter.setSkipAnnotation(Transient.class);
 exporter.setTargetFolder(new File("target/generated-sources/java"));
 exporter.export(com.example.domain.Entity.class.getPackage());
 
Author:
tiwe
  • Constructor Details

    • GenericExporter

      public GenericExporter(ClassLoader classLoader, Charset charset)
      Create a GenericExporter instance using the given classloader and charset for serializing source files
      Parameters:
      classLoader - classloader to use
      charset - charset of target sources
    • GenericExporter

      public GenericExporter(ClassLoader classLoader)
      Create a GenericExporter instance using the given classloader and default charset
      Parameters:
      classLoader - classloader to use
    • GenericExporter

      public GenericExporter(Charset charset)
      Create a GenericExporter instance using the context classloader and the given charset
      Parameters:
      charset - charset of target sources
    • GenericExporter

      public GenericExporter()
      Create a GenericExporter instance using the context classloader and default charset
  • Method Details

    • export

      public void export(Package... packages)
      Export the given packages
      Parameters:
      packages - packages to be scanned
    • export

      public void export(String... packages)
      Export the given packages
      Parameters:
      packages - packages to be scanned
    • export

      public void export(Class<?>... classes)
      Export the given classes
      Parameters:
      classes - classes to be scanned
    • getGeneratedFiles

      public Set<File> getGeneratedFiles()
      Return the set of generated files
      Returns:
      a set of generated files
    • setEntityAnnotation

      public void setEntityAnnotation(Class<? extends Annotation> entityAnnotation)
      Set the entity annotation
      Parameters:
      entityAnnotation - entity annotation
    • setSupertypeAnnotation

      public void setSupertypeAnnotation(Class<? extends Annotation> supertypeAnnotation)
      Set the supertype annotation
      Parameters:
      supertypeAnnotation - supertype annotation
    • setEmbeddableAnnotation

      public void setEmbeddableAnnotation(Class<? extends Annotation> embeddableAnnotation)
      Set the embeddable annotation
      Parameters:
      embeddableAnnotation - embeddable annotation
    • setEmbeddedAnnotation

      public void setEmbeddedAnnotation(Class<? extends Annotation> embeddedAnnotation)
      Set the embedded annotation
      Parameters:
      embeddedAnnotation - embedded annotation
    • setSkipAnnotation

      public void setSkipAnnotation(Class<? extends Annotation> skipAnnotation)
      Set the skip annotation
      Parameters:
      skipAnnotation - skip annotation
    • setTargetFolder

      public void setTargetFolder(File targetFolder)
      Set the target folder for generated sources
      Parameters:
      targetFolder -
    • setSerializerClass

      public void setSerializerClass(Class<? extends Serializer> serializerClass)
      Set the serializer class to be used
      Parameters:
      serializerClass -
    • setTypeMappingsClass

      public void setTypeMappingsClass(Class<? extends TypeMappings> typeMappingsClass)
      Set the typemappings class to be used
      Parameters:
      typeMappingsClass -
    • setCreateScalaSources

      public void setCreateScalaSources(boolean createScalaSources)
      Set whether Scala sources are generated
      Parameters:
      createScalaSources -
    • setKeywords

      public void setKeywords(Collection<String> keywords)
      Set the keywords to be used
      Parameters:
      keywords -
    • setNamePrefix

      public void setNamePrefix(String prefix)
      Set the name prefix
      Parameters:
      prefix -
    • setNameSuffix

      public void setNameSuffix(String suffix)
      Set the name suffix
      Parameters:
      suffix -
    • setPackageSuffix

      public void setPackageSuffix(String suffix)
      Set the package suffix
      Parameters:
      suffix -
    • setHandleFields

      @Deprecated public void setHandleFields(boolean b)
      Deprecated.
      Set whether fields are handled (default true)
      Parameters:
      b -
    • setHandleMethods

      @Deprecated public void setHandleMethods(boolean b)
      Deprecated.
      Set whether methods are handled (default true)
      Parameters:
      b -
    • setPropertyHandling

      public void setPropertyHandling(PropertyHandling propertyHandling)
      Set the property handling mode
      Parameters:
      propertyHandling -
    • setUseFieldTypes

      public void setUseFieldTypes(boolean b)
      Set whether field types should be used instead of getter return types (default false)
      Parameters:
      b -
    • addStopClass

      public void addStopClass(Class<?> cl)
      Add a stop class to be used (default Object.class and Enum.class)
      Parameters:
      cl -
    • setStrictMode

      public void setStrictMode(boolean s)
      Set whether annotationless superclasses are handled or not (default: true)
      Parameters:
      s -
    • setSerializerConfig

      public void setSerializerConfig(SerializerConfig serializerConfig)
      Set the serializer configuration to use
      Parameters:
      serializerConfig -
    • addAnnotationHelper

      public void addAnnotationHelper(AnnotationHelper annotationHelper)
      Add a annotation helper object to process custom annotations
      Parameters:
      annotationHelper -
    • setGeneratedAnnotationClass

      public void setGeneratedAnnotationClass(@Nullable @Nullable String generatedAnnotationClass)
      Set the Generated annotation class. Will default to java @Generated
      Parameters:
      generatedAnnotationClass - the fully qualified class name of the Single-Element Annotation (with String element) to be used on the generated sources, or null (defaulting to javax.annotation.Generated or javax.annotation.processing.Generated depending on the java version).
      See Also: