Search in sources :

Example 1 with Role

use of joynr.infrastructure.DacTypes.Role in project joynr by bmwcarit.

the class DomainAccessControlStoreEhCache method getDomainRole.

@Override
public DomainRoleEntry getDomainRole(String uid, Role role) {
    Cache cache = getCache(CacheId.DOMAIN_ROLES);
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserRoleKey.USER_ID);
    Attribute<Role> roleAttribute = cache.getSearchAttribute(UserRoleKey.ROLE);
    // 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)).addCriteria(roleAttribute.eq(role)).includeKeys().end();
    Results results = queryRequestedUid.execute();
    DomainRoleEntry domainRole = null;
    if (!results.all().isEmpty()) {
        // results is either empty or contains exactly one entry
        assert (results.all().size() == 1);
        domainRole = (DomainAccessControlStoreEhCache.<DomainRoleEntry>getElementValue(cache.get(results.all().get(0).getKey())));
    }
    return domainRole;
}
Also used : Role(joynr.infrastructure.DacTypes.Role) Query(net.sf.ehcache.search.Query) Results(net.sf.ehcache.search.Results) DomainRoleEntry(joynr.infrastructure.DacTypes.DomainRoleEntry) Cache(net.sf.ehcache.Cache)

Aggregations

DomainRoleEntry (joynr.infrastructure.DacTypes.DomainRoleEntry)1 Role (joynr.infrastructure.DacTypes.Role)1 Cache (net.sf.ehcache.Cache)1 Query (net.sf.ehcache.search.Query)1 Results (net.sf.ehcache.search.Results)1