List of usage examples for com.mongodb.client.result UpdateResult getModifiedCount
public abstract long getModifiedCount();
From source file:com.dilmus.dilshad.scabi.db.DTable.java
License:Open Source License
public long update(Bson dob, Bson updateObj) throws DScabiException { UpdateResult result = m_table.updateMany(dob, updateObj); log.debug("update() result is : {}", result.getModifiedCount()); if (result.getModifiedCount() < 0) throw new DScabiException( "Update failed for dob : " + dob.toString() + " updateObj : " + updateObj.toString(), "DBT.UPE.1"); return result.getModifiedCount(); }
From source file:com.dilmus.dilshad.scabi.db.DTable.java
License:Open Source License
public long update(Bson dob, DDocument updateObj) throws DScabiException { UpdateResult result = m_table.updateMany(dob, updateObj.getDocument()); log.debug("update() result is : {}", result.getModifiedCount()); if (result.getModifiedCount() < 0) throw new DScabiException( "Update failed for dob : " + dob.toString() + " updateObj : " + updateObj.toString(), "DBT.UPE.1"); return result.getModifiedCount(); }
From source file:com.dilmus.dilshad.scabi.db.DTable.java
License:Open Source License
public long update(DDocument dob, Bson updateObj) throws DScabiException { UpdateResult result = m_table.updateMany(dob.getDocument(), updateObj); log.debug("update() result is : {}", result.getModifiedCount()); if (result.getModifiedCount() < 0) throw new DScabiException( "Update failed for dob : " + dob.toString() + " updateObj : " + updateObj.toString(), "DBT.UPE.1"); return result.getModifiedCount(); }
From source file:com.dilmus.dilshad.scabi.db.DTable.java
License:Open Source License
public long executeUpdate(String jsonUpdate, String jsonWhere) throws IOException, DScabiException { ArrayList<String> fieldList = fieldNamesUsingFindOne(); // fieldNames(); DMJson djsonWhere = new DMJson(jsonWhere); Set<String> stWhere = djsonWhere.keySet(); Document documentWhere = new Document(); DMJson djsonUpdate = new DMJson(jsonUpdate); Set<String> stUpdate = djsonUpdate.keySet(); Document documentUpdate = new Document(); if (false == isEmpty(fieldList)) { if (false == fieldList.containsAll(stWhere)) { throw new DScabiException( "One or more field name in jsonWhere doesn't exist in fieldNames list. jsonWhere : " + jsonWhere + " Field Names list : " + fieldList, "DBT.EUE.1"); }//from w w w.java 2 s.com if (false == fieldList.containsAll(stUpdate)) { throw new DScabiException( "One or more field name in jsonUpdate doesn't exist in fieldNames list. jsonUpdate : " + jsonUpdate + " Field Names list : " + fieldList, "DBT.EUE.2"); } } for (String keyWhere : stWhere) { // create a document to store key and value documentWhere.put(keyWhere, djsonWhere.getString(keyWhere)); } for (String keyUpdate : stUpdate) { // create a document to store key and value documentUpdate.put(keyUpdate, djsonUpdate.getString(keyUpdate)); } BasicDBObject updateObj = new BasicDBObject(); updateObj.put("$set", documentUpdate); UpdateResult result = m_table.updateMany(documentWhere, updateObj); log.debug("executeUpdate() result is : {}", result.getModifiedCount()); if (result.getModifiedCount() <= 0) throw new DScabiException("Update failed for documentWhere : " + documentWhere.toString() + " updateObj : " + updateObj.toString(), "DBT.EUE.3"); return result.getModifiedCount(); }
From source file:com.epam.dlab.backendapi.dao.ComputationalDAO.java
License:Apache License
/** * Updates the status of exploratory notebooks in Mongo database. * * @param dto object of exploratory status info. * @return The result of an update operation. *//*from w w w.j a v a2 s .c o m*/ public int updateComputationalStatusesForExploratory(StatusEnvBaseDTO<?> dto) { Document values = new Document(computationalFieldFilter(STATUS), dto.getStatus()); values.append(computationalFieldFilter(UPTIME), null); int count = 0; UpdateResult result; do { result = updateOne(USER_INSTANCES, and(exploratoryCondition(dto.getUser(), dto.getExploratoryName()), elemMatch(COMPUTATIONAL_RESOURCES, and(not(eq(STATUS, TERMINATED.toString())), not(eq(STATUS, dto.getStatus()))))), new Document(SET, values)); count += result.getModifiedCount(); } while (result.getModifiedCount() > 0); return count; }
From source file:com.epam.dlab.backendapi.dao.ComputationalDAO.java
License:Apache License
private void updateComputationalResource(String user, String exploratoryName, UserInstanceStatus dataengineServiceStatus, DataEngineType cloudService, UserInstanceStatus... excludedStatuses) { UpdateResult result; do {/* www .j a v a 2s . com*/ result = updateMany(USER_INSTANCES, computationalFilter(user, exploratoryName, dataengineServiceStatus.toString(), DataEngineType.getDockerImageName(cloudService), excludedStatuses), new Document(SET, new Document(computationalFieldFilter(STATUS), dataengineServiceStatus.toString()))); } while (result.getModifiedCount() > 0); }
From source file:com.epam.dlab.backendapi.dao.ComputationalDAO.java
License:Apache License
public void updateSchedulerSyncFlag(String user, String exploratoryName, boolean syncFlag) { final String syncStartField = SCHEDULER_DATA + ".sync_start_required"; UpdateResult result; do {/* w w w . j av a 2s. c om*/ result = updateOne(USER_INSTANCES, and(exploratoryCondition(user, exploratoryName), elemMatch(COMPUTATIONAL_RESOURCES, and(ne(SCHEDULER_DATA, null), ne(syncStartField, syncFlag)))), set(computationalFieldFilter(syncStartField), syncFlag)); } while (result.getModifiedCount() != 0); }
From source file:com.erudika.para.persistence.MongoDBDAO.java
License:Apache License
private void updateRow(String key, String appid, Document row) { if (StringUtils.isBlank(key) || StringUtils.isBlank(appid) || row == null || row.isEmpty()) { return;/*ww w .j av a2 s . c o m*/ } try { UpdateResult u = getTable(appid).updateOne(new Document(_ID, key), new Document("$set", row)); logger.debug("key: " + key + " updated count: " + u.getModifiedCount()); } catch (Exception e) { logger.error(null, e); } }
From source file:com.ibm.research.mongotx.lrc.LRCTxDBCollection.java
License:Open Source License
private int updateSD2V(LRCTx tx, Object key, Document updateQuery, Document newUnsafe, Document userQuery) throws TxRollback { Document cachedSd2v = tx.getCache(this, key); tx.insertTxStateIfNecessary();/*from www .j ava2s.c om*/ while (true) { String pinnedSafeTxId = null; boolean latestCache = false; boolean pinned = false; if (cachedSd2v == null) { Iterator<Document> itrCachedSd2v = baseCol.find(new Document(ATTR_ID, key)).iterator(); if (!itrCachedSd2v.hasNext()) return 0; cachedSd2v = itrCachedSd2v.next(); latestCache = true; } else if (tx.isPinned(this, key)) { latestCache = true; pinned = true; pinnedSafeTxId = cachedSd2v.getString(ATTR_VALUE_TXID); } if (hasLocalUnsafe(tx, cachedSd2v)) { Document query = new Document(ATTR_ID, key); for (Map.Entry<String, Object> field : userQuery.entrySet()) { if (field.getKey().equals(ATTR_ID)) continue; query.append(ATTR_VALUE_UNSAFE + "." + field.getKey(), field.getValue()); } query.append(ATTR_VALUE_UNSAFE + "." + ATTR_VALUE_UNSAFE_TXID, tx.txId); Document prev = getSafeVersion(cachedSd2v); if (newUnsafe == null) newUnsafe = generateNewValue(tx, key, prev, updateQuery); if (prev == null && newUnsafe == null) return 0; Document newSd2v = new Document(prev)// .append(ATTR_VALUE_UNSAFE, new Document(newUnsafe).append(ATTR_VALUE_UNSAFE_TXID, tx.txId)); UpdateResult ret = baseCol.replaceOne(query, newSd2v); if (ret.getModifiedCount() == 1L) { tx.putDirty(this, key, newSd2v); return 1; } else if (ret.getModifiedCount() == 0L) { tx.rollback(); throw new TxRollback("conflict. col=" + baseCol.getNamespace() + ", key=" + key); } } else if (hasCommittedUnsafe(cachedSd2v)) { if (pinnedSafeTxId != null) { tx.rollback(); throw new TxRollback("conflict. col=" + baseCol.getNamespace() + ", key=" + key); } String unsafeTxId = ((Document) cachedSd2v.get(ATTR_VALUE_UNSAFE)) .getString(ATTR_VALUE_UNSAFE_TXID); Document prev = getUnsafeVersion(cachedSd2v); if (newUnsafe == null) newUnsafe = generateNewValue(tx, key, prev, updateQuery); if (prev == null && newUnsafe == null) return 0; Document query = new Document(userQuery)// .append(ATTR_ID, key)// .append(ATTR_VALUE_UNSAFE + "." + ATTR_VALUE_UNSAFE_TXID, unsafeTxId); Document newSd2v = new Document(getUnsafeVersion(cachedSd2v))// .append(ATTR_VALUE_UNSAFE, newUnsafe.append(ATTR_VALUE_UNSAFE_TXID, tx.txId)); UpdateResult ret = baseCol.replaceOne(query, newSd2v); if (ret.getModifiedCount() == 1L) { tx.putDirty(this, key, newSd2v); return 1; } else if (ret.getModifiedCount() == 0L) { if (latestCache) { tx.rollback(); throw new TxRollback("conflict. col=" + baseCol.getNamespace() + ", key=" + key); } cachedSd2v = null; continue; } } else { Document query; if (hasUnsafe(cachedSd2v)) { String unsafeTxId = ((Document) cachedSd2v.get(ATTR_VALUE_UNSAFE)) .getString(ATTR_VALUE_UNSAFE_TXID); if (!txDB.abort(unsafeTxId)) { tx.rollback(); throw new TxRollback("conflict. col=" + baseCol.getNamespace() + ", key=" + key); } query = new Document(userQuery)// .append(ATTR_ID, key)// .append(ATTR_VALUE_UNSAFE + "." + ATTR_VALUE_UNSAFE_TXID, unsafeTxId); if (pinned && pinnedSafeTxId == null) query.append(ATTR_VALUE_TXID, new Document("$exists", false)); } else { query = new Document(userQuery)// .append(ATTR_ID, key)// .append(ATTR_VALUE_UNSAFE + "." + ATTR_VALUE_UNSAFE_TXID, new Document("$not", new Document("$exists", true))); if (pinned && pinnedSafeTxId == null) query.append(ATTR_VALUE_TXID, new Document("$exists", false)); Document prev = getSafeVersion(cachedSd2v); if (newUnsafe == null) newUnsafe = generateNewValue(tx, key, prev, updateQuery); if (prev == null && newUnsafe == null) return 0; } String latestSafeTxId = cachedSd2v.getString(ATTR_VALUE_TXID); if (pinnedSafeTxId != null && !pinnedSafeTxId.equals(latestSafeTxId)) { tx.rollback(); throw new TxRollback("conflict. col=" + baseCol.getNamespace() + ", key=" + key); } Document prev = getSafeVersion(cachedSd2v); if (newUnsafe == null) newUnsafe = generateNewValue(tx, key, prev, updateQuery); if (prev == null && newUnsafe == null) return 0; Document newSd2v = prev// .append(ATTR_VALUE_UNSAFE, newUnsafe.append(ATTR_VALUE_UNSAFE_TXID, tx.txId)); UpdateResult ret = baseCol.replaceOne(query, newSd2v); if (ret.getModifiedCount() == 1L) { tx.putDirty(this, key, newSd2v); return 1; } else if (ret.getModifiedCount() == 0L) { if (latestCache) { tx.rollback(); throw new TxRollback("conflict. col=" + baseCol.getNamespace() + ", key=" + key); } cachedSd2v = null; continue; } } } }
From source file:com.ibm.research.mongotx.lrc.LRCTxDBCollection.java
License:Open Source License
@Override public Document findOneAndReplace(Tx tx, Document query, Document update) throws TxRollback { synchronized (tx) { Document tgt = findOne(tx, query); if (tgt == null) return null; UpdateResult ret = updateMany(tx, new Document(ATTR_ID, tgt.get(ATTR_ID)), update); if (ret.getModifiedCount() == 1L) return tgt; else//from w ww.j a v a 2s. co m return null; } }