use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class CriteriaCapabilityValidatorVisitor method checkCompareCriteria.
public void checkCompareCriteria(AbstractCompareCriteria obj, Expression rightExpression) {
boolean negated = false;
// Check if operation is allowed
Capability operatorCap = null;
switch(obj.getOperator()) {
case CompareCriteria.NE:
negated = true;
case CompareCriteria.EQ:
operatorCap = Capability.CRITERIA_COMPARE_EQ;
break;
case CompareCriteria.LT:
case CompareCriteria.GT:
operatorCap = Capability.CRITERIA_COMPARE_ORDERED_EXCLUSIVE;
break;
case CompareCriteria.LE:
case CompareCriteria.GE:
operatorCap = Capability.CRITERIA_COMPARE_ORDERED;
break;
}
// Check if compares are allowed
if (!this.caps.supportsCapability(operatorCap)) {
boolean unsupported = true;
if (operatorCap == Capability.CRITERIA_COMPARE_ORDERED_EXCLUSIVE && this.caps.supportsCapability(Capability.CRITERIA_COMPARE_ORDERED) && this.caps.supportsCapability(Capability.CRITERIA_NOT)) {
unsupported = false;
}
if (unsupported) {
if (EvaluatableVisitor.willBecomeConstant(obj)) {
return;
}
// $NON-NLS-1$
markInvalid(obj, operatorCap + " CompareCriteria not supported by source");
return;
}
}
if (negated && !this.caps.supportsCapability(Capability.CRITERIA_NOT)) {
if (EvaluatableVisitor.willBecomeConstant(obj)) {
return;
}
// $NON-NLS-1$
markInvalid(obj, "Negation is not supported by source");
return;
}
// Check capabilities of the elements
try {
int support = SupportConstants.Element.SEARCHABLE_COMPARE;
if (!negated && obj.getOperator() == CompareCriteria.EQ) {
support = SupportConstants.Element.SEARCHABLE_EQUALITY;
}
checkElementsAreSearchable(obj.getLeftExpression(), support);
checkElementsAreSearchable(rightExpression, support);
} catch (QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch (TeiidComponentException e) {
handleException(e);
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class CriteriaCapabilityValidatorVisitor method visit.
/**
* @see org.teiid.query.sql.LanguageVisitor#visit(org.teiid.query.sql.lang.SubqueryCompareCriteria)
*/
public void visit(SubqueryCompareCriteria crit) {
if (crit.getArrayExpression() != null) {
// $NON-NLS-1$
markInvalid(crit, "Quantified compare with an array cannot yet be pushed down.");
return;
}
// Check if quantification operator is allowed
Capability capability = Capability.QUERY_SUBQUERIES_SCALAR;
switch(crit.getPredicateQuantifier()) {
case SubqueryCompareCriteria.ALL:
capability = Capability.CRITERIA_QUANTIFIED_ALL;
break;
case SubqueryCompareCriteria.ANY:
capability = Capability.CRITERIA_QUANTIFIED_SOME;
break;
case SubqueryCompareCriteria.SOME:
capability = Capability.CRITERIA_QUANTIFIED_SOME;
break;
}
if (!this.caps.supportsCapability(capability)) {
// $NON-NLS-1$
markInvalid(crit, "SubqueryCompare not supported by source");
return;
}
checkCompareCriteria(crit, crit.getCommand().getProjectedSymbols().get(0));
// Check capabilities of the elements
try {
if (validateSubqueryPushdown(crit, modelID, metadata, capFinder, analysisRecord) == null) {
// $NON-NLS-1$
markInvalid(crit.getCommand(), "Subquery cannot be pushed down");
}
} catch (QueryMetadataException e) {
handleException(new TeiidComponentException(e));
} catch (TeiidComponentException e) {
handleException(e);
}
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class SourceTriggerActionPlanner method optimize.
@Override
public ProcessorPlan optimize(Command command, IDGenerator idGenerator, QueryMetadataInterface metadata, CapabilitiesFinder capFinder, AnalysisRecord analysisRecord, CommandContext context) throws QueryPlannerException, QueryMetadataException, TeiidComponentException {
SourceEventCommand sec = (SourceEventCommand) command;
Map<Expression, Integer> lookup = new HashMap<Expression, Integer>();
Map<ElementSymbol, Expression> params = new HashMap<ElementSymbol, Expression>();
List<Object> tuple = new ArrayList<Object>();
Map<String, Integer> map = null;
if (sec.getColumnNames() != null) {
map = new TreeMap<String, Integer>(String.CASE_INSENSITIVE_ORDER);
for (String name : sec.getColumnNames()) {
map.put(name, map.size());
}
}
GroupSymbol changingGroup = new GroupSymbol(ProcedureReservedWords.CHANGING);
if (sec.newValues != null) {
GroupSymbol newGroup = new GroupSymbol(SQLConstants.Reserved.NEW);
newGroup.setMetadataID(sec.table);
for (int i = 0; i < sec.getTable().getColumns().size(); i++) {
Column c = sec.getTable().getColumns().get(i);
Integer index = null;
if (map != null) {
index = map.get(c.getName());
} else {
index = i;
}
ElementSymbol newElement = new ElementSymbol(c.getName(), newGroup);
newElement.setMetadataID(c);
ElementSymbol changingElement = new ElementSymbol(c.getName(), changingGroup);
lookup.put(newElement, tuple.size());
lookup.put(changingElement, tuple.size() + 1);
params.put(newElement, newElement);
params.put(changingElement, changingElement);
if (index == null) {
// not changing
tuple.add(new Constant(null));
tuple.add(new Constant(Boolean.FALSE));
} else {
// changing
tuple.add(new Constant(DataTypeManager.convertToRuntimeType(sec.newValues[index], true)));
tuple.add(new Constant(Boolean.TRUE));
}
}
}
if (sec.oldValues != null) {
GroupSymbol oldGroup = new GroupSymbol(SQLConstants.Reserved.OLD);
oldGroup.setMetadataID(sec.table);
for (int i = 0; i < sec.getTable().getColumns().size(); i++) {
Column c = sec.getTable().getColumns().get(i);
Integer index = null;
if (map != null) {
index = map.get(c.getName());
} else {
index = i;
}
ElementSymbol oldElement = new ElementSymbol(c.getName(), oldGroup);
oldElement.setMetadataID(c);
lookup.put(oldElement, tuple.size());
params.put(oldElement, oldElement);
if (index != null) {
tuple.add(new Constant(DataTypeManager.convertToRuntimeType(sec.oldValues[index], true)));
}
}
}
List<ProcessorPlan> plans = new ArrayList<ProcessorPlan>();
List<String> names = new ArrayList<String>();
for (Trigger tr : sec.getTable().getTriggers().values()) {
int updateType = Command.TYPE_UPDATE;
switch(tr.getEvent()) {
case DELETE:
updateType = Command.TYPE_DELETE;
if (sec.newValues != null) {
continue;
}
break;
case INSERT:
updateType = Command.TYPE_INSERT;
if (sec.oldValues != null) {
continue;
}
break;
case UPDATE:
if (sec.oldValues == null || sec.newValues == null) {
continue;
}
break;
}
// create plan
ForEachRowPlan result = new ForEachRowPlan();
result.setSingleRow(true);
result.setParams(params);
TriggerAction parseProcedure;
GroupSymbol gs = new GroupSymbol(sec.table.getFullName());
try {
parseProcedure = (TriggerAction) QueryParser.getQueryParser().parseProcedure(tr.getPlan(), true);
QueryResolver.resolveCommand(parseProcedure, gs, updateType, metadata.getDesignTimeMetadata(), false);
} catch (QueryParserException e) {
// should have been validated
throw new TeiidComponentException(e);
} catch (QueryResolverException e) {
// should have been validated
throw new TeiidComponentException(e);
}
CreateProcedureCommand cpc = new CreateProcedureCommand(parseProcedure.getBlock());
gs.setMetadataID(sec.table);
cpc.setVirtualGroup(gs);
cpc.setUpdateType(updateType);
ProcedurePlan rowProcedure = (ProcedurePlan) QueryOptimizer.optimizePlan(cpc, metadata, idGenerator, capFinder, analysisRecord, context);
rowProcedure.setRunInContext(false);
result.setRowProcedure(rowProcedure);
result.setLookupMap(lookup);
result.setTupleSource(new CollectionTupleSource(Arrays.asList(tuple).iterator()));
plans.add(result);
names.add(tr.getName());
}
return new CompositeProcessorPlan(plans, names, sec.table);
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class LocalServerConnection method getService.
public <T> T getService(final Class<T> iface) {
return iface.cast(Proxy.newProxyInstance(this.getClass().getClassLoader(), new Class[] { iface }, new InvocationHandler() {
boolean logon = iface.equals(ILogon.class);
public Object invoke(Object arg0, final Method arg1, final Object[] arg2) throws Throwable {
if (shutdown) {
throw ExceptionUtil.convertException(arg1, new TeiidComponentException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40074)));
}
try {
if (derived) {
workContext.setDerived(true);
}
// check to make sure the current security context same as logged one
if (!logon && (reconnect || (passthrough && // -- it's ok to use another thread to cancel
!arg1.equals(cancelMethod) && !workContext.getSession().isClosed() && // if configured without a security domain the context will be null
workContext.getSession().getSecurityDomain() != null && !sameSubject(workContext)))) {
// TODO: this is an implicit changeUser - we may want to make this explicit, but that would require pools to explicitly use changeUser
LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40115, workContext.getSession().getSessionId()));
reconnect = false;
authenticate();
}
final T service = csr.getClientService(iface);
return workContext.runInContext(new Callable<Object>() {
public Object call() throws Exception {
return arg1.invoke(service, arg2);
}
});
} catch (InvocationTargetException e) {
throw e.getTargetException();
} catch (Throwable e) {
throw ExceptionUtil.convertException(arg1, e);
} finally {
workContext.setDerived(false);
}
}
}));
}
use of org.teiid.core.TeiidComponentException in project teiid by teiid.
the class LocalServerConnection method authenticate.
public synchronized void authenticate() throws ConnectionException, CommunicationException {
Object previousSecurityContext = workContext.getSecurityHelper().associateSecurityContext(workContext.getSession().getSecurityContext());
try {
logoff();
} finally {
workContext.getSecurityHelper().associateSecurityContext(previousSecurityContext);
}
workContext.setSecurityContext(previousSecurityContext);
try {
this.result = this.getService(ILogon.class).logon(this.connectionProperties);
AuthenticationType type = (AuthenticationType) this.result.getProperty(ILogon.AUTH_TYPE);
if (type != null) {
// server has issued an additional challenge
if (type == AuthenticationType.GSS) {
try {
this.result = MakeGSS.authenticate(this.getService(ILogon.class), this.connectionProperties);
} catch (LogonException e) {
if (!passthrough) {
throw new LogonException(RuntimePlugin.Event.TEIID40150, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40150));
}
throw e;
}
} else {
throw new LogonException(JDBCPlugin.Event.TEIID20034, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20034, type));
}
}
} catch (LogonException e) {
// to give to the user
throw new ConnectionException(e);
} catch (TeiidComponentException e) {
if (e.getCause() instanceof CommunicationException) {
throw (CommunicationException) e.getCause();
}
throw new CommunicationException(RuntimePlugin.Event.TEIID40069, e);
}
}
Aggregations