Example usage for com.mongodb BasicDBList get

List of usage examples for com.mongodb BasicDBList get

Introduction

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

Prototype

public Object get(final String key) 

Source Link

Document

Gets a value at an index.

Usage

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();
    }/* w ww  .ja v a2 s.c o  m*/

    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   ww  w.  j ava  2s .c  o 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);

            }

        }

    }

}

From source file:Parent.java

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

    DBCollection coll = db.getCollection("parent");
    BasicDBObject andQuery = new BasicDBObject();
    List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    obj.add(new BasicDBObject("firstname", firstname));
    obj.add(new BasicDBObject("lastname", lastname));

    andQuery.put("$and", obj);
    DBCursor cursor = coll.find(andQuery);
    while (cursor.hasNext()) {
        BasicDBList sons = (BasicDBList) cursor.next().get("sons");
        String data[] = new String[sons.size()];
        for (int j = 0; j < sons.size(); ++j) {
            BasicDBObject son = (BasicDBObject) sons.get(j);
            data[j] = son.get("name").toString();

        }/* w  w  w.  ja v  a 2 s.com*/

        SonList.setListData(data);

    }
}

From source file:Parent.java

private void SonListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_SonListValueChanged
    // TODO add your handling code here:
    if (!evt.getValueIsAdjusting()) {
        DefaultTableModel model = (DefaultTableModel) jTable1.getModel();
        model.setRowCount(0);//w  w  w  .j a  va  2  s .  com

        String selected = SonList.getSelectedValue();
        DBCollection coll = db.getCollection("student");
        BasicDBObject andQuery = new BasicDBObject();
        List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
        obj.add(new BasicDBObject("firstname", selected));
        obj.add(new BasicDBObject("mid_name", firstname));
        obj.add(new BasicDBObject("lastname", lastname));
        andQuery.put("$and", obj);
        DBCursor cursor = coll.find(andQuery);
        while (cursor.hasNext()) {

            BasicDBList marks = (BasicDBList) cursor.next().get("marks");
            for (int j = 0; j < marks.size(); ++j) {
                BasicDBObject mark = (BasicDBObject) marks.get(j);
                String material = mark.get("course").toString();
                String teacher = mark.get("teacher").toString();
                if (mark.get("mid") == null) {

                    Object[] row = { material, teacher, "not readay", "not ready" };
                    model.addRow(row);

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

                    Object[] row = { material, teacher, mark.get("mid"), "not ready" };
                    model.addRow(row);
                } else {

                    Object[] row = { material, teacher, mark.get("mid"), mark.get("final") };
                    model.addRow(row);

                }
            }
        }
    }

}

From source file:TeacherOne.java

private void GetdataBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GetdataBtnActionPerformed
    // TODO add your handling code here:
    stuFirst = FirstnameField.getText();
    stuMid = MidnameField.getText();/*from   w  ww .j a  v  a2s.c  om*/
    stuLast = LastnameField.getText();
    grade = Integer.parseInt(GradeField.getText());
    section = Integer.parseInt(SectionField.getText());
    DBCollection coll = db.getCollection("student");
    BasicDBObject andQuery = new BasicDBObject();
    List<BasicDBObject> obj = new ArrayList<BasicDBObject>();
    obj.add(new BasicDBObject("firstname", stuFirst));
    obj.add(new BasicDBObject("mid_name", stuMid));
    obj.add(new BasicDBObject("lastname", stuLast));
    obj.add(new BasicDBObject("grade", grade));
    obj.add(new BasicDBObject("section", section));

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

    if (cursor.count() != 0) {
        UpdateBtn.setVisible(true);
        MidField.setVisible(true);
        FinalField.setVisible(true);
        jLabel6.setVisible(true);
        jLabel7.setVisible(true);
        jLabel8.setVisible(true);

        BasicDBList marks = (BasicDBList) cursor.next().get("marks");
        for (int j = 0; j < marks.size(); ++j) {
            BasicDBObject mark = (BasicDBObject) marks.get(j);

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

                }

            }
        }
    } else {
        JOptionPane.showMessageDialog(null, "wrong data,try again!");
        FirstnameField.setText("");
        MidnameField.setText("");
        LastnameField.setText("");
        GradeField.setText("");
        SectionField.setText("");
    }
}

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  w ww  .  ja v  a  2s  . com
        @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 www .j ava  2 s.co  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   www .ja va 2s .c o m*/
        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   w  ww. j av  a  2 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/*from w w  w. j  a v a2  s  .  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() });
    }
}