Example usage for org.apache.cassandra.db DecoratedKey getToken

List of usage examples for org.apache.cassandra.db DecoratedKey getToken

Introduction

In this page you can find the example usage for org.apache.cassandra.db DecoratedKey getToken.

Prototype

public Token getToken() 

Source Link

Usage

From source file:com.stratio.cassandra.index.PartitionKeyMapper.java

License:Apache License

public String toString(DecoratedKey decoratedKey) {
    return decoratedKey.getToken() + " - " + ByteBufferUtils.toString(decoratedKey.getKey(), type);
}

From source file:com.stratio.cassandra.index.TokenMapperGeneric.java

License:Apache License

/** {@inheritDoc} */
@Override/* w  ww  .  ja  va  2 s .  c o  m*/
@SuppressWarnings("unchecked")
public void addFields(Document document, DecoratedKey partitionKey) {
    ByteBuffer bb = factory.toByteArray(partitionKey.getToken());
    String serialized = ByteBufferUtils.toString(bb);
    Field field = new StringField(FIELD_NAME, serialized, Store.YES);
    document.add(field);
}

From source file:com.stratio.cassandra.index.TokenMapperMurmur.java

License:Apache License

/** {@inheritDoc} */
@Override//from w ww. j a v  a  2s . c om
public void addFields(Document document, DecoratedKey partitionKey) {
    Long value = (Long) partitionKey.getToken().getTokenValue();
    Field tokenField = new LongField(FIELD_NAME, value, Store.NO);
    document.add(tokenField);
}

From source file:com.stratio.cassandra.lucene.key.KeyMapper.java

License:Apache License

/**
 * Returns the {@link ByteBuffer} representation of the primary key formed by the specified partition key and the
 * clustering key.//from w  w  w .  j  av  a 2 s.  c o  m
 *
 * @param key the partition key
 * @param clustering the clustering key
 * @return the {@link ByteBuffer} representation of the primary key
 */
public ByteBuffer byteBuffer(DecoratedKey key, Clustering clustering) {
    return type.builder().add(TokenMapper.byteBuffer(key.getToken())).add(key.getKey())
            .add(byteBuffer(clustering)).build();
}

From source file:com.stratio.cassandra.lucene.key.KeyQuery.java

License:Apache License

/**
 * Returns a new clustering key query for the specified clustering key range using the specified mapper.
 *
 * @param mapper the clustering key mapper to be used
 * @param key the partition key/*from  ww  w.j  ava  2 s.  c  o  m*/
 * @param start the start clustering
 * @param stop the stop clustering
 * @param acceptLowerConflicts if accept lower token conflicts
 * @param acceptUpperConflicts if accept upper token conflicts
 */
public KeyQuery(KeyMapper mapper, DecoratedKey key, ClusteringPrefix start, ClusteringPrefix stop,
        boolean acceptLowerConflicts, boolean acceptUpperConflicts) {
    super(KeyMapper.FIELD_NAME);
    this.mapper = mapper;
    this.key = key;
    this.token = key.getToken();
    this.start = start;
    this.stop = stop;
    this.acceptLowerConflicts = acceptLowerConflicts;
    this.acceptUpperConflicts = acceptUpperConflicts;
    clusteringComparator = mapper.clusteringComparator();
}

From source file:com.stratio.cassandra.lucene.key.TokenMapper.java

License:Apache License

/**
 * Adds to the specified {@link Document} the {@link Field}s associated to the token of the specified row key.
 *
 * @param document A {@link Document}./*from  w w  w. ja  v a 2 s . co  m*/
 * @param key The raw partition key to be added.
 */
public void addFields(Document document, DecoratedKey key) {
    Token token = key.getToken();
    Long value = value(token);
    Field field = new LongField(FIELD_NAME, value, FIELD_TYPE);
    document.add(field);
}

From source file:com.stratio.cassandra.lucene.service.TokenMapperGeneric.java

License:Apache License

/** {@inheritDoc} */
@Override/*from w  ww. jav a  2s . c  o  m*/
public void addFields(Document document, DecoratedKey partitionKey) {
    ByteBuffer bb = factory.toByteArray(partitionKey.getToken());
    String serialized = ByteBufferUtils.toString(bb);
    BytesRef bytesRef = new BytesRef(serialized);
    document.add(new StringField(FIELD_NAME, serialized, Store.NO));
    document.add(new SortedDocValuesField(FIELD_NAME, bytesRef));
}

From source file:com.stratio.cassandra.lucene.service.TokenMapperGenericTest.java

License:Apache License

@Test
public void testValue() {
    DecoratedKey key = decoratedKey("key");
    Token token = key.getToken();
    BytesRef value = mapper.bytesRef(token);
    assertNotNull("Value is wrong", value);
    assertEquals("Value is wrong", "[3c 6e b 8a 9c 15 22 4a 82 28 b9 a9 8c a1 53 1d]", value.toString());
}

From source file:com.stratio.cassandra.lucene.service.TokenMapperGenericTest.java

License:Apache License

@Test
public void testToken() {
    DecoratedKey key = decoratedKey("key");
    Token expectedToken = key.getToken();
    BytesRef value = mapper.bytesRef(expectedToken);
    Token actualToken = mapper.token(value);
    assertNotNull("Token is wrong", actualToken);
    assertEquals("Token is wrong", expectedToken, actualToken);
}

From source file:com.stratio.cassandra.lucene.service.TokenMapperMurmur.java

License:Apache License

/** {@inheritDoc} */
@Override//from   ww  w  .  ja  v  a  2  s .c  o m
public void addFields(Document document, DecoratedKey partitionKey) {
    Long value = (Long) partitionKey.getToken().getTokenValue();
    document.add(new LongField(FIELD_NAME, value, FIELD_TYPE));
}