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

The following examples show how to use me.prettyprint.hector.api.beans.Composite. 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: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Maps the users to a role list. Adds the (username, tenantId) -> roleList
 * and (role, tenantId) -> userName
 *
 * @param userName The username of the user the roles need to be added to.
 * @param roleList The list of roles that needs to be mapped against the user.
 */
private void addUserToRoleList(String userName, String[] roleList) {

    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());

    if (roleList != null) {
        for (String role : roleList) {
            Composite key = new Composite();
            key.addComponent(userName, stringSerializer);
            key.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(role, role));

            Composite keyRole = new Composite();
            keyRole.addComponent(role, stringSerializer);
            keyRole.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName));

        }
        mutator.execute();
    }
}
 
Example #2
Source File: CassandraScheduledMessageRepository.java    From elasticactors with Apache License 2.0 6 votes vote down vote up
@Override
public List<ScheduledMessage> mapRow(final ColumnFamilyResult<Composite, Composite> results) {
    List<ScheduledMessage> resultList = new LinkedList<>();

    if(results.hasResults()) {
        Collection<Composite> scheduledMessages = results.getColumnNames();
        for (Composite columnName : scheduledMessages) {
            try {
                resultList.add(scheduledMessageDeserializer.deserialize(results.getByteArray(columnName)));
            } catch(IOException e)  {
                logger.error("Error while deserializing Scheduled Message", e);
            }
        }
    }
    return resultList;
}
 
Example #3
Source File: CassandraActorSystemEventListenerRepository.java    From elasticactors with Apache License 2.0 6 votes vote down vote up
@Override
public List<ActorSystemEventListener> mapRow(final ColumnFamilyResult<Composite, String> results) {
    List<ActorSystemEventListener> resultList = new ArrayList<>(1024);

    if(results.hasResults()) {
        Collection<String> actorIds = results.getColumnNames();
        for (String actorId : actorIds) {
            try {
                resultList.add(ActorSystemEventListenerDeserializer.get().deserialize(results.getByteArray(actorId)));
            } catch(IOException e)  {
                logger.error("IOException while deserializing ActorSystemEventListener",e);
            }
        }
    }
    return resultList;
}
 
Example #4
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 #5
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 #6
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Maps the role to a user list. Adds the (username, tenantId) -> roleList
 * and (role, tenantId) -> userName
 *
 * @param userNames The username list of the user the role need to be added to.
 * @param roleName  The role that needs to be mapped against the user list.
 * @param mutator   Passes the mutator and returns it with the insert statements.
 */
private Mutator<Composite> addRoleToUsersList(String[] userNames, String roleName, Mutator<Composite> mutator) {
    if (userNames != null) {
        for (String userName : userNames) {

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

            mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(roleName, roleName));

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

            mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName));

        }

    }
    return mutator;
}
 
Example #7
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Maps the users to a role list. Adds the (username, tenantId) -> roleList
 * and (role, tenantId) -> userName
 *
 * @param userName The username of the user the roles need to be added to.
 * @param roleList The list of roles that needs to be mapped against the user.
 * @param mutator  Passes the mutator and returns it with the insert statements.
 */
private Mutator<Composite> addUserToRoleList(String userName, String[] roleList, Mutator<Composite> mutator) {
    if (roleList != null && mutator != null) {
        for (String role : roleList) {
            Composite key = new Composite();
            key.addComponent(userName, stringSerializer);
            key.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(key, CFConstants.UM_USER_ROLE, HFactory.createColumn(role, role));

            Composite keyRole = new Composite();
            keyRole.addComponent(role, stringSerializer);
            keyRole.addComponent(tenantIdString, stringSerializer);

            mutator.addInsertion(keyRole, CFConstants.UM_ROLE_USER_INDEX, HFactory.createColumn(userName, userName));

        }
    }
    return mutator;
}
 
Example #8
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 6 votes vote down vote up
/**
 * Adds a role to the role store.
 */
@Override
public void doAddRole(String roleName, String[] userList, boolean shared) throws UserStoreException {

    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
    Composite composite = new Composite();
    composite.addComponent(roleName, stringSerializer);
    composite.addComponent(tenantIdString, stringSerializer);

    mutator.addInsertion(composite, CFConstants.UM_ROLES,
            HFactory.createColumn(CFConstants.UM_ROLE_NAME, roleName, stringSerializer, stringSerializer));
    mutator.addInsertion(composite, CFConstants.UM_ROLES,
            HFactory.createColumn(CFConstants.UM_TENANT_ID, tenantIdString, stringSerializer, stringSerializer));

    if (userList != null && userList.length > 0) {
        addRoleToUsersList(userList, roleName, mutator);
    }

    mutator.execute();
}
 
Example #9
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 #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: Cassandra12xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 6 votes vote down vote up
/**
 * Deletes in SPOC index.
 * 
 * @param rowKey the row key.
 * @param ids the triple identifiers
 * @throws DataAccessLayerException in case of data access failure.
 */
void deleteInSPOC(final byte[] rowKey, final byte[][]ids) throws DataAccessLayerException {
	final Composite poc_col = new Composite();

	// predicate
	poc_col.addComponent(ids[1], BYTE_SERIALIZER);
	// object
	poc_col.addComponent(ids[2], BYTE_SERIALIZER);

	if (ids.length == 4) {
		// context
		poc_col.addComponent(ids[3], BYTE_SERIALIZER);
	}

	_mutators.get().addDeletion(rowKey, S_POC, poc_col, COMPOSITE_SERIALIZER);	
}
 
Example #12
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
private Mutator<Composite> addClaimsForUser(String userName, Map<String, String> claims, Mutator<Composite> mutator) {

        Composite key = new Composite();
        key.addComponent(userName, stringSerializer);
        key.addComponent(tenantIdString, stringSerializer);
        // add claims
        for (Map.Entry<String, String> claimsVals : claims.entrySet()) {
            mutator.addInsertion(key, CFConstants.UM_USER_ATTRIBUTE,
                    HFactory.createColumn(claimsVals.getKey(), claimsVals.getValue()));
            mutator.addInsertion(key, CFConstants.UM_USER_ATTRIBUTE,
                    HFactory.createColumn(CFConstants.UM_TENANT_ID, tenantIdString));
        }
        return mutator;
    }
 
Example #13
Source File: Cassandra12xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes in OPSC index.
 * 
 * @param rowKey the row key.
 * @param ids the triple identifiers
 * @throws DataAccessLayerException in case of data access failure.
 */
void deleteInOSPC(final byte[] rowKey, final byte[][]ids) throws DataAccessLayerException {
	final Composite spc_col = new Composite();

	spc_col.addComponent(ids[0], BYTE_SERIALIZER);
	spc_col.addComponent(ids[1], BYTE_SERIALIZER);

	if (ids.length == 4) {
		spc_col.addComponent(ids[3], BYTE_SERIALIZER);
	}

	_mutators.get().addDeletion(rowKey, O_SPC, spc_col, COMPOSITE_SERIALIZER);		
}
 
Example #14
Source File: CassandraScheduledMessageRepository.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
private Composite createColumnName(ScheduledMessageKey scheduledMessageKey) {
    final Composite columnName = new Composite();
    columnName.addComponent(scheduledMessageKey.getFireTime(), LongSerializer.get());
    UUID id = scheduledMessageKey.getId();
    final com.eaio.uuid.UUID timeUuid = new com.eaio.uuid.UUID(id.getMostSignificantBits(),id.getLeastSignificantBits());
    columnName.addComponent(timeUuid, TimeUUIDSerializer.get());
    return columnName;
}
 
Example #15
Source File: CassandraScheduledMessageRepository.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
private Composite createColumnName(ScheduledMessage scheduledMessage) {
    final Composite columnName = new Composite();
    columnName.addComponent(scheduledMessage.getFireTime(TimeUnit.MILLISECONDS), LongSerializer.get());
    UUID id = scheduledMessage.getId();
    final com.eaio.uuid.UUID timeUuid = new com.eaio.uuid.UUID(id.getMostSignificantBits(),id.getLeastSignificantBits());
    columnName.addComponent(timeUuid, TimeUUIDSerializer.get());
    return columnName;
}
 
Example #16
Source File: CassandraScheduledMessageRepository.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
public void create(ShardKey shardKey, ScheduledMessage scheduledMessage) {
    final ColumnFamilyUpdater<Composite,Composite> updater = columnFamilyTemplate.createUpdater(createKey(shardKey));
    final Composite columnName = createColumnName(scheduledMessage);
    updater.setByteArray(columnName, ScheduledMessageSerializer.get().serialize(scheduledMessage));
    columnFamilyTemplate.update(updater);
}
 
Example #17
Source File: Cassandra12xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes in POSC index.
 * 
 * @param rowKey the row key.
 * @param ids the triple identifiers
 * @throws DataAccessLayerException in case of data access failure.
 */
void deleteInPOSC(final byte[] rowKey, final byte[][]ids) throws DataAccessLayerException {
	final Composite sc_col = new Composite();
	// subject
	sc_col.addComponent(ids[0], BYTE_SERIALIZER);

	if (ids.length == 4) {
		// context
		sc_col.addComponent(ids[3], BYTE_SERIALIZER);
	}

	_mutators.get().addDeletion(rowKey, ColumnFamily.PO_SC, sc_col, COMPOSITE_SERIALIZER);
}
 
Example #18
Source File: CassandraActorSystemEventListenerRepository.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
private Composite createKey(ShardKey shardKey, ActorSystemEvent event) {
    Composite composite = new Composite();
    composite.add(clusterName);
    composite.add(shardKey.toString());
    composite.add(event.name());
    return composite;
}
 
Example #19
Source File: CassandraActorSystemEventListenerRepository.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
public void delete(ShardKey shardKey, ActorSystemEvent event, ActorRef listenerId) {
    ColumnFamilyUpdater<Composite, String> updater = columnFamilyTemplate.createUpdater();
    updater.addKey(createKey(shardKey, event));
    updater.deleteColumn(listenerId.getActorId());
    columnFamilyTemplate.update(updater);
}
 
Example #20
Source File: CassandraActorSystemEventListenerRepository.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
@Override
public void create(ShardKey shardKey, ActorSystemEvent event, ActorSystemEventListener listener) {
    byte[] value = ActorSystemEventListenerSerializer.get().serialize(listener);
    ColumnFamilyUpdater<Composite,String> updater = columnFamilyTemplate.createUpdater(createKey(shardKey, event));
    updater.setByteArray(listener.getActorId(),value);
    columnFamilyTemplate.update(updater);
}
 
Example #21
Source File: PersistentActorUpdateEvent.java    From elasticactors with Apache License 2.0 5 votes vote down vote up
public PersistentActorUpdateEvent(Composite rowKey,
                                  ShardKey shardKey,
                                  String persistentActorId,
                                  @Nullable byte[] persistentActorBytes,
                                  @Nullable InternalMessage message,
                                  @Nullable MessageHandlerEventListener eventListener) {
    this.rowKey = rowKey;
    this.shardKey = shardKey;
    this.persistentActorId = persistentActorId;
    this.persistentActorBytes = persistentActorBytes;
    this.message = message;
    this.eventListener = eventListener;
}
 
Example #22
Source File: Cassandra12xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Insert a triple in SPOC index.
 * 
 * @param rowKey the row key.
 * @param ids the triple identifiers
 * @throws DataAccessLayerException in case of data access failure.
 */
void insertInSPOC(final byte [] rowKey, final byte[][]ids) throws DataAccessLayerException {
	final Composite poc_col = new Composite();
	poc_col.addComponent(ids[1], BYTE_SERIALIZER);
	poc_col.addComponent(ids[2], BYTE_SERIALIZER);
	if (ids.length == 4) {
		poc_col.addComponent(ids[3], BYTE_SERIALIZER);
	}

	_mutators.get().addInsertion(rowKey, S_POC, HFactory.createColumn(poc_col, EMPTY_VAL, COMPOSITE_SERIALIZER, BYTE_SERIALIZER));
}
 
Example #23
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Authenticates a user given the user name and password against the user
 * store.
 */
@Override
public boolean doAuthenticate(String userName, Object credential) throws UserStoreException {

    String password = (String) credential;
    boolean isAuthed = false;
    if (!checkUserNameValid(userName)) {
        log.error("Invalid Username");
        return false;
    }

    if (!checkUserPasswordValid(credential)) {
        log.error("Invalid password");
        return false;
    }

    if (UserCoreUtil.isRegistryAnnonymousUser(userName)) {
        log.error("Anonnymous user trying to login");
        return false;
    }

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

    ColumnFamilyTemplate<Composite, String> userCFTemplate = new ThriftColumnFamilyTemplate<Composite, String>(
            keyspace, CFConstants.UM_USER, CompositeSerializer.get(), StringSerializer.get());

    ColumnFamilyResult<Composite, String> result = userCFTemplate.queryColumns(key);
    String saltVallue = result.getString(CFConstants.UM_SALT_VALUE);
    String storedPassword = result.getString(CFConstants.UM_SECRET);

    if (TRUE.equalsIgnoreCase(realmConfig.getUserStoreProperty(JDBCRealmConstants.STORE_SALTED_PASSWORDS))) {
        password = Util.preparePassword(password, saltVallue);
        if ((storedPassword != null) && (storedPassword.equals(password))) {
            isAuthed = true;
        }
    }
    return isAuthed;
}
 
Example #24
Source File: Cassandra12xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Insert a triple in OPSC index.
 * 
 * @param rowKey the row key.
 * @param ids the triple identifiers
 * @throws DataAccessLayerException in case of data access failure.
 */
void insertInOPSC(final byte [] rowKey, final byte[][]ids) throws DataAccessLayerException {
	final Composite spc_col = new Composite();
	spc_col.addComponent(ids[0], BYTE_SERIALIZER);
	spc_col.addComponent(ids[1], BYTE_SERIALIZER);
	if (ids.length == 4) {
		spc_col.addComponent(ids[3], BYTE_SERIALIZER);
	}

	_mutators.get().addInsertion(rowKey, O_SPC, HFactory.createColumn(spc_col, EMPTY_VAL, COMPOSITE_SERIALIZER, BYTE_SERIALIZER));
}
 
Example #25
Source File: Cassandra12xTripleIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Insert a triple in POSC index.
 * 
 * @param rowKey the row key.
 * @param ids the triple identifiers
 * @throws DataAccessLayerException in case of data access failure.
 */
void insertInPOSC(final byte [] rowKey, final byte[][]ids) throws DataAccessLayerException {

	final Composite sc_col = new Composite();
	sc_col.addComponent(ids[0], BYTE_SERIALIZER);

	if (ids.length == 4) {
		sc_col.addComponent(ids[3], BYTE_SERIALIZER);
	}

	// subject col
	_mutators.get()
		.addInsertion(rowKey, PO_SC, HFactory.createColumn(sc_col, EMPTY_VAL, COMPOSITE_SERIALIZER, BYTE_SERIALIZER))
		.addInsertion(rowKey, PO_SC, HFactory.createColumn(P_COL, ids[1], COMPOSITE_SERIALIZER, BYTE_SERIALIZER));
}
 
Example #26
Source File: POSSlicesQueryIterator.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a new iterator with the given data.
 * 
 * @param dictionary the store dictionary.
 * @param isq the indexed slice query.
 * @param limit the result limit.
 * @param cf the column family name.
 * @param keyspace the keyspace.
 */
POSSlicesQueryIterator(
		final ITopLevelDictionary dictionary,
		final IndexedSlicesQuery<byte[], Composite, byte[]> isq,
		final int limit, 
		final String cf, 
		final Keyspace keyspace) {
	_dictionary = dictionary;
	_limit = limit;
	_cf = cf;
	_keyspace = keyspace;
	_rows = new IndexedSlicesIterator<byte[], Composite, byte[]>(isq, new byte[0]);
}
 
Example #27
Source File: CAndPCSlicesQueryIterator.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new iterator iterating over the results of the given query.
 * 
 * @param query The query.
 * @param limit The maximum amount of results to return.
 * @param cf The column family to query.
 * @param keyspace The keyspace to use.
 * @param dictionary the CumulusRDF dictionary.
 * @param isPC True, if this is a PC query, false, if this is a C query.
 */
CAndPCSlicesQueryIterator(
		final RangeSlicesQuery<byte[], Composite, byte[]> query,
		final int limit, 
		final String cf, 
		final Keyspace keyspace, 
		final ITopLevelDictionary dictionary,
		final boolean isPC) {
	_rows = new RangeSlicesIterator<byte[], Composite, byte[]>(query, new byte[0], new byte[0]);
	_limit = limit;
	_cf = cf;
	_keyspace = keyspace;
	_dictionary = dictionary;
	_isPC = isPC;
}
 
Example #28
Source File: Cassandra12xQuadIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
@Override
public void insertTriple(final byte[][] ids) throws DataAccessLayerException {
	super.insertTriple(ids);
	// Insert in OC_PS
	// Key: O + C
	byte[] oc_row = _dictionary.compose(ids[2], ids[3]);
	
	final Composite sp_col = new Composite();
	sp_col.addComponent(ids[1], BYTE_SERIALIZER);
	sp_col.addComponent(ids[0], BYTE_SERIALIZER);

	// subject + predicate col
	_mutators.get().addInsertion(oc_row, OC_PS, HFactory.createColumn(sp_col, EMPTY_VAL, COMPOSITE_SERIALIZER, BYTE_SERIALIZER));

	// context col
	_mutators.get().addInsertion(oc_row, OC_PS, HFactory.createColumn(C_COL, ids[3], COMPOSITE_SERIALIZER, BYTE_SERIALIZER));

	// Insert in SC_OP
	// Key: S + C
	final byte[] sc_row = _dictionary.compose(ids[0], ids[3]);
	
	final Composite op_col = new Composite();
	op_col.addComponent(ids[2], BYTE_SERIALIZER);
	op_col.addComponent(ids[1], BYTE_SERIALIZER);

	_mutators.get().addInsertion(sc_row, SC_OP, HFactory.createColumn(op_col, EMPTY_VAL, COMPOSITE_SERIALIZER, BYTE_SERIALIZER));

	// Insert in SPC_O
	// Key: S + P + C
	byte[] spc_row = _dictionary.compose(ids[0], ids[1], ids[3]);
	byte[] pc_val = _dictionary.compose(ids[1], ids[3]);
	
	final Composite o_col = new Composite();
	o_col.addComponent(ids[2], BYTE_SERIALIZER);

	// object col
	_mutators.get().addInsertion(spc_row, SPC_O, HFactory.createColumn(o_col, EMPTY_VAL, COMPOSITE_SERIALIZER, BYTE_SERIALIZER));
	// predicate + context col
	_mutators.get().addInsertion(spc_row, SPC_O, HFactory.createColumn(PC_COL, pc_val, COMPOSITE_SERIALIZER, BYTE_SERIALIZER));		
}
 
Example #29
Source File: Cassandra12xQuadIndexDAO.java    From cumulusrdf with Apache License 2.0 5 votes vote down vote up
/**
 * A SPC query.
 * 
 * @param query The query.
 * @param limit The maximum amount of results to return.
 * @return An iterator iterating over the query results.
 */
private Iterator<byte[][]> spcQuery(final byte[][] query, final int limit) {
	final ColumnSliceIterator<byte[], Composite, byte[]> results = new ColumnSliceIterator<byte[], Composite, byte[]>(
			HFactory.createSliceQuery(_dataAccessLayerFactory.getKeyspace(), BYTE_SERIALIZER, COMPOSITE_SERIALIZER, BYTE_SERIALIZER)
				.setColumnFamily(SPC_O)
				.setKey(_dictionary.compose(query[0], query[1], query[3]))
				.setRange(INCLUDE_ALL_COMPOSITE_LOWER_BOUND, INCLUDE_ALL_COMPOSITE_HIGHER_BOUND, false, limit),
			INCLUDE_ALL_COMPOSITE_LOWER_BOUND,
			INCLUDE_ALL_COMPOSITE_HIGHER_BOUND, 
			false);
	results.setFilter(DONT_INCLUDE_PREDICATE_COLUMN);
	
	return new AbstractIterator<byte[][]>() {
		@Override
		protected byte[][] computeNext() {
			if (!results.hasNext()) {
				return endOfData();
			}

			return new byte[][] { 
					query[0], 
					query[1], 
					BYTE_SERIALIZER.fromByteBuffer((ByteBuffer) results.next().getName().get(0)), 
					query[3] };
		}
	};
}
 
Example #30
Source File: CassandraUserStoreManager.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes a user by userName.
 */
@Override
public void doDeleteUser(String userName) throws UserStoreException {

    Mutator<Composite> mutator = HFactory.createMutator(keyspace, CompositeSerializer.get());
    String[] roles = doGetExternalRoleListOfUser(userName, "");
    for (String role : roles) {
        Composite key = new Composite();
        key.addComponent(role, stringSerializer);
        key.addComponent(tenantIdString, stringSerializer);
        ColumnFamilyTemplate<Composite, String> userCFTemplate = new ThriftColumnFamilyTemplate<Composite, String>(
                keyspace, CFConstants.UM_ROLE_USER_INDEX, CompositeSerializer.get(), StringSerializer.get());
        try {
            userCFTemplate.deleteColumn(key, userName);
        } catch (HectorException e) {
            log.error("Error during deletion ", e);
        }
    }

    Composite userKey = new Composite();
    userKey.addComponent(userName, stringSerializer);
    userKey.addComponent(tenantIdString, stringSerializer);
    mutator.addDeletion(userKey, CFConstants.UM_USER_ROLE, null, CompositeSerializer.get());
    mutator.addDeletion(userKey, CFConstants.UM_USER, null, CompositeSerializer.get());
    mutator.execute();

    if (log.isDebugEnabled()) {
        log.debug("Deleted user " + userName + " successfully");
    }
}