[ 
https://issues.apache.org/jira/browse/GORA-650?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17344730#comment-17344730
 ] 

ASF GitHub Bot commented on GORA-650:
-------------------------------------

kamaci commented on a change in pull request #218:
URL: https://github.com/apache/gora/pull/218#discussion_r632675364



##########
File path: 
gora-arangodb/src/main/java/org/apache/gora/arangodb/store/ArangoDBMappingBuilder.java
##########
@@ -0,0 +1,119 @@
+/**
+ * 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.gora.arangodb.store;
+
+import org.apache.gora.persistency.impl.PersistentBase;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility builder for create ArangoDB mapping from gora-arango-mapping.xml.
+ */
+public class ArangoDBMappingBuilder<K, T extends PersistentBase> {
+
+  public static final String ATT_NAME = "name";
+  public static final String ATT_TYPE = "type";
+  public static final String TAG_CLASS = "class";
+  public static final String ATT_KEYCLASS = "keyClass";
+  public static final String ATT_DOCUMENT = "document";
+  public static final String TAG_FIELD = "field";
+  public static final String ATT_FIELD = "docfield";
+  public static final Logger log = 
LoggerFactory.getLogger(ArangoDBMappingBuilder.class);
+
+  private final ArangoDBStore<K, T> dataStore;
+
+  private ArangoDBMapping mapping;
+
+  public ArangoDBMappingBuilder(final ArangoDBStore<K, T> store) {
+    this.dataStore = store;
+    this.mapping = new ArangoDBMapping();
+  }
+
+  public ArangoDBMapping build() {
+    if (mapping.getDocumentClass() == null)
+      throw new IllegalStateException("Document Class is not specified.");
+    return mapping;
+  }
+
+  protected ArangoDBMappingBuilder fromFile(String uri) throws IOException {
+    try {
+      SAXBuilder saxBuilder = new SAXBuilder();
+      InputStream is = getClass().getResourceAsStream(uri);
+      if (is == null) {
+        String msg = "Unable to load the mapping from classpath resource '" + 
uri
+                + "' Re-trying local from local file system location.";
+        log.warn(msg);
+        is = new FileInputStream(uri);
+      }
+      Document doc = saxBuilder.build(is);
+      Element root = doc.getRootElement();
+      List<Element> classElements = root.getChildren(TAG_CLASS);
+      for (Element classElement : classElements) {
+        final Class<T> persistentClass = dataStore.getPersistentClass();
+        final Class<K> keyClass = dataStore.getKeyClass();
+        if (matchesKeyClassWithMapping(keyClass, classElement)
+                && matchesPersistentClassWithMapping(persistentClass, 
classElement)) {
+          loadPersistentClass(classElement, persistentClass);
+          break;
+        }
+      }
+    } catch (IOException ex) {
+      throw ex;
+    } catch (Exception ex) {

Review comment:
       Instead of this catch `Exception` and throw `IOException`.
   
   On the other hand, what is the reason to wrap `Exception` as `IOException`?




-- 
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


> Add datastore for ArangoDB
> --------------------------
>
>                 Key: GORA-650
>                 URL: https://issues.apache.org/jira/browse/GORA-650
>             Project: Apache Gora
>          Issue Type: New Feature
>    Affects Versions: 0.9
>            Reporter: Kevin Ratnasekera
>            Priority: Major
>              Labels: gsoc2020
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> May be we should consider extending our multimodal datastore support with 
> ArangoDB. [1] 
> [1] https://www.arangodb.com/why-arangodb/multi-model/



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to