public Builder(State state) { className = state.className(); where.putAll(state.constraints()); includes.addAll(state.includes()); selectedKeys = state.selectedKeys() != null ? new HashSet(state.selectedKeys()) : null; limit = state.limit(); skip = state.skip(); order.addAll(state.order()); extraOptions.putAll(state.extraOptions()); trace = state.isTracingEnabled(); cachePolicy = state.cachePolicy(); maxCacheAge = state.maxCacheAge(); isFromLocalDatastore = state.isFromLocalDatastore(); pinName = state.pinName(); ignoreACLs = state.ignoreACLs(); }
@Test public void testDefaults() { ParseQuery.State.Builder<ParseObject> builder = new ParseQuery.State.Builder<>("TestObject"); ParseQuery.State<ParseObject> state = builder.build(); assertEquals("TestObject", state.className()); assertTrue(state.constraints().isEmpty()); assertTrue(state.includes().isEmpty()); assertNull(state.selectedKeys()); assertEquals(-1, state.limit()); assertEquals(0, state.skip()); assertTrue(state.order().isEmpty()); assertTrue(state.extraOptions().isEmpty()); assertFalse(state.isTracingEnabled()); assertEquals(ParseQuery.CachePolicy.IGNORE_CACHE, state.cachePolicy()); assertEquals(Long.MAX_VALUE, state.maxCacheAge()); assertFalse(state.isFromLocalDatastore()); assertNull(state.pinName()); assertFalse(state.ignoreACLs()); }
/** * Returns a ConstraintMatcher that return true iff the object matches the given query's * constraints. This takes in a SQLiteDatabase connection because SQLite is finicky about nesting * connections, so we want to reuse them whenever possible. * * @param state The query. * @param user The user we are testing ACL access for. * @param <T> Subclass of ParseObject. * @return A new instance of ConstraintMatcher. */ /* package */ <T extends ParseObject> ConstraintMatcher<T> createMatcher( ParseQuery.State<T> state, final ParseUser user) { final boolean ignoreACLs = state.ignoreACLs(); final ConstraintMatcher<T> constraintMatcher = createMatcher(user, state.constraints()); return new ConstraintMatcher<T>(user) { @Override public Task<Boolean> matchesAsync(T object, ParseSQLiteDatabase db) { if (!ignoreACLs && !hasReadAccess(user, object)) { return Task.forResult(false); } return constraintMatcher.matchesAsync(object, db); } }; }
/** * Returns the user used for the query. This user is used to filter results based on ACLs on the * target objects. Can be {@code null} if the there is no current user or {@link #ignoreACLs} is * enabled. */ /* package for tests */ Task<ParseUser> getUserAsync(State<T> state) { if (state.ignoreACLs()) { return Task.forResult(null); } if (user != null) { return Task.forResult(user); } return ParseUser.getCurrentUserAsync(); }