Red Hat Training

A Red Hat training course is available for Red Hat JBoss Data Virtualization

3.14. Partial Results Warnings

For each source that is excluded from the query, a warning will be generated describing the source and the failure. These warnings can be obtained from the Statement.getWarnings() method. This method returns a SQLWarning object, but in the case of partial results warnings this object will be an instance of the org.teiid.jdbc.PartialResultsWarning class. This class can be used to obtain a list of all the failed sources by name and to obtain the specific exception thrown by each resource adaptor.

Note

Since JBoss Data Virtualization supports cursoring before the entire result is formed, it is possible that a data source failure will not be determined until after the first batch of results have been returned to the client. This can happen in the case of unions, but not joins. To ensure that all warnings have been accumulated, the statement should be checked after the entire result set has been read.
The following is an example of how to obtain partial results warnings:
statement.execute("set partialResultsMode true");
ResultSet results = statement.executeQuery("SELECT Name FROM Accounts");
while (results.next())
{
   //process the result set
}

SQLWarning warning = statement.getWarnings();

if(warning instanceof PartialResultsWarning)
{
   PartialResultsWarning partialWarning = (PartialResultsWarning)warning;
   Collection failedConnectors = partialWarning.getFailedConnectors();
   Iterator iter = failedConnectors.iterator();
   while(iter.hasNext())
   {
      String connectorName = (String) iter.next();
      SQLException connectorException = partialWarning.getConnectorException(connectorName);
      System.out.println(connectorName + ": " + connectorException.getMessage());
   }
}