Package com.querydsl.codegen
Class GenericExporter
java.lang.Object
com.querydsl.codegen.GenericExporter
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 Summary
ConstructorsConstructorDescriptionCreate a GenericExporter instance using the context classloader and default charsetGenericExporter(ClassLoader classLoader) Create a GenericExporter instance using the given classloader and default charsetGenericExporter(ClassLoader classLoader, Charset charset) Create a GenericExporter instance using the given classloader and charset for serializing source filesGenericExporter(Charset charset) Create a GenericExporter instance using the context classloader and the given charset -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAnnotationHelper(AnnotationHelper annotationHelper) Add a annotation helper object to process custom annotationsvoidaddStopClass(Class<?> cl) Add a stop class to be used (default Object.class and Enum.class)voidExport the given classesvoidExport the given packagesvoidExport the given packagesReturn the set of generated filesvoidsetCreateScalaSources(boolean createScalaSources) Set whether Scala sources are generatedvoidsetEmbeddableAnnotation(Class<? extends Annotation> embeddableAnnotation) Set the embeddable annotationvoidsetEmbeddedAnnotation(Class<? extends Annotation> embeddedAnnotation) Set the embedded annotationvoidsetEntityAnnotation(Class<? extends Annotation> entityAnnotation) Set the entity annotationvoidsetGeneratedAnnotationClass(@Nullable String generatedAnnotationClass) Set the Generated annotation class.voidsetHandleFields(boolean b) Deprecated.voidsetHandleMethods(boolean b) Deprecated.UsesetPropertyHandling(PropertyHandling)insteadvoidsetKeywords(Collection<String> keywords) Set the keywords to be usedvoidsetNamePrefix(String prefix) Set the name prefixvoidsetNameSuffix(String suffix) Set the name suffixvoidsetPackageSuffix(String suffix) Set the package suffixvoidsetPropertyHandling(PropertyHandling propertyHandling) Set the property handling modevoidsetSerializerClass(Class<? extends Serializer> serializerClass) Set the serializer class to be usedvoidsetSerializerConfig(SerializerConfig serializerConfig) Set the serializer configuration to usevoidsetSkipAnnotation(Class<? extends Annotation> skipAnnotation) Set the skip annotationvoidsetStrictMode(boolean s) Set whether annotationless superclasses are handled or not (default: true)voidsetSupertypeAnnotation(Class<? extends Annotation> supertypeAnnotation) Set the supertype annotationvoidsetTargetFolder(File targetFolder) Set the target folder for generated sourcesvoidsetTypeMappingsClass(Class<? extends TypeMappings> typeMappingsClass) Set the typemappings class to be usedvoidsetUseFieldTypes(boolean b) Set whether field types should be used instead of getter return types (default false)
-
Constructor Details
-
GenericExporter
Create a GenericExporter instance using the given classloader and charset for serializing source files- Parameters:
classLoader- classloader to usecharset- charset of target sources
-
GenericExporter
Create a GenericExporter instance using the given classloader and default charset- Parameters:
classLoader- classloader to use
-
GenericExporter
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
Export the given packages- Parameters:
packages- packages to be scanned
-
export
Export the given packages- Parameters:
packages- packages to be scanned
-
export
Export the given classes- Parameters:
classes- classes to be scanned
-
getGeneratedFiles
Return the set of generated files- Returns:
- a set of generated files
-
setEntityAnnotation
Set the entity annotation- Parameters:
entityAnnotation- entity annotation
-
setSupertypeAnnotation
Set the supertype annotation- Parameters:
supertypeAnnotation- supertype annotation
-
setEmbeddableAnnotation
Set the embeddable annotation- Parameters:
embeddableAnnotation- embeddable annotation
-
setEmbeddedAnnotation
Set the embedded annotation- Parameters:
embeddedAnnotation- embedded annotation
-
setSkipAnnotation
Set the skip annotation- Parameters:
skipAnnotation- skip annotation
-
setTargetFolder
Set the target folder for generated sources- Parameters:
targetFolder-
-
setSerializerClass
Set the serializer class to be used- Parameters:
serializerClass-
-
setTypeMappingsClass
Set the typemappings class to be used- Parameters:
typeMappingsClass-
-
setCreateScalaSources
public void setCreateScalaSources(boolean createScalaSources) Set whether Scala sources are generated- Parameters:
createScalaSources-
-
setKeywords
Set the keywords to be used- Parameters:
keywords-
-
setNamePrefix
Set the name prefix- Parameters:
prefix-
-
setNameSuffix
Set the name suffix- Parameters:
suffix-
-
setPackageSuffix
Set the package suffix- Parameters:
suffix-
-
setHandleFields
Deprecated.UsesetPropertyHandling(PropertyHandling)insteadSet whether fields are handled (default true)- Parameters:
b-
-
setHandleMethods
Deprecated.UsesetPropertyHandling(PropertyHandling)insteadSet whether methods are handled (default true)- Parameters:
b-
-
setPropertyHandling
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
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
Set the serializer configuration to use- Parameters:
serializerConfig-
-
addAnnotationHelper
Add a annotation helper object to process custom annotations- Parameters:
annotationHelper-
-
setGeneratedAnnotationClass
Set the Generated annotation class. Will default to java@Generated- Parameters:
generatedAnnotationClass- the fully qualified class name of the Single-Element Annotation (withStringelement) to be used on the generated sources, ornull(defaulting tojavax.annotation.Generatedorjavax.annotation.processing.Generateddepending on the java version).- See Also:
-
setPropertyHandling(PropertyHandling)instead