[ https://issues.apache.org/jira/browse/GEODE-8626?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17263012#comment-17263012 ]
ASF GitHub Bot commented on GEODE-8626: --------------------------------------- jchen21 commented on a change in pull request #5637: URL: https://github.com/apache/geode/pull/5637#discussion_r555418639 ########## File path: geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/CacheXmlJdbcMappingIntegrationTest.java ########## @@ -0,0 +1,284 @@ +/* + * 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 static org.apache.geode.test.util.ResourceUtils.createTempFileFromResource; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +import java.net.URL; +import java.sql.Connection; +import java.sql.JDBCType; +import java.sql.Statement; +import java.util.Arrays; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; + +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; +import org.apache.geode.connectors.jdbc.internal.configuration.FieldMapping; +import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; +import org.apache.geode.connectors.jdbc.test.junit.rules.DatabaseConnectionRule; +import org.apache.geode.connectors.jdbc.test.junit.rules.MySqlConnectionRule; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.jndi.JNDIInvoker; +import org.apache.geode.pdx.FieldType; +import org.apache.geode.pdx.internal.AutoSerializableManager; + +public class CacheXmlJdbcMappingIntegrationTest { + + private static final URL COMPOSE_RESOURCE_PATH = + CacheXmlJdbcMappingIntegrationTest.class.getResource("mysql.yml"); + protected static final String DATA_SOURCE_NAME = "TestDataSource"; + protected static final String DB_NAME = "test"; + protected static final String REGION_TABLE_NAME = "employees"; + protected static final String REGION_NAME = "Region1"; + + @Rule + public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); + + private Connection connection; + private Statement statement; + private InternalCache cache; + + @ClassRule + public static DatabaseConnectionRule dbRule = new MySqlConnectionRule.Builder() + .file(COMPOSE_RESOURCE_PATH.getPath()).serviceName("db").port(3306).database(DB_NAME).build(); + + @Before + public void setUp() throws Exception { + System.setProperty(AutoSerializableManager.NO_HARDCODED_EXCLUDES_PARAM, "true"); + connection = dbRule.getConnection(); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + JNDIInvoker.unMapDatasource(DATA_SOURCE_NAME); + + if (cache != null) { + cache.close(); + } + + if (statement == null) { + statement = connection.createStatement(); + } + statement.execute("Drop table IF EXISTS " + REGION_TABLE_NAME); + statement.close(); + + if (connection != null) { + connection.close(); + } + } + + private InternalCache createCacheAndCreateJdbcMapping(String cacheXmlTestName) + throws Exception { + String url = dbRule.getConnectionUrl().replaceAll("&", "&"); + System.setProperty("TestDataSourceUrl", url); + InternalCache cache = + (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0") + .set("cache-xml-file", getXmlFileForTest(cacheXmlTestName)) + .create(); + return cache; + } + + private InternalCache createCacheAndCreateJdbcMappingWithNonSerializedClass( + String cacheXmlTestName) throws Exception { + return createCacheAndCreateJdbcMapping(cacheXmlTestName); + } + + private InternalCache createCacheAndCreateJdbcMappingWithWrongDataSource( + String cacheXmlTestName) throws Exception { + System.setProperty("TestDataSourceUrl", "jdbc:mysql://localhost/test"); + InternalCache cache = + (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0") + .set("cache-xml-file", getXmlFileForTest(cacheXmlTestName)) + .create(); + return cache; + } + + private InternalCache createCacheAndCreateJdbcMappingWithWrongPdxName(String cacheXmlTestName) + throws Exception { + String url = dbRule.getConnectionUrl().replaceAll("&", "&"); + System.setProperty("TestDataSourceUrl", url); + InternalCache cache = + (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0") + .set("cache-xml-file", getXmlFileForTest(cacheXmlTestName)) + .create(); + return cache; + } + + private String getXmlFileForTest(String testName) { + return createTempFileFromResource(getClass(), + getClassSimpleName() + "." + testName + ".cache.xml").getAbsolutePath(); + } + + private String getClassSimpleName() { + return getClass().getSimpleName(); + } + + private void createEmployeeTable() throws Exception { + statement.execute("Create Table " + REGION_TABLE_NAME + + " (id varchar(10) primary key not null, name varchar(10), age int)"); + } + + private void createEmployeeTableWithColumnNamesWithUnderscores() throws Exception { + statement.execute("Create Table " + REGION_TABLE_NAME + + " (id varchar(10) primary key not null, _name varchar(10), _age int)"); + } + + private List<FieldMapping> getEmployeeTableFieldMappings() { + List<FieldMapping> fieldMappings = Arrays.asList( + new FieldMapping("id", FieldType.STRING.name(), "id", JDBCType.VARCHAR.name(), false), + new FieldMapping("name", FieldType.STRING.name(), "name", JDBCType.VARCHAR.name(), true), + new FieldMapping("age", FieldType.INT.name(), "age", JDBCType.INTEGER.name(), true)); + return fieldMappings; + } + + private List<FieldMapping> getEmployeeTableColumnNameWithUnderscoresFieldMappings() { + List<FieldMapping> fieldMappings = Arrays.asList( + new FieldMapping("id", FieldType.STRING.name(), "id", JDBCType.VARCHAR.name(), false), + new FieldMapping("name", FieldType.STRING.name(), "_name", JDBCType.VARCHAR.name(), true), + new FieldMapping("age", FieldType.INT.name(), "_age", JDBCType.INTEGER.name(), true)); + return fieldMappings; + } + + @Test + public void mappingSuccessWhenFieldMappingsAreExists() throws Exception { + createEmployeeTable(); + + cache = createCacheAndCreateJdbcMapping("FieldMappings"); + JdbcConnectorService service = cache.getService(JdbcConnectorService.class); + + RegionMapping mapping = service.getMappingForRegion(REGION_NAME); + assertThat(mapping.getDataSourceName()).isEqualTo(DATA_SOURCE_NAME); + assertThat(mapping.getTableName()).isEqualTo(REGION_TABLE_NAME); + assertThat(mapping.getRegionName()).isEqualTo(REGION_NAME); + assertThat(mapping.getPdxName()).isEqualTo(Employee.class.getName()); + assertThat(mapping.getIds()).isEqualTo("id"); + assertThat(mapping.getFieldMappings().size()).isEqualTo(3); + assertThat(mapping.getFieldMappings()).containsAll(getEmployeeTableFieldMappings()); + } + + @Test + public void mappingSuccessWhenFieldMappingsAreOmitted() throws Exception { + createEmployeeTable(); + + cache = createCacheAndCreateJdbcMapping("NoFieldMappings"); + JdbcConnectorService service = cache.getService(JdbcConnectorService.class); + + RegionMapping mapping = service.getMappingForRegion(REGION_NAME); + assertThat(mapping.getDataSourceName()).isEqualTo(DATA_SOURCE_NAME); + assertThat(mapping.getTableName()).isEqualTo(REGION_TABLE_NAME); + assertThat(mapping.getRegionName()).isEqualTo(REGION_NAME); + assertThat(mapping.getPdxName()).isEqualTo(Employee.class.getName()); + assertThat(mapping.getIds()).isEqualTo("id"); + assertThat(mapping.getFieldMappings().size()).isEqualTo(3); + assertThat(mapping.getFieldMappings()).containsAll(getEmployeeTableFieldMappings()); + } + + @Test + public void mappingSuccessWhenFieldMappingsAreOmittedWithNonSerializedClass() throws Exception { + createEmployeeTable(); + + cache = createCacheAndCreateJdbcMappingWithNonSerializedClass( + "NoFieldMappingsWithNonSerializedClass"); + JdbcConnectorService service = cache.getService(JdbcConnectorService.class); + + RegionMapping mapping = service.getMappingForRegion(REGION_NAME); + assertThat(mapping.getDataSourceName()).isEqualTo(DATA_SOURCE_NAME); + assertThat(mapping.getTableName()).isEqualTo(REGION_TABLE_NAME); + assertThat(mapping.getRegionName()).isEqualTo(REGION_NAME); + assertThat(mapping.getPdxName()).isEqualTo(NonSerializedEmployee.class.getName()); + assertThat(mapping.getIds()).isEqualTo("id"); + assertThat(mapping.getFieldMappings().size()).isEqualTo(3); + assertThat(mapping.getFieldMappings()).containsAll(getEmployeeTableFieldMappings()); + } + + @Test + public void mappingFailureWhenConnectWrongDataSource() { + Throwable throwable = + catchThrowable(() -> createCacheAndCreateJdbcMappingWithWrongDataSource("NoFieldMappings")); + + assertThat(throwable).isInstanceOf(JdbcConnectorException.class) + .hasMessage(String.format("No datasource \"%s\" found when creating default field mapping", + DATA_SOURCE_NAME)); + } + + @Test + public void mappingFailureWhenTableNotExists() { + Throwable throwable = catchThrowable(() -> createCacheAndCreateJdbcMapping("NoFieldMappings")); + + assertThat(throwable).isInstanceOf(JdbcConnectorException.class) + .hasMessage(String.format("No table was found that matches \"%s\"", REGION_TABLE_NAME)); + } + + @Test + public void mappingFailureWhenPdxNotExists() throws Exception { + createEmployeeTable(); + + Throwable throwable = + catchThrowable(() -> createCacheAndCreateJdbcMappingWithWrongPdxName("NoPdxName")); Review comment: This is a bug. I believe the string in the quote should be `WrongPdxName` instead of `NoPdxName`. There is no such file `CacheXmlJdbcMappingIntegrationTest.NoPdxName.cache.xml`. So the actual error is something like `FileNotFoundException` returned by `getXmlFileForTest()`. And the assertion at line 241 and 242 doesn't really catch the bug. ########## File path: geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/CacheXmlJdbcMappingIntegrationTest.java ########## @@ -0,0 +1,284 @@ +/* + * 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 static org.apache.geode.test.util.ResourceUtils.createTempFileFromResource; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +import java.net.URL; +import java.sql.Connection; +import java.sql.JDBCType; +import java.sql.Statement; +import java.util.Arrays; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; + +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; +import org.apache.geode.connectors.jdbc.internal.configuration.FieldMapping; +import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; +import org.apache.geode.connectors.jdbc.test.junit.rules.DatabaseConnectionRule; +import org.apache.geode.connectors.jdbc.test.junit.rules.MySqlConnectionRule; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.jndi.JNDIInvoker; +import org.apache.geode.pdx.FieldType; +import org.apache.geode.pdx.internal.AutoSerializableManager; + +public class CacheXmlJdbcMappingIntegrationTest { + + private static final URL COMPOSE_RESOURCE_PATH = + CacheXmlJdbcMappingIntegrationTest.class.getResource("mysql.yml"); + protected static final String DATA_SOURCE_NAME = "TestDataSource"; + protected static final String DB_NAME = "test"; + protected static final String REGION_TABLE_NAME = "employees"; + protected static final String REGION_NAME = "Region1"; + + @Rule + public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); + + private Connection connection; + private Statement statement; + private InternalCache cache; + + @ClassRule + public static DatabaseConnectionRule dbRule = new MySqlConnectionRule.Builder() + .file(COMPOSE_RESOURCE_PATH.getPath()).serviceName("db").port(3306).database(DB_NAME).build(); + + @Before + public void setUp() throws Exception { + System.setProperty(AutoSerializableManager.NO_HARDCODED_EXCLUDES_PARAM, "true"); + connection = dbRule.getConnection(); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + JNDIInvoker.unMapDatasource(DATA_SOURCE_NAME); + + if (cache != null) { + cache.close(); + } + + if (statement == null) { + statement = connection.createStatement(); + } + statement.execute("Drop table IF EXISTS " + REGION_TABLE_NAME); + statement.close(); + + if (connection != null) { + connection.close(); + } + } + + private InternalCache createCacheAndCreateJdbcMapping(String cacheXmlTestName) + throws Exception { Review comment: This `throws Exception` can be removed. The same for line 93, 109 and 119. ########## File path: geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/CacheXmlJdbcMappingIntegrationTest.java ########## @@ -0,0 +1,284 @@ +/* + * 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 static org.apache.geode.test.util.ResourceUtils.createTempFileFromResource; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +import java.net.URL; +import java.sql.Connection; +import java.sql.JDBCType; +import java.sql.Statement; +import java.util.Arrays; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; + +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; +import org.apache.geode.connectors.jdbc.internal.configuration.FieldMapping; +import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; +import org.apache.geode.connectors.jdbc.test.junit.rules.DatabaseConnectionRule; +import org.apache.geode.connectors.jdbc.test.junit.rules.MySqlConnectionRule; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.jndi.JNDIInvoker; +import org.apache.geode.pdx.FieldType; +import org.apache.geode.pdx.internal.AutoSerializableManager; + +public class CacheXmlJdbcMappingIntegrationTest { + + private static final URL COMPOSE_RESOURCE_PATH = + CacheXmlJdbcMappingIntegrationTest.class.getResource("mysql.yml"); + protected static final String DATA_SOURCE_NAME = "TestDataSource"; + protected static final String DB_NAME = "test"; + protected static final String REGION_TABLE_NAME = "employees"; + protected static final String REGION_NAME = "Region1"; + + @Rule + public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); + + private Connection connection; + private Statement statement; + private InternalCache cache; + + @ClassRule + public static DatabaseConnectionRule dbRule = new MySqlConnectionRule.Builder() + .file(COMPOSE_RESOURCE_PATH.getPath()).serviceName("db").port(3306).database(DB_NAME).build(); + + @Before + public void setUp() throws Exception { + System.setProperty(AutoSerializableManager.NO_HARDCODED_EXCLUDES_PARAM, "true"); + connection = dbRule.getConnection(); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + JNDIInvoker.unMapDatasource(DATA_SOURCE_NAME); + + if (cache != null) { + cache.close(); + } + + if (statement == null) { + statement = connection.createStatement(); + } + statement.execute("Drop table IF EXISTS " + REGION_TABLE_NAME); + statement.close(); + + if (connection != null) { + connection.close(); + } + } + + private InternalCache createCacheAndCreateJdbcMapping(String cacheXmlTestName) + throws Exception { + String url = dbRule.getConnectionUrl().replaceAll("&", "&"); + System.setProperty("TestDataSourceUrl", url); + InternalCache cache = + (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0") + .set("cache-xml-file", getXmlFileForTest(cacheXmlTestName)) + .create(); + return cache; + } + + private InternalCache createCacheAndCreateJdbcMappingWithNonSerializedClass( + String cacheXmlTestName) throws Exception { + return createCacheAndCreateJdbcMapping(cacheXmlTestName); Review comment: I would recommend inline this one-line implementation for readability of code. ########## File path: geode-connectors/src/acceptanceTest/java/org/apache/geode/connectors/jdbc/CacheXmlJdbcMappingIntegrationTest.java ########## @@ -0,0 +1,284 @@ +/* + * 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 static org.apache.geode.test.util.ResourceUtils.createTempFileFromResource; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.catchThrowable; + +import java.net.URL; +import java.sql.Connection; +import java.sql.JDBCType; +import java.sql.Statement; +import java.util.Arrays; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.RestoreSystemProperties; + +import org.apache.geode.cache.CacheFactory; +import org.apache.geode.connectors.jdbc.internal.JdbcConnectorService; +import org.apache.geode.connectors.jdbc.internal.configuration.FieldMapping; +import org.apache.geode.connectors.jdbc.internal.configuration.RegionMapping; +import org.apache.geode.connectors.jdbc.test.junit.rules.DatabaseConnectionRule; +import org.apache.geode.connectors.jdbc.test.junit.rules.MySqlConnectionRule; +import org.apache.geode.internal.cache.InternalCache; +import org.apache.geode.internal.jndi.JNDIInvoker; +import org.apache.geode.pdx.FieldType; +import org.apache.geode.pdx.internal.AutoSerializableManager; + +public class CacheXmlJdbcMappingIntegrationTest { + + private static final URL COMPOSE_RESOURCE_PATH = + CacheXmlJdbcMappingIntegrationTest.class.getResource("mysql.yml"); + protected static final String DATA_SOURCE_NAME = "TestDataSource"; + protected static final String DB_NAME = "test"; + protected static final String REGION_TABLE_NAME = "employees"; + protected static final String REGION_NAME = "Region1"; + + @Rule + public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties(); + + private Connection connection; + private Statement statement; + private InternalCache cache; + + @ClassRule + public static DatabaseConnectionRule dbRule = new MySqlConnectionRule.Builder() + .file(COMPOSE_RESOURCE_PATH.getPath()).serviceName("db").port(3306).database(DB_NAME).build(); + + @Before + public void setUp() throws Exception { + System.setProperty(AutoSerializableManager.NO_HARDCODED_EXCLUDES_PARAM, "true"); + connection = dbRule.getConnection(); + statement = connection.createStatement(); + } + + @After + public void tearDown() throws Exception { + JNDIInvoker.unMapDatasource(DATA_SOURCE_NAME); + + if (cache != null) { + cache.close(); + } + + if (statement == null) { + statement = connection.createStatement(); + } + statement.execute("Drop table IF EXISTS " + REGION_TABLE_NAME); + statement.close(); + + if (connection != null) { + connection.close(); + } + } + + private InternalCache createCacheAndCreateJdbcMapping(String cacheXmlTestName) + throws Exception { + String url = dbRule.getConnectionUrl().replaceAll("&", "&"); + System.setProperty("TestDataSourceUrl", url); + InternalCache cache = + (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0") + .set("cache-xml-file", getXmlFileForTest(cacheXmlTestName)) + .create(); + return cache; + } + + private InternalCache createCacheAndCreateJdbcMappingWithNonSerializedClass( + String cacheXmlTestName) throws Exception { + return createCacheAndCreateJdbcMapping(cacheXmlTestName); + } + + private InternalCache createCacheAndCreateJdbcMappingWithWrongDataSource( + String cacheXmlTestName) throws Exception { + System.setProperty("TestDataSourceUrl", "jdbc:mysql://localhost/test"); + InternalCache cache = + (InternalCache) new CacheFactory().set("locators", "").set("mcast-port", "0") + .set("cache-xml-file", getXmlFileForTest(cacheXmlTestName)) + .create(); + return cache; + } + + private InternalCache createCacheAndCreateJdbcMappingWithWrongPdxName(String cacheXmlTestName) Review comment: This is method implementation is exactly the same as `createCacheAndCreateJdbcMapping()`. The only difference is the method name. So how about just using `createCacheAndCreateJdbcMapping()`? ########## File path: geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/xml/RegionMappingConfiguration.java ########## @@ -62,4 +96,159 @@ private void createRegionMapping(JdbcConnectorService service, throw new InternalGemFireException(e); } } + + protected List<FieldMapping> createDefaultFieldMapping(RegionMapping regionMapping, + PdxType pdxType) { + DataSource dataSource = getDataSource(regionMapping.getDataSourceName()); + if (dataSource == null) { + throw new JdbcConnectorException("No datasource \"" + regionMapping.getDataSourceName() + + "\" found when creating default field mapping"); + } + TableMetaDataManager manager = getTableMetaDataManager(); + try (Connection connection = dataSource.getConnection()) { + TableMetaDataView tableMetaData = manager.getTableMetaDataView(connection, regionMapping); + return createDefaultFieldMapping(regionMapping, pdxType, tableMetaData); + } catch (SQLException e) { + throw JdbcConnectorException.createException(e); + } + } + + private List<FieldMapping> createDefaultFieldMapping(RegionMapping regionMapping, Review comment: The `regionMapping` argument is not used, and can be removed. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Omitting field-mapping tag of cache.xml when using Simple JDBC Connector > ------------------------------------------------------------------------ > > Key: GEODE-8626 > URL: https://issues.apache.org/jira/browse/GEODE-8626 > Project: Geode > Issue Type: Improvement > Components: jdbc > Reporter: Masaki Yamakawa > Priority: Minor > Labels: pull-request-available > > When configuring Simple JDBC Connector with gfsh, I don't need to create > field-mapping, the default field-mapping will be created from pdx and table > meta data. > On the other hand, when using cache.xml(cluster.xml), pdx and table meta data > cannot be used, and field-mapping must be described in cache.xml. > I would like to create field-mapping defaults based on pdx and table meta > data when using cache.xml. > If field-mapping is specified in cache.xml, the xml setting has priority, and > only if there are no field-mapping tags. > cache.xml will be as follows: > {code:java} > <region name="Region1" refid="REPLICATE"> > <jdbc:mapping > data-source="TestDataSource" > table="employees" > pdx-name="org.apache.geode.connectors.jdbc.Employee" > ids="id"> > <!-- no need to jdbc:field-mapping tag > <jdbc:field-mapping pdx-name="id" pdx-type="STRING" jdbc-name="id" > jdbc-type="VARCHAR" jdbc-nullable="false"/> > <jdbc:field-mapping pdx-name="name" pdx-type="STRING" > jdbc-name="name" jdbc-type="VARCHAR" jdbc-nullable="true"/> > <jdbc:field-mapping pdx-name="age" pdx-type="INT" jdbc-name="age" > jdbc-type="INTEGER" jdbc-nullable="true"/> > --> > </jdbc:mapping> > </region> > {code} -- This message was sent by Atlassian Jira (v8.3.4#803005)