Package org.datanucleus.jdo.query
Class JDOQueryProcessor
- java.lang.Object
-
- javax.annotation.processing.AbstractProcessor
-
- org.datanucleus.jdo.query.JDOQueryProcessor
-
- All Implemented Interfaces:
Processor
@SupportedAnnotationTypes("javax.jdo.annotations.PersistenceCapable") public class JDOQueryProcessor extends AbstractProcessor
Annotation processor for JDO to generate "dummy" classes for all persistable classes for use with the JDOQLTypedQuery API. Any class ({MyClass}) that has a JDO "class" annotation will have a stub class (Q{MyClass}) generated.- For each managed class X in package p, a metamodel class QX in package p is created.
- The name of the metamodel class is derived from the name of the managed class by prepending "Q" to the name of the managed class.
This processor can generate classes in two modes.
- Property access - so users type in "field1()", "field1().field2()" etc. Specify the compiler argument "queryMode" as "PROPERTY" to get this
- Field access - so users type in "field1", "field1.field2". This is the default.
-
-
Field Summary
Fields Modifier and Type Field Description int
fieldDepth
Max field depth to use when generating references to the related Q class(es).static String
OPTION_MODE
int
queryMode
-
Fields inherited from class javax.annotation.processing.AbstractProcessor
processingEnv
-
-
Constructor Summary
Constructors Constructor Description JDOQueryProcessor()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addConstructorWithPersistableExpression(Writer w, String indent, String qclassNameSimple, TypeElement superEl, List<? extends Element> members, String classNameFull, Map<String,TypeMirror> genericLookups)
Method to add the code for a constructor taking in (PersistableExpression parent, String name, int depth).protected void
addConstructorWithType(Writer w, String indent, String qclassNameSimple, List<? extends Element> members, String classNameFull, Map<String,TypeMirror> genericLookups)
Method to add the code for a constructor taking in (Class type, String name, ExpressionType exprType).protected void
addPropertyAccessorMethod(Writer w, String indent, Element member, String classNameFull, Map<String,TypeMirror> genericLookups)
Generate accessor for a property.protected void
addStaticMethodAccessors(Writer w, String indent, String qclassNameSimple, String classNameSimple)
Method to add the code for static method accessors needed by this QClass.TypeElement
getPersistentSupertype(TypeElement element)
Method to find the next persistent supertype above this one.static String
getQueryClassNameForClassName(String name)
Method to return the (simple) name of the query class for a specified class name.SourceVersion
getSupportedSourceVersion()
void
init(ProcessingEnvironment pe)
boolean
process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
protected void
processClass(TypeElement el)
Handler for processing a JDO annotated class to create the criteria class stub.-
Methods inherited from class javax.annotation.processing.AbstractProcessor
getCompletions, getSupportedAnnotationTypes, getSupportedOptions, isInitialized
-
-
-
-
Field Detail
-
OPTION_MODE
public static final String OPTION_MODE
- See Also:
- Constant Field Values
-
queryMode
public int queryMode
-
fieldDepth
public int fieldDepth
Max field depth to use when generating references to the related Q class(es).
-
-
Method Detail
-
init
public void init(ProcessingEnvironment pe)
- Specified by:
init
in interfaceProcessor
- Overrides:
init
in classAbstractProcessor
-
process
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv)
- Specified by:
process
in interfaceProcessor
- Specified by:
process
in classAbstractProcessor
-
getSupportedSourceVersion
public SourceVersion getSupportedSourceVersion()
- Specified by:
getSupportedSourceVersion
in interfaceProcessor
- Overrides:
getSupportedSourceVersion
in classAbstractProcessor
-
processClass
protected void processClass(TypeElement el)
Handler for processing a JDO annotated class to create the criteria class stub.- Parameters:
el
- The class element
-
addStaticMethodAccessors
protected void addStaticMethodAccessors(Writer w, String indent, String qclassNameSimple, String classNameSimple) throws IOException
Method to add the code for static method accessors needed by this QClass.- Parameters:
w
- The writerindent
- Indent to apply to the codeqclassNameSimple
- Simple name of the QClass that this is constructingclassNameSimple
- Simple name of this persistable class- Throws:
IOException
- Thrown if an error occurs on writing this code
-
addConstructorWithPersistableExpression
protected void addConstructorWithPersistableExpression(Writer w, String indent, String qclassNameSimple, TypeElement superEl, List<? extends Element> members, String classNameFull, Map<String,TypeMirror> genericLookups) throws IOException
Method to add the code for a constructor taking in (PersistableExpression parent, String name, int depth).- Parameters:
w
- The writerindent
- Indent to apply to the codeqclassNameSimple
- Simple name of the QClass that this is constructingsuperEl
- Any super elementmembers
- Members for this QClass that need initialisingclassNameFull
- Fully qualified class namegenericLookups
- Lookup for TypeVariables- Throws:
IOException
- Thrown if an error occurs on writing this code
-
addConstructorWithType
protected void addConstructorWithType(Writer w, String indent, String qclassNameSimple, List<? extends Element> members, String classNameFull, Map<String,TypeMirror> genericLookups) throws IOException
Method to add the code for a constructor taking in (Class type, String name, ExpressionType exprType).- Parameters:
w
- The writerindent
- Indent to apply to the codeqclassNameSimple
- Simple name of the QClass that this is constructingmembers
- Members for this QClass that need initialisingclassNameFull
- Fully qualified class namegenericLookups
- Lookup for TypeVariables- Throws:
IOException
- Thrown if an error occurs on writing this code
-
addPropertyAccessorMethod
protected void addPropertyAccessorMethod(Writer w, String indent, Element member, String classNameFull, Map<String,TypeMirror> genericLookups) throws IOException
Generate accessor for a property.public {type} {memberName}() { if (memberVar == null) { this.memberVar = new {implClassName}(this, \"memberName\"); } return this.memberVar; }
- Parameters:
w
- The writerindent
- The indent to usemember
- The member we are generating forclassNameFull
- Fully qualified class namegenericLookups
- Lookup for TypeVariables- Throws:
IOException
- Thrown if an exception occurs during generation
-
getPersistentSupertype
public TypeElement getPersistentSupertype(TypeElement element)
Method to find the next persistent supertype above this one.- Parameters:
element
- The element- Returns:
- Its next parent that is persistable (or null if no persistable predecessors)
-
getQueryClassNameForClassName
public static String getQueryClassNameForClassName(String name)
Method to return the (simple) name of the query class for a specified class name. Currently just returns "Q{className}"- Parameters:
name
- Simple name of the class (without package)- Returns:
- Simple name of the query class
-
-