Search in sources :

Example 6 with Query

use of net.sf.ehcache.search.Query in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method getAces.

private <T extends ControlEntry> List<T> getAces(String uid, CacheId cacheId) {
    Cache cache = getCache(cacheId);
    List<T> aces = new ArrayList<T>();
    // here search on uid take place
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.USER_ID);
    // query is the fastest if you search for keys and if you need value then call Cache.get(key)
    Query queryRequestedUid = cache.createQuery().addCriteria(uidAttribute.eq(uid).or(uidAttribute.eq(WILDCARD))).addOrderBy(uidAttribute, Direction.DESCENDING).includeKeys().end();
    Results results = queryRequestedUid.execute();
    for (Result result : results.all()) {
        aces.add(DomainAccessControlStoreEhCache.<T>getElementValue(cache.get(result.getKey())));
    }
    return aces;
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) ArrayList(java.util.ArrayList) Cache(net.sf.ehcache.Cache) Result(net.sf.ehcache.search.Result)

Example 7 with Query

use of net.sf.ehcache.search.Query in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method getDomainRoles.

@Override
public List<DomainRoleEntry> getDomainRoles(String uid) {
    Cache cache = getCache(CacheId.DOMAIN_ROLES);
    List<DomainRoleEntry> domainRoles = new ArrayList<DomainRoleEntry>();
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserRoleKey.USER_ID);
    // query is the fastest if you search for keys and if you need value then call Cache.get(key)
    Query queryRequestedUid = cache.createQuery().addCriteria(uidAttribute.eq(uid)).includeKeys().end();
    Results results = queryRequestedUid.execute();
    for (Result result : results.all()) {
        domainRoles.add(DomainAccessControlStoreEhCache.<DomainRoleEntry>getElementValue(cache.get(result.getKey())));
    }
    return domainRoles;
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) ArrayList(java.util.ArrayList) Cache(net.sf.ehcache.Cache) Result(net.sf.ehcache.search.Result)

Example 8 with Query

use of net.sf.ehcache.search.Query in project directory-fortress-core by apache.

the class CacheSample method runTests.

void runTests() {
    loadCache();
    Attribute<String> member = cache.getSearchAttribute("member");
    Query query = cache.createQuery();
    query.includeKeys();
    query.includeValues();
    Set<String> roles = new HashSet<>();
    roles.add("oamt17dsd1");
    roles.add("oamt17dsd4");
    roles.add("oamT13DSD6");
    roles.add("oamT16SDR7");
    query.addCriteria(member.in(roles));
    Results results = query.execute();
    System.out.println(" Size: " + results.size());
    System.out.println("----Results-----\n");
    Set<SDSet> resultSet = new HashSet<>();
    for (Result result : results.all()) {
        DsdCacheEntry entry = (DsdCacheEntry) result.getValue();
        resultSet.add(entry.getSdSet());
    }
    for (SDSet sdSet : resultSet) {
        LOG.info("Found SDSet: " + sdSet.getName());
    }
}
Also used : SDSet(org.apache.directory.fortress.core.model.SDSet) Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) HashSet(java.util.HashSet) Result(net.sf.ehcache.search.Result)

Example 9 with Query

use of net.sf.ehcache.search.Query in project directory-fortress-core by apache.

the class SDUtil method clearDsdCacheEntry.

/**
 * Given DSD entry name, clear its corresponding object values from the cache.
 *
 * @param name contains the name of object to be cleared.
 * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.     *
 * @throws SecurityException in the event of system or rule violation.
 */
void clearDsdCacheEntry(String name, String contextId) {
    Attribute<String> context = m_dsdCache.getSearchAttribute(CONTEXT_ID);
    Attribute<String> dsdName = m_dsdCache.getSearchAttribute(DSD_NAME);
    Query query = m_dsdCache.createQuery();
    query.includeKeys();
    query.includeValues();
    query.addCriteria(dsdName.eq(name).and(context.eq(contextId)));
    Results results = query.execute();
    for (Result result : results.all()) {
        m_dsdCache.clear(result.getKey());
    }
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) Result(net.sf.ehcache.search.Result)

Example 10 with Query

use of net.sf.ehcache.search.Query in project directory-fortress-core by apache.

the class SDUtil method getDsdCache.

/**
 * Given a role name, return the set of DSD's that have a matching member.
 *
 * @param name contains name of authorized Role used to search the cache.
 * @param contextId maps to sub-tree in DIT, e.g. ou=contextId, dc=example, dc=com.
 * @return un-ordered set of matching DSD's.
 * @throws SecurityException in the event of system or rule violation.
 */
private Set<SDSet> getDsdCache(String name, String contextId) throws SecurityException {
    contextId = getContextId(contextId);
    Set<SDSet> finalSet = new HashSet<>();
    Attribute<String> context = m_dsdCache.getSearchAttribute(CONTEXT_ID);
    Attribute<String> member = m_dsdCache.getSearchAttribute(SchemaConstants.MEMBER_AT);
    Query query = m_dsdCache.createQuery();
    query.includeKeys();
    query.includeValues();
    query.addCriteria(member.eq(name).and(context.eq(contextId)));
    Results results = query.execute();
    boolean empty = false;
    for (Result result : results.all()) {
        DsdCacheEntry entry = (DsdCacheEntry) result.getValue();
        if (!entry.isEmpty()) {
            finalSet.add(entry.getSdSet());
            finalSet = putDsdCache(name, contextId);
        } else {
            empty = true;
        }
        finalSet.add(entry.getSdSet());
    }
    // If nothing was found in the cache, determine if it needs to be seeded:
    if (finalSet.size() == 0 && !empty) {
        finalSet = putDsdCache(name, contextId);
    }
    return finalSet;
}
Also used : Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) DsdCacheEntry(org.apache.directory.fortress.core.util.cache.DsdCacheEntry) HashSet(java.util.HashSet) Result(net.sf.ehcache.search.Result)

Aggregations

Query (net.sf.ehcache.search.Query)10 Results (net.sf.ehcache.search.Results)9 Result (net.sf.ehcache.search.Result)8 Cache (net.sf.ehcache.Cache)5 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)3 DsdCacheEntry (org.apache.directory.fortress.core.util.cache.DsdCacheEntry)2 UserRoleKey (io.joynr.accesscontrol.primarykey.UserRoleKey)1 Role (joynr.infrastructure.DacTypes.Role)1 SDSet (org.apache.directory.fortress.core.model.SDSet)1