Class 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 Detail

      • queryMode

        public int queryMode
      • fieldDepth

        public int fieldDepth
        Max field depth to use when generating references to the related Q class(es).
    • Constructor Detail

      • JDOQueryProcessor

        public JDOQueryProcessor()
    • Method Detail

      • 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 writer
        indent - Indent to apply to the code
        qclassNameSimple - Simple name of the QClass that this is constructing
        classNameSimple - 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 writer
        indent - Indent to apply to the code
        qclassNameSimple - Simple name of the QClass that this is constructing
        superEl - Any super element
        members - Members for this QClass that need initialising
        classNameFull - Fully qualified class name
        genericLookups - 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 writer
        indent - Indent to apply to the code
        qclassNameSimple - Simple name of the QClass that this is constructing
        members - Members for this QClass that need initialising
        classNameFull - Fully qualified class name
        genericLookups - 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 writer
        indent - The indent to use
        member - The member we are generating for
        classNameFull - Fully qualified class name
        genericLookups - 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