List of usage examples for com.mongodb DBCursor close
@Override public void close()
From source file:backend.facades.UserController.java
public Long getUserIdByEmail(String email) { Long id = 0L;// w w w. jav 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(); id = (Long) document.get("_id"); } } finally { cursor.close(); } return id; }
From source file:backend.facades.UserController.java
public boolean checkEmail(String email) { boolean retValue = false; BasicDBObject query = new BasicDBObject(); query.put("email", email); DBCursor cursor = userCollection.find(query); try {//from www. ja v a 2 s . c o m if (cursor == null) { return false; } if (cursor != null && cursor.count() > 0) { retValue = true; } else { return false; } } finally { cursor.close(); } return retValue; }
From source file:backend.facades.UserController.java
public boolean checkUsername(String username) { boolean retValue = false; BasicDBObject query = new BasicDBObject(); query.put("username", username); DBCursor cursor = userCollection.find(query); try {//from w ww . j av a2s .co m if (cursor != null && cursor.count() > 0) { retValue = true; } } finally { cursor.close(); } return retValue; }
From source file:bank_server.Task2.java
@Override public void run() { try {/*from w w w.ja v a 2s . c o m*/ SecretKey KS = new SecretKeySpec("cisco789".getBytes(), "DES"); Cipher cipher = Cipher.getInstance("DES/ECB/PKCS5Padding"); cipher.init(Cipher.DECRYPT_MODE, KS); System.out.println("KS " + KS); oos = new ObjectOutputStream(cSock.getOutputStream()); System.out.println(oos); ois = new ObjectInputStream(cSock.getInputStream()); System.out.println(ois); if (ois == null || oos == null) System.exit(1); else System.out.println("Flux crs"); Boolean fin = false; Pull pull = null; Push push = null; while (fin != true) { pull = (Pull) ois.readObject(); cipher.init(Cipher.DECRYPT_MODE, KS); SealedObject so = pull.getTicket().getKCS(); KCS unsealed = null; unsealed = (KCS) so.getObject(cipher); SecretKey KCS = unsealed.getKcs(); // Verification timestamp long validity = unsealed.getValidity().getTime(); long now = new Date().getTime(); if ((validity - now) < 0) throw new BadTimestampException(); else System.out.println("Timestamp valide"); switch (pull.getName()) { case "Hello": { push = new Push(); push.setName("Hello"); } break; case "END": { System.out.println("Closing Connection"); fin = true; } break; case "recherche": { push = new Push(); push.setName("recherche"); DBObject query = new BasicDBObject(); if (pull.getValide().equalsIgnoreCase("true") || pull.getValide().equalsIgnoreCase("false")) query.put("valide", pull.getValide()); if (!pull.getBanque().equals("")) query.put("banque.name", pull.getBanque()); DBCursor cursor = collection.find(query); iterateOverCursor(cursor, push); cursor.close(); } break; case "validation": { for (int i = 0; i < pull.getIds().size(); i++) { //System.out.println(pull.getIds().get(i)); DBObject query = new BasicDBObject("_id", Integer.parseInt(pull.getIds().get(i))); DBObject update = new BasicDBObject(); update.put("$set", new BasicDBObject("valide", "true")); collection.update(query, update); } push = new Push(); push.setName("validOK"); } break; } cipher.init(Cipher.DECRYPT_MODE, KCS); AuthenticatorTGS auth = (AuthenticatorTGS) pull.getAuthenticator().getObject(cipher); cipher.init(Cipher.ENCRYPT_MODE, KCS); push.setTimestamp(new SealedObject(auth.getCurrentTime(), cipher)); oos.writeObject(push); } oos.close(); ois.close(); cSock.close(); } catch (BadTimestampException ex) { System.out.println("BadTimeStampExc"); } catch (Exception ex) { Logger.getLogger(Task.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:bd.DArticulo.java
@Override public ArrayList listar() { ArrayList datos = new ArrayList(); CArticulo x = new CArticulo(); conecion con = new conecion(table); DBCursor cursor = con.get_colletion().find(); try {/*from w w w . j a v a2 s. co m*/ while (cursor.hasNext()) { x = new CArticulo(); BasicDBObject agg = (BasicDBObject) cursor.next(); x.set_datos((HashMap) agg.toMap()); x.setId((String) agg.getString("_id")); datos.add(x); } } finally { cursor.close(); } con.end(); return datos; }
From source file:bd.DArticulo.java
@Override public Object buscar_id(String id_find) { ArrayList datos = new ArrayList(); CArticulo x = new CArticulo(); conecion con = new conecion(table); System.out.println(id_find + "warrennnnn"); BasicDBObject id = new BasicDBObject("_id", new ObjectId(id_find)); DBCursor cursor = con.get_colletion().find(id); try {//from ww w . j ava 2 s.co m while (cursor.hasNext()) { x = new CArticulo(); x.set_datos((HashMap) cursor.next().toMap()); datos.add(x); } } finally { cursor.close(); } con.end(); if (datos.size() == 0) return null; return datos.get(0); }
From source file:bd.DArticulo.java
@Override public ArrayList listar(String clave, String valor) { ArrayList datos = new ArrayList(); CArticulo x = new CArticulo(); conecion con = new conecion(table); BasicDBObject id = new BasicDBObject(clave, valor); DBCursor cursor = con.get_colletion().find(id); try {//from w w w . j av a 2s .co 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.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 {//from w w w . jav 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 ArrayList listar() { ArrayList datos = new ArrayList(); CCategoria x = new CCategoria(); conecion con = new conecion(table); DBCursor cursor = con.get_colletion().find(); try {/*from w w w . ja v a 2 s .c om*/ while (cursor.hasNext()) { x = new CCategoria(); BasicDBObject agg = (BasicDBObject) cursor.next(); x.set_datos((HashMap) agg.toMap()); x.setId((String) agg.getString("_id")); datos.add(x); } } finally { cursor.close(); } con.end(); return datos; }
From source file:bd.DCategoria.java
@Override public Object buscar_id(String id_find) { ArrayList datos = new ArrayList(); CCategoria x = new CCategoria(); conecion con = new conecion(table); BasicDBObject id = new BasicDBObject("_id", new ObjectId(id_find)); DBCursor cursor = con.get_colletion().find(id); try {/* w ww . j av a 2s . com*/ while (cursor.hasNext()) { x = new CCategoria(); x.set_datos((HashMap) cursor.next().toMap()); datos.add(x); } } finally { cursor.close(); } con.end(); System.out.println(id_find + "lllll" + datos.size()); if (datos.size() == 0) return null; return datos.get(0); }