@Override public DBCollection getCollection() { return ds.getCollection(entityClazz); }
/** * @param obj the value to search with * @return the DBCollection * @deprecated this is an internal method. no replacement is planned. */ @Deprecated public DBCollection getCollection(final Object obj) { if (obj == null) { return null; } return getCollection(obj instanceof Class ? (Class) obj : obj.getClass()); }
@Override public <T> Query<T> createQuery(final Class<T> clazz, final DBObject q) { return newQuery(clazz, getCollection(clazz), q); }
@Override public long getCount(final String collection) { return getCollection(collection).count(); }
@Override public <T> Query<T> queryByExample(final T ex) { return queryByExample(getCollection(ex), ex); }
/** * @param source the initial type/collection to aggregate against * @return a new query bound to the kind (a specific {@link DBCollection}) */ @Override public AggregationPipeline createAggregation(final Class source) { return new AggregationPipelineImpl(this, getCollection(source), source); }
@Override public <T> Iterable<Key<T>> insert(final Iterable<T> entities, final InsertOptions options) { Iterator<T> iterator = entities.iterator(); return !iterator.hasNext() ? Collections.<Key<T>>emptyList() : insert(getCollection(iterator.next()), entities, options); }
@Override public <T> Query<T> createQuery(final Class<T> collection) { return newQuery(collection, getCollection(collection)); }
@Override public <T> Query<T> createQuery(final String collection, final Class<T> type, final DBObject q) { return newQuery(type, getCollection(collection), q); }
@Override public <T> Key<T> insert(final T entity, final InsertOptions options) { final T unwrapped = ProxyHelper.unwrap(entity); return insert(getCollection(unwrapped), unwrapped, options); }
@Override public <U> Iterator<U> aggregate(final Class<U> target, final AggregationOptions options, final ReadPreference readPreference) { return aggregate(datastore.getCollection(target).getName(), target, options, readPreference); }
@Override public <U> Iterator<U> out(final Class<U> target) { return out(datastore.getCollection(target).getName(), target); }
@Override public <U> Iterator<U> out(final Class<U> target, final AggregationOptions options) { return out(datastore.getCollection(target).getName(), target, options); }
@Override public <T> Key<T> save(final String collection, final T entity, final InsertOptions options) { return save(getCollection(collection), ProxyHelper.unwrap(entity), options); }
@Override public <T, V> DBRef createRef(final Class<T> clazz, final V id) { if (id == null) { throw new MappingException("Could not get id for " + clazz.getName()); } return new DBRef(getCollection(clazz).getName(), id); }
@Override public <T> Key<T> save(final T entity, final InsertOptions options) { if (entity == null) { throw new UpdateException("Can not persist a null entity"); } final T unwrapped = ProxyHelper.unwrap(entity); return save(getCollection(unwrapped), unwrapped, enforceWriteConcern(options, entity.getClass())); }
/** * Inserts an entity in to the database * * @param collection the collection to query against * @param entity the entity to insert * @param wc the WriteConcern to use when deleting * @param <T> the type of the entities * @return the key of entity */ public <T> Key<T> insert(final String collection, final T entity, final WriteConcern wc) { return insert(getCollection(collection), ProxyHelper.unwrap(entity), new InsertOptions().writeConcern(wc)); }
@Override public <T> Key<T> save(final String collection, final T entity, final WriteConcern wc) { return save(getCollection(collection), ProxyHelper.unwrap(entity), new InsertOptions().writeConcern(wc)); }
@Override public <T> Key<T> insert(final String collection, final T entity) { final T unwrapped = ProxyHelper.unwrap(entity); return insert(getCollection(collection), unwrapped, new InsertOptions() .writeConcern(getWriteConcern(unwrapped))); }
@Override public <T> WriteResult delete(final Query<T> query, final DeleteOptions options) { DBCollection dbColl = query.getCollection(); // TODO remove this after testing. if (dbColl == null) { dbColl = getCollection(query.getEntityClass()); } if (query.getSortObject() != null || query.getOffset() != 0 || query.getLimit() > 0) { throw new QueryException("Delete does not allow sort/offset/limit query options."); } return dbColl.remove(query.getQueryObject(), enforceWriteConcern(options, query.getEntityClass()).getOptions()); }