Skip to content

Commit

Permalink
TEIID-3116 adding more detail to the exception message
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Sep 23, 2014
1 parent 25fa452 commit ce8d17f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
*/
public class CachedFinder implements CapabilitiesFinder {

static BasicSourceCapabilities INVALID_CAPS = new BasicSourceCapabilities();
static class InvalidCaps extends BasicSourceCapabilities {

};
private static BasicSourceCapabilities SYSTEM_CAPS = new BasicSourceCapabilities();
static {
SYSTEM_CAPS.setCapabilitySupport(Capability.CRITERIA_IN, true);
Expand Down Expand Up @@ -94,6 +96,7 @@ public SourceCapabilities findCapabilities(String modelName) throws TeiidCompone
if (sourceNames.isEmpty()) {
throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30499, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30499, modelName));
}
TeiidException cause = null;
for (String sourceName:sourceNames) {
//TOOD: in multi-source mode it may be necessary to compute minimal capabilities across the sources
ConnectorManager mgr = this.connectorRepo.getConnectorManager(sourceName);
Expand All @@ -104,12 +107,15 @@ public SourceCapabilities findCapabilities(String modelName) throws TeiidCompone
caps = mgr.getCapabilities();
break;
} catch(TeiidException e) {
cause = e;
LogManager.logDetail(LogConstants.CTX_DQP, e, "Could not obtain capabilities for" + sourceName); //$NON-NLS-1$
}
}

if (caps == null) {
caps = INVALID_CAPS;
InvalidCaps ic = new InvalidCaps();
ic.setSourceProperty(Capability.INVALID_EXCEPTION, cause);
caps = ic;
}

userCache.put(modelName, caps);
Expand All @@ -121,7 +127,8 @@ public void addCapabilities(String connBinding, SourceCapabilities sourceCaps) {
}

public boolean isValid(String modelName) {
return userCache.get(modelName) != INVALID_CAPS;
SourceCapabilities caps = userCache.get(modelName);
return caps != null && !(caps instanceof InvalidCaps);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ public enum Capability {
FULL_DEPENDENT_JOIN,
SELECT_WITHOUT_FROM,
QUERY_GROUP_BY_ROLLUP,
QUERY_ORDERBY_EXTENDED_GROUPING;
QUERY_ORDERBY_EXTENDED_GROUPING,
INVALID_EXCEPTION; //property saying why the capabilities are invalid

private final String toString;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,20 @@ protected RelationalNode convertNode(PlanNode node)
AccessNode aNode = null;
Command command = (Command) node.getProperty(NodeConstants.Info.ATOMIC_REQUEST);
Object modelID = node.getProperty(NodeConstants.Info.MODEL_ID);
if (modelID != null && !capFinder.isValid(metadata.getFullName(modelID))) {
//TODO: we ideally want to handle the partial resutls case here differently
// by adding a null node / and a source warning
// for now it's just as easy to say that the user needs to take steps to
// return static capabilities
throw new QueryPlannerException(QueryPlugin.Event.TEIID30498, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30498, metadata.getFullName(modelID)));
if (modelID != null) {
String fullName = metadata.getFullName(modelID);
if (!capFinder.isValid(fullName)) {
//TODO: we ideally want to handle the partial resutls case here differently
// by adding a null node / and a source warning
// for now it's just as easy to say that the user needs to take steps to
// return static capabilities
SourceCapabilities caps = capFinder.findCapabilities(fullName);
Exception cause = null;
if (caps != null) {
cause = (Exception) caps.getSourceProperty(Capability.INVALID_EXCEPTION);
}
throw new QueryPlannerException(QueryPlugin.Event.TEIID30498, cause, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30498, fullName));
}
}
EvaluatableVisitor ev = null;
if(node.hasBooleanProperty(NodeConstants.Info.IS_DEPENDENT_SET)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class TestConnectorCapabilitiesFinder {

// Test
SourceCapabilities actual = finder.findCapabilities(modelName);
assertEquals(CachedFinder.INVALID_CAPS, actual); //$NON-NLS-1$
assertNotNull(actual); //$NON-NLS-1$
assertFalse(finder.isValid(modelName));
}

Expand Down

0 comments on commit ce8d17f

Please sign in to comment.