Example usage for org.apache.cassandra.utils UUIDGen getTimeUUID

List of usage examples for org.apache.cassandra.utils UUIDGen getTimeUUID

Introduction

In this page you can find the example usage for org.apache.cassandra.utils UUIDGen getTimeUUID.

Prototype

public static UUID getTimeUUID(long when) 

Source Link

Document

Creates a type 1 UUID (time-based UUID) with the timestamp of @param when, in milliseconds.

Usage

From source file:com.stratio.cassandra.lucene.schema.mapping.DateMapperTest.java

License:Apache License

@Test
public void testBaseTimeUUID() throws ParseException {
    Long expected = new SimpleDateFormat("yyyyMMdd").parse("20161127").getTime();
    DateMapper mapper = dateMapper().pattern("yyyyMMdd").build("name");
    Long parsed = mapper.base("test", UUIDGen.getTimeUUID(expected));
    assertEquals("Base value is not properly parsed", expected, parsed);
}

From source file:com.stratio.cassandra.lucene.util.DateParserTest.java

License:Apache License

@Test
public void testParseUUID() throws ParseException {
    UUID uuid = UUIDGen.getTimeUUID(date("yyyy-MM-dd HH:mm", "2015-11-03 06:23").getTime());
    Date expected = date("yyyyMMdd", "20151103");
    assertEquals("yyyyMMdd", uuid, expected);
}

From source file:com.tuplejump.stargate.Fields.java

License:Apache License

public static ByteBuffer defaultValue(AbstractType type, boolean min) {
    CQL3Type cqlType = type.asCQL3Type();
    if (cqlType == CQL3Type.Native.INT || cqlType == CQL3Type.Native.VARINT) {
        return ByteBufferUtil.bytes(min ? Integer.MIN_VALUE : Integer.MAX_VALUE);
    } else if (cqlType == CQL3Type.Native.BIGINT) {
        return ByteBufferUtil.bytes(min ? Long.MIN_VALUE : Long.MAX_VALUE);
    } else if (cqlType == CQL3Type.Native.DECIMAL || cqlType == CQL3Type.Native.DOUBLE) {
        return ByteBufferUtil.bytes(min ? Double.MIN_VALUE : Double.MAX_VALUE);
    } else if (cqlType == CQL3Type.Native.FLOAT) {
        return ByteBufferUtil.bytes(min ? Float.MIN_VALUE : Float.MAX_VALUE);
    } else if (cqlType == CQL3Type.Native.TEXT || cqlType == CQL3Type.Native.VARCHAR) {
        return ByteBufferUtil.bytes("");
    } else if (cqlType == CQL3Type.Native.UUID) {
        return ByteBufferUtil.bytes(UUID.randomUUID());
    } else if (cqlType == CQL3Type.Native.TIMEUUID) {
        return ByteBufferUtil.bytes(UUIDGen.getTimeUUID(0));
    } else if (cqlType == CQL3Type.Native.TIMESTAMP) {
        return ByteBufferUtil.bytes(0l);
    } else if (cqlType == CQL3Type.Native.BOOLEAN) {
        return BooleanType.instance.decompose(min ? false : true);
    } else if (type.isCollection()) {
        CollectionType collectionType = (CollectionType) type;
        List<Pair<ByteBuffer, Column>> collection = new ArrayList<>();
        ByteBuffer dummyColumn = defaultValue(collectionType.nameComparator());
        collection.add(Pair.create(dummyColumn,
                new Column(dummyColumn, defaultValue(collectionType.valueComparator(), min))));
        return collectionType.serialize(collection);
    } else {//  w ww .j av a  2  s .c  o  m
        return ByteBufferUtil.EMPTY_BYTE_BUFFER;
    }
}