Announcement

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

    optionDataSource problem

    So we have a few tables with millions of records. I took the approach suggested in the API and QuickStart guide (and referenced here http://forums.smartclient.com/showthread.php?t=22676&highlight=limit+listgrid+records)

    We have our own extended SqlDataSource which will check fetch() requests and throw an error if the resultSet is too large.

    Code:
    @Override
    	public DSResponse executeFetch(DSRequest req) throws Exception {
    		String fetchLimitStr = getProperty("fetchLimit");
    		int fetchLimit = Integer.MAX_VALUE;
    		long totalRows = 0;
    		
    		DSResponse response = super.executeFetch(req);
    		totalRows = response.getTotalRows();
    
    if (fetchLimitStr != null) {
    			boolean bNoFormatError = true;
    			
    			try {
    				fetchLimit = Integer.valueOf(fetchLimitStr);
    			} catch (NumberFormatException e) {
    				logger.error("DataSource " + this.getID() + " has invalid value for 'fetchLimit' field.  Please use a valid integer value. Value used was " + fetchLimitStr + ".");
    				bNoFormatError = false;
    			}
    			
    			if (bNoFormatError) {
    				totalRows = response.getTotalRows();
    				logger.debug("DataSource " + this.getID() + " has record fetch limit set to " + fetchLimitStr);
    				
    				if (totalRows > fetchLimit) {
    					logger.warn("DataSource " + this.getID() + " fetch resulted in " + totalRows + " but fetch limit set to " + fetchLimitStr + ".  DSResponse status set to failure.");
    					
    					response.setData("Query resulted in too many records being returned (" + totalRows + ").  Please filter your query and try again.");
    					response.setFailure();
    					response.setStartRow(0);
    					response.setEndRow(0);
    					response.setTotalRows(0);
    				}
    			}
    		}
    		
    		return response;
    	}
    If this isn't the correct way to do that, please let me know.

    Assuming that is the correct way, we now have an issue with anything that has an optionDataSource to the datasources that have this fetchLimit in place - they just don't load and timeout or they just crash if in devmode after a long wait (garbage collection error).

    Is there an alternative to optionDataSource? And if so, will it work with the large data Multi-Search SelectItem example from showcase? We need that as well.

    I've done the straight up foreign key and then modified the fetch to populate a client-side field but then it seems all of the other stuff has to be hand-coded (editorType, multi-search SelectItem, etc).

    Suggestions?

    #2
    SelectItem and ComboBoxItem don't have automatic handling for an out-and-out error reported by the server. It's possible that you could augment them to handle this case via dynamic setting of the emptyMessage on the ListGrid instance used to display rows.

    However, the better overall approach for you UI would probably be to implement a pop-up dialog triggered by a FormItemIcon, and in that pop-up dialog, offer a ListGrid with showFilterEditor:true as a means of filtering (or even something more advanced like a FilterBuilder, recently chosen records, or a saved search system..).

    ComboBoxItem and Multi-Search SelectItem are great when there are a relatively small number of related records, but a dedicated dialog that uses more screen real estate and can offer additional controls is the way to go where there are a very large number of related records.

    Comment

    Working...
    X