Search in sources :

Example 46 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class IckleConversionVisitor method visit.

@Override
public void visit(Select obj) {
    buffer.append(SQLConstants.Reserved.FROM).append(Tokens.SPACE);
    visitNodes(obj.getFrom());
    if (obj.getWhere() != null) {
        buffer.append(Tokens.SPACE);
        buffer.append(SQLConstants.Reserved.WHERE).append(Tokens.SPACE);
        visitNode(obj.getWhere());
    }
    if (obj.getGroupBy() != null) {
        buffer.append(Tokens.SPACE);
        append(obj.getGroupBy());
    }
    if (obj.getHaving() != null) {
        buffer.append(Tokens.SPACE).append(HAVING).append(Tokens.SPACE);
        append(obj.getHaving());
    }
    if (obj.getOrderBy() != null) {
        buffer.append(Tokens.SPACE);
        visitNode(obj.getOrderBy());
        if (this.nested) {
            this.exceptions.add(new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25010)));
        }
    }
    if (obj.getLimit() != null) {
        buffer.append(Tokens.SPACE);
        visitNode(obj.getLimit());
    }
    visitNodes(obj.getDerivedColumns());
}
Also used : TranslatorException(org.teiid.translator.TranslatorException)

Example 47 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class InfinispanDirectQueryExecution method execute.

@Override
public void execute() throws TranslatorException {
    String command = (String) this.arguments.get(0).getArgumentValue().getValue();
    BasicCache<String, String> aliasCache = getAliasCache(this.connection);
    Matcher m = truncatePattern.matcher(command);
    if (m.matches()) {
        String tableName = m.group(1);
        clearContents(aliasCache, tableName);
        return;
    }
    m = renamePattern.matcher(command);
    if (m.matches()) {
        String tableOne = m.group(1);
        String tableTwo = m.group(2);
        String aliasName = getAliasName(context, aliasCache, tableOne);
        if (aliasName.equals(tableOne)) {
            aliasCache.put(fqn(context, tableTwo), tableOne);
            aliasCache.put(fqn(context, tableOne), tableTwo);
        } else if (aliasName.equals(tableTwo)) {
            aliasCache.put(fqn(context, tableOne), tableOne);
            aliasCache.put(fqn(context, tableTwo), tableTwo);
        } else {
            throw new TranslatorException(InfinispanPlugin.Event.TEIID25015, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25015, tableOne, aliasName));
        }
        clearContents(aliasCache, tableOne);
        return;
    }
    throw new TranslatorException(InfinispanPlugin.Event.TEIID25016, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25016, command));
}
Also used : Matcher(java.util.regex.Matcher) TranslatorException(org.teiid.translator.TranslatorException)

Example 48 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class InfinispanDirectQueryExecution method clearContents.

private void clearContents(BasicCache<String, String> aliasCache, String tableName) throws TranslatorException {
    tableName = getAliasName(context, aliasCache, tableName);
    Table table = metadata.getTable(tableName);
    String cacheName = ProtobufMetadataProcessor.getCacheName(table);
    BasicCache<Object, Object> cache = connection.getCacheFactory().getCache(cacheName);
    if (cache == null) {
        throw new TranslatorException(InfinispanPlugin.Event.TEIID25014, InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25014, tableName));
    }
    cache.clear();
}
Also used : Table(org.teiid.metadata.Table) TranslatorException(org.teiid.translator.TranslatorException)

Example 49 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class InfinispanQueryExecution method useModifiedGroups.

static void useModifiedGroups(InfinispanConnection connection, ExecutionContext context, RuntimeMetadata metadata, Command command) throws TranslatorException {
    BasicCache<String, String> aliasCache = InfinispanDirectQueryExecution.getAliasCache(connection);
    CollectorVisitor.collectGroups(command).forEach(namedTable -> {
        try {
            Table table = InfinispanDirectQueryExecution.getAliasTable(context, metadata, aliasCache, namedTable.getMetadataObject());
            Collection<ColumnReference> columns = CollectorVisitor.collectElements(command);
            columns.forEach(reference -> {
                if (reference.getTable().getMetadataObject().equals(namedTable.getMetadataObject())) {
                    Column column = table.getColumnByName(reference.getMetadataObject().getName());
                    reference.getTable().setMetadataObject(table);
                    reference.setMetadataObject(column);
                }
            });
            namedTable.setMetadataObject(table);
        } catch (TranslatorException e) {
            LogManager.logError(LogConstants.CTX_CONNECTOR, e, e.getMessage());
        }
    });
}
Also used : Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) ColumnReference(org.teiid.language.ColumnReference)

Example 50 with TranslatorException

use of org.teiid.translator.TranslatorException in project teiid by teiid.

the class InfinispanUpdateExecution method execute.

@Override
public void execute() throws TranslatorException {
    if (useAliasCache) {
        if (useAliasCache) {
            InfinispanQueryExecution.useModifiedGroups(this.connection, this.executionContext, this.metadata, this.command);
        }
    }
    final InfinispanUpdateVisitor visitor = new InfinispanUpdateVisitor(this.metadata);
    visitor.append(this.command);
    if (!visitor.exceptions.isEmpty()) {
        throw visitor.exceptions.get(0);
    }
    TeiidTableMarsheller marshaller = null;
    try {
        Table table = visitor.getParentTable();
        Column pkColumn = visitor.getPrimaryKey();
        if (pkColumn == null) {
            throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25013, table.getName()));
        }
        final String PK = MarshallerBuilder.getDocumentAttributeName(pkColumn, false, this.metadata);
        DocumentFilter docFilter = null;
        if (visitor.isNestedOperation() && visitor.getWhereClause() != null) {
            Action action = Action.ALWAYSADD;
            if (command instanceof Delete) {
                action = Action.REMOVE;
            }
            SQLStringVisitor ssv = new SQLStringVisitor() {

                @Override
                public void visit(ColumnReference obj) {
                    String groupName = null;
                    NamedTable group = obj.getTable();
                    if (group.getCorrelationName() != null) {
                        groupName = group.getCorrelationName();
                    } else {
                        Table groupID = group.getMetadataObject();
                        if (groupID.getFullName().equals(visitor.getParentTable().getFullName())) {
                            groupName = visitor.getParentNamedTable().getCorrelationName();
                        } else {
                            groupName = visitor.getQueryNamedTable().getCorrelationName();
                        }
                    }
                    buffer.append(groupName).append(Tokens.DOT).append(getName(obj.getMetadataObject()));
                }

                @Override
                public String getName(AbstractMetadataRecord object) {
                    return object.getName();
                }
            };
            ssv.append(visitor.getWhereClause());
            docFilter = new ComplexDocumentFilter(visitor.getParentNamedTable(), visitor.getQueryNamedTable(), this.metadata, ssv.toString(), action);
        }
        marshaller = MarshallerBuilder.getMarshaller(table, this.metadata, docFilter);
        this.connection.registerMarshaller(marshaller);
        // if the message in defined in different cache than the default, switch it out now.
        final RemoteCache<Object, Object> cache = InfinispanQueryExecution.getCache(table, connection);
        if (visitor.getOperationType() == OperationType.DELETE) {
            paginateDeleteResults(cache, visitor.getDeleteQuery(), new Task() {

                @Override
                public void run(Object row) throws TranslatorException {
                    if (visitor.isNestedOperation()) {
                        String childName = ProtobufMetadataProcessor.getMessageName(visitor.getQueryTable());
                        InfinispanDocument document = (InfinispanDocument) row;
                        cache.replace(document.getProperties().get(PK), document);
                        // false below means count that not matched, i.e. deleted count
                        updateCount = updateCount + document.getUpdateCount(childName, false);
                    } else {
                        Object key = ((Object[]) row)[0];
                        cache.remove(key);
                        updateCount++;
                    }
                }
            }, this.executionContext.getBatchSize());
        } else if (visitor.getOperationType() == OperationType.UPDATE) {
            paginateUpdateResults(cache, visitor.getUpdateQuery(), new Task() {

                @Override
                public void run(Object row) throws TranslatorException {
                    InfinispanDocument previous = (InfinispanDocument) row;
                    Object key = previous.getProperties().get(PK);
                    int count = previous.merge(visitor.getInsertPayload());
                    cache.replace(key, previous);
                    updateCount = updateCount + count;
                }
            }, this.executionContext.getBatchSize());
        } else if (visitor.getOperationType() == OperationType.INSERT) {
            performInsert(visitor, table, cache, false, marshaller);
        } else if (visitor.getOperationType() == OperationType.UPSERT) {
            performInsert(visitor, table, cache, true, marshaller);
        }
    } finally {
        if (marshaller != null) {
            this.connection.unRegisterMarshaller(marshaller);
        }
    }
}
Also used : Delete(org.teiid.language.Delete) NamedTable(org.teiid.language.NamedTable) Action(org.teiid.infinispan.api.DocumentFilter.Action) NamedTable(org.teiid.language.NamedTable) Table(org.teiid.metadata.Table) SQLStringVisitor(org.teiid.language.visitor.SQLStringVisitor) TeiidTableMarsheller(org.teiid.infinispan.api.TeiidTableMarsheller) InfinispanDocument(org.teiid.infinispan.api.InfinispanDocument) DocumentFilter(org.teiid.infinispan.api.DocumentFilter) AbstractMetadataRecord(org.teiid.metadata.AbstractMetadataRecord) Column(org.teiid.metadata.Column) TranslatorException(org.teiid.translator.TranslatorException) ColumnReference(org.teiid.language.ColumnReference)

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