class DBDeviceGroupManager extends DBManager<DeviceGroup> implements DeviceGroupManager {

    @Override
    public final Set<DeviceGroup> getGroupsAssignedToPolicy(final Policy policy)
            throws DeviceGroupManagerException {

        if (policy == null) {
            LOGGER.error("policy provided was null");
            throw new DeviceGroupManagerException("policy provided was null");
        }

        final SessionFactory factory = getFactory();
        Set<DeviceGroup> groups = new HashSet<>();

        Session session = factory.getCurrentSession();
        Transaction tx = session.beginTransaction();

        try {
            LOGGER.debug("retrieving policy mapper from db where policy = {}", policy);

            //Retrieves a list of PolicyMapper objects that are unique per group
            List policyMapperList = session.createCriteria(PolicyMapper.class)
                    .add(Restrictions.eq("policy", policy)).list();

            session.getTransaction().commit();

            if (policyMapperList == null) {
                LOGGER.debug("no policy mapper found for policy {}", policy);

            } else {
                for (Object o : policyMapperList) {
                    if (o instanceof PolicyMapper) {
                        groups.add(((PolicyMapper) o).getDeviceGroup());
                    }
                }
            }
        } catch (Exception e) {

            final String msg = "unable to get default policy";
            LOGGER.error(msg, e);

            LOGGER.debug("rolling back transaction");
            tx.rollback();

            throw new DeviceGroupManagerException(msg, e);

        }
        return groups;
    }

    public  DBDeviceGroupManager(final SessionFactory factory);

}