private ByteBuffer[] getEndpointKeyHash(List<CassandraEpByAppId> filter) { ByteBuffer[] endpointKeyHash = new ByteBuffer[filter.size()]; int pos = 0; for (CassandraEpByAppId ep : filter) { endpointKeyHash[pos++] = ep.getEndpointKeyHash(); } return endpointKeyHash; }
private CassandraEndpointProfile saveProfile(CassandraEndpointProfile profile) { profile.setId(convertKeyHashToString(profile.getEndpointKeyHash())); LOG.debug("Saving endpoint profile with id {}", profile.getId()); profile = super.save(profile); ByteBuffer epKeyHash = profile.getEndpointKeyHash(); List<Statement> statementList = new ArrayList<>(); statementList.add(cassandraEpByAppIdDao.getSaveQuery( new CassandraEpByAppId(profile.getApplicationId(), epKeyHash))); String accessToken = profile.getAccessToken(); if (accessToken != null) { statementList.add( cassandraEpByAccessTokenDao.getSaveQuery( new CassandraEpByAccessToken(accessToken, epKeyHash))); } statementList.add(getSaveQuery(profile)); Statement saveBySdkTokenId = cassandraEpBySdkTokenDao.getSaveQuery( new CassandraEpBySdkToken(profile.getSdkToken(), epKeyHash)); statementList.add(saveBySdkTokenId); Set<String> groupIdSet = getEndpointProfilesGroupIdSet(profile); for (String groupId : groupIdSet) { statementList.add( cassandraEpByEndpointGroupIdDao.getSaveQuery( new CassandraEpByEndpointGroupId(groupId, epKeyHash))); } executeBatch(statementList.toArray(new Statement[statementList.size()])); LOG.debug("[{}] Endpoint profile saved", profile.getId()); return profile; }
/** * Get endpoints ids from specific application. * @param appId is application's id * @return endpoints ids */ public ByteBuffer[] getEpIdsListByAppId(String appId) { LOG.debug("Try to find endpoint key hash list by application id {}", appId); List<CassandraEpByAppId> filter = findListByStatement(select() .from(getColumnFamilyName()) .where(eq(EP_BY_APP_ID_APPLICATION_ID_PROPERTY, appId))); ByteBuffer[] result = new ByteBuffer[filter.size()]; int pos = 0; for (CassandraEpByAppId ep : filter) { result[pos++] = ep.getEndpointKeyHash(); } return result; }