Example usage for com.mongodb BasicDBObject BasicDBObject

List of usage examples for com.mongodb BasicDBObject BasicDBObject

Introduction

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

Prototype

public BasicDBObject() 

Source Link

Document

Creates an empty object.

Usage

From source file:Vehicle_exit.java

public void fetch() {
    try {/*from w  w w .  j  a va2  s  . c  om*/
        MongoClient mc = new MongoClient("localhost", 27017);
        DB db = mc.getDB("parking_system");
        DBCollection collectionx = db.getCollection("entry_info");

        if (veh_count == 2) {

            BasicDBObject queryx = new BasicDBObject();
            BasicDBObject fieldx = new BasicDBObject();
            fieldx.put("vehno", 1);
            DBCursor cursorx = collectionx.find(queryx, fieldx);

            while (cursorx.hasNext()) {

                System.out.println("hmmmWOW---n");
                BasicDBObject objx = (BasicDBObject) cursorx.next();

                char[] temp;
                temp = objx.getString("vehno").toCharArray();
                char last;
                last = temp[temp.length - 1];

                if (last == '2') {

                    vehno_combo.addItem(objx.get("vehno").toString());

                }
                System.out.println("hello");

            }
        } else if (veh_count == 4) {

            BasicDBObject queryx = new BasicDBObject();
            BasicDBObject fieldx = new BasicDBObject();
            fieldx.put("vehno", 1);
            DBCursor cursorx = collectionx.find(queryx, fieldx);

            while (cursorx.hasNext()) {

                System.out.println("hmmmWOW---n");
                BasicDBObject objx = (BasicDBObject) cursorx.next();

                char[] temp;
                temp = objx.getString("vehno").toCharArray();
                char last;
                last = temp[temp.length - 1];

                if (last == '4') {

                    vehno_combo.addItem(objx.get("vehno").toString());
                    //vehno = vehno_combo.getSelectedItem().toString();
                }
                System.out.println("hello");

            }
        }

        else {

            BasicDBObject queryx = new BasicDBObject();
            BasicDBObject fieldx = new BasicDBObject();
            fieldx.put("vehno", 1);
            DBCursor cursorx = collectionx.find(queryx, fieldx);

            while (cursorx.hasNext()) {

                System.out.println("hmmmWOW---n");
                BasicDBObject objx = (BasicDBObject) cursorx.next();

                char[] temp;
                temp = objx.getString("vehno").toCharArray();
                char last;
                last = temp[temp.length - 1];

                if (last == '6') {

                    vehno_combo.addItem(objx.get("vehno").toString());
                    //vehno = vehno_combo.getSelectedItem().toString();
                }
                System.out.println("hello");

            }
        }
    } catch (Exception e) {
    }
}

From source file:Vehicle_exit.java

private void Exit_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Exit_buttonActionPerformed
    // TODO add your handling code here:

    try {/* w ww  .j  av a2  s  .c  o  m*/
        vehno = vehno_combo.getSelectedItem().toString();
        vehno_copy = vehno;
        System.out.println("in button number niald" + vehno);

        MongoClient mc = new MongoClient("localhost", 27017);
        DB db = mc.getDB("parking_system");
        DBCollection collection = db.getCollection("entry_info");

        BasicDBObject query_time = new BasicDBObject();
        BasicDBObject field_time = new BasicDBObject();
        field_time.put("intime", 1);
        DBCursor cursor = collection.find(query_time, field_time);

        BasicDBObject query_token = new BasicDBObject();
        BasicDBObject field_token = new BasicDBObject();
        field_time.put("vehno", 1);
        DBCursor cursor_token = collection.find(query_token, field_token);

        while (cursor.hasNext()) {
            BasicDBObject obj_time = (BasicDBObject) cursor.next();
            in_time_mills = Long.parseLong(obj_time.getString("intime"));

            BasicDBObject obj_token = (BasicDBObject) cursor_token.next();
            //db_token = obj_token.getInt("_id");
            vehno_db = obj_token.getString("vehno");
            System.out.println(vehno_db);
            System.out.println("hello");

            System.out.println("hey ayu");

            DBCollection collection1 = db.getCollection("vehicle_count");
            DBCollection collection2 = db.getCollection("statistics");
            vehno = vehno_copy;
            if (veh_count == 2) {
                //vehno = vehno + "W2";

                if (vehno.equals(vehno_db)) {

                    flag = 1;

                    BasicDBObject deleteObject = new BasicDBObject();
                    //deleteObject.put("_id",Token);
                    deleteObject.put("vehno", vehno);
                    DBCursor findQuery = collection.find(deleteObject);
                    collection.remove(deleteObject);

                    int count_bike;
                    BasicDBObject query = new BasicDBObject();
                    BasicDBObject field = new BasicDBObject();
                    field.put("wheeler_2", 1);
                    DBCursor cursor1 = collection1.find(query, field);

                    BasicDBObject obj = (BasicDBObject) cursor1.next();
                    count_bike = obj.getInt("wheeler_2");

                    System.out.println(count_bike);

                    BasicDBObject searchUpdate = new BasicDBObject();
                    searchUpdate.append("wheeler_2", count_bike);

                    BasicDBObject UpdateObject = new BasicDBObject();
                    UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike - 1));

                    collection1.update(searchUpdate, UpdateObject);

                    System.out.println("Checking...");

                    time_diff = exit_time_mills - in_time_mills;
                    time_diff = time_diff / 1000;
                    time_diff = time_diff / 60;
                    System.out.println("difftime" + time_diff);
                    if (time_diff > 60)
                        charges = 20 + (time_diff) / 2;
                    else
                        charges = 20;

                    //updating session...

                    int income_bike;
                    BasicDBObject query2 = new BasicDBObject();
                    BasicDBObject field2 = new BasicDBObject();
                    field2.put("2wheeler_income", 1);
                    DBCursor cursor2 = collection2.find(query2, field2);

                    BasicDBObject obj2 = (BasicDBObject) cursor2.next();
                    income_bike = obj2.getInt("2wheeler_income");
                    System.out.println(income_bike);

                    BasicDBObject searchUpdate2 = new BasicDBObject();
                    searchUpdate2.append("2wheeler_income", income_bike);

                    BasicDBObject UpdateObject2 = new BasicDBObject();
                    UpdateObject2.append("$set", new BasicDBObject("2wheeler_income", income_bike + charges));

                    collection2.update(searchUpdate2, UpdateObject2);

                    JOptionPane.showMessageDialog(null, "Vehicle Out !\n" +
                    /*"In Time : " + in_time_mills + "\n" +*/
                            "Extra Parking Time : " + time_diff + "Min.\n" + "Charges : " + charges);

                    System.out.println("Checked...");

                    setVisible(false);
                    new Entry_OR_Exit().setVisible(true);
                    break;
                }
            }

            else if (veh_count == 4) {

                //vehno = vehno + "W4";

                if (vehno.equals(vehno_db)) {

                    flag = 1;

                    BasicDBObject deleteObject = new BasicDBObject();
                    //deleteObject.put("_id",Token);
                    deleteObject.put("vehno", vehno);
                    DBCursor findQuery = collection.find(deleteObject);
                    collection.remove(deleteObject);

                    int count_car;

                    BasicDBObject query = new BasicDBObject();
                    BasicDBObject field = new BasicDBObject();
                    field.put("wheeler_4", 1);
                    DBCursor cursor1 = collection1.find(query, field);

                    BasicDBObject obj = (BasicDBObject) cursor1.next();
                    count_car = obj.getInt("wheeler_4");
                    System.out.println(count_car);

                    BasicDBObject searchUpdate = new BasicDBObject();
                    searchUpdate.append("wheeler_4", count_car);

                    BasicDBObject UpdateObject = new BasicDBObject();
                    UpdateObject.append("$set", new BasicDBObject("wheeler_4", count_car - 1));

                    collection1.update(searchUpdate, UpdateObject);

                    System.out.println("Checking...2");

                    time_diff = exit_time_mills - in_time_mills;
                    time_diff = time_diff / 1000;
                    time_diff = time_diff / 60;
                    System.out.println("difftime" + time_diff);
                    if (time_diff > 60)
                        charges = 40 + (time_diff) * 3 / 2;
                    else
                        charges = 40;

                    //Session update....

                    int income_car;
                    BasicDBObject query2 = new BasicDBObject();
                    BasicDBObject field2 = new BasicDBObject();
                    field2.put("4wheeler_income", 1);
                    DBCursor cursor2 = collection2.find(query2, field2);

                    BasicDBObject obj2 = (BasicDBObject) cursor2.next();
                    income_car = obj2.getInt("4wheeler_income");
                    System.out.println(income_car);

                    BasicDBObject searchUpdate2 = new BasicDBObject();
                    searchUpdate2.append("4wheeler_income", income_car);

                    BasicDBObject UpdateObject2 = new BasicDBObject();
                    UpdateObject2.append("$set", new BasicDBObject("4wheeler_income", income_car + charges));

                    collection2.update(searchUpdate2, UpdateObject2);

                    JOptionPane.showMessageDialog(null, "Vehicle Out !\n" +
                    /*"In Time : " + in_time_mills + "\n" +*/
                            "Extra Parking Time : " + time_diff + "Min.\n" + "Charges : " + charges);

                    System.out.println("Checking...2");

                    setVisible(false);
                    new Entry_OR_Exit().setVisible(true);
                    break;

                }
            } else {

                //vehno = vehno + "W6";
                if (vehno.equals(vehno_db)) {

                    flag = 1;

                    BasicDBObject deleteObject = new BasicDBObject();
                    //deleteObject.put("_id",Token);
                    deleteObject.put("vehno", vehno);
                    DBCursor findQuery = collection.find(deleteObject);
                    collection.remove(deleteObject);

                    int count_other;

                    BasicDBObject query = new BasicDBObject();
                    BasicDBObject field = new BasicDBObject();
                    field.put("other", 1);
                    DBCursor cursor1 = collection1.find(query, field);

                    BasicDBObject obj = (BasicDBObject) cursor1.next();
                    count_other = obj.getInt("other");

                    System.out.println(count_other);

                    BasicDBObject searchUpdate = new BasicDBObject();
                    searchUpdate.append("other", count_other);

                    BasicDBObject UpdateObject = new BasicDBObject();
                    UpdateObject.append("$set", new BasicDBObject("other", count_other - 1));

                    collection1.update(searchUpdate, UpdateObject);

                    System.out.println("Checking...3");

                    time_diff = exit_time_mills - in_time_mills;
                    time_diff = time_diff / 1000;
                    time_diff = time_diff / 60;
                    System.out.println("difftime" + time_diff);
                    if (time_diff > 60)
                        charges = 60 + (time_diff);
                    else
                        charges = 60;

                    //sessiuon update....

                    int income_other;
                    BasicDBObject query2 = new BasicDBObject();
                    BasicDBObject field2 = new BasicDBObject();
                    field2.put("other_income", 1);
                    DBCursor cursor2 = collection2.find(query2, field2);

                    BasicDBObject obj2 = (BasicDBObject) cursor2.next();
                    income_other = obj2.getInt("other_income");
                    System.out.println(income_other);

                    BasicDBObject searchUpdate2 = new BasicDBObject();
                    searchUpdate2.append("other_income", income_other);

                    BasicDBObject UpdateObject2 = new BasicDBObject();
                    UpdateObject2.append("$set", new BasicDBObject("other_income", income_other + charges));

                    collection2.update(searchUpdate2, UpdateObject2);

                    JOptionPane.showMessageDialog(null, "Vehicle Out !\n" +
                    /*"In Time : " + in_time_mills + "\n" +*/
                            "Extra Parking Time : " + time_diff + "Min.\n" + "Charges : " + charges);

                    System.out.println("Checked...3");
                    setVisible(false);
                    new Entry_OR_Exit().setVisible(true);
                    break;

                }
            }
            //}
        }
        if (flag == 0) {
            JOptionPane.showMessageDialog(null, "Invalid Vehicle Number or Type");
            setVisible(false);
            new Entry_OR_Exit().setVisible(true);
        }
        /*
        BasicDBObject searchUpdate = new BasicDBObject();
        searchUpdate.append("wheeler_2", count_bike);
                
        BasicDBObject UpdateObject = new BasicDBObject();
        UpdateObject.append("$set", new BasicDBObject("wheeler_2", count_bike + 1));
                
        collection.update(searchUpdate, UpdateObject);
                
        */
        //}
    } catch (Exception e) {

    }

}

From source file:LoginUI.java

private HashMap<String, String> getUserInfo() throws ParseException {
    DBCollection collection = db.getCollection("Users");

    DBObject allquery = new BasicDBObject();
    DBObject fields = new BasicDBObject();
    fields.put("Info", 1);

    DBCursor infocursor = collection.find(allquery, fields);
    HashMap<String, String> userpw = new HashMap<String, String>();

    while (infocursor.hasNext()) {
        String json = infocursor.next().toString();
        JSONParser parser = new JSONParser();
        JSONObject jsonFile = (JSONObject) parser.parse(json);
        JSONObject structure = (JSONObject) jsonFile.get("Info");
        String user = structure.get("Username").toString();
        String pw = structure.get("Password").toString();
        JSONObject idStruct = (JSONObject) jsonFile.get("_id");
        String id = idStruct.get("$oid").toString();

        userpw.put(user, pw);//ww  w.j  a v a2 s  .  c  om
    }
    return userpw;
}

From source file:MashUp.java

public void readApi() throws Exception {

    // File f1 = new File("C:\\Users\\sowgandh\\Desktop\\API_&_MASHUP Text\\api.txt");
    BufferedReader br = new BufferedReader(new FileReader("/Users/Pranav/Desktop/api.txt"));
    BufferedReader br2 = new BufferedReader(new FileReader("/Users/Pranav/Desktop/mashup.txt"));
    try {//from   w w  w  .  j a  va  2  s .com

        String line1 = "";
        // String line2 = br2.readLine();
        int count = 0;

        while ((line1 = br.readLine()) != null) {

            ++count;
            String[] token1 = line1.split("\\$\\#\\$");
            BasicDBObject document = new BasicDBObject();
            for (int i = 0; i < token1.length; i++) {

                // System.out.println( i + " " +token1[i]);
                //System.out.println();
                switch (i) {
                case 0: {
                    //System.out.println(token1[i]);
                    document.put("id", token1[i]);
                    api.put("id", token1[i]);
                    break;
                }
                case 1: {
                    //System.out.println(token1[i]);
                    api.put("title", token1[i]);
                    document.put("title", token1[i]);
                    break;
                }
                case 2: {
                    //System.out.println(token1[i]);
                    document.put("summary", token1[i]);
                    api.put("summary", token1[i]);
                    break;
                }
                case 3: {
                    if (token1[i].equals("")) {
                        document.put("rating", 0.0);
                    } else {
                        DecimalFormat df = new DecimalFormat("#.#");

                        document.put("rating", Double.parseDouble(df.format(Double.parseDouble(token1[i]))));
                        api.put("rating", token1[i]);
                    }
                    break;
                }
                case 4: {

                    document.put("name", token1[i]);
                    api.put("name", token1[i]);
                    break;
                }
                case 7: {
                    document.put("description", token1[i]);
                    api.put("description", token1[i]);
                    break;
                }

                case 17: {
                    String tags[] = token1[i].split("\\#\\#\\#");
                    //  System.out.println("Tags lenght "+tags.length);
                    String tag = "";
                    for (int j = 0; j < tags.length; j++) {
                        tag = tag + tags[j] + " ";
                    }
                    // System.out.println("Tags are "+tag);
                    document.put("Tags", tag);
                    api.put("Tags", tag);
                    break;
                }
                case 18: {
                    document.put("category", token1[i]);
                    api.put("category", token1[i]);
                    break;
                }
                case 19: {
                    document.put("protocols", token1[i]);
                    api.put("protocols", token1[i]);
                    break;
                }

                case 45: {
                    document.put("updated", token1[i]);
                    api.put("updated", token1[i]);
                    break;
                }
                default: {
                    //System.out.println("Error");
                    break;
                }

                }

            }

            table1.insert(document);

        }
        //  line = br.readLine();

        /*
        second
        */

        System.out.println();
        System.out.println();
        System.out.println();

        String line2 = "";

        int count2 = 0;
        while ((line2 = br2.readLine()) != null) {

            ++count2;
            String[] token1 = line2.split("\\$\\#\\$");
            BasicDBObject document = new BasicDBObject();
            for (int i = 0; i < token1.length; i++) {

                //System.out.println( i + " " +token1[i]);
                //System.out.println();
                switch (i) {
                case 0: {
                    //System.out.println(token1[i]);
                    document.put("id", token1[i]);
                    api.put("id", token1[i]);
                    break;
                }
                case 1: {
                    //System.out.println(token1[i]);
                    api.put("title", token1[i]);
                    document.put("title", token1[i]);
                    break;
                }
                case 2: {
                    //System.out.println(token1[i]);
                    document.put("summary", token1[i]);
                    api.put("summary", token1[i]);
                    break;
                }
                case 3: {
                    document.put("rating", token1[i]);
                    api.put("rating", token1[i]);
                    break;
                }

                case 4: {
                    document.put("name", token1[i]);
                    api.put("name", token1[i]);
                    break;
                }

                case 7: {
                    document.put("description", token1[i]);
                    api.put("description", token1[i]);
                    break;
                }

                case 15: {
                    String tags[] = token1[i].split("\\#\\#\\#");
                    //  System.out.println("Tags lenght "+tags.length);
                    String tag = "";
                    for (int j = 0; j < tags.length; j++) {
                        tag = tag + tags[j] + " ";
                    }
                    // System.out.println("Tags are "+tag);
                    document.put("Tags", tag);
                    api.put("Tags", tag);
                    break;
                }
                case 16: {
                    String temp[] = token1[i].split("\\#\\#\\#");
                    String tag = "";
                    for (int j = 0; j < temp.length; j++) {
                        // System.out.println("Tags are "+temp[j]);
                        String g[] = temp[j].split("\\$\\$\\$");

                        for (int t = 0; t < g.length; t++) {
                            if (t % 2 == 0) {

                                tag = tag + "OO" + g[t] + " ";
                                // tag=tag+temp[j]+"(";
                                // System.out.println("1 "+tag);

                            }
                        }
                    }
                    //System.out.println("Tags are "+tag);
                    document.put("APIs", tag);
                    api.put("Apis", token1[i]);
                    break;
                }
                case 17: {
                    document.put("updated", token1[i]);
                    api.put("updated", token1[i]);
                    break;
                }

                default: {
                    //System.out.println("Error");
                    break;
                }

                }

            }

            table2.insert(document);

        }

    } finally {

        br.close();
        br2.close();
    }
}

From source file:MashUp.java

public ArrayList<String> getApibasedonProtocols(String protocol) {
    ArrayList<String> api = new ArrayList<String>();
    BasicDBObject whereQuery = new BasicDBObject();
    whereQuery.put("protocols", protocol);
    DBCursor cursor = table1.find(whereQuery);
    while (cursor.hasNext()) {
        String temp = cursor.next().get("id").toString();
        api.add(temp);//from  w w  w  .  ja  v  a 2  s  .c o m
    }

    return api;

}

From source file:MashUp.java

public ArrayList<String> getApibasedonCategory(String category) {
    ArrayList<String> api = new ArrayList<String>();
    BasicDBObject whereQuery = new BasicDBObject();

    whereQuery.put("category", category);
    DBCursor cursor = table1.find(whereQuery);
    while (cursor.hasNext()) {
        String temp = cursor.next().get("id").toString();
        api.add(temp);/*from   ww w .  ja  va 2 s . co  m*/
    }

    return api;

}

From source file:MashUp.java

public String queryDatabaseApi(String Year, String Protocol, String Category, String Tags, String Keywords,
        Double Rating) {//from  w  ww.j ava 2s.  c om

    String temp = "";
    BasicDBObject gtQuery = new BasicDBObject();
    BasicDBObject ltQuery = new BasicDBObject();
    BasicDBObject eqQuery = new BasicDBObject();

    if (!Rating.equals(0.0)) {

        /*
        greater than
        */

        temp = temp + "\n";
        temp = temp + "Greater than " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            gtQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            gtQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            gtQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            gtQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            gtQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        gtQuery.put("rating", new BasicDBObject("$gt", Rating));
        DBCursor cursor = table1.find(gtQuery);
        while (cursor.hasNext()) {
            DBObject temp1 = cursor.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

        /*
        lower than
        */

        temp = temp + "\n";
        temp = temp + "Lower than " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            ltQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            ltQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            ltQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            ltQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            ltQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        ltQuery.put("rating", new BasicDBObject("$lt", Rating));
        DBCursor cursor2 = table1.find(ltQuery);
        while (cursor2.hasNext()) {
            DBObject temp1 = cursor2.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

        /*
                
        equal to 
        */

        temp = temp + "\n";
        temp = temp + "Equal to " + Rating + "\n" + "\n";
        temp = temp + "\n";

        if (!Year.equals("")) {
            eqQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            eqQuery.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            eqQuery.put("category", Category);
        }
        if (!Tags.equals("")) {
            eqQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            eqQuery.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        eqQuery.put("rating", new BasicDBObject("$eq", Rating));
        DBCursor cursor3 = table1.find(eqQuery);
        while (cursor3.hasNext()) {
            DBObject temp1 = cursor3.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }

    } else {

        BasicDBObject test = new BasicDBObject();
        if (!Year.equals("")) {
            test.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
        }
        if (!Protocol.equals("")) {
            test.put("protocols", Protocol);
        }

        if (!Category.equals("")) {
            test.put("category", Category);
        }
        if (!Tags.equals("")) {
            test.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
        }
        if (!Keywords.equals("")) {
            DBObject clause1 = new BasicDBObject("summary",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause2 = new BasicDBObject("description",
                    new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
            BasicDBList or = new BasicDBList();
            or.add(clause1);
            or.add(clause3);
            or.add(clause2);
            test.put("$or", or);
            //DBObject query = new BasicDBObject("$or", or);
            //System.out.println(query);

        }

        DBCursor cursor = table1.find(test);
        while (cursor.hasNext()) {
            DBObject temp1 = cursor.next();
            if (!temp.contains(temp1.get("name").toString()))
                temp = temp + " " + temp1.get("name") + "\n";
        }
    }

    /*
    if(!Year.equals("")){
    //gtQuery.put("rating", new BasicDBObject("$gt", "4"));
    gtQuery.put("updated",new BasicDBObject("$regex",".*"+Year+".*"));
    }
    if(!Protocol.equals("")){
    gtQuery.put("protocols",Protocol);
    }
            
    if(!Category.equals("")){
    gtQuery.put("category",Category);
    }
    if(!Tags.equals("")){
    gtQuery.put("Tags",new BasicDBObject("$regex",".*"+Tags+".*") );
    }
     if(!Keywords.equals("")){
    DBObject clause1 = new BasicDBObject("summary", new BasicDBObject("$regex",".*"+Keywords+".*"));  
    DBObject clause2 = new BasicDBObject("description", new BasicDBObject("$regex",".*"+Keywords+".*"));
    DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex",".*"+Keywords+".*")); 
    BasicDBList or = new BasicDBList();
    or.add(clause1);or.add(clause3);
    or.add(clause2);
    gtQuery.put("$or", or);
    //DBObject query = new BasicDBObject("$or", or);
    //System.out.println(query);
            
    }
             
            
            
    //gtQuery.put("rating", new BasicDBObject("$gt", "4").append("$lt", "5"));
    //  gtQuery.put("updated", "2012-12-17T09:51:40Z");
    DBCursor cursor = table1.find(gtQuery);
    String temp="";
            
    if(!Rating.equals(0.0)){
     gtQuery.put("rating",new BasicDBObject("$gt",Rating));
     temp="Greater than "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
      }
              
      gtQuery.remove("rating");
      temp=temp+"\n";
    gtQuery.put("rating",new BasicDBObject("$lt",Rating));
     temp= temp+"Lesser than "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
            
    gtQuery.remove("rating");
    temp=temp+"\n";
    gtQuery.put("rating",new BasicDBObject("$eq",Rating));
     temp=temp+"Equal to "+Rating+"\n"+"\n";
      while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
            
    }else{
    while(cursor.hasNext()) {
    DBObject temp1 = cursor.next();
         temp=temp+" "+temp1.get("name")+"\n";
    }
    }
            
    */

    return temp;
}

From source file:MashUp.java

public String queryDatabaseMashUp(String Year, String UsedApi, String Tags, String Keywords) {
    BasicDBObject gtQuery = new BasicDBObject();

    if (!Year.equals("")) {
        //gtQuery.put("rating", new BasicDBObject("$gt", "4"));
        gtQuery.put("updated", new BasicDBObject("$regex", ".*" + Year + ".*"));
    }/* w w w  .  j  a va2  s  . c o  m*/
    if (!UsedApi.equals("")) {
        System.out.println("UsedApi " + UsedApi);
        // DBObject clause1 = new BasicDBObject("APIS", new BasicDBObject("$regex",".*"+UsedApi+".*"));  
        // gtQuery.put("APIs",new BasicDBObject("APIs", new BasicDBObject("$regex",".*"+UsedApi+".*")));
        gtQuery.put("APIs", new BasicDBObject("$regex", ".*" + UsedApi + ".*"));
    }

    if (!Tags.equals("")) {
        gtQuery.put("Tags", new BasicDBObject("$regex", ".*" + Tags + ".*"));
    }
    if (!Keywords.equals("")) {
        DBObject clause1 = new BasicDBObject("summary", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
        DBObject clause2 = new BasicDBObject("description",
                new BasicDBObject("$regex", ".*" + Keywords + ".*"));
        DBObject clause3 = new BasicDBObject("title", new BasicDBObject("$regex", ".*" + Keywords + ".*"));
        BasicDBList or = new BasicDBList();
        or.add(clause1);
        or.add(clause3);
        or.add(clause2);
        gtQuery.put("$or", or);
        //DBObject query = new BasicDBObject("$or", or);
        //System.out.println(query);

    }

    //gtQuery.put("rating", new BasicDBObject("$gt", "4").append("$lt", "5"));
    //  gtQuery.put("updated", "2012-12-17T09:51:40Z");
    DBCursor cursor = table2.find(gtQuery);
    String temp = "";
    while (cursor.hasNext()) {
        DBObject temp1 = cursor.next();
        temp = temp + " " + temp1.get("name") + "\n";
    }
    return temp;
}

From source file:TeacherSection.java

private void formComponentResized(java.awt.event.ComponentEvent evt) {//GEN-FIRST:event_formComponentResized
    // TODO add your handling code here:

    DBCollection coll = db.getCollection("user");
    BasicDBObject andQuery = new BasicDBObject();
    List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    String username = login.user;
    obj.add(new BasicDBObject("user", username));
    andQuery.put("$and", obj);

    DBCursor cursor = coll.find(andQuery);
    while (cursor.hasNext()) {
        lastname = cursor.next().get("lastname").toString();
    }//from   www .  j  ava  2  s  .  com

    DBCollection coll1 = db.getCollection("teacher");

    BasicDBObject andQuery1 = new BasicDBObject();
    List<BasicDBObject> obj1 = new ArrayList<BasicDBObject>();
    obj1.add(new BasicDBObject("firstname", firstname));
    obj1.add(new BasicDBObject("lastname", lastname));
    andQuery1.put("$and", obj1);
    cursor = coll1.find(andQuery1);

    while (cursor.hasNext()) {

        BasicDBList teache = (BasicDBList) cursor.next().get("teach");
        String data[] = new String[teache.size()];

        for (int j = 0; j < teache.size(); ++j) {
            BasicDBObject teach = (BasicDBObject) teache.get(j);
            String val = teach.getString("grade") + "-" + teach.getString("section");
            data[j] = val;

        }
        GradeList.setListData(data);
    }

}

From source file:TeacherSection.java

private void GradeListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_GradeListValueChanged
    // TODO add your handling code here:
    if (!evt.getValueIsAdjusting()) {
        String selected = GradeList.getSelectedValue();
        int grade = 0;
        int section = 0;
        for (int i = 0; i < selected.length(); ++i) {
            if (selected.charAt(i) == '-') {

                grade = (int) Double.parseDouble(selected.substring(0, i));
                section = (int) Double.parseDouble(selected.substring(i + 1));
            }//from  w  w w  . ja v a 2 s.co m
        }

        DBCollection coll = db.getCollection("student");
        BasicDBObject andQuery = new BasicDBObject();
        List<BasicDBObject> obj = new ArrayList<BasicDBObject>();

        obj.add(new BasicDBObject("grade", grade));
        obj.add(new BasicDBObject("section", section));

        andQuery.put("$and", obj);
        DBCursor cursor = coll.find(andQuery);
        while (cursor.hasNext()) {

            DBObject object = cursor.next();
            this.FirstnameField.setText(object.get("firstname").toString());
            this.MidnameField.setText(object.get("mid_name").toString());
            LastnameField.setText(object.get("lastname").toString());

            BasicDBList marks = (BasicDBList) object.get("marks");
            for (int i = 0; i < marks.size(); ++i) {
                BasicDBObject mark = (BasicDBObject) marks.get(i);
                if (mark.getString("teacher").equals(firstname)) {

                    if (mark.get("mid") == null) {

                        MidField.setText("-1");
                        FinalField.setText("-1");

                    } else if (mark.get("mid") != null && mark.get("final") == null) {

                        MidField.setText(mark.getString("mid"));
                        FinalField.setText("-1");
                    } else {

                        MidField.setText(mark.getString("mid"));
                        FinalField.setText(mark.getString("final"));

                    }

                    break;
                }

            }
            int reply = JOptionPane.showConfirmDialog(null, "if you want to update press yes", "Update or Skip",
                    JOptionPane.YES_NO_OPTION);
            if (reply == JOptionPane.YES_OPTION) {
                int midmark = Integer.parseInt(JOptionPane.showInputDialog("Please input mark for mid: "));
                int finalmark = Integer.parseInt(JOptionPane.showInputDialog("Please input mark for final: "));
                BasicDBObject andQuery1 = new BasicDBObject();
                List<BasicDBObject> obj1 = new ArrayList<BasicDBObject>();
                obj1.add(new BasicDBObject("firstname", FirstnameField.getText()));
                obj1.add(new BasicDBObject("mid_name", MidnameField.getText()));
                obj1.add(new BasicDBObject("lastname", LastnameField.getText()));
                obj1.add(new BasicDBObject("grade", grade));
                obj1.add(new BasicDBObject("section", section));
                obj1.add(new BasicDBObject("marks.teacher", firstname));
                andQuery1.put("$and", obj1);
                BasicDBObject data = new BasicDBObject();
                if (midmark == -1 && finalmark == -1) {
                    JOptionPane.showMessageDialog(null, "No data was updated!");
                } else if (midmark != -1 && finalmark != -1) {
                    data.put("marks.$.mid", midmark);
                    JOptionPane.showMessageDialog(null, "data was updated .");
                } else {
                    data.put("marks.$.mid", midmark);
                    data.put("marks.$.final", finalmark);
                    JOptionPane.showMessageDialog(null, "data was updated .");

                }
                BasicDBObject command = new BasicDBObject();
                command.put("$set", data);
                coll.update(andQuery1, command);

            }

        }

    }

}