Example usage for com.mongodb DBCursor hasNext

List of usage examples for com.mongodb DBCursor hasNext

Introduction

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

Prototype

@Override
public boolean hasNext() 

Source Link

Document

Checks if there is another object available.

Usage

From source file:Highscores.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    try {//  w w w. j a va  2 s  .  co  m
        String user;
        int count = 1;
        String highscore;
        jTextArea2.append("SR No.\tUSERNAME\tHIGHSCORE\n");
        int high;
        MongoClient mc = new MongoClient("localhost", 27017);
        DB db = mc.getDB("Classic_Hangman");
        System.out.println("Connected to database successfully!!");
        DBCollection coll = db.getCollection("high_score");
        System.out.println("Collection Retrieved");
        DBCursor cursor = coll.find();
        cursor.sort(new BasicDBObject("value", -1));
        while (cursor.hasNext() && count < 4) {
            DBObject result = cursor.next();
            high = ((Number) result.get("value")).intValue();
            highscore = Integer.toString(high);
            user = (String) result.get("_id");
            jTextArea2.append(count + "\t" + user + "\t" + highscore + "\n");
            count++;
        }
    } catch (UnknownHostException ex) {
        Logger.getLogger(Highscores.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:PersistMongo.java

public static void main(String[] args) {
    // conectando ao mongo, como esta sem parametros
    //se conecta ao mongo local por default 
    MongoClient mongoClient = new MongoClient("localhost", 27017);

    // Base de dados
    DB db = (DB) mongoClient.getDB("JavaDB");
    // Tabela /*from w ww. j  ava  2s .  c  o m*/
    DBCollection collection = db.getCollection("colJava");
    // objeto para ser persistido
    BasicDBObject document1 = new BasicDBObject();
    document1.put("id", 1001);
    document1.put("msg", "Persistencia com mongoDB");

    // salvando o documento na base nosql
    collection.insert(document1);
    BasicDBObject document = new BasicDBObject();
    document = new BasicDBObject();
    document.put("id", 1002);
    document.put("msg", "Java + Mongo");

    // salvando o documento na base nosql
    collection.insert(document);
    // objeto que recebe os dados do banco
    DBCursor cursor = collection.find();
    // percorrendo o objeto e mostrando os dados
    while (cursor.hasNext()) {
        System.out.println("Document: " + cursor.next());

    }
    // Passando o documento que sera removido
    collection.remove(document);
    // Passando o documentoque sera atualizado e o documento que entrara em seu lugar 
    collection.update(document, document1);

}

From source file:Add_train.java

@Override
/* Check The code below for insertion of values */
public void actionPerformed(ActionEvent ae) {
    // TODO Auto-generated method stub
    add(jLabel9);/*from  w w w.j  a v  a  2s  .  co m*/
    jLabel9.setText("");
    if (ae.getSource() == jButton1) {
        try {
            MongoClient mongo = new MongoClient("localhost", 27017);
            DB db = mongo.getDB("Gym");
            DBCollection Allot = db.getCollection("Batch_Trainer");
            DBCursor cursor1 = Allot.find();
            DBCollection Gym_Collection = db.getCollection("trainer");
            String first_name = jTextField1.getText();
            String last_name = jTextField2.getText();
            String password = jPassword1.getText().toString();
            String dup = jPassword2.getText().toString();
            String username = jTextField5.getText().toString();
            String address = jTextArea1.getText();

            String Batches = jComboBox5.getSelectedItem().toString();
            float Slots, Morning, Evening, Night;
            cursor1.next();
            Slots = Float.parseFloat(cursor1.curr().get("Slots").toString());
            Morning = Float.parseFloat(cursor1.curr().get("Morning").toString());
            Evening = Float.parseFloat(cursor1.curr().get("Evening").toString());
            Night = Float.parseFloat(cursor1.curr().get("Night").toString());
            int age = Integer.parseInt(jComboBox1.getSelectedItem().toString());
            String phone_number = jTextField3.getText().toString();
            DBCursor cursor = Gym_Collection.find();
            int i = 0;
            while (cursor.hasNext()) {
                cursor.next();
                if (username.equals(cursor.curr().get("Username").toString())) {
                    i = 1;
                }
            }
            if (i == 1) {
                JOptionPane.showMessageDialog(this, "Username has been taken !!!");
                jTextField5.setText("");
            } else if (!isAlpha(first_name) || !isAlpha(last_name)) {
                JOptionPane.showMessageDialog(this, "Enter a valid name");
                jTextField1.setText("");
                jTextField2.setText("");
            } else if (phone_number.length() < 8 || phone_number.length() > 10) {
                JOptionPane.showMessageDialog(this, "Enter a valid Phone no.");
                jTextField3.setText("");
            } else if (!password.equals(dup)) {
                JOptionPane.showMessageDialog(this, "Passwords didn't match");
                jPassword1.setText("");
                jPassword2.setText("");
            } else {

                int flag = 0, flag1 = 0, flag2 = 0, flag3 = 0;
                if (Batches.equals("Morning")) {
                    Morning += 1;
                    flag1 = 1;
                } else if (Batches.equals("Evening")) {
                    Evening += 1;
                    flag2 = 1;
                } else if (Batches.equals("Night")) {
                    Night += 1;
                    flag3 = 1;
                }
                if (Morning > Slots || Evening > Slots || Night > Slots) {
                    if (flag1 == 1) {
                        Morning -= 1;
                    } else if (flag2 == 1) {
                        Evening -= 1;
                    } else if (flag3 == 1) {
                        Night -= 1;
                    }
                    flag = 1;
                }
                if (flag == 1) {
                    float temp1, temp2;
                    if (flag1 == 1) {
                        temp1 = Slots - Evening;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Evening has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else if (flag2 == 1) {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Night;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Night has " + temp2 + " Slots.");
                    } else {
                        temp1 = Slots - Morning;
                        temp2 = Slots - Evening;
                        JOptionPane.showMessageDialog(this, "This time slot slot is full. Morning has " + temp1
                                + " Slots. Evening has " + temp2 + " Slots.");
                    }
                } else {

                    BasicDBObject doc = new BasicDBObject("First_Name", first_name.toLowerCase())
                            .append("Last_Name", last_name.toLowerCase()).append("Batch", Batches)
                            .append("Phone_Number", phone_number).append("Age", age)
                            .append("Username", username).append("Password", password)
                            .append("Address", address);
                    Gym_Collection.insert(doc);
                    jTextField1.setText("");
                    jTextField2.setText("");
                    jTextField3.setText("");
                    jTextField5.setText("");
                    jPassword1.setText("");
                    jPassword2.setText("");
                    jTextArea1.setText("");
                    jLabel9.setFont(new java.awt.Font("SansSerif", 3, 16)); // NOI18N
                    jLabel9.setForeground(new java.awt.Color(204, 255, 204));
                    jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
                    jLabel9.setText("Successfully Added");
                    jLabel9.setBounds(200, 10, 200, 40);

                    BasicDBObject newDocument = new BasicDBObject();
                    newDocument.append("$set", new BasicDBObject().append("Morning", Morning)
                            .append("Evening", Evening).append("Night", Night));

                    BasicDBObject searchQuery = new BasicDBObject().append("Slots", Slots);

                    Allot.update(searchQuery, newDocument);

                    setVisible(true);
                }
            }
        } catch (UnknownHostException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NumberFormatException e) {
            JOptionPane.showMessageDialog(this, "Please Check the Data types");
            jTextField1.setText("");
            jTextField2.setText("");
            jTextField3.setText("");
            jTextField5.setText("");
            jPassword1.setText("");
            jPassword2.setText("");
            jTextArea1.setText("");
        }
    }

    else if (ae.getSource() == jButton2) {
        this.setVisible(false);
        new Admin().setVisible(true);
    }
}

From source file:login_page.java

private void LoginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LoginActionPerformed
    // TODO add your handling code here:
    try {/*from w ww  . j a  v  a  2s  .  c  om*/
        int check = 0;
        userid = UserID.getText();
        password = Password.getText();
        submit = Login.getActionCommand();

        if (radio_check == -99)
            JOptionPane.showMessageDialog(null, "Please Chhose Admin/Employee");
        else {
            if (radio_check == 0) {
                if ((userid.equals("admin")) && (password.equals("password123"))) {
                    System.out.println("Done");

                    //TO connect theses two pages..
                    setVisible(false);
                    new Admin_rights().setVisible(true);
                } else {
                    JOptionPane.showMessageDialog(null, "Invalid Admin Login");
                }
            } else {
                MongoClient mc = new MongoClient("localhost", 27017);
                DB db = mc.getDB("parking_system");
                DBCollection collection = db.getCollection("employee_info");
                /*ISERT DOCUMENT 
                BasicDBObject doc = new BasicDBObject("userid",userid).append("password",password);
                collection.insert(doc);
                */
                DBCursor cursor = collection.find();
                DBObject obj;

                String temp_user, temp_pass;

                while (cursor.hasNext()) {
                    obj = (DBObject) cursor.next();

                    temp_user = obj.get("_id").toString();
                    temp_pass = obj.get("password").toString();

                    if ((userid.equals(temp_user)) && (password.equals(temp_pass))) {
                        System.out.println("Done");

                        //TO connect theses two pages..
                        setVisible(false);
                        /*new Vehicle_type_check().setVisible(true);*/
                        new Entry_OR_Exit().setVisible(true);
                        check = 1;
                        break;
                    }
                }
                if (check != 1) {
                    JOptionPane.showMessageDialog(null, "Authentication Failed!\nInvalid Login");
                }
            }
        }
    } catch (Exception e) {

    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadAbsen(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(new String[] { "Tanggal" },
            0) {/*from ww w .  j  a  va 2  s .c o m*/
        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblAbsen.setModel(m);
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("bukuabsen").find();
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    while (c.hasNext()) {
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) c.next().get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.BukuAbsen b = new achmad.rifai.erp1.entity.BukuAbsen(json);
        if (b.isDeleted())
            m.addRow(new Object[] { b.getTgl() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadBarang(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "KODE", "NAMA", "HARGA", "STOK" }, 0) {
        @Override/*from   w  ww  .  ja va  2  s. c  o m*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblBarang.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("barang").find();
    while (c.hasNext()) {
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) c.next().get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Barang b = new achmad.rifai.erp1.entity.Barang(json);
        if (b.isDeleted())
            m.addRow(new Object[] { b.getKode(), b.getNama(), b.getHarga(),
                    "" + b.getStok() + " " + b.getSatuan() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadAset(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Kode", "Golongan", "Posisi", "Keterangan" }, 0) {
        @Override//from w  w w.  j  a  va 2 s  . c  om
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblAset.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("rekening").find();
    while (c.hasNext()) {
        com.mongodb.DBObject o = c.next();
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) o.get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Rekening re = new achmad.rifai.erp1.entity.Rekening(json);
        if (re.isDeleted())
            m.addRow(new Object[] { re.getKode(), re.getGolongan(), re.getPosisi(), re.getKet() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadBonus(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new Object[] { "Kode", "Pegawai", "Bulan", "Tahun" }, 0) {
        private Class[] c = new Class[] { String.class, String.class, java.time.Month.class,
                java.time.Year.class };

        @Override/*from   ww  w .ja  v a2 s.  c o  m*/
        public boolean isCellEditable(int i, int i1) {
            return false;
        }

        @Override
        public Class<?> getColumnClass(int i) {
            return c[i];
        }
    };
    tblBonus.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("bulanbonus").find();
    while (c.hasNext()) {
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) c.next().get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.BulanBonus b = new achmad.rifai.erp1.entity.BulanBonus(json);
        if (b.isDeleted())
            m.addRow(new Object[] { b.getKode(), b.getPeg(), b.getBln(), b.getThn() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadJabatan(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "NAMA", "GAJI", "KAPASITAS" }, 0) {
        @Override/*w  w w.jav a2s .  c  om*/
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblJabatan.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("jabatan").find();
    while (c.hasNext()) {
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) c.next().get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Jabatan j = new achmad.rifai.erp1.entity.Jabatan(json);
        if (j.isDeleted())
            m.addRow(new Object[] { j.getNama(), j.getGaji(), j.getKapasitas() });
    }
}

From source file:achmad.rifai.admin.ui.Sampah.java

private void loadJurnal(Db d) throws Exception {
    javax.swing.table.DefaultTableModel m = new javax.swing.table.DefaultTableModel(
            new String[] { "Kode", "No", "Tanggal", "Keterangan", "Debit", "Kredit" }, 0) {
        @Override// w w  w . j a v a2 s . co m
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tblJurnal.setModel(m);
    achmad.rifai.erp1.util.RSA r = achmad.rifai.erp1.util.Work.loadRSA();
    com.mongodb.DBCursor c = d.getD().getCollectionFromString("jurnal").find();
    while (c.hasNext()) {
        com.mongodb.BasicDBList li = (com.mongodb.BasicDBList) c.next().get("bin");
        String json = "";
        for (int x = 0; x < li.size(); x++)
            json += r.decrypt("" + li.get(x));
        achmad.rifai.erp1.entity.Jurnal j = new achmad.rifai.erp1.entity.Jurnal(json);
        if (j.isDeleted())
            m.addRow(new Object[] { j.getKode(), j.getNo(), j.getTgl(), j.getKet(), j.getDebit(),
                    j.getKredit() });
    }
}