private JacksonDBCollection<Bar, String> getJacksonDBCollection() { return JacksonDBCollection.wrap(BarServer.mongoDB.getCollection(Bar.class.getSimpleName().toLowerCase()), Bar.class, String.class); }
/** * Finds a collection that is prefixed with this collection's name. * A typical use of this might be * <blockquote><pre> * DBCollection users = mongo.getCollection( "wiki" ).getCollection( "users" ); * </pre></blockquote> * Which is equivalent to * <pre><blockquote> * DBCollection users = mongo.getCollection( "wiki.users" ); * </pre></blockquote> * * @param n the name of the collection to find * @param type The type of the collection * @return the matching collection */ public <S, L> JacksonDBCollection<S, L> getCollection(String n, Class<S> type, Class<L> keyType) { return wrap(getDB().getCollection(getName() + "." + n), type, keyType, objectMapper); }
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; } }
/** * Finds a collection that is prefixed with this collection's name. * A typical use of this might be * <blockquote><pre> * DBCollection users = mongo.getCollection( "wiki" ).getCollection( "users" ); * </pre></blockquote> * Which is equivalent to * <pre><blockquote> * DBCollection users = mongo.getCollection( "wiki.users" ); * </pre></blockquote> * * @param n the name of the collection to find * @param type The type of the collection * @return the matching collection */ public <S, L> JacksonDBCollection<S, L> getCollection(String n, Class<S> type, Class<L> keyType) { return wrap(getDB().getCollection(getName() + "." + n), type, keyType, objectMapper); }
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; } }
@Override public void run(Reader30Configuration configuration, Environment environment) throws Exception { Mongo mongo = new Mongo(configuration.mongohost, configuration.mongoport); DB db = mongo.getDB(configuration.mongodb); JacksonDBCollection<Blog, String> blogs = JacksonDBCollection.wrap(db.getCollection("blogs"), Blog.class, String.class); MongoManaged mongoManaged = new MongoManaged(mongo); environment.manage(mongoManaged); environment.addHealthCheck(new MongoHealthCheck(mongo)); environment.addResource(new BlogResource(blogs)); environment.addResource(new IndexResource(blogs)); }