コード例 #1
0
  /**
   * Retrieves the first object that matches a set of keys and values, when sorted with the
   * specified sort orderings.
   *
   * @param context The editing context to use
   * @param sortOrderings the sort orderings
   * @param keysAndValues a dictionary of keys and values to match
   * @return the first entity that was retrieved, or null if there was none
   */
  public static UserMessageSubscription firstObjectMatchingValues(
      EOEditingContext context,
      NSArray<EOSortOrdering> sortOrderings,
      NSDictionary<String, Object> keysAndValues) {
    @SuppressWarnings("unchecked")
    EOFetchSpecification fspec =
        new WCFetchSpecification(
            ENTITY_NAME, EOQualifier.qualifierToMatchAllValues(keysAndValues), sortOrderings);
    fspec.setFetchLimit(1);

    NSArray<UserMessageSubscription> objects = objectsWithFetchSpecification(context, fspec);

    if (objects.count() == 0) {
      return null;
    } else {
      return objects.objectAtIndex(0);
    }
  }
コード例 #2
0
 /**
  * Retrieve the count of objects using a dictionary of keys and values to match.
  *
  * @param context The editing context to use
  * @param keysAndValues a dictionary of keys and values to match
  * @return the count of objects that matched the specified values
  */
 public static int countOfObjectsMatchingValues(
     EOEditingContext context, NSDictionary<String, Object> keysAndValues) {
   return countOfObjectsMatchingQualifier(
       context, EOQualifier.qualifierToMatchAllValues(keysAndValues));
 }