METAMODEL-1151: Added DataContextFactory for Salesforce Project: http://git-wip-us.apache.org/repos/asf/metamodel/repo Commit: http://git-wip-us.apache.org/repos/asf/metamodel/commit/22b9164a Tree: http://git-wip-us.apache.org/repos/asf/metamodel/tree/22b9164a Diff: http://git-wip-us.apache.org/repos/asf/metamodel/diff/22b9164a
Branch: refs/heads/master Commit: 22b9164ae7d35c26a51db70b2b62c40174813c4b Parents: 38676da Author: Kasper Sørensen <i.am.kasper.soren...@gmail.com> Authored: Sun Aug 6 19:42:07 2017 -0700 Committer: Kasper Sørensen <i.am.kasper.soren...@gmail.com> Committed: Sun Aug 6 19:42:07 2017 -0700 ---------------------------------------------------------------------- .../salesforce/SalesforceDataContext.java | 30 ++++++------- .../SalesforceDataContextFactory.java | 47 ++++++++++++++++++++ .../salesforce/SalesforceUpdateCallback.java | 30 ++++++------- 3 files changed, 75 insertions(+), 32 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/metamodel/blob/22b9164a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java ---------------------------------------------------------------------- diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java index 37467b7..0fc4257 100644 --- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java +++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContext.java @@ -24,8 +24,6 @@ import java.util.List; import java.util.Locale; import java.util.TimeZone; -import com.sforce.ws.ConnectorConfig; - import org.apache.metamodel.MetaModelException; import org.apache.metamodel.QueryPostprocessDataContext; import org.apache.metamodel.UpdateScript; @@ -50,16 +48,16 @@ import com.sforce.soap.partner.Connector; import com.sforce.soap.partner.PartnerConnection; import com.sforce.soap.partner.QueryResult; import com.sforce.ws.ConnectionException; +import com.sforce.ws.ConnectorConfig; /** * A datacontext that uses the Salesforce API. * - * Metadata about schema structure is explored using 'describe' SOAP web - * services. + * Metadata about schema structure is explored using 'describe' SOAP web services. * - * Queries are fired using the SOQL dialect of SQL, see <a href= - * "http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select.htm" - * >SOQL reference</a>. + * Queries are fired using the SOQL dialect of SQL, see + * <a href= "http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select.htm" >SOQL + * reference</a>. */ public class SalesforceDataContext extends QueryPostprocessDataContext implements UpdateableDataContext { @@ -77,11 +75,13 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement public SalesforceDataContext(String endpoint, String username, String password, String securityToken) { try { - ConnectorConfig config = new ConnectorConfig(); + final ConnectorConfig config = new ConnectorConfig(); config.setUsername(username); config.setPassword(securityToken == null ? password : password + securityToken); - config.setAuthEndpoint(endpoint); - config.setServiceEndpoint(endpoint); + if (endpoint != null) { + config.setAuthEndpoint(endpoint); + config.setServiceEndpoint(endpoint); + } _connection = Connector.newConnection(config); } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to log in to Salesforce service"); @@ -90,7 +90,8 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement public SalesforceDataContext(String username, String password, String securityToken) { try { - _connection = Connector.newConnection(username, securityToken == null ? password : password + securityToken); + _connection = + Connector.newConnection(username, securityToken == null ? password : password + securityToken); } catch (ConnectionException e) { throw SalesforceUtils.wrapException(e, "Failed to log in to Salesforce service"); } @@ -105,11 +106,9 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement } /** - * Creates a {@code SalesforceDataContext} instance , configured with given - * salesforce connection. + * Creates a {@code SalesforceDataContext} instance , configured with given salesforce connection. * - * @param connection - * salesforce connection (cannot be {@code null}). + * @param connection salesforce connection (cannot be {@code null}). * */ public SalesforceDataContext(PartnerConnection connection) { @@ -355,7 +354,6 @@ public class SalesforceDataContext extends QueryPostprocessDataContext implement } } - @SuppressWarnings("deprecation") private static void validateSoqlSupportedSelectItem(SelectItem selectItem) throws UnsupportedOperationException { if (selectItem.hasFunction()) { throw new UnsupportedOperationException("Function select items not supported: " + selectItem); http://git-wip-us.apache.org/repos/asf/metamodel/blob/22b9164a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContextFactory.java ---------------------------------------------------------------------- diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContextFactory.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContextFactory.java new file mode 100644 index 0000000..02093e7 --- /dev/null +++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceDataContextFactory.java @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.metamodel.salesforce; + +import org.apache.metamodel.ConnectionException; +import org.apache.metamodel.DataContext; +import org.apache.metamodel.factory.AbstractDataContextFactory; +import org.apache.metamodel.factory.DataContextProperties; +import org.apache.metamodel.factory.ResourceFactoryRegistry; +import org.apache.metamodel.factory.UnsupportedDataContextPropertiesException; + +public class SalesforceDataContextFactory extends AbstractDataContextFactory { + + @Override + protected String getType() { + return "salesforce"; + } + + @Override + public DataContext create(DataContextProperties properties, ResourceFactoryRegistry resourceFactoryRegistry) + throws UnsupportedDataContextPropertiesException, ConnectionException { + + final String endpoint = properties.getUrl(); + final String username = properties.getUsername(); + final String password = properties.getPassword(); + final String securityToken = (String) properties.toMap().get("security-token"); + + return new SalesforceDataContext(endpoint, username, password, securityToken); + } + +} http://git-wip-us.apache.org/repos/asf/metamodel/blob/22b9164a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java ---------------------------------------------------------------------- diff --git a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java index bf9b43b..b745267 100644 --- a/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java +++ b/salesforce/src/main/java/org/apache/metamodel/salesforce/SalesforceUpdateCallback.java @@ -63,8 +63,8 @@ final class SalesforceUpdateCallback extends AbstractUpdateCallback implements C } @Override - public TableCreationBuilder createTable(Schema schema, String name) throws IllegalArgumentException, - IllegalStateException { + public TableCreationBuilder createTable(Schema schema, String name) + throws IllegalArgumentException, IllegalStateException { throw new UnsupportedOperationException("Table creation not supported for Salesforce.com."); } @@ -79,14 +79,14 @@ final class SalesforceUpdateCallback extends AbstractUpdateCallback implements C } @Override - public TableDropBuilder dropTable(Table table) throws IllegalArgumentException, IllegalStateException, - UnsupportedOperationException { + public TableDropBuilder dropTable(Table table) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { throw new UnsupportedOperationException("Table dropping not supported for Salesforce.com."); } @Override - public RowInsertionBuilder insertInto(Table table) throws IllegalArgumentException, IllegalStateException, - UnsupportedOperationException { + public RowInsertionBuilder insertInto(Table table) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { return new SalesforceInsertBuilder(this, table); } @@ -96,8 +96,8 @@ final class SalesforceUpdateCallback extends AbstractUpdateCallback implements C } @Override - public RowDeletionBuilder deleteFrom(Table table) throws IllegalArgumentException, IllegalStateException, - UnsupportedOperationException { + public RowDeletionBuilder deleteFrom(Table table) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { return new SalesforceDeleteBuilder(this, table); } @@ -147,12 +147,12 @@ final class SalesforceUpdateCallback extends AbstractUpdateCallback implements C break; } } - + if (onlyMalformedId) { return; } } - + errors++; for (com.sforce.soap.partner.Error error : errorArray) { @@ -180,8 +180,8 @@ final class SalesforceUpdateCallback extends AbstractUpdateCallback implements C } @Override - public RowUpdationBuilder update(Table table) throws IllegalArgumentException, IllegalStateException, - UnsupportedOperationException { + public RowUpdationBuilder update(Table table) + throws IllegalArgumentException, IllegalStateException, UnsupportedOperationException { return new SalesforceUpdateBuilder(this, table); } @@ -208,14 +208,12 @@ final class SalesforceUpdateCallback extends AbstractUpdateCallback implements C } /** - * Validates and builds a list of ID's referenced in a (potentially - * composite) filter item. This is useful for both UPDATE and DELETE - * operations in Salesforce, which are only supported by-id. + * Validates and builds a list of ID's referenced in a (potentially composite) filter item. This is useful for both + * UPDATE and DELETE operations in Salesforce, which are only supported by-id. * * @param idList * @param whereItem */ - @SuppressWarnings("deprecation") protected void buildIdList(List<String> idList, FilterItem whereItem) { if (whereItem.isCompoundFilter()) { final LogicalOperator logicalOperator = whereItem.getLogicalOperator();