Announcement

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

    DSRequest after PreparedStatement

    I have a PreparedStatement for doing a batch insert, which I execute using
    Code:
    batchStmt.executeBatch();
    This batchStmt executes a lot of INSERTs, that's why I am using it directly and not DSRequests.

    AFTER this batch insert I need to call a DSRequest in order to update the inserted values. I must be sure that the batch insert is completely finished before doing the DSRequest. How to achieve this? With smartGWT I would set the same RPCManager for both DSRequests, but here I don't have any RPCManager, since the first request is a PreparedStatement. So how to achieve this?

    Using smartgwt 5.1p 31.03 power

    #2
    We're not sure what you mean when you say you "don't have any RPCManager"..

    If you mean you are running a command line process, see the Standalone DataSource Usage overview.

    If you mean you just don't understand how to have an RPCManager in this instance, see this sample showing how to use the JDBC API while still participating in an RPCManager-managed transaction.

    Comment


      #3
      The example (http://www.smartclient.com/smartgwte...jdbcOperations) seems to be what I need, since I am not running a standalone process and I am able to run normal DSRequests.

      What I am asking is how to combine JDBC Inserts and a DSRequest after the inserts, and make sure the JDBC Inserts are finished before executing the DSRequest.

      So I have JDBC Inserts:
      Code:
      PreparedStatement batchStmt = con.prepareStatement(insertSql);
      ....
      batchStmt.executeBatch();
      And then:
      Code:
      DSRequest request = new DSRequest("ds", "fetch");
      Since the DSRequest is a fetch, and I am using the data inserted by the JDBC inserts, I need to know that the Inserts are finished before doing the DSRequest.

      I looked at your example and I see:
      Code:
      Connection conn = (Connection)((BasicDataSource)req.getDataSource()).getTransactionObject(req);
      But, since my DSRequest is a server-side created request, created after I execute the JDBC Inserts, and not part of a transaction, I always get con = null.
      Normally, for my JDBC Inserts, I get the connection this way:
      Code:
      con = DriverManager.getConnection(sqlConnectionString);
      Another question: maybe I don't need transactions for this purpose?
      After my java code returns from the call to
      Code:
      batchStmt.executeBatch();
      are the Insert statements already in the DB? If this is true, I could directly call my DSRequest, since the Inserts are already in the DB. Do you know if this is the case?

      Comment


        #4
        Hi Edulid,

        isn't all SmartGWT server side request processing synchronous?
        Code:
        batchStmt.executeBatch();
        DSResponse yourResp = yourFetch.execute();
        should execute in order. Problem is when the batchStmt uses a transaction and the yourFetch does not use the same transaction. Then the transaction of batchStmt must be committed before you start your fetch.

        Best regards
        Blama

        Comment


          #5
          Ok, but executing batchStmt with batchStmt.executeBatch() should be synchronous or ?
          If I write:

          Code:
           batchStmt.executeBatch();
          conn.commit();
          DSResponse yourResp = yourFetch.execute();
          would this execute in order and would the DSResponse see the inserts inserted by the batchStmt?

          Comment


            #6
            Hi edulid,

            I'd expect it to do that. Are you saying that it does not?

            Best regards
            Blama

            Comment


              #7
              I am asking if it does that ;-) I always worked directly with DSRequests, so I am not sure if JDBC executes() are also synchronous

              Comment


                #8
                Hm, if this is true, why am I getting a deadlock on the db? The table I am inserting to is locked and the DSRequest is waiting for the lock ...

                Comment


                  #9
                  What if the JDBC and the DSRequest use different connections? As they do, since the connection for the JDCB Request is created by
                  con = DriverManager.getConnection(sqlConnectionString);

                  Comment


                    #10
                    IMHO there should be no deadlock possible after all writes have been committed.
                    Even before, as your batch does inserts and not updates I don't think you should have a deadlock, but this might depend on database and used isolation.
                    Anyway - after a commit everything should be fine. If you say it is not, what happens if you close the connection you created?

                    Comment

                    Working...
                    X