Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    JPA queries - JpaDataSource, EMFProviderCMT

    Hi,
    i am integrating SmartGWT (Power 3.0) CMT in my application.

    I am correctly executing stardard fetch and update operations, and some simple custom jpa queries using SmartGwt AdvancedFilter.


    I have some questions about custom jpa queries:

    1) Is there a way to execute custom jpa queries such as the definition of customSQL is .ds.xml?
    2) Is there a way to execute a jpa @NamedQuery defined in entity bean?



    Thanks in advance for your help.



    Giervella

    #2
    In both cases, you can use a DMI to do this. There is not currently a declarative way to do it similar to <customSQL> for SQLDataSource.

    Comment


      #3
      "In both cases, you can use a DMI to do this."
      What i understand is something like that:


      class DMI() {

      @PersistenceContext(name="xx", unitName="xx")
      private EntityManager em;

      /**
      * Default constructor.
      */
      public DMI() {
      // TODO Auto-generated constructor stub
      }


      @Override
      public DSResponse fetch(DSRequest dsRequest) throws Exception {

      DSResponse dsResponse = new DSResponse();

      Query query = em.createNamedQuery("fetchTest");
      @SuppressWarnings("unchecked")
      List<Entity> list = query.getResultList();


      dsResponse.setData(list);

      return dsResponse;
      }

      }

      Is this what you mean?

      Comment


        #4
        Yes, that plus the declaration in the .ds.xml file to call your method. The QuickStart Guide has lots more details.

        Comment


          #5
          Ok.
          So, i have a question:

          is there a way to execute the same custom jpa query ("fetchTest") defined in entity class through the built-in objects (EntityManager, ecc..) defined in EMFProviderCMT?
          I am saying, is there a way to execute that query in the following way? :

          @Override
          public DSResponse fetch(DSRequest dsRequest) throws Exception {

          return dsRequest.execute();
          }



          Thank you,

          Giervella

          Comment


            #6
            This seems to be asking if there's a way to simply declare the custom query without writing Java. There isn't - that's what we meant by "There is not currently a declarative way to do it".

            If your question was something else, please clarify.

            Comment


              #7
              This was exactly my question.
              I was looking for a way to generate and execute jpa queries through the SmartGwt engine built-in classes.

              So, at last, what i understand is:
              1) i can execute through the engine built-in classes (dsResponse.execute()) only the engine built-in jpa queries;
              2) i can make customized engine built-in jpa queries only through SmartGwt client objects as Criteria, AdvancedCriteria, .. ;

              Is it right?


              Thank you,


              Giervella

              Comment


                #8
                No.. have you read the QuickStart Guide yet? We referred to DMI, which is a server-side way to execute arbitrary logic in response to a DSRequest, but your question/conclusion suggests that you haven't read about DMI at all, because you're referring to client-side objects only.

                Comment


                  #9
                  Sorry, you are right, i referred only to client-side object, but i know the server-side objects.

                  My statement was:
                  2) i can make customized engine built-in jpa queries only through SmartGwt client/server side objects;

                  I mean:
                  because, as you say, there isn't currently a declarative way to make custom jpa queries, i can do it through the client and server side SmartGwt classes. The engine will make the jpa queries for me.


                  Are there errors in my conclusions?


                  Thank you for your help Isomorphic,


                  Giervella

                  Comment


                    #10
                    The statement is still oddly phrased and we can't honestly tell whether you now understand or not.

                    DMI lets you insert arbitrary Java code into the midst of the standard SmartGWT server flow. So you can call any JPA API you need, and then return results.

                    Comment


                      #11
                      We didn't chat about "any JPA API", but about SmartGwt JPA API.
                      However, this thread was very helpful for me.

                      Thank you for your help.


                      Giervella

                      Comment

                      Working...
                      X