use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class AbstractValidationVisitor method validateElementsSupport.
// ######################### Helper methods for validation #########################
protected Collection<ElementSymbol> validateElementsSupport(Collection<ElementSymbol> elements, int supportsFlag) {
// Collect any identifiers not supporting flag
List<ElementSymbol> dontSupport = null;
ElementSymbol symbol = null;
try {
Iterator<ElementSymbol> elemIter = elements.iterator();
while (elemIter.hasNext()) {
symbol = elemIter.next();
if (!getMetadata().elementSupports(symbol.getMetadataID(), supportsFlag)) {
if (dontSupport == null) {
dontSupport = new ArrayList<ElementSymbol>();
}
dontSupport.add(symbol);
}
}
} catch (QueryMetadataException e) {
handleException(e, symbol);
} catch (TeiidComponentException e) {
handleException(e, symbol);
}
return dontSupport;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class StatementImpl method postReceiveResults.
private synchronized void postReceiveResults(RequestMessage reqMessage, ResultsMessage resultsMsg) throws TeiidSQLException, SQLException {
commandStatus = State.DONE;
// warnings thrown
List resultsWarning = resultsMsg.getWarnings();
// save warnings if have any
if (resultsWarning != null) {
accumulateWarnings(resultsWarning);
}
setAnalysisInfo(resultsMsg);
// throw an exception unless this represents a batch update exception
if (resultsMsg.getException() != null && (!resultsMsg.isUpdateResult() || resultsMsg.getResultsList() == null)) {
throw TeiidSQLException.create(resultsMsg.getException());
}
resultsMsg.processResults();
if (resultsMsg.isUpdateResult()) {
List<? extends List<?>> results = resultsMsg.getResultsList();
if (resultsMsg.getUpdateCount() == -1) {
this.updateCounts = new int[results.size()];
for (int i = 0; i < results.size(); i++) {
updateCounts[i] = (Integer) results.get(i).get(0);
}
} else {
this.updateCounts = new int[] { resultsMsg.getUpdateCount() };
this.createResultSet(resultsMsg);
}
if (logger.isLoggable(Level.FINER)) {
// $NON-NLS-1$
logger.finer("Recieved update counts: " + Arrays.toString(updateCounts));
}
// In update scenarios close the statement implicitly - the server should have already done this
try {
getDQP().closeRequest(getCurrentRequestID());
} catch (TeiidProcessingException e) {
throw TeiidSQLException.create(e);
} catch (TeiidComponentException e) {
throw TeiidSQLException.create(e);
}
// handle a batch update exception
if (resultsMsg.getException() != null) {
TeiidSQLException exe = TeiidSQLException.create(resultsMsg.getException());
BatchUpdateException batchUpdateException = new BatchUpdateException(exe.getMessage(), exe.getSQLState(), exe.getErrorCode(), updateCounts, exe);
this.updateCounts = null;
throw batchUpdateException;
}
} else {
createResultSet(resultsMsg);
}
if (logger.isLoggable(Level.FINE)) {
// $NON-NLS-1$
logger.fine(JDBCPlugin.Util.getString("MMStatement.Success_query", reqMessage.getCommandString()));
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class GssAction method authenticate.
public static LogonResult authenticate(ILogon logon, Properties props) throws LogonException, TeiidComponentException, CommunicationException {
if (logger.isLoggable(Level.FINE)) {
// $NON-NLS-1$
logger.fine("GSS Authentication Request");
}
Object result = null;
StringBuilder errors = new StringBuilder();
String jaasApplicationName = props.getProperty(TeiidURL.CONNECTION.JAAS_NAME);
// $NON-NLS-1$
String nl = System.getProperty("line.separator");
if (jaasApplicationName == null) {
// $NON-NLS-1$
jaasApplicationName = "Teiid";
}
String kerberosPrincipalName = props.getProperty(TeiidURL.CONNECTION.KERBEROS_SERVICE_PRINCIPLE_NAME);
if (kerberosPrincipalName == null) {
try {
TeiidURL url = new TeiidURL(props.getProperty(TeiidURL.CONNECTION.SERVER_URL));
// $NON-NLS-1$
kerberosPrincipalName = "TEIID/" + url.getHostInfo().get(0).getHostName();
} catch (Exception e) {
// Ignore exception
}
if (kerberosPrincipalName == null) {
// $NON-NLS-1$
errors.append(JDBCPlugin.Util.getString("client_prop_missing", TeiidURL.CONNECTION.KERBEROS_SERVICE_PRINCIPLE_NAME));
errors.append(nl);
}
}
// $NON-NLS-1$
String krb5 = System.getProperty("java.security.krb5.conf");
// $NON-NLS-1$
String realm = System.getProperty("java.security.krb5.realm");
// $NON-NLS-1$
String kdc = System.getProperty("java.security.krb5.kdc");
if (krb5 == null && realm == null && kdc == null) {
// $NON-NLS-1$
errors.append(JDBCPlugin.Util.getString("no_gss_selection"));
errors.append(nl);
} else if (krb5 != null && (realm != null || kdc != null)) {
// $NON-NLS-1$
errors.append(JDBCPlugin.Util.getString("ambigious_gss_selection"));
errors.append(nl);
} else if ((realm != null && kdc == null) || (realm == null && kdc != null)) {
// krb5 is null here..
if (realm == null) {
// $NON-NLS-1$ //$NON-NLS-2$
errors.append(JDBCPlugin.Util.getString("system_prop_missing", "java.security.krb5.realm"));
errors.append(nl);
}
if (kdc == null) {
// $NON-NLS-1$ //$NON-NLS-2$
errors.append(JDBCPlugin.Util.getString("system_prop_missing", "java.security.krb5.kdc"));
errors.append(nl);
}
}
// $NON-NLS-1$
String config = System.getProperty("java.security.auth.login.config");
if (config == null) {
// $NON-NLS-1$ //$NON-NLS-2$
errors.append(JDBCPlugin.Util.getString("system_prop_missing", "java.security.auth.login.config"));
errors.append(nl);
}
try {
String user = props.getProperty(TeiidURL.CONNECTION.USER_NAME);
String password = props.getProperty(TeiidURL.CONNECTION.PASSWORD);
boolean performAuthentication = true;
GSSCredential gssCredential = null;
Subject sub = Subject.getSubject(AccessController.getContext());
if (sub != null) {
Set<GSSCredential> gssCreds = sub.getPrivateCredentials(GSSCredential.class);
if (gssCreds != null && gssCreds.size() > 0) {
gssCredential = gssCreds.iterator().next();
performAuthentication = false;
if (logger.isLoggable(Level.FINE)) {
// $NON-NLS-1$
logger.fine("GSS Authentication using delegated credential");
}
} else {
if (logger.isLoggable(Level.FINE)) {
// $NON-NLS-1$
logger.fine("No delegation credential found in the subject");
}
}
}
if (performAuthentication) {
if (errors.length() > 0) {
throw new LogonException(JDBCPlugin.Event.TEIID20005, errors.toString());
}
LoginContext lc = new LoginContext(jaasApplicationName, new GSSCallbackHandler(user, password));
lc.login();
sub = lc.getSubject();
}
PrivilegedAction action = new GssAction(logon, kerberosPrincipalName, props, user, gssCredential);
result = Subject.doAs(sub, action);
} catch (Exception e) {
throw new LogonException(JDBCPlugin.Event.TEIID20005, e, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20005));
}
if (result instanceof LogonException) {
throw (LogonException) result;
} else if (result instanceof TeiidComponentException) {
throw (TeiidComponentException) result;
} else if (result instanceof CommunicationException) {
throw (CommunicationException) result;
} else if (result instanceof Exception) {
throw new LogonException(JDBCPlugin.Event.TEIID20005, (Exception) result, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20005));
}
return (LogonResult) result;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class PlanToProcessConverter method aliasCommand.
private Command aliasCommand(AccessNode aNode, Command command, Object modelID) throws TeiidComponentException, QueryPlannerException {
try {
command = (Command) command.clone();
boolean aliasGroups = modelID != null && (CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
boolean aliasColumns = modelID != null && (CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata, capFinder) || CapabilitiesUtil.supports(Capability.QUERY_FROM_INLINE_VIEWS, modelID, metadata, capFinder));
AliasGenerator visitor = new AliasGenerator(aliasGroups, !aliasColumns);
SourceHint sh = command.getSourceHint();
if (sh != null && aliasGroups) {
VDBMetaData vdb = context.getDQPWorkContext().getVDB();
ModelMetaData model = vdb.getModel(aNode.getModelName());
List<String> sourceNames = model.getSourceNames();
SpecificHint sp = null;
if (sourceNames.size() == 1) {
sp = sh.getSpecificHint(sourceNames.get(0));
}
if (sh.isUseAliases() || (sp != null && sp.isUseAliases())) {
visitor.setAliasMapping(context.getAliasMapping());
}
}
List<Reference> references = ReferenceCollectorVisitor.getReferences(command);
if (!references.isEmpty()) {
Set<String> correleatedGroups = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
for (Reference ref : references) {
if (ref.isCorrelated() && ref.getExpression().getGroupSymbol() != null) {
correleatedGroups.add(ref.getExpression().getGroupSymbol().getName());
}
}
visitor.setCorrelationGroups(correleatedGroups);
}
command.acceptVisitor(visitor);
} catch (QueryMetadataException err) {
throw new TeiidComponentException(QueryPlugin.Event.TEIID30249, err);
} catch (TeiidRuntimeException e) {
if (e.getCause() instanceof QueryPlannerException) {
throw (QueryPlannerException) e.getCause();
}
throw e;
}
return command;
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class CriteriaCapabilityValidatorVisitor method visit.
@Override
public void visit(OrderBy obj) {
String collation = null;
try {
collation = (String) CapabilitiesUtil.getProperty(Capability.COLLATION_LOCALE, modelID, metadata, capFinder);
} catch (QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch (TeiidComponentException e) {
handleException(e);
}
CommandContext commandContext = CommandContext.getThreadLocalContext();
if (collation != null && commandContext != null && commandContext.getOptions().isRequireTeiidCollation() && !collation.equals(DataTypeManager.COLLATION_LOCALE)) {
for (OrderByItem symbol : obj.getOrderByItems()) {
if (symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.STRING || symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.CLOB || symbol.getSymbol().getType() == DataTypeManager.DefaultDataClasses.CHAR) {
// we require the collation to match
// $NON-NLS-1$
markInvalid(obj, "source is not using the same collation as Teiid");
break;
}
}
}
}
Aggregations