Uploaded image for project: 'Cayenne'
  1. Cayenne
  2. CAY-1070

Generating SelectQuery Access Code

    XMLWordPrintableJSON

Details

    • Task
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0
    • 3.0M5
    • Core Library
    • None

    Description

      The original request for this feature was submitted as CAY-995. I am using a separate Jira to better formulate what needs to be done and provide the context. The goal to generate a flexible type-safe code to invoke mapped select queries.

      1. This feature should initially target class generation with Ant (via 'cgen' task [1]), although backend should be done in a way that should be later reusable with CayenneModeler and Maven plugins (actually all code generation stuff is done like that, so it won't be hard to follow).

      2. The new feature will be activated in the "datamap" cgen "mode" (default mode is "entity"). Until now "datamap" mode always required a custom template to make any sense at all. Now it will result in generating a default predefined Java class (with a superclass if "makepairs" is true) per DataMap.

      3. The new standard Velocity templates need to be created for "datamap" mode under "resources/dotemplates/v1_2", one for singleclass generation and two for subclass/superclass generation. Just like with persistent Java class templates, datamap-subclass.vm should be an empty class inheriting from a generated superclass; datamap-superclass.vm and datamap-singleclass.vm should be essentially the same thing except for the class name.

      4. Generated class name should be derived from DataMap name and use DataMap.getDefaultPackage() for the package name. All non-Java identifier characters in the DataMap name should be replaced (with "" ??) when deriving a class name. Superclass in a makepairs generation mode should be prefixed with "" (same as persistent Java classes).

      5. Generated classes must include the following:

      • A singleton method that returns a static final instance of the class:

      protected static MyDataMap instance = new MyDataMap();

      public static MyDataMap getInstance()

      { return instance; }

      • A method for each mapped query. For each SelectQuery, a method would look like this:

      public List<EntityClass> performQuery1(ObjectContext context, Object parameter1, Object parameter2, ...)

      { // bind parameters and // run the query here }

      The number, names and order of parameters must match that of the mapped query (for SelectQuery that would require parsing qualifier expression to search for parameter nodes). also do something smart about parameter types (we can sort of guess them in SelectQuery), but this is not required for version 1 of the feature.

      [1] http://cayenne.apache.org/doc/cgen.html

      Attachments

        1. NamingFixes.patch
          3 kB
          Dzmitry Rusak
        2. DataMapGeneration.patch
          36 kB
          Dzmitry Rusak

        Issue Links

          Activity

            People

              andrus Andrus Adamchik
              andrus Andrus Adamchik
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: