Announcement

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

    Prefetching data to RestDataSource on module load

    Ok, this might be something I'm trying to do sideways, but I have the situation, where a few datasources contain metadata (EntityAttributes and AttributeTypes) , that I generate the rest of my business logic-related datasources with. So ideally, I would want to load the full set of data from those datasources on the application load, but allow the user to customize it (create/update/delete), and load the changes from the server, if any - but avoiding the first fetch request. Since I already do a call to the serverside to retrieve various configuration parameters from the serverside on module load, I figured it would be cool to return the data that would be otherwise queried using separate fetches in one go, and return the startRow, endRow, totalRows and the data for my configuration datasources in that call. I can construct DSResponse from that data successfully. There are a few methods that seemingly match my requirements, namely:


    Code:
    DataSource.updateCaches(DSResponse dsResponse)
    I was using something along the lines while testing:
    Code:
                        myDatasoure.updateCaches(new DSResponse(JSON.decode(result.getAttributeTypes())));
                         ResultSet rs = new ResultSet(myDatasoure);
                        rs.get(0);
    but rs.get(0) always triggers a fetch.

    There is also the

    Code:
    DataSource.processResponse(String requestId, DSResponse responseProperties)
    but I don't have a requestId there, and it fails if I pass a null or empty string here.

    Any hints would be greatly appreciated.

    regards,
    Andrius J.

    #2
    To answer my own question:

    Code:
            DataSource attributeTypeDS = RestDataSourceFactory.createAttributeTypeDS();
            ResultSet attributeTypeRS = new ResultSet(attributeTypeDS);
            JavaScriptObject decoded = JSON.decode(result.getAttributeTypesJson());
            attributeTypeRS.setAttribute("allRows", decoded, false);
    does just what I need - populates the result set with all the rows, and still catches all the CRUD events on dataArrived and dataChanged events.

    just in case anyone needs that :)

    regards,
    Andrius J.

    Comment

    Working...
    X