Author: shawkins
Date: 2012-10-03 10:27:31 -0400 (Wed, 03 Oct 2012)
New Revision: 4509
Modified:
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java
Log:
TEIID-2177 adding olap canned queries
Modified:
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java
===================================================================
---
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java 2012-10-03
13:10:21 UTC (rev 4508)
+++
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapExecutionFactory.java 2012-10-03
14:27:31 UTC (rev 4509)
@@ -30,7 +30,9 @@
import org.olap4j.OlapConnection;
import org.olap4j.OlapWrapper;
import org.teiid.language.Argument;
+import org.teiid.language.Call;
import org.teiid.language.Command;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.metadata.RuntimeMetadata;
@@ -52,8 +54,19 @@
@Override
public ProcedureExecution createDirectExecution(List<Argument> arguments,
Command command, ExecutionContext executionContext, RuntimeMetadata metadata, Connection
connection) throws TranslatorException {
- return new OlapQueryExecution(arguments, command, unwrap(connection),
executionContext, this);
+ return new OlapQueryExecution(arguments.subList(1, arguments.size()), command,
unwrap(connection), executionContext, this, (String)
arguments.get(0).getArgumentValue().getValue(), true);
}
+
+ @Override
+ public ProcedureExecution createProcedureExecution(Call command,
+ ExecutionContext executionContext, RuntimeMetadata metadata,
+ Connection connection) throws TranslatorException {
+ String nativeQuery =
command.getMetadataObject().getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, false);
+ if (nativeQuery != null) {
+ return new OlapQueryExecution(command.getArguments(), command, unwrap(connection),
executionContext, this, nativeQuery, false);
+ }
+ throw new TranslatorException("Missing native-query extension metadata.");
//$NON-NLS-1$
+ }
private OlapConnection unwrap(Connection conn) throws TranslatorException {
try {
Modified:
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java
===================================================================
---
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java 2012-10-03
13:10:21 UTC (rev 4508)
+++
trunk/connectors/translator-olap/src/main/java/org/teiid/translator/olap/OlapQueryExecution.java 2012-10-03
14:27:31 UTC (rev 4509)
@@ -23,6 +23,7 @@
import java.sql.SQLException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
@@ -36,6 +37,7 @@
import org.olap4j.metadata.Member;
import org.teiid.language.Argument;
import org.teiid.language.Command;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.logging.LogConstants;
import org.teiid.logging.LogManager;
import org.teiid.translator.ExecutionContext;
@@ -57,13 +59,27 @@
private int colWidth;
private ListIterator<Position> rowPositionIterator;
private String mdxQuery;
+ private boolean returnsArray;
- public OlapQueryExecution(List<Argument> arguments, Command command,
OlapConnection connection, ExecutionContext context, OlapExecutionFactory
executionFactory) {
- this.mdxQuery = (String) arguments.get(0).getArgumentValue().getValue();;
+ public OlapQueryExecution(List<Argument> arguments, Command command,
OlapConnection connection, ExecutionContext context, OlapExecutionFactory
executionFactory, String mdxQuery, boolean returnsArray) {
+ this.mdxQuery = mdxQuery;
+ if (arguments.size() > 0 || !returnsArray) { //TODO this is a hack at backwards
compatibility
+ StringBuilder buffer = new StringBuilder();
+ List<Object> parts = SQLStringVisitor.parseNativeQueryParts(this.mdxQuery,
arguments);
+ for (Object o : parts) {
+ if (o instanceof String) {
+ buffer.append(o);
+ } else {
+ Integer i = (Integer)o;
+ buffer.append(arguments.get(i).getArgumentValue().getValue());
+ }
+ }
+ }
this.command = command;
this.connection = connection;
this.context = context;
this.executionFactory = executionFactory;
+ this.returnsArray = returnsArray;
}
@Override
@@ -124,9 +140,12 @@
Cell cell = cellSet.getCell(colPos, rowPosition);
result[i++] = cell.getValue();
}
- ArrayList<Object[]> results = new ArrayList<Object[]>(1);
- results.add(result);
- return results;
+ if (returnsArray) {
+ ArrayList<Object[]> results = new ArrayList<Object[]>(1);
+ results.add(result);
+ return results;
+ }
+ return Arrays.asList(result);
}
@Override
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java
===================================================================
---
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-10-03
13:10:21 UTC (rev 4508)
+++
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/SalesForceExecutionFactory.java 2012-10-03
14:27:31 UTC (rev 4509)
@@ -56,7 +56,6 @@
import org.teiid.translator.salesforce.execution.ProcedureExecutionParentImpl;
import org.teiid.translator.salesforce.execution.QueryExecutionImpl;
import org.teiid.translator.salesforce.execution.UpdateExecutionImpl;
-import org.teiid.translator.salesforce.execution.visitors.CriteriaVisitor;
@Translator(name="salesforce", description="A translator for
Salesforce")
public class SalesForceExecutionFactory extends ExecutionFactory<ConnectionFactory,
SalesforceConnection> {
@@ -117,27 +116,14 @@
Procedure metadataObject = command.getMetadataObject();
String nativeQuery = metadataObject.getProperty(SQLStringVisitor.TEIID_NATIVE_QUERY,
false);
if (nativeQuery != null) {
- if (nativeQuery.startsWith(DirectQueryExecution.SEARCH)) {
- StringBuilder buffer = new StringBuilder();
- List<Object> parts = SQLStringVisitor.parseNativeQueryParts(nativeQuery,
command.getArguments());
- for (Object o : parts) {
- if (o instanceof String) {
- buffer.append(o);
- } else {
- Integer i = (Integer)o;
- CriteriaVisitor.appendLiteralValue(buffer,
command.getArguments().get(i).getArgumentValue());
- }
- }
- nativeQuery = buffer.toString();
- }
- return new DirectQueryExecution(command.getArguments(), command, connection, metadata,
executionContext, nativeQuery);
+ return new DirectQueryExecution(command.getArguments(), command, connection, metadata,
executionContext, nativeQuery, false);
}
return new ProcedureExecutionParentImpl(command, connection, metadata,
executionContext);
}
@Override
public ProcedureExecution createDirectExecution(List<Argument> arguments, Command
command, ExecutionContext executionContext, RuntimeMetadata metadata, SalesforceConnection
connection) throws TranslatorException {
- return new DirectQueryExecution(arguments.subList(1, arguments.size()), command,
connection, metadata, executionContext,
(String)arguments.get(0).getArgumentValue().getValue());
+ return new DirectQueryExecution(arguments.subList(1, arguments.size()), command,
connection, metadata, executionContext,
(String)arguments.get(0).getArgumentValue().getValue(), true);
}
@Override
Modified:
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java
===================================================================
---
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java 2012-10-03
13:10:21 UTC (rev 4508)
+++
trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/execution/DirectQueryExecution.java 2012-10-03
14:27:31 UTC (rev 4509)
@@ -32,6 +32,7 @@
import org.teiid.language.Argument;
import org.teiid.language.Command;
+import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.translator.DataNotAvailableException;
import org.teiid.translator.ExecutionContext;
@@ -40,6 +41,7 @@
import org.teiid.translator.salesforce.SalesForcePlugin;
import org.teiid.translator.salesforce.SalesforceConnection;
import org.teiid.translator.salesforce.Util;
+import org.teiid.translator.salesforce.execution.visitors.CriteriaVisitor;
import org.w3c.dom.Element;
import com.sforce.soap.partner.QueryResult;
@@ -62,6 +64,7 @@
private int updateCount = -1;
private boolean updateQuery = false;
private String query;
+ private boolean returnsArray = true;
/**
*
@@ -72,19 +75,30 @@
* @param context
* @param query
*/
- public DirectQueryExecution(List<Argument> arguments, Command command,
SalesforceConnection connection, RuntimeMetadata metadata, ExecutionContext context,
String query) {
+ public DirectQueryExecution(List<Argument> arguments, Command command,
SalesforceConnection connection, RuntimeMetadata metadata, ExecutionContext context,
String query, boolean returnsArray) {
this.arguments = arguments;
this.command = command;
this.connection = connection;
this.metadata = metadata;
this.context = context;
this.query = query;
+ this.returnsArray = returnsArray;
}
-
+
@Override
public void execute() throws TranslatorException {
if (query.startsWith(SEARCH)) {
- doSelect(query.substring(7));
+ StringBuilder buffer = new StringBuilder();
+ List<Object> parts = SQLStringVisitor.parseNativeQueryParts(query, arguments);
+ for (Object o : parts) {
+ if (o instanceof String) {
+ buffer.append(o);
+ } else {
+ Integer i = (Integer)o;
+ CriteriaVisitor.appendLiteralValue(buffer, arguments.get(i).getArgumentValue());
+ }
+ }
+ doSelect(buffer.toString().substring(7));
}
else if (query.startsWith("create;")) { //$NON-NLS-1$
doInsert(query.substring(7));
@@ -150,9 +164,12 @@
if (vals == null) {
return null;
}
- List<Object[]> row = new ArrayList<Object[]>(1);
- row.add(vals.toArray(new Object[vals.size()]));
- return row;
+ if (returnsArray) {
+ List<Object[]> row = new ArrayList<Object[]>(1);
+ row.add(vals.toArray(new Object[vals.size()]));
+ return row;
+ }
+ return vals;
}
private List<?> getRow(QueryResult result) throws TranslatorException {