List of usage examples for com.mongodb DBCursor next
@Override
public DBObject next()
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]; }//from w ww. j a va 2 s . co 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:applango.common.services.DB.mongo.mongoDB.java
public static DBObject getRollupValue(DBCollection coll, String userId) { logger.info("Getting today's rollup record for user " + userId); DBCursor cursor; int maxWait = 10; try {/*w w w.ja va 2s . c o m*/ DateTime jsonToday = new DateTime(); DateTime yesterday = new DateTime().minusDays(1); Date yesterdayDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse(yesterday.toString()); BasicDBObject dateQueryObj = new BasicDBObject("beginDate", new BasicDBObject("$gt", yesterdayDate)); dateQueryObj.append("userId", userId); dateQueryObj.append("customerId", "automationCustomer"); dateQueryObj.append("appName", "salesforce"); cursor = coll.find(dateQueryObj); while ((cursor.count() == 0) && maxWait > 0) { sleep(1000); maxWait--; } } catch (Exception ex) { cursor = null; logger.error(ex.getMessage()); } return cursor.next(); }
From source file:application.modules.client.model.DAO.daoC.java
public static void retrieve_admins() { //DBCollection dbCollection = db.getCollection(tableName); client c = new client(); DBCursor cur = collection.find(); for (int i = 0; i < cur.size(); i++) { BasicDBObject document = (BasicDBObject) cur.next(); c = c.DB_to_client(document);/*from w ww. j av a2 s.co m*/ client d = new client(c.getDni(), c.getName(), c.getSubname(), c.getPhone_number(), c.getEmail(), c.getUser(), c.getPass(), c.getAvatar(), c.getState(), c.getDate_birthday(), c.getDischarge_date(), c.getClient_type(), c.getShopping(), c.isPremium()); singleton.clients.getClients().add(d); } }
From source file:application.modules.login.model.DAO.daoLogin.java
/** * Tries to sign in with a username and a password from the view comparing it * with the clients from the database mongo * @return true, if it was well done//from w ww.j a v a 2 s . co m */ public static boolean sign_in_Client() { boolean valid = true; try { client c = new client(); DBCursor cur = SingletonF.collection .find(new BasicDBObject().append("user", login_view.usernameLogin.getText())); BasicDBObject document = (BasicDBObject) cur.next(); c = c.DB_to_client(document); if (c.getPass().equals(login_view.passwordLogin.getText())) { SingletonF.usernameConnected = login_view.usernameLogin.getText(); login.dispose(); new client_controller(new new_client_view(), 1).init("f"); new_client_view.emptyButton.setVisible(false); new_client_view.saveClientButton.setText("Edit your profile"); new_client_view.dniField.setText(c.getDni()); new_client_view.nameField.setText(c.getName()); new_client_view.subnameField.setText(c.getSubname()); new_client_view.phoneField.setText(c.getPhone_number()); new_client_view.emailField.setText(c.getEmail()); new_client_view.usernameField.setText(c.getUser()); new_client_view.passwordField.setText(c.getPass()); new_client_view.avatarField.setText(c.getAvatar()); new_client_view.statusField.setText(c.getState()); Dates b = new Dates(c.getDate_birthday()); new_client_view.datebirthdayField.setCalendar(b.DateToCalendar()); b = new Dates(c.getDischarge_date()); new_client_view.dischargedateField.setCalendar(b.DateToCalendar()); new_client_view.client_typeField.setText(c.getClient_type()); new_client_view.shoppingField.setText(c.getShopping() + ""); new_client_view.premiumCheckbox.setSelected(c.isPremium()); new_client_view.discartButton.setText("Sign Out"); } else { login_view.wrongpass.setVisible(true); valid = false; } } catch (Exception e) { login_view.wrongpass.setVisible(true); valid = false; } return valid; }
From source file:at.tuwien.aic.Main.java
private static void classifyTopic() { String topic = getNonEmptyString("Enter a topic you want to query"); Mongo mongo;//ww w.j a va 2 s . c o m DB db = null; try { mongo = new Mongo(_prop.getProperty("db_host")); db = mongo.getDB(_prop.getProperty("db_name")); } catch (UnknownHostException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); return; } Classifier c = ClassifyTweet.loadModel("resources/classifier.model"); TweetScorer scorer = new TweetScorer(); DBCollection tweetCollection = db.getCollection("tweets"); Pattern pattern = Pattern.compile("^.+" + topic + ".+$"); DBObject query = QueryBuilder.start("text").regex(pattern).get(); DBCursor resultSet = tweetCollection.find(query); int count = 0; double value = 0; double tweetClassifiedScore = 0; double tweetPosUserScore = 0; double tweetNegUserScore = 0; while (resultSet.hasNext()) { try { DBObject obj = resultSet.next(); String tweetText = (String) obj.get("text"); tweetClassifiedScore += ClassifyTweet.classifyTweet(c, tweetText); double score = scorer.scoreTweet(obj); if (tweetClassifiedScore > 0) { tweetPosUserScore += score; } else { tweetNegUserScore += score; } ++count; } catch (NumberFormatException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (JSONException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } // Normalizing between 0 an 1 value = tweetPosUserScore / (tweetPosUserScore + tweetNegUserScore); System.out.println("This topic has a sentiment value of: " + value); }
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 {//from w w w. j a va 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;/* w w w .j av a 2 s.c o m*/ 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;/*w w w. j a v a 2 s .c o m*/ 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 w w .j a v a2 s. c o m 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; }
From source file:backend.facades.UserController.java
public Long getUserIdByEmail(String email) { Long id = 0L;//from w w w . j av a 2s. c om BasicDBObject query = new BasicDBObject(); query.put("email", email); DBCursor cursor = userCollection.find(query); try { if (cursor.count() > 0) { DBObject document = cursor.next(); id = (Long) document.get("_id"); } } finally { cursor.close(); } return id; }