From a993af6c29d1f040ac7012eac1696a47f2e6ae16 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Sun, 12 Nov 2017 22:32:58 -0500 Subject: [PATCH] Enable toggle for showing values in logged CQL statements. Default to true. --- .../helenus/core/AbstractSessionOperations.java | 2 ++ .../java/net/helenus/core/HelenusSession.java | 17 +++++++++++++++++ .../net/helenus/core/SessionInitializer.java | 16 ++++++++++++++++ .../net/helenus/core/operation/Operation.java | 3 ++- 4 files changed, 37 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/helenus/core/AbstractSessionOperations.java b/src/main/java/net/helenus/core/AbstractSessionOperations.java index 4ff4072..65d98f8 100644 --- a/src/main/java/net/helenus/core/AbstractSessionOperations.java +++ b/src/main/java/net/helenus/core/AbstractSessionOperations.java @@ -42,6 +42,8 @@ public abstract class AbstractSessionOperations { public abstract boolean isShowCql(); + public abstract boolean showValues(); + public abstract PrintStream getPrintStream(); public abstract Executor getExecutor(); diff --git a/src/main/java/net/helenus/core/HelenusSession.java b/src/main/java/net/helenus/core/HelenusSession.java index 42d6bf9..699734d 100644 --- a/src/main/java/net/helenus/core/HelenusSession.java +++ b/src/main/java/net/helenus/core/HelenusSession.java @@ -74,12 +74,14 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab private final Metadata metadata; private volatile String usingKeyspace; private volatile boolean showCql; + private volatile boolean showValues; HelenusSession( Session session, String usingKeyspace, CodecRegistry registry, boolean showCql, + boolean showValues, PrintStream printStream, SessionRepositoryBuilder sessionRepositoryBuilder, Executor executor, @@ -96,6 +98,7 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab Objects.requireNonNull( usingKeyspace, "keyspace needs to be selected before creating session"); this.showCql = showCql; + this.showValues = showValues; this.printStream = printStream; this.sessionRepository = sessionRepositoryBuilder.build(); this.executor = executor; @@ -153,6 +156,20 @@ public class HelenusSession extends AbstractSessionOperations implements Closeab return this; } + public HelenusSession showQueryValuesInLog(boolean showValues) { + this.showValues = showValues; + return this; + } + + public HelenusSession showQueryValuesInLog() { + this.showValues = true; + return this; + } + + public boolean showValues() { + return showValues; + } + @Override public Executor getExecutor() { return executor; diff --git a/src/main/java/net/helenus/core/SessionInitializer.java b/src/main/java/net/helenus/core/SessionInitializer.java index c77379d..f8a39a7 100644 --- a/src/main/java/net/helenus/core/SessionInitializer.java +++ b/src/main/java/net/helenus/core/SessionInitializer.java @@ -43,6 +43,7 @@ public final class SessionInitializer extends AbstractSessionOperations { private CodecRegistry registry; private String usingKeyspace; private boolean showCql = false; + private boolean showValues = true; private ConsistencyLevel consistencyLevel; private boolean idempotent = true; private MetricRegistry metricRegistry = new MetricRegistry(); @@ -103,6 +104,20 @@ public final class SessionInitializer extends AbstractSessionOperations { return this; } + public SessionInitializer showQueryValuesInLog(boolean showValues) { + this.showValues = showValues; + return this; + } + + public SessionInitializer showQueryValuesInLog() { + this.showValues = true; + return this; + } + + public boolean showValues() { + return showValues; + } + public SessionInitializer metricRegistry(MetricRegistry metricRegistry) { this.metricRegistry = metricRegistry; return this; @@ -255,6 +270,7 @@ public final class SessionInitializer extends AbstractSessionOperations { usingKeyspace, registry, showCql, + showValues, printStream, sessionRepository, executor, diff --git a/src/main/java/net/helenus/core/operation/Operation.java b/src/main/java/net/helenus/core/operation/Operation.java index 2b875d6..28c8e27 100644 --- a/src/main/java/net/helenus/core/operation/Operation.java +++ b/src/main/java/net/helenus/core/operation/Operation.java @@ -42,7 +42,7 @@ public abstract class Operation { private static final Logger LOG = LoggerFactory.getLogger(Operation.class); protected final AbstractSessionOperations sessionOps; - protected boolean showValues = false; + protected boolean showValues; protected TraceContext traceContext; protected long queryExecutionTimeout = 10; protected TimeUnit queryTimeoutUnits = TimeUnit.SECONDS; @@ -56,6 +56,7 @@ public abstract class Operation { Operation(AbstractSessionOperations sessionOperations) { this.sessionOps = sessionOperations; + this.showValues = sessionOps.showValues(); MetricRegistry metrics = sessionOperations.getMetricRegistry(); if (metrics == null) { metrics = new MetricRegistry();