Exemplo n.º 1
0
  @Override
  public List<T> asList(final FindOptions options) {
    final List<T> results = new ArrayList<T>();
    final MorphiaIterator<T, T> iter = fetch(options);
    try {
      for (final T ent : iter) {
        results.add(ent);
      }
    } finally {
      iter.close();
    }

    if (LOG.isTraceEnabled()) {
      LOG.trace(
          format(
              "asList: %s \t %d entities, iterator time: driver %d ms, mapper %d ms %n\t cache: %s %n\t for %s",
              dbColl.getName(),
              results.size(),
              iter.getDriverTime(),
              iter.getMapperTime(),
              cache.stats(),
              getQueryObject()));
    }

    return results;
  }
Exemplo n.º 2
0
  @Override
  public MorphiaIterator<T, T> fetch(final FindOptions options) {
    final DBCursor cursor = prepareCursor(options);
    if (LOG.isTraceEnabled()) {
      LOG.trace("Getting cursor(" + dbColl.getName() + ")  for query:" + cursor.getQuery());
    }

    return new MorphiaIterator<T, T>(ds, cursor, ds.getMapper(), clazz, dbColl.getName(), cache);
  }
Exemplo n.º 3
0
 @Override
 @Deprecated
 public long countAll() {
   final DBObject query = getQueryObject();
   if (LOG.isTraceEnabled()) {
     LOG.trace("Executing count(" + dbColl.getName() + ") for query: " + query);
   }
   return dbColl.getCount(query);
 }
Exemplo n.º 4
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());
  }