Java Code Examples for com.avos.avoscloud.AVQuery#count()

The following examples show how to use com.avos.avoscloud.AVQuery#count() . 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: AddRequestService.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static int countAddRequests() throws AVException {
	AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
	q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
	q.whereEqualTo(AddRequest.TO_USER, AVUser.getCurrentUser());
	try {
		return q.count();
	} catch (AVException e) {
		if (e.getCode() == AVException.CACHE_MISS) {
			return 0;
		} else {
			throw e;
		}
	}
}
 
Example 2
Source File: AddRequestService.java    From LoveTalkClient with Apache License 2.0 5 votes vote down vote up
public static void createAddRequest(AVUser toUser) throws Exception {
	AVUser curUser = AVUser.getCurrentUser();
	AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
	q.whereEqualTo(AddRequest.FROM_USER, curUser);
	q.whereEqualTo(AddRequest.TO_USER, toUser);
	q.whereEqualTo(AddRequest.STATUS, AddRequest.STATUS_WAIT);
	int count = 0;
	try {
		count = q.count();
	} catch (AVException e) {
		e.printStackTrace();
		if (e.getCode() == AVException.OBJECT_NOT_FOUND) {
			count = 0;
		} else {
			throw e;
		}
	}
	if (count > 0) {
		throw new Exception(DemoApplication.context.getString(R.string.contact_alreadyCreateAddRequest));
	} else {
		AddRequest add = new AddRequest();
		add.setFromUser(curUser);
		add.setToUser(toUser);
		add.setStatus(AddRequest.STATUS_WAIT);
		add.save();
	}
}