geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nre...@apache.org
Subject [geode] branch feature/GEODE-3781 updated: GEODE-3990: Add gfsh command to alter jdbc region mapping
Date Fri, 08 Dec 2017 22:14:26 GMT
This is an automated email from the ASF dual-hosted git repository.

nreich pushed a commit to branch feature/GEODE-3781
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/feature/GEODE-3781 by this push:
     new c1b041c  GEODE-3990: Add gfsh command to alter jdbc region mapping
c1b041c is described below

commit c1b041c346f7fef12cdc984a2f3f5853b7593749
Author: Nick Reich <nreich@pivotal.io>
AuthorDate: Fri Dec 8 14:13:07 2017 -0800

    GEODE-3990: Add gfsh command to alter jdbc region mapping
---
 .../internal/InternalJdbcConnectorService.java     |   2 +
 .../jdbc/internal/JdbcConnectorService.java        |  13 ++
 .../connectors/jdbc/internal/RegionMapping.java    |  11 +-
 .../jdbc/internal/RegionMappingBuilder.java        |  18 +-
 ...ce.java => RegionMappingNotFoundException.java} |  29 +--
 ...Command.java => AlterRegionMappingCommand.java} |  93 ++++----
 .../internal/cli/AlterRegionMappingFunction.java   |  85 ++++++++
 .../internal/cli/CreateRegionMappingCommand.java   |   3 +-
 .../org.springframework.shell.core.CommandMarker   |   1 +
 .../cli/AlterConnectionCommandDUnitTest.java       |   3 +
 .../cli/AlterConnectionCommandIntegrationTest.java |   7 +-
 .../internal/cli/AlterConnectionFunctionTest.java  |  23 +-
 ...ava => AlterRegionMappingCommandDUnitTest.java} | 103 ++++-----
 ... AlterRegionMappingCommandIntegrationTest.java} |  53 ++---
 .../cli/AlterRegionMappingFunctionTest.java        | 237 +++++++++++++++++++++
 .../jdbc/internal/cli/JdbcCliFunctionTest.java     |   3 +
 .../internal/cli/ListConnectionFunctionTest.java   |   3 +
 .../internal/xml/RegionMappingBuilderTest.java     |   2 +-
 18 files changed, 523 insertions(+), 166 deletions(-)

diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
index a151610..600da00 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
@@ -36,5 +36,7 @@ public interface InternalJdbcConnectorService extends Extension<Cache>, CacheSer
 
   void createRegionMapping(RegionMapping mapping) throws RegionMappingExistsException;
 
+  void replaceRegionMapping(RegionMapping mapping) throws RegionMappingNotFoundException;
+
   RegionMapping getMappingForRegion(String regionName);
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java
index d6f40d1..d3a31a2 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JdbcConnectorService.java
@@ -87,6 +87,19 @@ public class JdbcConnectorService implements InternalJdbcConnectorService {
   }
 
   @Override
+  public void replaceRegionMapping(RegionMapping alteredMapping)
+      throws RegionMappingNotFoundException {
+    registerAsExtension();
+    RegionMapping existingMapping = mappingsByRegion.get(alteredMapping.getRegionName());
+    if (existingMapping == null) {
+      throw new RegionMappingNotFoundException(
+          "RegionMapping for region " + existingMapping.getRegionName() + " was not found");
+    }
+
+    mappingsByRegion.put(existingMapping.getRegionName(), alteredMapping);
+  }
+
+  @Override
   public RegionMapping getMappingForRegion(String regionName) {
     return mappingsByRegion.get(regionName);
   }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMapping.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMapping.java
index 1b5ec79..dcc87a6 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMapping.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMapping.java
@@ -23,18 +23,19 @@ public class RegionMapping implements Serializable {
   private final String pdxClassName;
   private final String tableName;
   private final String connectionConfigName;
-  private final boolean primaryKeyInValue;
+  private final Boolean primaryKeyInValue;
   private final Map<String, String> fieldToColumnMap;
 
   public RegionMapping(String regionName, String pdxClassName, String tableName,
-      String connectionConfigName, boolean primaryKeyInValue,
+      String connectionConfigName, Boolean primaryKeyInValue,
       Map<String, String> fieldToColumnMap) {
     this.regionName = regionName;
     this.pdxClassName = pdxClassName;
     this.tableName = tableName;
     this.connectionConfigName = connectionConfigName;
     this.primaryKeyInValue = primaryKeyInValue;
-    this.fieldToColumnMap = fieldToColumnMap;
+    this.fieldToColumnMap =
+        fieldToColumnMap == null ? null : Collections.unmodifiableMap(fieldToColumnMap);
   }
 
   public String getConnectionConfigName() {
@@ -53,7 +54,7 @@ public class RegionMapping implements Serializable {
     return tableName;
   }
 
-  public boolean isPrimaryKeyInValue() {
+  public Boolean isPrimaryKeyInValue() {
     return primaryKeyInValue;
   }
 
@@ -63,7 +64,7 @@ public class RegionMapping implements Serializable {
   }
 
   public Map<String, String> getFieldToColumnMap() {
-    return Collections.unmodifiableMap(fieldToColumnMap);
+    return fieldToColumnMap;
   }
 
   @Override
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java
index d1759c0..e4d0f76 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingBuilder.java
@@ -24,8 +24,8 @@ public class RegionMappingBuilder {
   private String pdxClassName;
   private String tableName;
   private String connectionConfigName;
-  private boolean primaryKeyInValue;
-  private final Map<String, String> fieldToColumnMap = new HashMap<>();
+  private Boolean primaryKeyInValue;
+  private Map<String, String> fieldToColumnMap = new HashMap<>();
 
   public RegionMappingBuilder withRegionName(String regionName) {
     this.regionName = regionName;
@@ -53,7 +53,7 @@ public class RegionMappingBuilder {
     return this;
   }
 
-  public RegionMappingBuilder withPrimaryKeyInValue(boolean primaryKeyInValue) {
+  public RegionMappingBuilder withPrimaryKeyInValue(Boolean primaryKeyInValue) {
     this.primaryKeyInValue = primaryKeyInValue;
     return this;
   }
@@ -64,10 +64,14 @@ public class RegionMappingBuilder {
   }
 
   public RegionMappingBuilder withFieldToColumnMappings(String[] mappings) {
-    for (String mapping : mappings) {
-      String[] keyValuePair = mapping.split(MAPPINGS_DELIMITER);
-      if (keyValuePair.length == 2) {
-        fieldToColumnMap.put(keyValuePair[0], keyValuePair[1]);
+    if (mappings == null) {
+      fieldToColumnMap = null;
+    } else {
+      for (String mapping : mappings) {
+        String[] keyValuePair = mapping.split(MAPPINGS_DELIMITER);
+        if (keyValuePair.length == 2) {
+          fieldToColumnMap.put(keyValuePair[0], keyValuePair[1]);
+        }
       }
     }
     return this;
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingNotFoundException.java
similarity index 51%
copy from geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
copy to geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingNotFoundException.java
index a151610..002a27a 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/InternalJdbcConnectorService.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/RegionMappingNotFoundException.java
@@ -14,27 +14,18 @@
  */
 package org.apache.geode.connectors.jdbc.internal;
 
-import java.util.Set;
+public class RegionMappingNotFoundException extends Exception {
 
-import org.apache.geode.cache.Cache;
-import org.apache.geode.internal.cache.CacheService;
-import org.apache.geode.internal.cache.extension.Extension;
+  public RegionMappingNotFoundException() {
+    super();
+  }
 
-public interface InternalJdbcConnectorService extends Extension<Cache>, CacheService {
+  public RegionMappingNotFoundException(String message) {
+    super(message);
+  }
 
-  void createConnectionConfig(ConnectionConfiguration config)
-      throws ConnectionConfigExistsException;
+  public RegionMappingNotFoundException(String message, Throwable cause) {
+    super(message, cause);
+  }
 
-  void replaceConnectionConfig(ConnectionConfiguration config)
-      throws ConnectionConfigNotFoundException;
-
-  void destroyConnectionConfig(String connectionName);
-
-  ConnectionConfiguration getConnectionConfig(String connectionName);
-
-  Set<ConnectionConfiguration> getConnectionConfigs();
-
-  void createRegionMapping(RegionMapping mapping) throws RegionMappingExistsException;
-
-  RegionMapping getMappingForRegion(String regionName);
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateRegionMappingCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommand.java
similarity index 64%
copy from geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateRegionMappingCommand.java
copy to geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommand.java
index c1da95c..112e9ca 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateRegionMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommand.java
@@ -35,51 +35,48 @@ import org.apache.geode.management.internal.configuration.domain.XmlEntity;
 import org.apache.geode.management.internal.security.ResourceOperation;
 import org.apache.geode.security.ResourcePermission;
 
-public class CreateRegionMappingCommand implements GfshCommand {
-
-  static final String CREATE_MAPPING = "create jdbc-mapping";
-  static final String CREATE_MAPPING__HELP =
-      "Create a mapping for a region for use with a JDBC database connection.";
-  static final String CREATE_MAPPING__REGION_NAME = "region";
-  static final String CREATE_MAPPING__REGION_NAME__HELP =
-      "Name of the region the mapping is being created for.";
-  static final String CREATE_MAPPING__PDX_CLASS_NAME = "pdx-class-name";
-  static final String CREATE_MAPPING__PDX_CLASS_NAME__HELP =
-      "Name of pdx class for which values with be written to the database.";
-  static final String CREATE_MAPPING__TABLE_NAME = "table";
-  static final String CREATE_MAPPING__TABLE_NAME__HELP =
-      "Name of database table for values to be written to.";
-  static final String CREATE_MAPPING__CONNECTION_NAME = "connection";
-  static final String CREATE_MAPPING__CONNECTION_NAME__HELP =
-      "Password to use when connecting to database.";
-  static final String CREATE_MAPPING__PRIMARY_KEY_IN_VALUE = "primary-key-in-value";
-  static final String CREATE_MAPPING__PRIMARY_KEY_IN_VALUE__HELP =
+public class AlterRegionMappingCommand implements GfshCommand {
+  static final String ALTER_MAPPING = "alter jdbc-mapping";
+  static final String ALTER_MAPPING__HELP = "Alter properties for an existing jdbc mapping.";
+
+  static final String ALTER_MAPPING__REGION_NAME = "region";
+  static final String ALTER_MAPPING__REGION_NAME__HELP =
+      "Name of the region the mapping to be altered.";
+  static final String ALTER_MAPPING__PDX_CLASS_NAME = "pdx-class-name";
+  static final String ALTER_MAPPING__PDX_CLASS_NAME__HELP =
+      "Name of new pdx class for which values with be written to the database.";
+  static final String ALTER_MAPPING__TABLE_NAME = "table";
+  static final String ALTER_MAPPING__TABLE_NAME__HELP =
+      "Name of new database table for values to be written to.";
+  static final String ALTER_MAPPING__CONNECTION_NAME = "connection";
+  static final String ALTER_MAPPING__CONNECTION_NAME__HELP = "Name of new JDBC connection to use.";
+  static final String ALTER_MAPPING__PRIMARY_KEY_IN_VALUE = "primary-key-in-value";
+  static final String ALTER_MAPPING__PRIMARY_KEY_IN_VALUE__HELP =
       "If false, the entry value does not contain the data used for the database table's primary key, instead the entry key will be used for the primary key column value.";
-  static final String CREATE_MAPPING__FIELD_MAPPING = "field-mapping";
-  static final String CREATE_MAPPING__FIELD_MAPPING__HELP =
-      "Key value pairs of entry value fields to database columns.";
+  static final String ALTER_MAPPING__FIELD_MAPPING = "field-mapping";
+  static final String ALTER_MAPPING__FIELD_MAPPING__HELP =
+      "New key value pairs of entry value fields to database columns.";
 
   private static final String ERROR_PREFIX = "ERROR: ";
 
-  @CliCommand(value = CREATE_MAPPING, help = CREATE_MAPPING__HELP)
+  @CliCommand(value = ALTER_MAPPING, help = ALTER_MAPPING__HELP)
   @CliMetaData(relatedTopic = CliStrings.DEFAULT_TOPIC_GEODE)
   @ResourceOperation(resource = ResourcePermission.Resource.CLUSTER,
       operation = ResourcePermission.Operation.MANAGE)
-  public Result createMapping(
-      @CliOption(key = CREATE_MAPPING__REGION_NAME, mandatory = true,
-          help = CREATE_MAPPING__REGION_NAME__HELP) String regionName,
-      @CliOption(key = CREATE_MAPPING__CONNECTION_NAME, mandatory = true,
-          help = CREATE_MAPPING__CONNECTION_NAME__HELP) String connectionName,
-      @CliOption(key = CREATE_MAPPING__TABLE_NAME,
-          help = CREATE_MAPPING__TABLE_NAME__HELP) String table,
-      @CliOption(key = CREATE_MAPPING__PDX_CLASS_NAME,
-          help = CREATE_MAPPING__PDX_CLASS_NAME__HELP) String pdxClassName,
-      @CliOption(key = CREATE_MAPPING__PRIMARY_KEY_IN_VALUE,
-          help = CREATE_MAPPING__PRIMARY_KEY_IN_VALUE__HELP, unspecifiedDefaultValue = "true",
-          specifiedDefaultValue = "true") boolean keyInValue,
-      @CliOption(key = CREATE_MAPPING__FIELD_MAPPING,
-          help = CREATE_MAPPING__FIELD_MAPPING__HELP) String[] fieldMappings) {
-
+  public Result alterMapping(
+      @CliOption(key = ALTER_MAPPING__REGION_NAME, mandatory = true,
+          help = ALTER_MAPPING__REGION_NAME__HELP) String regionName,
+      @CliOption(key = ALTER_MAPPING__CONNECTION_NAME,
+          help = ALTER_MAPPING__CONNECTION_NAME__HELP) String connectionName,
+      @CliOption(key = ALTER_MAPPING__TABLE_NAME, help = ALTER_MAPPING__TABLE_NAME__HELP,
+          specifiedDefaultValue = "") String table,
+      @CliOption(key = ALTER_MAPPING__PDX_CLASS_NAME, help = ALTER_MAPPING__PDX_CLASS_NAME__HELP,
+          specifiedDefaultValue = "") String pdxClassName,
+      @CliOption(key = ALTER_MAPPING__PRIMARY_KEY_IN_VALUE,
+          help = ALTER_MAPPING__PRIMARY_KEY_IN_VALUE__HELP,
+          specifiedDefaultValue = "true") Boolean keyInValue,
+      @CliOption(key = ALTER_MAPPING__FIELD_MAPPING, help = ALTER_MAPPING__FIELD_MAPPING__HELP,
+          specifiedDefaultValue = "") String[] fieldMappings) {
     // input
     Set<DistributedMember> targetMembers = getMembers(null, null);
     RegionMapping mapping =
@@ -87,7 +84,7 @@ public class CreateRegionMappingCommand implements GfshCommand {
 
     // action
     ResultCollector<CliFunctionResult, List<CliFunctionResult>> resultCollector =
-        execute(new CreateRegionMappingFunction(), mapping, targetMembers);
+        execute(new AlterRegionMappingFunction(), mapping, targetMembers);
 
     // output
     TabularResultData tabularResultData = ResultBuilder.createTabularResultData();
@@ -97,8 +94,15 @@ public class CreateRegionMappingCommand implements GfshCommand {
     return result;
   }
 
-  RegionMapping getArguments(String regionName, String connectionName, String table,
-      String pdxClassName, boolean keyInValue, String[] fieldMappings) {
+  ResultCollector<CliFunctionResult, List<CliFunctionResult>> execute(
+      AlterRegionMappingFunction function, RegionMapping mapping,
+      Set<DistributedMember> targetMembers) {
+    return (ResultCollector<CliFunctionResult, List<CliFunctionResult>>) executeFunction(function,
+        mapping, targetMembers);
+  }
+
+  private RegionMapping getArguments(String regionName, String connectionName, String table,
+      String pdxClassName, Boolean keyInValue, String[] fieldMappings) {
     RegionMappingBuilder builder = new RegionMappingBuilder().withRegionName(regionName)
         .withConnectionConfigName(connectionName).withTableName(table)
         .withPdxClassName(pdxClassName).withPrimaryKeyInValue(keyInValue)
@@ -106,13 +110,6 @@ public class CreateRegionMappingCommand implements GfshCommand {
     return builder.build();
   }
 
-  ResultCollector<CliFunctionResult, List<CliFunctionResult>> execute(
-      CreateRegionMappingFunction function, RegionMapping regionMapping,
-      Set<DistributedMember> targetMembers) {
-    return (ResultCollector<CliFunctionResult, List<CliFunctionResult>>) executeFunction(function,
-        regionMapping, targetMembers);
-  }
-
   private XmlEntity fillTabularResultData(
       ResultCollector<CliFunctionResult, List<CliFunctionResult>> resultCollector,
       TabularResultData tabularResultData) {
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingFunction.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingFunction.java
new file mode 100644
index 0000000..773b5b8
--- /dev/null
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingFunction.java
@@ -0,0 +1,85 @@
+/*
+ * 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.geode.connectors.jdbc.internal.cli;
+
+import java.util.Map;
+
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMapping;
+import org.apache.geode.connectors.jdbc.internal.RegionMappingNotFoundException;
+import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
+import org.apache.geode.management.internal.configuration.domain.XmlEntity;
+
+public class AlterRegionMappingFunction extends JdbcCliFunction<RegionMapping, CliFunctionResult> {
+
+  AlterRegionMappingFunction() {
+    super(new FunctionContextArgumentProvider(), new ExceptionHandler());
+  }
+
+  @Override
+  CliFunctionResult getFunctionResult(InternalJdbcConnectorService service,
+      FunctionContext<RegionMapping> context) throws Exception {
+    RegionMapping mapping = context.getArguments();
+    RegionMapping existingMapping = service.getMappingForRegion(mapping.getRegionName());
+    if (existingMapping == null) {
+      throw new RegionMappingNotFoundException(
+          "RegionMapping for region " + mapping.getRegionName() + " was not found");
+    }
+
+    // action
+    RegionMapping alteredMapping = alterRegionMapping(mapping, existingMapping);
+    service.replaceRegionMapping(alteredMapping);
+
+    // output
+    String member = getMember(context);
+    XmlEntity xmlEntity = createXmlEntity(context);
+    CliFunctionResult result = createSuccessResult(mapping.getRegionName(), member, xmlEntity);
+    return result;
+  }
+
+  RegionMapping alterRegionMapping(RegionMapping regionMapping, RegionMapping existingMapping) {
+    String connectionName = regionMapping.getConnectionConfigName() == null
+        ? existingMapping.getConnectionConfigName() : regionMapping.getConnectionConfigName();
+    String table = getValue(regionMapping.getTableName(), existingMapping.getTableName());
+    String pdxClassName =
+        getValue(regionMapping.getPdxClassName(), existingMapping.getPdxClassName());
+    Boolean keyInValue = regionMapping.isPrimaryKeyInValue() == null
+        ? existingMapping.isPrimaryKeyInValue() : regionMapping.isPrimaryKeyInValue();
+
+    Map<String, String> fieldMappings = regionMapping.getFieldToColumnMap();
+    if (fieldMappings == null) {
+      fieldMappings = existingMapping.getFieldToColumnMap();
+    }
+    RegionMapping alteredMapping = new RegionMapping(existingMapping.getRegionName(), pdxClassName,
+        table, connectionName, keyInValue, fieldMappings);
+    return alteredMapping;
+  }
+
+  private String getValue(String newValue, String existingValue) {
+    // if newValue is null use the value already in the config
+    // if newValue is the empty string, then "unset" it by returning null
+    if (newValue == null) {
+      return existingValue;
+    }
+    return newValue.isEmpty() ? null : newValue;
+  }
+
+  private CliFunctionResult createSuccessResult(String connectionName, String member,
+      XmlEntity xmlEntity) {
+    String message = "Altered JDBC connection " + connectionName + " on " + member;
+    return new CliFunctionResult(member, xmlEntity, message);
+  }
+}
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateRegionMappingCommand.java b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateRegionMappingCommand.java
index c1da95c..cea4109 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateRegionMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateRegionMappingCommand.java
@@ -50,8 +50,7 @@ public class CreateRegionMappingCommand implements GfshCommand {
   static final String CREATE_MAPPING__TABLE_NAME__HELP =
       "Name of database table for values to be written to.";
   static final String CREATE_MAPPING__CONNECTION_NAME = "connection";
-  static final String CREATE_MAPPING__CONNECTION_NAME__HELP =
-      "Password to use when connecting to database.";
+  static final String CREATE_MAPPING__CONNECTION_NAME__HELP = "Name of JDBC connection to use.";
   static final String CREATE_MAPPING__PRIMARY_KEY_IN_VALUE = "primary-key-in-value";
   static final String CREATE_MAPPING__PRIMARY_KEY_IN_VALUE__HELP =
       "If false, the entry value does not contain the data used for the database table's primary key, instead the entry key will be used for the primary key column value.";
diff --git a/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker b/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker
index 121ef75..ad85e00 100644
--- a/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker
+++ b/geode-connectors/src/main/resources/META-INF/services/org.springframework.shell.core.CommandMarker
@@ -21,3 +21,4 @@ org.apache.geode.connectors.jdbc.internal.cli.ListConnectionCommand
 org.apache.geode.connectors.jdbc.internal.cli.DescribeConnectionCommand
 org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand
 org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand
+org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandDUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandDUnitTest.java
index 836029c..cb57edf 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandDUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandDUnitTest.java
@@ -31,6 +31,7 @@ import static org.assertj.core.api.Assertions.assertThat;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 import org.apache.geode.connectors.jdbc.internal.ConnectionConfiguration;
 import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
@@ -39,9 +40,11 @@ import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.rules.GfshCommandRule;
 import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
 
+@Category(DistributedTest.class)
 public class AlterConnectionCommandDUnitTest {
 
   @Rule
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandIntegrationTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandIntegrationTest.java
index def0cfd..229dcb9 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandIntegrationTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandIntegrationTest.java
@@ -20,13 +20,16 @@ import static org.assertj.core.api.Assertions.assertThat;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.CacheFactory;
 import org.apache.geode.connectors.jdbc.internal.ConnectionConfiguration;
 import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.cli.Result;
+import org.apache.geode.test.junit.categories.IntegrationTest;
 
+@Category(IntegrationTest.class)
 public class AlterConnectionCommandIntegrationTest {
 
   private InternalCache cache;
@@ -35,7 +38,7 @@ public class AlterConnectionCommandIntegrationTest {
   private String name;
 
   @Before
-  public void setup() throws Exception {
+  public void setup() {
     name = "name";
     String url = "url";
     String user = "user";
@@ -54,7 +57,7 @@ public class AlterConnectionCommandIntegrationTest {
   }
 
   @Test
-  public void altersConnectionConfigurationInService() throws Exception {
+  public void altersConnectionConfigurationInService() {
     String[] newParams = new String[] {"key1:value1", "key2:value2"};
     Result result =
         alterConnectionCommand.alterConnection(name, "newUrl", "newUser", "newPassword", newParams);
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionFunctionTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionFunctionTest.java
index 7ed497b..bb17cc4 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionFunctionTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionFunctionTest.java
@@ -32,6 +32,7 @@ import java.util.Map;
 import org.apache.commons.lang.SerializationUtils;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 import org.mockito.ArgumentCaptor;
 
 import org.apache.geode.cache.execute.FunctionContext;
@@ -44,7 +45,9 @@ import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
+import org.apache.geode.test.junit.categories.UnitTest;
 
+@Category(UnitTest.class)
 public class AlterConnectionFunctionTest {
 
   private static final String CONNECTION_NAME = "theConnection";
@@ -59,7 +62,7 @@ public class AlterConnectionFunctionTest {
   private AlterConnectionFunction function;
 
   @Before
-  public void setUp() throws Exception {
+  public void setUp() {
     context = mock(FunctionContext.class);
     resultSender = mock(ResultSender.class);
     InternalCache cache = mock(InternalCache.class);
@@ -86,17 +89,17 @@ public class AlterConnectionFunctionTest {
   }
 
   @Test
-  public void isHAReturnsFalse() throws Exception {
+  public void isHAReturnsFalse() {
     assertThat(function.isHA()).isFalse();
   }
 
   @Test
-  public void getIdReturnsNameOfClass() throws Exception {
+  public void getIdReturnsNameOfClass() {
     assertThat(function.getId()).isEqualTo(function.getClass().getName());
   }
 
   @Test
-  public void serializes() throws Exception {
+  public void serializes() {
     Serializable original = function;
 
     Object copy = SerializationUtils.clone(original);
@@ -105,7 +108,7 @@ public class AlterConnectionFunctionTest {
   }
 
   @Test
-  public void alterConnectionConfigThrowsConnectionNotFound() throws Exception {
+  public void alterConnectionConfigThrowsConnectionNotFound() {
     AlterConnectionFunction alterFunction = mock(AlterConnectionFunction.class);
     doThrow(ConnectionConfigNotFoundException.class).when(alterFunction)
         .alterConnectionConfig(any(), any());
@@ -135,7 +138,7 @@ public class AlterConnectionFunctionTest {
   }
 
   @Test
-  public void alterConnectionConfigUrl() throws Exception {
+  public void alterConnectionConfigUrl() {
     ConnectionConfiguration newConfigValues =
         new ConnectionConfiguration(CONNECTION_NAME, "newUrl", null, null, null);
 
@@ -151,7 +154,7 @@ public class AlterConnectionFunctionTest {
   }
 
   @Test
-  public void alterConnectionConfigUser() throws Exception {
+  public void alterConnectionConfigUser() {
     ConnectionConfiguration newConfigValues =
         new ConnectionConfiguration(CONNECTION_NAME, null, "newUser", null, null);
 
@@ -167,7 +170,7 @@ public class AlterConnectionFunctionTest {
   }
 
   @Test
-  public void alterConnectionConfigPassword() throws Exception {
+  public void alterConnectionConfigPassword() {
     ConnectionConfiguration newConfigValues =
         new ConnectionConfiguration(CONNECTION_NAME, null, null, "newPassword", null);
 
@@ -183,7 +186,7 @@ public class AlterConnectionFunctionTest {
   }
 
   @Test
-  public void alterConnectionConfigParameters() throws Exception {
+  public void alterConnectionConfigParameters() {
     Map<String, String> newParameters = new HashMap<>();
     newParameters.put("key1", "anotherValue1");
     newParameters.put("key8", "value8");
@@ -202,7 +205,7 @@ public class AlterConnectionFunctionTest {
   }
 
   @Test
-  public void alterConnectionConfigWithNothingToAlter() throws Exception {
+  public void alterConnectionConfigWithNothingToAlter() {
     ConnectionConfiguration newConfigValues =
         new ConnectionConfiguration(CONNECTION_NAME, null, null, null, null);
 
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandDUnitTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommandDUnitTest.java
similarity index 53%
copy from geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandDUnitTest.java
copy to geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommandDUnitTest.java
index 836029c..150993b 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandDUnitTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommandDUnitTest.java
@@ -14,35 +14,41 @@
  */
 package org.apache.geode.connectors.jdbc.internal.cli;
 
-import static org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand.ALTER_CONNECTION__NAME;
-import static org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand.ALTER_CONNECTION__PARAMS;
-import static org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand.ALTER_CONNECTION__PASSWORD;
-import static org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand.ALTER_CONNECTION__URL;
-import static org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand.ALTER_CONNECTION__USER;
-import static org.apache.geode.connectors.jdbc.internal.cli.AlterConnectionCommand.ALTER_JDBC_CONNECTION;
-import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION;
-import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION__NAME;
-import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION__PARAMS;
-import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION__PASSWORD;
-import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION__URL;
-import static org.apache.geode.connectors.jdbc.internal.cli.CreateConnectionCommand.CREATE_CONNECTION__USER;
+import static org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand.ALTER_MAPPING;
+import static org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand.ALTER_MAPPING__CONNECTION_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand.ALTER_MAPPING__FIELD_MAPPING;
+import static org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand.ALTER_MAPPING__PDX_CLASS_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand.ALTER_MAPPING__PRIMARY_KEY_IN_VALUE;
+import static org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand.ALTER_MAPPING__REGION_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.AlterRegionMappingCommand.ALTER_MAPPING__TABLE_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand.CREATE_MAPPING;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand.CREATE_MAPPING__CONNECTION_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand.CREATE_MAPPING__FIELD_MAPPING;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand.CREATE_MAPPING__PDX_CLASS_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand.CREATE_MAPPING__PRIMARY_KEY_IN_VALUE;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand.CREATE_MAPPING__REGION_NAME;
+import static org.apache.geode.connectors.jdbc.internal.cli.CreateRegionMappingCommand.CREATE_MAPPING__TABLE_NAME;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.entry;
 
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
-import org.apache.geode.connectors.jdbc.internal.ConnectionConfiguration;
 import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMapping;
 import org.apache.geode.distributed.internal.InternalLocator;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.util.CommandStringBuilder;
 import org.apache.geode.test.dunit.rules.LocatorServerStartupRule;
 import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.DistributedTest;
 import org.apache.geode.test.junit.rules.GfshCommandRule;
 import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
 
-public class AlterConnectionCommandDUnitTest {
+@Category(DistributedTest.class)
+public class AlterRegionMappingCommandDUnitTest {
 
   @Rule
   public transient GfshCommandRule gfsh = new GfshCommandRule();
@@ -62,25 +68,26 @@ public class AlterConnectionCommandDUnitTest {
     server = startupRule.startServerVM(1, locator.getPort());
 
     gfsh.connectAndVerify(locator);
-
-    CommandStringBuilder csb = new CommandStringBuilder(CREATE_CONNECTION);
-    csb.addOption(CREATE_CONNECTION__NAME, "name");
-    csb.addOption(CREATE_CONNECTION__URL, "url");
-    csb.addOption(CREATE_CONNECTION__USER, "username");
-    csb.addOption(CREATE_CONNECTION__PASSWORD, "secret");
-    csb.addOption(CREATE_CONNECTION__PARAMS, "param1:value1,param2:value2");
+    CommandStringBuilder csb = new CommandStringBuilder(CREATE_MAPPING);
+    csb.addOption(CREATE_MAPPING__REGION_NAME, "testRegion");
+    csb.addOption(CREATE_MAPPING__CONNECTION_NAME, "connection");
+    csb.addOption(CREATE_MAPPING__TABLE_NAME, "myTable");
+    csb.addOption(CREATE_MAPPING__PDX_CLASS_NAME, "myPdxClass");
+    csb.addOption(CREATE_MAPPING__PRIMARY_KEY_IN_VALUE, "true");
+    csb.addOption(CREATE_MAPPING__FIELD_MAPPING, "field1:column1,field2:column2");
 
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
   }
 
   @Test
-  public void altersConnectionWithNewValues() throws Exception {
-    CommandStringBuilder csb = new CommandStringBuilder(ALTER_JDBC_CONNECTION);
-    csb.addOption(ALTER_CONNECTION__NAME, "name");
-    csb.addOption(ALTER_CONNECTION__URL, "newUrl");
-    csb.addOption(ALTER_CONNECTION__USER, "newUsername");
-    csb.addOption(ALTER_CONNECTION__PASSWORD, "newPassword");
-    csb.addOption(ALTER_CONNECTION__PARAMS, "Key1:Value1,Key22:Value22");
+  public void altersMappingWithNewValues() throws Exception {
+    CommandStringBuilder csb = new CommandStringBuilder(ALTER_MAPPING);
+    csb.addOption(ALTER_MAPPING__REGION_NAME, "testRegion");
+    csb.addOption(ALTER_MAPPING__CONNECTION_NAME, "newConnection");
+    csb.addOption(ALTER_MAPPING__TABLE_NAME, "newTable");
+    csb.addOption(ALTER_MAPPING__PDX_CLASS_NAME, "newPdxClass");
+    csb.addOption(ALTER_MAPPING__PRIMARY_KEY_IN_VALUE, "false");
+    csb.addOption(ALTER_MAPPING__FIELD_MAPPING, "field3:column3,field4:column4");
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
 
 
@@ -92,24 +99,24 @@ public class AlterConnectionCommandDUnitTest {
 
     server.invoke(() -> {
       InternalCache cache = LocatorServerStartupRule.getCache();
-      ConnectionConfiguration config =
-          cache.getService(InternalJdbcConnectorService.class).getConnectionConfig("name");
-      assertThat(config.getUrl()).isEqualTo("newUrl");
-      assertThat(config.getUser()).isEqualTo("newUsername");
-      assertThat(config.getPassword()).isEqualTo("newPassword");
-      assertThat(config.getConnectionProperties()).containsEntry("Key1", "Value1")
-          .containsEntry("Key22", "Value22");
+      RegionMapping mapping =
+          cache.getService(InternalJdbcConnectorService.class).getMappingForRegion("testRegion");
+      assertThat(mapping.getConnectionConfigName()).isEqualTo("newConnection");
+      assertThat(mapping.getTableName()).isEqualTo("newTable");
+      assertThat(mapping.getPdxClassName()).isEqualTo("newPdxClass");
+      assertThat(mapping.isPrimaryKeyInValue()).isEqualTo(false);
+      assertThat(mapping.getFieldToColumnMap()).containsExactly(entry("field3", "column3"),
+          entry("field4", "column4"));
     });
   }
 
   @Test
-  public void altersConnectionByRemovingValues() {
-    CommandStringBuilder csb = new CommandStringBuilder(ALTER_JDBC_CONNECTION);
-    csb.addOption(ALTER_CONNECTION__NAME, "name");
-    csb.addOption(ALTER_CONNECTION__URL, "");
-    csb.addOption(ALTER_CONNECTION__USER, "");
-    csb.addOption(ALTER_CONNECTION__PASSWORD, "");
-    csb.addOption(ALTER_CONNECTION__PARAMS, "");
+  public void altersMappingByRemovingValues() {
+    CommandStringBuilder csb = new CommandStringBuilder(ALTER_MAPPING);
+    csb.addOption(ALTER_MAPPING__REGION_NAME, "testRegion");
+    csb.addOption(ALTER_MAPPING__TABLE_NAME, "");
+    csb.addOption(ALTER_MAPPING__PDX_CLASS_NAME, "");
+    csb.addOption(ALTER_MAPPING__FIELD_MAPPING, "");
 
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
 
@@ -121,12 +128,12 @@ public class AlterConnectionCommandDUnitTest {
 
     server.invoke(() -> {
       InternalCache cache = LocatorServerStartupRule.getCache();
-      ConnectionConfiguration config =
-          cache.getService(InternalJdbcConnectorService.class).getConnectionConfig("name");
-      assertThat(config.getUrl()).isNull();
-      assertThat(config.getUser()).isNull();
-      assertThat(config.getPassword()).isNull();
-      assertThat(config.getConnectionProperties()).hasSize(0);
+      RegionMapping mapping =
+          cache.getService(InternalJdbcConnectorService.class).getMappingForRegion("testRegion");
+      assertThat(mapping.getConnectionConfigName()).isEqualTo("connection");
+      assertThat(mapping.getTableName()).isNull();
+      assertThat(mapping.getPdxClassName()).isNull();
+      assertThat(mapping.getFieldToColumnMap()).isEmpty();
     });
   }
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandIntegrationTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommandIntegrationTest.java
similarity index 50%
copy from geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandIntegrationTest.java
copy to geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommandIntegrationTest.java
index def0cfd..3e47c8b 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterConnectionCommandIntegrationTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingCommandIntegrationTest.java
@@ -20,32 +20,37 @@ import static org.assertj.core.api.Assertions.assertThat;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.CacheFactory;
-import org.apache.geode.connectors.jdbc.internal.ConnectionConfiguration;
 import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMapping;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.cli.Result;
+import org.apache.geode.test.junit.categories.IntegrationTest;
 
-public class AlterConnectionCommandIntegrationTest {
+@Category(IntegrationTest.class)
+public class AlterRegionMappingCommandIntegrationTest {
 
   private InternalCache cache;
-  private AlterConnectionCommand alterConnectionCommand;
+  private AlterRegionMappingCommand alterRegionMappingCommand;
 
-  private String name;
+  private String regionName;
 
   @Before
-  public void setup() throws Exception {
-    name = "name";
-    String url = "url";
-    String user = "user";
-    String password = "password";
-    String[] params = new String[] {"param1:value1", "param2:value2"};
+  public void setup() {
+    regionName = "regionName";
+    String connectionName = "connection";
+    String tableName = "testTable";
+    String pdxClass = "myPdxClass";
+    Boolean keyInValue = true;
+    String[] fieldMappings = new String[] {"field1:column1", "field2:column2"};
 
     cache = (InternalCache) new CacheFactory().set(ENABLE_CLUSTER_CONFIGURATION, "true").create();
-    (new CreateConnectionCommand()).createConnection(name, url, user, password, params);
+    new CreateRegionMappingCommand().createMapping(regionName, connectionName, tableName, pdxClass,
+        keyInValue, fieldMappings);
 
-    alterConnectionCommand = new AlterConnectionCommand();
+    alterRegionMappingCommand = new AlterRegionMappingCommand();
   }
 
   @After
@@ -54,23 +59,23 @@ public class AlterConnectionCommandIntegrationTest {
   }
 
   @Test
-  public void altersConnectionConfigurationInService() throws Exception {
-    String[] newParams = new String[] {"key1:value1", "key2:value2"};
-    Result result =
-        alterConnectionCommand.alterConnection(name, "newUrl", "newUser", "newPassword", newParams);
+  public void altersRegionMappingInService() {
+    String[] newMappings = new String[] {"field3:column3", "field4:column4"};
+    Result result = alterRegionMappingCommand.alterMapping(regionName, "newConnection", "newTable",
+        "newPdxClass", false, newMappings);
 
     assertThat(result.getStatus()).isSameAs(Result.Status.OK);
 
     InternalJdbcConnectorService service = cache.getService(InternalJdbcConnectorService.class);
-    ConnectionConfiguration connectionConfig = service.getConnectionConfig(name);
+    RegionMapping regionMapping = service.getMappingForRegion(regionName);
 
-    assertThat(connectionConfig).isNotNull();
-    assertThat(connectionConfig.getName()).isEqualTo(name);
-    assertThat(connectionConfig.getUrl()).isEqualTo("newUrl");
-    assertThat(connectionConfig.getUser()).isEqualTo("newUser");
-    assertThat(connectionConfig.getPassword()).isEqualTo("newPassword");
-    assertThat(connectionConfig.getConnectionProperties()).containsEntry("key1", "value1")
-        .containsEntry("key2", "value2");
+    assertThat(regionMapping).isNotNull();
+    assertThat(regionMapping.getConnectionConfigName()).isEqualTo("newConnection");
+    assertThat(regionMapping.getTableName()).isEqualTo("newTable");
+    assertThat(regionMapping.getPdxClassName()).isEqualTo("newPdxClass");
+    assertThat(regionMapping.isPrimaryKeyInValue()).isFalse();
+    assertThat(regionMapping.getFieldToColumnMap()).containsEntry("field3", "column3")
+        .containsEntry("field4", "column4");
   }
 
 }
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingFunctionTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingFunctionTest.java
new file mode 100644
index 0000000..e6a0d0d
--- /dev/null
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/AlterRegionMappingFunctionTest.java
@@ -0,0 +1,237 @@
+/*
+ * 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.geode.connectors.jdbc.internal.cli;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.assertj.core.api.Assertions.entry;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.commons.lang.SerializationUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.mockito.ArgumentCaptor;
+
+import org.apache.geode.cache.execute.FunctionContext;
+import org.apache.geode.cache.execute.ResultSender;
+import org.apache.geode.connectors.jdbc.internal.ConnectionConfigNotFoundException;
+import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.connectors.jdbc.internal.RegionMapping;
+import org.apache.geode.connectors.jdbc.internal.RegionMappingBuilder;
+import org.apache.geode.connectors.jdbc.internal.RegionMappingNotFoundException;
+import org.apache.geode.distributed.DistributedMember;
+import org.apache.geode.distributed.DistributedSystem;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class AlterRegionMappingFunctionTest {
+
+  private static final String REGION_NAME = "testRegion";
+
+  private RegionMapping regionMapping;
+  private RegionMapping existingMappping;
+  private RegionMapping mappingToAlter;
+  private FunctionContext<RegionMapping> context;
+  private ResultSender<Object> resultSender;
+  private InternalJdbcConnectorService service;
+
+  private AlterRegionMappingFunction function;
+
+  @Before
+  public void setUp() {
+    context = mock(FunctionContext.class);
+    resultSender = mock(ResultSender.class);
+    InternalCache cache = mock(InternalCache.class);
+    DistributedSystem system = mock(DistributedSystem.class);
+    DistributedMember distributedMember = mock(DistributedMember.class);
+    service = mock(InternalJdbcConnectorService.class);
+
+    regionMapping = new RegionMappingBuilder().withRegionName(REGION_NAME).build();
+    existingMappping = new RegionMappingBuilder().withRegionName(REGION_NAME).build();
+    Map<String, String> mappings = new HashMap<>();
+    mappings.put("field1", "column1");
+    mappings.put("field2", "column2");
+    mappingToAlter =
+        new RegionMapping(REGION_NAME, "pdxClass", "myTable", "connection", true, mappings);
+
+    when(context.getResultSender()).thenReturn(resultSender);
+    when(context.getCache()).thenReturn(cache);
+    when(cache.getDistributedSystem()).thenReturn(system);
+    when(system.getDistributedMember()).thenReturn(distributedMember);
+    when(context.getArguments()).thenReturn(regionMapping);
+    when(cache.getService(eq(InternalJdbcConnectorService.class))).thenReturn(service);
+
+    function = new AlterRegionMappingFunction();
+  }
+
+  @Test
+  public void isHAReturnsFalse() {
+    assertThat(function.isHA()).isFalse();
+  }
+
+  @Test
+  public void getIdReturnsNameOfClass() {
+    assertThat(function.getId()).isEqualTo(function.getClass().getName());
+  }
+
+  @Test
+  public void serializes() {
+    Serializable original = function;
+
+    Object copy = SerializationUtils.clone(original);
+
+    assertThat(copy).isNotSameAs(original).isInstanceOf(AlterRegionMappingFunction.class);
+  }
+
+  @Test
+  public void alterMissingRegionMappingThrowsRegionMappingNotFound() {
+    AlterRegionMappingFunction alterFunction = mock(AlterRegionMappingFunction.class);
+    doThrow(RegionMappingNotFoundException.class).when(alterFunction).alterRegionMapping(any(),
+        any());
+
+    assertThatThrownBy(() -> alterFunction.alterRegionMapping(regionMapping, existingMappping))
+        .isInstanceOf(RegionMappingNotFoundException.class);
+  }
+
+  @Test
+  public void executeInvokesReplaceOnService() throws Exception {
+    when(service.getMappingForRegion(REGION_NAME)).thenReturn(existingMappping);
+    function.execute(context);
+
+    verify(service, times(1)).replaceRegionMapping(any());
+  }
+
+  @Test
+  public void executeReportsErrorIfRegionMappingNotFound() throws Exception {
+    doThrow(ConnectionConfigNotFoundException.class).when(service)
+        .replaceRegionMapping(eq(regionMapping));
+
+    function.execute(context);
+
+    ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class);
+    verify(resultSender, times(1)).lastResult(argument.capture());
+    assertThat(argument.getValue().getErrorMessage()).contains(REGION_NAME);
+  }
+
+  @Test
+  public void alterMappingPdxClassName() {
+    RegionMapping newConfigValues =
+        new RegionMapping(REGION_NAME, "newClassName", null, null, null, null);
+
+    RegionMapping alteredConfig = function.alterRegionMapping(newConfigValues, mappingToAlter);
+
+    assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME);
+    assertThat(alteredConfig.getPdxClassName()).isEqualTo("newClassName");
+    assertThat(alteredConfig.getTableName()).isEqualTo("myTable");
+    assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection");
+    assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue();
+    Map<String, String> fieldMappings = alteredConfig.getFieldToColumnMap();
+    assertThat(fieldMappings).containsOnly(entry("field1", "column1"), entry("field2", "column2"));
+  }
+
+  @Test
+  public void alterRegionMappingTable() {
+    RegionMapping newConfigValues =
+        new RegionMapping(REGION_NAME, null, "newTable", null, null, null);
+
+    RegionMapping alteredConfig = function.alterRegionMapping(newConfigValues, mappingToAlter);
+
+    assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME);
+    assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass");
+    assertThat(alteredConfig.getTableName()).isEqualTo("newTable");
+    assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection");
+    assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue();
+    Map<String, String> fieldMappings = alteredConfig.getFieldToColumnMap();
+    assertThat(fieldMappings).containsOnly(entry("field1", "column1"), entry("field2", "column2"));
+  }
+
+  @Test
+  public void alterRegionMappingPrimaryKeyInValue() {
+    RegionMapping newConfigValues = new RegionMapping(REGION_NAME, null, null, null, false, null);
+
+    RegionMapping alteredConfig = function.alterRegionMapping(newConfigValues, mappingToAlter);
+
+    assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME);
+    assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass");
+    assertThat(alteredConfig.getTableName()).isEqualTo("myTable");
+    assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection");
+    assertThat(alteredConfig.isPrimaryKeyInValue()).isFalse();
+    Map<String, String> fieldMappings = alteredConfig.getFieldToColumnMap();
+    assertThat(fieldMappings).containsOnly(entry("field1", "column1"), entry("field2", "column2"));
+  }
+
+  @Test
+  public void alterRegionMappingConnectionName() {
+    RegionMapping newConfigValues =
+        new RegionMapping(REGION_NAME, null, null, "newConnection", null, null);
+
+    RegionMapping alteredConfig = function.alterRegionMapping(newConfigValues, mappingToAlter);
+
+    assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME);
+    assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass");
+    assertThat(alteredConfig.getTableName()).isEqualTo("myTable");
+    assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("newConnection");
+    assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue();
+    Map<String, String> fieldMappings = alteredConfig.getFieldToColumnMap();
+    assertThat(fieldMappings).containsOnly(entry("field1", "column1"), entry("field2", "column2"));
+  }
+
+  @Test
+  public void alterRegionMappingFieldMappings() {
+    Map<String, String> newMappings = new HashMap<>();
+    newMappings.put("field5", "column5");
+    newMappings.put("field6", "column6");
+    RegionMapping newConfigValues =
+        new RegionMapping(REGION_NAME, null, null, null, null, newMappings);
+
+    RegionMapping alteredConfig = function.alterRegionMapping(newConfigValues, mappingToAlter);
+
+    assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME);
+    assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass");
+    assertThat(alteredConfig.getTableName()).isEqualTo("myTable");
+    assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection");
+    assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue();
+    Map<String, String> fieldMappings = alteredConfig.getFieldToColumnMap();
+    assertThat(fieldMappings).containsOnly(entry("field5", "column5"), entry("field6", "column6"));
+  }
+
+  @Test
+  public void alterRegionMappingWithNothingToAlter() {
+    RegionMapping newConfigValues = new RegionMapping(REGION_NAME, null, null, null, null, null);
+
+    RegionMapping alteredConfig = function.alterRegionMapping(newConfigValues, mappingToAlter);
+
+    assertThat(alteredConfig.getRegionName()).isEqualTo(REGION_NAME);
+    assertThat(alteredConfig.getPdxClassName()).isEqualTo("pdxClass");
+    assertThat(alteredConfig.getTableName()).isEqualTo("myTable");
+    assertThat(alteredConfig.getConnectionConfigName()).isEqualTo("connection");
+    assertThat(alteredConfig.isPrimaryKeyInValue()).isTrue();
+    Map<String, String> fieldMappings = alteredConfig.getFieldToColumnMap();
+    assertThat(fieldMappings).containsOnly(entry("field1", "column1"), entry("field2", "column2"));
+  }
+}
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/JdbcCliFunctionTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/JdbcCliFunctionTest.java
index 9ceb58f..b966ced 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/JdbcCliFunctionTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/JdbcCliFunctionTest.java
@@ -19,10 +19,13 @@ import static org.mockito.Mockito.mock;
 
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 
 import org.apache.geode.cache.execute.FunctionContext;
 import org.apache.geode.connectors.jdbc.internal.InternalJdbcConnectorService;
+import org.apache.geode.test.junit.categories.UnitTest;
 
+@Category(UnitTest.class)
 public class JdbcCliFunctionTest {
 
   private JdbcCliFunction<Void, Void> function;
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionFunctionTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionFunctionTest.java
index 0ea9547..5976094 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionFunctionTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/cli/ListConnectionFunctionTest.java
@@ -28,6 +28,7 @@ import java.util.Set;
 import org.apache.commons.lang.SerializationUtils;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.experimental.categories.Category;
 import org.mockito.ArgumentCaptor;
 
 import org.apache.geode.cache.execute.FunctionContext;
@@ -38,7 +39,9 @@ import org.apache.geode.distributed.DistributedMember;
 import org.apache.geode.distributed.DistributedSystem;
 import org.apache.geode.internal.cache.InternalCache;
 import org.apache.geode.management.internal.cli.functions.CliFunctionResult;
+import org.apache.geode.test.junit.categories.UnitTest;
 
+@Category(UnitTest.class)
 public class ListConnectionFunctionTest {
 
   private FunctionContext<Void> context;
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
index 9099f82..695556d 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingBuilderTest.java
@@ -34,7 +34,7 @@ public class RegionMappingBuilderTest {
     assertThat(regionMapping.getTableName()).isNull();
     assertThat(regionMapping.getPdxClassName()).isNull();
     assertThat(regionMapping.getConnectionConfigName()).isNull();
-    assertThat(regionMapping.isPrimaryKeyInValue()).isFalse();
+    assertThat(regionMapping.isPrimaryKeyInValue()).isNull();
   }
 
   @Test

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <commits@geode.apache.org>'].

Mime
View raw message