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; }
private CassandraEndpointProfile updateProfile(CassandraEndpointProfile profile) { LOG.debug("Updating endpoint profile with id {}", profile.getId()); ByteBuffer epKeyHash = profile.getEndpointKeyHash(); byte[] keyHash = getBytes(epKeyHash); LOG.error("[{}] Can't update endpoint profile with version {}. " + "Endpoint profile already changed!", profile.getId(), profile.getVersion()); throw new KaaOptimisticLockingFailureException("Can't update endpoint profile with" + " version . Endpoint profile already changed!"); LOG.debug("[{}] Endpoint profile updated", profile.getId()); } else { LOG.error("[{}] Stored profile is null. Can't update endpoint profile.", profile.getId()); throw new DatabaseProcessingException("Stored profile is null. " + "Can't update endpoint profile.");