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:analizadorTweet.SavePE.java

License:Apache License

public void onEvent(Event event) {

    if (ImprimerEventoLlegada) {
        System.out.println("Pe: " + event.get("SaveId"));
        System.out.println("@" + event.get("User"));
        System.out.println(event.get("Text"));
        System.out.println("Location: " + event.get("Location"));
        System.out.println("Timestamp: " + event.get("Timestamp"));

        System.out.println("earthPos: " + event.get("earthPos"));
        System.out.println("earthNeg: " + event.get("earthNeg"));
        System.out.println("earthSub: " + event.get("earthSub"));
        System.out.println("earthNeu: " + event.get("earthNeu"));

        System.out.println("elhPos: " + event.get("elhPos"));
        System.out.println("elhNeg: " + event.get("elhNeg"));

        System.out.println("subScore: " + event.get("subScore"));
        System.out.println("earthSub: " + event.get("earthSub"));
        System.out.println("label: " + event.get("label"));

        System.out.println("-------------------------------------------");
    }//from  w ww  .j  av a  2  s.  com

    if (ImprimirDelay) {

        java.util.Date date = new java.util.Date();
        Long Tfinal = Calendar.getInstance().getTimeInMillis();
        Long Tinicio = Long.parseLong(event.get("Location"));

        System.out.println("PE: " + event.get("SaveId") + " delay: " + (Tfinal - Tinicio));

    }

    java.util.Date date = new java.util.Date();
    Long Tfinal = Calendar.getInstance().getTimeInMillis();
    Long Tinicio = Long.parseLong(event.get("Location"));

    //Aca hago el Save en mongo       
    DBObject tweet = new BasicDBObject();

    tweet.put("Content", event.get("Text"));
    tweet.put("Delay", Tfinal - Tinicio);

    mongo.setupMongo();
    mongo.insert(tweet);

    seen = true;
}

From source file:App.modules.main_menu.model.dao.Sign_in_DAO.java

public static int Select_Admin_dni_mongo() {
    DBCursor cursor = null;//from  w w w  .j  av a 2 s  . c  o m
    int ok = 0;
    Singleton_App.c = new Client();

    try {

        BasicDBObject query = new BasicDBObject();
        query.put("user", Sign_in.User_txt.getText());
        query.put("pass", Sign_in.Pass_txt.getText());

        // BasicDBObject searchById = new BasicDBObject();
        // searchById.append("dni", 1).append("_id",0);

        cursor = Singleton_App.collection.find(query);

        if (cursor.count() != 0) {

            while (cursor.hasNext()) {

                BasicDBObject document = (BasicDBObject) cursor.next();

                Singleton_App.c = Singleton_App.c.Client_to_DB(document);

                ok = 1;

            }
        } else {

            ok = 0;
            // JOptionPane.showMessageDialog(null, "Cliente no encontrado "+ ok);
            // System.out.println("NOT DATA"); 

        }
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }

    // JOptionPane.showMessageDialog(null, Singleton_App.c);
    return ok;

}

From source file:app.modules.SignIn.model.DAO_Login.java

/**
 * Compara el nombre de usuario con el de todos los clientes de la base de datos, cuando encuentra una coincidencia
 * compara la contrasea introducida con la de la base de datos, cuando ambos datos coinciden devuelve true y
 * rellena el perfil del usuario/*from w w  w  .j  av  a  2 s  . com*/
 * @return login True si se ha logrado iniciar sesin
 */
public static boolean SignInClient() {
    boolean login = false;
    DBCursor cursor = null;
    client c = new client();
    try {
        cursor = singleton_global.collection.find(new BasicDBObject().append("user", addusername.getText()));
        if (cursor.count() != 0) {
            for (int i = 0; i < cursor.size(); i++) {
                BasicDBObject document = (BasicDBObject) cursor.next();
                c = c.BBDD_to_client(document);
                fecha aux = new fecha();
                if (c.getPass().equals(addpass.getText())) {
                    new client_controller(new clientnew_view(), 2).Iniciar(2);
                    adddnic.setText(c.getDni());
                    caddname.setText(c.getName());
                    caddsurname.setText(c.getSubname());
                    caddmobile.setText(c.getMobile());
                    caddemail.setText(c.getEmail());
                    cadddatebirthday.setCalendar(aux.stringtocalendar(c.getDate_birthday()));
                    caddnameuser.setText(c.getUser());
                    caddpassword.setText(c.getPass());
                    caddavatar.setText(c.getAvatar());
                    cadd_status.setSelectedItem(c.getState());
                    caddreg.setCalendar(aux.stringtocalendar(c.getUp_date()));
                    caddshopping.setText(Float.toString(c.getShopping()));
                    caddpremium.setSelectedItem(c.getPremium());
                    caddtype.setText(c.getClient_type());
                    login = true;
                    if ("Premium".equals(c.getPremium())) {
                        cadddesc.setText("10%");
                    } else {
                        cadddesc.setText("0%");
                    }
                    caddyearsservice.setText(Integer.toString(
                            aux.restafechas(aux.stringtocalendar(c.getUp_date()), aux.fechasystem(), "years")));
                }
            }
        } else {
            System.out.println("NOT DATA");
        }
    } catch (Exception e) {
        if (cursor != null) {
            cursor.close();
        }
    }
    return login;
}

From source file:App.modules.users.Client.Model.dao.Client_DB_DAO.java

public static void delete_Client_by_dni(String dni) {
    Singleton_App.collection.remove(new BasicDBObject().append("dni", dni));
}

From source file:App.modules.users.Client.Model.dao.Client_DB_DAO.java

public static void update_Client(Client c) {
    //Prepara para insertar un nuevo campo
    BasicDBObject update = new BasicDBObject();

    update.append("$set", new BasicDBObject(c.to_DB_Client()));

    /**//  w ww. ja va  2  s . c  o  m
    update.append("$set", new BasicDBObject().append("nom", c.getNom()) .append("cognom", c.getCognom()) 
        .append("date_birthday", c.getDate_birthday().toStrinng()) 
    .append("mobil", c.getMobil()) .append("email", c.getEmail()) .append("avatar", c.getAvatar())
        .append("user", c.getUser()) .append("pass", c.getPass())
    .append("pass", c.getPass()) .append("status", c.getstatus())
        .append("f_alta", c.getF_alta().toStrinng()) 
    .append("compra$", c.getCompra$()) .append("premium", c.isPremium()) 
        .append("client_type", c.getClient_type()) .append("benefits", c.getbenefits())
    .append("age", c.getAge()) .append("antiguedad", c.getAntiguedad()) );   
    */

    //Busca el/los registro/s con el nombre indicado
    BasicDBObject searchById = new BasicDBObject();
    searchById.append("dni", c.getDni());

    //Realiza la actualizacin
    Singleton_App.collection.updateMulti(searchById, update);
}

From source file:app.modules.users.client.model.DAO.DAO_client.java

/**
 * Comprueba que todos los datos sean correctos y los guarda sobre los antiguos
 * @return True si se ha modificado correctamente
*//* w ww  .j  a  v a 2  s  . c o m*/
public static boolean saveeditclient() {
    boolean val = false;
    if (pidedni() && pidenombre() && pideapellidos() && pidefechanacimiento() && pidetelefono() && pideemail()
            && pideusuario() && pidecontrasenya() && pidefecharegistro() && pidecompras() && pidetipo()) {
        if ("admin".equals(singleton_global.type)) {
            String dni = clientnew_view.adddnic.getText();
            String name = clientnew_view.caddname.getText();
            String surname = clientnew_view.caddsurname.getText();
            String mobile = clientnew_view.caddmobile.getText();
            String email = clientnew_view.caddemail.getText();
            fecha aux = new fecha();
            String datebirthday = aux.calendartostring(clientnew_view.cadddatebirthday.getCalendar(), 0);
            String nameuser = clientnew_view.caddnameuser.getText();
            String passwd = clientnew_view.caddpassword.getText();
            String avatar = clientnew_view.caddavatar.getText();
            String status = clientnew_view.cadd_status.getSelectedItem().toString();
            String update = aux.calendartostring(clientnew_view.caddreg.getCalendar(), 0);
            float shopping = Float.parseFloat(clientnew_view.caddshopping.getText());
            String premium = clientnew_view.caddpremium.getSelectedItem().toString();
            String type = clientnew_view.caddtype.getText();
            int inicio = (pagina.currentPageIndex - 1) * pagina.itemsPerPage;
            selectedcli = TABLA.getSelectedRow();
            int selected1 = inicio + selectedcli;
            BLL_client.UpdateClientMongo(singleton_client.client.getClient(selected1).getDni());
            singleton_client.client.getClient(selected1).setDni(dni);
            singleton_client.client.getClient(selected1).setName(name);
            singleton_client.client.getClient(selected1).setSubname(surname);
            singleton_client.client.getClient(selected1).setMobile(mobile);
            singleton_client.client.getClient(selected1).setEmail(email);
            singleton_client.client.getClient(selected1).setDate_birthday(datebirthday);
            singleton_client.client.getClient(selected1).setUser(nameuser);
            singleton_client.client.getClient(selected1).setPass(passwd);
            singleton_client.client.getClient(selected1).setAvatar(avatar);
            singleton_client.client.getClient(selected1).setState(status);
            singleton_client.client.getClient(selected1).setUp_date(update);
            singleton_client.client.getClient(selected1).setShopping(shopping);
            singleton_client.client.getClient(selected1).setPremium(premium);
            singleton_client.client.getClient(selected1).setClient_type(type);

            val = true;
        } else {
            client c = new client();
            DBCursor cursor = singleton_global.collection
                    .find(new BasicDBObject().append("dni", adddnic.getText()));
            for (int i = 0; i < cursor.size(); i++) {
                BasicDBObject document = (BasicDBObject) cursor.next();
                c = c.BBDD_to_client(document);
                if (c.getDni().equals(adddnic.getText())) {
                    c.setDni(clientnew_view.adddnic.getText());
                    c.setName(clientnew_view.caddname.getText());
                    c.setSubname(clientnew_view.caddsurname.getText());
                    c.setMobile(clientnew_view.caddmobile.getText());
                    c.setEmail(clientnew_view.caddemail.getText());
                    fecha aux = new fecha();
                    c.setDate_birthday(aux.calendartostring(clientnew_view.cadddatebirthday.getCalendar(), 0));
                    c.setUser(clientnew_view.caddnameuser.getText());
                    c.setPass(clientnew_view.caddpassword.getText());
                    c.setAvatar(clientnew_view.caddavatar.getText());
                    c.setState(clientnew_view.cadd_status.getSelectedItem().toString());
                    c.setUp_date(aux.calendartostring(clientnew_view.caddreg.getCalendar(), 0));
                    c.setShopping(Float.parseFloat(clientnew_view.caddshopping.getText()));
                    c.setPremium(clientnew_view.caddpremium.getSelectedItem().toString());
                    c.setClient_type(clientnew_view.caddtype.getText());
                    BLL_client.UpdateClientMongo(c.getDni());
                }
            }
            val = true;
        }
    }
    return val;
}

From source file:app.modules.users.client.model.DAO.DAO_Mongo.java

/**
 * Selecciona un cliente por el DNI y modifica sus campos
 * @param dni /*from ww  w  .j  a v  a 2 s .c  o m*/
 */
public static void update_client(String dni) {
    fecha aux = new fecha();
    //Prepara para insertar un nuevo campo
    BasicDBObject updateDni = new BasicDBObject(), updateName = new BasicDBObject(),
            updateSurname = new BasicDBObject(), updateMobile = new BasicDBObject(),
            updateEmail = new BasicDBObject(), updateDate_birthday = new BasicDBObject(),
            updateName_user = new BasicDBObject(), updatePasswd = new BasicDBObject(),
            updateAvatar = new BasicDBObject(), updateState = new BasicDBObject(),
            updateUp_date = new BasicDBObject(), updateShopping = new BasicDBObject(),
            updatePremium = new BasicDBObject(), updateClient_type = new BasicDBObject();
    updateDni.append("$set", new BasicDBObject().append("dni", clientnew_view.adddnic.getText()));
    updateName.append("$set", new BasicDBObject().append("name", clientnew_view.caddname.getText()));
    updateSurname.append("$set", new BasicDBObject().append("subname", clientnew_view.caddsurname.getText()));
    updateMobile.append("$set", new BasicDBObject().append("mobile", clientnew_view.caddmobile.getText()));
    updateEmail.append("$set", new BasicDBObject().append("email", clientnew_view.caddemail.getText()));
    updateDate_birthday.append("$set", new BasicDBObject().append("date_birthday",
            aux.calendartostring(clientnew_view.cadddatebirthday.getCalendar(), 0)));
    updateName_user.append("$set", new BasicDBObject().append("user", clientnew_view.caddnameuser.getText()));
    updatePasswd.append("$set", new BasicDBObject().append("pass", clientnew_view.caddpassword.getText()));
    updateAvatar.append("$set", new BasicDBObject().append("avatar", clientnew_view.caddavatar.getText()));
    updateState.append("$set",
            new BasicDBObject().append("state", clientnew_view.cadd_status.getSelectedItem().toString()));
    updateUp_date.append("$set", new BasicDBObject().append("up_date",
            aux.calendartostring(clientnew_view.caddreg.getCalendar(), 0)));
    updateShopping.append("$set",
            new BasicDBObject().append("shopping", Float.parseFloat(clientnew_view.caddshopping.getText())));
    updatePremium.append("$set",
            new BasicDBObject().append("premium", clientnew_view.caddpremium.getSelectedItem().toString()));
    updateClient_type.append("$set",
            new BasicDBObject().append("client_type", clientnew_view.caddtype.getText()));
    //Busca el/los registro/s con el nombre indicado
    BasicDBObject searchById = new BasicDBObject();
    searchById.append("dni", dni);

    //Realiza la actualizacin
    singleton_global.collection.updateMulti(searchById, updateDni);
    singleton_global.collection.updateMulti(searchById, updateName);
    singleton_global.collection.updateMulti(searchById, updateSurname);
    singleton_global.collection.updateMulti(searchById, updateMobile);
    singleton_global.collection.updateMulti(searchById, updateEmail);
    singleton_global.collection.updateMulti(searchById, updateDate_birthday);
    singleton_global.collection.updateMulti(searchById, updateName_user);
    singleton_global.collection.updateMulti(searchById, updatePasswd);
    singleton_global.collection.updateMulti(searchById, updateAvatar);
    singleton_global.collection.updateMulti(searchById, updateState);
    singleton_global.collection.updateMulti(searchById, updateUp_date);
    singleton_global.collection.updateMulti(searchById, updateShopping);
    singleton_global.collection.updateMulti(searchById, updatePremium);
    singleton_global.collection.updateMulti(searchById, updateClient_type);
}

From source file:app.modules.users.client.model.DAO.DAO_Mongo.java

/**
 * Selecciona un cliente por su DNI y lo elimina
 * @param dni /*from   w w w  .  j  av  a  2 s.  co m*/
 */
public static void delete_client(String dni) {
    singleton_global.collection.remove(new BasicDBObject().append("dni", dni));
}

From source file:application.modules.client.model.DAO.daoC.java

public static void delete_worker(String dni) {
    SingletonF.collection.remove(new BasicDBObject().append("dni", dni));
}

From source file:application.modules.client.model.DAO.daoC.java

public static void update_worker(String dni) {
    //Prepara para insertar un nuevo campo
    BasicDBObject updateDni = new BasicDBObject(), updateName = new BasicDBObject(),
            updateSurname = new BasicDBObject(), updatePhone = new BasicDBObject(),
            updateEmail = new BasicDBObject(), updateUser = new BasicDBObject(),
            updatePass = new BasicDBObject(), updateAvatar = new BasicDBObject(),
            updateState = new BasicDBObject(), updateDate_birthday = new BasicDBObject(),
            updateClient_type = new BasicDBObject(), updatePremium = new BasicDBObject(),
            updateDischarge_date = new BasicDBObject();
    updateDni.append("$set", new BasicDBObject().append("dni", new_client_view.dniField.getText()));
    updateName.append("$set", new BasicDBObject().append("name", new_client_view.nameField.getText()));
    updateSurname.append("$set", new BasicDBObject().append("subname", new_client_view.subnameField.getText()));
    updatePhone.append("$set",
            new BasicDBObject().append("phone_number", new_client_view.phoneField.getText()));
    updateEmail.append("$set", new BasicDBObject().append("email", new_client_view.emailField.getText()));
    updateUser.append("$set", new BasicDBObject().append("user", new_client_view.usernameField.getText()));
    updatePass.append("$set", new BasicDBObject().append("pass", new_client_view.passwordField.getText()));
    updateAvatar.append("$set", new BasicDBObject().append("avatar", new_client_view.avatarField.getText()));
    updateState.append("$set", new BasicDBObject().append("state", new_client_view.statusField.getText()));
    updateClient_type.append("$set",
            new BasicDBObject().append("client_type", new_client_view.client_typeField.getText()));
    Dates d = new Dates("");
    updateDate_birthday.append("$set", new BasicDBObject().append("date_birthday",
            d.DateToString(new_client_view.datebirthdayField.getCalendar(), 0)));
    updateDischarge_date.append("discharge_date",
            d.DateToString(new_client_view.dischargedateField.getCalendar(), 0));
    updatePremium.append("$set",
            new BasicDBObject().append("premium", new_client_view.premiumCheckbox.isSelected()));
    //Busca el/los registro/s con el nombre indicado
    BasicDBObject searchById = new BasicDBObject();
    searchById.append("dni", dni);

    //Realiza la actualizacin
    SingletonF.collection.updateMulti(searchById, updateDni);
    SingletonF.collection.updateMulti(searchById, updateName);
    SingletonF.collection.updateMulti(searchById, updateSurname);
    SingletonF.collection.updateMulti(searchById, updatePhone);
    SingletonF.collection.updateMulti(searchById, updateEmail);
    SingletonF.collection.updateMulti(searchById, updateUser);
    SingletonF.collection.updateMulti(searchById, updatePass);
    SingletonF.collection.updateMulti(searchById, updateAvatar);
    SingletonF.collection.updateMulti(searchById, updateState);
    SingletonF.collection.updateMulti(searchById, updateDate_birthday);
    SingletonF.collection.updateMulti(searchById, updateClient_type);
    SingletonF.collection.updateMulti(searchById, updatePremium);
}