You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/04/07 22:21:58 UTC

[07/28] git commit: Changing code so that it uses the Object instead of the entity class.

Changing code so that it uses the Object instead of the entity class.


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

Branch: refs/heads/two-dot-o
Commit: 0d544e3e9c9a67ad7f72928cbe544479bae57f86
Parents: fe4d388
Author: grey <gr...@apigee.com>
Authored: Mon Mar 17 11:00:57 2014 -0700
Committer: grey <gr...@apigee.com>
Committed: Mon Mar 17 11:00:57 2014 -0700

----------------------------------------------------------------------
 .../MvccEntitySerializationStrategyImpl.java    | 48 +++++++++----
 ...MvccEntitySerializationStrategyImplTest.java | 72 ++++++++++++++++++++
 stack/corepersistence/model/pom.xml             |  5 ++
 .../persistence/model/entity/Entity.java        |  3 +
 stack/pom.xml                                   | 43 ++++++++++++
 5 files changed, 157 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0d544e3e/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
index e9466f2..1db0ac0 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImpl.java
@@ -29,8 +29,6 @@ import java.util.UUID;
 import org.codehaus.jackson.JsonGenerationException;
 import org.codehaus.jackson.map.JsonMappingException;
 import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.smile.SmileFactory;
-import org.codehaus.jackson.smile.SmileParser;
 
 import org.apache.cassandra.db.marshal.BytesType;
 import org.apache.cassandra.db.marshal.ReversedType;
@@ -277,9 +275,9 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
 
     public static class EntitySerializer extends AbstractSerializer<EntityWrapper> {
 
-        public static final SmileFactory f = new SmileFactory(  );
+        //public static final SmileFactory f = new SmileFactory(  );
 
-        public static ObjectMapper mapper = new ObjectMapper( f );
+        public static ObjectMapper mapper = new ObjectMapper(  );
         private static final BytesArraySerializer BYTES_ARRAY_SERIALIZER = BytesArraySerializer.get();
 
 
@@ -292,6 +290,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
 
         //the marker for when we're passed a "null" value
         private static final byte[] EMPTY = new byte[] { 0x0 };
+        String helper;
 
 //TODO:Make sure your exceptions provide descriptive error messages. And to make sure you even needs the descriptions
         @Override
@@ -304,11 +303,9 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
 
 
             builder.addBytes( VERSION );
-            f.disable( SmileParser.Feature.REQUIRE_HEADER );
-           // f.enable( SmileGenerator.Feature.WRITE_HEADER );
-            //f.enable( SmileGenerator.Feature.WRITE_END_MARKER );
-            mapper = new ObjectMapper( f );
-            //mapper.enable( SmileGenerator.Feature.WRITE_HEADER );
+           // f.disable( SmileParser.Feature.REQUIRE_HEADER );
+
+           // mapper = new ObjectMapper( f );
 
             //mark this version as empty
             if ( !wrapper.entity.isPresent() ) {
@@ -330,6 +327,7 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
 
             try {
                 builder.addBytes( mapper.writeValueAsBytes( wrapper.entity.get() ) );
+                helper = mapper.writeValueAsString( wrapper.entity.get() );
             }
             catch ( JsonMappingException e ) {
                 e.printStackTrace();
@@ -348,16 +346,29 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
         public EntityWrapper fromByteBuffer( final ByteBuffer byteBuffer ) {
             CompositeParser parser = Composites.newCompositeParser( byteBuffer );
             byte[] b = new byte[byteBuffer.remaining()];
-            byteBuffer.get( b, 0, b.length );
+
+            //byteBuffer.get( b, 0, b.length );
             //return mapper.readValue(b, Entity.class);
 
-            final byte[] version = parser.read( BYTES_ARRAY_SERIALIZER );
+            byte[] version = parser.read( BYTES_ARRAY_SERIALIZER );
+//            try {
+//                version = mapper.readValue( byteBuffer.array(),0,1, byte[].class);
+//            }
+//            catch ( IOException e ) {
+//                e.printStackTrace();
+//            }
 
             if ( !Arrays.equals( VERSION, version ) ) {
                 throw new UnsupportedOperationException( "A version of type " + version + " is unsupported" );
             }
 
-            final byte[] state = parser.read( BYTES_ARRAY_SERIALIZER );
+            byte[] state = parser.read( BYTES_ARRAY_SERIALIZER );
+//            try {
+//                state = mapper.readValue( byteBuffer.array(),1,2, new TypeReference<Byte>() {});
+//            }
+//            catch ( IOException e ) {
+//                e.printStackTrace();
+//            }
 
             /**
              * It's been deleted, remove it
@@ -366,13 +377,17 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
                 return new EntityWrapper( MvccEntity.Status.COMPLETE, Optional.<Entity>absent() );
             }
 
-            Entity storedEntity = null;//( Entity ) parser.read( mapper );
+            Object storedObject = null;
+            Entity storedEntity = null;
+            String derper = null;
+            byteBuffer.position( 9 );
             try {
-                storedEntity = mapper.readValue( b , Entity.class );
+                storedObject = mapper.readValue( helper,Object.class);
             }
             catch ( IOException e ) {
                 e.printStackTrace();
             }
+            storedEntity = convertToEntity(storedObject);
 
             final Optional<Entity> entity = Optional.of( storedEntity );
 
@@ -383,6 +398,11 @@ public class MvccEntitySerializationStrategyImpl implements MvccEntitySerializat
             //it's partial by default
             return new EntityWrapper( MvccEntity.Status.PARTIAL, entity );
         }
+
+        private Entity convertToEntity( final Object storedObject ) {
+            Entity storedEntity = null;
+            return null;
+        }
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0d544e3e/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
index 5375ead..bc4485d 100644
--- a/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
+++ b/stack/corepersistence/collection/src/test/java/org/apache/usergrid/persistence/collection/serialization/impl/MvccEntitySerializationStrategyImplTest.java
@@ -275,6 +275,78 @@ public class MvccEntitySerializationStrategyImplTest {
         assertNull( returned );
     }
 
+    @Test
+    public void writeLoadDeleteMinimalFields() throws ConnectionException {
+
+        final Id organizationId = new SimpleId( "organization" );
+        final Id applicationId = new SimpleId( "application" );
+        final String name = "test";
+
+        CollectionScope context = new CollectionScopeImpl( organizationId,  applicationId, name );
+
+
+        final UUID entityId = UUIDGenerator.newTimeUUID();
+        final UUID version = UUIDGenerator.newTimeUUID();
+        final String type = "test";
+
+        final Id id = new SimpleId( entityId, type );
+
+        Entity entity = new Entity( id );
+
+        EntityUtils.setVersion( entity, version );
+
+
+        BooleanField boolField = new BooleanField( "boolean", false );
+
+
+        entity.setField( boolField );
+
+
+
+        MvccEntity saved = new MvccEntityImpl( id, version, MvccEntity.Status.COMPLETE, Optional.of( entity ) );
+
+
+        //persist the entity
+        serializationStrategy.write( context, saved ).execute();
+
+        //now load it back
+
+        MvccEntity returned = serializationStrategy.load( context, id, version );
+
+        assertEquals( "Mvcc entities are the same", saved, returned );
+
+
+        assertEquals( id, entity.getId() );
+
+        //TODO: TN-> shouldn't this be testing the returned value to make sure we were able to load it correctly?
+        //YES THIS SHOULD BE DOING WHA TI THOUGHT< BUT ITSN:T
+        Field<Boolean> boolFieldReturned = returned.getEntity().get().getField( boolField.getName() );
+
+        assertSame( boolField, boolFieldReturned );
+
+        Set<Field> results = new HashSet<Field>();
+        results.addAll( entity.getFields() );
+
+
+        assertTrue( results.contains( boolField ) );
+
+
+        assertEquals( 1, results.size() );
+
+
+        assertEquals( id, entity.getId() );
+        assertEquals( version, entity.getVersion() );
+
+
+        //now delete it
+        serializationStrategy.delete( context, id, version ).execute();
+
+        //now get it, should be gone
+
+        returned = serializationStrategy.load( context, id, version );
+
+        assertNull( returned );
+    }
 
     @Test
     public void writeX2ClearDelete() throws ConnectionException {

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0d544e3e/stack/corepersistence/model/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/pom.xml b/stack/corepersistence/model/pom.xml
index 8a7af5b..418ae53 100644
--- a/stack/corepersistence/model/pom.xml
+++ b/stack/corepersistence/model/pom.xml
@@ -40,6 +40,11 @@
             <version>${commons.lang.version}</version>
             <scope>test</scope>
         </dependency>
+      <dependency>
+        <groupId>com.facebook.giraph.hive</groupId>
+        <artifactId>hive-io-exp-cmdline</artifactId>
+        <version>0.8-SNAPSHOT</version>
+      </dependency>
 
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0d544e3e/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
index 7a0eb5d..ee6e656 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/entity/Entity.java
@@ -21,6 +21,8 @@ package org.apache.usergrid.persistence.model.entity;
 
 import java.util.UUID;
 import org.apache.usergrid.persistence.model.field.value.EntityObject;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
 import com.google.common.base.Preconditions;
 
 
@@ -33,6 +35,7 @@ public class Entity extends EntityObject {
     /**
      * The id.  We should never serialize this
      */
+    @JsonIgnore
     private transient Id id;
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/0d544e3e/stack/pom.xml
----------------------------------------------------------------------
diff --git a/stack/pom.xml b/stack/pom.xml
index 46fbc68..621aaf0 100644
--- a/stack/pom.xml
+++ b/stack/pom.xml
@@ -101,6 +101,7 @@
     <hector-version>1.1-4</hector-version>
     <hector-test-version>1.1-4</hector-test-version>
     <jackson-version>1.9.9</jackson-version>
+    <jackson-2-version>2.3.1</jackson-2-version>
     <jclouds.version>1.6.2-incubating</jclouds.version>
     <jersey-version>1.18</jersey-version>
     <junit-version>4.11</junit-version>
@@ -114,6 +115,7 @@
     <antlr.version>3.4</antlr.version>
     <tika.version>1.4</tika.version>
 
+
   </properties>
 
   <licenses>
@@ -721,6 +723,47 @@
         <version>1.2</version>
       </dependency>
 
+      <!-- the core, which includes Streaming API, shared low-level abstractions (but NOT data-binding) -->
+      <dependency>
+        <groupId>com.fasterxml.jackson.core</groupId>
+        <artifactId>jackson-core</artifactId>
+        <version>${jackson-2-version}</version>
+      </dependency>
+
+      <!-- Just the annotations; use this dependency if you want to attach annotations
+           to classes without connecting them to the code. -->
+      <dependency>
+        <groupId>com.fasterxml.jackson.core</groupId>
+        <artifactId>jackson-annotations</artifactId>
+        <version>${jackson-2-version}</version>
+      </dependency>
+
+      <!-- databinding; ObjectMapper, JsonNode and related classes are here -->
+      <dependency>
+        <groupId>com.fasterxml.jackson.core</groupId>
+        <artifactId>jackson-databind</artifactId>
+        <version>${jackson-2-version}</version>
+      </dependency>
+
+      <!-- smile (binary JSON). Other artifacts in this group do other formats. -->
+      <dependency>
+        <groupId>com.fasterxml.jackson.dataformat</groupId>
+        <artifactId>jackson-dataformat-smile</artifactId>
+        <version>${jackson-2-version}</version>
+      </dependency>
+      <!-- JAX-RS provider -->
+      <dependency>
+        <groupId>com.fasterxml.jackson.jaxrs</groupId>
+        <artifactId>jackson-jaxrs-json-provider</artifactId>
+        <version>${jackson-2-version}</version>
+      </dependency>
+      <!-- Support for JAX-B annotations as additional configuration -->
+      <dependency>
+        <groupId>com.fasterxml.jackson.module</groupId>
+        <artifactId>jackson-module-jaxb-annotations</artifactId>
+        <version>${jackson-2-version}</version>
+      </dependency>
+
       <!-- Other Commercial Dependencies -->
 
       <dependency>