Announcement

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

    Should batch uploader update if record exists with same primary key?

    I'm testing the batch uploader component and it seems that it only generates add requests to the server, not updates if a record with matching primary key already exists. I can't seem to find any documentation for BatchUploader. Is it limited to inserts only?

    #2
    The built-in BatchUploader assumes inserts only, yes. However on the server-side, you're free to implement the add() operation as conditionally being an update instead.

    Comment


      #3
      Is there any way for the server-side code to know whether the request is coming from the BatchUploader? We want normal add requests to be handled as usual, but we want BatchUploader requests to use update-or-add logic.

      Comment


        #4
        The BatchUpload can target any DataSource, so that DataSource can be a facade that is actually doing "add" or "update" operations on another DataSource conditionally.

        Comment


          #5
          I was hoping for a more generalized solution. Unless I'm missing something, this would require a facade data source for every real data source we wanted to allow uploads to.

          We have a large number of data sources that use a generic editor component which includes the ability to upload using BatchUploader. All of our server-side code extends a single class so we were hoping to intercept the standard "add" request and, if it was from the BatchUploader, implement the conditional logic.

          Is there another technique you can recommend that would avoid the need for a separate facade datasource for every real datasource? I was hoping the DSRequest.getComponentId() would identify BatchUploader or maybe a way to set the operationId on the requests issued by BatchUploader.

          Comment


            #6
            A couple of ways to do this:

            1) create a reusable facade DataSource where the real target DataSource is specified as a custom property in .ds.xml "targetDataSource". This requires an extra .ds.xml per DataSource that supports batch upload, to eliminate that..

            2) give the BatchUploader a DataSource ID like targetDataSourceName_batchUpload. No .ds.xml file will exist for this; on the server you could either subclass IDACall to route them to custom code, or implement a strategy similar to the above via addDynamicDSGenerator() so that facade DataSources are automatically generated.

            Comment


              #7
              Option 2 sounds easy enough, but how do I "give the BatchUploader a DataSource ID like targetDataSourceName_batchUpload"? BatchUploader.setUploadDataSource() only takes an actual DataSource object as the argument, not a simple String data source name.

              Is there some way on the client side to clone a datasource to create one just like it with a different name?

              Comment


                #8
                Yes, use dataSource.setInheritsFrom().

                Comment


                  #9
                  Thanks for the help. I've got it working. Very nice feature.

                  Comment

                  Working...
                  X