Example usage for com.mongodb DBCursor curr

List of usage examples for com.mongodb DBCursor curr

Introduction

In this page you can find the example usage for com.mongodb DBCursor curr.

Prototype

public DBObject curr() 

Source Link

Document

Returns the element the cursor is at.

Usage

From source file:com.mycompany.Farmerama.getAllAccounts.java

public HashMap<String, String> getSearchedAccountsByNumber(String inputedS) {
    HashMap<String, String> allFoundUsersByNumber = new HashMap<String, String>();
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.append("number", new BasicDBObject("$regex", inputedS));
    DBCursor cursor = account.find(searchQuery);
    while (cursor.hasNext()) {
        allFoundUsersByNumber.put(cursor.next().get("number").toString(), cursor.curr().get("user").toString());
    }/*from w  ww  . j av a  2s .  c  o m*/
    return allFoundUsersByNumber;
}

From source file:com.tengen.Final7.java

License:Apache License

public static void main(String[] args) throws IOException {
    MongoClient client = new MongoClient();
    DB db = client.getDB("photoshare");
    int i = 0;/*from   ww w. jav a 2 s.c  o  m*/
    DBCollection album = db.getCollection("albums");
    DBCollection image = db.getCollection("images");

    DBCursor cur = image.find();
    cur.next();

    while (cur.hasNext()) {
        Object id = cur.curr().get("_id");
        DBCursor curalbum = album.find(new BasicDBObject("images", id));
        if (!curalbum.hasNext()) {
            image.remove(new BasicDBObject("_id", id));
        }
        cur.next();
    }
}

From source file:com.tml.pathummoto.Dao.CustomDao.java

public Customer searchCustomer(String no) {
    Customer customer = new Customer();
    // To connect to mongodb server
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("customer");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", no);
    DBCursor cursor = coll.find(whereQuery);
    while (cursor.hasNext()) {
        System.out.println(cursor.next());
    }/*from ww w .j  ava  2  s.  c o m*/
    BasicDBObject doc = (BasicDBObject) cursor.curr();
    System.out.println("doc" + doc);
    if (doc != null) {
        customer.setVehicleNo(doc.getString("_id"));
        customer.setName(doc.getString("name"));
        customer.setPayment(doc.getInt("payment"));
        customer.setFreeServiceNo(doc.getInt("freeServiceNo"));
        customer.setServiceNo(doc.getInt("serviceNo"));
        customer.setDateOfDelivery(doc.getDate("dateOfDelivery"));
        customer.setLastKm(doc.getInt("lastKm"));

    }

    return customer;
}

From source file:com.tml.pathummoto.Dao.PartDao.java

public Part searchPart(String partNo) {
    Part part = new Part();
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("part");
    System.out.println("Collection part selected successfully");

    BasicDBObject find = new BasicDBObject();
    find.put("_id", partNo);
    DBCursor cursor = coll.find(find);
    while (cursor.hasNext()) {
        System.out.println(cursor.next());
    }/*from w  w  w  .  ja  va2 s.  c  om*/
    BasicDBObject doc = (BasicDBObject) cursor.curr();
    if (doc != null) {

    }

    return part;

}

From source file:com.tml.pathummoto.Dao.PartDao.java

public Part singlePart(String partNumber) {
    Part part = new Part();
    // To connect to mongodb server
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("part");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("_id", partNumber);
    DBCursor cursor = coll.find(whereQuery);
    while (cursor.hasNext()) {
        System.out.println(cursor.next());
    }/*from w w w  . j  a  va2 s. com*/
    BasicDBObject doc = (BasicDBObject) cursor.curr();
    if (doc != null) {
        part.setPartName(doc.getString("Part Name"));
        part.setPartNo(doc.getString("_id"));

    }

    return part;
}

From source file:com.tml.pathummoto.Dao.UserDao.java

public User login(String name) {
    User user = new User();
    // To connect to mongodb server
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Now connect to your databases
    DB db = mongoClient.getDB("pathumdb");
    System.out.println("Connect to database successfully");

    DBCollection coll = db.getCollection("user");
    System.out.println("Collection user selected successfully");

    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("title", name);
    DBCursor cursor = coll.find(whereQuery);
    while (cursor.hasNext()) {
        System.out.println(cursor.next());
    }/*w  w w. j  a  v a  2  s .  c o m*/
    BasicDBObject doc = (BasicDBObject) cursor.curr();
    if (doc != null) {
        user.setName(doc.getString("title"));
        user.setPassword(doc.getString("password"));
    }

    return user;
}

From source file:es.eucm.gleaner.realtime.functions.DescriptivesGenerator.java

License:Apache License

@Override
public void execute(TridentTuple objects, TridentCollector tridentCollector) {
    // Extract values for searching the DB from the tuple
    Object taskId = objects.getValueByField("target");
    Object trial = objects.getValueByField("trial");

    // Extract value for updating the statistics from the tuple
    Double score = Double.parseDouble((String) objects.getValueByField("value"));

    /*** Step 1: get the initial performance statistics (from mongoDB or use starting values) ***/

    // Generate mongoDB query using target and trial
    BasicDBObject mongoDoc = new BasicDBObject();
    mongoDoc.append("taskId", taskId);
    mongoDoc.append("trial", trial);

    // Prepare statistics variables
    Double max; // Optional (not required for the calculation of the other statistics)
    Double min; // Optional (not required for the calculation of the other statistics)
    Double sum; // Optional (not required for the calculation of the other statistics)
    Double variance; // Variable needed for the calculation of stdDev
    Double mean; // Mean (target outcome)
    Double stdDev; // Standard deviation (target outcome)
    Double skewness; // The deviation of a gaussian distribution's mean from the median (target outcome)
    Double kurtosis; // The flatness of a gaussian distribution (target outcome)
    long n; // The number of samples that were used in this distribution (number of playthroughs)
    Boolean normal; // Is the normality assumption respected? (target outcome)
    Double help1; // Variable needed for skew and kurt calculation
    Double help2; // Variable needed for skew and kurt calculation
    Double help3; // Variable needed for skew and kurt calculation

    // Query the database in order to find the current statistics status
    n = performanceStatistics.count(mongoDoc);

    // Prepare the variables based on the statistics status
    if (n == 0) {
        // There were no previous completions of this task-trial combination so we start with a blank slate

        max = 0D;//from   w  w w. ja  va 2s.  com
        min = 0D;
        sum = 0D;
        variance = 0D;
        mean = 0D;
        stdDev = 0D;
        skewness = 0D;
        kurtosis = 0D;
        n = 1;
        normal = false;
        help1 = 0D;
        help2 = 0D;
        help3 = 0D;

    } else {
        // There were previous completions of this task-trial combination so we update the previous results

        DBCursor currentStatistics = performanceStatistics.find(mongoDoc);
        max = (double) currentStatistics.next().get("max"); // Uses next to get to the first field
        min = (double) currentStatistics.curr().get("min"); // Uses curr to moves through all fields after the first
        sum = (double) currentStatistics.curr().get("sum");
        variance = (double) currentStatistics.curr().get("variance");
        mean = (double) currentStatistics.curr().get("mean");
        stdDev = (double) currentStatistics.curr().get("stdDev");
        skewness = (double) currentStatistics.curr().get("skewness");
        kurtosis = (double) currentStatistics.curr().get("kurtosis");
        n = 1 + (long) currentStatistics.curr().get("n");
        normal = (boolean) currentStatistics.curr().get("normal");
        help1 = (double) currentStatistics.curr().get("help1");
        help2 = (double) currentStatistics.curr().get("help2");
        help3 = (double) currentStatistics.curr().get("help3");
    }

    // For testing: output results
    //        System.out.print("taskId: "); System.out.print(taskId);System.out.print(", ");
    //        System.out.print("trial: "); System.out.print(trial);System.out.print(", ");
    //        System.out.print("max: "); System.out.print(max);System.out.print(", ");
    //        System.out.print("min: "); System.out.print(min);System.out.print(", ");
    //        System.out.print("sum: "); System.out.print(sum);System.out.print(", ");
    //        System.out.print("var: "); System.out.print(variance);System.out.print(", ");
    //        System.out.print("mea: "); System.out.print(mean);System.out.print(", ");
    //        System.out.print("std: "); System.out.print(stdDev);System.out.print(", ");
    //        System.out.print("ske: "); System.out.print(skewness);System.out.print(", ");
    //        System.out.print("kur: "); System.out.print(kurtosis);System.out.print(", ");
    //        System.out.print("n  : "); System.out.print(n);System.out.print(", ");
    //        System.out.print("nor: "); System.out.print(normal);System.out.print(", ");
    //        System.out.print("hp1: "); System.out.print(help1);System.out.print(", ");
    //        System.out.print("hp2: "); System.out.print(help2);System.out.print(", ");
    //        System.out.print("hp3: "); System.out.print(help3);System.out.println(".");

    /*** Step 2: calculate the up-to-date statistics ***/

    if (n == 1) {
        max = score;
        min = score;
        sum = score;
    } else {
        // New max
        if (score > max)
            max = score;

        //New min
        if (score < min)
            min = score;

        // New sum
        sum += score;
    }

    // New mean, variance, & stdDev >> based on: http://www.johndcook.com/blog/standard_deviation/
    Double oldMean = mean;
    Double newMean;
    Double oldS = variance;
    Double newS;

    if (n == 1) {
        newMean = score;
        newS = 0D;
    } else {
        //New means formula suitable for 1-pass statistics (= big data ready)
        newMean = oldMean + (score - oldMean) / n;
        newS = oldS + (score - oldMean) * (score - newMean);
    }

    mean = newMean;
    variance = (n > 1) ? (newS / (n - 1)) : 0D;
    stdDev = Math.sqrt(variance);

    // New skewness & kurtosis >> based on: http://www.johndcook.com/blog/skewness_kurtosis/
    double delta, delta_n, delta_n2, term1;

    delta = score - newMean;
    delta_n = delta / n;
    delta_n2 = delta_n * delta_n;
    term1 = delta * delta_n * n;
    help3 = (term1 * delta_n2 * (n * n - 3 * n + 3)) + (6 * delta_n2 * help1) - (4 * delta_n * help2);
    help2 = (term1 * delta_n * (n - 2)) - (3 * n * delta_n * help1);
    help1 = term1;

    skewness = (Math.sqrt((double) n) * help2 / Math.pow(help1, 1.5));
    kurtosis = (((double) n) * help3 / (help1 * help1) - 3.0);

    // For testing: output results
    //        System.out.print("taskId: "); System.out.print(taskId);System.out.print(", ");
    //        System.out.print("trial: "); System.out.print(trial);System.out.print(", ");
    //        System.out.print("max: "); System.out.print(max);System.out.print(", ");
    //        System.out.print("min: "); System.out.print(min);System.out.print(", ");
    //        System.out.print("sum: "); System.out.print(sum);System.out.print(", ");
    //        System.out.print("var: "); System.out.print(variance);System.out.print(", ");
    //        System.out.print("mea: "); System.out.print(mean);System.out.print(", ");
    //        System.out.print("std: "); System.out.print(stdDev);System.out.print(", ");
    //        System.out.print("ske: "); System.out.print(skewness);System.out.print(", ");
    //        System.out.print("kur: "); System.out.print(kurtosis);System.out.print(", ");
    //        System.out.print("n  : "); System.out.print(n);System.out.print(", ");
    //        System.out.print("nor: "); System.out.print(normal);System.out.print(", ");
    //        System.out.print("hp1: "); System.out.print(help1);System.out.print(", ");
    //        System.out.print("hp2: "); System.out.print(help2);System.out.print(", ");
    //        System.out.print("hp3: "); System.out.print(help3);System.out.println(".");

    // Step 3: update the mongoDB performanceStatistics collection

    // Prepare the new document
    BasicDBObject newMongoDoc = new BasicDBObject();
    newMongoDoc.append("taskId", taskId).append("trial", trial).append("max", max).append("min", min)
            .append("sum", sum).append("variance", variance).append("mean", mean).append("stdDev", stdDev)
            .append("skewness", skewness).append("kurtosis", kurtosis).append("n", n).append("normal", normal)
            .append("help1", help1).append("help2", help2).append("help3", help3);

    // For EVEN MORE testing
    //        System.out.println(newDescriptives);

    // Insert the new document (create or update depending on whether it is a new task-trial combination
    if (n == 1) {
        // The doc did not previously exist so it will be created
        performanceStatistics.insert(newMongoDoc);
    } else {
        // The doc already existed so update the previous document
        performanceStatistics.update(new BasicDBObject().append("taskId", taskId).append("trial", trial),
                newMongoDoc);
    }

    // Step 4: emit the new tuple

    // Prepare the tuple
    ArrayList<Object> object = new ArrayList();
    object.add(max);
    object.add(max);
    object.add(min);
    object.add(sum);
    object.add(variance);
    object.add(mean);
    object.add(stdDev);
    object.add(skewness);
    object.add(kurtosis);
    object.add(n);
    object.add(normal);
    object.add(help1);
    object.add(help2);
    object.add(help3);

    // For testing
    //        System.out.print("The new tuple is: ");
    //        System.out.println(object);

    // Emit the tuple
    tridentCollector.emit(object);
}

From source file:exifIndexer.MetadataQueries.java

public ResultDataNormal cameraBrand(String s) {
    ArrayList paths = new ArrayList<>();
    ArrayList names = new ArrayList<>();

    //Consulta por marca de camara
    MongoHandler dbmon = new MongoHandler();
    DB dbmongo = dbmon.connect();//from   w  w  w  . ja  v a  2 s  .  c om
    DBCursor cursorDoc;
    DBCollection collection = dbmongo.getCollection("CameraBrands");
    BasicDBObject query = new BasicDBObject("CAMERA_BRAND", s);
    cursorDoc = collection.find(query);
    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 ResultDataNormal cameraModel(String s) {
    ArrayList paths = new ArrayList<>();
    ArrayList names;//from  w  w  w.ja  v a  2  s  .c  o  m
    names = new ArrayList<String>();
    //Consulta por modelo de camara
    MongoHandler dbmon = new MongoHandler();
    DB dbmongo = dbmon.connect();
    DBCursor cursorDoc;
    DBCollection collection = dbmongo.getCollection("CameraModels");
    BasicDBObject query = new BasicDBObject("CAMERA_MODEL", s);
    cursorDoc = collection.find(query);

    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 ResultDataNormal searchByISO(String s) {
    ArrayList paths = new ArrayList<>();
    ArrayList names = new ArrayList<>();
    //Consulta por modelo de camara
    MongoHandler dbmon = new MongoHandler();
    DB dbmongo = dbmon.connect();/*from ww  w.j av a2s.c o  m*/
    DBCursor cursorDoc;
    DBCollection collection = dbmongo.getCollection("SearchByISO");
    BasicDBObject query = new BasicDBObject();
    switch (s) {
    case "LOW":
        query = new BasicDBObject("ISO_VALUE", new BasicDBObject("$lt", 100));
        break;
    case "HIGH":
        query = new BasicDBObject("ISO_VALUE", new BasicDBObject("$gt", 3200));
        break;
    default:
        query = new BasicDBObject("ISO_VALUE", new BasicDBObject("$eq", Integer.parseInt(s)));
        break;

    }

    cursorDoc = collection.find(query);

    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);
}