Example #1
0
 public static NSArray fetchAll(
     EOEditingContext editingContext,
     EOQualifier qualifier,
     NSArray sortOrderings,
     boolean distinct,
     int fetchLimit,
     DTEOEditingContextHandler handler) {
   EOFetchSpecification fetchSpec =
       new EOFetchSpecification(ENTITY_NAME, qualifier, sortOrderings);
   fetchSpec.setIsDeep(true);
   fetchSpec.setUsesDistinct(distinct);
   fetchSpec.setFetchLimit(fetchLimit);
   if (handler != null) {
     fetchSpec.setPromptsAfterFetchLimit(true);
     editingContext.setMessageHandler(handler);
   }
   return (NSArray) editingContext.objectsWithFetchSpecification(fetchSpec);
 }
  /**
   * 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);
    }
  }