List of usage examples for com.mongodb DBCollection remove
public WriteResult remove(final DBObject query)
From source file:net.autosauler.ballance.server.model.User.java
License:Apache License
/** * Restore./* www .j a v a 2s . c om*/ * * @param domain2 * the domain2 * @param nodes * the nodes */ public static void restore(String domain, NodeList nodes) { Database.retain(); DB db = Database.get(domain); if (db != null) { DBCollection coll = db.getCollection(USERSTABLE); BasicDBObject query = new BasicDBObject(); query.put("domain", domain); coll.remove(query); } Database.release(); for (int i = 0; i < nodes.getLength(); i++) { User user = new User(); user.setDomain(domain); Element usernode = (Element) nodes.item(i); NodeList values = usernode.getChildNodes(); for (int c = 0; c < values.getLength(); c++) { Node v = values.item(c); if (v.getNodeType() == Node.ELEMENT_NODE) { Element val = (Element) v; if (val.getNodeName().equals("hash")) { user.setHash(val.getTextContent()); } else if (val.getNodeName().equals("login")) { user.setLogin(val.getTextContent()); } else if (val.getNodeName().equals("fullname")) { user.setUsername(val.getTextContent()); } else if (val.getNodeName().equals("roles")) { String roles = val.getTextContent(); user.setUserrole(new UserRole(Integer.parseInt(roles))); } else if (val.getNodeName().equals("createdate")) { String cd = val.getTextContent(); Long l = Long.parseLong(cd); Date d = new Date(l); user.setCreatedate(d); } else if (val.getNodeName().equals("active")) { String s = val.getTextContent(); Boolean b = Boolean.parseBoolean(s); user.setActive(b); } else if (val.getNodeName().equals("trash")) { String s = val.getTextContent(); Boolean b = Boolean.parseBoolean(s); user.setTrash(b); } } } user.create(true); } }
From source file:net.handle.server.MongoDBHandleStorage.java
License:Open Source License
/** * ****************************************************************** * Sets a flag indicating whether or not this server is responsible * for the given naming authority.//from w w w. j av a 2s.c o m * ******************************************************************* */ public void setHaveNA(byte authHandle[], boolean flag) throws HandleException { if (readOnly) throw new HandleException(HandleException.STORAGE_RDONLY, "Server is read-only"); boolean currentlyHaveIt = haveNA(authHandle); if (currentlyHaveIt == flag) return; final DBCollection collection = getCollection(database, collection_nas); final BasicDBObject na = new BasicDBObject(); na.put("na", Util.decodeString(authHandle)); authHandle = Util.upperCase(authHandle); if (currentlyHaveIt) { // we already have it but need to remove it { collection.remove(na); } } else { // we need to add the NA to the database { collection.insert(na); // Add indices to the handle collection. final DBCollection handle_na = getCollection(authHandle); for (String index : indices) { handle_na.ensureIndex(index); } } } }
From source file:net.handle.server.MongoDBHandleStorage.java
License:Open Source License
/** * ****************************************************************** * Delete the specified handle in the database. * ******************************************************************* *///from ww w . ja va2s.c om public boolean deleteHandle(byte handle[]) throws HandleException { if (readOnly) throw new HandleException(HandleException.STORAGE_RDONLY, "Server is read-only"); final String handleStr = Util.decodeString(handle); final BasicDBObject query = new BasicDBObject("handle", handleStr); final DBCollection collection = getCollection(handle); final WriteResult result = collection.remove(query); return (result.getN() != 0); }
From source file:net.luminis.useradmin.mongodb.MongoDBRepositoryStore.java
License:Apache License
@Override public boolean removeRole(Role role) throws IOException { try {//ww w.java 2 s. c om DBCollection coll = getCollection(); WriteResult result = coll.remove(getTemplateObject(role)); return (result.getLastError() != null) && result.getLastError().ok(); } catch (MongoException e) { m_log.log(LogService.LOG_WARNING, "Remove role failed!", e); throw new IOException("RemoveRole failed!", e); } }
From source file:net.onrc.openvirtex.db.DBManager.java
License:Apache License
/** * Remove document from db//from www . j a v a2 s .c o m */ public void removeDoc(Persistable obj) { // Suppress error stream when MongoDB raises java.net.ConnectException in another component (and cannot be caught) PrintStream ps = System.err; System.setErr(null); try { DBCollection collection = this.collections.get(obj.getDBName()); collection.remove(new BasicDBObject(obj.getDBObject())); } catch (Exception e) { log.error("Failed to remove document from database: {}", e.getMessage()); } finally { // Restore error stream System.setErr(ps); } }
From source file:net.scran24.datastore.mongodb.MongoDbDataStore.java
License:Apache License
public void deleteUsers(String survey_id, String role) throws DataStoreException { DBCollection col = getUsersCollection(survey_id); BasicDBObject removeQuery = new BasicDBObject(FIELD_ROLES, role); try {/*from w ww . ja v a 2 s .c o m*/ col.remove(removeQuery); } catch (MongoException e) { throw new DataStoreException(e); } }
From source file:net.tbnr.util.bungee.cooldowns.TCooldownManager.java
License:Open Source License
public static boolean canContinue(String key, TCooldown cooldown) { if (database == null) return true; DBCollection collection = TCooldownManager.getCollection(); BasicDBObject key2 = new BasicDBObject("key", key); DBCursor key1 = collection.find(key2); DBObject object = null;/*from w ww .jav a2 s . c o m*/ while (key1.hasNext()) { object = key1.next(); } if (object == null) { collection.save(key2.append("cooldown-time_stored", cooldown.getTime_stored()).append("cooldown-length", cooldown.getLength())); return true; } else { TCooldown cooldown1 = new TCooldown((Long) object.get("cooldown-time_stored"), (Long) object.get("cooldown-length")); if (cooldown1.canContinue()) { collection.remove(object); return canContinue(key, new TCooldown(cooldown.getLength())); } else { return false; } } }
From source file:net.tbnr.util.player.cooldowns.TCooldownManager.java
License:Open Source License
public static boolean canContinue(String key, TCooldown cooldown) { if (database == null) { return true; }/*w w w .j a v a2 s . c om*/ DBCollection collection = TCooldownManager.getCollection(); BasicDBObject key2 = new BasicDBObject("key", key); DBCursor key1 = collection.find(key2); DBObject object = null; while (key1.hasNext()) { object = key1.next(); } if (object == null) { collection.save(key2.append("cooldown-time_stored", cooldown.getTime_stored()).append("cooldown-length", cooldown.getLength())); return true; } else { TCooldown cooldown1 = new TCooldown((Long) object.get("cooldown-time_stored"), (Long) object.get("cooldown-length")); if (cooldown1.canContinue()) { collection.remove(object); return canContinue(key, new TCooldown(cooldown.getLength())); } else { return false; } } }
From source file:nl.knaw.huygens.timbuctoo.storage.mongo.MongoDB.java
License:Open Source License
/** * Removes documents from the database./*from ww w.j a v a2 s .co m*/ */ public int remove(DBCollection collection, DBObject query) throws StorageException { try { WriteResult result = collection.remove(query); return (result != null) ? result.getN() : 0; } catch (MongoException e) { throw new StorageException(e); } }
From source file:no.pritest.restapi.MongoChangeDAO.java
License:Open Source License
@Override public void delete(String after) throws MongoException, UnknownHostException { DB db = MongoDBProvider.getInstance().getDB(); DBCollection coll = db.getCollection("change"); BasicDBObject removalQuery = new BasicDBObject(); removalQuery.put("after", after); coll.remove(removalQuery); }