List of usage examples for com.mongodb DBCollection findOne
@Nullable public DBObject findOne(final Object id)
From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java
License:Apache License
public void modifyTapPolicy(final String tapPolicyId, TapPolicy tapPolicy) 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(tapPolicyId)); // Check whether the policy exists DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // Create a document containing the new tap policy BasicDBObject newDocument = tapPolicy.getAsDocument(); BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", newDocument); // Update the document in the database table.update(searchQuery, updateObj); logger.info("Updated tap policy id " + tapPolicyId); }
From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java
License:Apache License
private boolean matchCriteriaExistsByName(String name) { DBCollection table = database.getCollection(DatabaseNames.getMatchCriteriaTableName()); // Run a query to look for the Match Criteria name BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("name", name); DBObject dbObj = table.findOne(searchQuery); return (dbObj != null) ? true : false; }
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 a 2 s .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 modifyMatchCriteria(final String matchCriteriaId, MatchCriteria matchCriteria) throws NotFoundException { DBCollection table = database.getCollection(DatabaseNames.getMatchCriteriaTableName()); logger.info("Match Criteria enabled " + matchCriteria.getEnabled()); // Create a query to look for the existing TapPolicy by ID BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", new ObjectId(matchCriteriaId)); // Check whether the policy exists DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // Create a document containing the new tap policy BasicDBObject newDocument = matchCriteria.getAsDocument(); BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", newDocument); // Update the document in the database table.update(searchQuery, updateObj); logger.info("Updated match criteria id " + matchCriteriaId); }
From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java
License:Apache License
public void modifySwitchEntry(final String switchEntryId, SwitchEntry switchEntry) throws NotFoundException { 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(switchEntryId)); // Check whether the switchEntry exists DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // Create a document containing the new switch Entry BasicDBObject newDocument = switchEntry.getAsDocument(); BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", newDocument); // Update the document in the database table.update(searchQuery, updateObj); logger.info("Updated SwitchEntry id " + switchEntryId); }
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 ww w . j ava 2s .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
private boolean switchEntryExistsByName(String switchName) { DBCollection table = database.getCollection(DatabaseNames.getSwitchEntryTableName()); // Run a query to look for the SwitchEntry name BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("name", switchName); DBObject dbObj = table.findOne(searchQuery); return (dbObj != null) ? true : false; }
From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java
License:Apache License
public SwitchEntry findSwitchByDataPathId(final String switchId) throws NotFoundException { DBCollection table = database.getCollection(DatabaseNames.getSwitchEntryTableName()); // Create a query to look for the existing SwitchEntry by ID BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("OPFSwitchDatapath", switchId); DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); SwitchEntry switchEntry = null;/*w w w .j a v a 2s . co m*/ switchEntry = new SwitchEntry(dbObj, this); return switchEntry; }
From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java
License:Apache License
public void modifyNextHopSwitch(final String nhsId, NextHopSwitch nextHopSwitch) 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(nhsId)); // Check whether the nextHopSwitch exists DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // Create a document containing the new nextHopSwitch BasicDBObject newDocument = nextHopSwitch.getAsDocument(); BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", newDocument); // Update the document in the database table.update(searchQuery, updateObj); logger.info("Updated NextHopSwitch id " + nhsId); }
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);//from w w w . ja va2s . com logger.info("Removed Next Hop Switch " + nhsName); // Notify the application that the capture device changed // TODO - add objectID // tappingAppLogic.NotifyConfigChange(DBTableChangeEnum.NEXT_HOP_SWITCH; }