me.prettyprint.hector.api.beans.HColumn Java Examples

The following examples show how to use me.prettyprint.hector.api.beans.HColumn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public static void addInsertToMutator( Mutator<ByteBuffer> m, Object columnFamily, Object key, Object columnName,
                                       Object columnValue, long timestamp ) {

    logBatchOperation( "Insert", columnFamily, key, columnName, columnValue, timestamp );

    if ( columnName instanceof List<?> ) {
        columnName = DynamicComposite.toByteBuffer( ( List<?> ) columnName );
    }
    if ( columnValue instanceof List<?> ) {
        columnValue = DynamicComposite.toByteBuffer( ( List<?> ) columnValue );
    }

    HColumn<ByteBuffer, ByteBuffer> column =
            createColumn( bytebuffer( columnName ), bytebuffer( columnValue ), timestamp, be, be );
    m.addInsertion( bytebuffer( key ), columnFamily.toString(), column );
}
 
Example #2
Source File: AbstractSearch.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * This method intentionally swallows ordered execution issues.  For some reason, our Time UUID ordering does
 * not agree with the cassandra comparator as our micros get very close
 * @param query
 * @param <K>
 * @param <UUID>
 * @param <V>
 * @return
 */
protected static <K, UUID, V> List<HColumn<UUID, V>> swallowOrderedExecution( final SliceQuery<K, UUID, V> query ) {
    try {

        return query.execute().get().getColumns();
    }
    catch ( HInvalidRequestException e ) {
        //invalid request.  Occasionally we get order issues when there shouldn't be, disregard them.

        final Throwable invalidRequestException = e.getCause();

        if ( invalidRequestException instanceof InvalidRequestException
                //we had a range error
                && ( ( InvalidRequestException ) invalidRequestException ).getWhy().contains(
                "range finish must come after start in the order of traversal" )) {
            return Collections.emptyList();
        }

        throw e;
    }
}
 
Example #3
Source File: OpsCiStateDao.java    From oneops with Apache License 2.0 6 votes vote down vote up
public List<CiChangeStateEvent> getCiStateHistory(long ciId, Long startTime, Long endTime, Integer count) {

        if (count == null) count = 1000;
        List<CiChangeStateEvent> states = new ArrayList<CiChangeStateEvent>();
        SliceQuery<Long, Long, String> sliceQuery = HFactory.createSliceQuery(keyspace, longSerializer, longSerializer, stringSerializer);
        sliceQuery.setColumnFamily(SchemaBuilder.CI_STATE_HIST_CF);
        sliceQuery.setRange(startTime, endTime, false, count);
        sliceQuery.setKey(ciId);
        QueryResult<ColumnSlice<Long, String>> result = sliceQuery.execute();
        ColumnSlice<Long, String> resultCols = result.get();
        for (HColumn<Long, String> col : resultCols.getColumns()) {
            CiChangeStateEvent event = gson.fromJson(col.getValue(), CiChangeStateEvent.class);
            states.add(event);
        }
        return states;
    }
 
Example #4
Source File: CassandraPersistentActorRepository.java    From elasticactors with Apache License 2.0 6 votes vote down vote up
private HColumn<String,byte[]> querySingleColumnWithRetry(final ShardKey shard,final String actorId) {
    // try three times, and log a warning when we exceed the readExecutionThreshold
    final long startTime = currentTimeMillis();
    int attemptsRemaining = 3;
    try {
        while (true) {
            attemptsRemaining--;
            try {
                return columnFamilyTemplate.querySingleColumn(createKey(shard), actorId, BytesArraySerializer.get());
            } catch (HTimedOutException | HPoolRecoverableException e) {
                if (attemptsRemaining <= 0) {
                    throw e;
                }
            }
        }
    } finally {
        final long endTime = currentTimeMillis();
        if((endTime - startTime) > readExecutionThresholdMillis) {
            logger.warn("Cassandra read operation took {} msecs ({} retries) for actorId [{}] on shard [{}]", (endTime - startTime), (2 - attemptsRemaining), actorId, shard);
        }
    }
}
 
Example #5
Source File: CassandraMQUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public static Mutator<ByteBuffer> addMessageToMutator( Mutator<ByteBuffer> m, Message message, long timestamp ) {

        Map<ByteBuffer, ByteBuffer> columns = serializeMessage( message );

        if ( columns == null ) {
            return m;
        }

        for ( Map.Entry<ByteBuffer, ByteBuffer> column_entry : columns.entrySet() ) {
            if ( ( column_entry.getValue() != null ) && column_entry.getValue().hasRemaining() ) {
                HColumn<ByteBuffer, ByteBuffer> column =
                        createColumn( column_entry.getKey(), column_entry.getValue(), timestamp, be, be );
                m.addInsertion( bytebuffer( message.getUuid() ), QueuesCF.MESSAGE_PROPERTIES.toString(), column );
            }
            else {
                m.addDeletion( bytebuffer( message.getUuid() ), QueuesCF.MESSAGE_PROPERTIES.toString(),
                        column_entry.getKey(), be, timestamp );
            }
        }

        return m;
    }
 
Example #6
Source File: CassandraMQUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: CassandraMQUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: CassandraMQUtils.java    From usergrid with Apache License 2.0 6 votes vote down vote up
public static Mutator<ByteBuffer> addQueueToMutator( Mutator<ByteBuffer> m, Queue queue, long timestamp ) {

        Map<ByteBuffer, ByteBuffer> columns = serializeQueue( queue );

        if ( columns == null ) {
            return m;
        }

        for ( Map.Entry<ByteBuffer, ByteBuffer> column_entry : columns.entrySet() ) {
            if ( ( column_entry.getValue() != null ) && column_entry.getValue().hasRemaining() ) {
                HColumn<ByteBuffer, ByteBuffer> column =
                        createColumn( column_entry.getKey(), column_entry.getValue(), timestamp, be, be );
                m.addInsertion( bytebuffer( queue.getUuid() ), QueuesCF.QUEUE_PROPERTIES.toString(), column );
            }
            else {
                m.addDeletion( bytebuffer( queue.getUuid() ), QueuesCF.QUEUE_PROPERTIES.toString(),
                        column_entry.getKey(), be, timestamp );
            }
        }

        return m;
    }
 
Example #9
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the external role list of a user.
 */
@Override
public String[] doGetExternalRoleListOfUser(String userName, String filter) throws UserStoreException {

    List<String> roles = new ArrayList<String>();
    int arrayLength = 0;
    Composite key = new Composite();
    key.addComponent(userName, stringSerializer);
    key.addComponent(tenantIdString, stringSerializer);
    SliceQuery<Composite, String, String> query = HFactory
            .createSliceQuery(keyspace, CompositeSerializer.get(), StringSerializer.get(), StringSerializer.get())
            .setKey(key).setColumnFamily(CFConstants.UM_USER_ROLE);

    ColumnSliceIterator<Composite, String, String> iterator = new ColumnSliceIterator<Composite, String, String>(
            query, null, "\uFFFF", false);

    while (iterator.hasNext()) {
        HColumn<String, String> column = iterator.next();
        roles.add(column.getValue());
    }
    return roles.toArray(new String[arrayLength]);
}
 
Example #10
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the role is existing the role store.
 */
@Override
protected boolean doCheckExistingRole(String roleNameWithTenantDomain) throws UserStoreException {

    RoleContext roleContext = createRoleContext(roleNameWithTenantDomain);
    boolean isExisting = false;

    String roleName = roleContext.getRoleName();

    Composite key = new Composite();
    key.addComponent(roleName, stringSerializer);
    key.addComponent(tenantIdString, stringSerializer);

    ColumnQuery<Composite, String, String> getCredentialQuery = HFactory.createColumnQuery(keyspace,
            CompositeSerializer.get(), stringSerializer, stringSerializer);

    getCredentialQuery.setColumnFamily(CFConstants.UM_ROLES).setKey(key).setName(CFConstants.UM_ROLE_NAME);

    HColumn<String, String> result = getCredentialQuery.execute().get();
    if (result != null && result.getValue() != null) {
        isExisting = true;
    }

    return isExisting;
}
 
Example #11
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Checks if the user is existing in the user store.
 */
@Override
protected boolean doCheckExistingUser(String userName) throws UserStoreException {

    Boolean isExist = false;

    Composite key = new Composite();
    key.addComponent(userName, stringSerializer);
    key.addComponent(tenantIdString, stringSerializer);

    ColumnQuery<Composite, String, String> getCredentialQuery = HFactory.createColumnQuery(keyspace,
            CompositeSerializer.get(), stringSerializer, stringSerializer);

    getCredentialQuery.setColumnFamily(CFConstants.UM_USER).setKey(key).setName(CFConstants.UM_USER_NAME);

    HColumn<String, String> result = getCredentialQuery.execute().get();
    if (result != null && result.getValue() != null) {
        isExist = true;
    }

    return isExist;

}
 
Example #12
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Get the list of users mapped to a role.
 */
@Override
public String[] doGetUserListOfRole(String roleName, String filter) throws UserStoreException {

    List<String> usersList = new ArrayList<String>();
    Composite key = new Composite();
    key.addComponent(roleName, stringSerializer);
    key.addComponent(tenantIdString, stringSerializer);
    SliceQuery<Composite, String, String> query = HFactory
            .createSliceQuery(keyspace, CompositeSerializer.get(), StringSerializer.get(), StringSerializer.get())
            .setKey(key).setColumnFamily(CFConstants.UM_ROLE_USER_INDEX);

    ColumnSliceIterator<Composite, String, String> iterator = new ColumnSliceIterator<Composite, String, String>(
            query, null, "\uFFFF", false);

    while (iterator.hasNext()) {
        HColumn<String, String> column = iterator.next();
        usersList.add(column.getValue());
    }
    return usersList.toArray(new String[usersList.size()]);
}
 
Example #13
Source File: CassandraPersistentActorRepository.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
public PersistentActor<ShardKey> get(final ShardKey shard,final String actorId) throws IOException {
    HColumn<String,byte[]> column = querySingleColumnWithRetry(shard, actorId);
    if(column != null) {
        return deserializer.deserialize(column.getValue());
    } else {
        return null;
    }
}
 
Example #14
Source File: CassandraUtils.java    From archiva with Apache License 2.0 5 votes vote down vote up
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() );
}
 
Example #15
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public Message getMessage( UUID messageId ) {
    SliceQuery<UUID, String, ByteBuffer> q =
            createSliceQuery( cass.getApplicationKeyspace( applicationId ), ue, se, be );
    q.setColumnFamily( MESSAGE_PROPERTIES.getColumnFamily() );
    q.setKey( messageId );
    q.setRange( null, null, false, ALL_COUNT );
    QueryResult<ColumnSlice<String, ByteBuffer>> r = q.execute();
    ColumnSlice<String, ByteBuffer> slice = r.get();
    List<HColumn<String, ByteBuffer>> results = slice.getColumns();
    return deserializeMessage( results );
}
 
Example #16
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #17
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #18
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getQueueCounterNames( String queuePath ) throws Exception {
    Set<String> names = new HashSet<String>();
    Keyspace ko = cass.getApplicationKeyspace( applicationId );
    SliceQuery<String, String, ByteBuffer> q = createSliceQuery( ko, se, se, be );
    q.setColumnFamily( QueuesCF.QUEUE_DICTIONARIES.toString() );
    q.setKey( CassandraPersistenceUtils.key( getQueueId( queuePath ), DICTIONARY_COUNTERS ).toString() );
    q.setRange( null, null, false, ALL_COUNT );

    List<HColumn<String, ByteBuffer>> columns = q.execute().get().getColumns();
    for ( HColumn<String, ByteBuffer> column : columns ) {
        names.add( column.getName() );
    }
    return names;
}
 
Example #19
Source File: QueueManagerImpl.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public Queue getQueue( String queuePath, UUID queueId ) {
    SliceQuery<UUID, String, ByteBuffer> q =
            createSliceQuery( cass.getApplicationKeyspace( applicationId ), ue, se, be );
    q.setColumnFamily( QUEUE_PROPERTIES.getColumnFamily() );
    q.setKey( queueId );
    q.setRange( null, null, false, ALL_COUNT );
    QueryResult<ColumnSlice<String, ByteBuffer>> r = q.execute();
    ColumnSlice<String, ByteBuffer> slice = r.get();
    List<HColumn<String, ByteBuffer>> results = slice.getColumns();
    return deserializeQueue( results );
}
 
Example #20
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #21
Source File: CassandraPersistenceUtils.java    From usergrid with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #22
Source File: ConsumerTransaction.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Get all pending transactions that have timed out
 *
 * @param queueId The queue id
 * @param consumerId The consumer id
 * @param params The server params
 * @param startTimeUUID The start time
 */
protected List<TransactionPointer> getConsumerIds( UUID queueId, UUID consumerId, SearchParam params,
                                                   UUID startTimeUUID )
{

    SliceQuery<ByteBuffer, UUID, UUID> q = createSliceQuery( ko, be, ue, ue );
    q.setColumnFamily( CONSUMER_QUEUE_TIMEOUTS.getColumnFamily() );
    q.setKey( getQueueClientTransactionKey( queueId, consumerId ) );
    q.setRange( params.startId, startTimeUUID, false, params.limit + 1 );

    List<HColumn<UUID, UUID>> cassResults = swallowOrderedExecution(q);

    List<TransactionPointer> results = new ArrayList<TransactionPointer>( params.limit );

    for ( HColumn<UUID, UUID> column : cassResults )
    {

        if ( logger.isTraceEnabled() )
        {
            logger.trace( "Adding uuid '{}' for original message '{}' to results for queue '{}' and consumer '{}'",
                    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() ) );
    }

    return results;
}
 
Example #23
Source File: AbstractSearch.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: CassandraUtils.java    From archiva with Apache License 2.0 5 votes vote down vote up
public static Long getAsLongValue( ColumnSlice<String, String> columnSlice, String columnName )
{
    LongSerializer ls = LongSerializer.get();
    if ( StringUtils.isEmpty( columnName ) )
    {
        return null;
    }

    HColumn<String, String> hColumn = columnSlice.getColumnByName( columnName );
    return hColumn == null ? null : ls.fromByteBuffer( hColumn.getValueBytes() );
}
 
Example #25
Source File: CassandraDB.java    From cassandra-river with Apache License 2.0 5 votes vote down vote up
public CassandraCFData getCFData(String columnFamily, String start, int limit) {
	int columnLimit = 100;
	CassandraCFData data = new CassandraCFData();
	String lastEnd = null;
	
	Map<String, Map<String, String>> cfData = new HashMap<String, Map<String, String>>();
	RangeSlicesQuery<String, String, String> query = HFactory.createRangeSlicesQuery(keyspace, STR, STR, STR);
	query.setColumnFamily(columnFamily);
	query.setKeys(start, "");
	query.setRange("", "", false, columnLimit);
	query.setRowCount(limit);
	OrderedRows<String, String, String> rows = query.execute().get();
	if (rows.getCount() != 1) {
		lastEnd = rows.peekLast().getKey();
		data.start = lastEnd;
	} else {
		data.start = null;
		return data;
	}
	
	for(Row<String,String,String> row  : rows.getList()){
		Map<String, String> columnMap = new HashMap<String, String>();
		ColumnSlice<String, String> columnData = row.getColumnSlice();
		for (HColumn<String, String> column : columnData.getColumns()){
			columnMap.put(column.getName(), column.getValue());
		}
		
		cfData.put(row.getKey(), columnMap);
	}
	
	data.rowColumnMap = cfData;
	return data;
}
 
Example #26
Source File: CassandraUtils.java    From archiva with Apache License 2.0 5 votes vote down vote up
public static Long getLongValue( ColumnSlice<String, Long> columnSlice, String columnName )
{
    if ( StringUtils.isEmpty( columnName ) )
    {
        return null;
    }

    HColumn<String, Long> hColumn = columnSlice.getColumnByName( columnName );
    return hColumn == null ? null : hColumn.getValue();
}
 
Example #27
Source File: CassandraUtils.java    From archiva with Apache License 2.0 5 votes vote down vote up
public static String getStringValue( ColumnSlice<String, String> columnSlice, String columnName )
{
    if ( StringUtils.isEmpty( columnName ) )
    {
        return null;
    }

    HColumn<String, String> hColumn = columnSlice.getColumnByName( columnName );
    return hColumn == null ? null : hColumn.getValue();
}
 
Example #28
Source File: CassandraUtils.java    From archiva with Apache License 2.0 5 votes vote down vote up
public static <A, B> HColumn<A, B> column( final A name, final B value )
{

    return HFactory.createColumn( name, //
                                  value, //
        SerializerTypeInferer.getSerializer( name ), //
        SerializerTypeInferer.getSerializer( value ) );
}
 
Example #29
Source File: CassandraService.java    From usergrid with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the columns.
 *
 * @param ko the keyspace
 * @param columnFamily the column family
 * @param key the key
 *
 * @return columns
 *
 * @throws Exception the exception
 */
public <N, V> List<HColumn<N, V>> getAllColumns( Keyspace ko, Object columnFamily, Object key,
                                                 Serializer<N> nameSerializer, Serializer<V> valueSerializer )
        throws Exception {

    if ( db_logger.isTraceEnabled() ) {
        db_logger.trace( "getColumns cf={} key={}", columnFamily, key );
    }

    SliceQuery<ByteBuffer, N, V> q = createSliceQuery( ko, be, nameSerializer, valueSerializer );
    q.setColumnFamily( columnFamily.toString() );
    q.setKey( bytebuffer( key ) );
    q.setRange( null, null, false, ALL_COUNT );
    QueryResult<ColumnSlice<N, V>> r = q.execute();
    ColumnSlice<N, V> slice = r.get();
    List<HColumn<N, V>> results = slice.getColumns();

    if ( db_logger.isTraceEnabled() ) {
        if ( results == null ) {
            db_logger.trace( "getColumns returned null" );
        }
        else {
            db_logger.trace( "getColumns returned {} columns", results.size() );
        }
    }

    return results;
}
 
Example #30
Source File: Cassandra12xMapDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public V get(final K key) throws DataAccessLayerException {

	final ColumnQuery<K, byte[], V> q = createColumnQuery(_keyspace, _serializer_k, BYTE_SERIALIZER, _serializer_v);
	final QueryResult<HColumn<byte[], V>> r = q.setKey(key).setName(COLUMN_NAME).setColumnFamily(_cf_name).execute();
	final HColumn<byte[], V> c = r.get();

	if (c == null) {
		return (_default_value != null) ? _default_value : null;
	} else {
		return c.getValue();
	}
}