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

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

Introduction

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

Prototype

DecimalType instance

To view the source code for org.apache.cassandra.db.marshal DecimalType 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:// w  ww . ja v  a 2s.  com
        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 BigDecimal getDecimal(int i) {
    metadata.checkType(i, DataType.Name.DECIMAL);

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

    return DecimalType.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 decimal.
 *
 * @param i the index of the variable to set.
 * @param v the value to set.//  www  .j a  v a2  s  . c o 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 DECIMAL.
 */
public BoundStatement setDecimal(int i, BigDecimal v) {
    metadata().checkType(i, DataType.Name.DECIMAL);
    return setValue(i, v == null ? null : DecimalType.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 av 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 variable length decimal.
 *
 * @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 decimal. 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 DECIMAL.
 *//*from w  w  w. j  a v  a2s .  c  om*/
public BigDecimal getDecimal(int i) {
    metadata.checkType(i, DataType.Name.DECIMAL);

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

    return DecimalType.instance.compose(value);
}

From source file:com.jshnd.virp.hector.BigDecimalSerializer.java

License:Apache License

@Override
public ByteBuffer toByteBuffer(BigDecimal obj) {
    return DecimalType.instance.decompose(obj);
}

From source file:com.jshnd.virp.hector.BigDecimalSerializer.java

License:Apache License

@Override
public BigDecimal fromByteBuffer(ByteBuffer byteBuffer) {
    if (!byteBuffer.hasRemaining()) {
        return null;
    }//from  ww  w . j a va2s.  c  om
    return DecimalType.instance.compose(byteBuffer);
}

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.//  www  .j  a  va  2s  .  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.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 .  jav  a 2  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.//from www  .j  ava 2 s.co  m
 */
@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;
}