Java Code Examples for me.prettyprint.hector.api.query.RangeSlicesQuery#setRange()

The following examples show how to use me.prettyprint.hector.api.query.RangeSlicesQuery#setRange() . 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: 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 2
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Lists the users in the user store.
 */
@Override
protected String[] doListUsers(String filter, int maxItemLimit) throws UserStoreException {

    List<String> users = new ArrayList<String>();
    int arrayLength = 0;

    if (maxItemLimit == 0) {
        return new String[0];
    }

    int givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

    try {
        givenMax = Integer.parseInt(realmConfig
                .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_USER_LIST));
    } catch (Exception e) {
        givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

        if (log.isDebugEnabled()) {
            log.debug("Realm configuration maximum not set : Using User Core Constant value instead!", e);
        }
    }

    if (maxItemLimit < 0 || maxItemLimit > givenMax) {
        maxItemLimit = givenMax;
    }

    RangeSlicesQuery<String, String, String> rangeSliceQuery = HFactory.createRangeSlicesQuery(keyspace,
            stringSerializer, stringSerializer, stringSerializer);

    rangeSliceQuery.setColumnFamily(CFConstants.UM_USER);
    rangeSliceQuery.setRange(filter, null, false, Integer.MAX_VALUE);
    rangeSliceQuery.addEqualsExpression(CFConstants.UM_TENANT_ID, tenantIdString);

    // TODO - Need to check how to use the filter for range
    rangeSliceQuery.setKeys("", "");
    rangeSliceQuery.setRowCount(maxItemLimit);
    QueryResult<OrderedRows<String, String, String>> result = rangeSliceQuery.execute();
    if (result != null) {
        OrderedRows<String, String, String> rows = result.get();
        if (rows.getCount() <= 0) {
            // reformatted to avoid nesting too many blocks
            return users.toArray(new String[arrayLength]);

        }
        arrayLength = rows.getCount();

        Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

        while (rowsIterator.hasNext()) {
            Row<String, String, String> row = rowsIterator.next();
            if (row.getColumnSlice().getColumnByName(CFConstants.UM_USER_ID).getValue() != null) {
                String name = row.getColumnSlice().getColumnByName(CFConstants.UM_USER_NAME).getValue();
                // append the domain if exist
                name = UserCoreUtil.addDomainToName(name, domain);
                users.add(name);
            }
        }

    }
    return users.toArray(new String[arrayLength]);

}
 
Example 3
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 4 votes vote down vote up
/**
 * Get the role names in the roles store.
 */
@Override
public String[] doGetRoleNames(String filter, int maxItemLimit) throws UserStoreException {
    List<String> roles = new ArrayList<String>();

    if (maxItemLimit == 0) {
        return new String[0];
    }

    int givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

    try {
        givenMax = Integer.parseInt(realmConfig
                .getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_MAX_ROLE_LIST));
    } catch (Exception e) {
        givenMax = UserCoreConstants.MAX_USER_ROLE_LIST;

        if (log.isDebugEnabled()) {
            log.debug("Realm configuration maximum not set : Using User Core Constant value instead!", e);
        }
    }

    if (maxItemLimit < 0 || maxItemLimit > givenMax) {
        maxItemLimit = givenMax;
    }

    int arrayLength = 0;
    String domain = realmConfig.getUserStoreProperty(UserCoreConstants.RealmConfig.PROPERTY_DOMAIN_NAME);
    RangeSlicesQuery<String, String, String> rangeSliceQuery = HFactory.createRangeSlicesQuery(keyspace,
            stringSerializer, stringSerializer, stringSerializer);
    rangeSliceQuery.setColumnFamily(CFConstants.UM_ROLES);
    rangeSliceQuery.setRange(null, null, false, Integer.MAX_VALUE);
    rangeSliceQuery.addEqualsExpression(CFConstants.UM_TENANT_ID, tenantIdString);
    rangeSliceQuery.setKeys("", "");
    rangeSliceQuery.setRowCount(maxItemLimit);
    QueryResult<OrderedRows<String, String, String>> result = rangeSliceQuery.execute();
    if (result != null) {
        OrderedRows<String, String, String> rows = result.get();
        if (rows.getCount() <= 0) {
            return roles.toArray(new String[arrayLength]);
        }
        arrayLength = rows.getCount();

        Iterator<Row<String, String, String>> rowsIterator = rows.iterator();

        while (rowsIterator.hasNext()) {
            Row<String, String, String> row = rowsIterator.next();
            if (row.getColumnSlice().getColumnByName(CFConstants.UM_ROLE_NAME).getValue() != null) {
                String name = row.getColumnSlice().getColumnByName(CFConstants.UM_ROLE_NAME).getValue();
                // append the domain if exist
                name = UserCoreUtil.addDomainToName(name, domain);
                roles.add(name);
            }
        }

    }
    return roles.toArray(new String[arrayLength]);
}