class ServiceDBStore implements ServiceStore {

	@Override
	public void deletePolicy(Long policyId) throws Exception {
		if(LOG.isDebugEnabled()) {
			LOG.debug("==> ServiceDBStore.deletePolicy(" + policyId + ")");
		}

		RangerPolicy policy = getPolicy(policyId);

		if(policy == null) {
			throw new Exception("no policy exists with ID=" + policyId);
		}

		String policyName = policy.getName();
		RangerService service = getServiceByName(policy.getService());

		if(service == null) {
			throw new Exception("service does not exist - name='" + policy.getService());
		}

		Long version = policy.getVersion();
		if(version == null) {
			version = new Long(1);
			LOG.info("Found Version Value: `null`, so setting value of version to 1, While updating object, version should not be null.");
		} else {
			version = new Long(version.longValue() + 1);
		}

		policy.setVersion(version);

		List<XXTrxLog> trxLogList = policyService.getTransactionLog(policy, RangerPolicyService.OPERATION_DELETE_CONTEXT);

		deleteExistingPolicyItems(policy);
		deleteExistingPolicyResources(policy);

		policyService.delete(policy);
		handlePolicyUpdate(service);

		dataHistService.createObjectDataHistory(policy, RangerDataHistService.ACTION_DELETE);

		bizUtil.createTrxLog(trxLogList);

		RangerServicePoliciesCache.getInstance().
				updatePolicyInCache("delete", policy, this);

		LOG.info("Policy Deleted Successfully. PolicyName : " + policyName);
	}

}