@SuppressWarnings({"unchecked"}) T[] convertFromDbObjects(DBObject... dbObjects) throws MongoException { T[] results = (T[]) new Object[dbObjects.length]; for (int i = 0; i < dbObjects.length; i++) { results[i] = convertFromDbObject(dbObjects[i]); } return results; }
List<T> convertFromDbObjects(DBObject... dbObjects) throws MongoException { final List<T> results = new ArrayList<T>(dbObjects.length); for (int i = 0; i < dbObjects.length; i++) { results.add(convertFromDbObject(dbObjects[i])); } return results; }
/** * Converts this cursor to an array. * * @param max the maximum number of objects to return * @return an array of objects * @throws MongoException If an error occurred */ public List<T> toArray(int max) throws MongoException { executed(); if (max > all.size()) { List<DBObject> objects = cursor.toArray(max); for (int i = all.size(); i < objects.size(); i++) { all.add(jacksonDBCollection.convertFromDbObject(objects.get(i))); } } return all; }
/** * Converts this cursor to an array. * * @param max the maximum number of objects to return * @return an array of objects * @throws MongoException If an error occurred */ public List<T> toArray(int max) throws MongoException { executed(); if (max > all.size()) { List<DBObject> objects = cursor.toArray(max); for (int i = all.size(); i < objects.size(); i++) { all.add(jacksonDBCollection.convertFromDbObject(objects.get(i))); } } return all; }
/** * Returns the object the cursor is at and moves the cursor ahead by one. * * @return the next element * @throws MongoException */ public T next() throws MongoException { executed(); current = jacksonDBCollection.convertFromDbObject(cursor.next()); return current; }
/** * Returns the object the cursor is at and moves the cursor ahead by one. * * @return the next element * @throws MongoException */ public T next() throws MongoException { executed(); current = jacksonDBCollection.convertFromDbObject(cursor.next()); return current; }
/** * Finds the first document in the query and updates it. * * @param query query to match * @param fields fields to be returned * @param sort sort to apply before picking first document * @param remove if true, document found will be removed * @param update update to apply * @param returnNew if true, the updated document is returned, otherwise the old document is returned (or it would be lost forever) * @param upsert do upsert (insert if document not present) * @return the object */ public T findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify(serializeFields(query), fields, sort, remove, update, returnNew, upsert)); }
/** * Finds the first document in the query and updates it. * * @param query query to match * @param fields fields to be returned * @param sort sort to apply before picking first document * @param remove if true, document found will be removed * @param update update to apply * @param returnNew if true, the updated document is returned, otherwise the old document is returned (or it would be lost forever) * @param upsert do upsert (insert if document not present) * @return the object */ public T findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBObject update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify(serializeFields(query), fields, sort, remove, update, returnNew, upsert)); }
/** * Finds the first document in the query and updates it. * * @param query query to match * @param fields fields to be returned * @param sort sort to apply before picking first document * @param remove if true, document found will be removed * @param update update to apply * @param returnNew if true, the updated document is returned, otherwise the old document is returned (or it would be lost forever) * @param upsert do upsert (insert if document not present) * @return the object */ public T findAndModify(DBObject query, DBObject fields, DBObject sort, boolean remove, DBUpdate.Builder update, boolean returnNew, boolean upsert) { return convertFromDbObject(dbCollection.findAndModify(serializeFields(query), fields, sort, remove, update.serialiseAndGet(objectMapper), returnNew, upsert)); }
MapReduceOutput(JacksonDBCollection<?, ?> sourceCollection, com.mongodb.MapReduceOutput output, Class<T> type, Class<K> keyType) { this.output = output; if (output.getOutputCollection() != null) { this.outputCollection = JacksonDBCollection.wrap(output.getOutputCollection(), type, keyType, sourceCollection.getObjectMapper()); this.resultSet = outputCollection.find(); } else { this.outputCollection = null; Collection<T> results = new ArrayList<T>(); for (DBObject result : output.results()) { results.add(sourceCollection.convertFromDbObject(result, type)); } this.resultSet = results; } }
MapReduceOutput(JacksonDBCollection<?, ?> sourceCollection, com.mongodb.MapReduceOutput output, Class<T> type, Class<K> keyType) { this.output = output; if (output.getOutputCollection() != null) { this.outputCollection = JacksonDBCollection.wrap(output.getOutputCollection(), type, keyType, sourceCollection.getObjectMapper()); this.resultSet = outputCollection.find(); } else { this.outputCollection = null; Collection<T> results = new ArrayList<T>(); for (DBObject result : output.results()) { results.add(sourceCollection.convertFromDbObject(result, type)); } this.resultSet = results; } }