@Override public int getInt(N name) { return extractColumnValue(name, IntegerSerializer.get()); }
@Override public Float fromByteBuffer(ByteBuffer bytes) { return Float.intBitsToFloat(IntegerSerializer.get().fromByteBuffer(bytes)); }
@Override public ByteBuffer toByteBuffer(Float obj) { return IntegerSerializer.get().toByteBuffer(Float.floatToRawIntBits(obj)); }
public byte[] toByteArray(BigDecimal bigDecimal) { byte[] bigIntBytes = bigDecimal.unscaledValue().toByteArray(); byte[] scaleBytes = IntegerSerializer.get().toBytes(bigDecimal.scale()); byte[] bytes = new byte[scaleBytes.length + bigIntBytes.length]; System.arraycopy(scaleBytes, 0, bytes, 0, scaleBytes.length); System.arraycopy(bigIntBytes, 0, bytes, scaleBytes.length, bigIntBytes.length); return bytes; }
private Object convertColValueToDiscType(DiscriminatorType discType, byte[] value) { switch (discType) { case STRING: return new String(value); case CHAR: return ByteBuffer.wrap(value).asCharBuffer().get(); case INTEGER: return IntegerSerializer.get().fromBytes(value); } throw new RuntimeException("must have added a new discriminator type, " + discType + ", because don't know how to convert db value - cannot continue"); }
private DynamicComposite genComposite(int start, ComponentEquality equality) { DynamicComposite composite = new DynamicComposite(); composite.addComponent(start, IntegerSerializer.get(), IntegerSerializer .get().getComparatorType().getTypeName(), equality); return composite; }
private void test(Integer number) { assertEquals(number, ext.fromByteBuffer(ext.toByteBuffer(number))); // test compatibility with ByteBuffer default byte order if (number != null) { ByteBuffer b = ByteBuffer.allocate(4); b.putInt(number); b.rewind(); assertEquals(number, ext.fromByteBuffer(b)); } } }
@Test public void testFromCassandra() { assertEquals(new Integer(1), ext.fromByteBuffer(ByteBufferUtil.bytes(1))); assertEquals(new Integer(-1), ext.fromByteBuffer(ByteBufferUtil.bytes(-1))); assertEquals(new Integer(0), ext.fromByteBuffer(ByteBufferUtil.bytes(0))); assertEquals(new Integer(Integer.MAX_VALUE), ext.fromByteBuffer(ByteBufferUtil.bytes(Integer.MAX_VALUE))); assertEquals(new Integer(Integer.MIN_VALUE), ext.fromByteBuffer(ByteBufferUtil.bytes(Integer.MIN_VALUE))); }
@Test public void testFromCassandraAsBytes() { assertEquals(new Integer(1), ext.fromBytes(ByteBufferUtil.bytes(1).array())); assertEquals(new Integer(-1), ext.fromBytes(ByteBufferUtil.bytes(-1).array())); assertEquals(new Integer(0), ext.fromBytes(ByteBufferUtil.bytes(0).array())); assertEquals(new Integer(Integer.MAX_VALUE), ext.fromBytes(ByteBufferUtil.bytes(Integer.MAX_VALUE).array())); assertEquals(new Integer(Integer.MIN_VALUE), ext.fromBytes(ByteBufferUtil.bytes(Integer.MIN_VALUE).array())); }
private byte[] convertDiscTypeToColValue(DiscriminatorType discType, Object value) { switch (discType) { case STRING: return StringSerializer.get().toBytes((String) value); case CHAR: return String.valueOf((Character) value).getBytes(); case INTEGER: return IntegerSerializer.get().toBytes((Integer) value); } throw new RuntimeException("must have added a new discriminator type, " + discType + ", because don't know how to convert db value - cannot continue"); }
assertEquals(obj.getLongProp2(), LongSerializer.get().fromBytes(colMap.get("lp2").getValue())); assertEquals(obj.getIntProp1(), (int) IntegerSerializer.get().fromBytes(colMap.get("ip1").getValue())); assertEquals(obj.getIntProp2(), IntegerSerializer.get().fromBytes(colMap.get("ip2").getValue())); assertEquals(obj.isBoolProp1(), BooleanSerializer.get().fromBytes(colMap.get("bp1").getValue())); assertEquals(obj.getBoolProp2(), BooleanSerializer.get()
/** * Generate the given number of composites and returns the key for the row * * @param size */ private ByteBuffer generateComposites(int size) { Mutator<ByteBuffer> mutator = HFactory.createMutator( CassandraTestBase.keyspace, ByteBufferSerializer.get()); ByteBuffer rowKey = generateRowKey(); for (int i = 0; i < size; i++) { DynamicComposite composite = new DynamicComposite(); composite.addComponent(i, IntegerSerializer.get(), IntegerSerializer .get().getComparatorType().getTypeName()); mutator.addInsertion( rowKey, AbstractIndexOperation.CF_NAME, HFactory.createColumn(composite, holder, DynamicCompositeSerializer.get(), ByteBufferSerializer.get())); } mutator.execute(); return rowKey; }
/** * Read the field from the query result into the opject within the state * manager. * * @param stateManager * @param result * @return True if the field was loaded. False otherwise */ public boolean readField(OpenJPAStateManager stateManager, QueryResult<ColumnSlice<String, ByteBuffer>> result) { HColumn<String, ByteBuffer> bigIntCol = result.get().getColumnByName(name); HColumn<String, ByteBuffer> scaleCol = result.get().getColumnByName( scaleColumnName); if (bigIntCol == null || scaleCol == null) { stateManager.store(fieldId, null); return false; } BigInteger unscaled = BIGINT_SER.fromByteBuffer(bigIntCol.getValueBytes()); int scale = INT_SER.fromByteBuffer(scaleCol.getValueBytes()); stateManager.store(fieldId, new BigDecimal(unscaled, scale)); return true; }
public void setInteger(N columnName, Integer value) { addInsertion(columnName, value, IntegerSerializer.get(), globalTtl); }
public Integer getInteger(N columnName) { return IntegerSerializer.get().fromByteBuffer(getColumnValue(columnName)); }
public ByteBuffer toValue(Integer value) { return IntegerSerializer.get().toByteBuffer(value); }
public byte[] toByteArray(BigDecimal bigDecimal) { byte[] bigIntBytes = bigDecimal.unscaledValue().toByteArray(); byte[] scaleBytes = IntegerSerializer.get().toBytes(bigDecimal.scale()); byte[] bytes = new byte[scaleBytes.length + bigIntBytes.length]; System.arraycopy(scaleBytes, 0, bytes, 0, scaleBytes.length); System.arraycopy(bigIntBytes, 0, bytes, scaleBytes.length, bigIntBytes.length); return bytes; }
@Override public Integer getInteger(SN sColumnName, N columnName) { return extractType(sColumnName, columnName, IntegerSerializer.get()); }
public Integer fromValue(ByteBuffer value, Class<Integer> targetType) { return IntegerSerializer.get().fromByteBuffer(value); } }
@Override public ByteBuffer toByteBuffer(Float obj) { return IntegerSerializer.get().toByteBuffer(Float.floatToRawIntBits(obj)); }