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

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

Introduction

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

Prototype

Int32Type instance

To view the source code for org.apache.cassandra.db.marshal Int32Type 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 .j  a  va 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 int getInt(int i) {
    metadata.checkType(i, DataType.Name.INT);

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

    return Int32Type.instance.compose(value);
}

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

License:Apache License

/**
 * Set the {@code i}th value to the provided integer.
 *
 * @param i the index of the variable to set.
 * @param v the value to set.//  www .  j  a va2  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 INT.
 */
public BoundStatement setInt(int i, int v) {
    metadata().checkType(i, DataType.Name.INT);
    return setValue(i, Int32Type.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  .  j a va  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 an 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 an integer. If the
 * value is NULL, {@code 0} is returned.
 *
 * @throws IndexOutOfBoundsException if {@code i < 0 || i >= this.columns().size()}.
 * @throws InvalidTypeException if column {@code i} is not of type INT.
 *//*  w  w w .  ja  v  a2  s  .  c  o m*/
public int getInt(int i) {
    metadata.checkType(i, DataType.Name.INT);

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

    return Int32Type.instance.compose(value);
}

From source file:com.dse.pig.udfs.AbstractCassandraStorage.java

License:Apache License

/** convert object to ByteBuffer */
protected ByteBuffer objToBB(Object o) {
    if (o == null)
        return nullToBB();
    if (o instanceof java.lang.String)
        return ByteBuffer.wrap(new DataByteArray((String) o).get());
    if (o instanceof Integer)
        return Int32Type.instance.decompose((Integer) o);
    if (o instanceof Long)
        return LongType.instance.decompose((Long) o);
    if (o instanceof Float)
        return FloatType.instance.decompose((Float) o);
    if (o instanceof Double)
        return DoubleType.instance.decompose((Double) o);
    if (o instanceof java.util.UUID)
        //           return ByteBuffer.wrap(((UUID) o).toString().getBytes());
        return ByteBuffer.wrap(UUIDGen.decompose((java.util.UUID) o));
    if (o instanceof Tuple) {
        List<Object> objects = ((Tuple) o).getAll();
        //collections
        if (objects.size() > 0 && objects.get(0) instanceof String) {
            String collectionType = (String) objects.get(0);
            if ("set".equalsIgnoreCase(collectionType) || "list".equalsIgnoreCase(collectionType))
                return objToListOrSetBB(objects.subList(1, objects.size()));
            else if ("map".equalsIgnoreCase(collectionType))
                return objToMapBB(objects.subList(1, objects.size()));

        }//  ww w.ja  v a2 s. c o  m
        return objToCompositeBB(objects);
    }

    return ByteBuffer.wrap(((DataByteArray) o).get());
}

From source file:com.impetus.client.cassandra.common.CassandraUtilities.java

License:Apache License

/**
 * @param value/*from  w  w  w . jav  a 2s  .c  o  m*/
 * @param f
 * @return
 */
public static ByteBuffer toBytes(Object value, Class<?> clazz) {
    if (clazz.isAssignableFrom(String.class)) {
        return UTF8Type.instance.decompose((String) value);
    } else if (clazz.equals(int.class) || clazz.isAssignableFrom(Integer.class)) {
        return Int32Type.instance.decompose(Integer.parseInt(value.toString()));
    } else if (clazz.equals(long.class) || clazz.isAssignableFrom(Long.class)) {
        return LongType.instance.decompose(Long.parseLong(value.toString()));
    } else if (clazz.equals(boolean.class) || clazz.isAssignableFrom(Boolean.class)) {
        return BooleanType.instance.decompose(Boolean.valueOf(value.toString()));
    } else if (clazz.equals(double.class) || clazz.isAssignableFrom(Double.class)) {
        return DoubleType.instance.decompose(Double.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(java.util.UUID.class)) {
        return UUIDType.instance.decompose(UUID.fromString(value.toString()));
    } else if (clazz.equals(float.class) || clazz.isAssignableFrom(Float.class)) {
        return FloatType.instance.decompose(Float.valueOf(value.toString()));
    } else if (clazz.isAssignableFrom(Date.class)) {
        DateAccessor dateAccessor = new DateAccessor();
        return DateType.instance.decompose((Date) value);
    } else {
        if (value.getClass().isAssignableFrom(String.class)) {
            value = PropertyAccessorFactory.getPropertyAccessor(clazz).fromString(clazz, value.toString());
        }
        return BytesType.instance
                .decompose(ByteBuffer.wrap(PropertyAccessorFactory.getPropertyAccessor(clazz).toBytes(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.//  w w w.  j a  v a2s. co  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.  j  av  a2s . c  o  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  w  w w. j av a  2 s.co  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);
        }
    };
}