gora-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [gora] kamaci commented on a change in pull request #218: [GORA-650] [WIP] Add initial ArangoDB datastore
Date Fri, 14 May 2021 17:11:35 GMT

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:
users@infra.apache.org



Mime
View raw message