Example usage for com.mongodb DBCollection remove

List of usage examples for com.mongodb DBCollection remove

Introduction

In this page you can find the example usage for com.mongodb DBCollection remove.

Prototype

public WriteResult remove(final DBObject query) 

Source Link

Document

Remove documents from a collection.

Usage

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public void deleteTapPolicy(String objectId) throws NotFoundException {
    DBCollection table = database.getCollection(DatabaseNames.getTapPolicyTableName());

    // Create a query to look for the existing TapPolicy by ID
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", new ObjectId(objectId));
    DBObject dbObj = table.findOne(searchQuery);

    if (dbObj == null)
        throw new NotFoundException();

    // We are deleting this tapPolicy, so remove references to other objects
    TapPolicy.removeObjectReferences(dbObj);

    // Remove the TapPolicy from the database
    table.remove(searchQuery);

    logger.info("Removed tap policy " + (String) dbObj.get("name"));

    // Notify the application that the tap policy changed
    // TODO - add objectID
    // tappingAppLogic.NotifyConfigChange(DBTableChangeEnum.TAP_POLICY);
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public void deleteMatchCriteria(final String objectId) throws NotFoundException, ObjectInUseException {
    DBCollection table = database.getCollection(DatabaseNames.getMatchCriteriaTableName());

    // Create a query to look for the existing TapPolicy by ID
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", new ObjectId(objectId));
    DBObject dbObj = table.findOne(searchQuery);

    if (dbObj == null)
        throw new NotFoundException();

    if ((long) dbObj.get("refCount") != 0) {
        throw new ObjectInUseException();
    }//from  ww w.j av  a2s  .  c o m

    // Remove the Match Criteria from the database
    table.remove(searchQuery);

    logger.info("Removed match criteria " + (String) dbObj.get("name"));
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public void deleteSwitchEntry(String objectId) throws NotFoundException, ObjectInUseException {
    DBCollection table = database.getCollection(DatabaseNames.getSwitchEntryTableName());

    // Create a query to look for the existing SwitchEntry by ID
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", new ObjectId(objectId));
    DBObject dbObj = table.findOne(searchQuery);

    if (dbObj == null)
        throw new NotFoundException();

    if ((long) dbObj.get("refCount") != 0) {
        throw new ObjectInUseException();
    }//from  w  w w. ja va 2 s. co m

    // Get the existing portChain
    String switchName = (String) dbObj.get("name");

    // Remove the PortChain from the database
    table.remove(searchQuery);

    logger.info("Removed switch  " + switchName);

    // Notify the application that the port chaun changed
    // TODO - add objectID
    // tappingAppLogic.NotifyConfigChange(DBTableChangeEnum.SWITCH_ENTRY);
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public void deleteNextHopSwitch(String objectId) throws NotFoundException {
    DBCollection table = database.getCollection(DatabaseNames.getNextHopSwitchTableName());

    // Create a query to look for the existing NextHopSwitch by ID
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", new ObjectId(objectId));

    DBObject dbObj = table.findOne(searchQuery);
    if (dbObj == null)
        throw new NotFoundException();

    // Get the existing nextHopSwitch name
    String nhsName = (String) dbObj.get("name");

    // Remove the nextHopSwitch from the database
    table.remove(searchQuery);

    logger.info("Removed Next Hop Switch  " + nhsName);

    // Notify the application that the capture device changed
    // TODO - add objectID
    // tappingAppLogic.NotifyConfigChange(DBTableChangeEnum.NEXT_HOP_SWITCH;
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public void deleteCaptureDev(String objectId) throws NotFoundException, ObjectInUseException {
    DBCollection table = database.getCollection(DatabaseNames.getCaptureDevTableName());

    // Create a query to look for the existing CaptureDev by ID
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", new ObjectId(objectId));
    DBObject dbObj = table.findOne(searchQuery);

    if (dbObj == null)
        throw new NotFoundException();

    if ((long) dbObj.get("refCount") != 0) {
        throw new ObjectInUseException();
    }// w ww .  j a  v  a 2  s .  com

    // Get the existing captureDev
    String captureDevName = (String) dbObj.get("name");

    // Remove the captureDev from the database
    table.remove(searchQuery);

    logger.info("Removed Capture Device  " + captureDevName);

    // Notify the application that the capture device changed
    // TODO - add objectID
    // tappingAppLogic.NotifyConfigChange(DBTableChangeEnum.CAPTURE_DEVICE);
}

From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java

License:Apache License

public void deletePortChain(String objectId) throws NotFoundException, ObjectInUseException {
    DBCollection table = database.getCollection(DatabaseNames.getPortChainTableName());

    // Create a query to look for the existing TapPolicy by ID
    BasicDBObject searchQuery = new BasicDBObject();
    searchQuery.put("_id", new ObjectId(objectId));
    DBObject dbObj = table.findOne(searchQuery);

    if (dbObj == null)
        throw new NotFoundException();

    if ((long) dbObj.get("refCount") != 0) {
        throw new ObjectInUseException();
    }//from w w w. j a  v  a  2s. c  o  m

    // Get the existing PortChain
    String portChainName = (String) dbObj.get("name");

    // Remove the PortChain from the database
    table.remove(searchQuery);

    logger.info("Removed Port Chain " + portChainName);

    // Notify the application that the port chaun changed
    // TODO - add objectID
    // tappingAppLogic.NotifyConfigChange(DBTableChangeEnum.PORT_CHAIN);
}

From source file:org.openspotlight.storage.mongodb.MongoStorageSessionImpl.java

License:Open Source License

@Override
public void deleteNode(final StorageNode node) throws Exception, IllegalArgumentException {
    checkNotNull("node", node);

    final DBCollection collection = getCachedCollection(node.getPartition(), node.getType());
    collection.remove(new BasicDBObject(ID, node.getKey().getKeyAsString()));
}

From source file:org.sipfoundry.sipxconfig.admin.commserver.imdb.ReplicationManagerImpl.java

License:Contributor Agreement License

/**
 * shortcut to remove objects from mongo's imdb database
 *///from   w w w.ja v  a 2 s .  c o m
private void remove(String collectionName, Object id) {
    DBCollection collection = m_imdb.getDb().getCollection(collectionName);
    DBObject search = new BasicDBObject();
    search.put(ID, id);
    DBObject node = collection.findOne(search);
    //necessary only in case of CallSequences
    //(user delete will trigger CS delete but CS for user may not exist)
    if (node != null) {
        collection.remove(node);
    }
}

From source file:org.socialhistoryservices.security.MongoTokenStore.java

License:Open Source License

public void removeAccessToken(String tokenValue) {

    final BasicDBObject query = new BasicDBObject("token_id", tokenValue);
    final DBCollection collection = getCollection(OAUTH_ACCESS_TOKEN);
    collection.remove(query);
    this.accessTokenStore.remove(tokenValue);
}

From source file:org.socialhistoryservices.security.MongoTokenStore.java

License:Open Source License

public void removeRefreshToken(String token) {

    // remove from oauth_refresh_token where token_id = ?
    final BasicDBObject query = new BasicDBObject("token_id", token);
    final DBCollection collection = getCollection(OAUTH_REFRESH_TOKEN);
    collection.remove(query);
}