class DBPolicyManager extends DBManager<Policy> implements PolicyManager {

    public final int getGroupCountForPolicy(final Policy policy) {
        int count = 0;

        if (policy != null) {
            final SessionFactory factory = getFactory();
            Transaction tx = null;
            Session session = factory.getCurrentSession();
            try {
                tx = session.beginTransaction();
                LOGGER.debug("retrieving group use count for policy {}", policy);
                final Criteria cr = session.createCriteria(PolicyMapper.class)
                        .add(Restrictions.eq("policy", policy))
                        .setProjection(Projections.projectionList()
                                        .add(Projections.count("policy")));

                final Object result = cr.uniqueResult();
                if (result != null && result instanceof Long) {
                    count = ((Long) result).intValue();
                }
            } catch (Exception e) {
                // Log the error and return -1 to enable error handling.
                count = -1;
                final String msg =
                    "There was an error retrieving the group use count for a policy (ID: "
                            + policy.getId() + ", Name: " + policy.getName() + ").";
                LOGGER.error(msg, e);
            } finally {
                if (tx != null) {
                    tx.rollback();
                }
            }
        }

        return count;
    }

    public  DBPolicyManager(final SessionFactory factory);

}