@Override public void execute() throws TranslatorException { String worksheet = null; Integer limit = null; Integer offset = null; String toQuery = query; List<String> parts = StringUtil.tokenize(query, ';'); for (String var : parts) { int index = var.indexOf('='); if (index == -1) { continue; } String key = var.substring(0, index).trim(); String value = var.substring(index + 1).trim(); if (key.equalsIgnoreCase(WORKSHEET)) { worksheet = value; } else if (key.equalsIgnoreCase(QUERY)) { StringBuilder buffer = new StringBuilder(); SQLStringVisitor.parseNativeQueryParts( value, arguments, buffer, new SQLStringVisitor.Substitutor() { @Override public void substitute(Argument arg, StringBuilder builder, int index) { Literal argumentValue = arg.getArgumentValue(); SpreadsheetSQLVisitor visitor = new SpreadsheetSQLVisitor(); visitor.visit(argumentValue); builder.append(visitor.getTranslatedSQL()); } }); toQuery = buffer.toString(); } else if (key.equalsIgnoreCase(LIMIT)) { limit = Integer.parseInt(value); } else if (key.equalsIgnoreCase(OFFEST)) { offset = Integer.parseInt(value); } } this.rowIterator = this.connection .executeQuery(worksheet, toQuery, offset, limit, executionContext.getBatchSize()) .iterator(); }
public String toString() { if (!source) { if (event == Event.NEW) { return "\tSTART USER COMMAND:\tstartTime=" + new Timestamp(timestamp) + "\trequestID=" + requestID + "\ttxID=" + transactionID + "\tsessionID=" + sessionID + "\tapplicationName=" + applicationName + "\tprincipal=" + principal + "\tvdbName=" + vdbName + "\tvdbVersion=" + vdbVersion + "\tsql=" + sql; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ // //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ } return "\t" + event + " USER COMMAND:\tendTime=" + new Timestamp(timestamp) + "\trequestID=" + requestID + "\ttxID=" + transactionID + "\tsessionID=" + sessionID + "\tprincipal=" + principal + "\tvdbName=" + vdbName + "\tvdbVersion=" + vdbVersion + "\tfinalRowCount=" + rowCount + ((plan != null) ? "\tplan=" + plan : ""); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ // //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ // //$NON-NLS-11$ } if (event == Event.NEW) { return "\tSTART DATA SRC COMMAND:\tstartTime=" + new Timestamp(timestamp) + "\trequestID=" + requestID + "\tsourceCommandID=" + sourceCommandID + "\texecutionID=" + executionContext.getExecutionCountIdentifier() + "\ttxID=" + transactionID + "\tmodelName=" + modelName + "\ttranslatorName=" + translatorName + "\tsessionID=" + sessionID + "\tprincipal=" + principal + "\tsql=" + sql; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ //$NON-NLS-6$ // //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ } return "\t" + event + " SRC COMMAND:\tendTime=" + new Timestamp(timestamp) + "\trequestID=" + requestID + "\tsourceCommandID=" + sourceCommandID + "\texecutionID=" + executionContext.getExecutionCountIdentifier() + "\ttxID=" + transactionID + "\tmodelName=" + modelName + "\ttranslatorName=" + translatorName + "\tsessionID=" + sessionID + "\tprincipal=" + principal + "\tfinalRowCount=" + rowCount + "\tcpuTime(ns)=" + cpuTime; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$//$NON-NLS-5$ // //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-10$ // //$NON-NLS-11$ //$NON-NLS-12$ }
@Override public String getSourceComment(ExecutionContext context, Command command) { String comment = super.getSourceComment(context, command); boolean usingPayloadComment = false; if (context != null) { // Check for db hints Object payload = context.getCommandPayload(); if (payload instanceof String) { String payloadString = (String) payload; if (payloadString.startsWith(HINT_PREFIX)) { int i = payloadString.indexOf(HINT_SUFFIX); if (i > 0 && payloadString.substring(i + 2).trim().length() == 0) { comment += payloadString + " "; // $NON-NLS-1$ usingPayloadComment = true; } else { String msg = JDBCPlugin.Util.gs( JDBCPlugin.Event.TEIID11003, "Execution Payload", payloadString); // $NON-NLS-1$ context.addWarning(new TranslatorException(msg)); LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg); } } } } if (!usingPayloadComment && context != null) { String hint = context.getSourceHint(); if (context.getGeneralHint() != null) { if (hint != null) { hint += (" " + context.getGeneralHint()); // $NON-NLS-1$ } else { hint = context.getGeneralHint(); } } if (hint != null) { // append a source hint if (!hint.contains(HINT_PREFIX)) { comment += HINT_PREFIX + ' ' + hint + ' ' + HINT_SUFFIX + ' '; } else { String msg = JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11003, "Source Hint", hint); // $NON-NLS-1$ context.addWarning(new TranslatorException(msg)); LogManager.logWarning(LogConstants.CTX_CONNECTOR, msg); } } } if (command instanceof Select) { // // This simple algorithm determines the hint which will be added to the // query. // Right now, we look through all functions passed in the query // (returned as a collection) // Then we check if any of those functions are sdo_relate // If so, the ORDERED hint is added, if not, it isn't Collection<Function> col = CollectorVisitor.collectObjects(Function.class, command); for (Function func : col) { if (func.getName().equalsIgnoreCase(OracleExecutionFactory.RELATE)) { return comment + "/*+ ORDERED */ "; // $NON-NLS-1$ } } } return comment; }