@Override protected ScopedRowKey<Id> createKey( final Id applicationId, final Id entityId ) { final ScopedRowKey<Id> rowKey = ScopedRowKey.fromKey( applicationId, entityId ); return rowKey; }
/** * Utility function to generate a new key from the scope */ public static <K> ScopedRowKey< K> fromKey( final Id scope, K key ) { return new ScopedRowKey<>( scope, key ); } }
@Override public ByteBuffer toByteBuffer( final ScopedRowKey<K> scopedRowKey ) { final CompositeBuilder builder = Composites.newCompositeBuilder(); //add the organization's id ID_SER.toComposite( builder, scopedRowKey.getScope() ); //add the key type keySerializer.toComposite( builder, scopedRowKey.getKey() ); return builder.build(); }
@Override protected Id getEntityIdFromKey( final ScopedRowKey<Id> key ) { return key.getKey(); }
@Override public int hashCode() { int result = super.hashCode(); result = 31 * result + bucketNumber; return result; }
@Override public String toString() { return "BucketScopedRowKey{" + "bucketNumber=" + bucketNumber + "} " + super.toString(); }
@Override public boolean equals( final Object o ) { if ( this == o ) { return true; } if ( !( o instanceof BucketScopedRowKey ) ) { return false; } if ( !super.equals( o ) ) { return false; } final BucketScopedRowKey that = ( BucketScopedRowKey ) o; if ( bucketNumber != that.bucketNumber ) { return false; } return true; }
@Override protected Id getEntityIdFromKey( final ScopedRowKey<CollectionPrefixedKey<Id>> key ) { return key.getKey().getSubKey(); }
public List<ScopedRowKey<R>> getRowKeys() { if(logger.isTraceEnabled()) { logger.trace("Shards: {}", shards); } List<ScopedRowKey<R>> rowKeys = new ArrayList<>(shards.size()); for(Shard shard : shards){ final ScopedRowKey< R> rowKey = ScopedRowKey .fromKey( scope.getApplication(), generateRowKey(shard.getShardIndex() ) ); rowKeys.add( rowKey ); } if(logger.isTraceEnabled()) { logger.trace("Resulting Shards: {}", rowKeys); } return rowKeys; }
@Override public ScopedRowKey<K> fromByteBuffer( final ByteBuffer byteBuffer ) { final CompositeParser parser = Composites.newCompositeParser( byteBuffer ); //read back the id final Id orgId = ID_SER.fromComposite( parser ); final K value = keySerializer.fromComposite( parser ); return new ScopedRowKey<K>( orgId, value ); } }
@Override public ByteBuffer toByteBuffer( final ScopedRowKey<CollectionPrefixedKey<K>> scopedRowKey ) { final CompositeBuilder builder = Composites.newCompositeBuilder(); //add the organization's id ID_SER.toComposite( builder, scopedRowKey.getScope() ); final CollectionPrefixedKey<K> key = scopedRowKey.getKey(); //add the scope's owner id to the composite ID_SER.toComposite( builder, key.getOwner() ); //add the scope's name builder.addString( key.getCollectionName() ); //add the key type keySerializer.toComposite( builder, key.getSubKey() ); //addOtherComponents( builder, scopedRowKey ); return builder.build(); }
@Override void writeEdge( final MutationBatch batch, final MultiTenantColumnFamily<ScopedRowKey<RowKeyType>, DirectedEdge> columnFamily, final ApplicationScope scope, final RowKeyType rowKey, final DirectedEdge edge, final Shard shard, final boolean isDeleted ) { batch.withRow( columnFamily, ScopedRowKey.fromKey( scope.getApplication(), rowKey ) ).putColumn( edge, isDeleted ); } }.createBatch( scope, shards, timestamp );
@Override public ScopedRowKey<CollectionPrefixedKey<K>> fromByteBuffer( final ByteBuffer byteBuffer ) { final CompositeParser parser = Composites.newCompositeParser( byteBuffer ); //read back the id final Id orgId = ID_SER.fromComposite( parser ); final Id scopeId = ID_SER.fromComposite( parser ); final String scopeName = parser.readString(); final K value = keySerializer.fromComposite( parser ); final CollectionPrefixedKey<K> collectionPrefixedKey = new CollectionPrefixedKey<>( scopeName, scopeId, value ); return new ScopedRowKey<>( orgId, collectionPrefixedKey ); } }
@Override protected ScopedRowKey<CollectionPrefixedKey<Id>> createKey( final Id applicationId, final Id entityId ) { final Id ownerId = applicationId; final String collectionName = LegacyScopeUtils.getCollectionScopeNameFromEntityType( entityId.getType() ); final CollectionPrefixedKey<Id> collectionPrefixedKey = new CollectionPrefixedKey<>( collectionName, ownerId, entityId ); final ScopedRowKey<CollectionPrefixedKey<Id>> rowKey = ScopedRowKey.fromKey( applicationId, collectionPrefixedKey ); return rowKey; }
/** * Remove the edge * * @param scope The scope * @param rowKeyId The id to use in the row key * @param edgeType The edge type * @param version The version of the edge * @param cf The column family */ private MutationBatch removeEdgeType( final ApplicationScope scope, final Id rowKeyId, final String edgeType, final long version, final MultiTenantColumnFamily<ScopedRowKey<Id>, String> cf ) { //write target<--source edge type meta data final ScopedRowKey< Id> rowKey = new ScopedRowKey< Id>( scope.getApplication(), rowKeyId ); final MutationBatch batch = keyspace.prepareMutationBatch().withTimestamp( version ); batch.withRow( cf, rowKey ).deleteColumn( edgeType ); return batch; }
@Override void writeEdge( final MutationBatch batch, final MultiTenantColumnFamily<ScopedRowKey<RowKey>, DirectedEdge> columnFamily, final ApplicationScope scope, final RowKey rowKey, final DirectedEdge edge, final Shard shard, final boolean isDeleted ) { batch.withRow( columnFamily, ScopedRowKey.fromKey( scope.getApplication(), rowKey ) ).putColumn( edge, isDeleted ); } }.createBatch( scope, shards, timestamp );
@Override public MutationBatch writeEdge( final ApplicationScope scope, final Edge edge ) { ValidationUtils.validateApplicationScope( scope ); GraphValidation.validateEdge( edge ); final Id scopeId = scope.getApplication(); final Id source = edge.getSourceNode(); final Id target = edge.getTargetNode(); final String edgeType = edge.getType(); final long timestamp = edge.getTimestamp(); final MutationBatch batch = keyspace.prepareMutationBatch().withConsistencyLevel( cassandraConfig.getWriteCL() ) .withTimestamp( timestamp ); //add source->target edge type to meta data final ScopedRowKey< Id> sourceKey = new ScopedRowKey<>( scopeId, source ); batch.withRow( CF_SOURCE_EDGE_TYPES, sourceKey ).putColumn( edgeType, HOLDER ); //write source->target edge type and id type to meta data EdgeIdTypeKey tk = new EdgeIdTypeKey( source, edgeType ); final ScopedRowKey<EdgeIdTypeKey> sourceTypeKey = new ScopedRowKey<>( scopeId, tk ); batch.withRow( CF_SOURCE_EDGE_ID_TYPES, sourceTypeKey ).putColumn( target.getType(), HOLDER ); //write target<--source edge type meta data final ScopedRowKey< Id> targetKey = new ScopedRowKey<>( scopeId, target ); batch.withRow( CF_TARGET_EDGE_TYPES, targetKey ).putColumn( edgeType, HOLDER ); //write target<--source edge type and id type to meta data final ScopedRowKey<EdgeIdTypeKey> targetTypeKey = new ScopedRowKey<>( scopeId, new EdgeIdTypeKey( target, edgeType ) ); batch.withRow( CF_TARGET_EDGE_ID_TYPES, targetTypeKey ).putColumn( source.getType(), HOLDER ); return batch; }