Java Code Examples for net.sf.ehcache.Cache#getSearchAttribute()

The following examples show how to use net.sf.ehcache.Cache#getSearchAttribute() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 6 votes vote down vote up
@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()) {
        // Note: since (uid, role) is the primary key in domain role table
        // 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;
}
 
Example 2
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 6 votes vote down vote up
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)))
                                   // have specific user ids appear before wildcards
                                   .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;
}
 
Example 3
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 6 votes vote down vote up
private <T extends ControlEntry> List<T> getAces(String domain, String interfaceName, CacheId cacheId) {
    Cache cache = getCache(cacheId);
    List<T> aces = new ArrayList<T>();
    // here search on domain and interface take place
    Attribute<String> domainAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.DOMAIN);
    Attribute<String> interfaceAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.INTERFACE);
    // query is the fastest if you search for keys and if you need value then call Cache.get(key)
    Query queryDomainInterface = cache.createQuery()
                                      .addCriteria(domainAttribute.eq(domain)
                                                                  .and(interfaceAttribute.eq(interfaceName)))
                                      .includeKeys()
                                      .end();
    Results results = queryDomainInterface.execute();
    for (Result result : results.all()) {
        T ace = DomainAccessControlStoreEhCache.<T> getElementValue(cache.get(result.getKey()));
        aces.add(ace);
    }

    return aces;
}
 
Example 4
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 5
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 5 votes vote down vote up
private <T extends ControlEntry> T getAce(CacheId cacheId,
                                          String uid,
                                          String domain,
                                          String interfaceName,
                                          String operation) {
    Cache cache = getCache(cacheId);
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.USER_ID);
    Attribute<String> domainAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.DOMAIN);
    Attribute<String> interfaceAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.INTERFACE);
    Attribute<String> operationAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.OPERATION);
    Query queryAllOperations = cache.createQuery()
                                    .addCriteria(uidAttribute.eq(uid).or(uidAttribute.eq(WILDCARD)))
                                    .addCriteria(domainAttribute.eq(domain))
                                    .addCriteria(interfaceAttribute.eq(interfaceName))
                                    .addCriteria(operationAttribute.eq(operation))
                                    // have specific user ids appear before wildcards
                                    .addOrderBy(uidAttribute, Direction.DESCENDING)
                                    .includeKeys()
                                    .end();
    Results results = queryAllOperations.execute();
    T ace = null;
    if (!results.all().isEmpty()) {
        ace = DomainAccessControlStoreEhCache.<T> getElementValue(cache.get(results.all().get(0).getKey()));
    }

    return ace;
}
 
Example 6
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 5 votes vote down vote up
private <T extends ControlEntry> List<T> getAces(CacheId cacheId, String uid, String domain, String interfaceName) {
    Cache cache = getCache(cacheId);
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.USER_ID);
    Attribute<String> domainAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.DOMAIN);
    Attribute<String> interfaceAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.INTERFACE);
    Query queryAllOperations = cache.createQuery()
                                    .addCriteria(uidAttribute.eq(uid).or(uidAttribute.eq(WILDCARD)))
                                    .addCriteria(domainAttribute.eq(domain))
                                    .addCriteria(interfaceAttribute.eq(interfaceName))
                                    // have specific user ids appear before wildcards
                                    .addOrderBy(uidAttribute, Direction.DESCENDING)
                                    .includeKeys()
                                    .end();
    Results results = queryAllOperations.execute();
    List<T> aces = new ArrayList<T>();
    String currentUid = null;
    for (Result result : results.all()) {
        T ace = DomainAccessControlStoreEhCache.<T> getElementValue(cache.get(result.getKey()));

        // Don't add uid wildcards if a specific uid has been added to the results
        if (currentUid == null) {
            currentUid = ace.getUid();
        } else if (!currentUid.equals(ace.getUid())) {
            break;
        }

        aces.add(ace);
    }

    return aces;
}
 
Example 7
Source File: DomainAccessControlStoreEhCache.java    From joynr with Apache License 2.0 5 votes vote down vote up
private <T extends ControlEntry> List<T> getEditableAces(String uid, CacheId cacheId, Role role) {
    List<T> aces = new ArrayList<T>();
    // find out first on which domains uid has specified role
    Cache drtCache = getCache(CacheId.DOMAIN_ROLES);
    UserRoleKey dreKey = new UserRoleKey(uid, role);
    String[] uidDomains = null;
    // read domains from DRE
    if (drtCache.isKeyInCache(dreKey)) {
        DomainRoleEntry dre = DomainAccessControlStoreEhCache.<DomainRoleEntry> getElementValue(drtCache.get(dreKey));
        uidDomains = dre.getDomains();
    }
    // if uid has no domains with specified role return empty list
    if (uidDomains == null || uidDomains.length == 0) {
        return aces;
    }

    Cache cache = getCache(cacheId);
    // here should search on uid and domain take place
    Attribute<String> uidAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.USER_ID);
    Attribute<String> domainAttribute = cache.getSearchAttribute(UserDomainInterfaceOperationKey.DOMAIN);
    for (String domain : uidDomains) {
        Query query = cache.createQuery()
                           .addCriteria(uidAttribute.eq(uid).and(domainAttribute.eq(domain)))
                           .includeKeys()
                           .end();
        Results results = query.execute();
        for (Result result : results.all()) {
            aces.add(DomainAccessControlStoreEhCache.<T> getElementValue(cache.get(result.getKey())));
        }

    }

    return aces;
}