Example usage for org.apache.cassandra.db.marshal TimeUUIDType instance

List of usage examples for org.apache.cassandra.db.marshal TimeUUIDType instance

Introduction

In this page you can find the example usage for org.apache.cassandra.db.marshal TimeUUIDType instance.

Prototype

TimeUUIDType instance

To view the source code for org.apache.cassandra.db.marshal TimeUUIDType instance.

Click Source Link

Usage

From source file:clojurewerkz.cassaforte.Codec.java

License:Apache License

private static AbstractType getCodecInternal(DataType type) {
    switch (type.getName()) {
    case ASCII://from   w  w w  .  ja  v  a  2  s .  c  o m
        return AsciiType.instance;
    case BIGINT:
        return LongType.instance;
    case BLOB:
        return BytesType.instance;
    case BOOLEAN:
        return BooleanType.instance;
    case COUNTER:
        return CounterColumnType.instance;
    case DECIMAL:
        return DecimalType.instance;
    case DOUBLE:
        return DoubleType.instance;
    case FLOAT:
        return FloatType.instance;
    case INET:
        return InetAddressType.instance;
    case INT:
        return Int32Type.instance;
    case TEXT:
        return UTF8Type.instance;
    case TIMESTAMP:
        return DateType.instance;
    case UUID:
        return UUIDType.instance;
    case VARCHAR:
        return UTF8Type.instance;
    case VARINT:
        return IntegerType.instance;
    case TIMEUUID:
        return TimeUUIDType.instance;
    case LIST:
        return ListType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case SET:
        return SetType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case MAP:
        return MapType.getInstance(getCodec(type.getTypeArguments().get(0)),
                getCodec(type.getTypeArguments().get(1)));
    default:
        throw new RuntimeException("Unknown type");
    }
}

From source file:com.datastax.driver.core.ArrayBackedRow.java

License:Apache License

public UUID getUUID(int i) {
    DataType.Name type = metadata.checkType(i, DataType.Name.UUID, DataType.Name.TIMEUUID);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0)
        return null;

    return type == DataType.Name.UUID ? UUIDType.instance.compose(value) : TimeUUIDType.instance.compose(value);
}

From source file:com.datastax.driver.core.BoundStatement.java

License:Apache License

/**
 * Sets the {@code i}th value to the provided UUID.
 *
 * @param i the index of the variable to set.
 * @param v the value to set.//from  ww w.j  a  v a  2s  .co m
 * @return this BoundStatement.
 *
 * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.preparedStatement().variables().size()}.
 * @throws InvalidTypeException if column {@code i} is not of type UUID or
 * TIMEUUID, or if column {@code i} is of type TIMEUUID but {@code v} is
 * not a type 1 UUID.
 */
public BoundStatement setUUID(int i, UUID v) {
    DataType.Name type = metadata().checkType(i, DataType.Name.UUID, DataType.Name.TIMEUUID);

    if (v == null)
        return setValue(i, null);

    if (type == DataType.Name.TIMEUUID && v.version() != 1)
        throw new InvalidTypeException(String.format("%s is not a Type 1 (time-based) UUID", v));

    return type == DataType.Name.UUID ? setValue(i, UUIDType.instance.decompose(v))
            : setValue(i, TimeUUIDType.instance.decompose(v));
}

From source file:com.datastax.driver.core.Codec.java

License:Apache License

private static AbstractType<?> getCodecInternal(DataType type) {
    switch (type.getName()) {
    case ASCII:/*from   w w w  .  ja v a  2  s. c o m*/
        return AsciiType.instance;
    case BIGINT:
        return LongType.instance;
    case BLOB:
        return BytesType.instance;
    case BOOLEAN:
        return BooleanType.instance;
    case COUNTER:
        return CounterColumnType.instance;
    case DECIMAL:
        return DecimalType.instance;
    case DOUBLE:
        return DoubleType.instance;
    case FLOAT:
        return FloatType.instance;
    case INET:
        return InetAddressType.instance;
    case INT:
        return Int32Type.instance;
    case TEXT:
        return UTF8Type.instance;
    case TIMESTAMP:
        return DateType.instance;
    case UUID:
        return UUIDType.instance;
    case VARCHAR:
        return UTF8Type.instance;
    case VARINT:
        return IntegerType.instance;
    case TIMEUUID:
        return TimeUUIDType.instance;
    case LIST:
        return ListType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case SET:
        return SetType.getInstance(getCodec(type.getTypeArguments().get(0)));
    case MAP:
        return MapType.getInstance(getCodec(type.getTypeArguments().get(0)),
                getCodec(type.getTypeArguments().get(1)));
    // We don't interpret custom values in any way
    case CUSTOM:
        return BytesType.instance;
    default:
        throw new RuntimeException("Unknown type");
    }
}

From source file:com.datastax.driver.core.Row.java

License:Apache License

/**
 * Returns the {@code i}th value of this row as a UUID.
 *
 * @param i the index ({@code 0 <= i < size()}) of the column to retrieve.
 * @return the value of the {@code i}th column in this row as a UUID.
 * If the value is NULL, {@code null} is returned.
 *
 * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
 * @throws InvalidTypeException if column {@code i} is not of type UUID
 * or TIMEUUID./*from  w ww.j  av a  2 s .  c o  m*/
 */
public UUID getUUID(int i) {
    DataType.Name type = metadata.checkType(i, DataType.Name.UUID, DataType.Name.TIMEUUID);

    ByteBuffer value = data.get(i);
    if (value == null || value.remaining() == 0)
        return null;

    return type == DataType.Name.UUID ? UUIDType.instance.compose(value) : TimeUUIDType.instance.compose(value);
}

From source file:com.datastax.driver.core.utils.UUIDsTest.java

License:Apache License

private static void assertWithin(UUID uuid, UUID lowerBound, UUID upperBound) {
    ByteBuffer uuidBytes = TimeUUIDType.instance.decompose(uuid);
    ByteBuffer lb = TimeUUIDType.instance.decompose(lowerBound);
    ByteBuffer ub = TimeUUIDType.instance.decompose(upperBound);
    assertTrue(TimeUUIDType.instance.compare(lb, uuidBytes) <= 0);
    assertTrue(TimeUUIDType.instance.compare(ub, uuidBytes) >= 0);
}

From source file:com.impetus.client.cassandra.CassandraIdGenerator.java

License:Apache License

@Override
public Object generate(Client<?> client, String dataType) {
    CqlResult cqlResult = ((CassandraClientBase) client).execute(
            "SELECT NOW() FROM system_schema.columns LIMIT 1",
            ((CassandraClientBase) client).getRawClient(SYSTEM));

    CqlRow cqlRow = cqlResult.getRowsIterator().next();
    TimeUUIDType t = TimeUUIDType.instance;
    UUID timeUUID = t.compose(ByteBuffer.wrap(cqlRow.getColumns().get(0).getValue()));

    switch (dataType.toLowerCase()) {
    case UUID:
        return timeUUID;

    default:/*from w  w  w . ja  va  2 s . com*/
        return java.util.UUID.randomUUID();

    }
}

From source file:com.perpetumobile.bit.orm.cassandra.CliMain.java

License:Apache License

private void executeTraceNextQuery() throws TException, CharacterCodingException {
    if (!CliMain.isConnected())
        return;/*from   www  .j a  v a2  s  . c o m*/

    UUID sessionId = TimeUUIDType.instance.compose(thriftClient.trace_next_query());

    sessionState.out.println("Will trace next query. Session ID: " + sessionId.toString());
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperString.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperString}.
 *///from   w w  w .  j  av  a 2 s. co m
@JsonCreator
public ColumnMapperString() {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, BooleanType.instance,
            UUIDType.instance, TimeUUIDType.instance, TimestampType.instance, BytesType.instance,
            InetAddressType.instance }, new AbstractType[] { UTF8Type.instance });
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperText.java

License:Apache License

/**
 * Builds a new {@link ColumnMapperText} using the specified Lucene {@link Analyzer}.
 * @param analyzerClassName The Lucene {@link Analyzer} to be used.
 *//* ww w  .  j  a  v  a2  s.c  o m*/
@JsonCreator
public ColumnMapperText(@JsonProperty("analyzer") String analyzerClassName) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, BooleanType.instance,
            UUIDType.instance, TimeUUIDType.instance, TimestampType.instance, BytesType.instance,
            InetAddressType.instance }, new AbstractType[] {});
    if (analyzerClassName != null) {
        this.analyzer = AnalyzerFactory.getAnalyzer(analyzerClassName);
    } else {
        this.analyzer = Schema.DEFAULT_ANALYZER;
    }
}