List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:app.model.Model.java
public void setTable(JTable table, String collection) { DBCollection col = this.getCollection(collection); DBCursor cur = col.find(); String[] columnNames = { "id", "CIDADE", "UF" }; DefaultTableModel model = new DefaultTableModel(columnNames, 0); while (cur.hasNext()) { DBObject obj = cur.next();//from ww w.j av a 2 s . c o m String cidade = (String) obj.get("CIDADE"); String uf = (String) obj.get("UF"); ObjectId id = (ObjectId) obj.get("_id"); model.addRow(new Object[] { id, cidade, uf }); } cur.close(); table.setModel(model); }
From source file:App.modules.main_menu.model.dao.Sign_in_DAO.java
public static int Select_Admin_dni_mongo() { DBCursor cursor = null; int ok = 0;// w w w . jav a 2 s .c om 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 ww.j av a2 s. c o m * @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
/** * //ww w . j a v a 2 s . co m */ public static void print_table() { DBCursor cursor = null; // String rdo = ""; Client c = new Client(); Singleton_cli.cli.clear(); try { cursor = Singleton_App.collection.find(); if (cursor.count() != 0) { while (cursor.hasNext()) { BasicDBObject document = (BasicDBObject) cursor.next(); // JOptionPane.showMessageDialog(null, c.toString()); Singleton_cli.cli.add(c.Client_to_DB(document)); // JOptionPane.showMessageDialog(null, Singleton_cli.cli.toString()); // rdo = rdo + (c.getNombre() + " - " + w.getApellidos() + " - " +w.getEdad() + "\n"); } } else { System.out.println("NOT DATA"); } } finally { if (cursor != null) { cursor.close(); } } //return rdo; }
From source file:app.modules.users.client.model.DAO.DAO_Mongo.java
/** * Lee todos los clientes de la bbdd para mostrarlos en nuestra app */// w w w.j a va2 s. c o m public static void read_client() { DBCursor cursor = null; client c = new client(); try { cursor = singleton_global.collection.find(); if (cursor.count() != 0) { for (int i = 0; i < cursor.size(); i++) { BasicDBObject document = (BasicDBObject) cursor.next(); c = c.BBDD_to_client(document); client j = new client(c.getDni(), c.getName(), c.getSubname(), c.getMobile(), c.getEmail(), c.getDate_birthday(), c.getUser(), c.getPass(), c.getAvatar(), c.getState(), c.getUp_date(), c.getShopping(), c.getPremium(), c.getClient_type()); singleton_client.client.AddClient(j); } } else { System.out.println("NOT DATA"); } } catch (Exception e) { if (cursor != null) { cursor.close(); } } }
From source file:app.ui.Init.java
public void setTable() { String collection = cbDelta.getSelectedItem().toString().trim() + "_formated_" + cbOL.getSelectedItem().toString().toLowerCase().replace("-", ""); collection = collection.replace("rollup", "dice_rollup"); collection = collection.replace("drilldown", "dice_drilldown_formated"); DBCollection col = model.getCollection(collection); DBCursor cur = col.find(); String[] columnNames = Util.getAttsNames(collection); String[] pseudoColumns = new String[columnNames.length + 1]; String[] values = new String[columnNames.length + 1]; for (int i = 0; i < columnNames.length; i++) { pseudoColumns[i] = columnNames[i]; }// w w w .j av a2s.c o m pseudoColumns[pseudoColumns.length - 1] = lsM.getSelectedValue().toString().trim(); DefaultTableModel model = new DefaultTableModel(pseudoColumns, 0); for (int i = 0; i < pseudoColumns.length; i++) { pseudoColumns[i] = "_key" + (1 + i); } pseudoColumns[pseudoColumns.length - 1] = "_value"; while (cur.hasNext()) { DBObject obj = cur.next(); for (int i = 0; i < values.length - 1; i++) { values[i] = (String) obj.get(pseudoColumns[i]); } values[values.length - 1] = obj.get(pseudoColumns[values.length - 1]).toString(); /*String cidade = (String) obj.get("CIDADE"); String uf = (String) obj.get("UF"); ObjectId id = (ObjectId) obj.get("_id"); */ //model.addRow(new Object[]{id, cidade, uf}); //model.addRow(new Object[]{values}); Object[] newObj = new Object[values.length]; //{values} for (int i = 0; i < values.length; i++) { newObj[i] = values[i]; } model.addRow(newObj); } cur.close(); tbCR.setModel(model); }
From source file:backend.facades.UserController.java
public List<UserEntity> getUserList() { List<UserEntity> userList = new ArrayList<UserEntity>(); String sort = "registeredDate"; String order = "desc"; DBObject sortCriteria = new BasicDBObject(sort, "desc".equals(order) ? -1 : 1); BasicDBObject query = new BasicDBObject(); DBCursor cursor = userCollection.find(query).sort(sortCriteria); try {// w w w . java 2 s. c o m while (cursor.hasNext()) { DBObject document = cursor.next(); UserEntity userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); Integer value = (Integer) document.get("subscribe"); userEntity.setPersonalWebPage((String) document.get("webpage")); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } userList.add(userEntity); } } finally { cursor.close(); } return userList; }
From source file:backend.facades.UserController.java
public List<UserEntity> getSubscribersList() { UserEntity userEntity = null;// www. j a v a2 s . com List<UserEntity> userList = new ArrayList<UserEntity>(); BasicDBObject query = new BasicDBObject(); query.put("subscribe", StatusTypes.ACCEPT_SUBSCRB); DBCursor cursor = userCollection.find(query); try { while (cursor.hasNext()) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); userEntity.setPersonalWebPage((String) document.get("webpage")); Integer value = (Integer) document.get("subscribe"); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } userList.add(userEntity); } } finally { cursor.close(); } return userList; }
From source file:backend.facades.UserController.java
public UserEntity getUserByEmail(String email) { UserEntity userEntity = null;/*from ww w . j a va2 s . c om*/ BasicDBObject query = new BasicDBObject(); query.put("email", email); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); userEntity.setPersonalWebPage((String) document.get("webpage")); Integer value = (Integer) document.get("subscribe"); if (value != null && value.equals(StatusTypes.ACCEPT_LICENSE)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } } } finally { cursor.close(); } return userEntity; }
From source file:backend.facades.UserController.java
public UserEntity getUserById(Long id) { UserEntity userEntity = null;//w ww. jav a2 s . c om BasicDBObject query = new BasicDBObject(); query.put("_id", id); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); userEntity = new UserEntity(); userEntity.setId((Long) document.get("_id")); userEntity.setUsername((String) document.get("username")); userEntity.setEmail((String) document.get("email")); userEntity.setFirstname((String) document.get("firstname")); userEntity.setPasswd((String) document.get("passwd")); userEntity.setLastname((String) document.get("lastname")); userEntity.setStatus((Integer) document.get("status")); userEntity.setImageId((String) document.get("imageId")); userEntity.setRegisteredDate((Date) document.get("registeredDate")); userEntity.setLastLoginDate((Date) document.get("lastLoginDate")); userEntity.setLanguageCode((String) document.get("languageCode")); userEntity.setUserRole((Integer) document.get("userRole")); userEntity.setModeratorValue((Integer) document.get("moderator")); Integer value = (Integer) document.get("subscribe"); userEntity.setPersonalWebPage((String) document.get("webpage")); if (value != null && value.equals(StatusTypes.ACCEPT_SUBSCRB)) { userEntity.setAcceptSubscr(true); } else { userEntity.setAcceptSubscr(false); } } } finally { cursor.close(); } return userEntity; }