Search in sources :

Example 1 with SelectVisitor

use of org.teiid.translator.salesforce.execution.visitors.SelectVisitor in project teiid by teiid.

the class QueryExecutionImpl method execute.

@Override
public void execute() throws TranslatorException {
    try {
        // redundant with command log
        // $NON-NLS-1$
        LogManager.logDetail(LogConstants.CTX_CONNECTOR, getLogPreamble(), "Incoming Query:", query);
        List<TableReference> from = ((Select) query).getFrom();
        boolean join = false;
        if (from.get(0) instanceof Join) {
            join = true;
            visitor = new JoinQueryVisitor(metadata);
        } else {
            visitor = new SelectVisitor(metadata);
        }
        visitor.visitNode(query);
        if (visitor.canRetrieve()) {
            // $NON-NLS-1$
            context.logCommand("Using retrieve: ", visitor.getRetrieveFieldList(), visitor.getTableName(), visitor.getIdInCriteria());
            results = this.executionFactory.buildQueryResult(connection.retrieve(visitor.getRetrieveFieldList(), visitor.getTableName(), visitor.getIdInCriteria()));
        } else {
            String finalQuery = visitor.getQuery().trim();
            // redundant
            // $NON-NLS-1$
            LogManager.logDetail(LogConstants.CTX_CONNECTOR, getLogPreamble(), "Executing Query:", finalQuery);
            context.logCommand(finalQuery);
            if (!join && !visitor.getQueryAll() && (context.getSourceHints() != null && context.getSourceHints().contains("bulk"))) {
                // $NON-NLS-1$
                BulkValidator bulkValidator = new BulkValidator();
                query.acceptVisitor(bulkValidator);
                if (bulkValidator.isBulkEligible()) {
                    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
                    LogManager.logDetail(LogConstants.CTX_CONNECTOR, getLogPreamble(), "Using bulk logic", bulkValidator.usePkChunking() ? "with" : "without", "pk chunking");
                    this.activeJob = connection.createBulkJob(visitor.getTableName(), OperationEnum.query, bulkValidator.usePkChunking());
                    batchInfo = connection.addBatch(finalQuery, this.activeJob);
                    return;
                }
                // $NON-NLS-1$
                LogManager.logDetail(LogConstants.CTX_CONNECTOR, getLogPreamble(), "Ingoring bulk hint as the query is not bulk eligible");
            }
            results = connection.query(finalQuery, this.context.getBatchSize(), visitor.getQueryAll());
        }
    } catch (ResourceException e) {
        throw new TranslatorException(e);
    }
}
Also used : SelectVisitor(org.teiid.translator.salesforce.execution.visitors.SelectVisitor) JoinQueryVisitor(org.teiid.translator.salesforce.execution.visitors.JoinQueryVisitor) ResourceException(javax.resource.ResourceException) TranslatorException(org.teiid.translator.TranslatorException)

Aggregations

ResourceException (javax.resource.ResourceException)1 TranslatorException (org.teiid.translator.TranslatorException)1 JoinQueryVisitor (org.teiid.translator.salesforce.execution.visitors.JoinQueryVisitor)1 SelectVisitor (org.teiid.translator.salesforce.execution.visitors.SelectVisitor)1