public String getString(N columnName) { return StringSerializer.get().fromByteBuffer(getColumnValue(columnName)); }
@Test public void testMultiCallOnByteBuffer() { List<Column> tColumns = new ArrayList<Column>(); Column column = new Column(se.toByteBuffer("1")); column.setValue(ByteBuffer.wrap("colvalue".getBytes())); column.setTimestamp(0L); tColumns.add(column); ColumnSlice<String, ByteBuffer> slice = new ColumnSliceImpl<String, ByteBuffer>(tColumns, se, ByteBufferSerializer.get()); ByteBuffer value = slice.getColumnByName("1").getValue(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); value.rewind(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); value.rewind(); Assert.assertEquals("colvalue", se.fromByteBuffer(value)); } }
CounterColumn cc = cols.get(i); gotlist.add(cc.name.duplicate()); assertEquals(getValueFromName(ss.fromByteBuffer(cc.name.duplicate())), cc.getValue());
@Test public void test() throws Exception { Assert.assertEquals(str, s.fromByteBuffer(s.toByteBuffer(str))); if (str != null) { Assert .assertEquals(str, ByteBufferUtil.string(ByteBufferUtil.bytes(str))); } if (str != null) { UTF8Type.instance.validate(s.toByteBuffer(str)); } } }
@Override public Enum fromValue(ByteBuffer value, Class<Enum> targetType) throws Exception { String stringValue = StringSerializer.get().fromByteBuffer(value); return stringValue != null ? valueOf(targetType, stringValue) : null; }
public String fromValue(ByteBuffer value, Class<String> targetType) { return StringSerializer.get().fromByteBuffer(value); } }
@Test public void testEditColumnFamily() throws Exception { BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition(); columnFamilyDefinition.setKeyspaceName("DynKeyspace3"); columnFamilyDefinition.setName("DynamicCF"); ColumnFamilyDefinition cfDef = new ThriftCfDef(columnFamilyDefinition); KeyspaceDefinition keyspaceDefinition = HFactory.createKeyspaceDefinition("DynKeyspace3", "org.apache.cassandra.locator.SimpleStrategy", 1, Arrays.asList(cfDef)); cassandraCluster.addKeyspace(keyspaceDefinition); KeyspaceDefinition fromCluster = cassandraCluster.describeKeyspace("DynKeyspace3"); cfDef = fromCluster.getCfDefs().get(0); columnFamilyDefinition = new BasicColumnFamilyDefinition(cfDef); BasicColumnDefinition columnDefinition = new BasicColumnDefinition(); columnDefinition.setName(StringSerializer.get().toByteBuffer("birthdate")); columnDefinition.setIndexName("birthdate_idx"); columnDefinition.setIndexType(ColumnIndexType.KEYS); columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName()); columnFamilyDefinition.addColumnDefinition(columnDefinition); columnDefinition = new BasicColumnDefinition(); columnDefinition.setName(StringSerializer.get().toByteBuffer("nonindexed_field")); columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName()); columnFamilyDefinition.addColumnDefinition(columnDefinition); cassandraCluster.updateColumnFamily(new ThriftCfDef(columnFamilyDefinition)); fromCluster = cassandraCluster.describeKeyspace("DynKeyspace3"); assertEquals("birthdate",StringSerializer.get().fromByteBuffer(fromCluster.getCfDefs().get(0).getColumnMetadata().get(0).getName())); assertEquals("birthdate_idx",fromCluster.getCfDefs().get(0).getColumnMetadata().get(0).getIndexName()); assertEquals("nonindexed_field",StringSerializer.get().fromByteBuffer(fromCluster.getCfDefs().get(0).getColumnMetadata().get(1).getName())); }
private HColumn<ByteBuffer, ByteBuffer> getUnionTypeColumn(String fieldName, Object[] hColumns) { for (int iCnt = 0; iCnt < hColumns.length; iCnt++){ @SuppressWarnings("unchecked") HColumn<ByteBuffer, ByteBuffer> hColumn = (HColumn<ByteBuffer, ByteBuffer>)hColumns[iCnt]; String columnName = StringSerializer.get().fromByteBuffer(hColumn.getNameBytes().duplicate()); if (fieldName.equals(columnName)) return hColumn; } return null; }
/** * Gets a specific CassandraColumn within a row using its name * @param pCassandraColumnName * @return CassandraColumn */ public CassandraColumn getCassandraColumn(String pCassandraColumnName){ for (CassandraColumn cColumn: this) if ( pCassandraColumnName.equals(StringSerializer.get().fromByteBuffer(cColumn.getName())) ) return cColumn; return null; }
@Override //TODO: CharSequence cause Test Fail. All tests set UTF8. When change test set type. This will be CharSequence public Utf8 fromByteBuffer(ByteBuffer byteBuffer) { if (byteBuffer == null) { return null; } return new Utf8(StringSerializer.get().fromByteBuffer(byteBuffer)); }
/** * Gets the column containing the type of the union type element stored. * TODO: This might seem too much of a overhead if we consider that N rows have M columns, * this might have to be reviewed to get the specific column in O(1) * @param pFieldName * @param pCassandraRow * @return */ private CassandraColumn getUnionTypeColumn(String pFieldName, Object[] pCassandraRow){ for (int iCnt = 0; iCnt < pCassandraRow.length; iCnt++){ CassandraColumn cColumn = (CassandraColumn)pCassandraRow[iCnt]; String columnName = StringSerializer.get().fromByteBuffer(cColumn.getName().duplicate()); if (pFieldName.equals(columnName)) return cColumn; } return null; }
public String getString(N columnName) { return StringSerializer.get().fromByteBuffer(getColumnValue(columnName)); }
public String getString(N columnName) { return StringSerializer.get().fromByteBuffer(getColumnValue(columnName)); }
public static <T> String getAsStringValue( ColumnSlice<String, T> columnSlice, String columnName ) { StringSerializer ss = StringSerializer.get(); if ( StringUtils.isEmpty( columnName ) ) { return null; } HColumn<String, T> hColumn = columnSlice.getColumnByName( columnName ); return hColumn == null ? null : ss.fromByteBuffer( hColumn.getValueBytes() ); }
@Override public String getStoredType(ByteBuffer rowKey, String cfName, Keyspace keyspace) { SliceQuery<ByteBuffer, String, ByteBuffer> query = MappingUtils .buildSliceQuery(rowKey, columns, cfName, keyspace); QueryResult<ColumnSlice<String, ByteBuffer>> result = query.execute(); // only need to check > 0. If the entity wasn't tombstoned then we would // have loaded the static jpa marker column HColumn<String, ByteBuffer> descrimValue = result.get().getColumnByName( DISCRIMINAATOR_COL); if (descrimValue == null) { return null; } return StringSerializer.get().fromByteBuffer(descrimValue.getValue()); }
private PathTrackingEntry map( ColumnSlice<String, ?> columnSlice ) { final DynamicDelegatedSerializer<Object> serializer = new DynamicDelegatedSerializer<Object>(); String trackingId = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "trackingId" ).getValueBytes() ); String nodeId = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "nodeId" ).getValueBytes() ); String className = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "className" ).getValueBytes() ); String methodName = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "methodName" ).getValueBytes() ); long startTime = getOrDefault( serializer, // columnSlice.getColumnByName( "startTime" ), // LongSerializer.get() ).longValue(); long executionTime = getOrDefault( serializer, // columnSlice.getColumnByName( "executionTime" ), // LongSerializer.get() ).longValue(); int level = getOrDefault( serializer, // columnSlice.getColumnByName( "level" ), // LongSerializer.get() ).intValue(); return new PathTrackingEntry( trackingId, // nodeId, // className, // methodName, // startTime, // executionTime, // level ); }
private PathTrackingEntry map( ColumnSlice<String, ?> columnSlice ) { final DynamicDelegatedSerializer<Object> serializer = new DynamicDelegatedSerializer<Object>(); String trackingId = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "trackingId" ).getValueBytes() ); String nodeId = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "nodeId" ).getValueBytes() ); String className = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "className" ).getValueBytes() ); String methodName = StringSerializer.get().fromByteBuffer( columnSlice.getColumnByName( "methodName" ).getValueBytes() ); long startTime = getOrDefault( serializer, // columnSlice.getColumnByName( "startTime" ), // LongSerializer.get() ).longValue(); long executionTime = getOrDefault( serializer, // columnSlice.getColumnByName( "executionTime" ), // LongSerializer.get() ).longValue(); int level = getOrDefault( serializer, // columnSlice.getColumnByName( "level" ), // LongSerializer.get() ).intValue(); return new PathTrackingEntry( trackingId, // nodeId, // className, // methodName, // startTime, // executionTime, // level ); }
String fieldName = this.reverseMap.get(family + ":" + StringSerializer.get().fromByteBuffer(cassandraColumn.getName().duplicate()));
String memberName = StringSerializer.get().fromByteBuffer(hColumn.getName()); if (memberName.indexOf(CassandraStore.UNION_COL_SUFIX) < 0) {