fluo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject [2/6] incubator-fluo git commit: fixes #771 added default string tx methods
Date Fri, 16 Sep 2016 18:25:53 GMT
fixes #771 added default string tx methods


Project: http://git-wip-us.apache.org/repos/asf/incubator-fluo/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-fluo/commit/20d12a8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-fluo/tree/20d12a8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-fluo/diff/20d12a8a

Branch: refs/heads/master
Commit: 20d12a8ad24194295ae3b6df70f0bea554cb9f21
Parents: 7fa5296
Author: Keith Turner <keith@deenlo.com>
Authored: Thu Sep 15 14:04:45 2016 -0400
Committer: Keith Turner <keith@deenlo.com>
Committed: Thu Sep 15 14:04:45 2016 -0400

----------------------------------------------------------------------
 .../apache/fluo/api/client/SnapshotBase.java    | 34 +++++++++--
 .../apache/fluo/api/client/TransactionBase.java | 12 +++-
 .../apache/fluo/core/impl/TransactionImpl.java  | 36 -----------
 .../org/apache/fluo/core/impl/TxStringUtil.java | 64 --------------------
 .../fluo/core/log/TracingTransaction.java       | 37 -----------
 .../fluo/integration/TestTransaction.java       | 36 -----------
 6 files changed, 39 insertions(+), 180 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/20d12a8a/modules/api/src/main/java/org/apache/fluo/api/client/SnapshotBase.java
----------------------------------------------------------------------
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 0bc3837..e08132a 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,10 +16,14 @@
 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;
@@ -118,13 +122,26 @@ public interface SnapshotBase {
    * Wrapper for {@link #get(Collection)} that uses Strings. All strings are encoded and
decoded
    * using UTF-8.
    */
-  Map<RowColumn, String> gets(Collection<RowColumn> rowColumns);
+  default Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
+    Map<RowColumn, Bytes> bytesMap = get(rowColumns);
+    return Maps.transformValues(bytesMap, b -> b.toString());
+  }
 
   /**
    * Wrapper for {@link #get(Collection, Set)} that uses Strings. All strings are encoded
and
    * decoded using UTF-8.
    */
-  Map<String, Map<Column, String>> gets(Collection<? extends CharSequence>
rows, Set<Column> columns);
+  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;
+  }
 
   /**
    * Wrapper for {@link #get(Collection, Set)} that uses Strings. All strings are encoded
and
@@ -139,13 +156,22 @@ public interface SnapshotBase {
    * Wrapper for {@link #get(Bytes, Column)} that uses Strings. All strings are encoded and
decoded
    * using UTF-8.
    */
-  String gets(CharSequence row, Column column);
+  default String gets(CharSequence row, Column column) {
+    Bytes val = get(Bytes.of(row), column);
+    if (val == null) {
+      return null;
+    }
+    return val.toString();
+  }
 
   /**
    * Wrapper for {@link #get(Bytes, Set)} that uses Strings. All strings are encoded and
decoded
    * using UTF-8.
    */
-  Map<Column, String> gets(CharSequence row, Set<Column> columns);
+  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());
+  }
 
   /**
    * Wrapper for {@link #get(Bytes, Set)} that uses Strings. All strings are encoded and
decoded

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/20d12a8a/modules/api/src/main/java/org/apache/fluo/api/client/TransactionBase.java
----------------------------------------------------------------------
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 8167b72..57a0e1e 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
@@ -36,7 +36,9 @@ public interface TransactionBase extends SnapshotBase {
    * Wrapper for {@link #delete(Bytes, Column)} that uses Strings. All String are encoded
using
    * UTF-8.
    */
-  void delete(CharSequence row, Column col);
+  default void delete(CharSequence row, Column col) {
+    delete(Bytes.of(row), col);
+  }
 
   /**
    * Sets a value (in {@link Bytes}) at the given row and {@link Column}
@@ -47,7 +49,9 @@ public interface TransactionBase extends SnapshotBase {
    * Wrapper for {@link #set(Bytes, Column, Bytes)} that uses Strings. All String are encoded
using
    * UTF-8.
    */
-  void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException;
+  default void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException
{
+    set(Bytes.of(row), col, Bytes.of(value));
+  }
 
   /**
    * Sets a weak notification at the given row and {@link Column}
@@ -58,5 +62,7 @@ public interface TransactionBase extends SnapshotBase {
    * Wrapper for {@link #setWeakNotification(Bytes, Column)} that uses Strings. All String
are
    * encoded using UTF-8.
    */
-  void setWeakNotification(CharSequence row, Column col);
+  default void setWeakNotification(CharSequence row, Column col) {
+    setWeakNotification(Bytes.of(row), col);
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/20d12a8a/modules/core/src/main/java/org/apache/fluo/core/impl/TransactionImpl.java
----------------------------------------------------------------------
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 ebf06a7..2591a57 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
@@ -307,11 +307,6 @@ public class TransactionImpl implements AsyncTransaction, Snapshot {
   }
 
   @Override
-  public void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException
{
-    set(Bytes.of(row), col, Bytes.of(value));
-  }
-
-  @Override
   public void setWeakNotification(Bytes row, Column col) {
     checkIfOpen();
     Objects.requireNonNull(row);
@@ -333,11 +328,6 @@ public class TransactionImpl implements AsyncTransaction, Snapshot {
   }
 
   @Override
-  public void setWeakNotification(CharSequence row, Column col) {
-    setWeakNotification(Bytes.of(row), col);
-  }
-
-  @Override
   public void delete(Bytes row, Column col) throws AlreadySetException {
     checkIfOpen();
     Objects.requireNonNull(row);
@@ -345,11 +335,6 @@ public class TransactionImpl implements AsyncTransaction, Snapshot {
     set(row, col, DELETE);
   }
 
-  @Override
-  public void delete(CharSequence row, Column col) {
-    delete(Bytes.of(row), col);
-  }
-
   private ConditionalFlutation prewrite(ConditionalFlutation cm, Bytes row, Column col, Bytes
val,
       Bytes primaryRow, Column primaryColumn, boolean isTriggerRow) {
     IteratorSetting iterConf = new IteratorSetting(10, PrewriteIterator.class);
@@ -658,27 +643,6 @@ public class TransactionImpl implements AsyncTransaction, Snapshot {
     return startTs;
   }
 
-  @Override
-  public String gets(CharSequence row, Column column) {
-    return TxStringUtil.gets(this, row, column);
-  }
-
-  @Override
-  public Map<Column, String> gets(CharSequence row, Set<Column> columns) {
-    return TxStringUtil.gets(this, row, columns);
-  }
-
-  @Override
-  public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence>
rows,
-      Set<Column> columns) {
-    return TxStringUtil.gets(this, rows, columns);
-  }
-
-  @Override
-  public Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
-    return TxStringUtil.gets(this, rowColumns);
-  }
-
   // async experiment
 
   private abstract static class CommitCallback<V> implements FutureCallback<V>
{

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/20d12a8a/modules/core/src/main/java/org/apache/fluo/core/impl/TxStringUtil.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/fluo/core/impl/TxStringUtil.java b/modules/core/src/main/java/org/apache/fluo/core/impl/TxStringUtil.java
deleted file mode 100644
index c9874c0..0000000
--- a/modules/core/src/main/java/org/apache/fluo/core/impl/TxStringUtil.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * 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.core.impl;
-
-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.Maps;
-import org.apache.fluo.api.client.SnapshotBase;
-import org.apache.fluo.api.data.Bytes;
-import org.apache.fluo.api.data.Column;
-import org.apache.fluo.api.data.RowColumn;
-
-public class TxStringUtil {
-  private static Map<String, Map<Column, String>> transform(Map<Bytes, Map<Column,
Bytes>> rcvs) {
-    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 static String gets(SnapshotBase snapshot, CharSequence row, Column column) {
-    Bytes val = snapshot.get(Bytes.of(row), column);
-    if (val == null) {
-      return null;
-    }
-    return val.toString();
-  }
-
-  public static Map<Column, String> gets(SnapshotBase snapshot, CharSequence row,
-      Set<Column> columns) {
-    Map<Column, Bytes> values = snapshot.get(Bytes.of(row), columns);
-    return Maps.transformValues(values, b -> b.toString());
-  }
-
-  public static Map<String, Map<Column, String>> gets(SnapshotBase snapshot,
-      Collection<? extends CharSequence> rows, Set<Column> columns) {
-    return transform(snapshot.get(Collections2.transform(rows, s -> Bytes.of(s)), columns));
-  }
-
-  public static Map<RowColumn, String> gets(SnapshotBase snapshot, Collection<RowColumn>
rowColumns) {
-    Map<RowColumn, Bytes> bytesMap = snapshot.get(rowColumns);
-    return Maps.transformValues(bytesMap, b -> b.toString());
-  }
-}

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/20d12a8a/modules/core/src/main/java/org/apache/fluo/core/log/TracingTransaction.java
----------------------------------------------------------------------
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 34cd61e..6c52c9a 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
@@ -32,7 +32,6 @@ import org.apache.fluo.core.async.AsyncCommitObserver;
 import org.apache.fluo.core.async.AsyncTransaction;
 import org.apache.fluo.core.impl.Notification;
 import org.apache.fluo.core.impl.TxStats;
-import org.apache.fluo.core.impl.TxStringUtil;
 import org.apache.fluo.core.util.Hex;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -169,11 +168,6 @@ public class TracingTransaction implements AsyncTransaction, Snapshot
{
   }
 
   @Override
-  public void setWeakNotification(CharSequence row, Column col) {
-    setWeakNotification(Bytes.of(row), col);
-  }
-
-  @Override
   public void set(Bytes row, Column col, Bytes value) throws AlreadySetException {
     if (log.isTraceEnabled()) {
       log.trace("txid: {} set({}, {}, {})", txid, enc(row), enc(col), enc(value));
@@ -182,11 +176,6 @@ public class TracingTransaction implements AsyncTransaction, Snapshot
{
   }
 
   @Override
-  public void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException
{
-    set(Bytes.of(row), col, Bytes.of(value));
-  }
-
-  @Override
   public void delete(Bytes row, Column col) throws AlreadySetException {
     if (log.isTraceEnabled()) {
       log.trace("txid: {} delete({}, {})", txid, enc(row), enc(col));
@@ -195,11 +184,6 @@ public class TracingTransaction implements AsyncTransaction, Snapshot
{
   }
 
   @Override
-  public void delete(CharSequence row, Column col) {
-    delete(Bytes.of(row), col);
-  }
-
-  @Override
   public void commit() throws CommitException {
     try {
       tx.commit();
@@ -254,27 +238,6 @@ public class TracingTransaction implements AsyncTransaction, Snapshot
{
     return tx.getStartTimestamp();
   }
 
-  @Override
-  public String gets(CharSequence row, Column column) {
-    return TxStringUtil.gets(this, row, column);
-  }
-
-  @Override
-  public Map<Column, String> gets(CharSequence row, Set<Column> columns) {
-    return TxStringUtil.gets(this, row, columns);
-  }
-
-  @Override
-  public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence>
rows,
-      Set<Column> columns) {
-    return TxStringUtil.gets(this, rows, columns);
-  }
-
-  @Override
-  public Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
-    return TxStringUtil.gets(this, rowColumns);
-  }
-
   public class LoggingCommitObserver implements AsyncCommitObserver {
 
     AsyncCommitObserver aco;

http://git-wip-us.apache.org/repos/asf/incubator-fluo/blob/20d12a8a/modules/integration/src/test/java/org/apache/fluo/integration/TestTransaction.java
----------------------------------------------------------------------
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 c4c2088..6a214c8 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
@@ -160,31 +160,16 @@ public class TestTransaction implements TransactionBase {
   }
 
   @Override
-  public void delete(CharSequence row, Column col) {
-    tx.delete(row, col);
-  }
-
-  @Override
   public void set(Bytes row, Column col, Bytes value) throws AlreadySetException {
     tx.set(row, col, value);
   }
 
   @Override
-  public void set(CharSequence row, Column col, CharSequence value) throws AlreadySetException
{
-    tx.set(row, col, value);
-  }
-
-  @Override
   public void setWeakNotification(Bytes row, Column col) {
     tx.setWeakNotification(row, col);
   }
 
   @Override
-  public void setWeakNotification(CharSequence row, Column col) {
-    tx.setWeakNotification(row, col);
-  }
-
-  @Override
   public Bytes get(Bytes row, Column column) {
     return tx.get(row, column);
   }
@@ -210,27 +195,6 @@ public class TestTransaction implements TransactionBase {
   }
 
   @Override
-  public Map<RowColumn, String> gets(Collection<RowColumn> rowColumns) {
-    return tx.gets(rowColumns);
-  }
-
-  @Override
-  public Map<String, Map<Column, String>> gets(Collection<? extends CharSequence>
rows,
-      Set<Column> columns) {
-    return tx.gets(rows, columns);
-  }
-
-  @Override
-  public String gets(CharSequence row, Column column) {
-    return tx.gets(row, column);
-  }
-
-  @Override
-  public Map<Column, String> gets(CharSequence row, Set<Column> columns) {
-    return tx.gets(row, columns);
-  }
-
-  @Override
   public long getStartTimestamp() {
     return tx.getStartTimestamp();
   }


Mime
View raw message