@Override public String readString() { return read( StringSerializer.get() ); }
/** * add a string to buffer * @param value * @return */ public FieldBufferBuilder addString( final String value ) { buffer.add( STRING_SERIALIZER.toByteBuffer( value ) ); return this; }
log.debug("Entity Wrapper Deserialized: " + StringSerializer.get().fromByteBuffer(byteBuffer));
@Override public PreparedIndexExpression<K, C> value(String value) { this.value = StringSerializer.get().toByteBuffer(value); return this; }
public RowUniquenessConstraint<K, C> withData(String data) { this.data = StringSerializer.get().fromString(data); return this; }
/** * Return the value as an String */ public String readString() { return STRING_SERIALIZER.fromByteBuffer( getNext() ); }
@Override public CqlStatement withCql(String cql) { query = StringSerializer.get().toByteBuffer(cql); return this; }
public RowUniquenessConstraint<K, C> withData(String data) { this.data = StringSerializer.get().fromString(data); return this; }
private ColumnFamily getLocksColumnFamily() { if ( columnFamily == null ) { columnFamily = ColumnFamily.newColumnFamily( CF_NAME, StringSerializer.get(), StringSerializer.get() ); if ( logger.isDebugEnabled() ) { try { final KeyspaceDefinition kd = keyspace.describeKeyspace(); final ColumnFamilyDefinition cfd = kd.getColumnFamily( columnFamily.getName() ); Map<String, Object> options = new HashMap<>( 1 ); options.put( "gc_grace_seconds", cfd.getGcGraceSeconds() ); options.put( "caching", cfd.getCaching() ); options.put( "compaction_strategy", cfd.getCompactionStrategy() ); options.put( "compaction_strategy_options", cfd.getCompactionStrategyOptions() ); logger.debug( "Locks column family {} exists with options: {}", cfd.getName(), options); } catch ( ConnectionException ce ) { logger.warn("Error connecting to Cassandra for debug column family info", ce); } } } return columnFamily; }
@Override public CqlStatement withCql(String cql) { query = StringSerializer.get().toByteBuffer(cql); return this; }
public String readDataAsString() throws Exception { return StringSerializer.get().fromByteBuffer(readData()); } }
@Test public void testRowRangeAllColumnsQuery() throws Exception { String startToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("A")); String endToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("G")); keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(3 == result.size()); for (Row<String, String> row : result) { Assert.assertTrue(26 == row.getColumns().size()); } }
@Override public Health getHealth() { try { ColumnFamily<String, String> CF_SYSTEM_LOCAL = new ColumnFamily<String, String>( "system.local", StringSerializer.get(), StringSerializer.get(), StringSerializer.get() ); OperationResult<CqlResult<String, String>> result = keyspace.prepareQuery( CF_SYSTEM_LOCAL ) .setConsistencyLevel(ConsistencyLevel.CL_ONE) .withCql( "SELECT now() FROM system.local;" ) .execute(); if ( result.getResult().getRows().size() > 0 ) { return Health.GREEN; } } catch ( ConnectionException ex ) { logger.error( "Error connecting to Cassandra", ex ); } return Health.RED; } }
@Override public CqlStatement withCql(String cql) { query = StringSerializer.get().toByteBuffer(cql); return this; }
public String readDataAsString() throws Exception { return StringSerializer.get().fromByteBuffer(readData()); } }
@Test public void testRowRangeColumnSetQuery() throws Exception { String startToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("A")); String endToken = Murmur3Partitioner.get().getTokenForKey(StringSerializer.get().fromString("G")); keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .withColumnSlice("a", "s", "d", "f") .execute(); Rows<String, String> result = keyspace.prepareQuery(CF_ROW_RANGE) .withCaching(true) .getRowRange(null, null, startToken, endToken, 10) .withColumnSlice("a", "s", "d", "f") .execute() .getResult(); Assert.assertNotNull(result); Assert.assertTrue(3 == result.size()); for (Row<String, String> row : result) { Assert.assertTrue(4 == row.getColumns().size()); } }
private ColumnFamily createLocksColumnFamily() throws ConnectionException { ColumnFamily<String, String> cflocks = ColumnFamily.newColumnFamily( CF_NAME, StringSerializer.get(), StringSerializer.get() ); final KeyspaceDefinition kd = keyspace.describeKeyspace(); final ColumnFamilyDefinition cfdef = kd.getColumnFamily( cflocks.getName() ); if ( cfdef == null ) { // create only if does not already exist MultiTenantColumnFamilyDefinition mtcfd = new MultiTenantColumnFamilyDefinition( cflocks, BytesType.class.getSimpleName(), UTF8Type.class.getSimpleName(), BytesType.class.getSimpleName(), MultiTenantColumnFamilyDefinition.CacheOption.ALL ); Map<String, Object> cfOptions = mtcfd.getOptions(); // Additionally set the gc grace low cfOptions.put( "gc_grace_seconds", 60 ); keyspace.createColumnFamily( mtcfd.getColumnFamily(), cfOptions ); logger.info( "Created column family {}", mtcfd.getOptions() ); cflocks = mtcfd.getColumnFamily(); } else { return getLocksColumnFamily(); } return cflocks; }
@Override public CqlStatement withCql(String cql) { query = StringSerializer.get().toByteBuffer(cql); return this; }