return Int32Type.instance.decompose(Integer.parseInt(value.toString()));
private static Object decompose(Object value, Class clazz) { ByteBuffer buf = ByteBuffer.wrap((byte[]) value, 0, ((byte[]) value).length); return Int32Type.instance.compose(buf); } }
@Override public boolean isValueCompatibleWithInternal(AbstractType<?> otherType) { return this == otherType || Int32Type.instance.isValueCompatibleWith(otherType) || LongType.instance.isValueCompatibleWith(otherType); }
public int getTimeToLive(QueryOptions options, int defaultTimeToLive) throws InvalidRequestException { if (timeToLive == null) return defaultTimeToLive; ByteBuffer tval = timeToLive.bindAndGet(options); if (tval == null) return 0; if (tval == ByteBufferUtil.UNSET_BYTE_BUFFER) return defaultTimeToLive; try { Int32Type.instance.validate(tval); } catch (MarshalException e) { throw new InvalidRequestException("Invalid timestamp value: " + tval); } int ttl = Int32Type.instance.compose(tval); if (ttl < 0) throw new InvalidRequestException("A TTL must be greater or equal to 0, but was " + ttl); if (ttl > MAX_TTL) throw new InvalidRequestException(String.format("ttl is too large. requested (%d) maximum (%d)", ttl, MAX_TTL)); if (defaultTimeToLive != LivenessInfo.NO_TTL && ttl == LivenessInfo.NO_TTL) return LivenessInfo.NO_TTL; return ttl; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { if (parsed instanceof String) return new Constants.Value(fromString((String) parsed)); Number parsedNumber = (Number) parsed; if (!(parsedNumber instanceof Integer)) throw new MarshalException(String.format("Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); return new Constants.Value(getSerializer().serialize(parsedNumber.intValue())); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion) { return getSerializer().deserialize(buffer).toString(); }
private int getLimit(Term limit, QueryOptions options) { int userLimit = DataLimits.NO_LIMIT; if (limit != null) { ByteBuffer b = checkNotNull(limit.bindAndGet(options), "Invalid null value of limit"); // treat UNSET limit value as 'unlimited' if (b != UNSET_BYTE_BUFFER) { try { Int32Type.instance.validate(b); userLimit = Int32Type.instance.compose(b); checkTrue(userLimit > 0, "LIMIT must be strictly positive"); } catch (MarshalException e) { throw new InvalidRequestException("Invalid limit value"); } } } return userLimit; }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { if (parsed instanceof String) return new Constants.Value(fromString((String) parsed)); Number parsedNumber = (Number) parsed; if (!(parsedNumber instanceof Integer)) throw new MarshalException(String.format("Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); return new Constants.Value(getSerializer().serialize(parsedNumber.intValue())); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
@Override public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion) { return getSerializer().deserialize(buffer).toString(); }
private int getLimit(Term limit, QueryOptions options) { int userLimit = DataLimits.NO_LIMIT; if (limit != null) { ByteBuffer b = checkNotNull(limit.bindAndGet(options), "Invalid null value of limit"); // treat UNSET limit value as 'unlimited' if (b != UNSET_BYTE_BUFFER) { try { Int32Type.instance.validate(b); userLimit = Int32Type.instance.compose(b); checkTrue(userLimit > 0, "LIMIT must be strictly positive"); } catch (MarshalException e) { throw new InvalidRequestException("Invalid limit value"); } } } return userLimit; }
/** * This returns a dummy value to conform with Hadoop API but isn't used for Cassandra writing */ private ByteBuffer generateDummyValue() { return Int32Type.instance.decompose(1); } }
@Override public Term fromJSONObject(Object parsed) throws MarshalException { try { if (parsed instanceof String) return new Constants.Value(fromString((String) parsed)); Number parsedNumber = (Number) parsed; if (!(parsedNumber instanceof Integer)) throw new MarshalException(String.format("Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); return new Constants.Value(getSerializer().serialize(parsedNumber.intValue())); } catch (ClassCastException exc) { throw new MarshalException(String.format( "Expected an int value, but got a %s: %s", parsed.getClass().getSimpleName(), parsed)); } }
public int getInt(String column) { return Int32Type.instance.compose(data.get(column)); }
@Override public boolean isValueCompatibleWithInternal(AbstractType<?> otherType) { return this == otherType || Int32Type.instance.isValueCompatibleWith(otherType) || LongType.instance.isValueCompatibleWith(otherType); }
@Override public String toJSONString(ByteBuffer buffer, ProtocolVersion protocolVersion) { return getSerializer().deserialize(buffer).toString(); }
private int getLimit(Term limit, QueryOptions options) { int userLimit = DataLimits.NO_LIMIT; if (limit != null) { ByteBuffer b = checkNotNull(limit.bindAndGet(options), "Invalid null value of limit"); // treat UNSET limit value as 'unlimited' if (b != UNSET_BYTE_BUFFER) { try { Int32Type.instance.validate(b); userLimit = Int32Type.instance.compose(b); checkTrue(userLimit > 0, "LIMIT must be strictly positive"); } catch (MarshalException e) { throw new InvalidRequestException("Invalid limit value"); } } } return userLimit; }
private static byte[] compose(Object value, Class clazz) { return Int32Type.instance.decompose((Integer) value).array(); }