geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dschnei...@apache.org
Subject [geode] 01/01: pdx-name is now required on jdbc-mapping
Date Wed, 07 Nov 2018 01:15:56 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit a51582abfbb2d575a23f854ef73d9d1560c6cc10
Author: Darrel Schneider <dschneider@pivotal.io>
AuthorDate: Tue Nov 6 17:15:00 2018 -0800

    pdx-name is now required on jdbc-mapping
---
 .../geode/connectors/jdbc/JdbcDistributedTest.java | 71 +++++++++++-----------
 .../connectors/jdbc/JdbcLoaderIntegrationTest.java | 43 +++----------
 .../connectors/jdbc/MySqlJdbcDistributedTest.java  |  5 +-
 .../org/apache/geode/connectors/jdbc/TestDate.java | 53 ++++++++++++++++
 .../jdbc/internal/TestConfigService.java           |  9 ++-
 .../cli/CreateMappingCommandDUnitTest.java         |  4 +-
 .../cli/CreateMappingCommandIntegrationTest.java   |  4 +-
 .../jdbc/internal/SqlToPdxInstanceCreator.java     |  9 +--
 .../jdbc/internal/cli/CreateMappingCommand.java    |  2 +-
 .../jdbc/internal/configuration/RegionMapping.java | 25 ++------
 .../geode.apache.org/schema/jdbc/jdbc-1.0.xsd      |  2 +-
 .../jdbc/internal/RegionMappingTest.java           | 46 ++++----------
 .../jdbc/internal/SqlToPdxInstanceCreatorTest.java | 66 +++++++++++++++-----
 13 files changed, 177 insertions(+), 162 deletions(-)

diff --git a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcDistributedTest.java
b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcDistributedTest.java
index dca19d4..216e5ce 100644
--- a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcDistributedTest.java
+++ b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcDistributedTest.java
@@ -259,18 +259,19 @@ public abstract class JdbcDistributedTest implements Serializable {
       Connection connection = DriverManager.getConnection(connectionUrl);
       Statement statement = connection.createStatement();
       statement.execute(
-          "Create Table " + TABLE_NAME + " (id varchar(10) primary key not null, mydate date)");
+          "Create Table " + TABLE_NAME + " (id varchar(10) primary key not null, "
+              + TestDate.DATE_FIELD_NAME + " date)");
     });
     createRegionUsingGfsh(true, false, true);
     createJdbcConnection();
-    createMapping(REGION_NAME, DATA_SOURCE_NAME);
+    createMapping(REGION_NAME, DATA_SOURCE_NAME, TestDate.class.getName());
     final String key = "emp1";
     final java.sql.Date sqlDate = java.sql.Date.valueOf("1982-09-11");
     final Date jdkDate = new Date(sqlDate.getTime());
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
-              .writeString("id", "key1").writeDate("mydate", jdkDate).create();
+          ClusterStartupRule.getCache().createPdxInstanceFactory(TestDate.class.getName())
+              .writeString("id", "key1").writeDate(TestDate.DATE_FIELD_NAME, jdkDate).create();
 
       Region<Object, Object> region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       region.put(key, pdxEmployee1);
@@ -279,11 +280,10 @@ public abstract class JdbcDistributedTest implements Serializable {
     ClientVM client = getClientVM();
     createClientRegion(client);
     client.invoke(() -> {
-      Region<String, ClassWithSupportedPdxFields> region =
+      Region<String, TestDate> region =
           ClusterStartupRule.getClientCache().getRegion(REGION_NAME);
-      PdxInstance getResult = (PdxInstance) region.get(key);
-      assertThat(getResult.getField("mydate")).isInstanceOf(java.util.Date.class)
-          .isEqualTo(jdkDate);
+      TestDate getResult = region.get(key);
+      assertThat(getResult.getMyDate()).isEqualTo(jdkDate);
     });
   }
 
@@ -294,18 +294,19 @@ public abstract class JdbcDistributedTest implements Serializable {
       Connection connection = DriverManager.getConnection(connectionUrl);
       Statement statement = connection.createStatement();
       statement.execute(
-          "Create Table " + TABLE_NAME + " (id varchar(10) primary key not null, mytime time)");
+          "Create Table " + TABLE_NAME + " (id varchar(10) primary key not null, "
+              + TestDate.DATE_FIELD_NAME + " time)");
     });
     createRegionUsingGfsh(true, false, true);
     createJdbcConnection();
-    createMapping(REGION_NAME, DATA_SOURCE_NAME);
+    createMapping(REGION_NAME, DATA_SOURCE_NAME, TestDate.class.getName());
     final String key = "emp1";
     final java.sql.Time sqlTime = java.sql.Time.valueOf("23:59:59");
     final Date jdkDate = new Date(sqlTime.getTime());
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
-              .writeString("id", "key1").writeDate("mytime", jdkDate).create();
+          ClusterStartupRule.getCache().createPdxInstanceFactory(TestDate.class.getName())
+              .writeString("id", "key1").writeDate(TestDate.DATE_FIELD_NAME, jdkDate).create();
 
       Region<Object, Object> region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       region.put(key, pdxEmployee1);
@@ -314,29 +315,28 @@ public abstract class JdbcDistributedTest implements Serializable {
     ClientVM client = getClientVM();
     createClientRegion(client);
     client.invoke(() -> {
-      Region<String, ClassWithSupportedPdxFields> region =
+      Region<String, TestDate> region =
           ClusterStartupRule.getClientCache().getRegion(REGION_NAME);
-      PdxInstance getResult = (PdxInstance) region.get(key);
-      assertThat(getResult.getField("mytime")).isInstanceOf(java.util.Date.class)
-          .isEqualTo(jdkDate);
+      TestDate getResult = region.get(key);
+      assertThat(getResult.getMyDate()).isEqualTo(jdkDate);
     });
   }
 
   @Test
   public void verifyDateToTimestamp() throws Exception {
     server = startupRule.startServerVM(1, x -> x.withConnectionToLocator(locator.getPort()));
-    createTableWithTimeStamp(server, connectionUrl, TABLE_NAME);
+    createTableWithTimeStamp(server, connectionUrl, TABLE_NAME, TestDate.DATE_FIELD_NAME);
 
     createRegionUsingGfsh(true, false, true);
     createJdbcConnection();
-    createMapping(REGION_NAME, DATA_SOURCE_NAME);
+    createMapping(REGION_NAME, DATA_SOURCE_NAME, TestDate.class.getName());
     final String key = "emp1";
     final java.sql.Timestamp sqlTimestamp = java.sql.Timestamp.valueOf("1982-09-11 23:59:59.123");
     final Date jdkDate = new Date(sqlTimestamp.getTime());
     server.invoke(() -> {
       PdxInstance pdxEmployee1 =
-          ClusterStartupRule.getCache().createPdxInstanceFactory(Employee.class.getName())
-              .writeString("id", "key1").writeDate("mytimestamp", jdkDate).create();
+          ClusterStartupRule.getCache().createPdxInstanceFactory(TestDate.class.getName())
+              .writeString("id", "key1").writeDate(TestDate.DATE_FIELD_NAME, jdkDate).create();
 
       Region<Object, Object> region = ClusterStartupRule.getCache().getRegion(REGION_NAME);
       region.put(key, pdxEmployee1);
@@ -345,20 +345,20 @@ public abstract class JdbcDistributedTest implements Serializable {
     ClientVM client = getClientVM();
     createClientRegion(client);
     client.invoke(() -> {
-      Region<String, ClassWithSupportedPdxFields> region =
+      Region<String, TestDate> region =
           ClusterStartupRule.getClientCache().getRegion(REGION_NAME);
-      PdxInstance getResult = (PdxInstance) region.get(key);
-      assertThat(getResult.getField("mytimestamp")).isInstanceOf(java.util.Date.class)
-          .isEqualTo(jdkDate);
+      TestDate getResult = region.get(key);
+      assertThat(getResult.getMyDate()).isEqualTo(jdkDate);
     });
   }
 
-  protected void createTableWithTimeStamp(MemberVM vm, String connectionUrl, String tableName)
{
+  protected void createTableWithTimeStamp(MemberVM vm, String connectionUrl, String tableName,
+      String columnName) {
     vm.invoke(() -> {
       Connection connection = DriverManager.getConnection(connectionUrl);
       Statement statement = connection.createStatement();
       statement.execute("Create Table " + tableName
-          + " (id varchar(10) primary key not null, mytimestamp timestamp)");
+          + " (id varchar(10) primary key not null, " + columnName + " timestamp)");
     });
   }
 
@@ -431,11 +431,10 @@ public abstract class JdbcDistributedTest implements Serializable {
           (JdbcWriter<Object, Object>) region.getAttributes().getCacheWriter();
       long writeCallsCompletedBeforeGet = writer.getTotalEvents();
 
-      PdxInstance result = (PdxInstance) region.get(key);
-      assertThat(result.getFieldNames()).hasSize(3);
-      assertThat(result.getField("id")).isEqualTo(key);
-      assertThat(result.getField("name")).isEqualTo("Emp1");
-      assertThat(result.getField("age")).isEqualTo(55);
+      Employee result = (Employee) region.get(key);
+      assertThat(result.getId()).isEqualTo(key);
+      assertThat(result.getName()).isEqualTo("Emp1");
+      assertThat(result.getAge()).isEqualTo(55);
       assertThat(writer.getTotalEvents()).isEqualTo(writeCallsCompletedBeforeGet);
     });
   }
@@ -460,11 +459,11 @@ public abstract class JdbcDistributedTest implements Serializable {
         assertThat(asyncWriter.getSuccessfulEvents()).isEqualTo(1);
       });
       region.invalidate(key);
-      PdxInstance result = (PdxInstance) region.get(key);
+      Employee result = (Employee) region.get(key);
 
-      assertThat(result.getField("id")).isEqualTo(pdxEmployee1.getField("id"));
-      assertThat(result.getField("name")).isEqualTo(pdxEmployee1.getField("name"));
-      assertThat(result.getField("age")).isEqualTo(pdxEmployee1.getField("age"));
+      assertThat(result.getId()).isEqualTo(pdxEmployee1.getField("id"));
+      assertThat(result.getName()).isEqualTo(pdxEmployee1.getField("name"));
+      assertThat(result.getAge()).isEqualTo(pdxEmployee1.getField("age"));
       await().untilAsserted(() -> {
         assertThat(asyncWriter.getIgnoredEvents()).isEqualTo(1);
       });
@@ -640,7 +639,7 @@ public abstract class JdbcDistributedTest implements Serializable {
   }
 
   private void createMapping(String regionName, String connectionName) {
-    createMapping(regionName, connectionName, null);
+    createMapping(regionName, connectionName, Employee.class.getName());
   }
 
   private void createMapping(String regionName, String connectionName, String pdxClassName)
{
diff --git a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcLoaderIntegrationTest.java
b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcLoaderIntegrationTest.java
index aa21f2f..71858f7 100644
--- a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcLoaderIntegrationTest.java
+++ b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/JdbcLoaderIntegrationTest.java
@@ -103,40 +103,12 @@ public abstract class JdbcLoaderIntegrationTest {
   }
 
   @Test
-  public void verifySimpleGet() throws Exception {
-    createEmployeeTable();
-    statement
-        .execute("Insert into " + REGION_TABLE_NAME + " (id, name, age) values('1', 'Emp1',
21)");
-    Region<String, PdxInstance> region = createRegionWithJDBCLoader(REGION_TABLE_NAME,
null, false);
-    PdxInstance pdx = region.get("1");
-
-    assertThat(pdx.getFieldNames()).hasSize(3);
-    assertThat(pdx.getField("id")).isEqualTo("1");
-    assertThat(pdx.getField("name")).isEqualTo("Emp1");
-    assertThat(pdx.getField("age")).isEqualTo(21);
-  }
-
-  @Test
-  public void verifySimpleGetWithPrimaryKeyInValue() throws Exception {
-    createEmployeeTable();
-    statement
-        .execute("Insert into " + REGION_TABLE_NAME + " (id, name, age) values('1', 'Emp1',
21)");
-    Region<String, PdxInstance> region = createRegionWithJDBCLoader(REGION_TABLE_NAME,
null, true);
-    PdxInstance pdx = region.get("1");
-
-    assertThat(pdx.getFieldNames()).hasSize(3);
-    assertThat(pdx.getField("id")).isEqualTo("1");
-    assertThat(pdx.getField("name")).isEqualTo("Emp1");
-    assertThat(pdx.getField("age")).isEqualTo(21);
-  }
-
-  @Test
   public void verifyGetWithPdxClassName() throws Exception {
     createEmployeeTable();
     statement
         .execute("Insert into " + REGION_TABLE_NAME + "(id, name, age) values('1', 'Emp1',
21)");
     Region<String, Employee> region =
-        createRegionWithJDBCLoader(REGION_TABLE_NAME, Employee.class.getName(), false);
+        createRegionWithJDBCLoader(REGION_TABLE_NAME, Employee.class.getName());
     createPdxType();
 
     Employee value = region.get("1");
@@ -152,7 +124,7 @@ public abstract class JdbcLoaderIntegrationTest {
         createClassWithSupportedPdxFieldsForInsert("1");
     insertIntoClassWithSupportedPdxFieldsTable("1", classWithSupportedPdxFields);
     Region<String, ClassWithSupportedPdxFields> region = createRegionWithJDBCLoader(
-        REGION_TABLE_NAME, ClassWithSupportedPdxFields.class.getName(), false);
+        REGION_TABLE_NAME, ClassWithSupportedPdxFields.class.getName());
 
     createPdxType(classWithSupportedPdxFields);
 
@@ -172,24 +144,23 @@ public abstract class JdbcLoaderIntegrationTest {
   @Test
   public void verifySimpleMiss() throws Exception {
     createEmployeeTable();
-    Region<String, PdxInstance> region = createRegionWithJDBCLoader(REGION_TABLE_NAME,
null, false);
+    Region<String, PdxInstance> region = createRegionWithJDBCLoader(REGION_TABLE_NAME,
null);
     PdxInstance pdx = region.get("1");
     assertThat(pdx).isNull();
   }
 
-  private SqlHandler createSqlHandler(String pdxClassName, boolean primaryKeyInValue)
+  private SqlHandler createSqlHandler(String pdxClassName)
       throws RegionMappingExistsException {
     return new SqlHandler(new TableMetaDataManager(),
         TestConfigService.getTestConfigService((InternalCache) cache, pdxClassName,
-            primaryKeyInValue, getConnectionUrl()),
+            getConnectionUrl()),
         testDataSourceFactory);
   }
 
-  private <K, V> Region<K, V> createRegionWithJDBCLoader(String regionName, String
pdxClassName,
-      boolean primaryKeyInValue)
+  private <K, V> Region<K, V> createRegionWithJDBCLoader(String regionName, String
pdxClassName)
       throws RegionMappingExistsException {
     JdbcLoader<K, V> jdbcLoader =
-        new JdbcLoader<>(createSqlHandler(pdxClassName, primaryKeyInValue), cache);
+        new JdbcLoader<>(createSqlHandler(pdxClassName), cache);
     RegionFactory<K, V> regionFactory = cache.createRegionFactory(REPLICATE);
     regionFactory.setCacheLoader(jdbcLoader);
     return regionFactory.create(regionName);
diff --git a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/MySqlJdbcDistributedTest.java
b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/MySqlJdbcDistributedTest.java
index a84d543..f85708a 100644
--- a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/MySqlJdbcDistributedTest.java
+++ b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/MySqlJdbcDistributedTest.java
@@ -87,12 +87,13 @@ public class MySqlJdbcDistributedTest extends JdbcDistributedTest {
   }
 
   @Override
-  protected void createTableWithTimeStamp(MemberVM vm, String connectionUrl, String tableName)
{
+  protected void createTableWithTimeStamp(MemberVM vm, String connectionUrl, String tableName,
+      String columnName) {
     vm.invoke(() -> {
       Connection connection = DriverManager.getConnection(connectionUrl);
       Statement statement = connection.createStatement();
       statement.execute("CREATE TABLE " + tableName
-          + " (id varchar(10) primary key not null, mytimestamp timestamp(3))");
+          + " (id varchar(10) primary key not null, " + columnName + " timestamp(3))");
     });
   }
 }
diff --git a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/TestDate.java
b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/TestDate.java
new file mode 100644
index 0000000..40a208a
--- /dev/null
+++ b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/TestDate.java
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+import java.util.Date;
+
+import org.apache.geode.pdx.PdxReader;
+import org.apache.geode.pdx.PdxSerializable;
+import org.apache.geode.pdx.PdxWriter;
+
+public class TestDate implements PdxSerializable {
+  public static final String DATE_FIELD_NAME = "mydate";
+  private String id;
+  private Date myDate;
+
+  public TestDate() {
+    // nothing
+  }
+
+  public String getId() {
+    return id;
+  }
+
+  public Date getMyDate() {
+    return myDate;
+  }
+
+  @Override
+  public void toData(PdxWriter writer) {
+    writer.writeString("id", this.id);
+    writer.writeDate(DATE_FIELD_NAME, this.myDate);
+  }
+
+  @Override
+  public void fromData(PdxReader reader) {
+    this.id = reader.readString("id");
+    this.myDate = reader.readDate(DATE_FIELD_NAME);
+  }
+}
diff --git a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/internal/TestConfigService.java
b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/internal/TestConfigService.java
index 714b3dd..2f561f9 100644
--- a/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/internal/TestConfigService.java
+++ b/geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/internal/TestConfigService.java
@@ -31,16 +31,16 @@ public class TestConfigService {
 
   public static JdbcConnectorServiceImpl getTestConfigService(String connectionUrl)
       throws RegionMappingExistsException {
-    return getTestConfigService(createMockCache(), null, false, connectionUrl);
+    return getTestConfigService(createMockCache(), null, connectionUrl);
   }
 
   public static JdbcConnectorServiceImpl getTestConfigService(InternalCache cache,
-      String pdxClassName, boolean primaryKeyInValue, String connectionUrl)
+      String pdxClassName, String connectionUrl)
       throws RegionMappingExistsException {
 
     JdbcConnectorServiceImpl service = new JdbcConnectorServiceImpl();
     service.init(cache);
-    service.createRegionMapping(createRegionMapping(pdxClassName, primaryKeyInValue));
+    service.createRegionMapping(createRegionMapping(pdxClassName));
     return service;
   }
 
@@ -50,8 +50,7 @@ public class TestConfigService {
     return cache;
   }
 
-  private static RegionMapping createRegionMapping(String pdxClassName,
-      boolean primaryKeyInValue) {
+  private static RegionMapping createRegionMapping(String pdxClassName) {
     return new RegionMapping(REGION_NAME, pdxClassName, REGION_TABLE_NAME,
         CONNECTION_CONFIG_NAME);
   }
diff --git a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
index aea0d6e..ac2b69e 100644
--- a/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
+++ b/geode-connectors/src/distributedTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandDUnitTest.java
@@ -41,7 +41,6 @@ import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
 public class CreateMappingCommandDUnitTest {
 
   private static final String REGION_NAME = "testRegion";
-  private static final String SUBREGION_NAME = REGION_NAME + "/testSubRegion";
 
   @Rule
   public transient GfshCommandRule gfsh = new GfshCommandRule();
@@ -114,12 +113,14 @@ public class CreateMappingCommandDUnitTest {
     CommandStringBuilder csb = new CommandStringBuilder(CREATE_MAPPING);
     csb.addOption(CREATE_MAPPING__REGION_NAME, REGION_NAME);
     csb.addOption(CREATE_MAPPING__DATA_SOURCE_NAME, "connection");
+    csb.addOption(CREATE_MAPPING__PDX_NAME, "myPdxClass");
     csb.addOption(CREATE_MAPPING__TABLE_NAME, "myTable");
     gfsh.executeAndAssertThat(csb.toString()).statusIsSuccess();
 
     csb = new CommandStringBuilder(CREATE_MAPPING);
     csb.addOption(CREATE_MAPPING__REGION_NAME, REGION_NAME);
     csb.addOption(CREATE_MAPPING__DATA_SOURCE_NAME, "connection");
+    csb.addOption(CREATE_MAPPING__PDX_NAME, "myPdxClass");
     csb.addOption(CREATE_MAPPING__TABLE_NAME, "bogus");
     gfsh.executeAndAssertThat(csb.toString()).statusIsError();
 
@@ -127,6 +128,7 @@ public class CreateMappingCommandDUnitTest {
       String xml = InternalLocator.getLocator().getConfigurationPersistenceService()
           .getConfiguration("cluster").getCacheXmlContent();
       assertThat(xml).isNotNull().contains("jdbc:mapping").contains("myTable")
+          .contains("myPdxClass")
           .doesNotContain("bogus");
     });
   }
diff --git a/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandIntegrationTest.java
b/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandIntegrationTest.java
index 20d5598..f3d33ee 100644
--- a/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandIntegrationTest.java
+++ b/geode-connectors/src/integrationTest/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommandIntegrationTest.java
@@ -105,7 +105,7 @@ public class CreateMappingCommandIntegrationTest {
   @Test
   public void createsRegionMappingWithMinimumParams() {
     ResultModel result =
-        createRegionMappingCommand.createMapping(regionName, dataSourceName, null, null);
+        createRegionMappingCommand.createMapping(regionName, dataSourceName, null, pdxClass);
 
     assertThat(result.getStatus()).isSameAs(Result.Status.OK);
 
@@ -116,6 +116,6 @@ public class CreateMappingCommandIntegrationTest {
     assertThat(regionMapping.getRegionName()).isEqualTo(regionName);
     assertThat(regionMapping.getDataSourceName()).isEqualTo(dataSourceName);
     assertThat(regionMapping.getTableName()).isNull();
-    assertThat(regionMapping.getPdxName()).isNull();
+    assertThat(regionMapping.getPdxName()).isEqualTo(pdxClass);
   }
 }
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreator.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreator.java
index 9e7f791..6d3a98e 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreator.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreator.java
@@ -68,11 +68,7 @@ class SqlToPdxInstanceCreator {
 
   private PdxInstanceFactory createPdxInstanceFactory() {
     String valueClassName = regionMapping.getPdxName();
-    if (valueClassName != null) {
-      return cache.createPdxInstanceFactory(valueClassName);
-    } else {
-      return cache.createPdxInstanceFactory("no class", false);
-    }
+    return cache.createPdxInstanceFactory(valueClassName);
   }
 
   /**
@@ -248,9 +244,6 @@ class SqlToPdxInstanceCreator {
 
   private FieldType getFieldType(TypeRegistry typeRegistry, String fieldName) {
     String pdxClassName = regionMapping.getPdxName();
-    if (pdxClassName == null) {
-      return FieldType.OBJECT;
-    }
     PdxType pdxType = typeRegistry.getPdxTypeForField(fieldName, pdxClassName);
     if (pdxType != null) {
       PdxField pdxField = pdxType.getPdxField(fieldName);
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
index 5356c85..1de1062 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/cli/CreateMappingCommand.java
@@ -60,7 +60,7 @@ public class CreateMappingCommand extends SingleGfshCommand {
           help = CREATE_MAPPING__DATA_SOURCE_NAME__HELP) String dataSourceName,
       @CliOption(key = CREATE_MAPPING__TABLE_NAME,
           help = CREATE_MAPPING__TABLE_NAME__HELP) String table,
-      @CliOption(key = CREATE_MAPPING__PDX_NAME,
+      @CliOption(key = CREATE_MAPPING__PDX_NAME, mandatory = true,
           help = CREATE_MAPPING__PDX_NAME__HELP) String pdxName) {
     // input
     Set<DistributedMember> targetMembers = getMembers(null, null);
diff --git a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/configuration/RegionMapping.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/configuration/RegionMapping.java
index 8217e7f..7dfebeb 100644
--- a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/configuration/RegionMapping.java
+++ b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/configuration/RegionMapping.java
@@ -62,7 +62,6 @@ import org.apache.geode.pdx.internal.TypeRegistry;
 @XSDRootElement(namespace = "http://geode.apache.org/schema/jdbc",
     schemaLocation = "http://geode.apache.org/schema/jdbc/jdbc-1.0.xsd")
 public class RegionMapping implements CacheElement {
-  private static final String MAPPINGS_DELIMITER = ":";
 
   @XmlAttribute(name = "data-source")
   protected String dataSourceName;
@@ -147,22 +146,11 @@ public class RegionMapping implements CacheElement {
   }
 
   public String getFieldNameForColumn(String columnName, TypeRegistry typeRegistry) {
-    String fieldName = null;
-    if (getPdxName() == null) {
-      if (columnName.equals(columnName.toUpperCase())) {
-        fieldName = columnName.toLowerCase();
-      } else {
-        fieldName = columnName;
-      }
-    } else {
-      Set<PdxType> pdxTypes = getPdxTypesForClassName(typeRegistry);
-      fieldName = findExactMatch(columnName, pdxTypes);
-      if (fieldName == null) {
-        fieldName = findCaseInsensitiveMatch(columnName, pdxTypes);
-      }
+    Set<PdxType> pdxTypes = getPdxTypesForClassName(typeRegistry);
+    String fieldName = findExactMatch(columnName, pdxTypes);
+    if (fieldName == null) {
+      fieldName = findCaseInsensitiveMatch(columnName, pdxTypes);
     }
-    assert fieldName != null;
-
     return fieldName;
   }
 
@@ -232,8 +220,7 @@ public class RegionMapping implements CacheElement {
     if (regionName != null ? !regionName.equals(that.regionName) : that.regionName != null)
{
       return false;
     }
-    if (pdxName != null ? !pdxName.equals(that.pdxName)
-        : that.pdxName != null) {
+    if (!pdxName.equals(that.pdxName)) {
       return false;
     }
     if (tableName != null ? !tableName.equals(that.tableName) : that.tableName != null) {
@@ -249,7 +236,7 @@ public class RegionMapping implements CacheElement {
   @Override
   public int hashCode() {
     int result = regionName != null ? regionName.hashCode() : 0;
-    result = 31 * result + (pdxName != null ? pdxName.hashCode() : 0);
+    result = 31 * result + pdxName.hashCode();
     result = 31 * result + (tableName != null ? tableName.hashCode() : 0);
     result = 31 * result + (dataSourceName != null ? dataSourceName.hashCode() : 0);
     return result;
diff --git a/geode-connectors/src/main/resources/META-INF/schemas/geode.apache.org/schema/jdbc/jdbc-1.0.xsd
b/geode-connectors/src/main/resources/META-INF/schemas/geode.apache.org/schema/jdbc/jdbc-1.0.xsd
index 56f0559..7082812 100644
--- a/geode-connectors/src/main/resources/META-INF/schemas/geode.apache.org/schema/jdbc/jdbc-1.0.xsd
+++ b/geode-connectors/src/main/resources/META-INF/schemas/geode.apache.org/schema/jdbc/jdbc-1.0.xsd
@@ -42,7 +42,7 @@ XML schema for JDBC Connector Service in Geode.
             <xsd:complexType>
                 <xsd:attribute type="xsd:string" name="data-source" use="required"/>
                 <xsd:attribute type="xsd:string" name="table" use="optional"/>
-                <xsd:attribute type="xsd:string" name="pdx-name" use="optional"/>
+                <xsd:attribute type="xsd:string" name="pdx-name" use="required"/>
             </xsd:complexType>
         </xsd:element>
 </xsd:schema>
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/RegionMappingTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/RegionMappingTest.java
index c25e21b..f84b9c0 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/RegionMappingTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/RegionMappingTest.java
@@ -57,17 +57,15 @@ public class RegionMappingTest {
 
   @Test
   public void initiatedWithNullValues() {
-    mapping = new RegionMapping(null, null, null, null);
+    mapping = new RegionMapping(null, "pdxClassName", null, null);
 
     assertThat(mapping.getTableName()).isNull();
     assertThat(mapping.getRegionName()).isNull();
     assertThat(mapping.getDataSourceName()).isNull();
-    assertThat(mapping.getPdxName()).isNull();
+    assertThat(mapping.getPdxName()).isEqualTo("pdxClassName");
     assertThat(mapping.getRegionToTableName()).isNull();
     assertThat(mapping.getColumnNameForField("fieldName", mock(TableMetaDataView.class)))
         .isEqualTo("fieldName");
-    assertThat(mapping.getFieldNameForColumn("columnName", mock(TypeRegistry.class)))
-        .isEqualTo("columnName");
   }
 
   @Test
@@ -111,7 +109,7 @@ public class RegionMappingTest {
 
   @Test
   public void returnsColumnNameIfFieldNotMapped() {
-    mapping = new RegionMapping(null, null, null, null);
+    mapping = new RegionMapping(null, "pdxClassName", null, null);
 
     String columnName = mapping.getColumnNameForField(fieldName1, mock(TableMetaDataView.class));
 
@@ -121,7 +119,7 @@ public class RegionMappingTest {
   @Test
   public void returnsColumnNameFromTableMetaDataIfFieldNotMappedAndMetaDataMatchesWithCaseDiffering()
{
     String metaDataColumnName = fieldName1.toUpperCase();
-    mapping = new RegionMapping(null, null, null, null);
+    mapping = new RegionMapping(null, "pdxClassName", null, null);
     TableMetaDataView tableMetaDataView = mock(TableMetaDataView.class);
     when(tableMetaDataView.getColumnNames()).thenReturn(Collections.singleton(metaDataColumnName));
 
@@ -132,7 +130,7 @@ public class RegionMappingTest {
   @Test
   public void returnsColumnNameFromTableMetaDataIfFieldNotMappedAndMetaDataMatchesExactly()
{
     String metaDataColumnName = fieldName1;
-    mapping = new RegionMapping(null, null, null, null);
+    mapping = new RegionMapping(null, "pdxClassName", null, null);
     TableMetaDataView tableMetaDataView = mock(TableMetaDataView.class);
     when(tableMetaDataView.getColumnNames()).thenReturn(Collections.singleton(metaDataColumnName));
 
@@ -142,7 +140,7 @@ public class RegionMappingTest {
 
   @Test
   public void returnsColumnNameIfFieldNotMappedAndNotInMetaData() {
-    mapping = new RegionMapping(null, null, null, null);
+    mapping = new RegionMapping(null, "pdxClassName", null, null);
     TableMetaDataView tableMetaDataView = mock(TableMetaDataView.class);
     when(tableMetaDataView.getColumnNames()).thenReturn(Collections.singleton("does not match"));
 
@@ -151,7 +149,7 @@ public class RegionMappingTest {
 
   @Test
   public void getColumnNameForFieldThrowsIfTwoColumnsMatchField() {
-    mapping = new RegionMapping(null, null, null, null);
+    mapping = new RegionMapping(null, "pdxClassName", null, null);
 
     TableMetaDataView tableMetaDataView = mock(TableMetaDataView.class);
     HashSet<String> columnNames =
@@ -166,28 +164,6 @@ public class RegionMappingTest {
   }
 
   @Test
-  public void ifMixedCaseColumnNameNotMappedReturnsItAsFieldName() {
-    mapping = new RegionMapping(null, null, null, null);
-
-    assertThat(mapping.getFieldNameForColumn("columnName", null)).isEqualTo("columnName");
-  }
-
-  @Test
-  public void ifLowerCaseColumnNameNotMappedReturnsItAsFieldName() {
-    mapping = new RegionMapping(null, null, null, null);
-
-    assertThat(mapping.getFieldNameForColumn("columnname", null)).isEqualTo("columnname");
-  }
-
-  @Test
-  public void ifUpperCaseColumnNameNotMappedReturnsItLowerCasedAsFieldName() {
-    mapping = new RegionMapping(null, null, null, null);
-
-    assertThat(mapping.getFieldNameForColumn("COLUMNNAME", null)).isEqualTo("columnname");
-  }
-
-
-  @Test
   public void throwsIfColumnNotMappedAndPdxClassNameDoesNotExist() {
     mapping = new RegionMapping(null, "pdxClassName", null, null);
     TypeRegistry typeRegistry = mock(TypeRegistry.class);
@@ -264,9 +240,9 @@ public class RegionMappingTest {
   @Test
   public void verifyTwoDefaultInstancesAreEqual() {
     RegionMapping rm1 =
-        new RegionMapping("regionName", null, null, "connectionName");
+        new RegionMapping("regionName", "pdxClassName", null, "connectionName");
     RegionMapping rm2 =
-        new RegionMapping("regionName", null, null, "connectionName");
+        new RegionMapping("regionName", "pdxClassName", null, "connectionName");
     assertThat(rm1).isEqualTo(rm2);
   }
 
@@ -284,7 +260,7 @@ public class RegionMappingTest {
 
   @Test
   public void verifyThatMappingIsEqualToItself() {
-    mapping = new RegionMapping(null, null, null, null);
+    mapping = new RegionMapping(null, "pdxClassName", null, null);
     boolean result = mapping.equals(mapping);
     assertThat(mapping.hashCode()).isEqualTo(mapping.hashCode());
     assertThat(result).isTrue();
@@ -317,7 +293,7 @@ public class RegionMappingTest {
   @Test
   public void verifyMappingWithDifferentPdxClassNameAreNotEqual() {
     RegionMapping rm1 =
-        new RegionMapping(null, null, null, null);
+        new RegionMapping(null, "pdxClassName", null, null);
     RegionMapping rm2 =
         new RegionMapping(null, "pdxClass", null, null);
     boolean result = rm1.equals(rm2);
diff --git a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreatorTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreatorTest.java
index abac1fd..22fe169 100644
--- a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreatorTest.java
+++ b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/SqlToPdxInstanceCreatorTest.java
@@ -91,16 +91,6 @@ public class SqlToPdxInstanceCreatorTest {
   }
 
   @Test
-  public void usesPdxFactoryForNoPdxClassWhenClassNonExistent() throws Exception {
-    when(resultSet.next()).thenReturn(false);
-
-    createPdxInstance();
-
-    verify(cache).createPdxInstanceFactory("no class", false);
-    verifyNoMoreInteractions(cache);
-  }
-
-  @Test
   public void readReturnsNullIfNoResultsReturned() throws Exception {
     when(resultSet.next()).thenReturn(false);
 
@@ -114,13 +104,24 @@ public class SqlToPdxInstanceCreatorTest {
     setupResultSetForTwoObjectColumns(resultSet);
     when(resultSet.next()).thenReturn(true).thenReturn(false);
     PdxInstanceFactory factory = mock(PdxInstanceFactory.class);
-    when(cache.createPdxInstanceFactory(anyString(), anyBoolean())).thenReturn(factory);
     when(regionMapping.getFieldNameForColumn(eq(COLUMN_NAME_1), any()))
         .thenReturn(PDX_FIELD_NAME_1);
     when(regionMapping.getFieldNameForColumn(eq(COLUMN_NAME_2), any()))
         .thenReturn(PDX_FIELD_NAME_2);
     tableMetaDataView = mock(TableMetaDataView.class);
     when(tableMetaDataView.getKeyColumnName()).thenReturn(COLUMN_NAME_1);
+    TypeRegistry pdxTypeRegistry = mock(TypeRegistry.class);
+    when(cache.getPdxRegistry()).thenReturn(pdxTypeRegistry);
+    String pdxClassName = "myPdxClassName";
+    when(cache.createPdxInstanceFactory(pdxClassName)).thenReturn(factory);
+    PdxType pdxType = mock(PdxType.class);
+    when(regionMapping.getPdxName()).thenReturn(pdxClassName);
+    when(pdxTypeRegistry.getPdxTypeForField(PDX_FIELD_NAME_1, pdxClassName)).thenReturn(pdxType);
+    PdxField pdxField = mock(PdxField.class);
+    when(pdxField.getFieldType()).thenReturn(FieldType.OBJECT);
+    when(pdxType.getPdxField(PDX_FIELD_NAME_1)).thenReturn(pdxField);
+    when(pdxTypeRegistry.getPdxTypeForField(PDX_FIELD_NAME_2, pdxClassName)).thenReturn(pdxType);
+    when(pdxType.getPdxField(PDX_FIELD_NAME_2)).thenReturn(pdxField);
 
     createPdxInstance();
 
@@ -134,11 +135,23 @@ public class SqlToPdxInstanceCreatorTest {
     setupResultSetForTwoObjectColumns(resultSet);
     when(resultSet.next()).thenReturn(true).thenReturn(false);
     PdxInstanceFactory factory = mock(PdxInstanceFactory.class);
+    String pdxClassName = "myPdxClassName";
+    when(cache.createPdxInstanceFactory(pdxClassName)).thenReturn(factory);
     when(cache.createPdxInstanceFactory(anyString(), anyBoolean())).thenReturn(factory);
     when(regionMapping.getFieldNameForColumn(eq(COLUMN_NAME_1), any()))
         .thenReturn(PDX_FIELD_NAME_1);
     when(regionMapping.getFieldNameForColumn(eq(COLUMN_NAME_2), any()))
         .thenReturn(PDX_FIELD_NAME_2);
+    TypeRegistry pdxTypeRegistry = mock(TypeRegistry.class);
+    when(cache.getPdxRegistry()).thenReturn(pdxTypeRegistry);
+    PdxType pdxType = mock(PdxType.class);
+    when(regionMapping.getPdxName()).thenReturn(pdxClassName);
+    when(pdxTypeRegistry.getPdxTypeForField(PDX_FIELD_NAME_1, pdxClassName)).thenReturn(pdxType);
+    PdxField pdxField = mock(PdxField.class);
+    when(pdxField.getFieldType()).thenReturn(FieldType.OBJECT);
+    when(pdxType.getPdxField(PDX_FIELD_NAME_1)).thenReturn(pdxField);
+    when(pdxTypeRegistry.getPdxTypeForField(PDX_FIELD_NAME_2, pdxClassName)).thenReturn(pdxType);
+    when(pdxType.getPdxField(PDX_FIELD_NAME_2)).thenReturn(pdxField);
 
     createPdxInstance();
 
@@ -149,12 +162,21 @@ public class SqlToPdxInstanceCreatorTest {
 
   @Test
   public void usesMappedPdxFieldNameWhenReading() throws Exception {
-    setupResultSetForTwoObjectColumns(resultSet);
+    setupResultSet(resultSet, FieldType.OBJECT, COLUMN_VALUE_1);
     when(resultSet.next()).thenReturn(true).thenReturn(false);
     PdxInstanceFactory factory = mock(PdxInstanceFactory.class);
-    when(cache.createPdxInstanceFactory(anyString(), anyBoolean())).thenReturn(factory);
     String fieldName1 = "pdxFieldName1";
     when(regionMapping.getFieldNameForColumn(eq(COLUMN_NAME_1), any())).thenReturn(fieldName1);
+    TypeRegistry pdxTypeRegistry = mock(TypeRegistry.class);
+    when(cache.getPdxRegistry()).thenReturn(pdxTypeRegistry);
+    String pdxClassName = "myPdxClassName";
+    when(cache.createPdxInstanceFactory(pdxClassName)).thenReturn(factory);
+    PdxType pdxType = mock(PdxType.class);
+    when(regionMapping.getPdxName()).thenReturn(pdxClassName);
+    when(pdxTypeRegistry.getPdxTypeForField(fieldName1, pdxClassName)).thenReturn(pdxType);
+    PdxField pdxField = mock(PdxField.class);
+    when(pdxField.getFieldType()).thenReturn(FieldType.OBJECT);
+    when(pdxType.getPdxField(fieldName1)).thenReturn(pdxField);
 
     createPdxInstance();
 
@@ -478,12 +500,24 @@ public class SqlToPdxInstanceCreatorTest {
 
   @Test
   public void throwsExceptionIfMoreThanOneResultReturned() throws Exception {
-    setupResultSetForTwoObjectColumns(resultSet);
+    setupResultSet(resultSet, FieldType.OBJECT);
     when(resultSet.next()).thenReturn(true);
     when(resultSet.getStatement()).thenReturn(mock(PreparedStatement.class));
-    when(cache.createPdxInstanceFactory(anyString(), anyBoolean()))
-        .thenReturn(mock(PdxInstanceFactory.class));
+    PdxInstanceFactory factory = mock(PdxInstanceFactory.class);
+    String pdxClassName = "myPdxClassName";
+    when(cache.createPdxInstanceFactory(pdxClassName)).thenReturn(factory);
+    TypeRegistry pdxTypeRegistry = mock(TypeRegistry.class);
+    when(cache.getPdxRegistry()).thenReturn(pdxTypeRegistry);
+    PdxType pdxType = mock(PdxType.class);
+    when(regionMapping.getPdxName()).thenReturn(pdxClassName);
+    when(pdxTypeRegistry.getPdxTypeForField(PDX_FIELD_NAME_1, pdxClassName)).thenReturn(pdxType);
+    PdxField pdxField = mock(PdxField.class);
+    when(pdxField.getFieldType()).thenReturn(FieldType.OBJECT);
+    when(pdxType.getPdxField(PDX_FIELD_NAME_1)).thenReturn(pdxField);
+    when(regionMapping.getFieldNameForColumn(eq(COLUMN_NAME_1), any()))
+        .thenReturn(PDX_FIELD_NAME_1);
     thrown.expect(JdbcConnectorException.class);
+    thrown.expectMessage("Multiple rows returned for query: ");
 
     createPdxInstance();
   }


Mime
View raw message