gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djkevi...@apache.org
Subject [17/32] gora git commit: Refactor code
Date Thu, 27 Jul 2017 18:45:43 GMT
Refactor code


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/3b44781f
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/3b44781f
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/3b44781f

Branch: refs/heads/master
Commit: 3b44781f9514988a31e2748416b1cb7015e2767a
Parents: d3a44b2
Author: nishadi <ndimeshi@gmail.com>
Authored: Thu Jun 29 07:01:58 2017 +0530
Committer: nishadi <ndimeshi@gmail.com>
Committed: Thu Jun 29 07:01:58 2017 +0530

----------------------------------------------------------------------
 .../org/apache/gora/aerospike/package-info.java |  2 +-
 .../store/AerospikeMappingBuilder.java          | 82 +++++++++++---------
 .../aerospike/store/AerospikeParameters.java    | 17 ++--
 .../gora/aerospike/store/AerospikeStore.java    | 40 ++++++----
 .../gora/aerospike/store/package-info.java      |  2 +-
 .../gora/aerospike/GoraAerospikeTestDriver.java |  4 +-
 6 files changed, 82 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java b/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
index 0dbf8dd..7c1eae4 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/package-info.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.

http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
index ca51c5d..f24c08f 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeMappingBuilder.java
@@ -39,7 +39,7 @@ public class AerospikeMappingBuilder {
 
   private static final Logger LOG = LoggerFactory.getLogger(AerospikeMappingBuilder.class);
 
-  private AerospikeMapping aerospikeMapping;
+  private final AerospikeMapping aerospikeMapping;
 
   public AerospikeMappingBuilder() {
     this.aerospikeMapping = new AerospikeMapping();
@@ -81,28 +81,35 @@ public class AerospikeMappingBuilder {
         if (policy != null) {
           if (policy.equals("write")) {
             WritePolicy writePolicy = new WritePolicy();
-            if (policyElement.getAttributeValue("gen") != null)
+            if (policyElement.getAttributeValue("gen") != null) {
               writePolicy.generationPolicy = getGenerationPolicyMapping(
                       policyElement.getAttributeValue("gen").toUpperCase(Locale.getDefault()));
-            if (policyElement.getAttributeValue("exists") != null)
+            }
+            if (policyElement.getAttributeValue("exists") != null) {
               writePolicy.recordExistsAction = getRecordExistsAction(
                       policyElement.getAttributeValue("exists").toUpperCase(Locale.getDefault()));
-            if (policyElement.getAttributeValue("key") != null)
+            }
+            if (policyElement.getAttributeValue("key") != null) {
               writePolicy.sendKey = getKeyUsagePolicy(
                       policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
-            if (policyElement.getAttributeValue("retry") != null)
+            }
+            if (policyElement.getAttributeValue("retry") != null) {
               writePolicy.retryOnTimeout = getRetryOnTimeoutPolicy(
                       policyElement.getAttributeValue("retry").toUpperCase(Locale.getDefault()));
-            if (policyElement.getAttributeValue("timeout") != null)
+            }
+            if (policyElement.getAttributeValue("timeout") != null) {
               writePolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+            }
             aerospikeMapping.setWritePolicy(writePolicy);
           } else if (policy.equals("read")) {
             Policy readPolicy = new Policy();
-            if (policyElement.getAttributeValue("key") != null)
+            if (policyElement.getAttributeValue("key") != null) {
               readPolicy.sendKey = getKeyUsagePolicy(
                       policyElement.getAttributeValue("key").toUpperCase(Locale.getDefault()));
-            if (policyElement.getAttributeValue("timeout") != null)
+            }
+            if (policyElement.getAttributeValue("timeout") != null) {
               readPolicy.timeout = getTimeoutValue(policyElement.getAttributeValue("timeout"));
+            }
             aerospikeMapping.setReadPolicy(readPolicy);
           }
         }
@@ -116,36 +123,36 @@ public class AerospikeMappingBuilder {
         String mappingKeyClass = classElement.getAttributeValue("keyClass");
         String mappingClassName = classElement.getAttributeValue("name");
 
-        if (mappingKeyClass != null && mappingClassName != null) {
-          if (mappingKeyClass.equals(keyClass.getCanonicalName()) && mappingClassName
-                  .equals(persistentClass.getCanonicalName())) {
+        if (mappingKeyClass != null && mappingClassName != null && mappingKeyClass
+                .equals(keyClass.getCanonicalName()) && mappingClassName
+                .equals(persistentClass.getCanonicalName())) {
 
-            persistentClassAndKeyClassMatches = true;
+          persistentClassAndKeyClassMatches = true;
 
-            List<Element> fields = classElement.getChildren("field");
-            Map<String, String> binMapping = new HashMap<>();
-            for (Element field : fields) {
-              String fieldName = field.getAttributeValue("name");
-              String binName = field.getAttributeValue("bin");
-              if (fieldName != null && binName != null)
-                binMapping.put(fieldName, binName);
+          List<Element> fields = classElement.getChildren("field");
+          Map<String, String> binMapping = new HashMap<>();
+          for (Element field : fields) {
+            String fieldName = field.getAttributeValue("name");
+            String binName = field.getAttributeValue("bin");
+            if (fieldName != null && binName != null) {
+              binMapping.put(fieldName, binName);
             }
-            aerospikeMapping.setBinMapping(binMapping);
-
-            String nameSpace = classElement.getAttributeValue("namespace");
-            if (nameSpace == null || nameSpace.isEmpty()) {
-              LOG.error("Gora-aerospike-mapping does not include the relevant namespace for
the "
-                      + "{} class", mappingClassName);
-              throw new ConfigurationException(
-                      "Gora-aerospike-mapping does not include the relevant namespace for
the "
-                              + mappingClassName + "class");
-            }
-            aerospikeMapping.setNamespace(nameSpace);
+          }
+          aerospikeMapping.setBinMapping(binMapping);
+
+          String nameSpace = classElement.getAttributeValue("namespace");
+          if (nameSpace == null || nameSpace.isEmpty()) {
+            LOG.error("Gora-aerospike-mapping does not include the relevant namespace for
the "
+                    + "{} class", mappingClassName);
+            throw new ConfigurationException(
+                    "Gora-aerospike-mapping does not include the relevant namespace for the
"
+                            + mappingClassName + "class");
+          }
+          aerospikeMapping.setNamespace(nameSpace);
 
-            String set = classElement.getAttributeValue("set");
-            if (set != null && !set.isEmpty()) {
-              aerospikeMapping.setSet(set);
-            }
+          String set = classElement.getAttributeValue("set");
+          if (set != null && !set.isEmpty()) {
+            aerospikeMapping.setSet(set);
           }
         }
       }
@@ -262,8 +269,9 @@ public class AerospikeMappingBuilder {
    */
   private boolean getRetryOnTimeoutPolicy(String retry) {
 
-    if (retry == null)
+    if (retry == null) {
       return false;
+    }
 
     boolean retryOnTimeout;
     switch (retry) {
@@ -289,8 +297,9 @@ public class AerospikeMappingBuilder {
    */
   private int getTimeoutValue(String timeout) {
 
-    if (timeout == null)
+    if (timeout == null) {
       return 0;
+    }
     int timeoutInt = 0;
     try {
       timeoutInt = Integer.valueOf(timeout);
@@ -299,5 +308,4 @@ public class AerospikeMappingBuilder {
     }
     return timeoutInt;
   }
-
 }

http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
index 141808d..5cb91e2 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeParameters.java
@@ -41,7 +41,7 @@ public class AerospikeParameters {
   // Property names
   private static final String AS_SERVER_IP = "server.ip";
 
-  private static final String AS_SERVER_port = "server.port";
+  private static final String AS_SERVER_PORT = "server.port";
 
   // Default property values
   private static final String DEFAULT_SERVER_IP = "localhost";
@@ -59,7 +59,7 @@ public class AerospikeParameters {
   public AerospikeParameters(AerospikeMapping aerospikeMapping, Properties properties) {
     this.aerospikeMapping = aerospikeMapping;
     this.host = properties.getProperty(AS_SERVER_IP, DEFAULT_SERVER_IP);
-    this.port = Integer.parseInt(properties.getProperty(AS_SERVER_port, DEFAULT_SERVER_PORT));
+    this.port = Integer.parseInt(properties.getProperty(AS_SERVER_PORT, DEFAULT_SERVER_PORT));
   }
 
   public String getHost() {
@@ -170,13 +170,10 @@ public class AerospikeParameters {
    * @param fields fields of the persistent class
    */
   public void validateServerBinConfiguration(Field[] fields) {
-    if (isSingleBinEnabled) {
-      if (fields.length != 1) {
-        LOG.error(
-                "Aerospike server is single bin enabled and cannot allow multiple bin operations");
-        throw new RuntimeException("Aerospike server is single bin enabled and cannot allow
"
-                + "multiple bin operations");
-      }
+    if (isSingleBinEnabled && fields.length != 1) {
+      LOG.error("Aerospike server is single bin enabled and cannot allow multiple bin operations");
+      throw new RuntimeException("Aerospike server is single bin enabled and cannot allow
"
+              + "multiple bin operations");
     }
   }
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
index 66de783..01fdd93 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/AerospikeStore.java
@@ -280,9 +280,10 @@ public class AerospikeStore<K, T extends PersistentBase> extends
DataStoreBase<K
       case MAP:
         Map<Object, Object> newMap = new HashMap<>();
         Map<?, ?> fieldMap = (Map<?, ?>) object;
-        for (Object key : fieldMap.keySet()) {
-          newMap.put(key.toString(),
-                  getSerializableValue(fieldMap.get(key), schema.getValueType()));
+
+        for (Map.Entry<?, ?> entry : fieldMap.entrySet()) {
+          newMap.put(entry.getKey().toString(),
+                  getSerializableValue(fieldMap.get(entry.getKey()), schema.getValueType()));
         }
         value = Value.get(newMap);
         break;
@@ -444,28 +445,39 @@ public class AerospikeStore<K, T extends PersistentBase> extends
DataStoreBase<K
     int unionSchemaPos = 0;
     for (Schema currentSchema : unionSchema.getTypes()) {
       Schema.Type schemaType = currentSchema.getType();
-      if (instanceValue instanceof CharSequence && schemaType.equals(Schema.Type.STRING))
+      if (instanceValue instanceof CharSequence && schemaType.equals(Schema.Type.STRING))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof ByteBuffer && schemaType.equals(Schema.Type.BYTES))
+      }
+      if (instanceValue instanceof ByteBuffer && schemaType.equals(Schema.Type.BYTES))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof byte[] && schemaType.equals(Schema.Type.BYTES))
+      }
+      if (instanceValue instanceof byte[] && schemaType.equals(Schema.Type.BYTES))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof Integer && schemaType.equals(Schema.Type.INT))
+      }
+      if (instanceValue instanceof Integer && schemaType.equals(Schema.Type.INT))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof Long && schemaType.equals(Schema.Type.LONG))
+      }
+      if (instanceValue instanceof Long && schemaType.equals(Schema.Type.LONG)) {
         return unionSchemaPos;
-      else if (instanceValue instanceof Double && schemaType.equals(Schema.Type.DOUBLE))
+      }
+      if (instanceValue instanceof Double && schemaType.equals(Schema.Type.DOUBLE))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof Float && schemaType.equals(Schema.Type.FLOAT))
+      }
+      if (instanceValue instanceof Float && schemaType.equals(Schema.Type.FLOAT))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof Boolean && schemaType.equals(Schema.Type.BOOLEAN))
+      }
+      if (instanceValue instanceof Boolean && schemaType.equals(Schema.Type.BOOLEAN))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof Map && schemaType.equals(Schema.Type.MAP))
+      }
+      if (instanceValue instanceof Map && schemaType.equals(Schema.Type.MAP)) {
         return unionSchemaPos;
-      else if (instanceValue instanceof List && schemaType.equals(Schema.Type.ARRAY))
+      }
+      if (instanceValue instanceof List && schemaType.equals(Schema.Type.ARRAY))
{
         return unionSchemaPos;
-      else if (instanceValue instanceof Persistent && schemaType.equals(Schema.Type.RECORD))
+      }
+      if (instanceValue instanceof Persistent && schemaType.equals(Schema.Type.RECORD))
{
         return unionSchemaPos;
+      }
       unionSchemaPos++;
     }
     return 0;

http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
index e92fa51..30f72b3 100644
--- a/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
+++ b/gora-aerospike/src/main/java/org/apache/gora/aerospike/store/package-info.java
@@ -1,4 +1,4 @@
-/**
+/*
  * 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.

http://git-wip-us.apache.org/repos/asf/gora/blob/3b44781f/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 10ef7a1..6c025e4 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -34,8 +34,8 @@ import java.util.Properties;
  */
 public class GoraAerospikeTestDriver extends GoraTestDriver {
 
-  private GenericContainer aerospikeContainer;
-  private Properties properties = DataStoreFactory.createProps();
+  private final GenericContainer aerospikeContainer;
+  private final Properties properties = DataStoreFactory.createProps();
 
   public GoraAerospikeTestDriver(GenericContainer aerospikeContainer) {
     super(AerospikeStore.class);


Mime
View raw message