Repository: logging-log4j2
Updated Branches:
  refs/heads/master 487540ac0 -> 5f5c6c3c1


Minor clean ups.

Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/5f5c6c3c
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/5f5c6c3c
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/5f5c6c3c

Branch: refs/heads/master
Commit: 5f5c6c3c1f6c342b2d4173b09751fa0d86fb3b96
Parents: 487540a
Author: Gary Gregory <garydgreg...@gmail.com>
Authored: Fri Nov 16 16:50:42 2018 -0700
Committer: Gary Gregory <garydgreg...@gmail.com>
Committed: Fri Nov 16 16:50:42 2018 -0700

----------------------------------------------------------------------
 .../log4j/jdbc/appender/ColumnConfig.java       | 237 +++++++++----------
 1 file changed, 118 insertions(+), 119 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/5f5c6c3c/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/ColumnConfig.java
----------------------------------------------------------------------
diff --git 
a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/ColumnConfig.java
 
b/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/ColumnConfig.java
index e47a866..e1ef0ef 100644
--- 
a/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/ColumnConfig.java
+++ 
b/log4j-jdbc/src/main/java/org/apache/logging/log4j/jdbc/appender/ColumnConfig.java
@@ -26,7 +26,6 @@ import 
org.apache.logging.log4j.core.config.plugins.PluginBuilderFactory;
 import org.apache.logging.log4j.core.config.plugins.PluginConfiguration;
 import 
org.apache.logging.log4j.core.config.plugins.validation.constraints.Required;
 import org.apache.logging.log4j.core.layout.PatternLayout;
-import org.apache.logging.log4j.core.util.Booleans;
 import org.apache.logging.log4j.status.StatusLogger;
 import org.apache.logging.log4j.util.Strings;
 
@@ -37,60 +36,6 @@ import org.apache.logging.log4j.util.Strings;
  */
 @Plugin(name = "Column", category = Core.CATEGORY_NAME, printObject = true)
 public final class ColumnConfig {
-    private static final Logger LOGGER = StatusLogger.getLogger();
-
-    private final String columnName;
-    private final PatternLayout layout;
-    private final String literalValue;
-    private final boolean eventTimestamp;
-    private final boolean unicode;
-    private final boolean clob;
-
-    private ColumnConfig(final String columnName, final PatternLayout layout, 
final String literalValue,
-                         final boolean eventDate, final boolean unicode, final 
boolean clob) {
-        this.columnName = columnName;
-        this.layout = layout;
-        this.literalValue = literalValue;
-        this.eventTimestamp = eventDate;
-        this.unicode = unicode;
-        this.clob = clob;
-    }
-
-    public String getColumnName() {
-        return this.columnName;
-    }
-
-    public PatternLayout getLayout() {
-        return this.layout;
-    }
-
-    public String getLiteralValue() {
-        return this.literalValue;
-    }
-
-    public boolean isEventTimestamp() {
-        return this.eventTimestamp;
-    }
-
-    public boolean isUnicode() {
-        return this.unicode;
-    }
-
-    public boolean isClob() {
-        return this.clob;
-    }
-
-    @Override
-    public String toString() {
-        return "{ name=" + this.columnName + ", layout=" + this.layout + ", 
literal=" + this.literalValue
-                + ", timestamp=" + this.eventTimestamp + " }";
-    }
-
-    @PluginBuilderFactory
-    public static Builder newBuilder() {
-        return new Builder();
-    }
-
     public static class Builder implements 
org.apache.logging.log4j.core.util.Builder<ColumnConfig> {
 
         @PluginConfiguration
@@ -115,42 +60,79 @@ public final class ColumnConfig {
         @PluginBuilderAttribute
         private boolean isClob;
 
+        @Override
+        public ColumnConfig build() {
+            if (Strings.isEmpty(name)) {
+                LOGGER.error("The column config is not valid because it does 
not contain a column name.");
+                return null;
+            }
+
+            final boolean isPattern = Strings.isNotEmpty(pattern);
+            final boolean isLiteralValue = Strings.isNotEmpty(literal);
+
+            if ((isPattern && isLiteralValue) || (isPattern && 
isEventTimestamp) || (isLiteralValue && isEventTimestamp)) {
+                LOGGER.error("The pattern, literal, and isEventTimestamp 
attributes are mutually exclusive.");
+                return null;
+            }
+
+            if (isEventTimestamp) {
+                return new ColumnConfig(name, null, null, true, false, false);
+            }
+
+            if (isLiteralValue) {
+                return new ColumnConfig(name, null, literal, false, false, 
false);
+            }
+
+            if (isPattern) {
+                final PatternLayout layout =
+                    PatternLayout.newBuilder()
+                        .setPattern(pattern)
+                        .setConfiguration(configuration)
+                        .setAlwaysWriteExceptions(false)
+                        .build();
+                return new ColumnConfig(name, layout, null, false, isUnicode, 
isClob);
+            }
+
+            LOGGER.error("To configure a column you must specify a pattern or 
literal or set isEventDate to true.");
+            return null;
+        }
+
         /**
-         * The configuration object.
-         * 
-         * @return this. 
+         * If {@code "true"}, indicates that the column is a character LOB 
(CLOB).
+         *
+         * @return this.
          */
-        public Builder setConfiguration(final Configuration configuration) {
-            this.configuration = configuration;
+        public Builder setClob(final boolean clob) {
+            isClob = clob;
             return this;
         }
 
         /**
-         * The name of the database column as it exists within the database 
table.
-         * 
-         * @return this. 
+         * The configuration object.
+         *
+         * @return this.
          */
-        public Builder setName(final String name) {
-            this.name = name;
+        public Builder setConfiguration(final Configuration configuration) {
+            this.configuration = configuration;
             return this;
         }
 
         /**
-         * The {@link PatternLayout} pattern to insert in this column. 
Mutually exclusive with
-         * {@code literal!=null} and {@code eventTimestamp=true}
-         * 
-         * @return this. 
+         * If {@code "true"}, indicates that this column is a date-time column 
in which the event timestamp should be
+         * inserted. Mutually exclusive with {@code pattern!=null} and {@code 
literal!=null}.
+         *
+         * @return this.
          */
-        public Builder setPattern(final String pattern) {
-            this.pattern = pattern;
+        public Builder setEventTimestamp(final boolean eventTimestamp) {
+            isEventTimestamp = eventTimestamp;
             return this;
         }
 
         /**
          * The literal value to insert into the column as-is without any 
quoting or escaping. Mutually exclusive with
          * {@code pattern!=null} and {@code eventTimestamp=true}.
-         * 
-         * @return this. 
+         *
+         * @return this.
          */
         public Builder setLiteral(final String literal) {
             this.literal = literal;
@@ -158,71 +140,88 @@ public final class ColumnConfig {
         }
 
         /**
-         * If {@code "true"}, indicates that this column is a date-time column 
in which the event timestamp should be
-         * inserted. Mutually exclusive with {@code pattern!=null} and {@code 
literal!=null}.
-         * 
-         * @return this. 
+         * The name of the database column as it exists within the database 
table.
+         *
+         * @return this.
          */
-        public Builder setEventTimestamp(final boolean eventTimestamp) {
-            isEventTimestamp = eventTimestamp;
+        public Builder setName(final String name) {
+            this.name = name;
             return this;
         }
 
         /**
-         * If {@code "true"}, indicates that the column is a Unicode String.
-         * 
-         * @return this. 
+         * The {@link PatternLayout} pattern to insert in this column. 
Mutually exclusive with
+         * {@code literal!=null} and {@code eventTimestamp=true}
+         *
+         * @return this.
          */
-        public Builder setUnicode(final boolean unicode) {
-            isUnicode = unicode;
+        public Builder setPattern(final String pattern) {
+            this.pattern = pattern;
             return this;
         }
 
         /**
-         * If {@code "true"}, indicates that the column is a character LOB 
(CLOB).
-         * 
-         * @return this. 
+         * If {@code "true"}, indicates that the column is a Unicode String.
+         *
+         * @return this.
          */
-        public Builder setClob(final boolean clob) {
-            isClob = clob;
+        public Builder setUnicode(final boolean unicode) {
+            isUnicode = unicode;
             return this;
         }
+    }
 
-        @Override
-        public ColumnConfig build() {
-            if (Strings.isEmpty(name)) {
-                LOGGER.error("The column config is not valid because it does 
not contain a column name.");
-                return null;
-            }
+    private static final Logger LOGGER = StatusLogger.getLogger();
+    @PluginBuilderFactory
+    public static Builder newBuilder() {
+        return new Builder();
+    }
+    private final String columnName;
+    private final PatternLayout layout;
+    private final String literalValue;
+    private final boolean eventTimestamp;
 
-            final boolean isPattern = Strings.isNotEmpty(pattern);
-            final boolean isLiteralValue = Strings.isNotEmpty(literal);
+    private final boolean unicode;
 
-            if ((isPattern && isLiteralValue) || (isPattern && 
isEventTimestamp) || (isLiteralValue && isEventTimestamp)) {
-                LOGGER.error("The pattern, literal, and isEventTimestamp 
attributes are mutually exclusive.");
-                return null;
-            }
+    private final boolean clob;
 
-            if (isEventTimestamp) {
-                return new ColumnConfig(name, null, null, true, false, false);
-            }
+    private ColumnConfig(final String columnName, final PatternLayout layout, 
final String literalValue,
+                         final boolean eventDate, final boolean unicode, final 
boolean clob) {
+        this.columnName = columnName;
+        this.layout = layout;
+        this.literalValue = literalValue;
+        this.eventTimestamp = eventDate;
+        this.unicode = unicode;
+        this.clob = clob;
+    }
 
-            if (isLiteralValue) {
-                return new ColumnConfig(name, null, literal, false, false, 
false);
-            }
+    public String getColumnName() {
+        return this.columnName;
+    }
 
-            if (isPattern) {
-                final PatternLayout layout =
-                    PatternLayout.newBuilder()
-                        .setPattern(pattern)
-                        .setConfiguration(configuration)
-                        .setAlwaysWriteExceptions(false)
-                        .build();
-                return new ColumnConfig(name, layout, null, false, isUnicode, 
isClob);
-            }
+    public PatternLayout getLayout() {
+        return this.layout;
+    }
 
-            LOGGER.error("To configure a column you must specify a pattern or 
literal or set isEventDate to true.");
-            return null;
-        }
+    public String getLiteralValue() {
+        return this.literalValue;
+    }
+
+    public boolean isClob() {
+        return this.clob;
+    }
+
+    public boolean isEventTimestamp() {
+        return this.eventTimestamp;
+    }
+
+    public boolean isUnicode() {
+        return this.unicode;
+    }
+
+    @Override
+    public String toString() {
+        return "{ name=" + this.columnName + ", layout=" + this.layout + ", 
literal=" + this.literalValue
+                + ", timestamp=" + this.eventTimestamp + " }";
     }
 }

Reply via email to