@Override
  public Object internalRead(final Object obj1, final BInputJson bin) throws BException {
    final FindOptions obj =
        (FindOptions) (obj1 != null ? obj1 : bin.onObjectCreated(new FindOptions()));

    final BJsonObject js = bin.currentObject;
    obj.reserved = js.getString("reserved");

    return obj;
  }
示例#2
0
 @Override
 public Key<T> getKey(final FindOptions options) {
   final MorphiaIterator<T, Key<T>> it = fetchKeys(options.copy().limit(1));
   Key<T> key = (it.hasNext()) ? it.next() : null;
   it.close();
   return key;
 }
示例#3
0
 @Override
 public T get(final FindOptions options) {
   final MorphiaIterator<T, T> it = fetch(options.copy().limit(1));
   try {
     return (it.hasNext()) ? it.next() : null;
   } finally {
     it.close();
   }
 }
示例#4
0
  @Override
  public QueryImpl<T> cloneQuery() {
    final QueryImpl<T> n = new QueryImpl<T>(clazz, dbColl, ds);
    n.cache = ds.getMapper().createEntityCache(); // fresh cache
    n.includeFields = includeFields;
    n.setQuery(n); // feels weird, correct?
    n.validateName = validateName;
    n.validateType = validateType;
    n.baseQuery = copy(baseQuery);
    n.options = options != null ? options.copy() : null;

    // fields from superclass
    n.setAttachedTo(getAttachedTo());
    n.setChildren(getChildren() == null ? null : new ArrayList<Criteria>(getChildren()));
    return n;
  }
示例#5
0
  private DBCursor prepareCursor(final FindOptions findOptions) {
    final DBObject query = getQueryObject();

    if (LOG.isTraceEnabled()) {
      LOG.trace(
          String.format(
              "Running query(%s) : %s, options: %s,", dbColl.getName(), query, findOptions));
    }

    if (findOptions.isSnapshot()
        && (findOptions.getSortDBObject() != null || findOptions.hasHint())) {
      LOG.warning("Snapshotted query should not have hint/sort.");
    }

    if (findOptions.getCursorType() != NonTailable && (findOptions.getSortDBObject() != null)) {
      LOG.warning("Sorting on tail is not allowed.");
    }

    return dbColl
        .find(
            query,
            findOptions.getOptions().copy().sort(getSortObject()).projection(getFieldsObject()))
        .setDecoderFactory(ds.getDecoderFact());
  }
示例#6
0
 private int hash(final FindOptions options) {
   if (options == null) {
     return 0;
   }
   int result = options.getBatchSize();
   result = 31 * result + getLimit();
   result = 31 * result + (options.getModifiers() != null ? options.getModifiers().hashCode() : 0);
   result =
       31 * result + (options.getProjection() != null ? options.getProjection().hashCode() : 0);
   result =
       31 * result
           + (int) (options.getMaxTime(MILLISECONDS) ^ options.getMaxTime(MILLISECONDS) >>> 32);
   result =
       31 * result
           + (int)
               (options.getMaxAwaitTime(MILLISECONDS)
                   ^ options.getMaxAwaitTime(MILLISECONDS) >>> 32);
   result = 31 * result + options.getSkip();
   result =
       31 * result
           + (options.getSortDBObject() != null ? options.getSortDBObject().hashCode() : 0);
   result =
       31 * result + (options.getCursorType() != null ? options.getCursorType().hashCode() : 0);
   result = 31 * result + (options.isNoCursorTimeout() ? 1 : 0);
   result = 31 * result + (options.isOplogReplay() ? 1 : 0);
   result = 31 * result + (options.isPartial() ? 1 : 0);
   result =
       31 * result
           + (options.getReadPreference() != null ? options.getReadPreference().hashCode() : 0);
   result =
       31 * result + (options.getReadConcern() != null ? options.getReadConcern().hashCode() : 0);
   result = 31 * result + (options.getCollation() != null ? options.getCollation().hashCode() : 0);
   return result;
 }
示例#7
0
  private boolean compare(final FindOptions these, final FindOptions those) {
    if (these == null && those != null || these != null && those == null) {
      return false;
    }
    if (these == null) {
      return true;
    }

    DBCollectionFindOptions dbOptions = these.getOptions();
    DBCollectionFindOptions that = those.getOptions();

    if (dbOptions.getBatchSize() != that.getBatchSize()) {
      return false;
    }
    if (dbOptions.getLimit() != that.getLimit()) {
      return false;
    }
    if (dbOptions.getMaxTime(MILLISECONDS) != that.getMaxTime(MILLISECONDS)) {
      return false;
    }
    if (dbOptions.getMaxAwaitTime(MILLISECONDS) != that.getMaxAwaitTime(MILLISECONDS)) {
      return false;
    }
    if (dbOptions.getSkip() != that.getSkip()) {
      return false;
    }
    if (dbOptions.isNoCursorTimeout() != that.isNoCursorTimeout()) {
      return false;
    }
    if (dbOptions.isOplogReplay() != that.isOplogReplay()) {
      return false;
    }
    if (dbOptions.isPartial() != that.isPartial()) {
      return false;
    }
    if (dbOptions.getModifiers() != null
        ? !dbOptions.getModifiers().equals(that.getModifiers())
        : that.getModifiers() != null) {
      return false;
    }
    if (dbOptions.getProjection() != null
        ? !dbOptions.getProjection().equals(that.getProjection())
        : that.getProjection() != null) {
      return false;
    }
    if (dbOptions.getSort() != null
        ? !dbOptions.getSort().equals(that.getSort())
        : that.getSort() != null) {
      return false;
    }
    if (dbOptions.getCursorType() != that.getCursorType()) {
      return false;
    }
    if (dbOptions.getReadPreference() != null
        ? !dbOptions.getReadPreference().equals(that.getReadPreference())
        : that.getReadPreference() != null) {
      return false;
    }
    if (dbOptions.getReadConcern() != null
        ? !dbOptions.getReadConcern().equals(that.getReadConcern())
        : that.getReadConcern() != null) {
      return false;
    }
    return dbOptions.getCollation() != null
        ? dbOptions.getCollation().equals(that.getCollation())
        : that.getCollation() == null;
  }