List of usage examples for com.mongodb DBCursor curr
public DBObject curr()
From source file:exifIndexer.MetadataQueries.java
public ResultDataNormal shutterSpeed(String s) { //Consulta Shutter Speed ArrayList<String> paths = new ArrayList<>(); ArrayList<String> names = new ArrayList<>(); MongoHandler dbmon = new MongoHandler(); DB dbmongo = dbmon.connect();//from w w w .ja v a 2s. c om DBCursor cursorDoc; DBCollection collection = dbmongo.getCollection("Shutter_Speed"); BasicDBObject query = new BasicDBObject("SHUTTER_VALUE", s); cursorDoc = collection.find(query); try { while (cursorDoc.hasNext()) { System.out.println("algo encontrado"); paths.add((cursorDoc.next().get("IMG_PATH").toString())); names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION"))); } } finally { cursorDoc.close(); } return new ResultDataNormal(paths, names); }
From source file:exifIndexer.MetadataQueries.java
public ResultDataNormal DateCreated(String s) { //Consulta DateCreated ArrayList paths = new ArrayList<>(); ArrayList names = new ArrayList<>(); MongoHandler dbmon = new MongoHandler(); DB dbmongo = dbmon.connect();//from w w w . j a va 2s . c om DBCursor cursorDoc; DBCollection collection = dbmongo.getCollection("Date_created"); BasicDBObject query = new BasicDBObject("DATE_VALUE", s); cursorDoc = collection.find(query); if (isNull(cursorDoc)) { System.out.println("nulo"); } try { while (cursorDoc.hasNext()) { paths.add((cursorDoc.next().get("IMG_PATH"))); names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION"))); } } finally { cursorDoc.close(); } return new ResultDataNormal(paths, names); }
From source file:exifIndexer.MetadataQueries.java
public ResultDataWithGPS gps() { //Consulta gps ArrayList paths = new ArrayList<>(); ArrayList names = new ArrayList<>(); ArrayList latitudes = new ArrayList<>(); ArrayList longitudes = new ArrayList<>(); ArrayList latref = new ArrayList<>(); ArrayList lonref = new ArrayList<>(); MongoHandler dbmon = new MongoHandler(); DB dbmongo = dbmon.connect();/*w w w. ja v a 2s . c o m*/ DBCursor cursorDoc; Integer cont = 0; Integer pos = 0; ResultDataWithGPS res = null; DBCollection collection = dbmongo.getCollection("GPSFotos"); // BasicDBObject query = new BasicDBObject("GPS_VALUE",true); cursorDoc = collection.find(); try { while (cursorDoc.hasNext()) { pos = cont % 4; switch (pos) { case 0: //GPS_VALUE latitudes.add((cursorDoc.next().get("GPS_VALUE"))); break; case 1: latref.add((cursorDoc.next().get("GPS_VALUE"))); break; case 2: longitudes.add((cursorDoc.next().get("GPS_VALUE"))); break; case 3: lonref.add((cursorDoc.next().get("GPS_VALUE"))); break; } if ((cont != 0) && (pos == 0)) { paths.add((cursorDoc.curr().get("IMG_PATH"))); names.add((cursorDoc.curr().get("IMG_NAME")) + "." + (cursorDoc.curr().get("EXTENSION"))); } cont++; } res = new ResultDataWithGPS(paths, names, latitudes, longitudes, latref, lonref); } finally { cursorDoc.close(); } return res; }
From source file:implementations.mongoDB.java
License:GNU General Public License
@Override public int updateDB(String ID, String newValue) { int ret;/* w ww. j av a2 s . c om*/ try { db.requestStart(); BasicDBObject query = new BasicDBObject(); query.put("_id", ID); DBCursor cur = dbCol.find(query); cur.next(); BasicDBObject doc = new BasicDBObject(); doc.put("_id", ID); doc.put("artValue", newValue); dbCol.update(cur.curr(), doc); db.requestDone(); ret = 1; } catch (Exception e) { e.printStackTrace(); System.out.println("ID = " + ID + " ==============================="); ret = -1; } return ret; }
From source file:models.datasource.SingletonDataSource.java
public static List<User> findAll() { DBCollection collection = connectDB("mongo.usersCollection"); DBCursor cursor = collection.find(); List<User> users = new ArrayList<>(); try {/*from w w w . jav a 2s . c o m*/ while (cursor.hasNext()) { User user = new User(); String userStr = cursor.next().toString(); //Get user object from JSON user = new Gson().fromJson(userStr, User.class); // Deserialize Current Situation object user.currentSituation = new Gson().fromJson( cursor.curr().get(Constants.USER_CURRENT_SITUATION).toString(), CurrentSituation.class); // Deserialize ArrayList of Skills user.skill = new Gson().fromJson(cursor.curr().get(Constants.USER_SKILLS_LIST).toString(), new TypeToken<List<Skill>>() { }.getType()); //Add to USER the completedOrientationSteps object stored in JSON user.completedOrientationSteps = new Gson().fromJson( cursor.curr().get(Constants.USER_ORIENTATION_STEPS).toString(), User.CompletedOrientationSteps.class); // Deserialize ArrayList of InterviewSchedule Objects user.interviewScheduleList = new Gson().fromJson( cursor.curr().get(Constants.USER_NEXT_INTERVIEWS_LIST).toString(), new TypeToken<List<InterviewSchedule>>() { }.getType()); // Deserialize ArrayList of Courses user.courses = new Gson().fromJson(cursor.curr().get(Constants.USER_COURSES).toString(), new TypeToken<List<Course>>() { }.getType()); //Deserialize ArrayList of Languages user.languages = new Gson().fromJson(cursor.curr().get(Constants.USER_LANGUAGES).toString(), new TypeToken<List<Language>>() { }.getType()); //Deserialize ArrayList of Software user.softwareList = new Gson().fromJson(cursor.curr().get(Constants.USER_SOFTWARE).toString(), new TypeToken<List<Software>>() { }.getType()); user.id = cursor.curr().get("_id").toString(); users.add(user); } } finally { cursor.close(); } mongoClient.close(); return users; }
From source file:poke.resources.NameSpaceResource.java
License:Apache License
@Override public Request process(Request request) throws FileNotFoundException, IOException { // TODO Auto-generated method stub Request reply = buildMessage(request, PokeStatus.NOFOUND, "Request not fulfilled", request.getBody().getSpaceOp().getAction()); MongoDBDAO mclient = new MongoDBDAO(); try {//from w ww .j av a2s . c o m mclient.getDBConnection(); mclient.getDB(mclient.getDbName()); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } //If Request is for User CRUD operations if (request.getBody().getSpaceOp().hasUId()) { mclient.getCollection("usercollection"); User user = new User(); user.setUserId(request.getBody().getSpaceOp().getUId().getUserId()); user.setName(request.getBody().getSpaceOp().getUId().getUserName()); user.setPassword(request.getBody().getSpaceOp().getUId().getPassword()); user.setCity(request.getBody().getSpaceOp().getUId().getCity()); user.setZipCode(request.getBody().getSpaceOp().getUId().getZipcode()); switch (request.getBody().getSpaceOp().getAction()) { case ADDSPACE: BasicDBObject doc = new BasicDBObject("userid", user.getUserId()).append("username", user.getName()) .append("password", user.getPassword()).append("city", user.getCity()) .append("zipcode", user.getZipCode()); mclient.insertData(doc); reply = buildMessage(request, PokeStatus.SUCCESS, "User added to database", SpaceAction.ADDSPACE); break; case LISTSPACES: int authenticated = 400; BasicDBObject query1 = new BasicDBObject(); List<BasicDBObject> query1List = new ArrayList<BasicDBObject>(); query1List.add(new BasicDBObject("username", user.getName())); query1List.add(new BasicDBObject("password", user.getPassword())); query1.put("$and", query1List); DBCursor cursor = mclient.findData(query1); while (cursor.hasNext()) { cursor.next(); authenticated = 200; } if (authenticated == 200) reply = buildMessage(request, PokeStatus.SUCCESS, "User login successful", SpaceAction.LISTSPACES); else reply = buildMessage(request, PokeStatus.FAILURE, "User login failed!", SpaceAction.LISTSPACES); break; case REMOVESPACE: BasicDBObject rem = new BasicDBObject("userid", user.getUserId()); mclient.deleteData(rem); reply = buildMessage(request, PokeStatus.SUCCESS, "User deleted", SpaceAction.REMOVESPACE); break; case UPDATESPACE: BasicDBObject que = new BasicDBObject("userid", user.getUserId()); BasicDBObject upd = new BasicDBObject("userid", user.getUserId()).append("username", user.getName()) .append("password", user.getPassword()).append("city", user.getCity()) .append("zipcode", user.getZipCode()); mclient.updateData(que, upd); reply = buildMessage(request, PokeStatus.SUCCESS, "User updated", SpaceAction.UPDATESPACE); break; default: break; } } //If Request is for Course CRUD operations else if (request.getBody().getSpaceOp().hasCId()) { mclient.getCollection("coursecollection"); Course course = new Course(); course.setCourseId(request.getBody().getSpaceOp().getCId().getCourseId()); course.setCourseName(request.getBody().getSpaceOp().getCId().getCourseName()); course.setCourseDescription(request.getBody().getSpaceOp().getCId().getCourseDescription()); course.setAddCode(request.getBody().getSpaceOp().getCId().getAddCode()); switch (request.getBody().getSpaceOp().getAction()) { case ADDSPACE: BasicDBObject doc = new BasicDBObject("courseid", course.getCourseId()) .append("coursename", course.getCourseName()) .append("coursedesc", course.getCourseDescription()).append("addcode", course.getAddCode()); mclient.insertData(doc); reply = buildMessage(request, PokeStatus.SUCCESS, "Course added to database", SpaceAction.ADDSPACE); break; case LISTSPACES: BasicDBObject view = new BasicDBObject("courseid", course.getCourseId()); DBCursor cursor = mclient.findData(view); Request.Builder r = Request.newBuilder(); eye.Comm.Course.Builder f = eye.Comm.Course.newBuilder(); while (cursor.hasNext()) { f.setCourseId((String) cursor.next().get("courseid")); f.setCourseName((String) cursor.curr().get("coursename")); f.setCourseDescription((String) cursor.curr().get("coursedesc")); } NameSpaceOperation.Builder b = NameSpaceOperation.newBuilder(); b.setAction(SpaceAction.LISTSPACES); b.setCId(f.build()); eye.Comm.Payload.Builder p = Payload.newBuilder(); p.setSpaceOp(b.build()); r.setBody(p.build()); eye.Comm.Header.Builder h = Header.newBuilder(); h.setOriginator("client"); h.setRoutingId(eye.Comm.Header.Routing.NAMESPACES); h.setReplyMsg("Course Details"); r.setHeader(h.build()); reply = r.build(); break; case REMOVESPACE: BasicDBObject rem = new BasicDBObject("courseid", course.getCourseId()); mclient.deleteData(rem); reply = buildMessage(request, PokeStatus.SUCCESS, "Course deleted", SpaceAction.REMOVESPACE); break; case UPDATESPACE: BasicDBObject que = new BasicDBObject("courseid", course.getCourseId()); BasicDBObject upd = new BasicDBObject("courseid", course.getCourseId()) .append("coursename", course.getCourseName()) .append("coursedesc", course.getCourseDescription()).append("addcode", course.getAddCode()); mclient.updateData(que, upd); reply = buildMessage(request, PokeStatus.SUCCESS, "Course updated", SpaceAction.UPDATESPACE); break; default: break; } } mclient.closeConnection(); return reply; }
From source file:usermanager.Main2.java
private void btnFindUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindUserActionPerformed // TODO add your handling code here: // Get connection to the Collection DB userDB = DBManager.getDatabase(); DBCollection col = userDB.getCollection("user"); // Search/*from ww w . ja va 2 s . c o m*/ BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", Integer.parseInt(txtId.getText())); DBCursor cursor = col.find(searchQuery); while (cursor.hasNext()) { // Access next object cursor.next(); // Get the whole document printed in the console, if needed System.out.println(cursor.curr()); // Find by field and set to user object User newUser = new User(); newUser.setId(Integer.parseInt(cursor.curr().get("_id").toString())); newUser.setFirstName(cursor.curr().get("firstName").toString()); newUser.setLastName(cursor.curr().get("lastName").toString()); newUser.setEmail(cursor.curr().get("email").toString()); // Show in the form txtId.setText(String.valueOf(newUser.getId())); txtFirstName.setText(newUser.getFirstName()); txtLastName.setText(newUser.getLastName()); txtEmail.setText(newUser.getEmail()); } }
From source file:usermanager.Main3.java
private void btnFindUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnFindUserActionPerformed // Get connection to the Collection DB userDB = DBManager.getDatabase(); DBCollection col = userDB.getCollection("user"); // Search/*from w ww. j a v a 2 s.c o m*/ BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", Integer.parseInt(txtId.getText())); DBCursor cursor = col.find(searchQuery); while (cursor.hasNext()) { // Find by field and show in the form txtFirstName.setText(cursor.next().get("firstName").toString()); txtLastName.setText(cursor.curr().get("lastName").toString()); } }