quarks
quarks

Reputation: 35326

Retrieve Entities based on logic

I have this code:

EntityIterable iterable = null;
                    if(authId== null) {
                        iterable = txn.find(entityType, "publicRead", true).skip(skip).take(limit);
                    } else {
                        iterable = txn.getAll(entityType)
                                .union(txn.find(entityType, "read(" + authId+ ")", true))
                                .union(txn.find(entityType, "publicRead", false))
                                .union(txn.find(entityType, "publicRead" ,true)).skip(skip).take(limit);
                    }
}

I'm trying to figure out a way to be able to get results based on this logic:

The problems is this:

How can this be achieved with the Xodus API?

Upvotes: 0

Views: 46

Answers (1)

Vyacheslav Lukianov
Vyacheslav Lukianov

Reputation: 2053

This can be achieved in the following way:

EntityIterable publicRead = txn.find(entityType, "publicRead", true);

EntityIterable result;

if (authId == null) {
    result = publicRead;
} else {
    result =
        txn.getAll(entityType).minus(publicRead).intersect(txn.find(entityType, "read(userIdauthIdRoleId)", true))
        .union(publicRead.intersect(txn.find(entityType, "read(" + authId + ")", true)));
}

result = result.skip(skip).take(limit);

Upvotes: 1

Related Questions