Java Code Examples for me.prettyprint.hector.api.beans.Row#getColumnSlice()

The following examples show how to use me.prettyprint.hector.api.beans.Row#getColumnSlice() . 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: 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 2
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 3
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 4
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 5
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;
}