carlosrmng commented on a change in pull request #177: [GORA-527] Implement a 
data store for redis
URL: https://github.com/apache/gora/pull/177#discussion_r312648541
 
 

 ##########
 File path: gora-redis/src/main/java/org/apache/gora/redis/store/RedisStore.java
 ##########
 @@ -0,0 +1,519 @@
+/**
+ * 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.redis.store;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.stream.Collectors;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import org.apache.avro.Schema;
+import org.apache.commons.io.IOUtils;
+import org.apache.gora.persistency.impl.PersistentBase;
+import org.apache.gora.query.PartitionQuery;
+import org.apache.gora.query.Query;
+import org.apache.gora.query.Result;
+import org.apache.gora.query.impl.PartitionQueryImpl;
+import org.apache.gora.redis.query.RedisQuery;
+import org.apache.gora.redis.query.RedisResult;
+import org.apache.gora.redis.util.DatumHandler;
+import org.apache.gora.redis.util.ServerMode;
+import org.apache.gora.redis.util.StorageMode;
+import org.apache.gora.store.impl.DataStoreBase;
+import org.apache.gora.util.GoraException;
+import org.redisson.Redisson;
+import org.redisson.api.RBatch;
+import org.redisson.api.RBucket;
+import org.redisson.api.RBucketAsync;
+import org.redisson.api.RFuture;
+import org.redisson.api.RLexSortedSet;
+import org.redisson.api.RLexSortedSetAsync;
+import org.redisson.api.RList;
+import org.redisson.api.RListAsync;
+import org.redisson.api.RMap;
+import org.redisson.api.RMapAsync;
+import org.redisson.api.RedissonClient;
+import org.redisson.config.Config;
+import org.redisson.config.ReadMode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * Implementation of a Redis data store to be used by gora.
+ *
+ * @param <K> class to be used for the key
+ * @param <T> class to be persisted within the store
+ */
+public class RedisStore<K, T extends PersistentBase> extends DataStoreBase<K, 
T> {
+
+  //Redis constants
+  private static final String FIELD_SEPARATOR = ".";
+  private static final String WILDCARD = "*";
+  private static final String INDEX = "index";
+  private static final String START_TAG = "{";
+  private static final String END_TAG = "}";
+  private static final String PREFIX = "redis://";
+
+  protected static final String MOCK_PROPERTY = "redis.mock";
+  protected static final String INSTANCE_NAME_PROPERTY = "redis.instance";
+  protected static final String ZOOKEEPERS_NAME_PROPERTY = "redis.zookeepers";
+  protected static final String USERNAME_PROPERTY = "redis.user";
+  protected static final String PASSWORD_PROPERTY = "redis.password";
+  protected static final String PARSE_MAPPING_FILE_KEY = 
"gora.redis.mapping.file";
+  protected static final String DEFAULT_MAPPING_FILE = 
"gora-redis-mapping.xml";
+  protected static final String XML_MAPPING_DEFINITION = "gora.mapping";
+  private RedissonClient redisInstance;
+  private RedisMapping mapping;
+  public static final Logger LOG = LoggerFactory.getLogger(RedisStore.class);
+
+  private static final DatumHandler handler = new DatumHandler();
+  private StorageMode mode;
+
+  /**
+   * Initialize the data store by reading the credentials, setting the client's
+   * properties up and reading the mapping file. Initialize is called when then
+   * the call to {@link org.apache.gora.store.DataStoreFactory#createDataStore}
+   * is made.
+   *
+   * @param keyClass
+   * @param persistentClass
+   * @param properties
+   */
+  @Override
+  public void initialize(Class<K> keyClass, Class<T> persistentClass, 
Properties properties) throws GoraException {
+    try {
+      super.initialize(keyClass, persistentClass, properties);
+
+      InputStream mappingStream;
+      if (properties.containsKey(XML_MAPPING_DEFINITION)) {
+        if (LOG.isTraceEnabled()) {
+          LOG.trace(XML_MAPPING_DEFINITION + " = " + 
properties.getProperty(XML_MAPPING_DEFINITION));
 
 Review comment:
   Use parameterized logging

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


With regards,
Apache Git Services

Reply via email to