@Override public byte[] getByteArray(SN sColumnName, N columnName) { return extractType(sColumnName, columnName, BytesArraySerializer.get()); }
public void setByteArray(N columnName, byte[] value) { addInsertion(columnName, value, BytesArraySerializer.get(), globalTtl); }
public void setByteArray(N columnName, byte[] value, int ttl) { addInsertion(columnName, value, BytesArraySerializer.get(), ttl); }
public void setByteArray(N subColumnName, byte[] value) { addToSubColumns(subColumnName, value, BytesArraySerializer.get(), globalTtl); }
public byte[] getByteArray(N columnName) { return BytesArraySerializer.get() .fromByteBuffer(getColumnValue(columnName)); }
private HColumn<String, byte[]> createHColumn(String name, byte[] value) { return HFactory.createColumn(name, value, StringSerializer.get(), BytesArraySerializer.get()); }
/** * * @param keyspace * @param obj * @return */ public <T> T saveObj(Keyspace keyspace, T obj) { if (null == obj) { throw new IllegalArgumentException("object cannot be null"); } Mutator<byte[]> m = HFactory.createMutator(keyspace, BytesArraySerializer.get()); saveObj(keyspace, m, obj); m.execute(); return obj; }
/** * Write the data to column if the configured chunk size is reached or if the * stream should be closed * * @param close * @throws IOException */ private void writeData(boolean close) throws IOException { if (pos != 0 && (close || pos == chunk.length - 1)) { byte[] data; if (pos != chunk.length - 1) { data = new byte[(int) pos + 1]; // we need to adjust the array System.arraycopy(chunk, 0, data, 0, data.length); } else { data = chunk; } try { mutator.insert(key, cf, HFactory.createColumn(chunkPos, data, LongSerializer.get(), BytesArraySerializer.get())); } catch (HectorException e) { throw new IOException("Unable to write data", e); } chunkPos++; pos = 0; } }
@SuppressWarnings("unchecked") private <T> void addAnonymousProperties(T obj, CFMappingDef<T> cfMapDef, Map<String, HColumn<String, byte[]>> colSet) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { Method meth = cfMapDef.getAnonymousPropertyGetHandler(); if (null == meth) { return; } Collection<Entry<String, Object>> propColl = (Collection<Entry<String, Object>>) meth.invoke( obj, (Object[]) null); if (null == propColl || propColl.isEmpty()) { return; } for (Entry<String, Object> entry : propColl) { if (!(entry.getKey() instanceof String) || !entry.getValue().getClass().equals(cfMapDef.getAnonymousValueType())) { throw new HectorObjectMapperException("Class, " + cfMapDef.getRealClass() + ", anonymous properties must have entry.key of type, " + String.class.getName() + ", and entry.value of type, " + cfMapDef.getAnonymousValueType().getName() + ", to properly map to Cassandra column name/value"); } } for (Entry<String, Object> entry : propColl) { colSet.put( entry.getKey(), HFactory.createColumn(entry.getKey(), cfMapDef.getAnonymousValueSerializer().toBytes(entry.getValue()), StringSerializer.get(), BytesArraySerializer.get())); } }
/** * Persists the object collection using a single batch mutate. It is up to the * client to partition large collections appropriately so not to cause timeout * or buffer overflow issues. The objects can be heterogenous (mapping to * multiple column families, etc.) * * @param keyspace * @param objColl * @return */ public Collection<?> saveObjCollection(Keyspace keyspace, Collection<?> objColl) { Mutator<byte[]> m = HFactory.createMutator(keyspace, BytesArraySerializer.get()); Collection<?> retColl = saveObjCollection(keyspace, objColl, m); m.execute(); return retColl; }
serializer = BooleanSerializer.get(); } else if (valueClass.equals(byte[].class)) { serializer = BytesArraySerializer.get(); } else if (valueClass.equals(ByteBuffer.class)) { serializer = ByteBufferSerializer.get();
public ColumnSliceMockImpl add( String name, byte[] value ) { HColumnImpl<String, byte[]> col = new HColumnImpl<String, byte[]>(StringSerializer.get(), BytesArraySerializer.get()); col.setName(name); col.setValue(value); colList.add(col); return this; } }
/** * Fetch the next chunk. * * @return exists if there was a chunk to fetch. * @throws IOException */ private boolean fetchChunk() throws IOException { try { ColumnQuery<T, Long, byte[]> query = HFactory.createColumnQuery(keyspace, rowKeySerializer, LongSerializer.get(), BytesArraySerializer.get()); QueryResult<HColumn<Long, byte[]>> result = query.setColumnFamily(cf).setKey(key).setName(chunkPos).execute(); HColumn<Long, byte[]> column = result.get(); if (column != null) { chunk = column.getValue(); chunkPos++; pos = 0; return true; } else { return false; } } catch (HectorException e) { throw new IOException("Unable to read data", e); } }
serializer = BooleanSerializer.get(); } else if (value instanceof byte[]) { serializer = BytesArraySerializer.get(); } else if (value instanceof ByteBuffer) { serializer = ByteBufferSerializer.get();
assertEquals(obj.getDateProp(), DateSerializer.get().fromBytes(colMap.get("dp").getValue())); assertEquals("somebytes", new String(BytesArraySerializer.get().fromBytes(colMap.get("bytes").getValue())));
composite.addComponent(1, new byte[]{0, 1, 2, 3}, BytesArraySerializer.get(), "BytesType", ComponentEquality.EQUAL); composite.addComponent(2, -1, IntegerSerializer.get(), "IntegerType", ComponentEquality.EQUAL); composite.addComponent(3, lexUUID, UUIDSerializer.get(), "LexicalUUIDType", ComponentEquality.EQUAL); composite.addComponent(9, new byte[]{0, 1, 2, 3}, BytesArraySerializer.get(), "BytesType(reversed=true)", ComponentEquality.EQUAL); composite.addComponent(10, -1, IntegerSerializer.get(), "IntegerType(reversed=true)", ComponentEquality.EQUAL); composite.addComponent(11, lexUUID, UUIDSerializer.get(), "LexicalUUIDType(reversed=true)", ComponentEquality.EQUAL); assertArrayEquals(new byte[]{0, 1, 2, 3}, parsed.get(1, BytesArraySerializer.get())); assertEquals(Integer.valueOf(-1), parsed.get(2, IntegerSerializer.get())); assertEquals(lexUUID, parsed.get(3, UUIDSerializer.get())); assertArrayEquals(new byte[]{0, 1, 2, 3}, parsed.get(9, BytesArraySerializer.get())); assertEquals(Integer.valueOf(-1), parsed.get(10, IntegerSerializer.get())); assertEquals(lexUUID, parsed.get(11, UUIDSerializer.get()));
private static void checkColumn(Keyspace keyspace, RowModel expectedRowModel, String expectedColumnFamilyName, ColumnModel expectedColumnModel) throws Error { ColumnQuery<byte[], byte[], byte[]> columnQuery = HFactory.createColumnQuery(keyspace, BytesArraySerializer.get(), BytesArraySerializer.get(), BytesArraySerializer.get()); columnQuery.setColumnFamily(expectedColumnFamilyName).setKey(getBytes(expectedRowModel.getKey())) .setName(getBytes(expectedColumnModel.getName())); QueryResult<HColumn<byte[], byte[]>> result = columnQuery.execute(); HColumn<byte[], byte[]> hColumn = result.get(); checkColumnName(expectedColumnModel, hColumn); checkColumnValue(expectedRowModel, hColumn); }
slice.add("up", UUIDSerializer.get().toBytes(uuidProp)); slice.add("dp", DateSerializer.get().toBytes(dateProp)); slice.add("bytes", BytesArraySerializer.get().toBytes(bytesProp)); slice.add("color", StringSerializer.get().toBytes(color.getName())); slice.add("serialProp", ObjectSerializer.get().toBytes(serialProp));
public void setByteArray(N columnName, byte[] value) { HColumn<N, byte[]> column = columnFactory.createColumn(columnName, value, clock, template.getTopSerializer(), BytesArraySerializer.get()); mutator.addInsertion(getCurrentKey(), template.getColumnFamily(), column); }