/** * <p> * Searches the database for the {@code ACL} associated with the specified resource. * </p> * * @param resource the {@code Resource} that is associated with the {@code ACL} being searched. * @param entityManager the {@code EntityManager} used to search the database. * @return the {@code ACL} retrieved from the database, or {@code null} if no {@code ACL} could be found. */ private ACLImpl findACLByResource(Resource resource, EntityManager entityManager) { ACLImpl acl = null; try { acl = (ACLImpl) entityManager.createQuery( "SELECT a FROM ACLImpl a WHERE a.resourceAsString LIKE '" + Util.getResourceAsString(resource) + "'") .getSingleResult(); acl.setResource(resource); } catch (NoResultException nre) { // ignore the exception when no ACL could be found for the given resource. } return acl; } }
/** * <p> * Searches the database for the {@code ACL} associated with the specified resource. * </p> * * @param resource the {@code Resource} that is associated with the {@code ACL} being searched. * @param entityManager the {@code EntityManager} used to search the database. * @return the {@code ACL} retrieved from the database, or {@code null} if no {@code ACL} could be found. */ private ACLImpl findACLByResource(Resource resource, EntityManager entityManager) { ACLImpl acl = null; try { acl = (ACLImpl) entityManager.createQuery( "SELECT a FROM ACLImpl a WHERE a.resourceAsString LIKE '" + Util.getResourceAsString(resource) + "'") .getSingleResult(); acl.setResource(resource); } catch (NoResultException nre) { // ignore the exception when no ACL could be found for the given resource. } return acl; } }
@SuppressWarnings("unchecked") public Collection<ACL> getACLs() { Collection<ACL> acls = null; EntityManager entityManager = this.managerFactory.createEntityManager(); try { acls = entityManager.createQuery("SELECT a FROM ACLImpl a").getResultList(); if (acls != null && this.resourceFactory != null) { for (ACL acl : acls) { ACLImpl impl = (ACLImpl) acl; String[] resourceName = impl.getResourceAsString().split(":"); impl.setResource(this.resourceFactory.instantiateResource(resourceName[0], resourceName[1])); } } } finally { entityManager.close(); } return acls; }
@SuppressWarnings("unchecked") public Collection<ACL> getACLs() { Collection<ACL> acls = null; EntityManager entityManager = this.managerFactory.createEntityManager(); try { acls = entityManager.createQuery("SELECT a FROM ACLImpl a").getResultList(); if (acls != null && this.resourceFactory != null) { for (ACL acl : acls) { ACLImpl impl = (ACLImpl) acl; String[] resourceName = impl.getResourceAsString().split(":"); impl.setResource(this.resourceFactory.instantiateResource(resourceName[0], resourceName[1])); } } } finally { entityManager.close(); } return acls; }