Author: jdoyle
Date: 2009-12-11 14:59:37 -0500 (Fri, 11 Dec 2009)
New Revision: 1650
Added:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/AbstractUpdateExecution.java
Removed:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionParent.java
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Constants.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/SalesforceConnection.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/DeleteExecutionImpl.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/InsertExecutionImpl.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/QueryExecutionImpl.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionImpl.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/CriteriaVisitor.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/SelectVisitor.java
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/UpdateVisitor.java
trunk/connectors/connector-salesforce/src/test/java/com/metamatrix/connector/salesforce/execution/visitors/TestVisitors.java
Log:
TEIID-180
Consider using Salesforce retrieve() rather than generic query() call for queries with IN
criteria
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Constants.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Constants.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/Constants.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -45,5 +45,7 @@
public static final String RESTRICTED_MULTISELECT_PICKLIST_TYPE =
"restrictedmultiselectpicklist"; //$NON-NLS-1$
public static final String SUPPORTS_QUERY = "Supports Query";
+
+ public static final String SUPPORTS_RETRIEVE = "Supports Retrieve";
}
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/SalesforceConnection.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/SalesforceConnection.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/SalesforceConnection.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -40,12 +40,15 @@
import com.metamatrix.connector.salesforce.Messages;
import com.metamatrix.connector.salesforce.connection.impl.ConnectionImpl;
import com.metamatrix.connector.salesforce.execution.DataPayload;
+import com.metamatrix.connector.salesforce.execution.DeleteExecutionImpl;
import com.metamatrix.connector.salesforce.execution.DeletedResult;
+import com.metamatrix.connector.salesforce.execution.InsertExecutionImpl;
import com.metamatrix.connector.salesforce.execution.ProcedureExecutionParentImpl;
import com.metamatrix.connector.salesforce.execution.QueryExecutionImpl;
-import com.metamatrix.connector.salesforce.execution.UpdateExecutionParent;
+import com.metamatrix.connector.salesforce.execution.UpdateExecutionImpl;
import com.metamatrix.connector.salesforce.execution.UpdatedResult;
import com.sforce.soap.partner.QueryResult;
+import com.sforce.soap.partner.sobject.SObject;
public class SalesforceConnection extends BasicConnection {
@@ -99,7 +102,15 @@
public UpdateExecution createUpdateExecution(ICommand command,
ExecutionContext executionContext, RuntimeMetadata metadata)
throws ConnectorException {
- return new UpdateExecutionParent(command, this, metadata, executionContext,
connectorEnv);
+ UpdateExecution result = null;
+ if(command instanceof org.teiid.connector.language.IDelete) {
+ result = new DeleteExecutionImpl(command, this, metadata, executionContext,
connectorEnv);
+ } else if (command instanceof org.teiid.connector.language.IInsert) {
+ result = new InsertExecutionImpl(command, this, metadata, executionContext,
connectorEnv);
+ } else if (command instanceof org.teiid.connector.language.IUpdate) {
+ result = new UpdateExecutionImpl(command, this, metadata, executionContext,
connectorEnv);
+ }
+ return result;
}
@@ -158,4 +169,11 @@
Calendar endCalendar) throws ConnectorException {
return connection.getDeleted(objectName, startCalendar, endCalendar);
}
+
+ public QueryResult retrieve(String fieldList, String sObjectType, String[] ids) throws
ConnectorException {
+ SObject[] objects = connection.retrieve(fieldList, sObjectType, ids);
+ QueryResult result = new QueryResult(true, "teiid_created_result",
+ objects, objects.length);
+ return result;
+ }
}
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/connection/impl/ConnectionImpl.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -330,4 +330,14 @@
throw new ConnectorException(e, e.getMessage());
}
}
+
+ public SObject[] retrieve(String fieldList, String sObjectType, String[] ids) throws
ConnectorException {
+ try {
+ return binding.retrieve(fieldList, sObjectType, ids);
+ } catch (ApiFault e) {
+ throw new ConnectorException(e.getMessage());
+ } catch (RemoteException e) {
+ throw new ConnectorException(e, e.getMessage());
+ }
+ }
}
Copied:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/AbstractUpdateExecution.java
(from rev 1625,
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionParent.java)
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/AbstractUpdateExecution.java
(rev 0)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/AbstractUpdateExecution.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+package com.metamatrix.connector.salesforce.execution;
+
+import java.util.ArrayList;
+
+import org.teiid.connector.api.ConnectorEnvironment;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.DataNotAvailableException;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.api.UpdateExecution;
+import org.teiid.connector.basic.BasicExecution;
+import org.teiid.connector.language.ICommand;
+import org.teiid.connector.language.ICompareCriteria;
+import org.teiid.connector.language.ICriteria;
+import org.teiid.connector.metadata.runtime.RuntimeMetadata;
+
+import com.metamatrix.connector.salesforce.Util;
+import com.metamatrix.connector.salesforce.connection.SalesforceConnection;
+import com.metamatrix.connector.salesforce.execution.visitors.IQueryProvidingVisitor;
+import com.sforce.soap.partner.QueryResult;
+import com.sforce.soap.partner.sobject.SObject;
+
+/**
+ *
+ * Parent class to the Update, Delete, and Insert execution classes.
+ * Provisions the correct impl and contains some common code to
+ * get IDs of Salesforce objects.
+ *
+ */
+public abstract class AbstractUpdateExecution extends BasicExecution implements
UpdateExecution {
+
+ protected SalesforceConnection connection;
+ protected RuntimeMetadata metadata;
+ protected ExecutionContext context;
+ protected ConnectorEnvironment connectorEnv;
+ protected ICommand command;
+ protected int result;
+
+ public AbstractUpdateExecution(ICommand command, SalesforceConnection
salesforceConnection,
+ RuntimeMetadata metadata, ExecutionContext context,
+ ConnectorEnvironment connectorEnv) {
+ this.connection = salesforceConnection;
+ this.metadata = metadata;
+ this.context = context;
+ this.connectorEnv = connectorEnv;
+ this.command = command;
+ }
+
+ @Override
+ public void cancel() throws ConnectorException {
+ }
+
+ @Override
+ public void close() throws ConnectorException {
+ }
+
+ @Override
+ public int[] getUpdateCounts() throws DataNotAvailableException,
+ ConnectorException {
+ return new int[] {result};
+ }
+
+ public RuntimeMetadata getMetadata() {
+ return metadata;
+ }
+
+ public ConnectorEnvironment getConnectorEnv() {
+ return connectorEnv;
+ }
+
+ public SalesforceConnection getConnection() {
+ return connection;
+ }
+
+ String[] getIDs(ICriteria criteria, IQueryProvidingVisitor visitor) throws
ConnectorException {
+ String[] Ids = null;
+ if (visitor.hasOnlyIDCriteria()) {
+ try {
+ String Id = ((ICompareCriteria)criteria).getRightExpression().toString();
+ Id = Util.stripQutes(Id);
+ Ids = new String[] { Id };
+ } catch (ClassCastException cce) {
+ throw new RuntimeException(
+ "Error: The delete criteria is not a CompareCriteria");
+ }
+
+ } else if (visitor.hasCriteria()) {
+ String query = visitor.getQuery();
+ QueryResult results = getConnection().query(query, context.getBatchSize(),
Boolean.FALSE);
+ if (null != results && results.getSize() > 0) {
+ ArrayList<String> idList = new ArrayList<String>(results
+ .getRecords().length);
+ for (int i = 0; i < results.getRecords().length; i++) {
+ SObject sObject = results.getRecords(i);
+ idList.add(sObject.getId());
+ }
+ Ids = idList.toArray(new String[0]);
+ }
+ }
+ return Ids;
+ }
+}
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/DeleteExecutionImpl.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/DeleteExecutionImpl.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/DeleteExecutionImpl.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -21,22 +21,33 @@
*/
package com.metamatrix.connector.salesforce.execution;
+import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.language.ICommand;
import org.teiid.connector.language.IDelete;
+import org.teiid.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.salesforce.connection.SalesforceConnection;
import com.metamatrix.connector.salesforce.execution.visitors.DeleteVisitor;
-public class DeleteExecutionImpl {
+public class DeleteExecutionImpl extends AbstractUpdateExecution {
- public int execute(IDelete delete, UpdateExecutionParent parent) throws
ConnectorException {
-
- int result = 0;
- DeleteVisitor dVisitor = new DeleteVisitor(parent.getMetadata());
- dVisitor.visitNode(delete);
- String[] Ids = parent.getIDs(delete.getCriteria(), dVisitor);
+
+ public DeleteExecutionImpl(ICommand command,
+ SalesforceConnection salesforceConnection,
+ RuntimeMetadata metadata, ExecutionContext context,
+ ConnectorEnvironment connectorEnv) {
+ super(command, salesforceConnection, metadata, context, connectorEnv);
+ }
+
+ @Override
+ public void execute() throws ConnectorException {
+ DeleteVisitor dVisitor = new DeleteVisitor(getMetadata());
+ dVisitor.visitNode(command);
+ String[] Ids = getIDs(((IDelete)command).getCriteria(), dVisitor);
if(null != Ids && Ids.length > 0) {
- result = parent.getConnection().delete(Ids);
+ result = getConnection().delete(Ids);
}
- return result;
}
}
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/InsertExecutionImpl.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/InsertExecutionImpl.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/InsertExecutionImpl.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -22,21 +22,32 @@
package com.metamatrix.connector.salesforce.execution;
+import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.language.ICommand;
import org.teiid.connector.language.IInsert;
+import org.teiid.connector.metadata.runtime.RuntimeMetadata;
+import com.metamatrix.connector.salesforce.connection.SalesforceConnection;
import com.metamatrix.connector.salesforce.execution.visitors.InsertVisitor;
-public class InsertExecutionImpl {
+public class InsertExecutionImpl extends AbstractUpdateExecution {
- public int execute(IInsert insert,
- UpdateExecutionParent salesforceUpdateExecution) throws ConnectorException {
-
- InsertVisitor visitor = new InsertVisitor(salesforceUpdateExecution.getMetadata());
- visitor.visit(insert);
+ public InsertExecutionImpl(ICommand command,
+ SalesforceConnection salesforceConnection,
+ RuntimeMetadata metadata, ExecutionContext context,
+ ConnectorEnvironment connectorEnv) {
+ super(command, salesforceConnection, metadata, context, connectorEnv);
+ }
+
+ @Override
+ public void execute() throws ConnectorException {
+ InsertVisitor visitor = new InsertVisitor(getMetadata());
+ visitor.visit((IInsert)command);
DataPayload data = new DataPayload();
data.setType(visitor.getTableName());
data.setMessageElements(visitor.getMessageElements());
- return salesforceUpdateExecution.getConnection().create(data);
+ result = getConnection().create(data);
}
}
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/QueryExecutionImpl.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/QueryExecutionImpl.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/QueryExecutionImpl.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -118,18 +118,28 @@
connectorEnv.getLogger().logInfo(
getLogPreamble() + "Incoming Query: " + query.toString());
IFrom from = ((IQuery)query).getFrom();
+ String finalQuery;
if(from.getItems().get(0) instanceof IJoin) {
visitor = new JoinQueryVisitor(metadata);
+ visitor.visitNode(query);
+ finalQuery = visitor.getQuery().trim();
+ connectorEnv.getLogger().logInfo(
+ getLogPreamble() + "Executing Query: " + finalQuery);
+
+ results = connection.query(finalQuery, this.context.getBatchSize(),
visitor.getQueryAll());
} else {
visitor = new SelectVisitor(metadata);
+ visitor.visitNode(query);
+ if(visitor.canRetrieve()) {
+ results = connection.retrieve(visitor.getRetrieveFieldList(),
+ visitor.getTableName(), visitor.getIdInCriteria());
+ } else {
+ finalQuery = visitor.getQuery().trim();
+ connectorEnv.getLogger().logInfo(
+ getLogPreamble() + "Executing Query: " + finalQuery);
+ results = connection.query(finalQuery, this.context.getBatchSize(),
visitor.getQueryAll());
+ }
}
- visitor.visitNode(query);
- String finalQuery;
- finalQuery = visitor.getQuery().trim();
- connectorEnv.getLogger().logInfo(
- getLogPreamble() + "Executing Query: " + finalQuery);
-
- results = connection.query(finalQuery, this.context.getBatchSize(),
visitor.getQueryAll());
}
@SuppressWarnings("unchecked")
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionImpl.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionImpl.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionImpl.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -27,29 +27,39 @@
import javax.xml.namespace.QName;
import org.apache.axis.message.MessageElement;
+import org.teiid.connector.api.ConnectorEnvironment;
import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.ExecutionContext;
+import org.teiid.connector.language.ICommand;
import org.teiid.connector.language.IElement;
import org.teiid.connector.language.ILiteral;
import org.teiid.connector.language.ISetClause;
import org.teiid.connector.language.IUpdate;
import org.teiid.connector.metadata.runtime.Element;
+import org.teiid.connector.metadata.runtime.RuntimeMetadata;
import com.metamatrix.connector.salesforce.Util;
+import com.metamatrix.connector.salesforce.connection.SalesforceConnection;
import com.metamatrix.connector.salesforce.execution.visitors.UpdateVisitor;
-public class UpdateExecutionImpl {
+public class UpdateExecutionImpl extends AbstractUpdateExecution {
- public int execute(IUpdate update, UpdateExecutionParent parent)
- throws ConnectorException {
- int result = 0;
- UpdateVisitor visitor = new UpdateVisitor(parent
- .getMetadata());
- visitor.visit(update);
- String[] Ids = parent.getIDs(update.getCriteria(), visitor);
+ public UpdateExecutionImpl(ICommand command,
+ SalesforceConnection salesforceConnection,
+ RuntimeMetadata metadata, ExecutionContext context,
+ ConnectorEnvironment connectorEnv) {
+ super(command, salesforceConnection, metadata, context, connectorEnv);
+ }
+ @Override
+ public void execute() throws ConnectorException {
+ UpdateVisitor visitor = new UpdateVisitor(getMetadata());
+ visitor.visit((IUpdate)command);
+ String[] Ids = getIDs(((IUpdate)command).getCriteria(), visitor);
+
if (null != Ids && Ids.length > 0) {
List<MessageElement> elements = new ArrayList<MessageElement>();
- for (ISetClause clause : update.getChanges().getClauses()) {
+ for (ISetClause clause : ((IUpdate)command).getChanges().getClauses()) {
IElement element = clause.getSymbol();
Element column = element.getMetadataObject();
String val = ((ILiteral) clause.getValue())
@@ -69,9 +79,7 @@
updateDataList.add(data);
}
- result = parent.getConnection().update(updateDataList);
+ result = getConnection().update(updateDataList);
}
- return result;
}
-
}
Deleted:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionParent.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionParent.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/UpdateExecutionParent.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -1,139 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-package com.metamatrix.connector.salesforce.execution;
-
-import java.util.ArrayList;
-
-import org.teiid.connector.api.ConnectorEnvironment;
-import org.teiid.connector.api.ConnectorException;
-import org.teiid.connector.api.DataNotAvailableException;
-import org.teiid.connector.api.ExecutionContext;
-import org.teiid.connector.api.UpdateExecution;
-import org.teiid.connector.basic.BasicExecution;
-import org.teiid.connector.language.ICommand;
-import org.teiid.connector.language.ICompareCriteria;
-import org.teiid.connector.language.ICriteria;
-import org.teiid.connector.language.IDelete;
-import org.teiid.connector.language.IInsert;
-import org.teiid.connector.language.IUpdate;
-import org.teiid.connector.metadata.runtime.RuntimeMetadata;
-
-import com.metamatrix.connector.salesforce.Util;
-import com.metamatrix.connector.salesforce.connection.SalesforceConnection;
-import com.metamatrix.connector.salesforce.execution.visitors.IQueryProvidingVisitor;
-import com.sforce.soap.partner.QueryResult;
-import com.sforce.soap.partner.sobject.SObject;
-
-/**
- *
- * Parent class to the Update, Delete, and Insert execution classes.
- * Provisions the correct impl and contains some common code to
- * get IDs of Salesforce objects.
- *
- */
-public class UpdateExecutionParent extends BasicExecution implements UpdateExecution {
-
- private SalesforceConnection connection;
- private RuntimeMetadata metadata;
- private ExecutionContext context;
- private ConnectorEnvironment connectorEnv;
- private ICommand command;
- private int result;
-
- public UpdateExecutionParent(ICommand command, SalesforceConnection
salesforceConnection,
- RuntimeMetadata metadata, ExecutionContext context,
- ConnectorEnvironment connectorEnv) {
- this.connection = salesforceConnection;
- this.metadata = metadata;
- this.context = context;
- this.connectorEnv = connectorEnv;
- this.command = command;
- }
-
- @Override
- public void cancel() throws ConnectorException {
- }
-
- @Override
- public void close() throws ConnectorException {
- }
-
- @Override
- public void execute() throws ConnectorException {
- if(command instanceof org.teiid.connector.language.IDelete) {
- DeleteExecutionImpl ex = new DeleteExecutionImpl();
- result = ex.execute(((IDelete)command), this);
- } else if (command instanceof org.teiid.connector.language.IInsert) {
- InsertExecutionImpl ex = new InsertExecutionImpl();
- result = ex.execute(((IInsert)command), this);
- } else if (command instanceof org.teiid.connector.language.IUpdate) {
- UpdateExecutionImpl ex = new UpdateExecutionImpl();
- result = ex.execute(((IUpdate)command), this);
- }
- }
-
- @Override
- public int[] getUpdateCounts() throws DataNotAvailableException,
- ConnectorException {
- return new int[] {result};
- }
-
- public RuntimeMetadata getMetadata() {
- return metadata;
- }
-
- public ConnectorEnvironment getConnectorEnv() {
- return connectorEnv;
- }
-
- public SalesforceConnection getConnection() {
- return connection;
- }
-
- String[] getIDs(ICriteria criteria, IQueryProvidingVisitor visitor) throws
ConnectorException {
- String[] Ids = null;
- if (visitor.hasOnlyIDCriteria()) {
- try {
- String Id = ((ICompareCriteria)criteria).getRightExpression().toString();
- Id = Util.stripQutes(Id);
- Ids = new String[] { Id };
- } catch (ClassCastException cce) {
- throw new RuntimeException(
- "Error: The delete criteria is not a CompareCriteria");
- }
-
- } else if (visitor.hasCriteria()) {
- String query = visitor.getQuery();
- QueryResult results = getConnection().query(query, context.getBatchSize(),
Boolean.FALSE);
- if (null != results && results.getSize() > 0) {
- ArrayList<String> idList = new ArrayList<String>(results
- .getRecords().length);
- for (int i = 0; i < results.getRecords().length; i++) {
- SObject sObject = results.getRecords(i);
- idList.add(sObject.getId());
- }
- Ids = idList.toArray(new String[0]);
- }
- }
- return Ids;
- }
-}
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/CriteriaVisitor.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/CriteriaVisitor.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/CriteriaVisitor.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -76,6 +76,10 @@
protected Group table;
boolean onlyIDCriteria;
protected Boolean queryAll = Boolean.FALSE;
+
+ // support for invoking a retrieve when possible.
+ protected IInCriteria idInCriteria = null;
+
public CriteriaVisitor( RuntimeMetadata metadata ) {
this.metadata = metadata;
@@ -322,9 +326,12 @@
private void appendCriteria( IInCriteria criteria ) throws ConnectorException {
StringBuffer queryString = new StringBuffer();
+ IExpression leftExp = criteria.getLeftExpression();
+ if(isIdColumn(leftExp)) {
+ idInCriteria = criteria;
+ }
+ queryString.append(getValue(leftExp));
queryString.append(' ');
- queryString.append(getValue(criteria.getLeftExpression()));
- queryString.append(' ');
if (criteria.isNegated()) {
queryString.append("NOT ");
}
@@ -354,7 +361,7 @@
return result;
}
- private String getValue( IExpression expr ) throws ConnectorException {
+ protected String getValue( IExpression expr ) throws ConnectorException {
String result;
if (expr instanceof IElement) {
IElement element = (IElement)expr;
@@ -378,7 +385,7 @@
}
List<Element> columnIds = table.getChildren();
for (Element element : columnIds) {
- String name = table.getName() + '.' + element.getName();
+ String name = table.getName() + '.' + element.getNameInSource();
columnElementsByName.put(name, element);
// influences queryAll behavior
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/SelectVisitor.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/SelectVisitor.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/SelectVisitor.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -51,6 +51,7 @@
private int idIndex = -1; // index of the ID select symbol.
protected List<ISelectSymbol> selectSymbols;
protected StringBuffer limitClause = new StringBuffer();
+ private Boolean supportsRetrieve;
public SelectVisitor(RuntimeMetadata metadata) {
super(metadata);
@@ -112,6 +113,7 @@
if(fromItem instanceof IGroup) {
table = ((IGroup)fromItem).getMetadataObject();
String supportsQuery =
(String)table.getProperties().get(Constants.SUPPORTS_QUERY);
+ supportsRetrieve =
Boolean.valueOf((String)table.getProperties().get(Constants.SUPPORTS_RETRIEVE));
if (!Boolean.valueOf(supportsQuery)) {
throw new ConnectorException(table.getNameInSource() + " "
+
Messages.getString("CriteriaVisitor.query.not.supported"));
@@ -198,4 +200,37 @@
return queryAll;
}
+
+ public String getRetrieveFieldList() throws ConnectorException {
+ assertRetrieveValidated();
+ StringBuffer result = new StringBuffer();
+ addSelectSymbols(table.getNameInSource(), result);
+ return result.toString();
+ }
+
+
+ public String[] getIdInCriteria() throws ConnectorException {
+ assertRetrieveValidated();
+ List<IExpression> expressions = this.idInCriteria.getRightExpressions();
+ String[] result = new String[expressions.size()];
+ for(int i = 0; i < expressions.size(); i++) {
+ result[i] = getValue(expressions.get(i));
+ }
+ return result;
+ }
+
+ private void assertRetrieveValidated() throws AssertionError {
+ if(!hasOnlyIDCriteria()) {
+ throw new AssertionError("Must call hasOnlyIdInCriteria() before this
method");
+ }
+ }
+
+ public boolean hasOnlyIdInCriteria() {
+ return hasOnlyIDCriteria() && idInCriteria != null;
+ }
+
+ public boolean canRetrieve() {
+ return supportsRetrieve && hasOnlyIDCriteria();
+ }
+
}
Modified:
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/UpdateVisitor.java
===================================================================
---
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/UpdateVisitor.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/main/java/com/metamatrix/connector/salesforce/execution/visitors/UpdateVisitor.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -21,8 +21,6 @@
*/
package com.metamatrix.connector.salesforce.execution.visitors;
-import java.util.Iterator;
-
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.language.IUpdate;
import org.teiid.connector.metadata.runtime.RuntimeMetadata;
Modified:
trunk/connectors/connector-salesforce/src/test/java/com/metamatrix/connector/salesforce/execution/visitors/TestVisitors.java
===================================================================
---
trunk/connectors/connector-salesforce/src/test/java/com/metamatrix/connector/salesforce/execution/visitors/TestVisitors.java 2009-12-11
18:32:04 UTC (rev 1649)
+++
trunk/connectors/connector-salesforce/src/test/java/com/metamatrix/connector/salesforce/execution/visitors/TestVisitors.java 2009-12-11
19:59:37 UTC (rev 1650)
@@ -132,23 +132,37 @@
visitor.visit(command);
assertEquals("SELECT Account.id, Account.AccountName, Account.Stuff,
Account.Industry FROM Account WHERE (NOT (Account.AccountName LIKE '%foo')) OR
(Account.Stuff = 'bar')", visitor.getQuery().toString().trim());
//$NON-NLS-1$
}
+
- // I can't really write this test until I see what teiid is going to pass the
connectro based upon the user query.
- // SELECT Account.Name AS c_0, Contact.Name AS c_1 FROM Contact LEFT OUTER JOIN Account
ON Account.Id = Contact.AccountId
+ @Test public void testIN() throws Exception {
+ IQuery command = (IQuery)translationUtility.parseCommand("select * from Account
where Industry IN (1,2,3)"); //$NON-NLS-1$
+ SelectVisitor visitor = new SelectVisitor(translationUtility.createRuntimeMetadata());
+ visitor.visit(command);
+ assertFalse(visitor.hasOnlyIDCriteria());
+ assertEquals("SELECT Account.id, Account.AccountName, Account.Stuff,
Account.Industry FROM Account WHERE Industry
IN('1','2','3')", visitor.getQuery().toString().trim());
//$NON-NLS-1$
+
+ }
+
+ @Test public void testOnlyIDsIN() throws Exception {
+ // this can resolve to a better performing retrieve call
+ IQuery command = (IQuery)translationUtility.parseCommand("select * from Account
where ID IN (1,2,3)"); //$NON-NLS-1$
+ SelectVisitor visitor = new SelectVisitor(translationUtility.createRuntimeMetadata());
+ visitor.visit(command);
+ assertTrue(visitor.hasOnlyIdInCriteria());
+ assertEquals("Account", visitor.getTableName());
+ assertEquals("Account.id, Account.AccountName, Account.Stuff,
Account.Industry", visitor.getRetrieveFieldList());
+ assertEquals(new String[]{"1", "2", "3"},
visitor.getIdInCriteria());
+ }
+
@Test public void testJoin() throws Exception {
IQuery command = (IQuery)translationUtility.parseCommand("SELECT Account.Name,
Contact.Name FROM Contact LEFT OUTER JOIN Account ON Account.Id =
Contact.AccountId"); //$NON-NLS-1$
-
SelectVisitor visitor = new
JoinQueryVisitor(translationUtility.createRuntimeMetadata());
visitor.visit(command);
assertEquals("SELECT Account.AccountName, Contact.ContactName FROM Contact",
visitor.getQuery().toString().trim()); //$NON-NLS-1$
- // SELECT Contact.Id, Contact.Name, Account.Name FROM Contact WHERE Account.Industry !=
'media'
- // Looks like using q names will work, but we need to distinguish between the parent
and child table somehow cannot send
- // SELECT Contact.Id, Contact.Name, Account.Name FROM Contact, Account WHERE
Account.Industry != 'media'
}
@Test public void testJoin2() throws Exception {
IQuery command = (IQuery)translationUtility.parseCommand("SELECT Account.Name,
Contact.Name FROM Account LEFT OUTER JOIN Contact ON Account.Id =
Contact.AccountId"); //$NON-NLS-1$
-
SelectVisitor visitor = new
JoinQueryVisitor(translationUtility.createRuntimeMetadata());
visitor.visit(command);
assertEquals("SELECT Account.AccountName, (SELECT Contact.ContactName FROM
Contacts) FROM Account", visitor.getQuery().toString().trim()); //$NON-NLS-1$