Set<String> includeds = state.includes(); if (!includeds.isEmpty()) { parameters.put(KEY_INCLUDE, ParseTextUtils.join(",", includeds));
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 testInclude() { ParseQuery<ParseObject> query = new ParseQuery<>("Test"); query.include("key"); // We generate a state to verify the content of the builder ParseQuery.State state = query.getBuilder().build(); assertEquals(1, state.includes().size()); assertTrue(state.includes().contains("key")); }
/** * Makes sure all of the objects included by the given query get fetched. */ /* package */ static <T extends ParseObject> Task<Void> fetchIncludesAsync( final OfflineStore store, final T object, ParseQuery.State<T> state, final ParseSQLiteDatabase db) { Set<String> includes = state.includes(); // We do the fetches in series because it makes it easier to fail on the first error. Task<Void> task = Task.forResult(null); for (final String include : includes) { task = task.onSuccessTask(new Continuation<Void, Task<Void>>() { @Override public Task<Void> then(Task<Void> task) { return fetchIncludeAsync(store, object, include, db); } }); } return task; }
@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()); }
@Test public void testMisc() { // Include, SelectKeys, Limit, Skip ParseQuery.State.Builder<ParseObject> builder = new ParseQuery.State.Builder<>("TestObject"); builder.include("foo").include("bar"); assertEquals(2, builder.build().includes().size()); builder.selectKeys(Collections.singletonList("foo")).selectKeys(Arrays.asList("bar", "baz", "qux")); assertEquals(4, builder.build().selectedKeys().size()); builder.setLimit(42); assertEquals(42, builder.getLimit()); assertEquals(42, builder.build().limit()); builder.setSkip(48); assertEquals(48, builder.getSkip()); assertEquals(48, builder.build().skip()); }