List of usage examples for com.mongodb DBCollection update
public WriteResult update(final DBObject query, final DBObject update)
From source file:org.opendaylight.controller.samples.onftappingapp.MatchCriteria.java
License:Apache License
public static boolean adjustReferenceCount(final ReferenceCountEnum adjType, String matchCriteriaId) throws NotFoundException { DB database = TappingApp.getDatabase(); DBCollection table = database.getCollection(DatabaseNames.getMatchCriteriaTableName()); // Look for the Match Criteria object by object ID in the database BasicDBObject searchQuery = new BasicDBObject(); ObjectId id = new ObjectId(matchCriteriaId); searchQuery.put("_id", id); DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // create an increment query DBObject modifier = new BasicDBObject("refCount", (adjType == ReferenceCountEnum.DECREMENT) ? -1 : 1); DBObject incQuery = new BasicDBObject("$inc", modifier); // increment a counter value atomically WriteResult result = table.update(searchQuery, incQuery); return (result != null) ? true : false; }
From source file:org.opendaylight.controller.samples.onftappingapp.NextHopSwitch.java
License:Apache License
public static boolean adjustReference(final ReferenceCountEnum adjType, String nhsId, SwitchEntry tapPolicy) throws NotFoundException { DB database = TappingApp.getDatabase(); DBCollection table = database.getCollection(DatabaseNames.getNextHopSwitchTableName()); // Look for the SwitchEntry object by object ID in the database BasicDBObject searchQuery = new BasicDBObject(); ObjectId id = new ObjectId(nhsId); searchQuery.put("_id", id); DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // create an increment query DBObject modifier = new BasicDBObject("refCount", (adjType == ReferenceCountEnum.DECREMENT) ? -1 : 1); DBObject incQuery = new BasicDBObject("$inc", modifier); // increment a counter value atomically WriteResult result = table.update(searchQuery, incQuery); return (result != null) ? true : false; }
From source file:org.opendaylight.controller.samples.onftappingapp.PortChain.java
License:Apache License
public static Boolean adjustReferenceCount(final ReferenceCountEnum adjType, String switchEntryId) throws NotFoundException { DB database = TappingApp.getDatabase(); DBCollection table = database.getCollection(DatabaseNames.getPortChainTableName()); // Look for the SwitchEntry object by object ID in the database BasicDBObject searchQuery = new BasicDBObject(); ObjectId id = new ObjectId(switchEntryId); searchQuery.put("_id", id); DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // create an increment query DBObject modifier = new BasicDBObject("refCount", (adjType == ReferenceCountEnum.DECREMENT) ? -1 : 1); DBObject incQuery = new BasicDBObject("$inc", modifier); // increment a counter value atomically WriteResult result = table.update(searchQuery, incQuery); return (result != null) ? true : false; }
From source file:org.opendaylight.controller.samples.onftappingapp.SwitchEntry.java
License:Apache License
public static boolean adjustReferenceCount(final ReferenceCountEnum adjType, String switchEntryId) throws NotFoundException { DB database = TappingApp.getDatabase(); DBCollection table = database.getCollection(DatabaseNames.getSwitchEntryTableName()); // Look for the SwitchEntry object by object ID in the database BasicDBObject searchQuery = new BasicDBObject(); ObjectId id = new ObjectId(switchEntryId); searchQuery.put("_id", id); DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // create an increment query DBObject modifier = new BasicDBObject("refCount", (adjType == ReferenceCountEnum.DECREMENT) ? -1 : 1); DBObject incQuery = new BasicDBObject("$inc", modifier); // increment a counter value atomically WriteResult result = table.update(searchQuery, incQuery); return (result != null) ? true : false; }
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
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 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 modifyCaptureDev(final String captureDevId, CaptureDev captureDev) throws NotFoundException { 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(captureDevId)); // Check whether the CaptureDev exists DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // Create a document containing the new switch Entry BasicDBObject newDocument = captureDev.getAsDocument(); BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", newDocument); // Update the document in the database table.update(searchQuery, updateObj); logger.info("Updated CaptureDev id " + captureDevId); }
From source file:org.opendaylight.controller.samples.onftappingapp.TappingApp.java
License:Apache License
public void modifyPortChain(final String portChainId, PortChain portChain) throws NotFoundException { DBCollection table = database.getCollection(DatabaseNames.getPortChainTableName()); // Create a query to look for the existing PortChain by ID BasicDBObject searchQuery = new BasicDBObject(); searchQuery.put("_id", new ObjectId(portChainId)); // Check whether the PortChain exists DBObject dbObj = table.findOne(searchQuery); if (dbObj == null) throw new NotFoundException(); // Create a document containing the new portChain BasicDBObject newDocument = portChain.getAsDocument(); BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", newDocument); // Update the document in the database table.update(searchQuery, updateObj); logger.info("Updated PortChain ID " + portChainId); }