Tabnine Logo
AVQuery
Code IndexAdd Tabnine to your IDE (free)

How to use
AVQuery
in
com.avos.avoscloud

Best Java code snippets using com.avos.avoscloud.AVQuery (Showing top 20 results out of 315)

origin: BaaSBeginner/leanchat-android

public void findAddRequests(int skip, int limit, FindCallback findCallback) {
 LeanchatUser user = LeanchatUser.getCurrentUser();
 AVQuery<AddRequest> q = AVObject.getQuery(AddRequest.class);
 q.include(AddRequest.FROM_USER);
 q.skip(skip);
 q.limit(limit);
 q.whereEqualTo(AddRequest.TO_USER, user);
 q.orderByDescending(AVObject.CREATED_AT);
 q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
 q.findInBackground(findCallback);
}
origin: cn.leancloud.android/avoscloud-sdk

public void getRolesInBackground(final AVCallback<List<AVRole>> callback) {
 AVQuery<AVRole> roleQuery = new AVQuery<AVRole>(AVRole.className);
 roleQuery.whereEqualTo(AVUSER_ENDPOINT, this);
 roleQuery.findInBackground(new FindCallback<AVRole>() {
  @Override
  public void done(List<AVRole> list, AVException e) {
   callback.internalDone(list, e);
  }
 });
}
origin: xia-weiyang/MainScreenShow

/**
 * 从服务器查看是否需要下载图片
 *
 * @param callBack
 */
public void isDownloadImage(final IsDownloadCallBack callBack) {
  AVQuery<AVObject> query = new AVQuery<AVObject>(CLASS_NAME);
  query.orderByDescending(ID);
  query.setLimit(1);
  query.findInBackground(new FindCallback<AVObject>() {
    @Override
    public void done(List<AVObject> list, AVException e) {
      if (null == e) {
        if (list.size() == 1) {
          if (sp.getInt("image", -1) < list.get(0).getInt(ID)) {
            callBack.done(true, list.get(0));
          } else {
            callBack.done(false, null);
          }
        } else
          callBack.done(false, null);
      } else
        callBack.done(false, null);
    }
  });
}
origin: cn.leancloud.android/avoscloud-sdk

@JSONField(serialize = false)
public List<AVRole> getRoles() throws AVException {
 AVQuery<AVRole> roleQuery = new AVQuery<AVRole>(AVRole.className);
 roleQuery.whereEqualTo(AVUser.AVUSER_ENDPOINT, this);
 return roleQuery.find();
}
origin: cn.leancloud.android/avoscloud-sdk

/**
 * Create a query that can be used to query the parent objects in this relation.
 * 
 * @param parentClassName The parent class name
 * @param relationKey The relation field key in parent
 * @param child The child object.
 * @return A AVQuery that restricts the results to parent objects in this relations.
 */
public static <M extends AVObject> AVQuery<M> reverseQuery(String parentClassName,
  String relationKey, AVObject child) {
 AVQuery<M> query = new AVQuery<M>(parentClassName);
 query.whereEqualTo(relationKey, AVUtils.mapFromPointerObject(child));
 return query;
}
origin: cn.leancloud/leancloud-common

/**
 * Constructs a query. A default query with no further parameters will retrieve all AVObjects of
 * the provided class.
 *
 * @param theClassName The name of the class to retrieve AVObjects for.
 * @return the query object.
 */
public static <T extends AVObject> AVQuery<T> getQuery(String theClassName) {
 return new AVQuery<T>(theClassName);
}
origin: WuXiaolong/WoChat

q.whereContainedIn(AppConstant.OBJECT_ID, uncachedIds);
q.setLimit(1000);
q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
q.findInBackground(new FindCallback<LeanchatUser>() {
 @Override
 public void done(List<LeanchatUser> list, AVException e) {
origin: BaaSBeginner/leanchat-android

private void loadMoreFriend(int skip, final int limit, final boolean isRefresh) {
 AVQuery<LeanchatUser> q = LeanchatUser.getQuery(LeanchatUser.class);
 q.whereContains(LeanchatUser.USERNAME, searchName);
 q.limit(Constants.PAGE_SIZE);
 q.skip(skip);
 LeanchatUser user = LeanchatUser.getCurrentUser();
 List<String> friendIds = new ArrayList<String>(FriendsManager.getFriendIds());
 friendIds.add(user.getObjectId());
 q.whereNotContainedIn(Constants.OBJECT_ID, friendIds);
 q.orderByDescending(Constants.UPDATED_AT);
 q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
 q.findInBackground(new FindCallback<LeanchatUser>() {
  @Override
  public void done(List<LeanchatUser> list, AVException e) {
   UserCacheUtils.cacheUsers(list);
   recyclerView.setLoadComplete(null == list ? null : list.toArray(), false);
   if (null != e) {
    showToast(e.getMessage());
   }
  }
 });
}
origin: cn.leancloud/leancloud-common

public static <T extends AVObject> AVQuery<T> and(List<AVQuery<T>> queries) {
 String className = null;
 if (queries.size() > 0) {
  className = queries.get(0).getClassName();
 }
 AVQuery<T> result = new AVQuery<T>(className);
 if (queries.size() > 1) {
  for (AVQuery<T> query : queries) {
   if (!className.equals(query.getClassName())) {
    throw new IllegalArgumentException("All queries must be for the same class");
   }
   result.addAndItems(query);
  }
 } else {
  result.setWhere(queries.get(0).conditions.getWhere());
 }
 return result;
}
origin: cn.leancloud.android/avoscloud-sdk

/**
 * Constructs a query that is the or of the given queries.
 *
 * @param queries The list of AVQueries to 'or' together
 * @return A AVQuery that is the 'or' of the passed in queries
 */
public static <T extends AVObject> AVQuery<T> or(List<AVQuery<T>> queries) {
 String className = null;
 if (queries.size() > 0) {
  className = queries.get(0).getClassName();
 }
 AVQuery<T> result = new AVQuery<T>(className);
 if (queries.size() > 1) {
  for (AVQuery<T> query : queries) {
   if (!className.equals(query.getClassName())) {
    throw new IllegalArgumentException("All queries must be for the same class");
   }
   result.addOrItems(new QueryOperation("$or", "$or", query.conditions
     .compileWhereOperationMap()));
  }
 } else {
  result.setWhere(queries.get(0).conditions.getWhere());
 }
 return result;
}
origin: cn.leancloud.android/avoscloud-push

 pushQuery.whereNotContainedIn(deviceTypeTag, DEVICE_TYPES);
} else if (pushTarget.size() == 1) {
 pushQuery.whereEqualTo(deviceTypeTag, pushTarget.toArray()[0]);
Map<String, String> pushParameters = pushQuery.assembleParameters();
if (pushParameters.keySet().size() > 0 && !AVUtils.isBlankString(cql)) {
 throw new IllegalStateException("You can't use AVQuery and Cloud query at the same time.");
origin: cn.leancloud.android/avoscloud-sdk

private void getFirstInBackground(boolean sync, GetCallback<T> callback) {
 this.assembleParameters();
 Map<String, String> parameters = getParameters();
 parameters.put("limit", Integer.toString(1));
 PaasClient.storageInstance().getObject(queryPath(), new AVRequestParams(parameters), sync,
   null, new GenericObjectCallback() {
    @Override
origin: xia-weiyang/MainScreenShow

AVQuery<AVObject> query = new AVQuery<AVObject>(CLASS_NAME);
query.orderByDescending(VERSION_NAME);
query.whereGreaterThan(VERSION_NAME, getVersionName());
query.findInBackground(new FindCallback<AVObject>() {
origin: WuXiaolong/WoChat

  public static void queryUser(String username, FindCallback<LeanchatUser> findCallback) {
    final long a = System.currentTimeMillis();
//        AVQuery<LeanchatUser> query = new AVQuery<>("_User");
    AVQuery<LeanchatUser> query = AVObject.getQuery(LeanchatUser.class);
    query.whereEqualTo(LeanchatUser.USERNAME, username);
    query.findInBackground(findCallback);
  }

origin: BaaSBeginner/leanchat-android

q.whereNotEqualTo(Constants.OBJECT_ID, user.getObjectId());
if (orderType == Constants.ORDER_DISTANCE) {
 q.whereNear(LeanchatUser.LOCATION, geoPoint);
} else {
 q.orderByDescending(Constants.UPDATED_AT);
q.skip(skip);
q.limit(limit);
q.setCachePolicy(AVQuery.CachePolicy.NETWORK_ELSE_CACHE);
q.findInBackground(new FindCallback<LeanchatUser>() {
 @Override
 public void done(List<LeanchatUser> list, AVException e) {
origin: xia-weiyang/MainScreenShow

private void loadAppInfo() {
  if (AVOSCloud.applicationContext == null) return;
  AVQuery<AVObject> avQuery = new AVQuery<>("App");
  avQuery.findInBackground(new FindCallback<AVObject>() {
    @Override
    public void done(final List<AVObject> list, AVException e) {
      if (list != null && list.size() == 1) {
        final AVObject avObject = list.get(0);
        new AlertDialog.Builder(MSS.this)
            .setMessage(avObject.getString("text"))
            .setPositiveButton("去围观", new OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog, int which) {
                String url = avObject.getString("url");
                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse(url);
                intent.setData(content_url);
                startActivity(intent);
              }
            }).show();
      }
    }
  });
}
origin: BaaSBeginner/leanchat-android

private UpdateInfo getNewestUpdateInfo() throws AVException {
 AVQuery<UpdateInfo> query = AVObject.getQuery(UpdateInfo.class);
 query.setLimit(1);
 query.orderByDescending(UpdateInfo.VERSION);
 if (policy != null) {
  query.setCachePolicy(policy);
 }
 List<UpdateInfo> updateInfos = query.find();
 if (updateInfos.size() > 0) {
  return updateInfos.get(0);
 }
 return null;
}
origin: cn.leancloud.android/avoscloud-sdk

private String queryPath() {
 if (!AVUtils.isBlankString(externalQueryPath)) {
  return externalQueryPath;
 }
 return AVPowerfulUtils.getEndpoint(getClassName());
}
origin: BaaSBeginner/leanchat-android

/**
 * 从 server 获取未读消息的数量
 */
public void countUnreadRequests(final CountCallback countCallback) {
 AVQuery<AddRequest> addRequestAVQuery = AVObject.getQuery(AddRequest.class);
 addRequestAVQuery.setCachePolicy(AVQuery.CachePolicy.NETWORK_ONLY);
 addRequestAVQuery.whereEqualTo(AddRequest.TO_USER, LeanchatUser.getCurrentUser());
 addRequestAVQuery.whereEqualTo(AddRequest.IS_READ, false);
 addRequestAVQuery.countInBackground(new CountCallback() {
  @Override
  public void done(int i, AVException e) {
   if (null != countCallback) {
    unreadAddRequestsCount = i;
    countCallback.done(i, e);
   }
  }
 });
}
origin: BaaSBeginner/leanchat-android

 public void findFriendsWithCachePolicy(AVQuery.CachePolicy cachePolicy, FindCallback<LeanchatUser>
   findCallback) {
  AVQuery<LeanchatUser> q = null;
  try {
   q = followeeQuery(LeanchatUser.class);
  } catch (Exception e) {
  }
  q.setCachePolicy(cachePolicy);
  q.setMaxCacheAge(TimeUnit.MINUTES.toMillis(1));
  q.findInBackground(findCallback);
 }
}
com.avos.avoscloudAVQuery

Javadoc

The AVQuery class defines a query that is used to fetch AVObjects. The most common use case is finding all objects that match a query through the findInBackground method, using a FindCallback. For example, this sample code fetches all objects of class "MyClass". It calls a different function depending on whether the fetch succeeded or not.

 
AVQuery query = AVQuery.getQuery("MyClass"); 
query.findInBackground(new FindCallback() { 
public void done(List objects, AVException e) { 
if (e == null) { 
objectsWereRetrievedSuccessfully(objects); 
} else { 
objectRetrievalFailed(); 
} 
} 
} 

A AVQuery can also be used to retrieve a single object whose id is known, through the getInBackground method, using a GetCallback. For example, this sample code fetches an object of class "MyClass" and id myId. It calls a different function depending on whether the fetch succeeded or not.

 
AVQuery query = AVQuery.getQuery("MyClass"); 
query.getInBackground(myId, new GetCallback() { 
public void done(AVObject object, AVException e) { 
if (e == null) { 
objectWasRetrievedSuccessfully(object); 
} else { 
objectRetrievalFailed(); 
} 
} 
} 

A AVQuery can also be used to count the number of objects that match the query without retrieving all of those objects. For example, this sample code counts the number of objects of the class "MyClass".

 
AVQuery query = AVQuery.getQuery("MyClass"); 
query.countInBackground(new CountCallback() { 
public void done(int count, AVException e) { 
if (e == null) { 
objectsWereCounted(count); 
} else { 
objectCountFailed(); 
} 
} 
} 

Using the callback methods is usually preferred because the network operation will not block the calling thread. However, in some cases it may be easier to use the find, get or count calls, which do block the calling thread. For example, if your application has already spawned a background task to perform work, that background task could use the blocking calls and avoid the code complexity of callbacks.

Most used methods

  • whereEqualTo
    Add a constraint to the query that requires a particular key's value to be equal to the provided val
  • <init>
  • findInBackground
    Retrieves a list of AVObjects that satisfy this query from the server in a background thread. This i
  • setLimit
    Controls the maximum number of results that are returned. Setting a negative limit denotes retrieval
  • assembleParameters
  • getClassName
    Accessor for the class name.
  • countInBackground
  • doCloudQueryInBackground
    通过cql查询对象
  • find
    Retrieves a list of AVObjects that satisfy this query. Uses the network and/or the cache, depending
  • whereNotContainedIn
    Add a constraint to the query that requires a particular key's value not be contained in the provide
  • addAndItems
  • addOrItems
  • addAndItems,
  • addOrItems,
  • addWhereItem,
  • doCloudQuery,
  • generateQueryPath,
  • get,
  • getFirstInBackground,
  • getInBackground,
  • getInclude,
  • getLimit

Popular in Java

  • Reactive rest calls using spring rest template
  • scheduleAtFixedRate (ScheduledExecutorService)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • getSystemService (Context)
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • TreeSet (java.util)
    TreeSet is an implementation of SortedSet. All optional operations (adding and removing) are support
  • ExecutorService (java.util.concurrent)
    An Executor that provides methods to manage termination and methods that can produce a Future for tr
  • ImageIO (javax.imageio)
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • LoggerFactory (org.slf4j)
    The LoggerFactory is a utility class producing Loggers for various logging APIs, most notably for lo
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now