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

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

Introduction

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

Prototype

IntegerType instance

To view the source code for org.apache.cassandra.db.marshal IntegerType 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 va 2 s  .c om
        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 BigInteger getVarint(int i) {
    metadata.checkType(i, DataType.Name.VARINT);

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

    return IntegerType.instance.compose(value);
}

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

License:Apache License

/**
 * Sets the {@code i}th value to the provided big integer.
 *
 * @param i the index of the variable to set.
 * @param v the value to set.//from  w w w . j  av  a2s . 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 VARINT.
 */
public BoundStatement setVarint(int i, BigInteger v) {
    metadata().checkType(i, DataType.Name.VARINT);
    return setValue(i, v == null ? null : IntegerType.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:/*  ww w. j  a  va 2 s .  co 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 variable length integer.
 *
 * @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 variable
 * length integer. 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 VARINT.
 *//*from   www . j  av  a 2s  .co m*/
public BigInteger getVarint(int i) {
    metadata.checkType(i, DataType.Name.VARINT);

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

    return IntegerType.instance.compose(value);
}

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

License:Apache License

/**
 * Builds a new {@link ColumnMapperBigDecimal} using the specified max number of digits for the integer and decimal
 * parts.//from   w ww  .j  a  v  a2  s  . c  o m
 *
 * @param integerDigits The max number of digits for the integer part. If {@code null}, the {@link
 *                      #DEFAULT_INTEGER_DIGITS} will be used.
 * @param decimalDigits The max number of digits for the decimal part. If {@code null}, the {@link
 *                      #DEFAULT_DECIMAL_DIGITS} will be used.
 */
@JsonCreator
public ColumnMapperBigDecimal(@JsonProperty("integer_digits") Integer integerDigits,
        @JsonProperty("decimal_digits") Integer decimalDigits) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance },
            new AbstractType[] {});

    // Setup integer part mapping
    if (integerDigits != null && integerDigits <= 0) {
        throw new IllegalArgumentException("Positive integer part digits required");
    }
    this.integerDigits = integerDigits == null ? DEFAULT_INTEGER_DIGITS : integerDigits;

    // Setup decimal part mapping
    if (decimalDigits != null && decimalDigits <= 0) {
        throw new IllegalArgumentException("Positive decimal part digits required");
    }
    this.decimalDigits = decimalDigits == null ? DEFAULT_DECIMAL_DIGITS : decimalDigits;

    int totalDigits = this.integerDigits + this.decimalDigits;
    BigDecimal divisor = BigDecimal.valueOf(10).pow(this.decimalDigits);
    BigDecimal dividend = BigDecimal.valueOf(10).pow(totalDigits).subtract(BigDecimal.valueOf(1));
    complement = dividend.divide(divisor);
}

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

License:Apache License

/**
 * Builds a new {@link ColumnMapperBigDecimal} using the specified max number of digits.
 *
 * @param digits The max number of digits. If {@code null}, the {@link #DEFAULT_DIGITS} will be used.
 *//*from   www.ja  v  a2  s . co m*/
@JsonCreator
public ColumnMapperBigInteger(@JsonProperty("digits") Integer digits) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance }, new AbstractType[] {});

    if (digits != null && digits <= 0) {
        throw new IllegalArgumentException("Positive digits required");
    }

    this.digits = digits == null ? DEFAULT_DIGITS : digits;
    complement = BigInteger.valueOf(10).pow(this.digits).subtract(BigInteger.valueOf(1));
    BigInteger maxValue = complement.multiply(BigInteger.valueOf(2));
    hexDigits = encode(maxValue).length();
}

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

License:Apache License

/**
 * Builds a new {@link ColumnMapperDate} using the specified pattern.
 *
 * @param pattern The {@link SimpleDateFormat} pattern to be used.
 *//*from  www .j av  a2 s .c  o m*/
@JsonCreator
public ColumnMapperDate(@JsonProperty("pattern") String pattern) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance,
            TimestampType.instance }, new AbstractType[] { LongType.instance, TimestampType.instance });
    this.pattern = pattern == null ? DEFAULT_PATTERN : pattern;
    concurrentDateFormat = new ThreadLocal<DateFormat>() {
        @Override
        protected DateFormat initialValue() {
            return new SimpleDateFormat(ColumnMapperDate.this.pattern);
        }
    };
}

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

License:Apache License

/**
 * Builds a new {@link ColumnMapperDouble} using the specified boost.
 * @param boost The boost to be used./*  w w w .  j a  v a  2s .c  om*/
 */
@JsonCreator
public ColumnMapperDouble(@JsonProperty("boost") Float boost) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance },
            new AbstractType[] { DoubleType.instance });
    this.boost = boost == null ? DEFAULT_BOOST : boost;
}

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

License:Apache License

/**
 * Builds a new {@link ColumnMapperFloat} using the specified boost.
 * @param boost The boost to be used./*www  .j  a v  a  2 s.  c o  m*/
 */
@JsonCreator
public ColumnMapperFloat(@JsonProperty("boost") Float boost) {
    super(new AbstractType<?>[] { AsciiType.instance, UTF8Type.instance, Int32Type.instance, LongType.instance,
            IntegerType.instance, FloatType.instance, DoubleType.instance, DecimalType.instance },
            new AbstractType[] { FloatType.instance });
    this.boost = boost == null ? DEFAULT_BOOST : boost;
}