List of usage examples for com.mongodb BasicDBObject BasicDBObject
public BasicDBObject()
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// w ww. j a va2s . 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:ARS.DBManager.java
public boolean findUserByName(String name) { User uObj;/* w ww . j a va2s . c om*/ int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("first-name", name); MongoCursor cursor = collection.find(query).iterator(); //Counter gives one if it's give the result while (cursor.hasNext()) { System.out.println(cursor.next()); counter++; } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean deleteUser(String firstName) { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("first-name", firstName); collection.deleteOne(searchQuery);/*from w ww . ja v a2 s . c o m*/ if (findUserByName(firstName) == false) { return true; } else return false; }
From source file:ARS.DBManager.java
public int findAllUsers() { int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); MongoCursor cursor = collection.find().iterator(); while (cursor.hasNext()) { System.out.println(cursor.next()); counter++;/* w ww .jav a 2s . com*/ } return counter; }
From source file:ARS.DBManager.java
public boolean findUserByNumber(Long pNo) { int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("phone-number", pNo); MongoCursor cursor = collection.find(query).iterator(); while (cursor.hasNext()) { System.out.println(cursor.next()); counter++;//from ww w .j a v a2 s . c om } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean findNullForGender() { User uObj;/* w ww . j av a 2 s. c om*/ int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("gender", null); MongoCursor cursor = collection.find(query).iterator(); //Counter gives one if it's give the result while (cursor.hasNext()) { System.out.println(cursor.next()); counter++; } if (counter >= 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public boolean findUserByEmail(String email, String password) { User uObj;//w ww .j a v a2 s. co m int counter = 0; MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("email", email); query.put("password", password); MongoCursor cursor = collection.find(query).iterator(); //Counter gives one if it's give the result while (cursor.hasNext()) { System.out.println(cursor.next()); counter++; } if (counter == 1) { return true; } else { return false; } }
From source file:ARS.DBManager.java
public void insertPlane(Plane pObj) { try {//from www .j a v a 2s . c o m MongoClient mongoClient = new MongoClient("localhost", 27017); //Connecting MongoDatabase db = mongoClient.getDatabase("ars"); System.out.println("Connecting to the db..."); MongoCollection collection = db.getCollection("plane"); //Choosing the collection to insert System.out.println(collection); List<Object> seatDBList = new BasicDBList(); Document planeObj = new Document(); planeObj.put("pNo", 2); planeObj.put("flightNo", 2); planeObj.put("Type", "Airbus A380"); for (Seat seatList : pObj.getSeatVector()) //TODO: Change it { DBObject seatDBObject = new BasicDBObject(); seatDBObject.put("sNo", seatList.getSeatNumber()); seatDBObject.put("isEmpty", seatList.getIsEmpty()); seatDBObject.put("isEconomy", seatList.getIsEconomy()); seatDBList.add(seatDBObject); } planeObj.put("Seats", seatDBList); collection.insertOne(planeObj); } catch (Exception e) { e.printStackTrace(); } }
From source file:ARS.DBManager.java
public ArrayList findFlight(String departure, String arrival) { MongoClient mongoClient = new MongoClient("localhost", 27017); MongoDatabase db = mongoClient.getDatabase("ars"); MongoCollection collection = db.getCollection("users"); //Choosing the collection to insert BasicDBObject query = new BasicDBObject(); query.put("departure", departure); query.put("arrival", arrival); MongoCursor cursor = collection.find(query).iterator(); ArrayList<Flight> flightList = new ArrayList<>(); //Counter gives one if it's give the result while (cursor.hasNext()) { flightList.add((Flight) cursor.next()); }/*from w w w . j ava2 s . c o m*/ return flightList; }
From source file:at.ac.tuwien.dsg.smartcom.manager.messaging.logging.dao.MongoDBLoggingDAO.java
License:Apache License
private BasicDBObject serializeMessage(Message message) { return new BasicDBObject().append("_id", message.getId().getId()).append("type", message.getType()) .append("subtype", message.getSubtype()) .append("sender", serializeIdentifier(message.getSenderId())) .append("receiver", serializeIdentifier(message.getReceiverId())) .append("content", message.getContent()).append("conversationId", message.getConversationId()) .append("ttl", message.getTtl()).append("language", message.getLanguage()) .append("securityToken", message.getSecurityToken()) //TODO should we log the security token too? .append("created", new Date()); }