usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [1/3] git commit: Finished serialization I/O operations and tests
Date Tue, 04 Feb 2014 12:20:39 GMT
Updated Branches:
  refs/heads/two-dot-o 50a3f748f -> 804e2df0e
Updated Tags:  refs/tags/0.0.43.r4 [created] 13dc203d5


Finished serialization I/O operations and tests


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

Branch: refs/heads/two-dot-o
Commit: 1af59d48a93051a5eb87120b31757888d76117c4
Parents: 3f1f841
Author: Todd Nine <tnine@apigee.com>
Authored: Fri Jan 31 18:16:37 2014 -0700
Committer: Todd Nine <tnine@apigee.com>
Committed: Tue Feb 4 04:06:00 2014 -0700

----------------------------------------------------------------------
 .../astyanax/IdRowCompositeSerializer.java      |   2 +
 .../persistence/graph/SearchByEdge.java         |  70 ++
 .../graph/impl/SimpleSearchByEdge.java          |  98 +++
 .../graph/serialization/EdgeSerialization.java  |  18 +-
 .../impl/EdgeSerializationImpl.java             | 659 +++++++++++++------
 .../graph/serialization/util/EdgeHasher.java    |  22 +-
 .../graph/serialization/util/EdgeUtils.java     |   1 -
 .../serialization/EdgeSerializationTest.java    |  74 ++-
 .../graph/test/util/EdgeTestUtils.java          |  35 +-
 .../persistence/model/util/UUIDGenerator.java   |   2 +-
 10 files changed, 751 insertions(+), 230 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
index 8444adc..5961196 100644
--- a/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
+++ b/stack/corepersistence/collection/src/main/java/org/apache/usergrid/persistence/collection/astyanax/IdRowCompositeSerializer.java
@@ -44,6 +44,8 @@ public class IdRowCompositeSerializer implements CompositeFieldSerializer<Id> {
 
     @Override
     public void toComposite( final CompositeBuilder builder, final Id id ) {
+        //note that this order is important.  Our default behavior is it order by time uuid, NOT by type, so we want our
+        //uuid written BEFORE the string type
         builder.addUUID( id.getUuid() );
         builder.addString( id.getType() );
     }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/SearchByEdge.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/SearchByEdge.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/SearchByEdge.java
new file mode 100644
index 0000000..565b5ce
--- /dev/null
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/SearchByEdge.java
@@ -0,0 +1,70 @@
+/*
+ * 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.usergrid.persistence.graph;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import com.google.common.base.Optional;
+
+
+/**
+ * Defines parameters for a search operation to search for a specific edge with a version
+ * <= the given version
+ *
+ * @author tnine */
+public interface SearchByEdge {
+
+    /**
+     * Get the Id of the node of this edge
+     * @return
+     */
+    Id sourceNode();
+
+
+    /**
+     * Get the id of the target node in the edge
+     * @return
+     */
+    Id targetNode();
+
+    /**
+     * Get the name of the edge
+     * @return
+     */
+    String getType();
+
+    /**
+     * Get the Maximum Version of an edge we can return.
+     * This should always be a type 1 time uuid.
+     * @return
+     */
+    UUID getMaxVersion();
+
+    /**
+     * The optional start parameter.  All edges emitted with be > the specified start edge.
+     * This is useful for paging.  Simply use the last value returned in the previous call in the start parameter
+     * @return
+     */
+    Optional<Edge> last();
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdge.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdge.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdge.java
new file mode 100644
index 0000000..d7ae830
--- /dev/null
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/impl/SimpleSearchByEdge.java
@@ -0,0 +1,98 @@
+/*
+ * 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.usergrid.persistence.graph.impl;
+
+
+import java.util.UUID;
+
+import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
+import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.SearchByEdge;
+import org.apache.usergrid.persistence.graph.SearchByEdgeType;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+import com.google.common.base.Optional;
+
+
+/**
+ * Simple bean implementation of search by edge
+ *
+ */
+public class SimpleSearchByEdge implements SearchByEdge {
+
+    private final Id sourceNode;
+    private final Id targetNode;
+    private final String type;
+    private final UUID maxVersion;
+    private final Optional<Edge> last;
+
+
+    /**
+     * Create the search modules
+     * @param sourceNode The source node of the edge
+     * @param targetNode The target node of the edge
+     * @param type The edge type
+     * @param maxVersion The maximum version to return
+     * @param last The value to start seeking from.  Must be >= this value
+     */
+    public SimpleSearchByEdge( final Id sourceNode, final String type, final Id targetNode, final UUID maxVersion, final Edge last ) {
+        ValidationUtils.verifyIdentity(sourceNode);
+        ValidationUtils.verifyIdentity(targetNode);
+        ValidationUtils.verifyString( type, "type" );
+        ValidationUtils.verifyTimeUuid( maxVersion, "maxVersion" );
+
+
+        this.sourceNode = sourceNode;
+        this.targetNode = targetNode;
+        this.type = type;
+        this.maxVersion = maxVersion;
+        this.last = Optional.fromNullable(last);
+    }
+
+
+    @Override
+    public Id sourceNode() {
+        return sourceNode;
+    }
+
+
+    @Override
+    public Id targetNode() {
+        return targetNode;
+    }
+
+
+    @Override
+    public String getType() {
+        return type;
+    }
+
+
+    @Override
+    public UUID getMaxVersion() {
+        return maxVersion;
+    }
+
+
+    @Override
+    public Optional<Edge> last() {
+        return last;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
index f6434df..6c336c2 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerialization.java
@@ -24,6 +24,7 @@ import java.util.Iterator;
 
 import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.SearchByEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
 import org.apache.usergrid.persistence.graph.SearchByIdType;
 
@@ -53,6 +54,13 @@ public interface EdgeSerialization {
      */
     MutationBatch deleteEdge( OrganizationScope scope, Edge edge );
 
+
+    /**
+     * Search for specific versions of the edge from source->target. Will return all versions
+     *
+     */
+    Iterator<Edge> getEdgeFromSource( OrganizationScope scope, SearchByEdge search );
+
     /**
      * Get an iterator of all edges by edge type originating from source node
      *
@@ -72,15 +80,21 @@ public interface EdgeSerialization {
 
     /**
      * Get an iterator of all edges by edge type pointing to the target node
+     *
      * @param scope The org scope of the graph
      * @param edgeType The search edge
      */
     Iterator<Edge> getEdgesToTarget( OrganizationScope scope, SearchByEdgeType edgeType );
 
+    /**
+     * Search for specific versions of the edge from source->target. Will return all versions
+     */
+    Iterator<Edge> getEdgeToTarget( OrganizationScope scope, SearchByEdge search );
+
 
     /**
-     * Get an iterator of all edges by edge type pointing to the target node.  Also uses the source id
-     * type to limit the results
+     * Get an iterator of all edges by edge type pointing to the target node.  Also uses the source id type to limit the
+     * results
      *
      * @param scope The org scope of the graph
      * @param edgeType The search edge

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
index a726e3e..522d4c1 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/impl/EdgeSerializationImpl.java
@@ -32,6 +32,7 @@ import org.apache.cassandra.db.marshal.BytesType;
 
 import org.apache.usergrid.persistence.astyanax.IdColDynamicCompositeSerializer;
 import org.apache.usergrid.persistence.collection.OrganizationScope;
+import org.apache.usergrid.persistence.collection.astyanax.CompositeFieldSerializer;
 import org.apache.usergrid.persistence.collection.astyanax.IdRowCompositeSerializer;
 import org.apache.usergrid.persistence.collection.astyanax.MultiTennantColumnFamily;
 import org.apache.usergrid.persistence.collection.astyanax.MultiTennantColumnFamilyDefinition;
@@ -40,6 +41,7 @@ import org.apache.usergrid.persistence.collection.cassandra.ColumnTypes;
 import org.apache.usergrid.persistence.collection.migration.Migration;
 import org.apache.usergrid.persistence.collection.mvcc.entity.ValidationUtils;
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.SearchByEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
 import org.apache.usergrid.persistence.graph.SearchByIdType;
 import org.apache.usergrid.persistence.graph.impl.SimpleEdge;
@@ -55,12 +57,12 @@ import com.google.inject.Singleton;
 import com.netflix.astyanax.Keyspace;
 import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
-import com.netflix.astyanax.model.ByteBufferRange;
 import com.netflix.astyanax.model.Column;
+import com.netflix.astyanax.model.CompositeBuilder;
+import com.netflix.astyanax.model.CompositeParser;
 import com.netflix.astyanax.model.DynamicComposite;
 import com.netflix.astyanax.query.RowQuery;
 import com.netflix.astyanax.serializers.AbstractSerializer;
-import com.netflix.astyanax.serializers.LongSerializer;
 import com.netflix.astyanax.serializers.UUIDSerializer;
 import com.netflix.astyanax.util.RangeBuilder;
 
@@ -78,54 +80,51 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
     //holder to put data into col value
     private static final byte[] HOLDER = new byte[] { 0 };
 
-    //row key serializers
-    private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
-    private static final OrganizationScopedRowKeySerializer<Id> ORG_ROW_KEY_SER =
-            new OrganizationScopedRowKeySerializer<Id>( ID_SER );
+    //Row key with no type
+    private static final RowSerializer ROW_SERIALIZER = new RowSerializer();
+
+    //row key with target id type
+    private static final RowTypeSerializer ROW_TYPE_SERIALIZER = new RowTypeSerializer();
 
     //Edge serializers
-    private static final EdgeTypeSerializer EDGE_TYPE_SERIALIZER = new EdgeTypeSerializer();
+    private static final EdgeSerializer EDGE_SERIALIZER = new EdgeSerializer();
 
-    private static final EdgeTypeIdSerializer EDGE_TYPE_ID_SERIALIZER = new EdgeTypeIdSerializer();
 
 
     // column families
     /**
      * Edges that are from the source node. The row key is the source node
      */
-    private static final MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge> GRAPH_SOURCE_NODE_EDGES =
-            new MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge>( "Graph_Source_Node_Edges",
-                    ORG_ROW_KEY_SER, EDGE_TYPE_SERIALIZER );
+    private static final MultiTennantColumnFamily<OrganizationScope, RowKey, DirectedEdge> GRAPH_SOURCE_NODE_EDGES =
+            new MultiTennantColumnFamily<OrganizationScope, RowKey, DirectedEdge>( "Graph_Source_Node_Edges",
+                    new OrganizationScopedRowKeySerializer<RowKey>( ROW_SERIALIZER ), EDGE_SERIALIZER );
 
 
     /**
      * Edges that are incoming to the target node.  The target node is the row key
      */
-    private static final MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge> GRAPH_TARGET_NODE_EDGES =
-            new MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge>( "Graph_Target_Node_Edges",
-                    ORG_ROW_KEY_SER, EDGE_TYPE_SERIALIZER );
+    private static final MultiTennantColumnFamily<OrganizationScope, RowKey, DirectedEdge> GRAPH_TARGET_NODE_EDGES =
+            new MultiTennantColumnFamily<OrganizationScope, RowKey, DirectedEdge>( "Graph_Target_Node_Edges",
+                    new OrganizationScopedRowKeySerializer<RowKey>( ROW_SERIALIZER ), EDGE_SERIALIZER );
 
 
     /**
      * The edges that are from the source node with target type.  The source node is the row key.
      */
-    private static final MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge> GRAPH_SOURCE_NODE_TARGET_TYPE =
-            new MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge>( "Graph_Source_Node_Target_Type",
-                    ORG_ROW_KEY_SER, EDGE_TYPE_ID_SERIALIZER );
+    private static final MultiTennantColumnFamily<OrganizationScope, RowKeyType, DirectedEdge>
+            GRAPH_SOURCE_NODE_TARGET_TYPE =
+            new MultiTennantColumnFamily<OrganizationScope, RowKeyType, DirectedEdge>( "Graph_Source_Node_Target_Type",
+                    new OrganizationScopedRowKeySerializer<RowKeyType>( ROW_TYPE_SERIALIZER ), EDGE_SERIALIZER );
 
 
     /**
      * The edges that are to the target node with the source type.  The target node is the row key
      */
-    private static final MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge> GRAPH_TARGET_NODE_SOURCE_TYPE =
-            new MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge>( "Graph_Target_Node_Source_Type",
-                    ORG_ROW_KEY_SER, EDGE_TYPE_ID_SERIALIZER );
-
+    private static final MultiTennantColumnFamily<OrganizationScope, RowKeyType, DirectedEdge>
+            GRAPH_TARGET_NODE_SOURCE_TYPE =
+            new MultiTennantColumnFamily<OrganizationScope, RowKeyType, DirectedEdge>( "Graph_Target_Node_Source_Type",
+                    new OrganizationScopedRowKeySerializer<RowKeyType>( ROW_TYPE_SERIALIZER ), EDGE_SERIALIZER );
 
-    //edge creators for seeking in either direction
-    private static final SourceDirectedEdgeCreator SOURCE_DIRECTED_EDGE_CREATOR = new SourceDirectedEdgeCreator();
-
-    private static final TargetDirectedEdgeCreator TARGET_DIRECTED_EDGE_CREATOR = new TargetDirectedEdgeCreator();
 
     protected final Keyspace keyspace;
 
@@ -138,133 +137,294 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
     @Override
     public MutationBatch writeEdge( final OrganizationScope scope, final Edge edge ) {
-        ValidationUtils.validateOrganizationScope( scope );
-        EdgeUtils.validateEdge( edge );
-
         final MutationBatch batch = keyspace.prepareMutationBatch();
 
-        final String edgeTypeName = edge.getType();
-        final Id sourceNodeId = edge.getSourceNode();
-        final Id targetNodeId = edge.getTargetNode();
-        final UUID version = edge.getVersion();
-
 
-        /**
-         * Edge from source->target
-         */
-        final ScopedRowKey<OrganizationScope, Id> sourceKey =
-                new ScopedRowKey<OrganizationScope, Id>( scope, sourceNodeId );
+        doWrite( scope, edge, new RowOp() {
+            @Override
+            public void doWrite( final MultiTennantColumnFamily columnFamily, final Object rowKey,
+                                 final DirectedEdge edge ) {
 
+                batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).putColumn( edge, HOLDER );
+            }
+        } );
 
-        final DirectedEdge sourceEdge = new DirectedEdge( edgeTypeName, targetNodeId, version );
 
-
-        /**
-         * Edge of target<-source
-         */
-        final ScopedRowKey<OrganizationScope, Id> targetKey =
-                new ScopedRowKey<OrganizationScope, Id>( scope, targetNodeId );
-
-        final DirectedEdge targetEdge = new DirectedEdge( edgeTypeName, sourceNodeId, version );
+        return batch;
+    }
 
 
-        //TODO T.N Resume here
-        /**
-         * Write edges from target<-source
-         */
-        batch.withRow( GRAPH_SOURCE_NODE_EDGES, sourceKey ).putColumn( sourceEdge, HOLDER );
+    @Override
+    public MutationBatch deleteEdge( final OrganizationScope scope, final Edge edge ) {
+        final MutationBatch batch = keyspace.prepareMutationBatch();
 
-        batch.withRow( GRAPH_SOURCE_NODE_TARGET_TYPE, sourceKey ).putColumn( sourceEdge, HOLDER );
 
-        /**
-         * Write edges source->target
-         */
+        doWrite( scope, edge, new RowOp() {
+            @Override
+            public void doWrite( final MultiTennantColumnFamily columnFamily, final Object rowKey,
+                                 final DirectedEdge edge ) {
 
-        batch.withRow( GRAPH_TARGET_NODE_EDGES, targetKey ).putColumn( targetEdge, HOLDER );
+                batch.withRow( columnFamily, ScopedRowKey.fromKey( scope, rowKey ) ).deleteColumn( edge );
+            }
+        } );
 
-        batch.withRow( GRAPH_TARGET_NODE_SOURCE_TYPE, targetKey ).putColumn( targetEdge, HOLDER );
 
         return batch;
     }
 
 
     @Override
-    public MutationBatch deleteEdge( final OrganizationScope scope, final Edge edge ) {
+    public Iterator<Edge> getEdgeFromSource( final OrganizationScope scope, final SearchByEdge search ) {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
 
+    private void doWrite( final OrganizationScope scope, final Edge edge, final RowOp op ) {
         ValidationUtils.validateOrganizationScope( scope );
         EdgeUtils.validateEdge( edge );
 
         final MutationBatch batch = keyspace.prepareMutationBatch();
-
-        final String edgeTypeName = edge.getType();
         final Id sourceNodeId = edge.getSourceNode();
         final Id targetNodeId = edge.getTargetNode();
         final UUID version = edge.getVersion();
+        final String type = edge.getType();
 
 
         /**
-         * Edge from source->target
+         * Key in the serializers based on the edge
          */
-        final ScopedRowKey<OrganizationScope, Id> sourceKey =
-                new ScopedRowKey<OrganizationScope, Id>( scope, sourceNodeId );
 
+        final RowKey sourceRowKey = new RowKey( sourceNodeId, type );
 
-        final DirectedEdge sourceEdge = new DirectedEdge( edgeTypeName, targetNodeId, version );
+        final RowKeyType sourceRowKeyType = new RowKeyType( sourceNodeId, type, targetNodeId );
 
+        final DirectedEdge sourceEdge = new DirectedEdge( targetNodeId, version );
 
-        /**
-         * Edge of target<-source
-         */
-        final ScopedRowKey<OrganizationScope, Id> targetKey =
-                new ScopedRowKey<OrganizationScope, Id>( scope, targetNodeId );
 
-        final DirectedEdge targetEdge = new DirectedEdge( edgeTypeName, sourceNodeId, version );
+        final RowKey targetRowKey = new RowKey( targetNodeId, type );
 
+        final RowKeyType targetRowKeyType = new RowKeyType( targetNodeId, type, sourceNodeId );
 
-        /**
-         * Write edges from source->target
-         */
-        batch.withRow( GRAPH_SOURCE_NODE_EDGES, sourceKey ).deleteColumn( sourceEdge );
+        final DirectedEdge targetEdge = new DirectedEdge( sourceNodeId, version );
 
-        batch.withRow( GRAPH_SOURCE_NODE_TARGET_TYPE, sourceKey ).deleteColumn( sourceEdge );
 
         /**
-         * Write edges target<- source
+         * Write edges from target<-source
          */
 
-        batch.withRow( GRAPH_TARGET_NODE_EDGES, targetKey ).deleteColumn( targetEdge );
 
-        batch.withRow( GRAPH_TARGET_NODE_SOURCE_TYPE, targetKey ).deleteColumn( targetEdge );
+        op.doWrite( GRAPH_SOURCE_NODE_EDGES, sourceRowKey, sourceEdge );
 
-        return batch;
+        op.doWrite( GRAPH_SOURCE_NODE_TARGET_TYPE, sourceRowKeyType, sourceEdge );
+
+        op.doWrite( GRAPH_TARGET_NODE_EDGES, targetRowKey, targetEdge );
+
+        op.doWrite( GRAPH_TARGET_NODE_SOURCE_TYPE, targetRowKeyType, targetEdge );
     }
 
 
     @Override
     public Iterator<Edge> getEdgesFromSource( final OrganizationScope scope, final SearchByEdgeType edgeType ) {
-        return getEdges( scope, edgeType, GRAPH_SOURCE_NODE_EDGES, EDGE_TYPE_SERIALIZER, TARGET_DIRECTED_EDGE_CREATOR, new SourceEdgeColumnParser( edgeType ) );
+
+        ValidationUtils.validateOrganizationScope( scope );
+        EdgeUtils.validateSearchByEdgeType( edgeType );
+
+        final Id sourceId = edgeType.getNode();
+        final String type = edgeType.getType();
+
+        return getEdges( scope, GRAPH_SOURCE_NODE_EDGES, new EdgeSearcher<RowKey>() {
+
+            @Override
+            public void setRange( final RangeBuilder builder ) {
+
+                //set our start range since it was supplied to us
+                if ( edgeType.last().isPresent() ) {
+
+                    final Edge edge = edgeType.last().get();
+                    DirectedEdge sourceEdge = new DirectedEdge( edge.getTargetNode(), edge.getVersion() );
+
+                    builder.setStart( sourceEdge, EDGE_SERIALIZER );
+                }
+            }
+
+
+            @Override
+            public ScopedRowKey<OrganizationScope, RowKey> getRowKey() {
+                final RowKey sourceRowKey = new RowKey( sourceId, type );
+
+                return ScopedRowKey.fromKey( scope, sourceRowKey );
+            }
+
+
+            @Override
+            public boolean hasPage() {
+                return edgeType.last().isPresent();
+            }
+
+
+            @Override
+            public Edge parseColumn( final Column<DirectedEdge> column ) {
+                final DirectedEdge edge = column.getName();
+
+                return new SimpleEdge( sourceId, type, edge.id, edge.version );
+            }
+        } );
     }
 
 
     @Override
     public Iterator<Edge> getEdgesFromSourceByTargetType( final OrganizationScope scope,
                                                           final SearchByIdType edgeType ) {
-        return getEdges( scope, edgeType, GRAPH_SOURCE_NODE_TARGET_TYPE, EDGE_TYPE_SERIALIZER,
-                SOURCE_DIRECTED_EDGE_CREATOR,  new SourceEdgeColumnParser( edgeType ) );
+
+        ValidationUtils.validateOrganizationScope( scope );
+        EdgeUtils.validateSearchByEdgeType( edgeType );
+
+        final Id targetId = edgeType.getNode();
+        final String type = edgeType.getType();
+        final String targetType = edgeType.getIdType();
+
+        return getEdges( scope, GRAPH_SOURCE_NODE_TARGET_TYPE, new EdgeSearcher<RowKeyType>() {
+
+            @Override
+            public void setRange( final RangeBuilder builder ) {
+
+                //set our start range since it was supplied to us
+                if ( edgeType.last().isPresent() ) {
+
+                    final Edge edge = edgeType.last().get();
+                    DirectedEdge sourceEdge = new DirectedEdge( edge.getTargetNode(), edge.getVersion() );
+
+                    builder.setStart( sourceEdge, EDGE_SERIALIZER );
+                }
+            }
+
+
+            @Override
+            public ScopedRowKey<OrganizationScope, RowKeyType> getRowKey() {
+                final RowKeyType sourceRowKey = new RowKeyType( targetId, type, targetType);
+
+                return ScopedRowKey.fromKey( scope, sourceRowKey );
+            }
+
+
+            @Override
+            public boolean hasPage() {
+                return edgeType.last().isPresent();
+            }
+
+
+            @Override
+            public Edge parseColumn( final Column<DirectedEdge> column ) {
+                final DirectedEdge edge = column.getName();
+
+                return new SimpleEdge( targetId, type, edge.id, edge.version );
+            }
+        } );
     }
 
 
     @Override
     public Iterator<Edge> getEdgesToTarget( final OrganizationScope scope, final SearchByEdgeType edgeType ) {
-        return getEdges( scope, edgeType, GRAPH_TARGET_NODE_EDGES, EDGE_TYPE_ID_SERIALIZER,
-                SOURCE_DIRECTED_EDGE_CREATOR,  new TargetEdgeColumnParser( edgeType ) );
+
+        ValidationUtils.validateOrganizationScope( scope );
+        EdgeUtils.validateSearchByEdgeType( edgeType );
+
+        final Id targetId = edgeType.getNode();
+        final String type = edgeType.getType();
+
+        return getEdges( scope, GRAPH_TARGET_NODE_EDGES, new EdgeSearcher<RowKey>() {
+
+            @Override
+            public void setRange( final RangeBuilder builder ) {
+
+                //set our start range since it was supplied to us
+                if ( edgeType.last().isPresent() ) {
+
+                    final Edge edge = edgeType.last().get();
+                    DirectedEdge sourceEdge = new DirectedEdge( edge.getSourceNode(), edge.getVersion() );
+
+                    builder.setStart( sourceEdge, EDGE_SERIALIZER );
+                }
+            }
+
+
+            @Override
+            public ScopedRowKey<OrganizationScope, RowKey> getRowKey() {
+                final RowKey sourceRowKey = new RowKey( targetId, type );
+
+                return ScopedRowKey.fromKey( scope, sourceRowKey );
+            }
+
+
+            @Override
+            public boolean hasPage() {
+                return edgeType.last().isPresent();
+            }
+
+
+            @Override
+            public Edge parseColumn( final Column<DirectedEdge> column ) {
+                final DirectedEdge edge = column.getName();
+
+                return new SimpleEdge( edge.id,  type, targetId, edge.version );
+            }
+        } );
+    }
+
+
+    @Override
+    public Iterator<Edge> getEdgeToTarget( final OrganizationScope scope, final SearchByEdge search ) {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
     }
 
 
     @Override
     public Iterator<Edge> getEdgesToTargetBySourceType( final OrganizationScope scope, final SearchByIdType edgeType ) {
-        return getEdges( scope, edgeType, GRAPH_TARGET_NODE_SOURCE_TYPE, EDGE_TYPE_ID_SERIALIZER,
-                TARGET_DIRECTED_EDGE_CREATOR,  new TargetEdgeColumnParser( edgeType ) );
+
+        ValidationUtils.validateOrganizationScope( scope );
+        EdgeUtils.validateSearchByEdgeType( edgeType );
+
+        final Id targetId = edgeType.getNode();
+        final String sourceType = edgeType.getIdType();
+        final String type = edgeType.getType();
+
+        return getEdges( scope, GRAPH_TARGET_NODE_SOURCE_TYPE, new EdgeSearcher<RowKeyType>() {
+
+            @Override
+            public void setRange( final RangeBuilder builder ) {
+
+                //set our start range since it was supplied to us
+                if ( edgeType.last().isPresent() ) {
+
+                    final Edge edge = edgeType.last().get();
+                    DirectedEdge sourceEdge = new DirectedEdge( edge.getTargetNode(), edge.getVersion() );
+
+                    builder.setStart( sourceEdge, EDGE_SERIALIZER );
+                }
+            }
+
+
+            @Override
+            public ScopedRowKey<OrganizationScope, RowKeyType> getRowKey() {
+                final RowKeyType sourceRowKey = new RowKeyType( targetId, type, sourceType );
+
+                return ScopedRowKey.fromKey( scope, sourceRowKey );
+            }
+
+
+            @Override
+            public boolean hasPage() {
+                return edgeType.last().isPresent();
+            }
+
+
+            @Override
+            public Edge parseColumn( final Column<DirectedEdge> column ) {
+                final DirectedEdge edge = column.getName();
+
+                return new SimpleEdge( targetId, type, edge.id, edge.version );
+            }
+        } );
     }
 
 
@@ -272,58 +432,36 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
      * Get the edges with the specified criteria
      *
      * @param scope The organization scope
-     * @param edgeType The search type
      * @param cf The column familiy to search
-     * @param edgeSerializer The serializer to use when reading columns
-     * @param directedEdgeCreator The creator to use when creating the edges for searching
-     * @param edgeColumnParser The parser to user when iterating the columns
      *
      * @return An iterator of all Edge instance that match the criteria
      */
-    private Iterator<Edge> getEdges( final OrganizationScope scope, final SearchByEdgeType edgeType,
-                                     MultiTennantColumnFamily<OrganizationScope, Id, DirectedEdge> cf,
-                                     final EdgeSerializer edgeSerializer,
-                                     final DirectedEdgeCreator directedEdgeCreator,
-                                     final EdgeColumnParser edgeColumnParser) {
-        ValidationUtils.validateOrganizationScope( scope );
-        EdgeUtils.validateSearchByEdgeType( edgeType );
-
-
-        final String edgeTypeName = edgeType.getType();
-        final Id nodeId = edgeType.getNode();
-        final UUID version = edgeType.getMaxVersion();
+    private <R> Iterator<Edge> getEdges( final OrganizationScope scope,
+                                         MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> cf,
+                                         final EdgeSearcher<R> searcher ) {
 
 
         /**
-         * Edge from source->target
+         * If the edge is present, we need to being seeking from this
          */
-        final ScopedRowKey<OrganizationScope, Id> rowkey = new ScopedRowKey<OrganizationScope, Id>( scope, nodeId );
 
+        final RangeBuilder rangeBuilder = new RangeBuilder().setLimit( PAGE_SIZE );
 
-        DirectedEdge lastEdge;
 
-        /**
-         * If the edge is present, we need to being seeking from this
-         */
-        if ( edgeType.last().isPresent() ) {
-            lastEdge = directedEdgeCreator.getDirectedEdge( edgeType.last().get() );
-        }
-        else {
-            lastEdge = new DirectedEdge( edgeTypeName, nodeId, version );
-        }
+        //set the range into the search
+        searcher.setRange( rangeBuilder );
 
+        final ScopedRowKey<OrganizationScope, R> rowKey = searcher.getRowKey();
 
-        //resume from the last if specified.  Also set the range
-        final ByteBufferRange searchRange =
-                new RangeBuilder().setLimit( PAGE_SIZE ).setStart( lastEdge, edgeSerializer ).build();
 
-        RowQuery<ScopedRowKey<OrganizationScope, Id>, DirectedEdge> query =
-                keyspace.prepareQuery( cf ).getKey( rowkey ).autoPaginate( true ).withColumnRange( searchRange );
+        RowQuery<ScopedRowKey<OrganizationScope, R>, DirectedEdge> query =
+                keyspace.prepareQuery( cf ).getKey( rowKey ).autoPaginate( true )
+                        .withColumnRange( rangeBuilder.build() );
 
 
         try {
-            return new ColumnNameIterator<DirectedEdge, Edge>( query.execute().getResult().iterator(),
-                   edgeColumnParser, edgeType.last().isPresent() );
+            return new ColumnNameIterator<DirectedEdge, Edge>( query.execute().getResult().iterator(), searcher,
+                    searcher.hasPage() );
         }
         catch ( ConnectionException e ) {
             throw new RuntimeException( "Unable to connect to cassandra", e );
@@ -348,32 +486,41 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
 
 
     /**
+     * Internal class to represent edge data for serialization
+     */
+    private static class DirectedEdge {
+
+        public final UUID version;
+        public final Id id;
+
+
+        private DirectedEdge( final Id id, final UUID version ) {
+            this.version = version;
+            this.id = id;
+        }
+    }
+
+
+    /**
      * Serializes to a source->target edge Note that we cannot set the edge type on de-serialization.  Only the target
      * Id and version.
      */
-    private static abstract class EdgeSerializer extends AbstractSerializer<DirectedEdge> {
+    private static class EdgeSerializer extends AbstractSerializer<DirectedEdge> {
 
         private static final IdColDynamicCompositeSerializer ID_COL_SERIALIZER = IdColDynamicCompositeSerializer.get();
 
         private static final UUIDSerializer UUID_SERIALIZER = UUIDSerializer.get();
-        private static final LongSerializer LONG_SERIALIZER = LongSerializer.get();
 
 
         @Override
         public ByteBuffer toByteBuffer( final DirectedEdge edge ) {
-            final long[] targetEdgeTypes = getHash( edge );
-
-
             DynamicComposite composite = new DynamicComposite();
 
-            composite.addComponent( targetEdgeTypes[0], LONG_SERIALIZER );
-            composite.addComponent( targetEdgeTypes[1], LONG_SERIALIZER );
-
+            ID_COL_SERIALIZER.toComposite( composite, edge.id );
 
+            //add our edge
             composite.addComponent( edge.version, UUID_SERIALIZER );
 
-            ID_COL_SERIALIZER.toComposite( composite, edge.id );
-
             return composite.serialize();
         }
 
@@ -382,172 +529,256 @@ public class EdgeSerializationImpl implements EdgeSerialization, Migration {
         public DirectedEdge fromByteBuffer( final ByteBuffer byteBuffer ) {
             DynamicComposite composite = DynamicComposite.fromByteBuffer( byteBuffer );
 
+            Preconditions.checkArgument( composite.size() == 3, "Composite should have 3 elements" );
+
 
-            Preconditions.checkArgument( composite.size() == 5, "Composite should have 5 elements" );
+            //parse our id
+            final Id id = ID_COL_SERIALIZER.fromComposite( composite, 0 );
 
+            //return the version
             final UUID version = composite.get( 2, UUID_SERIALIZER );
 
-            final Id id = ID_COL_SERIALIZER.fromComposite( composite, 3 );
+
+            return new DirectedEdge( id, version );
+        }
+    }
+
+
+    /**
+     * Class that represents an edge row key
+     */
+    private static class RowKey {
+        public final Id nodeId;
+        public final long[] hash;
 
 
-            return new DirectedEdge( null, id, version );
+        /**
+         * Create a row key with the node and the edgeType
+         */
+        public RowKey( Id nodeId, String edgeType ) {
+            this( nodeId, EdgeHasher.createEdgeHash( edgeType ) );
         }
 
 
         /**
-         * Get the hashes for the edge
+         * Create a new row key with the hash, should only be used in deserialization or internal callers.
          */
-        protected abstract long[] getHash( DirectedEdge edge );
+        protected RowKey( Id nodeId, long[] hash ) {
+            this.nodeId = nodeId;
+            this.hash = hash;
+        }
     }
 
 
-    /**
-     * Edge type serializer
-     */
-    private static class EdgeTypeSerializer extends EdgeSerializer {
+    private static class RowKeyType extends RowKey {
 
-        @Override
-        protected long[] getHash( final DirectedEdge edge ) {
-            return EdgeHasher.createEdgeHash( edge.type );
+        /**
+         * Create a row key with the node id in the row key, the edge type, and the type from the typeid
+         *
+         * @param nodeId The node id in the row key
+         * @param edgeType The type of the edge
+         * @param typeId The type of hte id
+         */
+        public RowKeyType( final Id nodeId, final String edgeType, final Id typeId ) {
+            this( nodeId, edgeType, typeId.getType() );
         }
-    }
 
 
-    /**
-     * Edge type serializer
-     */
-    private static class EdgeTypeIdSerializer extends EdgeSerializer {
+        /**
+         * Create a row key with the node id in the row key, the edge type, adn the target type from the id
+         */
+        public RowKeyType( final Id nodeId, final String edgeType, final String targetType ) {
+            super( nodeId, EdgeHasher.createEdgeHash( edgeType, targetType ) );
+        }
 
-        @Override
-        protected long[] getHash( final DirectedEdge edge ) {
-            return EdgeHasher.createEdgeHash( edge.type, edge.id );
+
+        /**
+         * Internal use in de-serializing.  Should only be used in this case or by internal callers
+         */
+        private RowKeyType( final Id nodeId, final long[] hash ) {
+            super( nodeId, hash );
         }
     }
 
 
     /**
-     * Internal class to represent edge data for serialization
+     * Simple parser to parse column names
      */
-    private static class DirectedEdge {
+    private interface EdgeSearcher<R> extends ColumnParser<DirectedEdge, Edge> {
 
-        public final String type;
-        public final UUID version;
-        public final Id id;
 
+        /**
+         * Set the range on a search
+         */
+        public void setRange( RangeBuilder builder );
 
-        private DirectedEdge( final String type, final Id id, final UUID version ) {
-            this.type = type;
-            this.version = version;
-            this.id = id;
-        }
+        /**
+         * Get the row key to be used for the search
+         */
+        public abstract ScopedRowKey<OrganizationScope, R> getRowKey();
+
+        /**
+         * Return true if the search has a page value, meaning we should skip the first value
+         *
+         * @return true if there is an element in the page
+         */
+        public boolean hasPage();
+
+
+        //        protected abstract Edge buildEdge( final Id rowKeyId, final String edgeType, final Id colId,
+        //                                           final UUID version );
     }
 
+    //
+    //    /**
+    //     * Creator from source->target
+    //     */
+    //    private static class SourceEdgeColumnParser extends EdgeSearcher {
+    //
+    //
+    //        /**
+    //         * Default constructor. Needs to take the id and edge used in the search
+    //         */
+    //        protected SourceEdgeColumnParser( final SearchByEdgeType searchByEdgeType ) {
+    //            super( searchByEdgeType );
+    //        }
+    //
+    //
+    //        @Override
+    //        protected Edge buildEdge( final Id rowKeyId, final String edgeType, final Id colId, final UUID version ) {
+    //            return new SimpleEdge( rowKeyId, edgeType, colId, version );
+    //        }
+    //    }
+
 
     /**
-     * Simple parser to parse column names
+     * Class to perform serialization for row keys from edges
      */
-    private abstract static class EdgeColumnParser implements ColumnParser<DirectedEdge, Edge> {
+    private static class RowSerializer implements CompositeFieldSerializer<RowKey> {
 
-        private final Id id;
-        private final String edgeType;
+        private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
 
 
-        /**
-         * Default constructor. Needs to take the id and edge used in the search
-         */
-        protected EdgeColumnParser( SearchByEdgeType searchByEdgeType ) {
-            this.id = searchByEdgeType.getNode();
-            this.edgeType = searchByEdgeType.getType();
+        @Override
+        public void toComposite( final CompositeBuilder builder, final RowKey key ) {
+
+            //add the row id to the composite
+            ID_SER.toComposite( builder, key.nodeId );
+
+            builder.addLong( key.hash[0] );
+            builder.addLong( key.hash[1] );
         }
 
 
         @Override
-        public Edge parseColumn( final Column<DirectedEdge> column ) {
+        public RowKey fromComposite( final CompositeParser composite ) {
 
-            final DirectedEdge edge = column.getName();
+            final Id id = ID_SER.fromComposite( composite );
+            long[] hash = new long[] { composite.readLong(), composite.readLong() };
 
-            return buildEdge( id, edgeType, edge.id, edge.version );
+            return new RowKey( id, hash );
         }
-
-
-        protected abstract Edge buildEdge( final Id rowKeyId, final String edgeType, final Id colId,
-                                           final UUID version );
     }
 
 
     /**
-     * Creator from source->target
+     * Class to perform serialization for row keys from edges
      */
-    private static class SourceEdgeColumnParser extends EdgeColumnParser {
+    private static class RowTypeSerializer implements CompositeFieldSerializer<RowKeyType> {
 
+        private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
 
-        /**
-         * Default constructor. Needs to take the id and edge used in the search
-         */
-        protected SourceEdgeColumnParser( final SearchByEdgeType searchByEdgeType ) {
-            super( searchByEdgeType );
+
+        @Override
+        public void toComposite( final CompositeBuilder builder, final RowKeyType keyType ) {
+
+            //add the row id to the composite
+            ID_SER.toComposite( builder, keyType.nodeId );
+
+            builder.addLong( keyType.hash[0] );
+            builder.addLong( keyType.hash[1] );
         }
 
 
         @Override
-        protected Edge buildEdge( final Id rowKeyId, final String edgeType, final Id colId, final UUID version ) {
-            return new SimpleEdge( rowKeyId, edgeType, colId, version );
+        public RowKeyType fromComposite( final CompositeParser composite ) {
+
+            final Id id = ID_SER.fromComposite( composite );
+            long[] hash = new long[] { composite.readLong(), composite.readLong() };
+
+            return new RowKeyType( id, hash );
         }
     }
 
 
     /**
-     * Creator from target<-source
+     * Serializes the row key by sourceId, edge type
      */
-    private static class TargetEdgeColumnParser extends EdgeColumnParser {
+    private static class SourceRowSerializer extends RowSerializer {
 
+        private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
 
-        /**
-         * Default constructor. Needs to take the id and edge used in the search
-         */
-        protected TargetEdgeColumnParser( final SearchByEdgeType searchByEdgeType ) {
-            super( searchByEdgeType );
+
+        protected long[] hash( Edge e ) {
+            return EdgeHasher.createEdgeHash( e.getType() );
         }
 
 
-        @Override
-        protected Edge buildEdge( final Id rowKeyId, final String edgeType, final Id colId, final UUID version ) {
-            return new SimpleEdge( colId, edgeType, rowKeyId, version );
+        protected Id getRowId( Edge e ) {
+            return e.getSourceNode();
         }
     }
 
 
-    private static interface DirectedEdgeCreator {
+    /**
+     * Serializes the row key by sourceId, edge type, and target node type
+     */
+    private static class SourceRowTypeSerializer extends SourceRowSerializer {
 
-        /**
-         * @param last The last edge
-         *
-         * @return The edge to use when searching
-         */
-        DirectedEdge getDirectedEdge( Edge last );
+        @Override
+        protected long[] hash( final Edge e ) {
+            return EdgeHasher.createEdgeHash( e.getType(), e.getTargetNode() );
+        }
     }
 
 
     /**
-     * Source->Target directed edge
+     * Serializes the row key by targetId, edge type
      */
-    private static class SourceDirectedEdgeCreator implements DirectedEdgeCreator {
+    private static class TargetRowSerializer extends RowSerializer {
 
-        @Override
-        public DirectedEdge getDirectedEdge( final Edge last ) {
-            return new DirectedEdge( last.getType(), last.getTargetNode(), last.getVersion() );
+        private static final IdRowCompositeSerializer ID_SER = IdRowCompositeSerializer.get();
+
+
+        protected long[] hash( Edge e ) {
+            return EdgeHasher.createEdgeHash( e.getType() );
+        }
+
+
+        protected Id getRowId( Edge e ) {
+            return e.getTargetNode();
         }
     }
 
 
     /**
-     * Source->Target directed edge
+     * Serializes the row key by targetId, edge type, and source node type
      */
-    private static class TargetDirectedEdgeCreator implements DirectedEdgeCreator {
+    private static class TargetRowTypeSerializer extends SourceRowSerializer {
 
         @Override
-        public DirectedEdge getDirectedEdge( final Edge last ) {
-            return new DirectedEdge( last.getType(), last.getSourceNode(), last.getVersion() );
+        protected long[] hash( final Edge e ) {
+            return EdgeHasher.createEdgeHash( e.getType(), e.getSourceNode() );
         }
     }
+
+
+    /**
+     * Simple callback to perform puts and deletes with a common row setup code
+     */
+    private static interface RowOp<R> {
+
+        void doWrite( final MultiTennantColumnFamily<OrganizationScope, R, DirectedEdge> columnFamily, R rowKey,
+                      DirectedEdge edge );
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasher.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasher.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasher.java
index 717773c..b90aae1 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasher.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeHasher.java
@@ -39,27 +39,39 @@ public class EdgeHasher {
 
 
     /**
-     * Create a UUID based on the edge type and the type of the id that will be inserted into the column
+     * Create a hash based on the edge type and the type of the id that will be inserted into the column
      *
      *
      * @param edgeType The name of the edge type
      * @param idForColumn The id of the value that will be in the column
      *
-     * @return A UUID that represents a consistent one way hash of the fields
+     * @return A hash that represents a consistent one way hash of the fields
      */
     public static long[] createEdgeHash( final String edgeType, final Id idForColumn ) {
 
+        return createEdgeHash( edgeType, idForColumn.getType() );
+    }
+
+
+    /**
+     * Create the edge hash from the edge type and id type
+     * @param edgeType
+     * @param idType
+     * @return
+     */
+    public static long[] createEdgeHash(final String edgeType, final String idType){
+
         final String hashString =
-                new StringBuilder( edgeType ).append( idForColumn.getType() ).toString();
+                new StringBuilder( edgeType ).append(idType ).toString();
 
         return createEdgeHash( hashString );
     }
 
 
     /**
-     * Create a UUID based on the edge type and the type of the id that will be inserted into the column
+     * Create a ash based on the edge type and the type of the id that will be inserted into the column
      *
-     * @return A UUID that represents a consistent one way hash of the fields
+     * @return A hash that represents a consistent one way hash of the fields
      */
     public static long[] createEdgeHash( final String edgeType ) {
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeUtils.java b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeUtils.java
index 0979d95..2dc7ba7 100644
--- a/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeUtils.java
+++ b/stack/corepersistence/graph/src/main/java/org/apache/usergrid/persistence/graph/serialization/util/EdgeUtils.java
@@ -79,7 +79,6 @@ public class EdgeUtils {
 
         ValidationUtils.verifyIdentity( search.getNode() );
         ValidationUtils.verifyString( search.getType(), "type" );
-        ValidationUtils.verifyTimeUuid( search.getMaxVersion(), "version" );
 
         //only validate if the value is present
         if(search.last().isPresent()){

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
index 5bee908..8cee1e0 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/serialization/EdgeSerializationTest.java
@@ -16,6 +16,7 @@ import org.apache.usergrid.persistence.collection.OrganizationScope;
 import org.apache.usergrid.persistence.collection.cassandra.CassandraRule;
 import org.apache.usergrid.persistence.collection.guice.MigrationManagerRule;
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.SearchByEdge;
 import org.apache.usergrid.persistence.graph.guice.GraphModule;
 import org.apache.usergrid.persistence.model.entity.Id;
 import org.apache.usergrid.persistence.model.util.UUIDGenerator;
@@ -24,9 +25,11 @@ import com.google.inject.Inject;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createEdge;
+import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createGetByEdge;
 import static org.apache.usergrid.persistence.graph.test.util.EdgeTestUtils.createSearchByEdge;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
@@ -35,8 +38,8 @@ import static org.mockito.Mockito.when;
  *
  *
  */
-@RunWith( JukitoRunner.class )
-@UseModules( { GraphModule.class } )
+@RunWith(JukitoRunner.class)
+@UseModules({ GraphModule.class })
 public class EdgeSerializationTest {
 
     @ClassRule
@@ -139,7 +142,7 @@ public class EdgeSerializationTest {
         Iterator<Edge> results =
                 serialization.getEdgesFromSource( scope, createSearchByEdge( sourceId, "edge", now, edge1 ) );
 
-        assertEquals(edge2, results.next());
+        assertEquals( edge2, results.next() );
         assertFalse( results.hasNext() );
 
         //test getting the next edge
@@ -150,7 +153,7 @@ public class EdgeSerializationTest {
         //test getting source edges from the target
 
         results = serialization.getEdgesToTarget( scope, createSearchByEdge( targetId, "edge", now, edge1 ) );
-        assertEquals(edge2, results.next());
+        assertEquals( edge2, results.next() );
         assertFalse( results.hasNext() );
 
 
@@ -159,4 +162,67 @@ public class EdgeSerializationTest {
         //test resume by name
     }
 
+
+    /**
+     * Tests mixing 2 edge types between 2 nodes.  We should get results for the same source->destination with the 2
+     * edge types
+     */
+    @Test
+    public void directEdgeGets() throws ConnectionException {
+        final Edge edgev1 = createEdge( "source", "edge", "target" );
+
+        final Id sourceId = edgev1.getSourceNode();
+        final Id targetId = edgev1.getTargetNode();
+
+
+        final Edge edgev2 = createEdge( sourceId, "edge", targetId );
+
+        assertTrue( "Edge version 1 has lower time uuid", edgev1.getVersion().compareTo( edgev2.getVersion() ) < 0 );
+
+        serialization.writeEdge( scope, edgev1 ).execute();
+
+        final UUID now = UUIDGenerator.newTimeUUID();
+
+
+        SearchByEdge search = createGetByEdge( sourceId, "edge1", targetId, now, null );
+
+        Iterator<Edge> results = serialization.getEdgeFromSource( scope, search );
+
+        assertEquals( edgev1, results.next() );
+        assertEquals( edgev2, results.next() );
+        assertFalse( "No results should be returned", results.hasNext() );
+
+
+        results = serialization.getEdgeToTarget( scope, search );
+
+        assertEquals( edgev1, results.next() );
+        assertEquals( edgev2, results.next() );
+        assertFalse( "No results should be returned", results.hasNext() );
+
+        //test paging
+        search = createGetByEdge( sourceId, "edge1", targetId, now, edgev1 );
+
+        results = serialization.getEdgeFromSource( scope, search );
+
+        assertEquals( edgev2, results.next() );
+        assertFalse( "No results should be returned", results.hasNext() );
+
+
+        results = serialization.getEdgeToTarget( scope, search );
+
+        assertEquals( edgev2, results.next() );
+        assertFalse( "No results should be returned", results.hasNext() );
+
+        //test paging
+        search = createGetByEdge( sourceId, "edge1", targetId, now, edgev2 );
+
+        results = serialization.getEdgeFromSource( scope, search );
+
+        assertFalse( "No results should be returned", results.hasNext() );
+
+
+        results = serialization.getEdgeToTarget( scope, search );
+
+        assertFalse( "No results should be returned", results.hasNext() );
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
index 5e063ee..b196844 100644
--- a/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
+++ b/stack/corepersistence/graph/src/test/java/org/apache/usergrid/persistence/graph/test/util/EdgeTestUtils.java
@@ -23,10 +23,12 @@ package org.apache.usergrid.persistence.graph.test.util;
 import java.util.UUID;
 
 import org.apache.usergrid.persistence.graph.Edge;
+import org.apache.usergrid.persistence.graph.SearchByEdge;
 import org.apache.usergrid.persistence.graph.SearchByEdgeType;
 import org.apache.usergrid.persistence.graph.SearchByIdType;
 import org.apache.usergrid.persistence.graph.SearchEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleEdge;
+import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdge;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByEdgeType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchByIdType;
 import org.apache.usergrid.persistence.graph.impl.SimpleSearchEdgeType;
@@ -51,19 +53,31 @@ public class EdgeTestUtils {
      * @return an Edge for testing
      */
     public static Edge createEdge( final String sourceType, final String edgeType, final String targetType ) {
-        return createEdge( createId( sourceType ), edgeType, createId( targetType ) );
+        return createEdge( createId( sourceType ), edgeType, createId( targetType ), UUIDGenerator.newTimeUUID() );
     }
 
 
     /**
-     * Create an edge with the specified params
+     * Create an edge for testing
      * @param sourceId
      * @param edgeType
      * @param targetId
      * @return
      */
     public static Edge createEdge(final Id sourceId, final String edgeType, final Id targetId){
-       return new SimpleEdge( sourceId, edgeType, targetId, UUIDGenerator.newTimeUUID() );
+        return  createEdge( sourceId, edgeType, targetId, UUIDGenerator.newTimeUUID() );
+    }
+
+    /**
+     * Create an edge with the specified params
+     * @param sourceId
+     * @param edgeType
+     * @param targetId
+     * @param version
+     * @return
+     */
+    public static Edge createEdge(final Id sourceId, final String edgeType, final Id targetId, final UUID version){
+       return new SimpleEdge( sourceId, edgeType, targetId, version );
     }
 
 
@@ -129,6 +143,21 @@ public class EdgeTestUtils {
         return new SimpleSearchIdType( sourceId, type, last );
     }
 
+
+    /**
+     * Get the edge by type
+     * @param sourceId
+     * @param type
+     * @param targetId
+     * @param maxVersion
+     * @param last
+     * @return
+     */
+    public static SearchByEdge createGetByEdge( final Id sourceId, final String type, final Id targetId, final UUID maxVersion,
+                                                 final Edge last ) {
+        return new SimpleSearchByEdge( sourceId, type, targetId, maxVersion, last );
+    }
+
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/1af59d48/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/util/UUIDGenerator.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/util/UUIDGenerator.java b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/util/UUIDGenerator.java
index b04d13b..f2c4fa8 100644
--- a/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/util/UUIDGenerator.java
+++ b/stack/corepersistence/model/src/main/java/org/apache/usergrid/persistence/model/util/UUIDGenerator.java
@@ -13,7 +13,7 @@ import com.fasterxml.uuid.impl.TimeBasedGenerator;
 
 
 /**
- *
+ * TODO replace this with the Astyanax generator libs
  * @author: tnine
  *
  */


Mime
View raw message