private <T> QueryResult<T> endQuery(List result, double start) { int numResults = (result != null) ? result.size() : 0; return endQuery(result, numResults, start); }
private <T> QueryResult<T> privateFindAndUpdate(Bson query, Bson projection, Bson sort, Bson update, QueryOptions options, Class<T> clazz, ComplexTypeConverter<T, Document> converter) { long start = startQuery(); Document result = mongoDBNativeQuery.findAndUpdate(query, projection, sort, update, options); if (clazz != null && !clazz.equals(Document.class)) { try { return endQuery(Collections.singletonList(objectMapper.readValue(objectWriter.writeValueAsString(result), clazz)), start); } catch (IOException e) { e.printStackTrace(); } } return endQuery(Collections.singletonList(result), start); }
public QueryResult dropIndex(Bson keys) { long start = startQuery(); mongoDBNativeQuery.dropIndex(keys); QueryResult queryResult = endQuery(Collections.emptyList(), start); return queryResult; }
public QueryResult<BulkWriteResult> insert(List<Document> objects, QueryOptions options) { long start = startQuery(); BulkWriteResult writeResult = mongoDBNativeQuery.insert(objects, options); return endQuery(Collections.singletonList(writeResult), start); }
private <T> QueryResult<T> privateFindAndModify(Bson query, Bson fields, Bson sort, Document update, QueryOptions options, Class<T> clazz, ComplexTypeConverter<T, Document> converter) { long start = startQuery(); Object result = mongoDBNativeQuery.findAndModify(query, fields, sort, update, options); return endQuery(Collections.singletonList(result), start); }
public QueryResult<Long> count() { long start = startQuery(); long l = mongoDBNativeQuery.count(); return endQuery(Collections.singletonList(l), start); }
public QueryResult<DeleteResult> remove(Bson query, QueryOptions options) { long start = startQuery(); DeleteResult wr = mongoDBNativeQuery.remove(query); QueryResult<DeleteResult> queryResult = endQuery(Arrays.asList(wr), start); return queryResult; }
public QueryResult<Long> count(Bson query) { long start = startQuery(); long l = mongoDBNativeQuery.count(query); return endQuery(Collections.singletonList(l), start); }
public QueryResult insert(Document object, QueryOptions options) { long start = startQuery(); mongoDBNativeQuery.insert(object, options); return endQuery(Collections.emptyList(), start); }
public QueryResult<Document> getIndex() { long start = startQuery(); List<Document> index = mongoDBNativeQuery.getIndex(); QueryResult<Document> queryResult = endQuery(index, start); return queryResult; }
public QueryResult<BulkWriteResult> remove(List<? extends Bson> query, QueryOptions options) { long start = startQuery(); boolean multi = false; if (options != null) { multi = options.getBoolean(MULTI); } com.mongodb.bulk.BulkWriteResult wr = mongoDBNativeQuery.remove(query, multi); QueryResult<BulkWriteResult> queryResult = endQuery(Arrays.asList(wr), start); return queryResult; }
public <T> QueryResult<T> distinct(String key, Bson query, Class<T> clazz) { if (clazz == null || clazz.equals(String.class)) { QueryResult<T> result = (QueryResult<T>) distinct(key, query); result.setResultType(String.class.getName()); return result; } long start = startQuery(); List<T> list = new ArrayList<>(); MongoCursor iterator = mongoDBNativeQuery.distinct(key, query, clazz).iterator(); while (iterator.hasNext()) { Object next = iterator.next(); if (next != null) { list.add((T) next); } } return endQuery(list, start); } //
public QueryResult<String> distinct(String key, Bson query) { long start = startQuery(); List<String> l = new ArrayList<>(); MongoCursor<BsonValue> iterator = mongoDBNativeQuery.distinct(key, query, BsonValue.class).iterator(); while (iterator.hasNext()) { BsonValue value = iterator.next(); if (value == null || value.isNull()) { l.add(null); } else if (value.isString()) { l.add(value.asString().getValue()); } else { throw new IllegalArgumentException("Found result with BsonType != " + BsonType.STRING + " : " + value.getBsonType()); } } return endQuery(l, start); }
public QueryResult<UpdateResult> update(Bson query, Bson update, QueryOptions options) { long start = startQuery(); boolean upsert = false; boolean multi = false; boolean replace = false; if (options != null) { upsert = options.getBoolean(UPSERT); multi = options.getBoolean(MULTI); replace = options.getBoolean(REPLACE); } UpdateResult updateResult; if (replace) { updateResult = mongoDBNativeQuery.replace(query, update, upsert); } else { updateResult = mongoDBNativeQuery.update(query, update, upsert, multi); } return endQuery(Collections.singletonList(updateResult), start); }
public QueryResult<BulkWriteResult> update(List<? extends Bson> queries, List<? extends Bson> updates, QueryOptions options) { long start = startQuery(); boolean upsert = false; boolean multi = false; boolean replace = false; if (options != null) { upsert = options.getBoolean(UPSERT); multi = options.getBoolean(MULTI); replace = options.getBoolean(REPLACE); } com.mongodb.bulk.BulkWriteResult wr; if (replace) { wr = mongoDBNativeQuery.replace(queries, updates, upsert); } else { wr = mongoDBNativeQuery.update(queries, updates, upsert, multi); } return endQuery(Collections.singletonList(wr), start); }
} catch (IOException e) { cursor.close(); queryResult = endQuery(null, start); queryResult.setErrorMsg(e.getMessage() + " " + Arrays.toString(e.getStackTrace())); return queryResult; queryResult = endQuery(list, numTotalResults, start); } else { queryResult = endQuery(list, start); queryResult = endQuery(list, start);
public QueryResult createIndex(Bson keys, ObjectMap options) { long start = startQuery(); IndexOptions i = new IndexOptions(); if (options.containsKey(UNIQUE)) { i.unique(options.getBoolean(UNIQUE)); } if (options.containsKey(BACKGROUND)) { i.background(options.getBoolean(BACKGROUND)); } if (options.containsKey(SPARSE)) { i.sparse(options.getBoolean(SPARSE)); } if (options.containsKey(NAME)) { i.name(options.getString(NAME)); } mongoDBNativeQuery.createIndex(keys, i); QueryResult queryResult = endQuery(Collections.emptyList(), start); return queryResult; }