Back-end Search

Backend search allows the client to operate on a subset of data, obtained as a result of executing a specific named query on the server.

Search MBO Create

Consider a named query on the server, BE_SEARCH_GETLIST. To initiate a back-end search, the first step is to create a search MBO.

BackendSearch search = new BackendSearch();

Fill up the required fields for the MBO as follows:

//any name as desired by the user. 
     search.setSearchName("MySearch");

 //entity type for the result set (corresponds to the return type of the named query ) 
     search.setEntityType("ENTITY_TYPE_DETAILS");

//the name of the query to be executed  on the server
[search setNamedQuery: [BackendSearch BE_SEARCH_GETLIST]]; 
     search.setNamedQuery ("BE_SEARCH_GETLIST");

For every named query on the server, the generated client code contains a corresponding class file, with the same name as the query. For example, BE_SEARCH_GETLIST.java. The attributes of the class represent the parameters for the query and can be set as follows.

//Set up the search parameters , which will be used as the search criteria
     BE_SEARCH_GETLIST searchParameters = new BE_SEARCH_GETLIST();
     searchParameters.setNAME_FIRST("John");
     //additional parameters if required.

//Now set the above as searchparameters in the MBO
     search.setParameters(searchParameters);

The search MBO has other optional fields:

     search.setSearchTime(com.sybase.afx.util.DateTimeUtil.now());
     search.setTake(100);
     search.setSearchId(1);
     //…
     // other optional fields of search.

//submit search request to the server
     search.submitPending();

After some time the server sends a search failure or success message, and the results of the query. You can get the search result notification from CallbackHandler. The results are saved into the back-end search results table on the device database. The result data can be retrieved as follows:

GernericList<ENTITY_TYPE_DETAILS> searchResults = ENTITY_TYPE_DETAILS.searchResults(search);

Search MBO Update

     searchParameters = new BE_SEARCH_GETLIST();
     searchParameters.setNAME_FIRST(“Ron”);
     search.setParameters(searchParameters);
     search.update();
     search.refresh();
     search.submitPending();

Search MBO Delete

Delete on a search MBO will delete the search entity and result locally in the client database. Data on the server cannot be deleted using the search MBO and a call to submitPending will not propagate the delete message to the server.

     search.delete();