Details

    • Type: Feature Request
    • Status: Open (View Workflow)
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      The query interface allows for easy usage of JPA queries. Basically you annotate an interface as follows:

      public interface QueryInterface {
      		@QueryMethod("person.query.all")
      		List<Person> getAll();
       
      		@QueryMethod("person.select.by.name")
      		Person getPersonByName(@QueryParam("name") String name);
       
      		@QueryMethod(value = "person.select.by.name", nullable = true)
      		Person findPersonByName(@QueryParam("name") String name);
       
      		@QueryMethod("person.query.all")
      		Query getAllQuery();
      		
      		@QueryMethod(query = "SELECT COUNT(*) FROM Person")
      		Long countAll();
      	}
      

      Using some inject QueryInterfaceFactory you can get a proxy on this interface that will interpret the annotations towards JPA queries. See attached patch for a basic implementation.

        Gliffy Diagrams

        1. 0001-Query-Interface.patch
          17 kB
          Frank Cornelis
        2. 0002-Update-queries.patch
          6 kB
          Frank Cornelis
        3. 0003-Pagination.patch
          5 kB
          Frank Cornelis
        4. 0004-Query-Interface-injection.patch
          10 kB
          Frank Cornelis
        5. 0005-javadoc.patch
          8 kB
          Frank Cornelis

          Activity

          Hide
          swd847 Stuart Douglas added a comment -

          A few things:

          • Patches should be submitted as github pull requests, it makes it a lot easier to review than patch files
          • This should be using solder @ServiceHandler functionality
          Show
          swd847 Stuart Douglas added a comment - A few things: Patches should be submitted as github pull requests, it makes it a lot easier to review than patch files This should be using solder @ServiceHandler functionality
          Hide
          fcorneli Frank Cornelis added a comment -

          I've tried to used @ServiceHandler at first. But this one required the implementing handler class to be accessible from within an API annotation (@ServiceHandlerType), which would kind of void the separation between API and impl. This way, the query interface also doesn't need a TYPE annotation @QueryInterface (which would have a meta-annotation @ServiceHandlerType if implemented via Solder ServiceHandler). The QueryInterfaceExtension marks an interface as being a query interface by creating a corresponding bean if the interface contains a method annotated with @QueryMethod, which is quite clean. The @Inject also doesn't need any qualifier, it can directly inject the query interface proxies.

          Anyway, as I'm new to CDI, there are probably cleaner ways to implement this feature.

          I'll try setting up a github thing.

          Show
          fcorneli Frank Cornelis added a comment - I've tried to used @ServiceHandler at first. But this one required the implementing handler class to be accessible from within an API annotation (@ServiceHandlerType), which would kind of void the separation between API and impl. This way, the query interface also doesn't need a TYPE annotation @QueryInterface (which would have a meta-annotation @ServiceHandlerType if implemented via Solder ServiceHandler). The QueryInterfaceExtension marks an interface as being a query interface by creating a corresponding bean if the interface contains a method annotated with @QueryMethod, which is quite clean. The @Inject also doesn't need any qualifier, it can directly inject the query interface proxies. Anyway, as I'm new to CDI, there are probably cleaner ways to implement this feature. I'll try setting up a github thing.
          Show
          gastaldi George Gastaldi added a comment - What about merging http://ctpconsulting.github.com/query/1.0.0.Alpha2/index.html in ? More info: http://ctpjava.blogspot.com/2011/11/cdi-query-module-first-alpha-released.html

            People

            • Assignee:
              Unassigned
              Reporter:
              fcorneli Frank Cornelis
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:

                Development