@Override protected ScopedRowKey<Id> createKey( final Id applicationId, final Id entityId ) { final ScopedRowKey<Id> rowKey = ScopedRowKey.fromKey( applicationId, entityId ); return rowKey; }
@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 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 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 BucketScopedRowKey<K> scopedRowKey ) { final CompositeBuilder builder = Composites.newCompositeBuilder(); //add the organization's id ID_SER.toComposite( builder, scopedRowKey.getScope() ); //add the bucket builder.addInteger( scopedRowKey.getBucketNumber() ); //add the key type keySerializer.toComposite( builder, scopedRowKey.getKey() ); return builder.build(); }
@Override public BucketScopedRowKey<K> fromByteBuffer( final ByteBuffer byteBuffer ) { final CompositeParser parser = Composites.newCompositeParser( byteBuffer ); //read back the id final Id orgId = ID_SER.fromComposite( parser ); final int bucket = parser.readInteger(); final K value = keySerializer.fromComposite( parser ); return new BucketScopedRowKey<>( orgId, value, bucket ); } }
@Override public void toComposite( final CompositeBuilder builder, final EdgeRowKey key ) { //add the row id to the composite ID_SER.toComposite( builder, key.sourceId ); builder.addString( key.edgeType ); ID_SER.toComposite( builder, key.targetId ); builder.addLong( key.shardId ); }
/** * 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 protected Id getEntityIdFromKey( final ScopedRowKey<Id> key ) { return key.getKey(); }
@Override public T next() { if ( !hasNext() ) { throw new NoSuchElementException(); } return parser.parseColumn( sourceIterator.next() ); }
/** * Utility function to generate a new key from the scope */ public static <K> BucketScopedRowKey<K> fromKey( final Id scope, final K key, final int bucketNumber ) { return new BucketScopedRowKey<>( scope, key, bucketNumber ); }
@Override public Keyspace get() { return cassandraCluster.getApplicationKeyspace(); }
public FieldBufferBuilder( final int elementSize ) { buffer = new FieldBuffer( elementSize ); }
@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; }
@Inject public AstyanaxLockManagerImpl(CassandraFig cassandraFig, CassandraCluster cassandraCluster ) throws ConnectionException { this.cassandraFig = cassandraFig; this.cassandraCluster = cassandraCluster; this.keyspace = cassandraCluster.getLocksKeyspace(); }
/** * return the next vlaue as a byte */ public byte readByte() { return BYTE_SERIALIZER.fromByteBuffer( getNext() ); }
@Override public void buildRange(final RangeBuilder rangeBuilder, final Long value, Long end) { rangeBuilder.setStart( value ); buildRange( rangeBuilder ); }
@Override public void buildRange(final RangeBuilder rangeBuilder, final Long value, Long end) { rangeBuilder.setStart( value ); buildRange( rangeBuilder ); }
@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 ); } }