@Override protected DBObject runMongoCommand() { return getDBCollection().findOne(query); } }
@Override protected WriteResult runMongoCommand() { if (concern != null) { return getDBCollection().remove(data, concern); } else { return getDBCollection().remove(data); } } }
@Override protected WriteResult runMongoCommand() { return concern == null ? getDBCollection().insert(data) : getDBCollection().insert(data, concern); } }
@Override public void removeEntity(String entityName) { if (entityName == null || entityName.length() == 0) { throw new IllegalArgumentException(LITERAL_ENTITY_NAME); } // All versions must be disabled. Search for a schema that is not disabled DBObject query = new BasicDBObject(LITERAL_NAME, entityName). append(LITERAL_VERSION, new BasicDBObject("$exists", 1)). append(LITERAL_STATUS_VALUE, new BasicDBObject("$ne", MetadataParser.toString(MetadataStatus.DISABLED))); LOGGER.debug("Checking if there are entity versions that are not disabled: {}", query); DBObject result = new FindOneCommand(collection, query).execute(); if (result != null) { LOGGER.debug("There is at least one enabled version {}", result); throw Error.get(MongoMetadataConstants.ERR_CANNOT_DELETE, entityName); } LOGGER.warn("All versions of {} are disabled, deleting {}", entityName, entityName); query = new BasicDBObject(LITERAL_ID, Pattern.compile(entityName + "\\" + BSONParser.DELIMITER_ID + ".*")); LOGGER.debug("Removal query:{}", query); try { WriteResult r = new RemoveCommand(collection, query).execute(); LOGGER.debug("Removal result:{}", r); String error = r.getError(); if (error != null) { throw Error.get(MongoMetadataConstants.ERR_DB_ERROR, error); } } catch (Exception e) { LOGGER.error("Error during delete", e); throw Error.get(MongoMetadataConstants.ERR_DB_ERROR, e.toString()); } }
@Override public void delete(CRUDOperationContext ctx, DBCollection collection, DBObject mongoQuery, CRUDDeleteResponse response) { LOGGER.debug("Removing docs with {}", mongoQuery); WriteResult result = new RemoveCommand(collection, mongoQuery).executeAndUnwrap(); LOGGER.debug("Removal complete, write result={}", result); response.setNumDeleted(result.getN()); } }
@Override protected DBObject runMongoCommand() { return getDBCollection().findAndModify(query, fields, sort, remove, update, returnNew, upsert); } }
@Override protected DBCursor runMongoCommand() { return getDBCollection().find(query, projection); } }
@Override protected WriteResult runMongoCommand() { return getDBCollection().save(data); } }
@Override protected WriteResult runMongoCommand() { if (concern != null) { return getDBCollection().update(query, update, upsert, multi, concern); } else { return getDBCollection().update(query, update, upsert, multi); } } }
@Override protected List runMongoCommand() { if (query == null) { return getDBCollection().distinct(key); } else { return getDBCollection().distinct(key, query); } } }
@Override protected T run() { try { return runMongoCommand(); } catch (MongoSocketException mse) { // must rethrow because MongoSocketException is instance of RuntimeException throw mse; } catch (RuntimeException x) { throw new HystrixBadRequestException("in " + getClass().getName(), x); } }
public T executeAndUnwrap() { try { return execute(); } catch (HystrixRuntimeException x) { Throwable t=x.getCause(); if(t instanceof RuntimeException) throw (RuntimeException)t; else throw new RuntimeException(t); } } }
@Override protected DBObject runMongoCommand() { DBObject q=query==null?new BasicDBObject():query; if(projection==null) return getDBCollection().findOne(q); else return getDBCollection().findOne(q,projection); } }
@Override protected WriteResult runMongoCommand() { if (concern != null) { return getDBCollection().remove(data, concern); } else { return getDBCollection().remove(data); } } }
@Override protected WriteResult runMongoCommand() { return getDBCollection().insert(data, concern); } }
@Override protected DBObject runMongoCommand() { return getDBCollection().findAndModify(query, fields, sort, remove, update, returnNew, upsert); } }
@Override protected DBCursor runMongoCommand() { DBObject q=query==null?new BasicDBObject():query; return getDBCollection().find(q, projection); } }
@Override protected WriteResult runMongoCommand() { return getDBCollection().save(data); } }
@Override protected WriteResult runMongoCommand() { if (concern != null) { return getDBCollection().update(query, update, upsert, multi, concern); } else { return getDBCollection().update(query, update, upsert, multi); } } }
@Override protected List runMongoCommand() { if (query == null) { return getDBCollection().distinct(key); } else { return getDBCollection().distinct(key, query); } } }