/** * Renames the existing authzObj to a new one in the authzObj -> [Paths] mapping, * but keeps its paths mapping as-is. * * @param pm PersistenceManager * @param oldObj the existing authzObj * @param newObj the new name to be changed to * @throws SentryNoSuchObjectException if cannot find the existing authzObj. */ private void renameAuthzObjCore(PersistenceManager pm, String oldObj, String newObj) { long currentSnapshotID = getCurrentAuthzPathsSnapshotID(pm); if (currentSnapshotID <= EMPTY_PATHS_SNAPSHOT_ID) { LOGGER.error("No paths snapshot ID is found. Cannot rename authzoObj: {}", oldObj); } MAuthzPathsMapping mAuthzPathsMapping = getMAuthzPathsMappingCore(pm, currentSnapshotID, oldObj); if (mAuthzPathsMapping != null) { mAuthzPathsMapping.setAuthzObjName(newObj); pm.makePersistent(mAuthzPathsMapping); } else { LOGGER.error("nonexistent authzObj: {} on current paths snapshot ID #{}", oldObj, currentSnapshotID); } }
/** * Renames the existing authzObj to a new one in the authzObj -> [Paths] mapping. * And updates its existing path with a new path, while keeps the rest of its paths * untouched if there is any. * * @param pm PersistenceManager * @param oldObj the existing authzObj * @param newObj the new name to be changed to * @param oldPath a existing path of the given authzObj * @param newPath a new path to be changed to * @throws SentryNoSuchObjectException if cannot find the existing authzObj or path. */ private void renameAuthzPathsMappingCore(PersistenceManager pm, String oldObj, String newObj, String oldPath, String newPath) { long currentSnapshotID = getCurrentAuthzPathsSnapshotID(pm); if (currentSnapshotID <= EMPTY_PATHS_SNAPSHOT_ID) { LOGGER.error("No paths snapshot ID is found. Cannot rename authzoObj: {}", oldObj); } MAuthzPathsMapping mAuthzPathsMapping = getMAuthzPathsMappingCore(pm, currentSnapshotID, oldObj); if (mAuthzPathsMapping != null) { mAuthzPathsMapping.deletePersistent(pm,Collections.singleton(oldPath)); mAuthzPathsMapping.setAuthzObjName(newObj); mAuthzPathsMapping.addPathToPersist(Collections.singleton(newPath)); mAuthzPathsMapping.makePersistent(pm); } else { LOGGER.error("nonexistent authzObj: {} on current paths snapshot ID #{}", oldObj, currentSnapshotID); } }