This is an automated email from the ASF dual-hosted git repository.

madhawa pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/gora.git

commit e08524c5d5aaac9fd3e4ed42739c03e398d6fa8b
Author: LahiruJayasekara <mlpjayasek...@gmail.com>
AuthorDate: Sat May 11 01:50:44 2019 +0530

    Fix mapping file name access method in hbaseStore
---
 .../org/apache/gora/hbase/store/HBaseStore.java    | 28 ++++++++++------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git 
a/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java 
b/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java
index 518f6ac..d16700b 100644
--- a/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java
+++ b/gora-hbase/src/main/java/org/apache/gora/hbase/store/HBaseStore.java
@@ -139,20 +139,17 @@ public class HBaseStore<K, T extends PersistentBase> 
extends DataStoreBase<K, T>
 
     try {
       this.conf = HBaseConfiguration.create(getConf());
-      
-      InputStream mappingInputStream ;
-      // If there is a mapping definition in the Properties, use it.
-      if (properties.containsKey(XML_MAPPING_DEFINITION)) {
-        if (LOG.isTraceEnabled()) LOG.trace(XML_MAPPING_DEFINITION + " = " + 
properties.getProperty(XML_MAPPING_DEFINITION));  
-        mappingInputStream = 
IOUtils.toInputStream(properties.getProperty(XML_MAPPING_DEFINITION), 
(Charset)null) ;
-      }
-      // Otherwise use the configuration from de default file 
gora-hbase-mapping.xml or whatever
-      // configured in the key "gora.hbase.mapping.file"
-      else {
-        mappingInputStream = 
getClass().getClassLoader().getResourceAsStream(getConf().get(PARSE_MAPPING_FILE_KEY,
 DEFAULT_MAPPING_FILE)) ;
+
+      String mappingFile = DataStoreFactory.getMappingFile(properties, this,
+              DEFAULT_MAPPING_FILE);
+
+      // if there is no mapping.file property in gora.properties, then check
+      // configurations for mapping.file key
+      if (mappingFile.equals(DEFAULT_MAPPING_FILE)) {
+        mappingFile = getConf().get(PARSE_MAPPING_FILE_KEY, 
DEFAULT_MAPPING_FILE);
       }
       
-      mapping = readMapping(mappingInputStream);
+      mapping = readMapping(mappingFile);
       filterUtil = new HBaseFilterUtil<>(this.conf);
     } catch (FileNotFoundException ex) {
       throw new GoraException("Mapping file '" + 
getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE) + "' not 
found.",ex);
@@ -819,13 +816,14 @@ public class HBaseStore<K, T extends PersistentBase> 
extends DataStoreBase<K, T>
   }
 
   @SuppressWarnings("unchecked")
-  private HBaseMapping readMapping(InputStream mappingStream) throws 
IOException {
+  private HBaseMapping readMapping(String filename) throws IOException {
 
     HBaseMappingBuilder mappingBuilder = new HBaseMappingBuilder();
 
     try {
       SAXBuilder builder = new SAXBuilder();
-      Document doc = builder.build(mappingStream);
+      Document doc = builder.build(getClass().getClassLoader()
+              .getResourceAsStream(filename));
       Element root = doc.getRootElement();
 
       List<Element> tableElements = root.getChildren("table");
@@ -892,7 +890,7 @@ public class HBaseStore<K, T extends PersistentBase> 
extends DataStoreBase<K, T>
       LOG.error("Error while trying to read the mapping file {}. "
               + "Expected to be in the classpath "
               + "(ClassLoader#getResource(java.lang.String)).",
-              mappingStream) ;
+              filename) ;
       LOG.error("Actual classpath = {}", Arrays.asList(
           ((URLClassLoader) getClass().getClassLoader()).getURLs()));
       throw ex ;

Reply via email to