This is an automated email from the ASF dual-hosted git repository.
dschneider pushed a commit to branch feature/GEODE-6291
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-6291 by this
push:
new e43bde9 getColumnNameForField now does inexact matching
e43bde9 is described below
commit e43bde9f5b3a7a67eee202a38d999b46ae2c6c4c
Author: Darrel Schneider <[email protected]>
AuthorDate: Mon Jan 28 15:23:04 2019 -0800
getColumnNameForField now does inexact matching
---
.../jdbc/internal/configuration/RegionMapping.java | 22 +++++++++---
.../jdbc/internal/RegionMappingTest.java | 40 +++++++++++++++++++---
2 files changed, 53 insertions(+), 9 deletions(-)
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 eddf2a6..79ef582 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
@@ -189,12 +189,24 @@ public class RegionMapping implements CacheElement {
}
public String getColumnNameForField(String fieldName) {
- FieldMapping fieldMapping = getFieldMappingByPdxName(fieldName);
- if (fieldMapping != null) {
- return fieldMapping.getJdbcName();
+ FieldMapping exactMatch = getFieldMappingByPdxName(fieldName);
+ if (exactMatch != null) {
+ return exactMatch.getJdbcName();
}
- throw new JdbcConnectorException(
- "A field mapping for the pdx field \"" + fieldName + "\" does not
exist.");
+ FieldMapping inexactMatch = null;
+ for (FieldMapping fieldMapping : getFieldMappings()) {
+ if (fieldMapping.getPdxName().equalsIgnoreCase(fieldName)) {
+ if (inexactMatch != null) {
+ throw new JdbcConnectorException(
+ "Multiple columns matched the pdx field \"" + fieldName + "\".");
+ }
+ inexactMatch = fieldMapping;
+ }
+ }
+ if (inexactMatch == null) {
+ throw new JdbcConnectorException("No column matched the pdx field \"" +
fieldName + "\".");
+ }
+ return inexactMatch.getJdbcName();
}
@Override
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 5f486a5..688e1ab 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
@@ -111,19 +111,51 @@ public class RegionMappingTest {
mapping = new RegionMapping(null, "pdxClassName", null, null, null, null,
null);
expectedException.expect(JdbcConnectorException.class);
expectedException
- .expectMessage("A field mapping for the pdx field \"" + fieldName1 +
"\" does not exist.");
+ .expectMessage("No column matched the pdx field \"" + fieldName1 +
"\".");
mapping.getColumnNameForField(fieldName1);
}
@Test
- public void getColumnNameForFieldReturnsColumnNameIfMapped() {
+ public void getColumnNameForFieldThrowsIfMultipleFieldsMatchInexactly() {
String pdxClassName = "pdxClassName";
String columnName = "columnName";
+ String pdxFieldName = "pdxFieldName";
mapping = new RegionMapping(null, pdxClassName, null, null, null, null,
null);
- mapping.addFieldMapping(new FieldMapping(pdxClassName, null, columnName,
null, false));
+ mapping.addFieldMapping(new FieldMapping("f1", null, "c1", null, false));
+ mapping.addFieldMapping(
+ new FieldMapping(pdxFieldName.toLowerCase(), null, columnName, null,
false));
+ mapping.addFieldMapping(
+ new FieldMapping(pdxFieldName.toUpperCase(), null, columnName, null,
false));
+ expectedException.expect(JdbcConnectorException.class);
+ expectedException
+ .expectMessage("Multiple columns matched the pdx field \"" +
pdxFieldName + "\".");
+
+ mapping.getColumnNameForField(pdxFieldName);
+ }
+
+ @Test
+ public void getColumnNameForFieldReturnsColumnNameWhenMappedExactly() {
+ String pdxClassName = "pdxClassName";
+ String columnName = "columnName";
+ String pdxFieldName = "pdxFieldName";
+ mapping = new RegionMapping(null, pdxClassName, null, null, null, null,
null);
+ mapping.addFieldMapping(new FieldMapping(pdxFieldName, null, columnName,
null, false));
+
+
assertThat(mapping.getColumnNameForField(pdxFieldName)).isEqualTo(columnName);
+ }
+
+ @Test
+ public void getColumnNameForFieldReturnsColumnNameWhenMappedInexactly() {
+ String pdxClassName = "pdxClassName";
+ String columnName = "columnName";
+ String pdxFieldName = "pdxFieldName";
+ mapping = new RegionMapping(null, pdxClassName, null, null, null, null,
null);
+ mapping.addFieldMapping(new FieldMapping("f1", null, "c1", null, false));
+ mapping.addFieldMapping(
+ new FieldMapping(pdxFieldName.toLowerCase(), null, columnName, null,
false));
-
assertThat(mapping.getColumnNameForField(pdxClassName)).isEqualTo(columnName);
+
assertThat(mapping.getColumnNameForField(pdxFieldName)).isEqualTo(columnName);
}
@Test