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; }
@Override public void removeByKeyHash(byte[] endpointKeyHash) { LOG.debug("Remove endpoint profile by key hash [{}]", Utils.encodeHexString(endpointKeyHash)); CassandraEndpointProfile storedProfile = findByKeyHash(endpointKeyHash); removeByKeyHashFromEpByEndpointGroupId(endpointKeyHash); String appId = storedProfile.getApplicationId(); if (!appId.isEmpty()) { Statement deleteEp = delete() .from(EP_BY_APP_ID_COLUMN_FAMILY_NAME) .where(eq(EP_BY_APP_ID_APPLICATION_ID_PROPERTY, appId)) .and(eq(EP_BY_APP_ID_ENDPOINT_KEY_HASH_PROPERTY, getByteBuffer(endpointKeyHash))); executeBatch(deleteEp); } getMapper().delete(getByteBuffer(endpointKeyHash)); }