Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

CacheSync not Updating ListGrid?

$
0
0
Please save me from resorting to invalidateCache!

I'm having a couple issues with a CacheSync operation.

I have drag (COPY) & drop working mostly as desired between two ListGrids. However, I'm not having success in trying to address the use case of when a user repeatedly drags the same record. In that case, I want to ignore the drag (or prevent?)

What I'm seeing is that the first Drop is not updated on the ListGrid. Subsequent Drops are reflected, but they add a new row for each drop.

On the SQL side the Record is only the dropped Record appears only once, as expected. If I invalidateCache, the display is corrected to show the Record only once. But I want to avoid that.

Here is the DataSource w/ operation bindings:
Code:


<DataSource ID="favorites" serverType="sql" dataSourceVersion="1" dbName="myOracleSID" schema="myOracleSchema" tableName="FAVORITES">
 <fields>
  <field name="PK" type="sequence" primaryKey="true">
  <columnCode>1cd3c693132f4c31b5b5e5f4c5eed6bd</columnCode>
  </field>
  <field name="USERNAME" type="text" length="8">
  <columnCode>14c4b06b824ec593239362517f538b29</columnCode>
  </field>
  <field name="FAV_FORM_ID" title="Form #" type="text" length="20" foreignKey="DOCUMENTS.FORM_ID">
  <columnCode>cc2eb80c283048cec41fe4a65eb10e22</columnCode>
  </field>
  <field includeFrom="DOCUMENTS.TITLE"/>
  <field includeFrom="DOCUMENTS.DATE_REVISED"/>
  <field includeFrom="DOCUMENTS.FILETYPE"/>
  <field includeFrom="DOCUMENTS.DOCUMENT"/>
  <field includeFrom="DOCUMENTS.DOCUMENT_filename"/>
  <field includeFrom="DOCUMENTS.DOCUMENT_filesize"/>
  <field includeFrom="DOCUMENTS.DOCUMENT_date_created"/>
 </fields>
 
 <allowAdvancedCriteria>true</allowAdvancedCriteria>
 
 <operationBindings>
 
  <!--  This is used onModuleLoad, works fine -->
 
  <operationBinding operationType="fetch" operationId="favorites">
    <selectClause>       
      fav_form_id,
      favorites.pk,
      title,
      date_revised,
      filetype,
      document,
      document_filename,
      document_filesize,
      document_date_created         
    </selectClause>
          <tableClause>        ${defaultTableClause}
          </tableClause>
    <whereClause>        username = ${advancedCriteria.USERNAME}
    </whereClause>
  </operationBinding>

  <!--  This is used when target ListGrid accepts a Record from a Drop event , works fine. -->
  <!--  Custom SQL query is to prevent drag & drop of "duplicate" Records.  -->
 
  <operationBinding operationType="add" operationId="addFavorite" cacheSyncOperation="favoritesAfterAdd">
  <customSQL> INSERT INTO favorites
    SELECT ${criteria.USERNAME}, ${criteria.FAV_FORM_ID}, favorites_pk.nextval FROM dual
  WHERE NOT EXISTS (SELECT 0 FROM favorites WHERE username=${criteria.USERNAME} and fav_form_id=${criteria.FAV_FORM_ID})
  </customSQL>
  </operationBinding>
 
  <!--  Two issues here, described below in whereClause: -->
 
  <operationBinding operationType="fetch" operationId="favoritesAfterAdd">
  <selectClause>
    fav_form_id,
    favorites.pk,
    title,
    date_revised,
    filetype,
    document,
    document_filename,
    document_filesize,
    document_date_created   
  </selectClause>
  <tableClause> ${defaultTableClause}
  </tableClause>
 
  <!-- ISSUE 1:  The ${criteria.USERNAME} from the calling operationId="addFavorite" is not passed to this cacheSyncOperation.  Shouldn't it be?  -->
  <!-- Absent the passed value, Velocity uses the literal "${criteria.USERNAME}" which causes the SQL query to bomb.  --> 
 
  <whereClause> favorites.username = ${criteria.USERNAME} </whereClause>
 
  <!-- ISSUE 2:  If I supply a hardcoded value for the purpose of troubleshooting, the console indicates execution of the "favoritesAfterAdd" operation AND the expected number of returned items;  -->
  <!-- BUT the client-side ListGrid does not update graphically to show the correct number.  invalidateCache will work, but then I lose the smooth Ajaxy refresh.  -->
 
  <whereClause> favorites.username = 'hardcoded value works OK' </whereClause>
 
  </operationBinding>
 
 
 </operationBindings>
 
 <generatedBy>v9.0p_2013-12-31/PowerEdition Deployment 2013-12-31</generatedBy>
 <tableCode>b21522fa2fe28bb48d2d89c739d290fb</tableCode>
</DataSource>

Here is the code for the source ListGrid (Record dragged out of...):
Code:

protected Canvas make_ListGrid(final String title) {

  ListGrid listGrid = new ListGrid(ds_Documents) {
  {
    String titleNoSpaces = title.replaceAll(" ", "_");
    titleNoSpaces = titleNoSpaces.replaceAll("-", "_");
    setID(titleNoSpaces);

    setCriteria(new AdvancedCriteria("SECTION", OperatorId.ISTARTS_WITH, title));
    setAutoFetchData(true);

    setFields(make_ListGridFieldArray());

    setSortField("TITLE");

    setShowFilterEditor(true);

    setCanEdit(true);

    setCanDragRecordsOut(true);
    setDragDataAction(DragDataAction.COPY);

  }
  };

  return listGrid;

 }

And here is the code for the target ListGrid (Record dropped onto...)
Code:

protected Canvas make_ListGrid_Favorites() {

  listGridFavorites = new ListGrid(ds_Favorites) {
  {
    setCanRemoveRecords(true); // supplies auto delete icon, neat!

    setAutoFetchData(true);
    setID("ListGridFavorites");

    setAddOperation("addFavorite");

    setCriteria(favoritesCriteria);
    setFilterEditorCriteria(favoritesCriteria);

    setFetchOperation("favorites");

    setFields(make_ListGridFieldArray_Favorites());

    setSortField("TITLE");
    setEmptyMessage("Drag items from tabs below...");

    setShowFilterEditor(true);

    setSelectionType(SelectionStyle.SINGLE);

    setCanAcceptDrop(true);
    setCanAcceptDroppedRecords(true);

    LinkedHashMap<String, String> dropValues = new LinkedHashMap<String, String>() {
    {
      put("USERNAME", formUser.getAdAccount());
    }
    };

    setAddDropValues(true); // default = true

    setDropValues(dropValues);

    addDropCompleteHandler(new DropCompleteHandler() {

    @Override
    public void onDropComplete(DropCompleteEvent event) {

      invalidateCache(); // This works, but it's ugly, I want cacheSync to work!

    }
    });

  }
  };

  return listGridFavorites;

 }

Here are the console results I see when dropping the same Record repeatedly onto the target ListGrid:

On the first drop:
Code:

=== 2014-01-17 13:56:00,989 [0-12] INFO  RequestContext - URL: '/Forms/sc/IDACall', User-Agent: 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3; .NET4.0C; .NET4.0E)': MSIE with Accept-Encoding header, ready for compressed JS
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Accept:*/*
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Referer:http://localhost.sdcourt.ca.gov:8888/Forms.html?gwt.codesvr=127.0.0.1:9997
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Accept-Language:en-us
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: User-Agent:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; InfoPath.3; .NET4.0C; .NET4.0E)
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: UA-CPU:AMD64
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Accept-Encoding:gzip, deflate
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Host:localhost.sdcourt.ca.gov:8888
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Connection:Keep-Alive
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Cookie:GLog=%7B%0D%20%20%20%20left%3A1662%2C%20%0D%20%20%20%20top%3A7%2C%20%0D%20%20%20%20width%3A640%2C%20%0D%20%20%20%20height%3A480%2C%20%0D%20%20%20%20priorityDefaults%3A%7B%0D%20%20%20%20%20%20%20%20Log%3A4%0D%20%20%20%20%7D%2C%20%0D%20%20%20%20defaultPriority%3A3%0D%7D; isc_cState=ready; JSESSIONID=10msjecpogahe
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Content-Type:application/x-www-form-urlencoded; charset=UTF-8
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Content-Length:2186
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - Header Name:Value pair: Cache-Control:no-cache
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - session exists: 10msjecpogahe
=== 2014-01-17 13:56:00,989 [0-12] DEBUG IDACall - remote user: null
=== 2014-01-17 13:56:00,991 [0-12] DEBUG XML - Parsed XML from (in memory stream): 1ms
=== 2014-01-17 13:56:00,993 [0-12] DEBUG RPCManager - Processing 1 requests.
=== 2014-01-17 13:56:00,993 [0-12] DEBUG DSRequest - Caching instance 34 of DS favorites from DSRequest.getDataSource()
=== 2014-01-17 13:56:00,993 [0-12] DEBUG RPCManager - Request #1 (DSRequest) payload: {
    values:{
        DOCUMENT_date_created:new Date(1389772800000),
        DOCUMENT_filesize:175616,
        SECTION:"Administrative",
        FORM_ID:"ADM-152A",
        DOCUMENT_filename:"ADM152A.dot",
        DATE_REVISED:new Date(1216105200000),
        FILETYPE:"DOT",
        OWNER:"SDSC",
        TITLE:"Access Card Log",
        _selection_21:true,
        USERNAME:"myAdAccount",
        FAV_FORM_ID:"ADM-152A"
    },
    operationConfig:{
        dataSource:"favorites",
        operationType:"add"
    },
    componentId:"ListGridFavorites",
    appID:"builtinApplication",
    operation:"addFavorite",
    oldValues:{
        DOCUMENT_date_created:new Date(1389772800000),
        DOCUMENT_filesize:175616,
        SECTION:"Administrative",
        FORM_ID:"ADM-152A",
        DOCUMENT_filename:"ADM152A.dot",
        DATE_REVISED:new Date(1216105200000),
        FILETYPE:"DOT",
        OWNER:"SDSC",
        TITLE:"Access Card Log",
        _selection_21:true,
        USERNAME:"myAdAccount",
        FAV_FORM_ID:"ADM-152A"
    },
    criteria:{
    }
}
=== 2014-01-17 13:56:00,993 [0-12] INFO  IDACall - Performing 1 operation(s)
=== 2014-01-17 13:56:00,994 [0-12] DEBUG Relation - Caching instance of toDS 'DOCUMENTS' in the DSRequest map
=== 2014-01-17 13:56:00,994 [0-12] DEBUG DeclarativeSecurity - Processing security checks for DataSource null, field null
=== 2014-01-17 13:56:00,994 [0-12] DEBUG DeclarativeSecurity - DataSource favorites is not in the pre-checked list, processing...
=== 2014-01-17 13:56:00,994 [0-12] DEBUG AppBase - [builtinApplication.addFavorite] No userTypes defined, allowing anyone access to all operations for this application
=== 2014-01-17 13:56:00,994 [0-12] DEBUG AppBase - [builtinApplication.addFavorite] No public zero-argument method named '_addFavorite' found, performing generic datasource operation
=== 2014-01-17 13:56:00,994 [0-12] INFO  SQLDataSource - [builtinApplication.addFavorite] Performing add operation with
        criteria: {DOCUMENT_date_created:new Date(1389772800000),DOCUMENT_filesize:175616,SECTION:"Administrative",FORM_ID:"ADM-152A",DOCUMENT_filename:"ADM152A.dot",DATE_REVISED:new Date(1216105200000),FILETYPE:"DOT",OWNER:"SDSC",TITLE:"Access Card Log",_selection_21:true,USERNAME:"myAdAccount",FAV_FORM_ID:"ADM-152A"}        values: {DOCUMENT_date_created:new Date(1389772800000),DOCUMENT_filesize:175616,SECTION:"Administrative",FORM_ID:"ADM-152A",DOCUMENT_filename:"ADM152A.dot",DATE_REVISED:new Date(1216105200000),FILETYPE:"DOT",OWNER:"SDSC",TITLE:"Access Card Log",_selection_21:true,USERNAME:"myAdAccount",FAV_FORM_ID:"ADM-152A"}
=== 2014-01-17 13:56:00,994 [0-12] INFO  SQLValuesClause - [builtinApplication.addFavorite] Ignored data for non-existent or included columns: [DOCUMENT_date_created, DOCUMENT_filesize, SECTION, FORM_ID, DOCUMENT_filename, DATE_REVISED, FILETYPE, OWNER, TITLE, _selection_21]
=== 2014-01-17 13:56:00,994 [0-12] DEBUG SQLValuesClause - [builtinApplication.addFavorite] Sequences: {PK=__default}
=== 2014-01-17 13:56:00,995 [0-12] DEBUG PoolableSQLConnectionFactory - [builtinApplication.addFavorite] Executing pingTest 'select 1 from dual' on connection 397939605
=== 2014-01-17 13:56:00,996 [0-12] DEBUG SQLConnectionManager - [builtinApplication.addFavorite] Borrowed connection '397939605'
=== 2014-01-17 13:56:00,996 [0-12] DEBUG SQLTransaction - [builtinApplication.addFavorite] Started new myOracleSID transaction "397939605"
=== 2014-01-17 13:56:00,997 [0-12] DEBUG SQLDriver - [builtinApplication.addFavorite] About to execute SQL update in 'myOracleSID' using connection'397939605'
=== 2014-01-17 13:56:00,997 [0-12] INFO  SQLDriver - [builtinApplication.addFavorite] Executing SQL update on 'myOracleSID': INSERT INTO favorites
              SELECT 'myAdAccount', 'ADM-152A', favorites_pk.nextval FROM dual
        WHERE NOT EXISTS (SELECT 0 FROM favorites WHERE username='myAdAccount' and fav_form_id='ADM-152A')
=== 2014-01-17 13:56:01,013 [0-12] DEBUG SQLDataSource - [builtinApplication.addFavorite] add operation affected 1 rows
=== 2014-01-17 13:56:01,013 [0-12] DEBUG SQLDriver - [builtinApplication.addFavorite] About to execute SQL query in 'myOracleSID' using connection '397939605'
=== 2014-01-17 13:56:01,013 [0-12] INFO  SQLDriver - [builtinApplication.addFavorite] Executing SQL query on 'myOracleSID': SELECT absence_dev.FAVORITES_PK.CurrVal FROM DUAL
=== 2014-01-17 13:56:01,015 [0-12] INFO  SQLDataSource - [builtinApplication.addFavorite] primaryKeys: {PK=321}
=== 2014-01-17 13:56:01,015 [0-12] INFO  SQLDataSource - [builtinApplication.addFavorite] myOracleSID getLastRow(): using specific cacheSyncOperation favoritesAfterAdd
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource null, field null
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] DataSource favorites is not in the pre-checked list, processing...
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FORM_ID
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] DataSource DOCUMENTS is not in the pre-checked list, processing...
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field TITLE
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] DataSource DOCUMENTS is not in the pre-checked list, processing...
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FORM_ID
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field DATE_REVISED
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FORM_ID
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FILETYPE
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FORM_ID
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field DOCUMENT
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FORM_ID
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field DOCUMENT_filename
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FORM_ID
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field DOCUMENT_filesize
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field FORM_ID
=== 2014-01-17 13:56:01,015 [0-12] DEBUG DeclarativeSecurity - [builtinApplication.addFavorite] Processing security checks for DataSource DOCUMENTS, field DOCUMENT_date_created
=== 2014-01-17 13:56:01,015 [0-12] DEBUG AppBase - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] No userTypes defined, allowing anyone access to all operations for this application
=== 2014-01-17 13:56:01,016 [0-12] DEBUG AppBase - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] No public zero-argument method named '_favoritesAfterAdd' found, performing generic datasource operation
=== 2014-01-17 13:56:01,016 [0-12] INFO  SQLDataSource - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] Performing fetch operation with
        criteria: {PK:"321"}        values: {PK:"321"}
=== 2014-01-17 13:56:01,016 [0-12] INFO  SQLDataSource - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] derived query: SELECT       
          fav_form_id,
          favorites.pk,
          title,
          date_revised,
          filetype,
          document,
        document_filename,
        document_filesize,
        document_date_created         
    FROM        ${defaultTableClause}
          WHERE        username = 'myAdAccount'
      AND $defaultJoinWhereClause
=== 2014-01-17 13:56:01,016 [0-12] INFO  SQLDataSource - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] 34: Executing SQL query on 'myOracleSID': SELECT       
          fav_form_id,
          favorites.pk,
          title,
          date_revised,
          filetype,
          document,
        document_filename,
        document_filesize,
        document_date_created         
    FROM        absence_dev.FAVORITES, absence_dev.DOCUMENTS
          WHERE        username = 'myAdAccount'
      AND FAVORITES.FAV_FORM_ID = DOCUMENTS.FORM_ID
=== 2014-01-17 13:56:01,016 [0-12] DEBUG SQLDriver - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] About to execute SQL query in 'myOracleSID' using connection '397939605'
=== 2014-01-17 13:56:01,016 [0-12] INFO  SQLDriver - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] Executing SQL query on 'myOracleSID': SELECT       
          fav_form_id,
          favorites.pk,
          title,
          date_revised,
          filetype,
          document,
        document_filename,
        document_filesize,
        document_date_created         
    FROM        absence_dev.FAVORITES, absence_dev.DOCUMENTS
          WHERE        username = 'myAdAccount'
      AND FAVORITES.FAV_FORM_ID = DOCUMENTS.FORM_ID
=== 2014-01-17 13:56:01,020 [0-12] INFO  DSResponse - [builtinApplication.addFavorite, builtinApplication.favoritesAfterAdd] DSResponse: List with 1 items
=== 2014-01-17 13:56:01,020 [0-12] INFO  DSResponse - [builtinApplication.addFavorite] DSResponse: List with 1 items
=== 2014-01-17 13:56:01,020 [0-12] DEBUG RPCManager - Content type for RPC transaction: text/plain; charset=UTF-8
=== 2014-01-17 13:56:01,020 [0-12] DEBUG SQLTransaction - Committing myOracleSID transaction "397939605"
=== 2014-01-17 13:56:01,040 [0-12] DEBUG RPCManager - non-DMI response, dropExtraFields: false
=== 2014-01-17 13:56:01,040 [0-12] DEBUG SQLTransaction - Returning transactional connection for myOracleSID with hashcode "397939605"
=== 2014-01-17 13:56:01,040 [0-12] DEBUG SQLTransaction - Ending myOracleSID transaction "397939605"
=== 2014-01-17 13:56:01,041 [0-12] DEBUG SQLConnectionManager - About to close PoolableConnection with hashcode "397939605"
=== 2014-01-17 13:56:01,041 [0-12] DEBUG PoolableSQLConnectionFactory - Executing pingTest 'select 1 from dual' on connection 397939605
=== 2014-01-17 13:56:01,042 [0-12] INFO  Compression - /Forms/sc/IDACall: 365 -> 277 bytes

The issue at this point is that the ListGrid does not update to reflect the 1 item DSResponse. If I reload the page, or do an listGridFavorites.invalidateCache(), then the Record will show.

The SmartClient Developer Console RPC tab shows the add operation as a success. It does not show the cacheSync fetch operation, though I'm not sure it should?

For all subsequent drops (same record from same source ListGrid), my observations:
- Each drop adds one row in the ListGrid.
- From the console, the add operation executed (zero records added, as expected per the conditional SQL insert), but the cacheSyncOperation was not triggered.
- The dropped Record does not have a PK value. Which tells me it's a locally cached Record, not from the SQL database.

Please advise, thanks.

-----------------------------
Windows 7 64-bit
IE 8 64-bit
Eclipse 64-bit
JRE 7 64-bit
SmartClient Version: v9.0p_2014-01-15/PowerEdition Deployment (built 2014-01-15)

Viewing all articles
Browse latest Browse all 4756

Trending Articles