Search in sources :

Example 66 with TranslatorException

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);
    }
}
Also used : BasicAttribute(javax.naming.directory.BasicAttribute) Attribute(javax.naming.directory.Attribute) org.teiid.language(org.teiid.language) NamingException(javax.naming.NamingException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) ModificationItem(javax.naming.directory.ModificationItem) TranslatorException(org.teiid.translator.TranslatorException) NamingException(javax.naming.NamingException)

Example 67 with TranslatorException

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);
    }
}
Also used : NamingException(javax.naming.NamingException) TranslatorException(org.teiid.translator.TranslatorException) NamingException(javax.naming.NamingException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException)

Example 68 with TranslatorException

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);
    }
}
Also used : TranslatorException(org.teiid.translator.TranslatorException)

Example 69 with TranslatorException

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());
    }
}
Also used : DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) TranslatorException(org.teiid.translator.TranslatorException) QueryBuilder(com.mongodb.QueryBuilder)

Example 70 with TranslatorException

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);
    }
}
Also used : ClobType(org.teiid.core.types.ClobType) TransformationException(org.teiid.core.types.TransformationException) FunctionExecutionException(org.teiid.api.exception.query.FunctionExecutionException) ClobToStringTransform(org.teiid.core.types.basic.ClobToStringTransform) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

TranslatorException (org.teiid.translator.TranslatorException)227 ArrayList (java.util.ArrayList)51 Column (org.teiid.metadata.Column)47 List (java.util.List)32 Table (org.teiid.metadata.Table)30 IOException (java.io.IOException)26 SQLException (java.sql.SQLException)26 ResourceException (javax.resource.ResourceException)26 Test (org.junit.Test)16 Expression (org.teiid.language.Expression)16 Literal (org.teiid.language.Literal)16 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)16 Blob (java.sql.Blob)15 Argument (org.teiid.language.Argument)13 DBObject (com.mongodb.DBObject)11 HashMap (java.util.HashMap)11 ColumnReference (org.teiid.language.ColumnReference)11 ExecutionContext (org.teiid.translator.ExecutionContext)11 BasicDBObject (com.mongodb.BasicDBObject)10 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)10