Java Code Examples for com.mongodb.client.FindIterable#batchSize()
The following examples show how to use
com.mongodb.client.FindIterable#batchSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoSession.java From presto with Apache License 2.0 | 5 votes |
public MongoCursor<Document> execute(MongoTableHandle tableHandle, List<MongoColumnHandle> columns) { Document output = new Document(); for (MongoColumnHandle column : columns) { output.append(column.getName(), 1); } MongoCollection<Document> collection = getCollection(tableHandle.getSchemaTableName()); FindIterable<Document> iterable = collection.find(buildQuery(tableHandle.getConstraint())).projection(output); if (cursorBatchSize != 0) { iterable.batchSize(cursorBatchSize); } return iterable.iterator(); }
Example 2
Source File: FindOptions.java From morphia with Apache License 2.0 | 5 votes |
/** * @param iterable the iterable to use * @param mapper the mapper to use * @param type the result type * @param <T> the result type * @return the iterable instance for the query results * @morphia.internal */ public <T> FindIterable<T> apply(final FindIterable<T> iterable, final Mapper mapper, final Class<?> type) { if (projection != null) { iterable.projection(projection.map(mapper, type)); } iterable.batchSize(batchSize); iterable.collation(collation); iterable.comment(comment); if (cursorType != null) { iterable.cursorType(cursorType); } iterable.hint(hint); iterable.hintString(hintString); iterable.limit(limit); iterable.max(max); iterable.maxAwaitTime(maxAwaitTimeMS, TimeUnit.MILLISECONDS); iterable.maxTime(maxTimeMS, TimeUnit.MILLISECONDS); iterable.min(min); iterable.noCursorTimeout(noCursorTimeout); iterable.oplogReplay(oplogReplay); iterable.partial(partial); iterable.returnKey(returnKey); iterable.showRecordId(showRecordId); iterable.skip(skip); if (sort != null) { Document mapped = new Document(); MappedClass mappedClass = mapper.getMappedClass(type); for (final Entry<String, Object> entry : sort.entrySet()) { Object value = entry.getValue(); boolean metaScore = value instanceof Document && ((Document) value).get("$meta") != null; mapped.put(new PathTarget(mapper, mappedClass, entry.getKey(), !metaScore).translatedPath(), value); } iterable.sort(mapped); } return iterable; }
Example 3
Source File: GetMongo.java From localization_nifi with Apache License 2.0 | 4 votes |
@Override public void onTrigger(final ProcessContext context, final ProcessSession session) throws ProcessException { final ComponentLog logger = getLogger(); final Document query = context.getProperty(QUERY).isSet() ? Document.parse(context.getProperty(QUERY).getValue()) : null; final Document projection = context.getProperty(PROJECTION).isSet() ? Document.parse(context.getProperty(PROJECTION).getValue()) : null; final Document sort = context.getProperty(SORT).isSet() ? Document.parse(context.getProperty(SORT).getValue()) : null; final MongoCollection<Document> collection = getCollection(context); try { final FindIterable<Document> it = query != null ? collection.find(query) : collection.find(); if (projection != null) { it.projection(projection); } if (sort != null) { it.sort(sort); } if (context.getProperty(LIMIT).isSet()) { it.limit(context.getProperty(LIMIT).asInteger()); } if (context.getProperty(BATCH_SIZE).isSet()) { it.batchSize(context.getProperty(BATCH_SIZE).asInteger()); } final MongoCursor<Document> cursor = it.iterator(); try { FlowFile flowFile = null; while (cursor.hasNext()) { flowFile = session.create(); flowFile = session.write(flowFile, new OutputStreamCallback() { @Override public void process(OutputStream out) throws IOException { IOUtils.write(cursor.next().toJson(), out); } }); session.getProvenanceReporter().receive(flowFile, context.getProperty(URI).getValue()); session.transfer(flowFile, REL_SUCCESS); } session.commit(); } finally { cursor.close(); } } catch (final RuntimeException e) { context.yield(); session.rollback(); logger.error("Failed to execute query {} due to {}", new Object[] { query, e }, e); } }
Example 4
Source File: MDbOperation.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Applies data set query properties and hints on DBCursor, except * for cursor limit. * @see #applyPropertiesToCursor(DBCursor,QueryProperties,boolean,boolean) */ static void applyPropertiesToCursor( MongoIterable<Document> mongoIterable, QueryProperties queryProps, boolean includeSortExpr ) { BasicDBObject sortExprObj = null; if( includeSortExpr ) // normally done only when executing a query to get full result set { try { sortExprObj = queryProps.getSortExprAsParsedObject(); } catch( OdaException ex ) { // log warning and ignore DriverUtil.getLogger().log( Level.WARNING, Messages.bind( "Unable to parse the user-defined Sort Expression: {0}", queryProps.getSortExpr() ), //$NON-NLS-1$ ex ); } } // Map it to correct iterable object FindIterable<Document> findIterable = null; AggregateIterable<Document> aggregateIterable = null; MapReduceIterable<Document> mapReduceIterable = null; if ( mongoIterable instanceof FindIterable ) { findIterable = (FindIterable<Document>) mongoIterable; } else if ( mongoIterable instanceof AggregateIterable ) { aggregateIterable = (AggregateIterable<Document>) mongoIterable; } else if ( mongoIterable instanceof MapReduceIterable ) { mapReduceIterable = (MapReduceIterable<Document>) mongoIterable; } if ( findIterable == null && aggregateIterable == null && mapReduceIterable == null ) { // Unknown type, return } if ( findIterable != null ) { if ( sortExprObj != null ) findIterable.sort( sortExprObj ); if ( queryProps.getBatchSize( ) > 0 ) findIterable.batchSize( queryProps.getBatchSize( ) ); if ( queryProps.getNumDocsToSkip( ) > 0 ) findIterable.skip( queryProps.getNumDocsToSkip( ) ); if ( queryProps.isPartialResultsOk( ) ) findIterable.partial( true ); // TODO: Remove hint from the UI // TODO: add Time out in the UI /* * // hint is deprecated in 3.2 DBObject hintObj = * queryProps.getIndexHintsAsParsedObject(); String hintValue = * queryProps.getIndexHints(); if( hintObj != null ) * rowsCursor.hint( hintObj ); else // try to pass the hint string * value as is { String hintValue = queryProps.getIndexHints(); if( * ! hintValue.isEmpty() ) rowsCursor.hint( hintValue ); } * findIterable.maxTime(Bytes.QUERYOPTION_NOTIMEOUT, arg1) if( * queryProps.hasNoTimeOut() ) rowsCursor.addOption( * Bytes.QUERYOPTION_NOTIMEOUT ); */ } if ( aggregateIterable != null ) { if ( queryProps.getBatchSize( ) > 0 ) aggregateIterable.batchSize( queryProps.getBatchSize( ) ); } if ( mapReduceIterable != null ) { if ( sortExprObj != null ) mapReduceIterable.sort( sortExprObj ); if ( queryProps.getBatchSize( ) > 0 ) mapReduceIterable.batchSize( queryProps.getBatchSize( ) ); } }