예제 #1
0
 @Override
 public Query<T> project(final Meta meta) {
   final StringBuilder sb = new StringBuilder(meta.getField());
   validateQuery(clazz, ds.getMapper(), sb, FilterOperator.EQUAL, null, false, false);
   String fieldName = sb.toString();
   validateProjections(fieldName, true);
   project(meta.toDatabase());
   return this;
 }
예제 #2
0
 @Override
 public Query<T> project(final String field, final boolean include) {
   final StringBuilder sb = new StringBuilder(field);
   validateQuery(clazz, ds.getMapper(), sb, FilterOperator.EQUAL, null, validateName, false);
   String fieldName = sb.toString();
   validateProjections(fieldName, include);
   project(fieldName, include ? 1 : 0);
   return this;
 }
예제 #3
0
 @Override
 public Query<T> project(final String field, final ArraySlice slice) {
   final StringBuilder sb = new StringBuilder(field);
   validateQuery(clazz, ds.getMapper(), sb, FilterOperator.EQUAL, null, validateName, false);
   String fieldName = sb.toString();
   validateProjections(fieldName, true);
   project(fieldName, slice.toDatabase());
   return this;
 }
예제 #4
0
  @Override
  public MorphiaKeyIterator<T> fetchKeys(final FindOptions options) {
    QueryImpl<T> cloned = cloneQuery();
    cloned.getOptions().projection(new BasicDBObject(Mapper.ID_KEY, 1));
    cloned.includeFields = true;

    return new MorphiaKeyIterator<T>(
        ds, cloned.prepareCursor(options), ds.getMapper(), clazz, dbColl.getName());
  }
예제 #5
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);
  }
예제 #6
0
 @Override
 public Query<T> retrieveKnownFields() {
   final MappedClass mc = ds.getMapper().getMappedClass(clazz);
   final List<String> fields = new ArrayList<String>(mc.getPersistenceFields().size() + 1);
   for (final MappedField mf : mc.getPersistenceFields()) {
     fields.add(mf.getNameToStore());
   }
   retrievedFields(true, fields.toArray(new String[fields.size()]));
   return this;
 }
예제 #7
0
 @Override
 public Query<T> order(final Sort... sorts) {
   BasicDBObject sortList = new BasicDBObject();
   for (Sort sort : sorts) {
     String s = sort.getField();
     if (validateName) {
       final StringBuilder sb = new StringBuilder(s);
       validateQuery(clazz, ds.getMapper(), sb, FilterOperator.IN, "", true, false);
       s = sb.toString();
     }
     sortList.put(s, sort.getOrder());
   }
   getOptions().sort(sortList);
   return this;
 }
예제 #8
0
  @Override
  public Query<T> order(final Meta sort) {
    validateQuery(
        clazz,
        ds.getMapper(),
        new StringBuilder(sort.getField()),
        FilterOperator.IN,
        "",
        false,
        false);

    getOptions().sort(sort.toDatabase());

    return this;
  }
예제 #9
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;
  }
예제 #10
0
  @Override
  @Deprecated
  public DBObject getFieldsObject() {
    DBObject projection = getOptions().getProjection();
    if (projection == null || projection.keySet().size() == 0) {
      return null;
    }

    final MappedClass mc = ds.getMapper().getMappedClass(clazz);

    Entity entityAnnotation = mc.getEntityAnnotation();
    final BasicDBObject fieldsFilter = copy(projection);

    if (includeFields && entityAnnotation != null && !entityAnnotation.noClassnameStored()) {
      fieldsFilter.put(Mapper.CLASS_NAME_FIELDNAME, 1);
    }

    return fieldsFilter;
  }
예제 #11
0
 @Override
 public Query<T> order(final String sort) {
   getOptions().sort(parseFieldsString(sort, clazz, ds.getMapper(), validateName));
   return this;
 }
예제 #12
0
 public AggregationPipelineImpl(final DatastoreImpl datastore, final Class<T> source) {
   this.datastore = datastore;
   this.collection = datastore.getCollection(source);
   mapper = datastore.getMapper();
   this.source = source;
 }