Repository: apache/incubator-fluo
Pull request #776 (2016-09-16 20:23:36)

removed default methods from interfaces #770 #771 #772


Patch:
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/AbstractSnapshotBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractSnapshotBase.java
new file mode 100644
index 00000000..30b325ac
--- /dev/null
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractSnapshotBase.java
@@ -0,0 +1,102 @@
+/*
+ * 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.fluo.api.client;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.data.RowColumn;
+
+/**
+ * This class provides default implementations for many of the classes in SnapshotBase. It exists to
+ * make implementing SnapshotBase easier.
+ */
+
+public abstract class AbstractSnapshotBase implements SnapshotBase {
+
+  public Bytes get(Bytes row, Column column, Bytes defaultValue) {
+    Bytes ret = get(row, column);
+    if (ret == null) {
+      return defaultValue;
+    }
+
+    return ret;
+  }
+
+  public Map<Column, Bytes> get(Bytes row, Column... columns) {
+    return get(row, ImmutableSet.copyOf(columns));
+  }
+
+  public Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Column... columns) {
+    return get(rows, ImmutableSet.copyOf(columns));
+  }
+
+  public Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
+    Map<RowColumn, Bytes> bytesMap = get(rowColumns);
+    return Maps.transformValues(bytesMap, b -> b.toString());
+  }
+
+  public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
+      Set<Column> columns) {
+    Map<Bytes, Map<Column, Bytes>> rcvs =
+        get(Collections2.transform(rows, s -> Bytes.of(s)), columns);
+    Map<String, Map<Column, String>> ret = new HashMap<>(rcvs.size());
+
+    for (Entry<Bytes, Map<Column, Bytes>> entry : rcvs.entrySet()) {
+      ret.put(entry.getKey().toString(), Maps.transformValues(entry.getValue(), b -> b.toString()));
+    }
+    return ret;
+  }
+
+  public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
+      Column... columns) {
+    return gets(rows, ImmutableSet.copyOf(columns));
+  }
+
+  public String gets(CharSequence row, Column column) {
+    Bytes val = get(Bytes.of(row), column);
+    if (val == null) {
+      return null;
+    }
+    return val.toString();
+  }
+
+  public String gets(CharSequence row, Column column, String defaultValue) {
+    Bytes val = get(Bytes.of(row), column);
+    if (val == null) {
+      return defaultValue;
+    }
+
+    return val.toString();
+  }
+
+  public Map<Column, String> gets(CharSequence row, Set<Column> columns) {
+    Map<Column, Bytes> values = get(Bytes.of(row), columns);
+    return Maps.transformValues(values, b -> b.toString());
+  }
+
+  public Map<Column, String> gets(CharSequence row, Column... columns) {
+    return gets(row, ImmutableSet.copyOf(columns));
+  }
+}
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/AbstractTransactionBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractTransactionBase.java
new file mode 100644
index 00000000..0ffd6503
--- /dev/null
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/AbstractTransactionBase.java
@@ -0,0 +1,41 @@
+/*
+ * 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.fluo.api.client;
+
+import org.apache.fluo.api.data.Bytes;
+import org.apache.fluo.api.data.Column;
+import org.apache.fluo.api.exceptions.AlreadySetException;
+
+/**
+ * This class provides default implementations for many of the methods in TransactionBase. It exists
+ * to make implementing TransactionBase easier.
+ */
+
+public abstract class AbstractTransactionBase extends AbstractSnapshotBase implements
+    TransactionBase {
+
+  public void delete(CharSequence row, Column col) {
+    delete(Bytes.of(row), col);
+  }
+
+  public void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException {
+    set(Bytes.of(row), col, Bytes.of(value));
+  }
+
+  public void setWeakNotification(CharSequence row, Column col) {
+    setWeakNotification(Bytes.of(row), col);
+  }
+}
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
index 723b9c7d..ac8bc40a 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
@@ -16,14 +16,9 @@
 package org.apache.fluo.api.client;
 
 import java.util.Collection;
-import java.util.HashMap;
 import java.util.Map;
 import java.util.Set;
-import java.util.Map.Entry;
 
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
 import org.apache.fluo.api.client.scanner.ScannerBuilder;
 import org.apache.fluo.api.data.Bytes;
 import org.apache.fluo.api.data.Column;
@@ -34,6 +29,7 @@ import org.apache.fluo.api.data.Span;
  * Allows users to read from a Fluo table at a certain point in time
  *
  * @since 1.0.0
+ * @see AbstractSnapshotBase
  */
 public interface SnapshotBase {
 
@@ -49,14 +45,7 @@ public interface SnapshotBase {
    * 
    * @param defaultValue this will be returned if row+columns does not exists
    */
-  default Bytes get(Bytes row, Column column, Bytes defaultValue) {
-    Bytes ret = get(row, column);
-    if (ret == null) {
-      return defaultValue;
-    }
-
-    return ret;
-  }
+  Bytes get(Bytes row, Column column, Bytes defaultValue);
 
   /**
    * Given a row and set of {@link Column}s, retrieves a map that contains the values at those
@@ -68,9 +57,7 @@ public interface SnapshotBase {
    * Given a row and list of {@link Column}s, retrieves a map that contains the values at those
    * {@link Column}s. Only columns that exist will be returned in map.
    */
-  default Map<Column, Bytes> get(Bytes row, Column... columns) {
-    return get(row, ImmutableSet.copyOf(columns));
-  }
+  Map<Column, Bytes> get(Bytes row, Column... columns);
 
   /**
    * Given a collection of rows and set of {@link Column}s, retrieves a map that contains the values
@@ -83,9 +70,7 @@ public interface SnapshotBase {
    * values at those rows and {@link Column}s. Only rows and columns that exists will be returned in
    * map.
    */
-  default Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Column... columns) {
-    return get(rows, ImmutableSet.copyOf(columns));
-  }
+  Map<Bytes, Map<Column, Bytes>> get(Collection<Bytes> rows, Column... columns);
 
 
   /**
@@ -137,77 +122,43 @@ public interface SnapshotBase {
    * Wrapper for {@link #get(Collection)} that uses Strings. All strings are encoded and decoded
    * using UTF-8.
    */
-  default Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
-    Map<RowColumn, Bytes> bytesMap = get(rowColumns);
-    return Maps.transformValues(bytesMap, b -> b.toString());
-  }
+  Map<RowColumn, String> gets(Collection<RowColumn> rowColumns);
 
   /**
    * Wrapper for {@link #get(Collection, Set)} that uses Strings. All strings are encoded and
    * decoded using UTF-8.
    */
-  default Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
-      Set<Column> columns) {
-    Map<Bytes, Map<Column, Bytes>> rcvs =
-        get(Collections2.transform(rows, s -> Bytes.of(s)), columns);
-    Map<String, Map<Column, String>> ret = new HashMap<>(rcvs.size());
-
-    for (Entry<Bytes, Map<Column, Bytes>> entry : rcvs.entrySet()) {
-      ret.put(entry.getKey().toString(), Maps.transformValues(entry.getValue(), b -> b.toString()));
-    }
-    return ret;
-  }
+  Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows, Set<Column> columns);
 
   /**
    * Wrapper for {@link #get(Collection, Set)} that uses Strings. All strings are encoded and
    * decoded using UTF-8.
    */
-  default Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows,
-      Column... columns) {
-    return gets(rows, ImmutableSet.copyOf(columns));
-  }
+  Map<String, Map<Column, String>> gets(Collection<? extends CharSequence> rows, Column... columns);
 
   /**
    * Wrapper for {@link #get(Bytes, Column)} that uses Strings. All strings are encoded and decoded
    * using UTF-8.
    */
-  default String gets(CharSequence row, Column column) {
-    Bytes val = get(Bytes.of(row), column);
-    if (val == null) {
-      return null;
-    }
-    return val.toString();
-  }
+  String gets(CharSequence row, Column column);
 
   /**
    * Wrapper for {@link #get(Bytes, Column, Bytes)} that uses Strings. All strings are encoded and
    * decoded using UTF-8.
    */
-  default String gets(CharSequence row, Column column, String defaultValue) {
-    Bytes val = get(Bytes.of(row), column);
-    if (val == null) {
-      return defaultValue;
-    }
-
-    return val.toString();
-  }
+  String gets(CharSequence row, Column column, String defaultValue);
 
   /**
    * Wrapper for {@link #get(Bytes, Set)} that uses Strings. All strings are encoded and decoded
    * using UTF-8.
    */
-  default Map<Column, String> gets(CharSequence row, Set<Column> columns) {
-    Map<Column, Bytes> values = get(Bytes.of(row), columns);
-    return Maps.transformValues(values, b -> b.toString());
-  }
+  Map<Column, String> gets(CharSequence row, Set<Column> columns);
 
   /**
    * Wrapper for {@link #get(Bytes, Set)} that uses Strings. All strings are encoded and decoded
    * using UTF-8.
    */
-  default Map<Column, String> gets(CharSequence row, Column... columns) {
-    return gets(row, ImmutableSet.copyOf(columns));
-  }
+  Map<Column, String> gets(CharSequence row, Column... columns);
 
   /**
    * @return transactions start timestamp allocated from Oracle.
diff --git a/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java b/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
index 57a0e1e3..06303b66 100644
--- a/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
+++ b/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
@@ -24,6 +24,7 @@ import org.apache.fluo.api.exceptions.AlreadySetException;
  * {@link SnapshotBase} to include methods for writing to Fluo.
  *
  * @since 1.0.0
+ * @see AbstractTransactionBase
  */
 public interface TransactionBase extends SnapshotBase {
 
@@ -36,9 +37,7 @@ public interface TransactionBase extends SnapshotBase {
    * Wrapper for {@link #delete(Bytes, Column)} that uses Strings. All String are encoded using
    * UTF-8.
    */
-  default void delete(CharSequence row, Column col) {
-    delete(Bytes.of(row), col);
-  }
+  void delete(CharSequence row, Column col);
 
   /**
    * Sets a value (in {@link Bytes}) at the given row and {@link Column}
@@ -49,9 +48,7 @@ public interface TransactionBase extends SnapshotBase {
    * Wrapper for {@link #set(Bytes, Column, Bytes)} that uses Strings. All String are encoded using
    * UTF-8.
    */
-  default void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException {
-    set(Bytes.of(row), col, Bytes.of(value));
-  }
+  void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException;
 
   /**
    * Sets a weak notification at the given row and {@link Column}
@@ -62,7 +59,5 @@ public interface TransactionBase extends SnapshotBase {
    * Wrapper for {@link #setWeakNotification(Bytes, Column)} that uses Strings. All String are
    * encoded using UTF-8.
    */
-  default void setWeakNotification(CharSequence row, Column col) {
-    setWeakNotification(Bytes.of(row), col);
-  }
+  void setWeakNotification(CharSequence row, Column col);
 }
diff --git a/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java b/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
index 2591a57e..441517a9 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
@@ -53,6 +53,7 @@ import org.apache.fluo.accumulo.iterators.PrewriteIterator;
 import org.apache.fluo.accumulo.util.ColumnConstants;
 import org.apache.fluo.accumulo.values.DelLockValue;
 import org.apache.fluo.accumulo.values.LockValue;
+import org.apache.fluo.api.client.AbstractTransactionBase;
 import org.apache.fluo.api.client.Snapshot;
 import org.apache.fluo.api.client.scanner.ScannerBuilder;
 import org.apache.fluo.api.data.Bytes;
@@ -81,7 +82,7 @@ import org.apache.fluo.core.util.SpanUtil;
 /**
  * Transaction implementation
  */
-public class TransactionImpl implements AsyncTransaction, Snapshot {
+public class TransactionImpl extends AbstractTransactionBase implements AsyncTransaction, Snapshot {
 
   public static final byte[] EMPTY = new byte[0];
   public static final Bytes EMPTY_BS = Bytes.of(EMPTY);
diff --git a/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java b/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
index 6c52c9a2..f9298de8 100644
--- a/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
+++ b/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.Set;
 
 import com.google.common.collect.Iterators;
+import org.apache.fluo.api.client.AbstractTransactionBase;
 import org.apache.fluo.api.client.Snapshot;
 import org.apache.fluo.api.client.scanner.ScannerBuilder;
 import org.apache.fluo.api.config.FluoConfiguration;
@@ -36,7 +37,8 @@ import org.apache.fluo.core.util.Hex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class TracingTransaction implements AsyncTransaction, Snapshot {
+public class TracingTransaction extends AbstractTransactionBase implements AsyncTransaction,
+    Snapshot {
 
   private static final Logger log = LoggerFactory.getLogger(FluoConfiguration.TRANSACTION_PREFIX);
   private static final Logger collisionLog = LoggerFactory


Test patch:
diff --git a/modules/api/src/test/java/org/apache/fluo/api/client/TestDefaultTransactionMethods.java b/modules/api/src/test/java/org/apache/fluo/api/client/AbstractTransactionBaseTest.java
similarity index 98%
rename from modules/api/src/test/java/org/apache/fluo/api/client/TestDefaultTransactionMethods.java
rename to modules/api/src/test/java/org/apache/fluo/api/client/AbstractTransactionBaseTest.java
index bbe894ab..6e082314 100644
--- a/modules/api/src/test/java/org/apache/fluo/api/client/TestDefaultTransactionMethods.java
+++ b/modules/api/src/test/java/org/apache/fluo/api/client/AbstractTransactionBaseTest.java
@@ -34,9 +34,9 @@ import org.apache.fluo.api.exceptions.CommitException;
 import org.junit.Assert;
 import org.junit.Test;
 
-public class TestDefaultTransactionMethods {
+public class AbstractTransactionBaseTest {
 
-  private static class MockTransaction implements Transaction {
+  private static class MockTransaction extends AbstractTransactionBase implements Transaction {
 
     public Set<RowColumnValue> sets = new HashSet<>();
     public Set<RowColumn> deletes = new HashSet<>();
diff --git a/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java b/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
index 6a214c89..ac2a774a 100644
--- a/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
+++ b/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
@@ -30,6 +30,7 @@ import org.apache.accumulo.core.data.Key;
 import org.apache.fluo.accumulo.iterators.NotificationIterator;
 import org.apache.fluo.accumulo.util.ColumnConstants;
 import org.apache.fluo.accumulo.util.NotificationUtil;
+import org.apache.fluo.api.client.AbstractTransactionBase;
 import org.apache.fluo.api.client.TransactionBase;
 import org.apache.fluo.api.client.scanner.ScannerBuilder;
 import org.apache.fluo.api.data.Bytes;
@@ -50,7 +51,7 @@ import org.apache.fluo.core.util.ByteUtil;
 import org.apache.fluo.core.util.SpanUtil;
 import org.apache.hadoop.io.Text;
 
-public class TestTransaction implements TransactionBase {
+public class TestTransaction extends AbstractTransactionBase implements TransactionBase {
 
   private TransactionImpl tx;
   private Environment env;