/** * Create a scan range that represents the timestamp of the edge * @param timestamp * @return */ public ByteBuffer fromTimeRange( final long timestamp ) { DynamicComposite composite = new DynamicComposite(); composite.addComponent( timestamp, LONG_SERIALIZER ); return composite.serialize(); } }
@Override public Shard fromByteBuffer( final ByteBuffer byteBuffer ) { DynamicComposite composite = DynamicComposite.fromByteBuffer( byteBuffer ); Preconditions.checkArgument( composite.size() == 5 || composite.size() == 6, "Composite should 5 elements" ); final byte version = composite.get(0, BYTE_SERIALIZER); final long shardIndex = composite.get( 1, LONG_SERIALIZER ); final long shardCreated = composite.get( 2, LONG_SERIALIZER ); final DirectedEdge shardEnd = composite.get( 3, EDGE_SERIALIZER); final boolean isCompacted = composite.get( 4, BOOLEAN_SERIALIZER); final Shard shard = new Shard(shardIndex, shardCreated, isCompacted); shard.setShardEnd(Optional.fromNullable(shardEnd)); if( composite.size() == 6){ final boolean isDeleted = composite.get( 5, BOOLEAN_SERIALIZER); shard.setDeleted(isDeleted); } return shard; }
@Override public Id fromComposite( final DynamicComposite composite, int startIndex ) { Preconditions.checkArgument( composite.size() >= startIndex+2, "Composite must contain a next element for uuid and type" ); final UUID uuid = composite.get(startIndex, UUID_SERIALIZER ); final String type = composite.get(startIndex +1, STRING_SERIALIZER); return new SimpleId(uuid, type ); }
public static ByteBuffer toByteBuffer(Object... o) { DynamicComposite composite = new DynamicComposite(o); return composite.serialize(); }
public static DynamicComposite fromByteBuffer(ByteBuffer byteBuffer) { DynamicComposite composite = new DynamicComposite(); composite.deserialize(byteBuffer); return composite; }
@SuppressWarnings("unchecked") @Override public <T> T read(Serializer<T> serializer) { Object obj = this.composite.get(position, serializer); position++; return (T) obj; }
public DynamicCompositeParserImpl(ByteBuffer bb) { this.composite = DynamicComposite.fromByteBuffer(bb); }
@Override public void toComposite( final DynamicComposite composite, final Id value ) { composite.addComponent( value.getUuid(), UUID_SERIALIZER ); composite.addComponent( value.getType(), STRING_SERIALIZER ); }
@Override public ByteBuffer toByteBuffer(DynamicComposite obj) { return obj.serialize(); }
public static CompositeBuilder newDynamicCompositeBuilder() { return new CompositeBuilderImpl(new DynamicComposite()); }
public static ByteBuffer toByteBuffer(List<?> l) { DynamicComposite composite = new DynamicComposite(l); return composite.serialize(); } }
@Override public DynamicComposite fromByteBuffer(ByteBuffer byteBuffer) { if (byteBuffer == null) return null; ByteBuffer dup = byteBuffer.duplicate(); DynamicComposite composite = new DynamicComposite(); composite.deserialize(dup); return composite; }
@Override public ByteBuffer toByteBuffer( final DirectedEdge edge ) { DynamicComposite composite = new DynamicComposite(); composite.addComponent( edge.timestamp, LONG_SERIALIZER ); ID_COL_SERIALIZER.toComposite( composite, edge.id ); return composite.serialize(); }
@Override public DirectedEdge fromByteBuffer( final ByteBuffer byteBuffer ) { DynamicComposite composite = DynamicComposite.fromByteBuffer( byteBuffer ); Preconditions.checkArgument( composite.size() == 3, "Composite should have 3 elements" ); //return the version final long timestamp = composite.get( 0, LONG_SERIALIZER ); //parse our id final Id id = ID_COL_SERIALIZER.fromComposite( composite, 1 ); return new DirectedEdge( id, timestamp ); }
@Override public ByteBuffer toByteBuffer(final Shard shard ) { DynamicComposite composite = new DynamicComposite(); composite.addComponent( (byte) 2 , BYTE_SERIALIZER); composite.addComponent( shard.getShardIndex(), LONG_SERIALIZER); composite.addComponent( shard.getCreatedTime(), LONG_SERIALIZER); if(shard.getShardEnd().isPresent()) { composite.addComponent(shard.getShardEnd().get(), EDGE_SERIALIZER); }else{ composite.addComponent(null, EDGE_SERIALIZER); } composite.addComponent( shard.isCompacted(), BOOLEAN_SERIALIZER); composite.addComponent( shard.isDeleted(), BOOLEAN_SERIALIZER); return composite.serialize(); }
@Override public EntityVersion fromByteBuffer(final ByteBuffer byteBuffer) { // would use Composites.newDynamicCompositeParser(byteBuffer) but it is not implemented DynamicComposite composite = DynamicComposite.fromByteBuffer(byteBuffer); Preconditions.checkArgument(composite.size() == 3, "Composite should have 3 elements"); final UUID version = composite.get( 0, UUIDSerializer.get() ); final UUID entityId = composite.get( 1, UUIDSerializer.get() ); final String entityType = composite.get( 2, StringSerializer.get() ); return new EntityVersion( new SimpleId( entityId, entityType ), version); }
@Override public ByteBuffer toByteBuffer( final UniqueFieldEntry value ) { final UUID version = value.getVersion(); final Field<?> field = value.getField(); final FieldTypeName fieldType = field.getTypeName(); final String fieldValue = field.getValue().toString().toLowerCase(); DynamicComposite composite = new DynamicComposite( ); //we want to sort ascending to descending by version composite.addComponent( version, UUID_SERIALIZER, ColumnTypes.UUID_TYPE_REVERSED); composite.addComponent( field.getName(), STRING_SERIALIZER ); composite.addComponent( fieldValue, STRING_SERIALIZER ); composite.addComponent( fieldType.name() , STRING_SERIALIZER); return composite.serialize(); }