public static Map<String, ByteBuffer> getColumnMap( List<HColumn<String, ByteBuffer>> columns ) { Map<String, ByteBuffer> column_map = new TreeMap<String, ByteBuffer>( String.CASE_INSENSITIVE_ORDER ); if ( columns != null ) { for ( HColumn<String, ByteBuffer> column : columns ) { String column_name = column.getName(); column_map.put( column_name, column.getValue() ); } } return column_map; }
public static <K, V> Map<K, V> asMap( List<HColumn<K, V>> columns ) { if ( columns == null ) { return null; } Map<K, V> column_map = new LinkedHashMap<K, V>(); for ( HColumn<K, V> column : columns ) { K column_name = column.getName(); column_map.put( column_name, column.getValue() ); } return column_map; }
public static Queue deserializeQueue( List<HColumn<String, ByteBuffer>> columns ) { Queue queue = null; Map<String, Object> properties = new HashMap<String, Object>(); for ( HColumn<String, ByteBuffer> column : columns ) { if ( QUEUE_PROPERTIES.containsKey( column.getName() ) ) { properties .put( column.getName(), object( QUEUE_PROPERTIES.get( column.getName() ), column.getValue() ) ); } else { properties.put( column.getName(), JsonUtils.fromByteBuffer( column.getValue() ) ); } } if ( !properties.isEmpty() ) { queue = new Queue( properties ); } return queue; }
public static Message deserializeMessage( List<HColumn<String, ByteBuffer>> columns ) { Message message = null; Map<String, Object> properties = new HashMap<String, Object>(); for ( HColumn<String, ByteBuffer> column : columns ) { if ( MESSAGE_TYPE.equals( column.getName() ) || MESSAGE_ID.equals( column.getName() ) ) { properties.put( column.getName(), object( MESSAGE_PROPERTIES.get( column.getName() ), column.getValue() ) ); } else { properties.put( column.getName(), JsonUtils.fromByteBuffer( column.getValue() ) ); } } if ( !properties.isEmpty() ) { message = new Message( properties ); } return message; }
column.getName(), column.getValue(), queueId, consumerId ); logger.trace( "Max timeuuid : '{}', Current timeuuid : '{}', comparison '{}'", startTimeUUID, column.getName(), UUIDUtils.compare( startTimeUUID, column.getName() ) results.add( new TransactionPointer( column.getName(), column.getValue() ) );
/** * Get the bounds for the queue * * @return The bounds for the queue */ public QueueBounds getQueueBounds( UUID queueId ) { try { ColumnSlice<String, UUID> result = HFactory.createSliceQuery( ko, ue, se, ue ).setKey( queueId ) .setColumnNames( QUEUE_NEWEST, QUEUE_OLDEST ) .setColumnFamily( QUEUE_PROPERTIES.getColumnFamily() ).execute() .get(); if ( result != null && result.getColumnByName( QUEUE_OLDEST ) != null && result.getColumnByName( QUEUE_NEWEST ) != null ) { return new QueueBounds( result.getColumnByName( QUEUE_OLDEST ).getValue(), result.getColumnByName( QUEUE_NEWEST ).getValue() ); } } catch ( Exception e ) { logger.error( "Error getting oldest queue message ID", e ); } return null; }
DynamicComposite.fromByteBuffer( result.getName() ).get( 0, se ); if ( entityHasDictionary && coTypeIsBasic ) { values.put( name, object( dictionaryCoType, result.getValue() ) ); else if ( result.getValue().remaining() > 0 ) { values.put( name, Schema.deserializePropertyValueFromJsonBinary( result.getValue().slice(), dictionaryCoType ) );
/** * Get the position in the queue for the given appId, consumer and queu * * @param queueId The queueId * @param consumerId The consumerId */ public UUID getConsumerQueuePosition( UUID queueId, UUID consumerId ) { HColumn<UUID, UUID> result = HFactory.createColumnQuery( ko, ue, ue, ue ).setKey( consumerId ).setName( queueId ) .setColumnFamily( CONSUMERS.getColumnFamily() ).execute().get(); if ( result != null ) { return result.getValue(); } return null; }
@Override public QueueSet getSubscribers( String publisherQueuePath, String firstSubscriberQueuePath, int limit ) { UUID publisherQueueId = getQueueId( publisherQueuePath ); Keyspace ko = cass.getApplicationKeyspace( applicationId ); if ( firstSubscriberQueuePath != null ) { limit += 1; } List<HColumn<String, UUID>> columns = createSliceQuery( ko, ue, se, ue ).setKey( publisherQueueId ) .setColumnFamily( QUEUE_SUBSCRIBERS.getColumnFamily() ) .setRange( normalizeQueuePath( firstSubscriberQueuePath ), null, false, limit + 1 ).execute().get() .getColumns(); QueueSet queues = new QueueSet(); int count = Math.min( limit, columns.size() ); if ( columns != null ) { for ( int i = firstSubscriberQueuePath != null ? 1 : 0; i < count; i++ ) { HColumn<String, UUID> column = columns.get( i ); queues.addQueue( column.getName(), column.getValue() ); } } if ( columns.size() > limit ) { queues.setMore( true ); } return queues; }
@Override public QueueSet getSubscriptions( String subscriberQueuePath, String firstSubscriptionQueuePath, int limit ) { UUID subscriberQueueId = getQueueId( subscriberQueuePath ); Keyspace ko = cass.getApplicationKeyspace( applicationId ); if ( firstSubscriptionQueuePath != null ) { limit += 1; } List<HColumn<String, UUID>> columns = createSliceQuery( ko, ue, se, ue ).setKey( subscriberQueueId ) .setColumnFamily( QUEUE_SUBSCRIPTIONS.getColumnFamily() ) .setRange( normalizeQueuePath( firstSubscriptionQueuePath ), null, false, limit + 1 ).execute().get() .getColumns(); QueueSet queues = new QueueSet(); int count = Math.min( limit, columns.size() ); if ( columns != null ) { for ( int i = firstSubscriptionQueuePath != null ? 1 : 0; i < count; i++ ) { HColumn<String, UUID> column = columns.get( i ); queues.addQueue( column.getName(), column.getValue() ); } } if ( columns.size() > limit ) { queues.setMore( true ); } return queues; }
UUID messageId = col.getValue();
@Override public ByteBuffer getColumnValue(N columnName) { HColumn<N,ByteBuffer> col = getColumn( columnName ); return col != null ? col.getValue() : null; }
private <T> void setPropertyUsingColumn(T obj, HColumn<String, byte[]> col, PropertyMappingDefinition md) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException { PropertyDescriptor pd = md.getPropDesc(); if (null == pd.getWriteMethod()) { throw new RuntimeException("property, " + pd.getName() + ", on class, " + obj.getClass().getName() + ", does not have a setter and therefore cannot be set"); } Object value = md.getConverter().convertCassTypeToObjType(md, col.getValue()); pd.getWriteMethod().invoke(obj, value); }
private Map<String, String> getResults(QueryResult<ColumnSlice<String, String>> queryResult) { Map<String, String> result = Maps.newHashMap(); for (HColumn<String, String> col : queryResult.get().getColumns()) { result.put(col.getName(), col.getValue()); } return result; }
@Test public void testIterator() { SliceQuery<String, UUID, String> query = HFactory.createSliceQuery(keyspace, se, us, se).setKey(KEY).setColumnFamily(CF); ColumnSliceIterator<String, UUID, String> it = new ColumnSliceIterator<String, UUID, String>(query, null, FINISH, false, 100); Map<UUID, String> results = new HashMap<UUID, String>(); while (it.hasNext()) { HColumn<UUID, String> c = it.next(); results.put(c.getName(), c.getValue()); } assertEquals(1000, results.size()); }
@Test public void testCreateColumn() { long clock = HFactory.createClock(); HColumn<String, Long> col = HFactory.createColumn("nameString", new Long("345"), clock); HColumn<String, Long> col2 = HFactory.createColumn("nameString", new Long("345"), clock, StringSerializer.get(), LongSerializer.get()); assertEquals(col.getName(), col2.getName()); assertEquals(col.getValue(), col2.getValue()); assertEquals(col.getClock(), col2.getClock()); } }
@Test public void testQuerySingleSubColumn() { SuperCfTemplate<String, String, String> sTemplate = new ThriftSuperCfTemplate<String, String, String>(keyspace, "Super1", se, se, se); SuperCfUpdater<String,String,String> sUpdater = sTemplate.createUpdater("skey3","super1"); sUpdater.setString("sub1_col_1", "sub1_val_1"); sTemplate.update(sUpdater); HColumn<String,String> myCol = sTemplate.querySingleSubColumn("skey3", "super1", "sub1_col_1", se); assertEquals("sub1_val_1", myCol.getValue()); }
private void assertColumnExists(String keyspace, String cf, String key, String column) { ColumnPath cp = new ColumnPath(cf); cp.setColumn(StringUtils.bytes(column)); Keyspace ks = HFactory.createKeyspace(keyspace, cluster); ColumnQuery<String, String, String> columnQuery = HFactory.createStringColumnQuery(ks); assertNotNull(String.format("Should have value for %s.%s[%s][%s]", keyspace, cf, key, column), columnQuery.setColumnFamily(cf).setKey(key).setName(column).execute().get().getValue()); //client.getKeyspace(keyspace).getColumn(key, cp)); //cluster.releaseClient(client); }