@SuppressWarnings("unchecked") public List<JetspeedPrincipal> getAssociatedFrom(Long principalFromId, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName, Long fromSecurityDomain, Long toSecurityDomain) { Criteria criteria = new Criteria(); criteria.addEqualTo("associationsTo.associationName", associationName); criteria.addEqualTo("associationsTo.from.id", principalFromId); criteria.addEqualTo("associationsTo.from.type", from.getName()); criteria.addEqualTo("type", to.getName()); criteria.addEqualTo("associationsTo.from.domainId", fromSecurityDomain); criteria.addEqualTo("domainId", toSecurityDomain); // check cache String cacheKey = "getAssociatedFrom:"+criteria; List<JetspeedPrincipal> associatedFrom = (List<JetspeedPrincipal>)jspmCache.getAssociationQuery(cacheKey); if (associatedFrom != null) { return new ArrayList<JetspeedPrincipal>(associatedFrom); } // perform query Query query = QueryFactory.newQuery(PersistentJetspeedPrincipal.class, criteria); associatedFrom = (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query)); // put result in cache jspmCache.putAssociationQuery(cacheKey, principalFromId, extractPrincipalIds(associatedFrom), fromSecurityDomain, toSecurityDomain, new ArrayList<JetspeedPrincipal>(associatedFrom)); // return result return associatedFrom; }
@SuppressWarnings("unchecked") public List<JetspeedPrincipal> getAssociatedTo(Long principalToId, JetspeedPrincipalType from, JetspeedPrincipalType to, String associationName, Long fromSecurityDomain, Long toSecurityDomain) { Criteria criteria = new Criteria(); criteria.addEqualTo("associationsFrom.associationName", associationName); criteria.addEqualTo("associationsFrom.to.id", principalToId); criteria.addEqualTo("type", from.getName()); criteria.addEqualTo("associationsFrom.to.type", to.getName()); criteria.addEqualTo("associationsFrom.to.domainId", toSecurityDomain); criteria.addEqualTo("domainId", fromSecurityDomain); // check cache String cacheKey = "getAssociatedTo:"+criteria; List<JetspeedPrincipal> associatedTo = (List<JetspeedPrincipal>)jspmCache.getAssociationQuery(cacheKey); if (associatedTo != null) { return new ArrayList<JetspeedPrincipal>(associatedTo); } // perform query Query query = QueryFactory.newQuery(PersistentJetspeedPrincipal.class, criteria); associatedTo = (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query)); // put result in cache jspmCache.putAssociationQuery(cacheKey, principalToId, extractPrincipalIds(associatedTo), fromSecurityDomain, toSecurityDomain, new ArrayList<JetspeedPrincipal>(associatedTo)); // return result return associatedTo; }
jspmCache.putAssociationQuery(cacheKey, principalFromId, extractPrincipalIds(associatedFrom), fromSecurityDomain, toSecurityDomain, new ArrayList<JetspeedPrincipal>(associatedFrom));
jspmCache.putAssociationQuery(cacheKey, principalToId, extractPrincipalIds(associatedTo), fromSecurityDomain, toSecurityDomain, new ArrayList<JetspeedPrincipal>(associatedTo));
principals = (List<JetspeedPrincipal>) getPersistenceBrokerTemplate().execute(new ManagedListByQueryCallback(query)); jspmCache.putPermissionQuery(cacheKey, null, extractPrincipalIds(principals), ((permission.getId() != null) ? permission.getId(): JSPMCache.ANY_ID), securityDomain, new ArrayList<JetspeedPrincipal>(principals));