logging-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattsic...@apache.org
Subject svn commit: r1606953 - in /logging/log4j/log4j2/trunk/log4j-nosql/src: main/java/org/apache/logging/log4j/nosql/appender/ main/java/org/apache/logging/log4j/nosql/appender/couchdb/ test/java/org/apache/logging/log4j/nosql/appender/
Date Tue, 01 Jul 2014 00:27:26 GMT
Author: mattsicker
Date: Tue Jul  1 00:27:25 2014
New Revision: 1606953

URL: http://svn.apache.org/r1606953
Log:
Refactor CouchDbObject into DefaultNoSqlObject.

  - Back when I was looking into the APIs for some other NoSQL drivers, I noticed that almost
all of them use Map<String, Object> as their document type. Only MongoDB uses a more
specific class. Therefore, I've renamed the CouchDbObject class due to its versatility in
supporting more NoSQL drivers in the future.
  - Updated tests that referenced the old class.

Added:
    logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/DefaultNoSqlObject.java
Removed:
    logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbObject.java
Modified:
    logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
    logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java

Added: logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/DefaultNoSqlObject.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/DefaultNoSqlObject.java?rev=1606953&view=auto
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/DefaultNoSqlObject.java
(added)
+++ logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/DefaultNoSqlObject.java
Tue Jul  1 00:27:25 2014
@@ -0,0 +1,66 @@
+/*
+ * 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.logging.log4j.nosql.appender;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Default implementation of {@link org.apache.logging.log4j.nosql.appender.NoSqlObject}.
Most NoSQL Java APIs tend
+ * to re-use the Map interface for storage and retrieval of the underlying JSON documents.
Therefore, this
+ * implementation is provided for convenience.
+ */
+public class DefaultNoSqlObject implements NoSqlObject<Map<String, Object>> {
+
+    private final Map<String, Object> map;
+
+    public DefaultNoSqlObject() {
+        this.map = new HashMap<String, Object>();
+    }
+
+    @Override
+    public void set(String field, Object value) {
+        this.map.put(field, value);
+    }
+
+    @Override
+    public void set(String field, NoSqlObject<Map<String, Object>> value) {
+        this.map.put(field, value.unwrap());
+    }
+
+    @Override
+    public void set(String field, Object[] values) {
+        this.map.put(field, Arrays.asList(values));
+    }
+
+    @Override
+    public void set(String field, NoSqlObject<Map<String, Object>>[] values)
{
+        final List<Map<String, Object>> list = new ArrayList<Map<String,
Object>>(values.length);
+        for (final NoSqlObject<Map<String, Object>> value : values) {
+            list.add(value.unwrap());
+        }
+        this.map.put(field, list);
+    }
+
+    @Override
+    public Map<String, Object> unwrap() {
+        return this.map;
+    }
+}

Modified: logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java?rev=1606953&r1=1606952&r2=1606953&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-nosql/src/main/java/org/apache/logging/log4j/nosql/appender/couchdb/CouchDbConnection.java
Tue Jul  1 00:27:25 2014
@@ -20,6 +20,7 @@ import java.util.Map;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
+import org.apache.logging.log4j.nosql.appender.DefaultNoSqlObject;
 import org.apache.logging.log4j.nosql.appender.NoSqlConnection;
 import org.apache.logging.log4j.nosql.appender.NoSqlObject;
 import org.lightcouch.CouchDbClient;
@@ -28,7 +29,7 @@ import org.lightcouch.Response;
 /**
  * The Apache CouchDB implementation of {@link NoSqlConnection}.
  */
-public final class CouchDbConnection implements NoSqlConnection<Map<String, Object>,
CouchDbObject> {
+public final class CouchDbConnection implements NoSqlConnection<Map<String, Object>,
DefaultNoSqlObject> {
     private final CouchDbClient client;
     private final AtomicBoolean closed = new AtomicBoolean(false);
 
@@ -37,13 +38,13 @@ public final class CouchDbConnection imp
     }
 
     @Override
-    public CouchDbObject createObject() {
-        return new CouchDbObject();
+    public DefaultNoSqlObject createObject() {
+        return new DefaultNoSqlObject();
     }
 
     @Override
-    public CouchDbObject[] createList(final int length) {
-        return new CouchDbObject[length];
+    public DefaultNoSqlObject[] createList(final int length) {
+        return new DefaultNoSqlObject[length];
     }
 
     @Override

Modified: logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java?rev=1606953&r1=1606952&r2=1606953&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java
(original)
+++ logging/log4j/log4j2/trunk/log4j-nosql/src/test/java/org/apache/logging/log4j/nosql/appender/NoSqlDatabaseManagerTest.java
Tue Jul  1 00:27:25 2014
@@ -29,7 +29,6 @@ import org.apache.logging.log4j.ThreadCo
 import org.apache.logging.log4j.core.LogEvent;
 import org.apache.logging.log4j.core.appender.AppenderLoggingException;
 import org.apache.logging.log4j.message.Message;
-import org.apache.logging.log4j.nosql.appender.couchdb.CouchDbObject;
 import org.easymock.Capture;
 import org.easymock.IAnswer;
 import org.junit.After;
@@ -41,8 +40,8 @@ import static org.easymock.EasyMock.*;
 import static org.junit.Assert.*;
 
 public class NoSqlDatabaseManagerTest {
-    private NoSqlConnection<Map<String, Object>, CouchDbObject> connection;
-    private NoSqlProvider<NoSqlConnection<Map<String, Object>, CouchDbObject>>
provider;
+    private NoSqlConnection<Map<String, Object>, DefaultNoSqlObject> connection;
+    private NoSqlProvider<NoSqlConnection<Map<String, Object>, DefaultNoSqlObject>>
provider;
 
     @Before
     @SuppressWarnings("unchecked")
@@ -174,10 +173,10 @@ public class NoSqlDatabaseManagerTest {
             final Message message = createStrictMock(Message.class);
 
             expect(this.connection.isClosed()).andReturn(false);
-            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDbObject>()
{
+            expect(this.connection.createObject()).andAnswer(new IAnswer<DefaultNoSqlObject>()
{
                 @Override
-                public CouchDbObject answer() throws Throwable {
-                    return new CouchDbObject();
+                public DefaultNoSqlObject answer() throws Throwable {
+                    return new DefaultNoSqlObject();
                 }
             }).atLeastOnce();
             expect(event.getLevel()).andReturn(Level.WARN);
@@ -270,22 +269,22 @@ public class NoSqlDatabaseManagerTest {
             ThreadContext.clearStack();
 
             expect(this.connection.isClosed()).andReturn(false);
-            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDbObject>()
{
+            expect(this.connection.createObject()).andAnswer(new IAnswer<DefaultNoSqlObject>()
{
                 @Override
-                public CouchDbObject answer() throws Throwable {
-                    return new CouchDbObject();
+                public DefaultNoSqlObject answer() throws Throwable {
+                    return new DefaultNoSqlObject();
                 }
             }).atLeastOnce();
-            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<CouchDbObject[]>()
{
+            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<DefaultNoSqlObject[]>()
{
                 @Override
-                public CouchDbObject[] answer() throws Throwable {
-                    return new CouchDbObject[(Integer) getCurrentArguments()[0]];
+                public DefaultNoSqlObject[] answer() throws Throwable {
+                    return new DefaultNoSqlObject[(Integer) getCurrentArguments()[0]];
                 }
             });
-            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDbObject>()
{
+            expect(this.connection.createObject()).andAnswer(new IAnswer<DefaultNoSqlObject>()
{
                 @Override
-                public CouchDbObject answer() throws Throwable {
-                    return new CouchDbObject();
+                public DefaultNoSqlObject answer() throws Throwable {
+                    return new DefaultNoSqlObject();
                 }
             }).atLeastOnce();
             expect(event.getLevel()).andReturn(Level.DEBUG);
@@ -406,34 +405,34 @@ public class NoSqlDatabaseManagerTest {
             ThreadContext.clearStack();
 
             expect(this.connection.isClosed()).andReturn(false);
-            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDbObject>()
{
+            expect(this.connection.createObject()).andAnswer(new IAnswer<DefaultNoSqlObject>()
{
                 @Override
-                public CouchDbObject answer() throws Throwable {
-                    return new CouchDbObject();
+                public DefaultNoSqlObject answer() throws Throwable {
+                    return new DefaultNoSqlObject();
                 }
             }).atLeastOnce();
-            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<CouchDbObject[]>()
{
+            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<DefaultNoSqlObject[]>()
{
                 @Override
-                public CouchDbObject[] answer() throws Throwable {
-                    return new CouchDbObject[(Integer) getCurrentArguments()[0]];
+                public DefaultNoSqlObject[] answer() throws Throwable {
+                    return new DefaultNoSqlObject[(Integer) getCurrentArguments()[0]];
                 }
             });
-            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDbObject>()
{
+            expect(this.connection.createObject()).andAnswer(new IAnswer<DefaultNoSqlObject>()
{
                 @Override
-                public CouchDbObject answer() throws Throwable {
-                    return new CouchDbObject();
+                public DefaultNoSqlObject answer() throws Throwable {
+                    return new DefaultNoSqlObject();
                 }
             }).atLeastOnce();
-            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<CouchDbObject[]>()
{
+            expect(this.connection.createList(anyInt())).andAnswer(new IAnswer<DefaultNoSqlObject[]>()
{
                 @Override
-                public CouchDbObject[] answer() throws Throwable {
-                    return new CouchDbObject[(Integer) getCurrentArguments()[0]];
+                public DefaultNoSqlObject[] answer() throws Throwable {
+                    return new DefaultNoSqlObject[(Integer) getCurrentArguments()[0]];
                 }
             });
-            expect(this.connection.createObject()).andAnswer(new IAnswer<CouchDbObject>()
{
+            expect(this.connection.createObject()).andAnswer(new IAnswer<DefaultNoSqlObject>()
{
                 @Override
-                public CouchDbObject answer() throws Throwable {
-                    return new CouchDbObject();
+                public DefaultNoSqlObject answer() throws Throwable {
+                    return new DefaultNoSqlObject();
                 }
             }).atLeastOnce();
             expect(event.getLevel()).andReturn(Level.DEBUG);



Mime
View raw message