Java Code Examples for com.mongodb.DBCursor#batchSize()
The following examples show how to use
com.mongodb.DBCursor#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: StudentSectionEdgeImporter.java From secure-data-service with Apache License 2.0 | 6 votes |
@Override public void importCollection() { DBCursor cursor = mongo.getCollection("studentSectionAssociation").find(); cursor.batchSize(BATCH_SIZE); while (cursor.hasNext()) { DBObject spa = cursor.next(); @SuppressWarnings("unchecked") Map<String, Object> body = (Map<String, Object>) spa.get("body"); String studentId = (String) body.get("studentId"); String sectionId = (String) body.get("sectionId"); for (Vertex student : graph.getVertices("mongoid", studentId)) { for (Vertex section : graph.getVertices("mongoid", sectionId)) { Edge e = graph.addEdge(null, section, student, "studentSection"); e.setProperty("mongoid", spa.get("_id")); if (body.containsKey("endDate")) { e.setProperty("endDate", body.get("endDate")); } logger.log(Level.INFO, "Adding an edge between section: " + sectionId + " --> student: " + studentId); } } } }
Example 2
Source File: MongoDBQueryHelpers.java From hvdf with Apache License 2.0 | 5 votes |
public static void getSamplesFromCursor(DBCursor cursor, int limit, List<Sample> outList){ try{ // exhaust the cursor adding each sample cursor.batchSize(limit); cursor.limit(limit); while(cursor.hasNext()) { outList.add(new Sample(cursor.next())); } } finally { // ensure cursor is closed cursor.close(); } }
Example 3
Source File: EdOrgImporter.java From secure-data-service with Apache License 2.0 | 5 votes |
public void importEducationOrganizations(String type) { logger.log(Level.INFO, "Importing education organizations into graph: " + type); DBObject query = new BasicDBObject(); query.put("type", type); DBCursor cursor = mongo.getCollection(EDUCATION_ORGANIZATION).find(query); cursor.batchSize(BATCH_SIZE); while (cursor.hasNext()) { DBObject edOrg = cursor.next(); String currentEdOrgId = (String) edOrg.get("_id"); Vertex v = graph.addVertex(null); logger.log(Level.INFO, "Adding vertex for {0}#{1} \t {2}", new String[] { type, currentEdOrgId, v.getId().toString() }); v.setProperty("mongoid", currentEdOrgId); @SuppressWarnings("unchecked") Map<String, Object> body = (Map<String, Object>) edOrg.get("body"); if (body.containsKey("parentEducationAgencyReference")) { String parentId = (String) body.get("parentEducationAgencyReference"); for (Vertex child : graph.getVertices("mongoid", currentEdOrgId)) { for (Vertex parent : graph.getVertices("mongoid", parentId)) { graph.addEdge(null, parent, child, EDUCATION_ORGANIZATION_ASSOCIATION); logger.log(Level.INFO, "Adding an edge between ed org: " + parentId + " --> " + currentEdOrgId); } } } } }
Example 4
Source File: StudentSchoolEdgeImporter.java From secure-data-service with Apache License 2.0 | 5 votes |
/** * Imports student school associations (as edges) into the graph structure. */ @Override public void importCollection() { logger.log(Level.INFO, "Importing collection into graph: " + STUDENT_SCHOOL_ASSOCIATION); DBCursor cursor = mongo.getCollection(STUDENT_SCHOOL_ASSOCIATION).find(); cursor.batchSize(BATCH_SIZE); while (cursor.hasNext()) { DBObject association = cursor.next(); @SuppressWarnings("unchecked") Map<String, Object> body = (Map<String, Object>) association.get("body"); String studentId = (String) body.get("studentId"); String schoolId = (String) body.get("schoolId"); for (Vertex student : graph.getVertices("mongoid", studentId)) { for (Vertex school : graph.getVertices("mongoid", schoolId)) { Edge e = graph.addEdge(null, school, student, "studentSchoolAssociation"); e.setProperty("mongoid", association.get("_id")); if (body.containsKey("exitWithdrawDate")) { e.setProperty("exitWithdrawDate", body.get("exitWithdrawDate")); } logger.log(Level.INFO, "Adding an edge between school: " + schoolId + " --> student: " + studentId); } } } }