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

The following examples show how to use me.prettyprint.hector.api.beans.ColumnSlice. 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: 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 #2
Source File: AbstractSearch.java    From usergrid with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
protected Namespace getNamespace( String repositoryId, String namespaceId )
{

    QueryResult<OrderedRows<String, String, String>> result = HFactory //
        .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
        .setColumnFamily( cassandraArchivaManager.getNamespaceFamilyName() ) //
        .setColumnNames( REPOSITORY_NAME.toString(), NAME.toString() ) //
        .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) //
        .addEqualsExpression( NAME.toString(), namespaceId ) //
        .execute();
    if ( result.get().getCount() > 0 )
    {
        ColumnSlice<String, String> columnSlice = result.get().getList().get( 0 ).getColumnSlice();
        return new Namespace( getStringValue( columnSlice, NAME.toString() ), //
                              new Repository( getStringValue( columnSlice, REPOSITORY_NAME.toString() ) ) );

    }
    return null;
}
 
Example #4
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
protected ArtifactMetadata mapArtifactMetadataStringColumnSlice( String key, ColumnSlice<String, String> columnSlice )
{
    ArtifactMetadata artifactMetadata = new ArtifactMetadata();
    artifactMetadata.setNamespace( getStringValue( columnSlice, NAMESPACE_ID.toString() ) );
    artifactMetadata.setSize( getAsLongValue( columnSlice, SIZE.toString() ) );
    artifactMetadata.setId( getStringValue( columnSlice, ID.toString() ) );
    artifactMetadata.setFileLastModified( getAsLongValue( columnSlice, FILE_LAST_MODIFIED.toString() ) );
    artifactMetadata.setMd5( getStringValue( columnSlice, MD5.toString() ) );
    artifactMetadata.setProject( getStringValue( columnSlice, PROJECT.toString() ) );
    artifactMetadata.setProjectVersion( getStringValue( columnSlice, PROJECT_VERSION.toString() ) );
    artifactMetadata.setRepositoryId( getStringValue( columnSlice, REPOSITORY_NAME.toString() ) );
    artifactMetadata.setSha1( getStringValue( columnSlice, SHA1.toString() ) );
    artifactMetadata.setVersion( getStringValue( columnSlice, VERSION.toString() ) );
    Long whenGathered = getAsLongValue( columnSlice, WHEN_GATHERED.toString() );
    if ( whenGathered != null )
    {
        artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), STORAGE_TZ));
    }
    artifactMetadata.setChecksums(mapChecksumsReverse(getChecksums(key)));
    return artifactMetadata;
}
 
Example #5
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 6 votes vote down vote up
protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( String key, ColumnSlice<String, Long> columnSlice )
{
    ArtifactMetadata artifactMetadata = new ArtifactMetadata();
    artifactMetadata.setNamespace( getAsStringValue( columnSlice, NAMESPACE_ID.toString() ) );
    artifactMetadata.setSize( getLongValue( columnSlice, SIZE.toString() ) );
    artifactMetadata.setId( getAsStringValue( columnSlice, ID.toString() ) );
    artifactMetadata.setFileLastModified( getLongValue( columnSlice, FILE_LAST_MODIFIED.toString() ) );
    artifactMetadata.setMd5( getAsStringValue( columnSlice, MD5.toString() ) );
    artifactMetadata.setProject( getAsStringValue( columnSlice, PROJECT.toString() ) );
    artifactMetadata.setProjectVersion( getAsStringValue( columnSlice, PROJECT_VERSION.toString() ) );
    artifactMetadata.setRepositoryId( getAsStringValue( columnSlice, REPOSITORY_NAME.toString() ) );
    artifactMetadata.setSha1( getAsStringValue( columnSlice, SHA1.toString() ) );
    artifactMetadata.setVersion( getAsStringValue( columnSlice, VERSION.toString() ) );
    Long whenGathered = getLongValue( columnSlice, WHEN_GATHERED.toString() );
    if ( whenGathered != null )
    {
        artifactMetadata.setWhenGathered(ZonedDateTime.ofInstant(Instant.ofEpochMilli(whenGathered), STORAGE_TZ));
    }
    artifactMetadata.setChecksums(mapChecksumsReverse(getChecksums(key)));
    return artifactMetadata;
}
 
Example #6
Source File: Schema.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public static Map<String, Object> deserializeEntityProperties( Row<UUID, String, ByteBuffer> row ) {
    if ( row == null ) {
        return null;
    }
    ColumnSlice<String, ByteBuffer> slice = row.getColumnSlice();
    if ( slice == null ) {
        return null;
    }
    return deserializeEntityProperties( slice.getColumns(), true, false );
}
 
Example #7
Source File: CassandraService.java    From usergrid with Apache License 2.0 5 votes vote down vote up
public <N, V> ColumnSlice<N, V> getColumns( Keyspace ko, Object columnFamily, Object key, N[] columns,
                                            Serializer<N> nameSerializer, Serializer<V> valueSerializer )
        throws Exception {

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

/*
 * ByteBuffer column_bytes = null; if (column instanceof List) {
 * column_bytes = Composite.serializeToByteBuffer((List<?>) column); } else
 * { column_bytes = bytebuffer(column); }
 */

    SliceQuery<ByteBuffer, N, V> q = HFactory.createSliceQuery( ko, be, nameSerializer, valueSerializer );
    QueryResult<ColumnSlice<N, V>> r =
            q.setKey( bytebuffer( key ) ).setColumnNames( columns ).setColumnFamily( columnFamily.toString() )
             .execute();
    ColumnSlice<N, V> result = r.get();

    if ( db_logger.isTraceEnabled() ) {
        if ( result == null ) {
            db_logger.trace( "getColumn returned null" );
        }
    }

    return result;
}
 
Example #8
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
 * @param columnNames the column names
 *
 * @return columns
 *
 * @throws Exception the exception
 */
@SuppressWarnings("unchecked")
public <N, V> List<HColumn<N, V>> getColumns( Keyspace ko, Object columnFamily, Object key, Set<String> columnNames,
                                              Serializer<N> nameSerializer, Serializer<V> valueSerializer )
        throws Exception {

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

    SliceQuery<ByteBuffer, N, V> q = createSliceQuery( ko, be, nameSerializer, valueSerializer );
    q.setColumnFamily( columnFamily.toString() );
    q.setKey( bytebuffer( key ) );
    // q.setColumnNames(columnNames.toArray(new String[0]));
    q.setColumnNames( ( N[] ) nameSerializer.fromBytesSet( se.toBytesSet( new ArrayList<String>( columnNames ) ) )
                                            .toArray() );

    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 #9
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 #10
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 #11
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 #12
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 #13
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public List<ArtifactMetadata> getArtifactsByDateRange( RepositorySession session, final String repositoryId, final ZonedDateTime startTime,
                                                       final ZonedDateTime endTime, QueryParameter queryParameter )
    throws MetadataRepositoryException
{

    LongSerializer ls = LongSerializer.get();
    RangeSlicesQuery<String, String, Long> query = HFactory //
        .createRangeSlicesQuery( keyspace, ss, ss, ls ) //
        .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
        .setColumnNames( ArtifactMetadataModel.COLUMNS ); //


    if ( startTime != null )
    {
        query = query.addGteExpression( WHEN_GATHERED.toString(), startTime.toInstant().toEpochMilli() );
    }
    if ( endTime != null )
    {
        query = query.addLteExpression( WHEN_GATHERED.toString(), endTime.toInstant().toEpochMilli() );
    }
    QueryResult<OrderedRows<String, String, Long>> result = query.execute();

    List<ArtifactMetadata> artifactMetadatas = new ArrayList<>( result.get().getCount() );
    Iterator<Row<String, String, Long>> keyIter = result.get().iterator();
    if (keyIter.hasNext()) {
        String key = keyIter.next().getKey();
        for (Row<String, String, Long> row : result.get()) {
            ColumnSlice<String, Long> columnSlice = row.getColumnSlice();
            String repositoryName = getAsStringValue(columnSlice, REPOSITORY_NAME.toString());
            if (StringUtils.equals(repositoryName, repositoryId)) {

                artifactMetadatas.add(mapArtifactMetadataLongColumnSlice(key, columnSlice));
            }
        }
    }

    return artifactMetadatas;
}
 
Example #14
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
@Override
public <T extends MetadataFacet> T getMetadataFacet( RepositorySession session, final String repositoryId, final Class<T> facetClazz, final String name )
    throws MetadataRepositoryException
{
    final MetadataFacetFactory<T> metadataFacetFactory = getFacetFactory( facetClazz );
    if (metadataFacetFactory==null) {
        return null;
    }
    final String facetId = metadataFacetFactory.getFacetId( );

    QueryResult<OrderedRows<String, String, String>> result = HFactory //
        .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
        .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) //
        .setColumnNames( KEY.toString(), VALUE.toString() ) //
        .addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId ) //
        .addEqualsExpression( FACET_ID.toString(), facetId ) //
        .addEqualsExpression( NAME.toString(), name ) //
        .execute();

    T metadataFacet = metadataFacetFactory.createMetadataFacet( repositoryId, name );
    int size = result.get().getCount();
    if ( size < 1 )
    {
        return null;
    }
    Map<String, String> map = new HashMap<>( size );
    for ( Row<String, String, String> row : result.get() )
    {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        map.put( getStringValue( columnSlice, KEY.toString() ), getStringValue( columnSlice, VALUE.toString() ) );
    }
    metadataFacet.fromProperties( map );
    return metadataFacet;
}
 
Example #15
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 5 votes vote down vote up
protected ProjectVersionMetadataModel mapProjectVersionMetadataModel( ColumnSlice<String, String> columnSlice )
{
    ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
    projectVersionMetadataModel.setId( getStringValue( columnSlice, ID.toString() ) );
    projectVersionMetadataModel.setDescription( getStringValue( columnSlice, DESCRIPTION.toString() ) );
    projectVersionMetadataModel.setName( getStringValue( columnSlice, NAME.toString() ) );
    Namespace namespace = new Namespace( getStringValue( columnSlice, NAMESPACE_ID.toString() ), //
                                         new Repository( getStringValue( columnSlice, REPOSITORY_NAME.toString() ) ) );
    projectVersionMetadataModel.setNamespace( namespace );
    projectVersionMetadataModel.setIncomplete(
        Boolean.parseBoolean( getStringValue( columnSlice, "incomplete" ) ) );
    projectVersionMetadataModel.setProjectId( getStringValue( columnSlice, PROJECT_ID.toString() ) );
    projectVersionMetadataModel.setUrl( getStringValue( columnSlice, URL.toString() ) );
    return projectVersionMetadataModel;
}
 
Example #16
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 #17
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 #18
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 #19
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 #20
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 4 votes vote down vote up
/**
 * Implementation is not very performant, because sorting is part of the stream. I do not know how to specify the sort
 * in the query.
 * 
 * @param <T>
 * @param session
 * @param repositoryId
 * @param facetClazz
 * @param queryParameter
 * @return
 * @throws MetadataRepositoryException
 */
@Override
public <T extends MetadataFacet> Stream<T> getMetadataFacetStream(RepositorySession session, String repositoryId, Class<T> facetClazz, QueryParameter queryParameter) throws MetadataRepositoryException
{
    final MetadataFacetFactory<T> metadataFacetFactory = getFacetFactory( facetClazz );
    final String facetId = metadataFacetFactory.getFacetId( );

    QueryResult<OrderedRows<String, String, String>> result = HFactory //
        .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
        .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName( ) ) //
        .setColumnNames( NAME.toString( ), KEY.toString( ), VALUE.toString( ) ) //
        .addEqualsExpression( REPOSITORY_NAME.toString( ), repositoryId ) //
        .addEqualsExpression( FACET_ID.toString( ), facetId ) //
        .setRange( null, null, false, Integer.MAX_VALUE )
        .setRowCount( Integer.MAX_VALUE )
        .execute( );



    return StreamSupport.stream( createResultSpliterator( result, ( Row<String, String, String> row, T lastItem)-> {
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        String name = getStringValue( columnSlice, NAME.toString( ) );
        T updateItem;
        if (lastItem!=null && lastItem.getName().equals(name))
        {
            updateItem = lastItem;
        } else
        {
            updateItem = metadataFacetFactory.createMetadataFacet( repositoryId, name );
        }
        String key = getStringValue( columnSlice, KEY.toString() );
        if (StringUtils.isNotEmpty( key ))
        {
            Map<String, String> map = new HashMap<>( );
            map.put( key , getStringValue( columnSlice, VALUE.toString( ) ) );
            updateItem.fromProperties( map );
        }
        return updateItem;

    }), false ).sorted( (f1, f2) -> f1.getName()!=null ? f1.getName().compareTo( f2.getName() ) : 1 ).skip( queryParameter.getOffset()).limit( queryParameter.getLimit());
}
 
Example #21
Source File: CassandraService.java    From usergrid with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the columns.
 *
 * @param ko the keyspace
 * @param columnFamily the column family
 * @param key the key
 * @param start the start
 * @param finish the finish
 * @param count the count
 * @param reversed the reversed
 *
 * @return columns
 *
 * @throws Exception the exception
 */
public List<HColumn<ByteBuffer, ByteBuffer>> getColumns( Keyspace ko, Object columnFamily, Object key, Object start,
                                                         Object finish, int count, boolean reversed )
        throws Exception {

    if ( db_logger.isTraceEnabled() ) {
        db_logger.debug( "getColumns cf=" + columnFamily + " key=" + key + " start=" + start + " finish=" + finish
                + " count=" + count + " reversed=" + reversed );
    }

    SliceQuery<ByteBuffer, ByteBuffer, ByteBuffer> q = createSliceQuery( ko, be, be, be );
    q.setColumnFamily( columnFamily.toString() );
    q.setKey( bytebuffer( key ) );

    ByteBuffer start_bytes = null;
    if ( start instanceof DynamicComposite ) {
        start_bytes = ( ( DynamicComposite ) start ).serialize();
    }
    else if ( start instanceof List ) {
        start_bytes = DynamicComposite.toByteBuffer( ( List<?> ) start );
    }
    else {
        start_bytes = bytebuffer( start );
    }

    ByteBuffer finish_bytes = null;
    if ( finish instanceof DynamicComposite ) {
        finish_bytes = ( ( DynamicComposite ) finish ).serialize();
    }
    else if ( finish instanceof List ) {
        finish_bytes = DynamicComposite.toByteBuffer( ( List<?> ) finish );
    }
    else {
        finish_bytes = bytebuffer( finish );
    }

/*
 * if (reversed) { q.setRange(finish_bytes, start_bytes, reversed, count); }
 * else { q.setRange(start_bytes, finish_bytes, reversed, count); }
 */
    q.setRange( start_bytes, finish_bytes, reversed, count );
    QueryResult<ColumnSlice<ByteBuffer, ByteBuffer>> r = q.execute();
    ColumnSlice<ByteBuffer, ByteBuffer> slice = r.get();
    List<HColumn<ByteBuffer, ByteBuffer>> 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 #22
Source File: CassandraUtils.java    From archiva with Apache License 2.0 4 votes vote down vote up
public static String getStringValue( ColumnSlice<String, String> columnSlice, ColumnNames columnName )
{
    return getStringValue( columnSlice, columnName.toString() );
}
 
Example #23
Source File: HectorPolicyManagerImpl.java    From ck with Apache License 2.0 4 votes vote down vote up
@Override
public List<PolicyDAO> getAllPolicies() {
    List<NamedColumn<UUID, String, String>> list = CollectionUtils.list(
            Schema.POLICIES.SHORT_NAME,
            Schema.POLICIES.DESCRIPTION);
    RangeSlicesQuery<UUID, String, String> query =
            Schema.POLICIES.createRangeSlicesQuery(_keyspace,
                    list);

    // TODO: may need paging of data once we have more than a few hundred.
    //       This may need some sort of indexing since we're using RandomPartitioner,
    //       in order to return them in a useful order.
    query.setRowCount(1000);
    // TODO: needed?
    // query.setKeys("fake_key_0", "fake_key_4");

    QueryResult<OrderedRows<UUID, String, String>> result = query.execute();

    OrderedRows<UUID, String, String> orderedRows = result.get();
    if (orderedRows == null) {
        return Collections.emptyList();
    }

    return Functional.filter(orderedRows.getList(),
            new Filter<Row<UUID, String, String>, PolicyDAO>() {
                @Override
                public PolicyDAO filter(Row<UUID, String, String> row) throws SkippedElementException {
                    ColumnSlice<String, String> cs = row.getColumnSlice();
                    if (cs == null) {
                        throw new SkippedElementException();
                    }

                    String shortName;
                    try {
                        shortName = getNonNullStringColumn(cs, Schema.POLICIES.SHORT_NAME.getName());
                    } catch (NoSuchColumnException e) {
                        // Tombstone row
                        throw new SkippedElementException();
                    }

                    String description = getStringColumnOrNull(cs, Schema.POLICIES.DESCRIPTION.getName());

                    // FIXME: can't get date from string result.
                    //        To fix this, we need variable-value-typed range slices queries.
                    return new PolicyDAOImpl(new HectorPolicyIDImpl(row.getKey()), shortName, description,
                            new Date());
                }
            });
}
 
Example #24
Source File: CassandraMetadataRepository.java    From archiva with Apache License 2.0 3 votes vote down vote up
@Override
public List<ArtifactMetadata> getArtifacts( RepositorySession session, final String repositoryId )
    throws MetadataRepositoryException
{

    RangeSlicesQuery<String, String, String> query = HFactory //
        .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
        .setColumnFamily( cassandraArchivaManager.getArtifactMetadataFamilyName() ) //
        .setColumnNames( ArtifactMetadataModel.COLUMNS ); //

    query = query.addEqualsExpression( REPOSITORY_NAME.toString(), repositoryId );

    QueryResult<OrderedRows<String, String, String>> result = query.execute();



    List<ArtifactMetadata> artifactMetadatas = new ArrayList<>( result.get().getCount() );

    for ( Row<String, String, String> row : result.get() )
    {
        String key = row.getKey();
        ColumnSlice<String, String> columnSlice = row.getColumnSlice();
        artifactMetadatas.add( mapArtifactMetadataStringColumnSlice( key, columnSlice ) );

    }

    return artifactMetadatas;
}