usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject incubator-usergrid git commit: add string field serialization
Date Thu, 23 Jul 2015 22:24:08 GMT
Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-878 [created] 5308b0848


add string field serialization

add string field serialization


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/5308b084
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/5308b084
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/5308b084

Branch: refs/heads/USERGRID-878
Commit: 5308b084839bd3cca5670fe1302a9cb8f5c5468c
Parents: 54fccac
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Thu Jul 23 16:20:44 2015 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Thu Jul 23 16:21:52 2015 -0600

----------------------------------------------------------------------
 .../corepersistence/CpEntityManager.java        |  9 +---
 .../corepersistence/util/CpEntityMapUtils.java  | 51 +++++++++-----------
 .../org/apache/usergrid/persistence/Query.java  |  2 +
 stack/corepersistence/model/pom.xml             |  7 +++
 .../persistence/model/field/FieldTypeName.java  |  1 +
 .../model/field/SerializedObjectField.java      | 51 ++++++++++++++++++++
 6 files changed, 85 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5308b084/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
index d998de0..e29f7fb 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/CpEntityManager.java
@@ -2630,14 +2630,7 @@ public class CpEntityManager implements EntityManager {
                     applicationId,
                     CpEntityMapUtils.toMap( cpEntity )
                 } );
-            //
-            //            if ( entity.getType().equals("group")) {
-            //                logger.debug("Writing Group");
-            //                for ( Field field : cpEntity.getFields() ) {
-            //                    logger.debug(
-            //                        "   Writing Group name={} value={}", field.getName(),
field.getValue() );
-            //                }
-            //            }
+
         }
 
         try {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5308b084/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
index 6eb1b0c..88bc2c3 100644
--- a/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
+++ b/stack/core/src/main/java/org/apache/usergrid/corepersistence/util/CpEntityMapUtils.java
@@ -20,7 +20,6 @@
 package org.apache.usergrid.corepersistence.util;
 
 import java.io.IOException;
-import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
@@ -30,23 +29,12 @@ import java.util.Set;
 import java.util.TreeMap;
 import java.util.UUID;
 
+import com.fasterxml.jackson.core.JsonFactory;
+import com.fasterxml.jackson.datatype.guava.GuavaModule;
 import org.apache.usergrid.persistence.Schema;
 import org.apache.usergrid.persistence.model.entity.Entity;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.field.ArrayField;
-import org.apache.usergrid.persistence.model.field.BooleanField;
-import org.apache.usergrid.persistence.model.field.ByteArrayField;
-import org.apache.usergrid.persistence.model.field.DoubleField;
-import org.apache.usergrid.persistence.model.field.EntityObjectField;
-import org.apache.usergrid.persistence.model.field.Field;
-import org.apache.usergrid.persistence.model.field.FloatField;
-import org.apache.usergrid.persistence.model.field.IntegerField;
-import org.apache.usergrid.persistence.model.field.ListField;
-import org.apache.usergrid.persistence.model.field.LocationField;
-import org.apache.usergrid.persistence.model.field.LongField;
-import org.apache.usergrid.persistence.model.field.SetField;
-import org.apache.usergrid.persistence.model.field.StringField;
-import org.apache.usergrid.persistence.model.field.UUIDField;
+import org.apache.usergrid.persistence.model.field.*;
 import org.apache.usergrid.persistence.model.field.value.EntityObject;
 import org.apache.usergrid.persistence.model.field.value.Location;
 
@@ -61,9 +49,11 @@ import org.slf4j.LoggerFactory;
  * Aware of unique properties via Schema.
  */
 public class CpEntityMapUtils {
+
     private static final Logger logger = LoggerFactory.getLogger( CpEntityMapUtils.class
);
 
-    public static ObjectMapper objectMapper = new ObjectMapper(  );
+    public static JsonFactory jsonFactory = new JsonFactory();
+    public static ObjectMapper objectMapper = new ObjectMapper( jsonFactory  ).registerModule(new
GuavaModule());
 
 
     /**
@@ -101,10 +91,6 @@ public class CpEntityMapUtils {
             Object value = map.get( fieldName );
             boolean unique = Schema.getDefaultSchema().isPropertyUnique(entityType, fieldName);
 
-//            if ( unique ) {
-//                logger.debug("{} is a unique property", fieldName );
-//            }
-
             if ( value instanceof String ) {
                 entity.setField( new StringField( fieldName, (String)value, unique &&
topLevel ));
 
@@ -136,18 +122,15 @@ public class CpEntityMapUtils {
                 entity.setField( new StringField( fieldName, value.toString(), unique &&
topLevel ));
 
 			} else if ( value != null ) {
-                byte[] valueSerialized;
+                String valueSerialized;
                 try {
-                    valueSerialized = objectMapper.writeValueAsBytes( value );
+                    valueSerialized = objectMapper.writeValueAsString(value);
                 }
                 catch ( JsonProcessingException e ) {
                     throw new RuntimeException( "Can't serialize object ",e );
                 }
-                catch ( IOException e ) {
-                    throw new RuntimeException( "Can't serialize object ",e );
-                }
-                ByteBuffer byteBuffer = ByteBuffer.wrap( valueSerialized );
-                ByteArrayField bf = new ByteArrayField( fieldName, byteBuffer.array(), value.getClass()
);
+
+                SerializedObjectField bf = new SerializedObjectField( fieldName, valueSerialized,
value.getClass() );
                 entity.setField( bf );
             }
         }
@@ -323,7 +306,19 @@ public class CpEntityMapUtils {
                     }
                     entityMap.put( bf.getName(), o );
             }
-            else {
+            else if (f instanceof SerializedObjectField) {
+                SerializedObjectField bf = (SerializedObjectField) f;
+
+                String serilizedObj =  bf.getValue();
+                Object o;
+                try {
+                    o = objectMapper.readValue( serilizedObj, bf.getClassinfo() );
+                }
+                catch ( IOException e ) {
+                    throw new RuntimeException( "Can't deserialize object "+serilizedObj,e
);
+                }
+                entityMap.put( bf.getName(), o );
+            }else {
                 entityMap.put( field.getName(), field.getValue());
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5308b084/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
----------------------------------------------------------------------
diff --git a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
index ead73f0..0074cc9 100644
--- a/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
+++ b/stack/core/src/main/java/org/apache/usergrid/persistence/Query.java
@@ -853,10 +853,12 @@ public class Query {
      * Return true if no query is present and we should perform a graph search
      * @return
      */
+    @JsonIgnore
     public boolean isGraphSearch(){
         return ql == null || ql.trim().toLowerCase().equals("select *");
     }
 
+
     public Query setQl( String ql ) {
         this.ql = ql;
         return this;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5308b084/stack/corepersistence/model/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/pom.xml b/stack/corepersistence/model/pom.xml
index 0efb1b6..142bca1 100644
--- a/stack/corepersistence/model/pom.xml
+++ b/stack/corepersistence/model/pom.xml
@@ -63,6 +63,13 @@
         <version>${jackson-2-version}</version>
       </dependency>
 
+        <!-- Serialize Guava Types -->
+        <dependency>
+            <groupId>com.fasterxml.jackson.datatype</groupId>
+            <artifactId>jackson-datatype-guava</artifactId>
+            <version>2.4.0</version>
+        </dependency>
+
       <!-- smile (binary JSON). Other artifacts in this group do other formats. -->
       <dependency>
         <groupId>com.fasterxml.jackson.dataformat</groupId>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5308b084/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
index 7bba4c9..90f3879 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/FieldTypeName.java
@@ -29,6 +29,7 @@ public enum FieldTypeName {
     ARRAY,
     BOOLEAN,
     BYTE_ARRAY,
+    SERIALIZED_OBJECT,
     DOUBLE,
     OBJECT,
     FLOAT,

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/5308b084/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SerializedObjectField.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SerializedObjectField.java
b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SerializedObjectField.java
new file mode 100644
index 0000000..5b16f89
--- /dev/null
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/field/SerializedObjectField.java
@@ -0,0 +1,51 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  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.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+package org.apache.usergrid.persistence.model.field;
+
+/**
+ * Classy class class.
+ */
+public class SerializedObjectField extends AbstractField<String> {
+    Class classinfo;
+
+    public SerializedObjectField(String name, String value, Class classinfo) {
+        super( name, value );
+        this.classinfo = classinfo;
+    }
+
+    public SerializedObjectField() {
+
+    }
+
+    @Override
+    public String getValue() {
+        return value;
+    }
+
+    public Class getClassinfo() {
+        return classinfo;
+    }
+
+
+    @Override
+    public FieldTypeName getTypeName() {
+        return FieldTypeName.SERIALIZED_OBJECT;
+    }
+}


Mime
View raw message