use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class LDAPUpdateExecution method executeUpdate.
// Private method to actually do an update operation. Per JNDI doc at
// http://java.sun.com/products/jndi/tutorial/ldap/models/operations.html,
// the JNDI method to use to update an entry to LDAP is one of the
// DirContext.modifyAttributes() methods that takes ModificationItem[]
// as a parameter, so that is what is used here.
// Note that this method does not allow for changing of the DN - to
// implement that we would need to use Context.rename(). Since right
// now we only call modifyAttributes(), and don't check for the DN
// in the list of updates, we will attempt to update the DN using
// modifyAttributes(), and let the LDAP server fail the request (and
// send us the explanation for the failure, which is returned in
// a ConnectorException)
//
// The update criteria must include only an equals comparison
// on the "DN" column ("WHERE DN='cn=John Doe,ou=people,dc=company,dc=com'")
private void executeUpdate() throws TranslatorException {
List<SetClause> updateList = ((Update) command).getChanges();
Condition criteria = ((Update) command).getWhere();
// since we have the exact same processing rules for criteria
// for updates and deletes, we use a common private method to do this.
// note that this private method will throw a ConnectorException
// for illegal criteria, which we deliberately don't catch
// so it gets passed on as is.
String distinguishedName = getDNFromCriteria(criteria);
// this will be the list of modifications to attempt. Since
// we currently blindly try all the updates the query
// specifies, right now this is the same size as the updateList.
// When we start filtering out DN changes (which would need to
// be performed separately using Context.rename()), we will
// need to account for this in determining this list size.
ModificationItem[] updateMods = new ModificationItem[updateList.size()];
// API).
for (int i = 0; i < updateList.size(); i++) {
SetClause setClause = updateList.get(i);
// trust that connector API is right and left side
// will always be an IElement
ColumnReference leftElement = setClause.getSymbol();
// call utility method to get NameInSource/Name for element
String nameLeftElement = getNameFromElement(leftElement);
// get right expression - if it is not a literal we
// can't handle that so throw an exception
Expression rightExpr = setClause.getValue();
if (!(rightExpr instanceof Literal) && !(rightExpr instanceof org.teiid.language.Array)) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.valueNotLiteralError", nameLeftElement);
throw new TranslatorException(msg);
}
// add in the modification as a replacement - meaning
// any existing value(s) for this attribute will
// be replaced by the new value. If the attribute
// didn't exist, it will automatically be created
// TODO - since null is a valid attribute
// value, we don't do any special handling of it right
// now. But maybe null should mean to delete an
// attribute?
Attribute attribute = createBasicAttribute(nameLeftElement, rightExpr, leftElement.getMetadataObject());
updateMods[i] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, attribute);
}
// we'll return in a ConnectorException
try {
ldapCtx.modifyAttributes(distinguishedName, updateMods);
} catch (NamingException ne) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.updateFailed", distinguishedName, ne.getExplanation());
throw new TranslatorException(ne, msg);
// don't remember why I added this generic catch of Exception,
// but it does no harm...
} catch (Exception e) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.updateFailedUnexpected", distinguishedName);
throw new TranslatorException(e, msg);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class LDAPUpdateExecution method executeDelete.
// Private method to actually do a delete operation. Per JNDI doc at
// http://java.sun.com/products/jndi/tutorial/ldap/models/operations.html,
// a good JNDI method to delete an entry to LDAP is
// DirContext.destroySubContext(), so that is what is used here.
//
// The delete criteria must include only an equals comparison
// on the "DN" column ("WHERE DN='cn=John Doe,ou=people,dc=company,dc=com'")
// Note that the underlying LDAP operations here return successfully
// even if the named entry doesn't exist (as long as its parent does
// exist).
private void executeDelete() throws TranslatorException {
Condition criteria = ((Delete) command).getWhere();
// since we have the exact same processing rules for criteria
// for updates and deletes, we use a common private method to do this.
// note that this private method will throw a ConnectorException
// for illegal criteria, which we deliberately don't catch
// so it gets passed on as is.
String distinguishedName = getDNFromCriteria(criteria);
// we'll return in a ConnectorException
try {
ldapCtx.destroySubcontext(distinguishedName);
} catch (NamingException ne) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.deleteFailed", distinguishedName, ne.getExplanation());
throw new TranslatorException(msg);
// don't remember why I added this generic catch of Exception,
// but it does no harm...
} catch (Exception e) {
// $NON-NLS-1$
final String msg = LDAPPlugin.Util.getString("LDAPUpdateExecution.deleteFailedUnexpected", distinguishedName);
throw new TranslatorException(e, msg);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class MongoDBSelectVisitor method processJoin.
private void processJoin(MongoDocument left, MongoDocument right, Condition cond, JoinType joinType) throws TranslatorException {
// now adjust for the left/right outer depending upon who is the outer document
JoinCriteriaVisitor jcv = new JoinCriteriaVisitor(joinType, left, right, this.mergePlanner);
jcv.process(cond);
if (left.contains(right)) {
this.mongoDoc = left;
this.joinedDocuments.add(right);
configureUnwind(right);
} else if (right.contains(left)) {
this.mongoDoc = right;
this.joinedDocuments.add(left);
configureUnwind(left);
} else {
if (this.mongoDoc != null) {
// this is for nested grand kids
for (MongoDocument child : this.joinedDocuments) {
if (child.contains(right)) {
this.joinedDocuments.add(right);
configureUnwind(right);
return;
}
}
}
throw new TranslatorException(MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18012, left.getTable().getName(), right.getTable().getName()));
}
if (cond != null) {
this.pendingConditions.add(cond);
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class MongoDBSelectVisitor method visit.
@Override
public void visit(In obj) {
append(obj.getLeftExpression());
Object expr = this.onGoingExpression.pop();
ColumnDetail detail = this.expressionMap.get(expr);
QueryBuilder query = QueryBuilder.start();
if (detail == null) {
this.exceptions.add(new TranslatorException(MongoDBPlugin.Event.TEIID18031, MongoDBPlugin.Util.gs(MongoDBPlugin.Event.TEIID18031)));
} else {
query = detail.getQueryBuilder();
this.onGoingExpression.push(buildInQuery(obj, query).get());
}
}
use of org.teiid.translator.TranslatorException in project teiid by teiid.
the class MongoDBSelectVisitor method convertGeometryToJson.
private void convertGeometryToJson(BasicDBObjectBuilder builder, GeometryType object) throws TranslatorException {
try {
ClobType clob = GeometryUtils.geometryToGeoJson(object);
ClobToStringTransform clob2str = new ClobToStringTransform();
String geometry = (String) clob2str.transform(clob, String.class);
builder.add("$geometry", geometry);
} catch (FunctionExecutionException | TransformationException e) {
throw new TranslatorException(e);
}
}
Aggregations