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(final Map map) 

Source Link

Document

Creates an object from a map.

Usage

From source file:mail.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    int success = 0;
    String id = request.getParameter("email");
    System.out.println(id);/*  w w w. j a v a 2s . co m*/
    //String id="anjaliverma25792@gmail.com";
    MongoClient mongo = new MongoClient();
    DB db = mongo.getDB("WebDB");
    DBCollection table = db.getCollection("User");
    Document d = new Document();
    d.put("Email", id);
    DBObject ob = new BasicDBObject(d);
    DBCursor cur = table.find(ob);
    System.out.println(cur.size());
    System.out.println("Above value");
    String user = null;
    if (cur.hasNext()) {
        success = 1;
        cur.next();
        DBObject temp = cur.curr();
        String pass = (String) temp.get("Password");

        HttpSession session = request.getSession();
        user = (String) temp.get("Name");

        final String username = "nature.lover.ritika@gmail.com";
        final String password = "ritika7vision";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.port", "587");

        Session sess = Session.getInstance(props, new javax.mail.Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
        });

        try {
            Message message = new MimeMessage(sess);
            message.setFrom(new InternetAddress("papertree.official@gmail.com"));
            message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(id)); //retrive email id from forgot your password form.
            message.setSubject("PaperTree: Password Reset");
            message.setText("Dear, " + user + ". Your password is " + pass
                    + ". \n\n Directly LOGIN And START READING...");

            Transport.send(message);

            // Mongo DB connectivity LEFT 

            //                        response.sendRedirect("success.jsp");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }

    }
    if (success == 1) {
        response.sendRedirect("success.jsp?success=yes");

    } else {
        response.sendRedirect("success.jsp?success=no");

    }
}

From source file:bd.DArticulo.java

@Override
public String insertar(Object o) {
    CArticulo x = (CArticulo) o;// ww w .  j a  v a 2 s . c om

    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().insert(datos);
    con.end();
    return datos.getString("_id");
}

From source file:bd.DArticulo.java

@Override
public String modificar(Object o) {
    CArticulo x = (CArticulo) o;/*w  w w . j  a va 2 s.  c  o  m*/
    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().update(new BasicDBObject("_id", x.getId()), datos);
    con.end();
    return x.getId().toString();
}

From source file:bd.DArticulo.java

@Override
public ArrayList listar(HashMap map) {
    ArrayList datos = new ArrayList();
    CArticulo x = new CArticulo();
    conecion con = new conecion(table);
    BasicDBObject id = new BasicDBObject(map);
    DBCursor cursor = con.get_colletion().find(id);

    try {/*w w w .ja  v a  2s.  c o m*/
        while (cursor.hasNext()) {
            x = new CArticulo();
            x.set_datos((HashMap) cursor.next().toMap());
            datos.add(x);
        }
    } finally {
        cursor.close();
    }
    con.end();

    return datos;
}

From source file:bd.DCategoria.java

@Override
public String insertar(Object o) {
    CCategoria x = (CCategoria) o;//from  w  ww  .  j  ava  2 s  . c  om

    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().insert(datos);
    con.end();
    return datos.getString("_id");
}

From source file:bd.DCategoria.java

@Override
public String modificar(Object o) {
    CCategoria x = (CCategoria) o;/*from  w w w  .j  a  v a2s .com*/
    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().update(new BasicDBObject("_id", x.getId()), datos);
    con.end();
    return x.getId().toString();
}

From source file:bd.DCategoria.java

@Override
public ArrayList listar(HashMap map) {
    ArrayList datos = new ArrayList();
    CCategoria x = new CCategoria();
    conecion con = new conecion(table);
    BasicDBObject id = new BasicDBObject(map);
    DBCursor cursor = con.get_colletion().find(id);

    try {/*from w w w . java  2 s .  c  o  m*/
        while (cursor.hasNext()) {
            x = new CCategoria();
            x.set_datos((HashMap) cursor.next().toMap());
            datos.add(x);
        }
    } finally {
        cursor.close();
    }
    con.end();

    return datos;
}

From source file:bd.DPersona.java

@Override
public String insertar(Object o) {
    CPersona x = (CPersona) o;//ww w .ja va 2 s  .c o  m

    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().insert(datos);
    con.end();
    return datos.getString("_id");
}

From source file:bd.DPersona.java

@Override
public String modificar(Object o) {
    CPersona x = (CPersona) o;/*from w w w  .j  av a  2s  .  co m*/
    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().update(new BasicDBObject("_id", x.getId()), datos);
    con.end();
    return x.getId().toString();
}

From source file:bd.DPersona.java

@Override
public ArrayList listar(HashMap map) {
    ArrayList datos = new ArrayList();
    CPersona x = new CPersona();
    conecion con = new conecion(table);
    BasicDBObject id = new BasicDBObject(map);
    DBCursor cursor = con.get_colletion().find(id);

    try {//w  w  w.j a  va  2  s  .  co  m
        while (cursor.hasNext()) {
            x = new CPersona();
            x.set_datos((HashMap) cursor.next().toMap());
            datos.add(x);
        }
    } finally {
        cursor.close();
    }
    con.end();

    return datos;
}