Java Code Examples for com.parse.ParseObject

The following examples show how to use com.parse.ParseObject. These examples are extracted from open source projects. 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
@Override
protected void doIndexedStringEntityQueries() throws Exception {
    // According to the documentation, Parse does NOT support defining indexes manually
    // or for the local datastore.
    // We still are going to determine query performance WITHOUT AN INDEX.

    // set up parse inside of test
    // setting it up in setUp() breaks Parse, as it keeps its init state between tests
    // in hidden ParsePlugins
    ParseObject.registerSubclass(IndexedStringEntity.class);
    setupParse();

    for (int i = 0; i < RUNS; i++) {
        log("----Run " + (i + 1) + " of " + RUNS);
        indexedStringEntityQueriesRun(getBatchSize());
    }
}
 
Example 2
@Override
protected void doOneByOneCrudRun(int count) throws Exception {
    List<ParseObject> list = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        list.add(createEntity(i));
    }

    startClock();
    for (int i = 0; i < count; i++) {
        list.get(i).pin();
    }
    stopClock(Benchmark.Type.ONE_BY_ONE_CREATE);

    startClock();
    for (int i = 0; i < count; i++) {
        list.get(i).pin();
    }
    stopClock(Benchmark.Type.ONE_BY_ONE_UPDATE);

    deleteAll();
}
 
Example 3
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 6 votes vote down vote up
/**
 *  Limit 10000 by skip
 */
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Observable<R> all(@NonNull final ParseQuery<R> query, int count) {
    final int limit = 1000; // limit limitation
    query.setSkip(0);
    query.setLimit(limit);
    Observable<R> find = find(query);
    for (int i = limit; i < count; i+= limit) {
        if (i >= 10000) break; // skip limitation
        query.setSkip(i);
        query.setLimit(limit);
        find.concatWith(find(query));
    }
    return find.distinct(o -> o.getObjectId());
}
 
Example 4
Source Project: DataSync   Source File: SyncEntity.java    License: Apache License 2.0 6 votes vote down vote up
public static <T extends SyncEntity> ParseObject toParseObject(T entity) {
    try {
        Class entityClass = entity.getClass();
        ParseClass a = (ParseClass) entityClass.getAnnotation(ParseClass.class);
        String parseClassName = entityClass.getSimpleName();

        if (a.name() != null && !a.name().isEmpty()) {
            parseClassName = a.name();
        }

        ParseObject parseObject = ParseObject.create(parseClassName);
        toParseObject(entity, parseObject);

        return parseObject;

    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 5
Source Project: protohipster   Source File: LikeUserCall.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void call() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery(ParseLikeTableDefinitions.PARSE_LIKE_TABLE);
    query.whereEqualTo(ParseLikeTableDefinitions.PARSE_LIKE_USER_ID, userId);

    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> parseLikes, ParseException e) {
            if (e == null) {
                if(parseLikes.size() > 0){
                    ParseObject likeObject = parseLikes.get(0);

                    likeObject.increment(ParseLikeTableDefinitions.PARSE_LIKE_NUM_LIKES);
                    likeObject.saveInBackground();
                }

                responseCallback.complete(userId);

            } else {
                LoggerProvider.getLogger().d(LOGTAG, "Error retrying info from parse");
            }
        }

    });
}
 
Example 6
private void logEvent(final String eventName, Map<String, Object> properties)
{
    if (!OBConfigManager.sharedManager.isAnalyticsEnabled()) return;
    //
    MainActivity.log("OBAnalyticsManagerOnline.logEvent: " + eventName + " " + properties.toString());
    //
    ParseObject parseObject = new ParseObject(eventName);
    for (String key : properties.keySet())
    {
        parseObject.put(key, properties.get(key));
    }
    //
    parseObject.put(OBAnalytics.Params.DEVICE_UUID, OBSystemsManager.sharedManager.device_getUUID());
    parseObject.saveEventually(new SaveCallback()
    {
        @Override
        public void done (ParseException e)
        {
            if (e != null)
            {
                MainActivity.log("OBAnalyticsManagerOnline.logEvent.event save failed");
                e.printStackTrace();
            }
        }
    });
    //
    long currentTime = System.currentTimeMillis();
    // TODO: move the time frame for uploads to the config (1hour)
    if (currentTime - lastDataUploadTimestamp > 1000 * 60 * 60 * 1)
    {
        uploadData();
    }
}
 
Example 7
private void indexedStringEntityQueriesRun(int count) throws ParseException {
    // create entities
    List<IndexedStringEntity> entities = new ArrayList<>(count);
    String[] fixedRandomStrings = StringGenerator.createFixedRandomStrings(count);
    for (int i = 0; i < count; i++) {
        IndexedStringEntity entity = new IndexedStringEntity();
        entity.setIndexedString(fixedRandomStrings[i]);
        entities.add(entity);
    }
    log("Built entities.");

    // insert entities
    ParseObject.pinAll(entities);
    log("Inserted entities.");

    // query for entities by indexed string at random
    int[] randomIndices = StringGenerator.getFixedRandomIndices(QUERY_COUNT, count - 1);

    startClock();
    for (int i = 0; i < QUERY_COUNT; i++) {
        int nextIndex = randomIndices[i];

        ParseQuery<IndexedStringEntity> query = ParseQuery.getQuery(IndexedStringEntity.class);
        query.whereEqualTo(IndexedStringEntity.INDEXED_STRING, fixedRandomStrings[nextIndex]);
        //noinspection unused
        List<IndexedStringEntity> result = query.find();
    }
    stopClock(Benchmark.Type.QUERY_INDEXED);

    // delete all entities
    ParseObject.unpinAll();
    log("Deleted all entities.");
}
 
Example 8
@Override
protected void doBatchCrudRun(int count) throws Exception {
    List<ParseObject> list = new ArrayList<>(count);
    for (int i = 0; i < count; i++) {
        list.add(createEntity(i));
    }

    startClock();
    ParseObject.pinAll(list);
    stopClock(Benchmark.Type.BATCH_CREATE);

    startClock();
    ParseObject.pinAll(list);
    stopClock(Benchmark.Type.BATCH_UPDATE);

    startClock();
    List<ParseObject> reloaded = ParseQuery.getQuery("SimpleEntity")
            .fromLocalDatastore()
            .find();
    stopClock(Benchmark.Type.BATCH_READ);

    startClock();
    for (int i = 0; i < reloaded.size(); i++) {
        ParseObject entity = reloaded.get(i);
        entity.getBoolean("simpleBoolean");
        entity.getInt("simpleByte");
        entity.getInt("simpleShort");
        entity.getInt("simpleInt");
        entity.getLong("simpleLong");
        entity.getDouble("simpleFloat");
        entity.getDouble("simpleDouble");
        entity.getString("simpleString");
        entity.getBytes("simpleByteArray");
    }
    stopClock(Benchmark.Type.BATCH_ACCESS);

    startClock();
    deleteAll();
    stopClock(Benchmark.Type.BATCH_DELETE);
}
 
Example 9
private ParseObject createEntity(int nr) {
    ParseObject entity = new ParseObject("SimpleEntity");
    entity.put("simpleBoolean", true);
    entity.put("simpleByte", nr & 0xff);
    entity.put("simpleShort", nr & 0xffff);
    entity.put("simpleInt", nr);
    entity.put("simpleLong", Long.MAX_VALUE - nr);
    entity.put("simpleFloat", (float) (Math.PI * nr));
    entity.put("simpleDouble", Math.E * nr);
    entity.put("simpleString", "greenrobot greenDAO");
    byte[] bytes = { 42, -17, 23, 0, 127, -128 };
    entity.put("simpleByteArray", bytes);
    return entity;
}
 
Example 10
Source Project: DataSync   Source File: SyncEntity.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends SyncEntity> T fromParseObject(ParseObject parseObject, Class<T> entityClass) {
    try {
        final T entity = entityClass.newInstance();
        fromParseObject(parseObject, entity);
        return entity;
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
 
Example 11
Source Project: DataSync   Source File: ParseTools.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends ParseObject> Task<List<T>> findAllParseObjectsAsync(final ParseQuery<T> query) {
    return Task.callInBackground(new Callable<List<T>>() {
        @Override
        public List<T> call() throws Exception {
            return findAllParseObjects(query);
        }
    });
}
 
Example 12
Source Project: DataSync   Source File: ParseTools.java    License: Apache License 2.0 5 votes vote down vote up
public static <T extends ParseObject> List<T> findAllParseObjects(ParseQuery<T> query) throws ParseException {
    List <T> result = new ArrayList<T>();
    query.setLimit(DEFAULT_PARSE_QUERY_LIMIT);
    List<T> chunk = null;
    do {
        chunk = query.find();
        result.addAll(chunk);
        query.setSkip(query.getSkip() + query.getLimit());
    } while (chunk.size() == query.getLimit());
    return result;
}
 
Example 13
Source Project: Gazetti_Newspaper_Reader   Source File: NewsAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        LayoutInflater inflater = ctx.getLayoutInflater();
        convertView = inflater.inflate(R.layout.headline_list_row, parent, false);

        holder = new ViewHolder();
        holder.textViewItem = (TextView) convertView.findViewById(R.id.headline);
        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    ParseObject object = articleObjectList.get(position);
    // Add the title view
    holder.textViewItem.setText(object.getString("title"));

    // get PubDate
    Date createdAtDate = object.getCreatedAt();
    long createdAtDateInMillis = createdAtDate.getTime();
    //Log.d(TAG, "createdAtDateInMillis " + createdAtDateInMillis);

    String diff = getTimeAgo(createdAtDateInMillis);
    //Log.d(TAG, "diff " + diff);

    // Add title, link to Map
    linkMap.put(object.getString("title"), object.getString("link"));
    pubDateMap.put(object.getString("title"), diff);
    //Log.d(TAG, "Added " + pubDateMap.get(object.getString("title")));

    // PubDate

    return convertView;

}
 
Example 14
Source Project: Gazetti_Newspaper_Reader   Source File: WebsiteListFragment.java    License: MIT License 5 votes vote down vote up
private void getOldListItems(Date lastObjectCreatedAtDate) {

        ParseQuery<ParseObject> queryGetOldItems = ParseQuery.getQuery(dbToSearch);
        queryGetOldItems.whereEqualTo("newspaper_id", npIdString);
        queryGetOldItems.whereEqualTo("cat_id", catIdString);
        queryGetOldItems.whereLessThan("createdAt", lastObjectCreatedAtDate);
        queryGetOldItems.setLimit(20);
        queryGetOldItems.orderByDescending("createdAt");

        queryGetOldItems.findInBackground(new FindCallback<ParseObject>() {
            @Override
            public void done(List<ParseObject> articleObjectList, ParseException exception) {
                // Log.d(TAG, "Old Items articleObjectList " +
                // articleObjectList.size());
                if(exception == null){
                    retainedList.addAll(articleObjectList);
                    newsAdapter.notifyDataSetChanged();

                    // Log.d(TAG, "articleObjectList Retained " +
                    // retainedList.size());

                    mListView.removeFooterView(footerOnList);
                    mListViewContainer.setRefreshing(false);
                    flag_loading_old_data = false;
                } else {
                    Crashlytics.log("Wrong while fetching - " + exception.getMessage());
                    headerTextView.setText("Something went wrong!");
                }
            }

        });

    }
 
Example 15
Source Project: protohipster   Source File: GetLikesCall.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void call() {
    ParseQuery<ParseObject> query = ParseQuery.getQuery(ParseLikeTableDefinitions.PARSE_LIKE_TABLE);
    query.whereContainedIn(ParseLikeTableDefinitions.PARSE_LIKE_USER_ID, userIds);

    query.findInBackground(new FindCallback<ParseObject>() {
        @Override
        public void done(List<ParseObject> parseLikes, ParseException e) {
            if (e == null) {
                GetLikesResponse response = new GetLikesResponse();

                for (ParseObject likeObject : parseLikes) {
                    String userId = likeObject.getString(ParseLikeTableDefinitions.PARSE_LIKE_USER_ID);
                    int numLikes = likeObject.getInt(ParseLikeTableDefinitions.PARSE_LIKE_NUM_LIKES);

                    response.add(userId, numLikes);
                }

                responseCallback.complete(response);

            } else {
                LoggerProvider.getLogger().d(LOGTAG, "Error retrying info from parse");
            }
        }

    });
}
 
Example 16
private void deleteAll() throws ParseException {
    ParseObject.unpinAll();
}
 
Example 17
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Observable<R> find(@NonNull final ParseQuery<R> query) {
    return RxTask.observable(() -> query.findInBackground())
            .flatMap(l -> Observable.fromIterable(l));
}
 
Example 18
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Single<Integer> count(@NonNull final ParseQuery<R> query) {
    return RxTask.single(() -> query.countInBackground());

}
 
Example 19
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable pin(@NonNull final R object) {
    return RxTask.completable(() -> object.pinInBackground());
}
 
Example 20
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable pin(@NonNull final List<R> objects) {
    return RxTask.completable(() -> ParseObject.pinAllInBackground(objects));
}
 
Example 21
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable pin(@NonNull final String name, @NonNull final R object) {
    return RxTask.completable(() -> object.pinInBackground(name));
}
 
Example 22
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable pin(@NonNull final String name, @NonNull final List<R> objects) {
    return RxTask.completable(() -> ParseObject.pinAllInBackground(name, objects));
}
 
Example 23
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable unpin(@NonNull final R object) {
    return RxTask.completable(() -> object.unpinInBackground());
}
 
Example 24
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable unpin(@NonNull final List<R> objects) {
    return RxTask.completable(() -> ParseObject.unpinAllInBackground(objects));
}
 
Example 25
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable unpin(@NonNull final String name, @NonNull final R object) {
    return RxTask.completable(() -> object.unpinInBackground(name));
}
 
Example 26
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public static <R extends ParseObject> Completable unpin(@NonNull final String name, @NonNull final List<R> objects) {
    return RxTask.completable(() -> ParseObject.unpinAllInBackground(name, objects));
}
 
Example 27
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Observable<R> all(@NonNull final ParseQuery<R> query) {
    return count(query).flatMapObservable(c -> all(query, c));
}
 
Example 28
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Single<R> first(@NonNull final ParseQuery<R> query) {
    return RxTask.single(() -> query.getFirstInBackground());
}
 
Example 29
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Single<R> get(@NonNull final Class<R> clazz, @NonNull final String objectId) {
    return get(ParseQuery.getQuery(clazz), objectId);
}
 
Example 30
Source Project: RxParse   Source File: ParseObservable.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@CheckReturnValue
public static <R extends ParseObject> Single<R> get(@NonNull final ParseQuery<R> query, @NonNull final String objectId) {
    return RxTask.single(() -> query.getInBackground(objectId));
}