DATAMONGO-1176 - Cleanup.
- Update licenses headers. - Renname variables and methods from dbo -> document. - Remove deprecations. - Remove unused code blocks. - Upgrade to MongoDB Java Driver 3.3
This commit is contained in:
committed by
Oliver Gierke
parent
2d3efdc0b4
commit
054274392e
@@ -18,7 +18,7 @@
|
||||
<properties>
|
||||
<objenesis>1.3</objenesis>
|
||||
<equalsverifier>1.5</equalsverifier>
|
||||
<mongo>3.2.2</mongo>
|
||||
<mongo>3.3.0</mongo>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -21,6 +21,8 @@ import org.springframework.data.mongodb.core.query.Query;
|
||||
import org.springframework.data.mongodb.core.query.Update;
|
||||
import org.springframework.data.util.Pair;
|
||||
|
||||
import com.mongodb.bulk.BulkWriteResult;
|
||||
|
||||
/**
|
||||
* Bulk operations for insert/update/remove actions on a collection. These bulks operation are available since MongoDB
|
||||
* 2.6 and make use of low level bulk commands on the protocol level. This interface defines a fluent API to add
|
||||
@@ -36,7 +38,7 @@ public interface BulkOperations {
|
||||
/**
|
||||
* Mode for bulk operation.
|
||||
**/
|
||||
public enum BulkMode {
|
||||
enum BulkMode {
|
||||
|
||||
/** Perform bulk operations in sequence. The first error will cancel processing. */
|
||||
ORDERED,
|
||||
@@ -139,5 +141,5 @@ public interface BulkOperations {
|
||||
* @return Result of the bulk operation providing counters for inserts/updates etc.
|
||||
* @throws {@link BulkOperationException} if an error occurred during bulk processing.
|
||||
*/
|
||||
com.mongodb.bulk.BulkWriteResult execute();
|
||||
BulkWriteResult execute();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,8 +21,24 @@ import org.springframework.dao.DataAccessException;
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.client.MongoCollection;
|
||||
|
||||
/**
|
||||
* Callback interface for executing actions against a {@link MongoCollection}
|
||||
*
|
||||
* @author Mark Pollak
|
||||
* @author Grame Rocher
|
||||
* @author Oliver Gierke
|
||||
* @author John Brisbin
|
||||
* @auhtor Christoph Strobl
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface CollectionCallback<T> {
|
||||
|
||||
/**
|
||||
* @param collection never {@literal null}.
|
||||
* @return
|
||||
* @throws MongoException
|
||||
* @throws DataAccessException
|
||||
*/
|
||||
T doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,13 +17,13 @@ package org.springframework.data.mongodb.core;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
import com.mongodb.DBCursor;
|
||||
import com.mongodb.client.FindIterable;
|
||||
|
||||
/**
|
||||
* Simple callback interface to allow customization of a {@link DBCursor}.
|
||||
* Simple callback interface to allow customization of a {@link FindIterable}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
interface CursorPreparer {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,10 @@ import org.springframework.dao.DataAccessException;
|
||||
import com.mongodb.MongoException;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public interface DbCallback<T> {
|
||||
|
||||
T doInDB(MongoDatabase db) throws MongoException, DataAccessException;
|
||||
|
||||
@@ -43,6 +43,7 @@ import com.mongodb.client.model.WriteModel;
|
||||
*
|
||||
* @author Tobias Trelle
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.9
|
||||
*/
|
||||
class DefaultBulkOperations implements BulkOperations {
|
||||
@@ -50,7 +51,6 @@ class DefaultBulkOperations implements BulkOperations {
|
||||
private final MongoOperations mongoOperations;
|
||||
private final BulkMode bulkMode;
|
||||
private final String collectionName;
|
||||
private final Class<?> entityType;
|
||||
|
||||
private PersistenceExceptionTranslator exceptionTranslator;
|
||||
private WriteConcernResolver writeConcernResolver;
|
||||
@@ -79,7 +79,6 @@ class DefaultBulkOperations implements BulkOperations {
|
||||
this.mongoOperations = mongoOperations;
|
||||
this.bulkMode = bulkMode;
|
||||
this.collectionName = collectionName;
|
||||
this.entityType = entityType;
|
||||
|
||||
this.exceptionTranslator = new MongoExceptionTranslator();
|
||||
this.writeConcernResolver = DefaultWriteConcernResolver.INSTANCE;
|
||||
@@ -237,8 +236,6 @@ class DefaultBulkOperations implements BulkOperations {
|
||||
Assert.notNull(query, "Query must not be null!");
|
||||
|
||||
models.add(new DeleteManyModel<Document>(query.getQueryObject()));
|
||||
// bulk.find(query.getQueryObject()).remove();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -86,9 +86,6 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
if (indexOptions.containsKey("unique")) {
|
||||
ops = ops.unique((Boolean) indexOptions.get("unique"));
|
||||
}
|
||||
// if(indexOptions.containsField("dropDuplicates")) {
|
||||
// ops = ops.((boolean)indexOptions.get("dropDuplicates"));
|
||||
// }
|
||||
if (indexOptions.containsKey("sparse")) {
|
||||
ops = ops.sparse((Boolean) indexOptions.get("sparse"));
|
||||
}
|
||||
@@ -151,22 +148,6 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
dropIndex("*");
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.IndexOperations#resetIndexCache()
|
||||
*/
|
||||
@Deprecated
|
||||
public void resetIndexCache() {
|
||||
mongoOperations.execute(collectionName, new CollectionCallback<Void>() {
|
||||
public Void doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
|
||||
|
||||
// TODO remove this one
|
||||
// ReflectiveDBCollectionInvoker.resetIndexCache(collection);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.IndexOperations#getIndexInfo()
|
||||
@@ -177,25 +158,25 @@ public class DefaultIndexOperations implements IndexOperations {
|
||||
public List<IndexInfo> doInCollection(MongoCollection<Document> collection)
|
||||
throws MongoException, DataAccessException {
|
||||
|
||||
MongoCursor<Document> dbObjectList = collection.listIndexes(Document.class).iterator();
|
||||
return getIndexData(dbObjectList);
|
||||
MongoCursor<Document> cursor = collection.listIndexes(Document.class).iterator();
|
||||
return getIndexData(cursor);
|
||||
}
|
||||
|
||||
private List<IndexInfo> getIndexData(MongoCursor<Document> dbObjectList) {
|
||||
private List<IndexInfo> getIndexData(MongoCursor<Document> cursor) {
|
||||
|
||||
List<IndexInfo> indexInfoList = new ArrayList<IndexInfo>();
|
||||
|
||||
while (dbObjectList.hasNext()) {
|
||||
while (cursor.hasNext()) {
|
||||
|
||||
Document ix = dbObjectList.next();
|
||||
Document keyDbObject = (Document) ix.get("key");
|
||||
int numberOfElements = keyDbObject.keySet().size();
|
||||
Document ix = cursor.next();
|
||||
Document keyDocument = (Document) ix.get("key");
|
||||
int numberOfElements = keyDocument.keySet().size();
|
||||
|
||||
List<IndexField> indexFields = new ArrayList<IndexField>(numberOfElements);
|
||||
|
||||
for (String key : keyDbObject.keySet()) {
|
||||
for (String key : keyDocument.keySet()) {
|
||||
|
||||
Object value = keyDbObject.get(key);
|
||||
Object value = keyDocument.get(key);
|
||||
|
||||
if (TWO_D_IDENTIFIERS.contains(value)) {
|
||||
indexFields.add(IndexField.geo(key));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,8 +28,13 @@ import com.mongodb.MongoException;
|
||||
* later inspection.
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Grame Rocher
|
||||
* @author Oliver Gierke
|
||||
* @author John Brisbin
|
||||
* @author Christoph Strobl
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface DocumentCallbackHandler {
|
||||
|
||||
void processDocument(Document dbObject) throws MongoException, DataAccessException;
|
||||
void processDocument(Document document) throws MongoException, DataAccessException;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,9 @@ import org.springframework.util.Assert;
|
||||
* Value object to mitigate different representations of geo command execution results in MongoDB.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @soundtrack Fruitcake - Jeff Coffin (The Inside of the Outside)
|
||||
* @since 1.9
|
||||
*/
|
||||
class GeoCommandStatistics {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -49,15 +49,6 @@ public interface IndexOperations {
|
||||
*/
|
||||
void dropAllIndexes();
|
||||
|
||||
/**
|
||||
* Clears all indices that have not yet been applied to this collection.
|
||||
*
|
||||
* @deprecated since 1.7. The MongoDB Java driver version 3.0 does no longer support reseting the index cache.
|
||||
* @throws {@link UnsupportedOperationException} when used with MongoDB Java driver version 3.0.
|
||||
*/
|
||||
@Deprecated
|
||||
void resetIndexCache();
|
||||
|
||||
/**
|
||||
* Returns the index information on the collection.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2012 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import com.mongodb.WriteConcern;
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class MongoAction {
|
||||
|
||||
@@ -72,14 +73,6 @@ public class MongoAction {
|
||||
return defaultWriteConcern;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #getEntityType()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public Class<?> getEntityClass() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
public Class<?> getEntityType() {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -84,18 +84,6 @@ public interface MongoOperations {
|
||||
*/
|
||||
Document executeCommand(Document command);
|
||||
|
||||
/**
|
||||
* Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's DAO
|
||||
* exception hierarchy.
|
||||
*
|
||||
* @param command a MongoDB command
|
||||
* @param options query options to use
|
||||
* @deprecated since 1.7. Please use {@link #executeCommand(Document, ReadPreference)}, as the MongoDB Java driver
|
||||
* version 3 no longer supports this operation.
|
||||
*/
|
||||
@Deprecated
|
||||
Document executeCommand(Document command, int options);
|
||||
|
||||
/**
|
||||
* Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's data
|
||||
* access exception hierarchy.
|
||||
@@ -152,22 +140,6 @@ public interface MongoOperations {
|
||||
*/
|
||||
<T> T execute(String collectionName, CollectionCallback<T> action);
|
||||
|
||||
/**
|
||||
* Executes the given {@link DbCallback} within the same connection to the database so as to ensure consistency in a
|
||||
* write heavy environment where you may read the data that you wrote. See the comments on {@see <a
|
||||
* href=http://www.mongodb.org/display/DOCS/Java+Driver+Concurrency>Java Driver Concurrency</a>}
|
||||
* <p/>
|
||||
* Allows for returning a result object, that is a domain object or a collection of domain objects.
|
||||
*
|
||||
* @param <T> return type
|
||||
* @param action callback that specified the MongoDB actions to perform on the DB instance
|
||||
* @return a result object returned by the action or <tt>null</tt>
|
||||
* @deprecated since 1.7 as the MongoDB Java driver version 3 does not longer support request boundaries via
|
||||
* {@link DB#requestStart()} and {@link DB#requestDone()}.
|
||||
*/
|
||||
@Deprecated
|
||||
<T> T executeInSession(DbCallback<T> action);
|
||||
|
||||
/**
|
||||
* Executes the given {@link Query} on the entity collection of the specified {@code entityType} backed by a Mongo DB
|
||||
* {@link Cursor}.
|
||||
|
||||
@@ -361,7 +361,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
FindIterable<Document> cursor = collection.find(mappedQuery).projection(mappedFields);
|
||||
QueryCursorPreparer cursorPreparer = new QueryCursorPreparer(query, entityType);
|
||||
|
||||
ReadDbObjectCallback<T> readCallback = new ReadDbObjectCallback<T>(mongoConverter, entityType,
|
||||
ReadDocumentCallback<T> readCallback = new ReadDocumentCallback<T>(mongoConverter, entityType,
|
||||
collectionName);
|
||||
|
||||
return new CloseableIterableCursorAdapter<T>(cursorPreparer.prepare(cursor), exceptionTranslator, readCallback);
|
||||
@@ -393,16 +393,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.MongoOperations#executeCommand(com.mongodb.Document, int)
|
||||
*/
|
||||
@Deprecated
|
||||
public Document executeCommand(final Document command, final int options) {
|
||||
return executeCommand(command,
|
||||
(options & Bytes.QUERYOPTION_SLAVEOK) != 0 ? ReadPreference.secondaryPreferred() : ReadPreference.primary());
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.MongoOperations#executeCommand(com.mongodb.Document, com.mongodb.ReadPreference)
|
||||
@@ -490,20 +480,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.MongoOperations#executeInSession(org.springframework.data.mongodb.core.DbCallback)
|
||||
*/
|
||||
@Deprecated
|
||||
public <T> T executeInSession(final DbCallback<T> action) {
|
||||
|
||||
return execute(new DbCallback<T>() {
|
||||
public T doInDB(MongoDatabase db) throws MongoException, DataAccessException {
|
||||
return action.doInDB(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public <T> MongoCollection<Document> createCollection(Class<T> entityClass) {
|
||||
return createCollection(determineCollectionName(entityClass));
|
||||
}
|
||||
@@ -518,7 +494,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
|
||||
public MongoCollection<Document> createCollection(final String collectionName,
|
||||
final CollectionOptions collectionOptions) {
|
||||
return doCreateCollection(collectionName, convertToDbObject(collectionOptions));
|
||||
return doCreateCollection(collectionName, convertToDocument(collectionOptions));
|
||||
}
|
||||
|
||||
public MongoCollection<Document> getCollection(final String collectionName) {
|
||||
@@ -697,8 +673,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
List<Object> results = (List<Object>) commandResult.get("results");
|
||||
results = results == null ? Collections.emptyList() : results;
|
||||
|
||||
DbObjectCallback<GeoResult<T>> callback = new GeoNearResultDbObjectCallback<T>(
|
||||
new ReadDbObjectCallback<T>(mongoConverter, entityClass, collectionName), near.getMetric());
|
||||
DocumentCallback<GeoResult<T>> callback = new GeoNearResultDocumentCallback<T>(
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName), near.getMetric());
|
||||
List<GeoResult<T>> result = new ArrayList<GeoResult<T>>(results.size());
|
||||
|
||||
int index = 0;
|
||||
@@ -774,13 +750,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
public long count(Query query, Class<?> entityClass, String collectionName) {
|
||||
|
||||
Assert.hasText(collectionName);
|
||||
final Document dbObject = query == null ? null
|
||||
final Document document = query == null ? null
|
||||
: queryMapper.getMappedObject(query.getQueryObject(),
|
||||
entityClass == null ? null : mappingContext.getPersistentEntity(entityClass));
|
||||
|
||||
return execute(collectionName, new CollectionCallback<Long>() {
|
||||
public Long doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
|
||||
return collection.count(dbObject);
|
||||
return collection.count(document);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -860,7 +836,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
|
||||
Document dbDoc = toDbObject(objectToSave, writer);
|
||||
Document dbDoc = toDocument(objectToSave, writer);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
Object id = insertDocument(collectionName, dbDoc, objectToSave.getClass());
|
||||
@@ -874,7 +850,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
* @param writer
|
||||
* @return
|
||||
*/
|
||||
private <T> Document toDbObject(T objectToSave, MongoWriter<T> writer) {
|
||||
private <T> Document toDocument(T objectToSave, MongoWriter<T> writer) {
|
||||
|
||||
if (objectToSave instanceof Document) {
|
||||
return (Document) objectToSave;
|
||||
@@ -958,7 +934,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
|
||||
Assert.notNull(writer);
|
||||
|
||||
List<Document> dbObjectList = new ArrayList<Document>();
|
||||
List<Document> documentList = new ArrayList<Document>();
|
||||
for (T o : batchToSave) {
|
||||
|
||||
initializeVersionProperty(o);
|
||||
@@ -968,16 +944,16 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
writer.write(o, dbDoc);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(o, dbDoc, collectionName));
|
||||
dbObjectList.add(dbDoc);
|
||||
documentList.add(dbDoc);
|
||||
}
|
||||
|
||||
List<Object> ids = consolidateIdentifiers(insertDBObjectList(collectionName, dbObjectList), dbObjectList);
|
||||
List<Object> ids = consolidateIdentifiers(insertDocumentList(collectionName, documentList), documentList);
|
||||
|
||||
int i = 0;
|
||||
for (T obj : batchToSave) {
|
||||
if (i < ids.size()) {
|
||||
populateIdIfNecessary(obj, ids.get(i));
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(obj, dbObjectList.get(i), collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(obj, documentList.get(i), collectionName));
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -1030,13 +1006,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
// Bump version number
|
||||
convertingAccessor.setProperty(versionProperty, versionNumber.longValue() + 1);
|
||||
|
||||
Document dbObject = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
this.mongoConverter.write(objectToSave, dbObject);
|
||||
this.mongoConverter.write(objectToSave, document);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbObject, collectionName));
|
||||
Update update = Update.fromDocument(dbObject, ID_FIELD);
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, document, collectionName));
|
||||
Update update = Update.fromDocument(document, ID_FIELD);
|
||||
|
||||
UpdateResult result = doUpdate(collectionName, query, update, objectToSave.getClass(), false, false);
|
||||
|
||||
@@ -1045,7 +1021,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
String.format("Cannot save entity %s with version %s to collection %s. Has it been modified meanwhile?", id,
|
||||
versionNumber, collectionName));
|
||||
}
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbObject, collectionName));
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, document, collectionName));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1055,7 +1031,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
|
||||
maybeEmitEvent(new BeforeConvertEvent<T>(objectToSave, collectionName));
|
||||
|
||||
Document dbDoc = toDbObject(objectToSave, writer);
|
||||
Document dbDoc = toDocument(objectToSave, writer);
|
||||
|
||||
maybeEmitEvent(new BeforeSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
Object id = saveDocument(collectionName, dbDoc, objectToSave.getClass());
|
||||
@@ -1064,31 +1040,30 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
maybeEmitEvent(new AfterSaveEvent<T>(objectToSave, dbDoc, collectionName));
|
||||
}
|
||||
|
||||
protected Object insertDocument(final String collectionName, final Document dbDoc, final Class<?> entityClass) {
|
||||
protected Object insertDocument(final String collectionName, final Document document, final Class<?> entityClass) {
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Inserting Document containing fields: {} in collection: {}", dbDoc.keySet(), collectionName);
|
||||
LOGGER.debug("Inserting Document containing fields: {} in collection: {}", document.keySet(), collectionName);
|
||||
}
|
||||
|
||||
return execute(collectionName, new CollectionCallback<Object>() {
|
||||
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
|
||||
MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.INSERT, collectionName,
|
||||
entityClass, dbDoc, null);
|
||||
entityClass, document, null);
|
||||
WriteConcern writeConcernToUse = prepareWriteConcern(mongoAction);
|
||||
if (writeConcernToUse == null) {
|
||||
collection.insertOne(dbDoc);
|
||||
collection.insertOne(document);
|
||||
} else {
|
||||
collection.withWriteConcern(writeConcernToUse).insertOne(dbDoc);
|
||||
collection.withWriteConcern(writeConcernToUse).insertOne(document);
|
||||
}
|
||||
// handleAnyWriteResultErrors(writeResult, dbDoc, MongoActionOperation.INSERT);
|
||||
return dbDoc.get(ID_FIELD);
|
||||
return document.get(ID_FIELD);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// TODO: 2.0 - Change method signature to return List<Object> and return all identifiers (DATAMONGO-1513,
|
||||
// DATAMONGO-1519)
|
||||
protected List<ObjectId> insertDBObjectList(final String collectionName, final List<Document> documents) {
|
||||
protected List<ObjectId> insertDocumentList(final String collectionName, final List<Document> documents) {
|
||||
if (documents.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -1109,9 +1084,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
collection.withWriteConcern(writeConcernToUse).insertMany(documents);
|
||||
}
|
||||
|
||||
// WriteResult writeResult = writeConcernToUse == null ? collection.insert(dbDocList)
|
||||
// : collection.insert(dbDocList.toArray((Document[]) new Document[dbDocList.size()]), writeConcernToUse);
|
||||
// handleAnyWriteResultErrors(writeResult, null, MongoActionOperation.INSERT_LIST);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
@@ -1155,7 +1127,6 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
collection.withWriteConcern(writeConcernToUse).replaceOne(Filters.eq(ID_FIELD, dbDoc.get(ID_FIELD)), dbDoc,
|
||||
new UpdateOptions().upsert(true));
|
||||
}
|
||||
// handleAnyWriteResultErrors(writeResult, dbDoc, MongoActionOperation.SAVE);
|
||||
return dbDoc.get(ID_FIELD);
|
||||
}
|
||||
});
|
||||
@@ -1250,13 +1221,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean dbObjectContainsVersionProperty(Document dbObject, MongoPersistentEntity<?> persistentEntity) {
|
||||
private boolean documentContainsVersionProperty(Document document, MongoPersistentEntity<?> persistentEntity) {
|
||||
|
||||
if (persistentEntity == null || !persistentEntity.hasVersionProperty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return dbObject.containsKey(persistentEntity.getVersionProperty().getFieldName());
|
||||
return document.containsKey(persistentEntity.getVersionProperty().getFieldName());
|
||||
}
|
||||
|
||||
public DeleteResult remove(Object object) {
|
||||
@@ -1389,7 +1360,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
|
||||
maybeEmitEvent(new BeforeDeleteEvent<T>(queryObject, entityClass, collectionName));
|
||||
|
||||
Document dboq = queryMapper.getMappedObject(queryObject, entity);
|
||||
Document mappedQuery = queryMapper.getMappedObject(queryObject, entity);
|
||||
|
||||
MongoAction mongoAction = new MongoAction(writeConcern, MongoActionOperation.REMOVE, collectionName,
|
||||
entityClass, null, queryObject);
|
||||
@@ -1398,13 +1369,13 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
DeleteResult dr = null;
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Remove using query: {} in collection: {}.",
|
||||
new Object[] { serializeToJsonSafely(dboq), collectionName });
|
||||
new Object[] { serializeToJsonSafely(mappedQuery), collectionName });
|
||||
}
|
||||
|
||||
if (writeConcernToUse == null) {
|
||||
dr = collection.deleteMany(dboq);
|
||||
dr = collection.deleteMany(mappedQuery);
|
||||
} else {
|
||||
dr = collection.withWriteConcern(writeConcernToUse).deleteMany(dboq);
|
||||
dr = collection.withWriteConcern(writeConcernToUse).deleteMany(mappedQuery);
|
||||
}
|
||||
|
||||
maybeEmitEvent(new AfterDeleteEvent<T>(queryObject, entityClass, collectionName));
|
||||
@@ -1420,7 +1391,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
|
||||
public <T> List<T> findAll(Class<T> entityClass, String collectionName) {
|
||||
return executeFindMultiInternal(new FindCallback(null), null,
|
||||
new ReadDbObjectCallback<T>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
public <T> MapReduceResults<T> mapReduce(String inputCollectionName, String mapFunction, String reduceFunction,
|
||||
@@ -1448,7 +1419,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
MongoCollection<Document> inputCollection = getCollection(inputCollectionName);
|
||||
|
||||
// MapReduceOp
|
||||
MapReduceIterable<Document> result = inputCollection.mapReduce(mapFunction, reduceFunction);
|
||||
MapReduceIterable<Document> result = inputCollection.mapReduce(mapFunc, reduceFunc);
|
||||
if (query != null && result != null) {
|
||||
|
||||
if (query.getLimit() > 0 && mapReduceOptions.getLimit() == null) {
|
||||
@@ -1485,10 +1456,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
}
|
||||
List<T> mappedResults = new ArrayList<T>();
|
||||
DbObjectCallback<T> callback = new ReadDbObjectCallback<T>(mongoConverter, entityClass, inputCollectionName);
|
||||
DocumentCallback<T> callback = new ReadDocumentCallback<T>(mongoConverter, entityClass, inputCollectionName);
|
||||
|
||||
for (Document dbObject : result) {
|
||||
mappedResults.add(callback.doWith(dbObject));
|
||||
for (Document document : result) {
|
||||
mappedResults.add(callback.doWith(document));
|
||||
}
|
||||
|
||||
return new MapReduceResults<T>(mappedResults, new Document());
|
||||
@@ -1501,36 +1472,36 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
public <T> GroupByResults<T> group(Criteria criteria, String inputCollectionName, GroupBy groupBy,
|
||||
Class<T> entityClass) {
|
||||
|
||||
Document dbo = groupBy.getGroupByObject();
|
||||
dbo.put("ns", inputCollectionName);
|
||||
Document document = groupBy.getGroupByObject();
|
||||
document.put("ns", inputCollectionName);
|
||||
|
||||
if (criteria == null) {
|
||||
dbo.put("cond", null);
|
||||
document.put("cond", null);
|
||||
} else {
|
||||
dbo.put("cond", queryMapper.getMappedObject(criteria.getCriteriaObject(), null));
|
||||
document.put("cond", queryMapper.getMappedObject(criteria.getCriteriaObject(), null));
|
||||
}
|
||||
// If initial document was a JavaScript string, potentially loaded by Spring's Resource abstraction, load it and
|
||||
// convert to Document
|
||||
|
||||
if (dbo.containsKey("initial")) {
|
||||
Object initialObj = dbo.get("initial");
|
||||
if (document.containsKey("initial")) {
|
||||
Object initialObj = document.get("initial");
|
||||
if (initialObj instanceof String) {
|
||||
String initialAsString = replaceWithResourceIfNecessary((String) initialObj);
|
||||
dbo.put("initial", Document.parse(initialAsString));
|
||||
document.put("initial", Document.parse(initialAsString));
|
||||
}
|
||||
}
|
||||
|
||||
if (dbo.containsKey("$reduce")) {
|
||||
dbo.put("$reduce", replaceWithResourceIfNecessary(dbo.get("$reduce").toString()));
|
||||
if (document.containsKey("$reduce")) {
|
||||
document.put("$reduce", replaceWithResourceIfNecessary(document.get("$reduce").toString()));
|
||||
}
|
||||
if (dbo.containsKey("$keyf")) {
|
||||
dbo.put("$keyf", replaceWithResourceIfNecessary(dbo.get("$keyf").toString()));
|
||||
if (document.containsKey("$keyf")) {
|
||||
document.put("$keyf", replaceWithResourceIfNecessary(document.get("$keyf").toString()));
|
||||
}
|
||||
if (dbo.containsKey("finalize")) {
|
||||
dbo.put("finalize", replaceWithResourceIfNecessary(dbo.get("finalize").toString()));
|
||||
if (document.containsKey("finalize")) {
|
||||
document.put("finalize", replaceWithResourceIfNecessary(document.get("finalize").toString()));
|
||||
}
|
||||
|
||||
Document commandObject = new Document("group", dbo);
|
||||
Document commandObject = new Document("group", document);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Executing Group with Document [{}]", serializeToJsonSafely(commandObject));
|
||||
@@ -1545,10 +1516,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterable<Document> resultSet = (Iterable<Document>) commandResult.get("retval");
|
||||
List<T> mappedResults = new ArrayList<T>();
|
||||
DbObjectCallback<T> callback = new ReadDbObjectCallback<T>(mongoConverter, entityClass, inputCollectionName);
|
||||
DocumentCallback<T> callback = new ReadDocumentCallback<T>(mongoConverter, entityClass, inputCollectionName);
|
||||
|
||||
for (Document dbObject : resultSet) {
|
||||
mappedResults.add(callback.doWith(dbObject));
|
||||
for (Document resultDocument : resultSet) {
|
||||
mappedResults.add(callback.doWith(resultDocument));
|
||||
}
|
||||
|
||||
return new GroupByResults<T>(mappedResults, commandResult);
|
||||
@@ -1638,7 +1609,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
Assert.notNull(outputType, "Output type must not be null!");
|
||||
|
||||
AggregationOperationContext rootContext = context == null ? Aggregation.DEFAULT_CONTEXT : context;
|
||||
Document command = aggregation.toDbObject(collectionName, rootContext);
|
||||
Document command = aggregation.toDocument(collectionName, rootContext);
|
||||
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Executing aggregation: {}", serializeToJsonSafely(command));
|
||||
@@ -1666,11 +1637,11 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
DbObjectCallback<O> callback = new UnwrapAndReadDbObjectCallback<O>(mongoConverter, outputType, collectionName);
|
||||
DocumentCallback<O> callback = new UnwrapAndReadDocumentCallback<O>(mongoConverter, outputType, collectionName);
|
||||
|
||||
List<O> mappedResults = new ArrayList<O>();
|
||||
for (Document dbObject : resultSet) {
|
||||
mappedResults.add(callback.doWith(dbObject));
|
||||
for (Document document : resultSet) {
|
||||
mappedResults.add(callback.doWith(document));
|
||||
}
|
||||
|
||||
return mappedResults;
|
||||
@@ -1785,7 +1756,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
|
||||
return executeFindOneInternal(new FindOneCallback(mappedQuery, mappedFields),
|
||||
new ReadDbObjectCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1800,7 +1771,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
*/
|
||||
protected <T> List<T> doFind(String collectionName, Document query, Document fields, Class<T> entityClass) {
|
||||
return doFind(collectionName, query, fields, entityClass, null,
|
||||
new ReadDbObjectCallback<T>(this.mongoConverter, entityClass, collectionName));
|
||||
new ReadDocumentCallback<T>(this.mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1819,11 +1790,11 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
protected <T> List<T> doFind(String collectionName, Document query, Document fields, Class<T> entityClass,
|
||||
CursorPreparer preparer) {
|
||||
return doFind(collectionName, query, fields, entityClass, preparer,
|
||||
new ReadDbObjectCallback<T>(mongoConverter, entityClass, collectionName));
|
||||
new ReadDocumentCallback<T>(mongoConverter, entityClass, collectionName));
|
||||
}
|
||||
|
||||
protected <S, T> List<T> doFind(String collectionName, Document query, Document fields, Class<S> entityClass,
|
||||
CursorPreparer preparer, DbObjectCallback<T> objectCallback) {
|
||||
CursorPreparer preparer, DocumentCallback<T> objectCallback) {
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
@@ -1839,20 +1810,20 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
collectionName);
|
||||
}
|
||||
|
||||
protected Document convertToDbObject(CollectionOptions collectionOptions) {
|
||||
Document dbo = new Document();
|
||||
protected Document convertToDocument(CollectionOptions collectionOptions) {
|
||||
Document document = new Document();
|
||||
if (collectionOptions != null) {
|
||||
if (collectionOptions.getCapped() != null) {
|
||||
dbo.put("capped", collectionOptions.getCapped().booleanValue());
|
||||
document.put("capped", collectionOptions.getCapped().booleanValue());
|
||||
}
|
||||
if (collectionOptions.getSize() != null) {
|
||||
dbo.put("size", collectionOptions.getSize().intValue());
|
||||
document.put("size", collectionOptions.getSize().intValue());
|
||||
}
|
||||
if (collectionOptions.getMaxDocuments() != null) {
|
||||
dbo.put("max", collectionOptions.getMaxDocuments().intValue());
|
||||
document.put("max", collectionOptions.getMaxDocuments().intValue());
|
||||
}
|
||||
}
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1879,7 +1850,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass);
|
||||
|
||||
return executeFindOneInternal(new FindAndRemoveCallback(queryMapper.getMappedObject(query, entity), fields, sort),
|
||||
new ReadDbObjectCallback<T>(readerToUse, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<T>(readerToUse, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
protected <T> T doFindAndModify(String collectionName, Document query, Document fields, Document sort,
|
||||
@@ -1906,7 +1877,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
|
||||
return executeFindOneInternal(new FindAndModifyCallback(mappedQuery, fields, sort, mappedUpdate, options),
|
||||
new ReadDbObjectCallback<T>(readerToUse, entityClass, collectionName), collectionName);
|
||||
new ReadDocumentCallback<T>(readerToUse, entityClass, collectionName), collectionName);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1922,8 +1893,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
|
||||
if (savedObject instanceof Document) {
|
||||
Document dbObject = (Document) savedObject;
|
||||
dbObject.put(ID_FIELD, id);
|
||||
Document document = (Document) savedObject;
|
||||
document.put(ID_FIELD, id);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1959,17 +1930,17 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
* collection of objects. It will take the following steps
|
||||
* <ol>
|
||||
* <li>Execute the given {@link ConnectionCallback} for a {@link Document}.</li>
|
||||
* <li>Apply the given {@link DbObjectCallback} to each of the {@link Document}s to obtain the result.</li>
|
||||
* <li>Apply the given {@link DocumentCallback} to each of the {@link Document}s to obtain the result.</li>
|
||||
* <ol>
|
||||
*
|
||||
* @param <T>
|
||||
* @param collectionCallback the callback to retrieve the {@link Document} with
|
||||
* @param objectCallback the {@link DbObjectCallback} to transform {@link Document}s into the actual domain type
|
||||
* @param objectCallback the {@link DocumentCallback} to transform {@link Document}s into the actual domain type
|
||||
* @param collectionName the collection to be queried
|
||||
* @return
|
||||
*/
|
||||
private <T> T executeFindOneInternal(CollectionCallback<Document> collectionCallback,
|
||||
DbObjectCallback<T> objectCallback, String collectionName) {
|
||||
DocumentCallback<T> objectCallback, String collectionName) {
|
||||
|
||||
try {
|
||||
T result = objectCallback
|
||||
@@ -1987,19 +1958,19 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
* <li>Execute the given {@link ConnectionCallback} for a {@link DBCursor}.</li>
|
||||
* <li>Prepare that {@link DBCursor} with the given {@link CursorPreparer} (will be skipped if {@link CursorPreparer}
|
||||
* is {@literal null}</li>
|
||||
* <li>Iterate over the {@link DBCursor} and applies the given {@link DbObjectCallback} to each of the
|
||||
* <li>Iterate over the {@link DBCursor} and applies the given {@link DocumentCallback} to each of the
|
||||
* {@link Document}s collecting the actual result {@link List}.</li>
|
||||
* <ol>
|
||||
*
|
||||
* @param <T>
|
||||
* @param collectionCallback the callback to retrieve the {@link DBCursor} with
|
||||
* @param preparer the {@link CursorPreparer} to potentially modify the {@link DBCursor} before ireating over it
|
||||
* @param objectCallback the {@link DbObjectCallback} to transform {@link Document}s into the actual domain type
|
||||
* @param objectCallback the {@link DocumentCallback} to transform {@link Document}s into the actual domain type
|
||||
* @param collectionName the collection to be queried
|
||||
* @return
|
||||
*/
|
||||
private <T> List<T> executeFindMultiInternal(CollectionCallback<FindIterable<Document>> collectionCallback,
|
||||
CursorPreparer preparer, DbObjectCallback<T> objectCallback, String collectionName) {
|
||||
CursorPreparer preparer, DocumentCallback<T> objectCallback, String collectionName) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -2054,8 +2025,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
cursor = iterable.iterator();
|
||||
|
||||
while (cursor.hasNext()) {
|
||||
Document dbobject = cursor.next();
|
||||
callbackHandler.processDocument(dbobject);
|
||||
callbackHandler.processDocument(cursor.next());
|
||||
}
|
||||
|
||||
} finally {
|
||||
@@ -2355,25 +2325,25 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
|
||||
interface DbObjectCallback<T> {
|
||||
interface DocumentCallback<T> {
|
||||
|
||||
T doWith(Document object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple {@link DbObjectCallback} that will transform {@link Document} into the given target type using the given
|
||||
* Simple {@link DocumentCallback} that will transform {@link Document} into the given target type using the given
|
||||
* {@link MongoReader}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
private class ReadDbObjectCallback<T> implements DbObjectCallback<T> {
|
||||
private class ReadDocumentCallback<T> implements DocumentCallback<T> {
|
||||
|
||||
private final EntityReader<? super T, Bson> reader;
|
||||
private final Class<T> type;
|
||||
private final String collectionName;
|
||||
|
||||
public ReadDbObjectCallback(EntityReader<? super T, Bson> reader, Class<T> type, String collectionName) {
|
||||
public ReadDocumentCallback(EntityReader<? super T, Bson> reader, Class<T> type, String collectionName) {
|
||||
|
||||
Assert.notNull(reader);
|
||||
Assert.notNull(type);
|
||||
@@ -2394,9 +2364,9 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
}
|
||||
|
||||
class UnwrapAndReadDbObjectCallback<T> extends ReadDbObjectCallback<T> {
|
||||
class UnwrapAndReadDocumentCallback<T> extends ReadDocumentCallback<T> {
|
||||
|
||||
public UnwrapAndReadDbObjectCallback(EntityReader<? super T, Bson> reader, Class<T> type, String collectionName) {
|
||||
public UnwrapAndReadDocumentCallback(EntityReader<? super T, Bson> reader, Class<T> type, String collectionName) {
|
||||
super(reader, type, collectionName);
|
||||
}
|
||||
|
||||
@@ -2459,8 +2429,8 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
cursorToUse = cursorToUse.limit(query.getLimit());
|
||||
}
|
||||
if (query.getSortObject() != null) {
|
||||
Document sortDbo = type != null ? getMappedSortObject(query, type) : query.getSortObject();
|
||||
cursorToUse = cursorToUse.sort(sortDbo);
|
||||
Document sort = type != null ? getMappedSortObject(query, type) : query.getSortObject();
|
||||
cursorToUse = cursorToUse.sort(sort);
|
||||
}
|
||||
|
||||
Document meta = new Document();
|
||||
@@ -2501,23 +2471,23 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link DbObjectCallback} that assumes a {@link GeoResult} to be created, delegates actual content unmarshalling to
|
||||
* {@link DocumentCallback} that assumes a {@link GeoResult} to be created, delegates actual content unmarshalling to
|
||||
* a delegate and creates a {@link GeoResult} from the result.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
static class GeoNearResultDbObjectCallback<T> implements DbObjectCallback<GeoResult<T>> {
|
||||
static class GeoNearResultDocumentCallback<T> implements DocumentCallback<GeoResult<T>> {
|
||||
|
||||
private final DbObjectCallback<T> delegate;
|
||||
private final DocumentCallback<T> delegate;
|
||||
private final Metric metric;
|
||||
|
||||
/**
|
||||
* Creates a new {@link GeoNearResultDbObjectCallback} using the given {@link DbObjectCallback} delegate for
|
||||
* Creates a new {@link GeoNearResultDocumentCallback} using the given {@link DocumentCallback} delegate for
|
||||
* {@link GeoResult} content unmarshalling.
|
||||
*
|
||||
* @param delegate must not be {@literal null}.
|
||||
*/
|
||||
public GeoNearResultDbObjectCallback(DbObjectCallback<T> delegate, Metric metric) {
|
||||
public GeoNearResultDocumentCallback(DocumentCallback<T> delegate, Metric metric) {
|
||||
Assert.notNull(delegate);
|
||||
this.delegate = delegate;
|
||||
this.metric = metric;
|
||||
@@ -2544,10 +2514,10 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
|
||||
private volatile MongoCursor<Document> cursor;
|
||||
private PersistenceExceptionTranslator exceptionTranslator;
|
||||
private DbObjectCallback<T> objectReadCallback;
|
||||
private DocumentCallback<T> objectReadCallback;
|
||||
|
||||
CloseableIterableCursorAdapter(MongoCursor<Document> cursor, PersistenceExceptionTranslator exceptionTranslator,
|
||||
DbObjectCallback<T> objectReadCallback) {
|
||||
DocumentCallback<T> objectReadCallback) {
|
||||
this.cursor = cursor;
|
||||
this.exceptionTranslator = exceptionTranslator;
|
||||
this.objectReadCallback = objectReadCallback;
|
||||
@@ -2561,7 +2531,7 @@ public class MongoTemplate implements MongoOperations, ApplicationContextAware {
|
||||
* @param objectReadCallback
|
||||
*/
|
||||
public CloseableIterableCursorAdapter(FindIterable<Document> cursor,
|
||||
PersistenceExceptionTranslator exceptionTranslator, DbObjectCallback<T> objectReadCallback) {
|
||||
PersistenceExceptionTranslator exceptionTranslator, DocumentCallback<T> objectReadCallback) {
|
||||
|
||||
this.cursor = cursor.iterator();
|
||||
this.exceptionTranslator = exceptionTranslator;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -494,7 +494,7 @@ public class Aggregation {
|
||||
* @param inputCollectionName the name of the input collection
|
||||
* @return the {@code Document} representing this aggregation
|
||||
*/
|
||||
public Document toDbObject(String inputCollectionName, AggregationOperationContext rootContext) {
|
||||
public Document toDocument(String inputCollectionName, AggregationOperationContext rootContext) {
|
||||
|
||||
AggregationOperationContext context = rootContext;
|
||||
List<Document> operationDocuments = new ArrayList<Document>(operations.size());
|
||||
@@ -530,7 +530,7 @@ public class Aggregation {
|
||||
@Override
|
||||
public String toString() {
|
||||
return SerializationUtils
|
||||
.serializeToJsonSafely(toDbObject("__collection__", new NoOpAggregationOperationContext()));
|
||||
.serializeToJsonSafely(toDocument("__collection__", new NoOpAggregationOperationContext()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -545,8 +545,8 @@ public class Aggregation {
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getMappedObject(com.mongodb.Document)
|
||||
*/
|
||||
@Override
|
||||
public Document getMappedObject(Document dbObject) {
|
||||
return dbObject;
|
||||
public Document getMappedObject(Document document) {
|
||||
return document;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -34,5 +34,5 @@ public interface AggregationExpression {
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
Document toDbObject(AggregationOperationContext context);
|
||||
Document toDocument(AggregationOperationContext context);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,8 @@ import org.springframework.util.Assert;
|
||||
* {@link AggregationExpressionTransformationContext}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.4
|
||||
*/
|
||||
interface AggregationExpressionTransformer
|
||||
extends ExpressionTransformer<AggregationExpressionTransformationContext<ExpressionNode>> {
|
||||
@@ -38,7 +40,7 @@ interface AggregationExpressionTransformer
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
*/
|
||||
public static class AggregationExpressionTransformationContext<T extends ExpressionNode>
|
||||
class AggregationExpressionTransformationContext<T extends ExpressionNode>
|
||||
extends ExpressionTransformationContextSupport<T> {
|
||||
|
||||
private final AggregationOperationContext aggregationContext;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,8 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @since 1.10
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
public enum AggregationFunctionExpressions {
|
||||
|
||||
@@ -77,7 +78,7 @@ public enum AggregationFunctionExpressions {
|
||||
* @see org.springframework.data.mongodb.core.aggregation.Expression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
@Override
|
||||
public Document toDbObject(AggregationOperationContext context) {
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
List<Object> args = new ArrayList<Object>(values.size());
|
||||
|
||||
@@ -91,7 +92,7 @@ public enum AggregationFunctionExpressions {
|
||||
private static Object unpack(Object value, AggregationOperationContext context) {
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDbObject(context);
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
}
|
||||
|
||||
if (value instanceof Field) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import org.bson.Document;
|
||||
* @author Sebastian Herold
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public interface AggregationOperation {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,6 +22,7 @@ import org.springframework.data.mongodb.core.aggregation.ExposedFields.FieldRefe
|
||||
* The context for an {@link AggregationOperation}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public interface AggregationOperationContext {
|
||||
@@ -29,10 +30,10 @@ public interface AggregationOperationContext {
|
||||
/**
|
||||
* Returns the mapped {@link Document}, potentially converting the source considering mapping metadata etc.
|
||||
*
|
||||
* @param dbObject will never be {@literal null}.
|
||||
* @param document will never be {@literal null}.
|
||||
* @return must not be {@literal null}.
|
||||
*/
|
||||
Document getMappedObject(Document dbObject);
|
||||
Document getMappedObject(Document document);
|
||||
|
||||
/**
|
||||
* Returns a {@link FieldReference} for the given field or {@literal null} if the context does not expose the given
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.bson.Document;
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @see Aggregation#withOptions(AggregationOptions)
|
||||
* @see TypedAggregation#withOptions(AggregationOptions)
|
||||
* @since 1.6
|
||||
@@ -111,14 +112,14 @@ public class AggregationOptions {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Document toDbObject() {
|
||||
public Document toDocument() {
|
||||
|
||||
Document dbo = new Document();
|
||||
dbo.put(ALLOW_DISK_USE, allowDiskUse);
|
||||
dbo.put(EXPLAIN, explain);
|
||||
dbo.put(CURSOR, cursor);
|
||||
Document document = new Document();
|
||||
document.put(ALLOW_DISK_USE, allowDiskUse);
|
||||
document.put(EXPLAIN, explain);
|
||||
document.put(CURSOR, cursor);
|
||||
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -126,7 +127,7 @@ public class AggregationOptions {
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return toDbObject().toJson();
|
||||
return toDocument().toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,7 @@ import org.springframework.util.Assert;
|
||||
* @author Tobias Trelle
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @param <T> The class in which the results are mapped onto.
|
||||
* @since 1.3
|
||||
*/
|
||||
|
||||
@@ -75,7 +75,7 @@ public class ConditionalOperator implements AggregationExpression {
|
||||
* @param thenValue must not be {@literal null}.
|
||||
* @param otherwiseValue must not be {@literal null}.
|
||||
*/
|
||||
public ConditionalOperator(DBObject condition, Object thenValue, Object otherwiseValue) {
|
||||
public ConditionalOperator(Document condition, Object thenValue, Object otherwiseValue) {
|
||||
this((Object) condition, thenValue, otherwiseValue);
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class ConditionalOperator implements AggregationExpression {
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationExpression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
@Override
|
||||
public Document toDbObject(AggregationOperationContext context) {
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
Document condObject = new Document();
|
||||
|
||||
@@ -117,7 +117,7 @@ public class ConditionalOperator implements AggregationExpression {
|
||||
}
|
||||
|
||||
if (value instanceof ConditionalOperator) {
|
||||
return ((ConditionalOperator) value).toDbObject(context);
|
||||
return ((ConditionalOperator) value).toDocument(context);
|
||||
}
|
||||
|
||||
return context.getMappedObject(new Document("$set", value)).get("$set");
|
||||
@@ -244,7 +244,7 @@ public class ConditionalOperator implements AggregationExpression {
|
||||
* @param booleanExpression expression that yields in a boolean result, must not be {@literal null}.
|
||||
* @return the {@link ThenBuilder}
|
||||
*/
|
||||
ThenBuilder when(DBObject booleanExpression);
|
||||
ThenBuilder when(Document booleanExpression);
|
||||
|
||||
/**
|
||||
* @param booleanField reference to a field holding a boolean value, must not be {@literal null}.
|
||||
@@ -320,7 +320,7 @@ public class ConditionalOperator implements AggregationExpression {
|
||||
* @see org.springframework.data.mongodb.core.aggregation.ConditionalOperator.WhenBuilder#when(com.mongodb.DBObject)
|
||||
*/
|
||||
@Override
|
||||
public ConditionalExpressionBuilder when(DBObject booleanExpression) {
|
||||
public ConditionalExpressionBuilder when(Document booleanExpression) {
|
||||
|
||||
Assert.notNull(booleanExpression, "'Boolean expression' must not be null!");
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 1.4
|
||||
*/
|
||||
class ExposedFieldsAggregationOperationContext implements AggregationOperationContext {
|
||||
@@ -56,8 +57,8 @@ class ExposedFieldsAggregationOperationContext implements AggregationOperationCo
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getMappedObject(com.mongodb.Document)
|
||||
*/
|
||||
@Override
|
||||
public Document getMappedObject(Document dbObject) {
|
||||
return rootContext.getMappedObject(dbObject);
|
||||
public Document getMappedObject(Document document) {
|
||||
return rootContext.getMappedObject(document);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,6 +26,7 @@ import org.springframework.util.Assert;
|
||||
* instances of this class directly.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public class GeoNearOperation implements AggregationOperation {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,6 +37,7 @@ import org.springframework.util.StringUtils;
|
||||
* @author Sebastian Herold
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public class GroupOperation implements FieldsExposingAggregationOperation {
|
||||
@@ -424,7 +425,7 @@ public class GroupOperation implements FieldsExposingAggregationOperation {
|
||||
if (reference == null) {
|
||||
|
||||
if (value instanceof AggregationExpression) {
|
||||
return ((AggregationExpression) value).toDbObject(context);
|
||||
return ((AggregationExpression) value).toDocument(context);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -31,6 +31,7 @@ import com.mongodb.DBObject;
|
||||
*
|
||||
* @see http://docs.mongodb.com/manual/reference/operator/aggregation/ifNull/
|
||||
* @author Mark Paluch
|
||||
* @author Christoph Strobl
|
||||
* @since 1.10
|
||||
*/
|
||||
public class IfNullOperator implements AggregationExpression {
|
||||
@@ -58,7 +59,7 @@ public class IfNullOperator implements AggregationExpression {
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationExpression#toDbObject(org.springframework.data.mongodb.core.aggregation.AggregationOperationContext)
|
||||
*/
|
||||
@Override
|
||||
public Document toDbObject(AggregationOperationContext context) {
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
|
||||
List<Object> list = new ArrayList<Object>();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
|
||||
* @see http://docs.mongodb.org/manual/reference/aggregation/limit/
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public class LimitOperation implements AggregationOperation {
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.aggregation;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -29,6 +26,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @see http://docs.mongodb.org/manual/reference/aggregation/out/
|
||||
* @author Nikolay Bogdanov
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class OutOperation implements AggregationOperation {
|
||||
|
||||
|
||||
@@ -1065,7 +1065,7 @@ public class ProjectionOperation implements FieldsExposingAggregationOperation {
|
||||
|
||||
@Override
|
||||
public Document toDocument(AggregationOperationContext context) {
|
||||
return new Document(field.getName(), expression.toDbObject(context));
|
||||
return new Document(field.getName(), expression.toDocument(context));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.springframework.util.Assert;
|
||||
* @see http://docs.mongodb.org/manual/reference/aggregation/skip/
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public class SkipOperation implements AggregationOperation {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,6 +31,7 @@ import org.springframework.util.Assert;
|
||||
* @see http://docs.mongodb.org/manual/reference/aggregation/sort/#pipe._S_sort
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public class SortOperation implements AggregationOperation {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -248,23 +248,23 @@ class SpelExpressionTransformer implements AggregationExpressionTransformer {
|
||||
private Document createOperationObjectAndAddToPreviousArgumentsIfNecessary(
|
||||
AggregationExpressionTransformationContext<OperatorNode> context, OperatorNode currentNode) {
|
||||
|
||||
Document nextDbObject = new Document(currentNode.getMongoOperator(), new ArrayList<Object>());
|
||||
Document nextDocument = new Document(currentNode.getMongoOperator(), new ArrayList<Object>());
|
||||
|
||||
if (!context.hasPreviousOperation()) {
|
||||
return nextDbObject;
|
||||
return nextDocument;
|
||||
}
|
||||
|
||||
if (context.parentIsSameOperation()) {
|
||||
|
||||
// same operator applied in a row e.g. 1 + 2 + 3 carry on with the operation and render as $add: [1, 2 ,3]
|
||||
nextDbObject = context.getPreviousOperationObject();
|
||||
nextDocument = context.getPreviousOperationObject();
|
||||
} else if (!currentNode.isUnaryOperator()) {
|
||||
|
||||
// different operator -> add context object for next level to list if arguments of previous expression
|
||||
context.addToPreviousOperation(nextDbObject);
|
||||
context.addToPreviousOperation(nextDocument);
|
||||
}
|
||||
|
||||
return nextDbObject;
|
||||
return nextDocument;
|
||||
}
|
||||
|
||||
private Object convertUnaryMinusOp(ExpressionTransformationContextSupport<OperatorNode> context,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,6 +33,7 @@ import org.springframework.util.Assert;
|
||||
* property references into document field names.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.3
|
||||
*/
|
||||
public class TypeBasedAggregationOperationContext implements AggregationOperationContext {
|
||||
@@ -66,8 +67,8 @@ public class TypeBasedAggregationOperationContext implements AggregationOperatio
|
||||
* @see org.springframework.data.mongodb.core.aggregation.AggregationOperationContext#getMappedObject(com.mongodb.Document)
|
||||
*/
|
||||
@Override
|
||||
public Document getMappedObject(Document dbObject) {
|
||||
return mapper.getMappedObject(dbObject, mappingContext.getPersistentEntity(type));
|
||||
public Document getMappedObject(Document document) {
|
||||
return mapper.getMappedObject(document, mappingContext.getPersistentEntity(type));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,11 +29,12 @@ import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.DBObject;
|
||||
|
||||
/**
|
||||
* Wrapper value object for a {@link BasicDocument} to be able to access raw values by {@link MongoPersistentProperty}
|
||||
* Wrapper value object for a {@link Document} to be able to access raw values by {@link MongoPersistentProperty}
|
||||
* references. The accessors will transparently resolve nested document values that a {@link MongoPersistentProperty}
|
||||
* might refer to through a path expression in field names.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DocumentAccessor {
|
||||
|
||||
@@ -42,7 +43,7 @@ class DocumentAccessor {
|
||||
/**
|
||||
* Creates a new {@link DocumentAccessor} for the given {@link Document}.
|
||||
*
|
||||
* @param dbObject must be a {@link BasicDocument} effectively, must not be {@literal null}.
|
||||
* @param dbObject must be a {@link Document} effectively, must not be {@literal null}.
|
||||
*/
|
||||
public DocumentAccessor(Bson dbObject) {
|
||||
|
||||
@@ -169,7 +170,7 @@ class DocumentAccessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the given source object as map, i.e. {@link BasicDocument}s and maps as is or {@literal null} otherwise.
|
||||
* Returns the given source object as map, i.e. {@link Document}s and maps as is or {@literal null} otherwise.
|
||||
*
|
||||
* @param source can be {@literal null}.
|
||||
* @return
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2014 the original author or authors.
|
||||
* Copyright 2012-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.expression.TypedValue;
|
||||
* {@link PropertyAccessor} to allow entity based field access to {@link Document}s.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DocumentPropertyAccessor extends MapAccessor {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,7 @@ import com.mongodb.DBRef;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DefaultDbRefProxyHandler implements DbRefProxyHandler {
|
||||
|
||||
@@ -37,8 +38,8 @@ class DefaultDbRefProxyHandler implements DbRefProxyHandler {
|
||||
|
||||
/**
|
||||
* @param spELContext must not be {@literal null}.
|
||||
* @param conversionService must not be {@literal null}.
|
||||
* @param mappingContext must not be {@literal null}.
|
||||
* @param resolver must not be {@literal null}.
|
||||
*/
|
||||
public DefaultDbRefProxyHandler(SpELContext spELContext,
|
||||
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext,
|
||||
|
||||
@@ -27,11 +27,6 @@ import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import com.mongodb.BasicDBObject;
|
||||
import com.mongodb.BasicDBObjectBuilder;
|
||||
import com.mongodb.DB;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.bson.Document;
|
||||
@@ -51,7 +46,9 @@ import org.springframework.objenesis.ObjenesisStd;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.DBRef;
|
||||
import com.mongodb.client.MongoDatabase;
|
||||
|
||||
/**
|
||||
* A {@link DbRefResolver} that resolves {@link org.springframework.data.mongodb.core.mapping.DBRef}s by delegating to a
|
||||
@@ -148,8 +145,7 @@ public class DefaultDbRefResolver implements DbRefResolver {
|
||||
|
||||
MongoDatabase db = mongoDbFactory.getDb();
|
||||
List<Document> result = new ArrayList<>();
|
||||
db.getCollection(collection)
|
||||
.find(new Document("_id", new Document("$in", ids))).into(result);
|
||||
db.getCollection(collection).find(new Document("_id", new Document("$in", ids))).into(result);
|
||||
Collections.sort(result, new DbRefByReferencePositionComparator(ids));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
* Default implementation of {@link DbRefResolverCallback}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
class DefaultDbRefResolverCallback implements DbRefResolverCallback {
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.mongodb.DBObject;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class DefaultMongoTypeMapper extends DefaultTypeMapper<Bson> implements MongoTypeMapper {
|
||||
|
||||
|
||||
@@ -69,27 +69,27 @@ abstract class GeoConverters {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Collection<? extends Object> getConvertersToRegister() {
|
||||
return Arrays.asList( //
|
||||
BoxToDbObjectConverter.INSTANCE //
|
||||
, PolygonToDbObjectConverter.INSTANCE //
|
||||
, CircleToDbObjectConverter.INSTANCE //
|
||||
, SphereToDbObjectConverter.INSTANCE //
|
||||
, DbObjectToBoxConverter.INSTANCE //
|
||||
, DbObjectToPolygonConverter.INSTANCE //
|
||||
, DbObjectToCircleConverter.INSTANCE //
|
||||
, DbObjectToSphereConverter.INSTANCE //
|
||||
, DbObjectToPointConverter.INSTANCE //
|
||||
, PointToDbObjectConverter.INSTANCE //
|
||||
, GeoCommandToDbObjectConverter.INSTANCE //
|
||||
, GeoJsonToDbObjectConverter.INSTANCE //
|
||||
, GeoJsonPointToDbObjectConverter.INSTANCE //
|
||||
, GeoJsonPolygonToDbObjectConverter.INSTANCE //
|
||||
, DbObjectToGeoJsonPointConverter.INSTANCE //
|
||||
, DbObjectToGeoJsonPolygonConverter.INSTANCE //
|
||||
, DbObjectToGeoJsonLineStringConverter.INSTANCE //
|
||||
, DbObjectToGeoJsonMultiLineStringConverter.INSTANCE //
|
||||
, DbObjectToGeoJsonMultiPointConverter.INSTANCE //
|
||||
, DbObjectToGeoJsonMultiPolygonConverter.INSTANCE //
|
||||
, DbObjectToGeoJsonGeometryCollectionConverter.INSTANCE);
|
||||
BoxToDocumentConverter.INSTANCE //
|
||||
, PolygonToDocumentConverter.INSTANCE //
|
||||
, CircleToDocumentConverter.INSTANCE //
|
||||
, SphereToDocumentConverter.INSTANCE //
|
||||
, DocumentToBoxConverter.INSTANCE //
|
||||
, DocumentToPolygonConverter.INSTANCE //
|
||||
, DocumentToCircleConverter.INSTANCE //
|
||||
, DocumentToSphereConverter.INSTANCE //
|
||||
, DocumentToPointConverter.INSTANCE //
|
||||
, PointToDocumentConverter.INSTANCE //
|
||||
, GeoCommandToDocumentConverter.INSTANCE //
|
||||
, GeoJsonToDocumentConverter.INSTANCE //
|
||||
, GeoJsonPointToDocumentConverter.INSTANCE //
|
||||
, GeoJsonPolygonToDocumentConverter.INSTANCE //
|
||||
, DocumentToGeoJsonPointConverter.INSTANCE //
|
||||
, DocumentToGeoJsonPolygonConverter.INSTANCE //
|
||||
, DocumentToGeoJsonLineStringConverter.INSTANCE //
|
||||
, DocumentToGeoJsonMultiLineStringConverter.INSTANCE //
|
||||
, DocumentToGeoJsonMultiPointConverter.INSTANCE //
|
||||
, DocumentToGeoJsonMultiPolygonConverter.INSTANCE //
|
||||
, DocumentToGeoJsonGeometryCollectionConverter.INSTANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,7 +99,7 @@ abstract class GeoConverters {
|
||||
* @since 1.5
|
||||
*/
|
||||
@ReadingConverter
|
||||
static enum DbObjectToPointConverter implements Converter<Document, Point> {
|
||||
static enum DocumentToPointConverter implements Converter<Document, Point> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -117,7 +117,7 @@ abstract class GeoConverters {
|
||||
Assert.isTrue(source.keySet().size() == 2, "Source must contain 2 elements");
|
||||
|
||||
if (source.containsKey("type")) {
|
||||
return DbObjectToGeoJsonPointConverter.INSTANCE.convert(source);
|
||||
return DocumentToGeoJsonPointConverter.INSTANCE.convert(source);
|
||||
}
|
||||
|
||||
return new Point((Double) source.get("x"), (Double) source.get("y"));
|
||||
@@ -130,7 +130,7 @@ abstract class GeoConverters {
|
||||
* @author Thomas Darimont
|
||||
* @since 1.5
|
||||
*/
|
||||
static enum PointToDbObjectConverter implements Converter<Point, Document> {
|
||||
static enum PointToDocumentConverter implements Converter<Point, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -151,7 +151,7 @@ abstract class GeoConverters {
|
||||
* @since 1.5
|
||||
*/
|
||||
@WritingConverter
|
||||
static enum BoxToDbObjectConverter implements Converter<Box, Document> {
|
||||
static enum BoxToDocumentConverter implements Converter<Box, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -167,8 +167,8 @@ abstract class GeoConverters {
|
||||
}
|
||||
|
||||
Document result = new Document();
|
||||
result.put("first", PointToDbObjectConverter.INSTANCE.convert(source.getFirst()));
|
||||
result.put("second", PointToDbObjectConverter.INSTANCE.convert(source.getSecond()));
|
||||
result.put("first", PointToDocumentConverter.INSTANCE.convert(source.getFirst()));
|
||||
result.put("second", PointToDocumentConverter.INSTANCE.convert(source.getSecond()));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,7 @@ abstract class GeoConverters {
|
||||
* @since 1.5
|
||||
*/
|
||||
@ReadingConverter
|
||||
static enum DbObjectToBoxConverter implements Converter<Document, Box> {
|
||||
static enum DocumentToBoxConverter implements Converter<Document, Box> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -195,8 +195,8 @@ abstract class GeoConverters {
|
||||
return null;
|
||||
}
|
||||
|
||||
Point first = DbObjectToPointConverter.INSTANCE.convert((Document) source.get("first"));
|
||||
Point second = DbObjectToPointConverter.INSTANCE.convert((Document) source.get("second"));
|
||||
Point first = DocumentToPointConverter.INSTANCE.convert((Document) source.get("first"));
|
||||
Point second = DocumentToPointConverter.INSTANCE.convert((Document) source.get("second"));
|
||||
|
||||
return new Box(first, second);
|
||||
}
|
||||
@@ -208,7 +208,7 @@ abstract class GeoConverters {
|
||||
* @author Thomas Darimont
|
||||
* @since 1.5
|
||||
*/
|
||||
static enum CircleToDbObjectConverter implements Converter<Circle, Document> {
|
||||
static enum CircleToDocumentConverter implements Converter<Circle, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -224,7 +224,7 @@ abstract class GeoConverters {
|
||||
}
|
||||
|
||||
Document result = new Document();
|
||||
result.put("center", PointToDbObjectConverter.INSTANCE.convert(source.getCenter()));
|
||||
result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter()));
|
||||
result.put("radius", source.getRadius().getNormalizedValue());
|
||||
result.put("metric", source.getRadius().getMetric().toString());
|
||||
return result;
|
||||
@@ -238,7 +238,7 @@ abstract class GeoConverters {
|
||||
* @since 1.5
|
||||
*/
|
||||
@ReadingConverter
|
||||
static enum DbObjectToCircleConverter implements Converter<Document, Circle> {
|
||||
static enum DocumentToCircleConverter implements Converter<Document, Circle> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -269,7 +269,7 @@ abstract class GeoConverters {
|
||||
Assert.notNull(center, "Center must not be null!");
|
||||
Assert.notNull(radius, "Radius must not be null!");
|
||||
|
||||
return new Circle(DbObjectToPointConverter.INSTANCE.convert(center), distance);
|
||||
return new Circle(DocumentToPointConverter.INSTANCE.convert(center), distance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,7 +279,7 @@ abstract class GeoConverters {
|
||||
* @author Thomas Darimont
|
||||
* @since 1.5
|
||||
*/
|
||||
static enum SphereToDbObjectConverter implements Converter<Sphere, Document> {
|
||||
static enum SphereToDocumentConverter implements Converter<Sphere, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -295,7 +295,7 @@ abstract class GeoConverters {
|
||||
}
|
||||
|
||||
Document result = new Document();
|
||||
result.put("center", PointToDbObjectConverter.INSTANCE.convert(source.getCenter()));
|
||||
result.put("center", PointToDocumentConverter.INSTANCE.convert(source.getCenter()));
|
||||
result.put("radius", source.getRadius().getNormalizedValue());
|
||||
result.put("metric", source.getRadius().getMetric().toString());
|
||||
return result;
|
||||
@@ -309,7 +309,7 @@ abstract class GeoConverters {
|
||||
* @since 1.5
|
||||
*/
|
||||
@ReadingConverter
|
||||
static enum DbObjectToSphereConverter implements Converter<Document, Sphere> {
|
||||
static enum DocumentToSphereConverter implements Converter<Document, Sphere> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -340,7 +340,7 @@ abstract class GeoConverters {
|
||||
Assert.notNull(center, "Center must not be null!");
|
||||
Assert.notNull(radius, "Radius must not be null!");
|
||||
|
||||
return new Sphere(DbObjectToPointConverter.INSTANCE.convert(center), distance);
|
||||
return new Sphere(DocumentToPointConverter.INSTANCE.convert(center), distance);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,7 +350,7 @@ abstract class GeoConverters {
|
||||
* @author Thomas Darimont
|
||||
* @since 1.5
|
||||
*/
|
||||
static enum PolygonToDbObjectConverter implements Converter<Polygon, Document> {
|
||||
static enum PolygonToDocumentConverter implements Converter<Polygon, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -369,7 +369,7 @@ abstract class GeoConverters {
|
||||
List<Document> pointTuples = new ArrayList<Document>(points.size());
|
||||
|
||||
for (Point point : points) {
|
||||
pointTuples.add(PointToDbObjectConverter.INSTANCE.convert(point));
|
||||
pointTuples.add(PointToDocumentConverter.INSTANCE.convert(point));
|
||||
}
|
||||
|
||||
Document result = new Document();
|
||||
@@ -385,7 +385,7 @@ abstract class GeoConverters {
|
||||
* @since 1.5
|
||||
*/
|
||||
@ReadingConverter
|
||||
static enum DbObjectToPolygonConverter implements Converter<Document, Polygon> {
|
||||
static enum DocumentToPolygonConverter implements Converter<Document, Polygon> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -407,7 +407,7 @@ abstract class GeoConverters {
|
||||
for (Document element : points) {
|
||||
|
||||
Assert.notNull(element, "Point elements of polygon must not be null!");
|
||||
newPoints.add(DbObjectToPointConverter.INSTANCE.convert(element));
|
||||
newPoints.add(DocumentToPointConverter.INSTANCE.convert(element));
|
||||
}
|
||||
|
||||
return new Polygon(newPoints);
|
||||
@@ -420,7 +420,7 @@ abstract class GeoConverters {
|
||||
* @author Thomas Darimont
|
||||
* @since 1.5
|
||||
*/
|
||||
static enum GeoCommandToDbObjectConverter implements Converter<GeoCommand, Document> {
|
||||
static enum GeoCommandToDocumentConverter implements Converter<GeoCommand, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -441,7 +441,7 @@ abstract class GeoConverters {
|
||||
Shape shape = source.getShape();
|
||||
|
||||
if (shape instanceof GeoJson) {
|
||||
return GeoJsonToDbObjectConverter.INSTANCE.convert((GeoJson) shape);
|
||||
return GeoJsonToDocumentConverter.INSTANCE.convert((GeoJson) shape);
|
||||
}
|
||||
|
||||
if (shape instanceof Box) {
|
||||
@@ -480,7 +480,7 @@ abstract class GeoConverters {
|
||||
* @since 1.7
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
static enum GeoJsonToDbObjectConverter implements Converter<GeoJson, Document> {
|
||||
static enum GeoJsonToDocumentConverter implements Converter<GeoJson, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -543,7 +543,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum GeoJsonPointToDbObjectConverter implements Converter<GeoJsonPoint, Document> {
|
||||
static enum GeoJsonPointToDocumentConverter implements Converter<GeoJsonPoint, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -553,7 +553,7 @@ abstract class GeoConverters {
|
||||
*/
|
||||
@Override
|
||||
public Document convert(GeoJsonPoint source) {
|
||||
return GeoJsonToDbObjectConverter.INSTANCE.convert(source);
|
||||
return GeoJsonToDocumentConverter.INSTANCE.convert(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -561,7 +561,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum GeoJsonPolygonToDbObjectConverter implements Converter<GeoJsonPolygon, Document> {
|
||||
static enum GeoJsonPolygonToDocumentConverter implements Converter<GeoJsonPolygon, Document> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -571,7 +571,7 @@ abstract class GeoConverters {
|
||||
*/
|
||||
@Override
|
||||
public Document convert(GeoJsonPolygon source) {
|
||||
return GeoJsonToDbObjectConverter.INSTANCE.convert(source);
|
||||
return GeoJsonToDocumentConverter.INSTANCE.convert(source);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -579,7 +579,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum DbObjectToGeoJsonPointConverter implements Converter<Document, GeoJsonPoint> {
|
||||
static enum DocumentToGeoJsonPointConverter implements Converter<Document, GeoJsonPoint> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -607,7 +607,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum DbObjectToGeoJsonPolygonConverter implements Converter<Document, GeoJsonPolygon> {
|
||||
static enum DocumentToGeoJsonPolygonConverter implements Converter<Document, GeoJsonPolygon> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -633,7 +633,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum DbObjectToGeoJsonMultiPolygonConverter implements Converter<Document, GeoJsonMultiPolygon> {
|
||||
static enum DocumentToGeoJsonMultiPolygonConverter implements Converter<Document, GeoJsonMultiPolygon> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -666,7 +666,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum DbObjectToGeoJsonLineStringConverter implements Converter<Document, GeoJsonLineString> {
|
||||
static enum DocumentToGeoJsonLineStringConverter implements Converter<Document, GeoJsonLineString> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -694,7 +694,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum DbObjectToGeoJsonMultiPointConverter implements Converter<Document, GeoJsonMultiPoint> {
|
||||
static enum DocumentToGeoJsonMultiPointConverter implements Converter<Document, GeoJsonMultiPoint> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -722,7 +722,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum DbObjectToGeoJsonMultiLineStringConverter implements Converter<Document, GeoJsonMultiLineString> {
|
||||
static enum DocumentToGeoJsonMultiLineStringConverter implements Converter<Document, GeoJsonMultiLineString> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -754,7 +754,7 @@ abstract class GeoConverters {
|
||||
* @author Christoph Strobl
|
||||
* @since 1.7
|
||||
*/
|
||||
static enum DbObjectToGeoJsonGeometryCollectionConverter implements Converter<Document, GeoJsonGeometryCollection> {
|
||||
static enum DocumentToGeoJsonGeometryCollectionConverter implements Converter<Document, GeoJsonGeometryCollection> {
|
||||
|
||||
INSTANCE;
|
||||
|
||||
@@ -785,26 +785,26 @@ abstract class GeoConverters {
|
||||
|
||||
Object type = source.get("type");
|
||||
if (ObjectUtils.nullSafeEquals(type, "Point")) {
|
||||
return DbObjectToGeoJsonPointConverter.INSTANCE.convert(source);
|
||||
return DocumentToGeoJsonPointConverter.INSTANCE.convert(source);
|
||||
}
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(type, "MultiPoint")) {
|
||||
return DbObjectToGeoJsonMultiPointConverter.INSTANCE.convert(source);
|
||||
return DocumentToGeoJsonMultiPointConverter.INSTANCE.convert(source);
|
||||
}
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(type, "LineString")) {
|
||||
return DbObjectToGeoJsonLineStringConverter.INSTANCE.convert(source);
|
||||
return DocumentToGeoJsonLineStringConverter.INSTANCE.convert(source);
|
||||
}
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(type, "MultiLineString")) {
|
||||
return DbObjectToGeoJsonMultiLineStringConverter.INSTANCE.convert(source);
|
||||
return DocumentToGeoJsonMultiLineStringConverter.INSTANCE.convert(source);
|
||||
}
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(type, "Polygon")) {
|
||||
return DbObjectToGeoJsonPolygonConverter.INSTANCE.convert(source);
|
||||
return DocumentToGeoJsonPolygonConverter.INSTANCE.convert(source);
|
||||
}
|
||||
if (ObjectUtils.nullSafeEquals(type, "MultiPolygon")) {
|
||||
return DbObjectToGeoJsonMultiPolygonConverter.INSTANCE.convert(source);
|
||||
return DocumentToGeoJsonMultiPolygonConverter.INSTANCE.convert(source);
|
||||
}
|
||||
|
||||
throw new IllegalArgumentException(String.format("Cannot convert unknown GeoJson type %s", type));
|
||||
|
||||
@@ -104,7 +104,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
/**
|
||||
* Creates a new {@link MappingMongoConverter} given the new {@link DbRefResolver} and {@link MappingContext}.
|
||||
*
|
||||
* @param mongoDbFactory must not be {@literal null}.
|
||||
* @param dbRefResolver must not be {@literal null}.
|
||||
* @param mappingContext must not be {@literal null}.
|
||||
*/
|
||||
public MappingMongoConverter(DbRefResolver dbRefResolver,
|
||||
@@ -192,50 +192,50 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.core.MongoReader#read(java.lang.Class, com.mongodb.Document)
|
||||
*/
|
||||
public <S extends Object> S read(Class<S> clazz, final Bson dbo) {
|
||||
return read(ClassTypeInformation.from(clazz), dbo);
|
||||
public <S extends Object> S read(Class<S> clazz, final Bson bson) {
|
||||
return read(ClassTypeInformation.from(clazz), bson);
|
||||
}
|
||||
|
||||
protected <S extends Object> S read(TypeInformation<S> type, Bson dbo) {
|
||||
return read(type, dbo, ObjectPath.ROOT);
|
||||
protected <S extends Object> S read(TypeInformation<S> type, Bson bson) {
|
||||
return read(type, bson, ObjectPath.ROOT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private <S extends Object> S read(TypeInformation<S> type, Bson dbo, ObjectPath path) {
|
||||
private <S extends Object> S read(TypeInformation<S> type, Bson bson, ObjectPath path) {
|
||||
|
||||
if (null == dbo) {
|
||||
if (null == bson) {
|
||||
return null;
|
||||
}
|
||||
|
||||
TypeInformation<? extends S> typeToUse = typeMapper.readType(dbo, type);
|
||||
TypeInformation<? extends S> typeToUse = typeMapper.readType(bson, type);
|
||||
Class<? extends S> rawType = typeToUse.getType();
|
||||
|
||||
if (conversions.hasCustomReadTarget(dbo.getClass(), rawType)) {
|
||||
return conversionService.convert(dbo, rawType);
|
||||
if (conversions.hasCustomReadTarget(bson.getClass(), rawType)) {
|
||||
return conversionService.convert(bson, rawType);
|
||||
}
|
||||
|
||||
if (DBObject.class.isAssignableFrom(rawType)) {
|
||||
return (S) dbo;
|
||||
return (S) bson;
|
||||
}
|
||||
|
||||
if (Document.class.isAssignableFrom(rawType)) {
|
||||
return (S) dbo;
|
||||
return (S) bson;
|
||||
}
|
||||
|
||||
if (typeToUse.isCollectionLike() && dbo instanceof List) {
|
||||
return (S) readCollectionOrArray(typeToUse, (List) dbo, path);
|
||||
if (typeToUse.isCollectionLike() && bson instanceof List) {
|
||||
return (S) readCollectionOrArray(typeToUse, (List) bson, path);
|
||||
}
|
||||
|
||||
if (typeToUse.isMap()) {
|
||||
return (S) readMap(typeToUse, dbo, path);
|
||||
return (S) readMap(typeToUse, bson, path);
|
||||
}
|
||||
|
||||
if (dbo instanceof Collection) {
|
||||
throw new MappingException(String.format(INCOMPATIBLE_TYPES, dbo, BasicDBList.class, typeToUse.getType(), path));
|
||||
if (bson instanceof Collection) {
|
||||
throw new MappingException(String.format(INCOMPATIBLE_TYPES, bson, BasicDBList.class, typeToUse.getType(), path));
|
||||
}
|
||||
|
||||
if (typeToUse.equals(ClassTypeInformation.OBJECT)) {
|
||||
return (S) dbo;
|
||||
return (S) bson;
|
||||
}
|
||||
// Retrieve persistent entity info
|
||||
MongoPersistentEntity<S> persistentEntity = (MongoPersistentEntity<S>) mappingContext
|
||||
@@ -244,7 +244,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
throw new MappingException("No mapping metadata found for " + rawType.getName());
|
||||
}
|
||||
|
||||
return read(persistentEntity, dbo, path);
|
||||
return read(persistentEntity, bson, path);
|
||||
}
|
||||
|
||||
private ParameterValueProvider<MongoPersistentProperty> getParameterProvider(MongoPersistentEntity<?> entity,
|
||||
@@ -258,11 +258,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
path);
|
||||
}
|
||||
|
||||
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final Bson dbo, final ObjectPath path) {
|
||||
private <S extends Object> S read(final MongoPersistentEntity<S> entity, final Bson bson, final ObjectPath path) {
|
||||
|
||||
final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(dbo, spELContext);
|
||||
final DefaultSpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(bson, spELContext);
|
||||
|
||||
ParameterValueProvider<MongoPersistentProperty> provider = getParameterProvider(entity, dbo, evaluator, path);
|
||||
ParameterValueProvider<MongoPersistentProperty> provider = getParameterProvider(entity, bson, evaluator, path);
|
||||
EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity);
|
||||
S instance = instantiator.createInstance(entity, provider);
|
||||
|
||||
@@ -274,10 +274,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
// make sure id property is set before all other properties
|
||||
Object idValue = null;
|
||||
DocumentAccessor documentAccessor = new DocumentAccessor(dbo);
|
||||
DocumentAccessor documentAccessor = new DocumentAccessor(bson);
|
||||
|
||||
if (idProperty != null && documentAccessor.hasValue(idProperty)) {
|
||||
idValue = getValueInternal(idProperty, dbo, evaluator, path);
|
||||
idValue = getValueInternal(idProperty, bson, evaluator, path);
|
||||
accessor.setProperty(idProperty, idValue);
|
||||
}
|
||||
|
||||
@@ -296,7 +296,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return;
|
||||
}
|
||||
|
||||
accessor.setProperty(prop, getValueInternal(prop, dbo, evaluator, currentPath));
|
||||
accessor.setProperty(prop, getValueInternal(prop, bson, evaluator, currentPath));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -315,7 +315,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
DbRefProxyHandler handler = new DefaultDbRefProxyHandler(spELContext, mappingContext,
|
||||
MappingMongoConverter.this);
|
||||
DbRefResolverCallback callback = new DefaultDbRefResolverCallback(dbo, currentPath, evaluator,
|
||||
DbRefResolverCallback callback = new DefaultDbRefResolverCallback(bson, currentPath, evaluator,
|
||||
MappingMongoConverter.this);
|
||||
|
||||
accessor.setProperty(property, dbRefResolver.resolveDbRef(property, dbref, callback, handler));
|
||||
@@ -352,7 +352,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
*
|
||||
* @see org.springframework.data.mongodb.core.core.convert.MongoWriter#write(java.lang.Object, com.mongodb.Document)
|
||||
*/
|
||||
public void write(final Object obj, final Bson dbo) {
|
||||
public void write(final Object obj, final Bson bson) {
|
||||
|
||||
if (null == obj) {
|
||||
return;
|
||||
@@ -362,15 +362,15 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
boolean handledByCustomConverter = conversions.getCustomWriteTarget(entityType, Document.class) != null;
|
||||
TypeInformation<? extends Object> type = ClassTypeInformation.from(entityType);
|
||||
|
||||
if (!handledByCustomConverter && !(dbo instanceof Collection)) {
|
||||
typeMapper.writeType(type, dbo);
|
||||
if (!handledByCustomConverter && !(bson instanceof Collection)) {
|
||||
typeMapper.writeType(type, bson);
|
||||
}
|
||||
|
||||
Object target = obj instanceof LazyLoadingProxy ? ((LazyLoadingProxy) obj).getTarget() : obj;
|
||||
|
||||
writeInternal(target, dbo, type);
|
||||
if (asMap(dbo).containsKey("_is") && asMap(dbo).get("_id") == null) {
|
||||
removeFromMap(dbo, "_id");
|
||||
writeInternal(target, bson, type);
|
||||
if (asMap(bson).containsKey("_is") && asMap(bson).get("_id") == null) {
|
||||
removeFromMap(bson, "_id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -378,10 +378,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* Internal write conversion method which should be used for nested invocations.
|
||||
*
|
||||
* @param obj
|
||||
* @param dbo
|
||||
* @param bson
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected void writeInternal(final Object obj, final Bson dbo, final TypeInformation<?> typeHint) {
|
||||
protected void writeInternal(final Object obj, final Bson bson, final TypeInformation<?> typeHint) {
|
||||
|
||||
if (null == obj) {
|
||||
return;
|
||||
@@ -392,26 +392,26 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
if (customTarget != null) {
|
||||
Document result = conversionService.convert(obj, Document.class);
|
||||
addAllToMap(dbo, result);
|
||||
addAllToMap(bson, result);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Map.class.isAssignableFrom(entityType)) {
|
||||
writeMapInternal((Map<Object, Object>) obj, dbo, ClassTypeInformation.MAP);
|
||||
writeMapInternal((Map<Object, Object>) obj, bson, ClassTypeInformation.MAP);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Collection.class.isAssignableFrom(entityType)) {
|
||||
writeCollectionInternal((Collection<?>) obj, ClassTypeInformation.LIST, (List) dbo);
|
||||
writeCollectionInternal((Collection<?>) obj, ClassTypeInformation.LIST, (List) bson);
|
||||
return;
|
||||
}
|
||||
|
||||
MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityType);
|
||||
writeInternal(obj, dbo, entity);
|
||||
addCustomTypeKeyIfNecessary(typeHint, obj, dbo);
|
||||
writeInternal(obj, bson, entity);
|
||||
addCustomTypeKeyIfNecessary(typeHint, obj, bson);
|
||||
}
|
||||
|
||||
protected void writeInternal(Object obj, final Bson dbo, MongoPersistentEntity<?> entity) {
|
||||
protected void writeInternal(Object obj, final Bson bson, MongoPersistentEntity<?> entity) {
|
||||
|
||||
if (obj == null) {
|
||||
return;
|
||||
@@ -424,11 +424,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
final PersistentPropertyAccessor accessor = entity.getPropertyAccessor(obj);
|
||||
final MongoPersistentProperty idProperty = entity.getIdProperty();
|
||||
|
||||
if (!asMap(dbo).containsKey("_id") && null != idProperty) {
|
||||
if (!asMap(bson).containsKey("_id") && null != idProperty) {
|
||||
|
||||
try {
|
||||
Object id = accessor.getProperty(idProperty);
|
||||
addToMap(dbo, "_id", idMapper.convertId(id));
|
||||
addToMap(bson, "_id", idMapper.convertId(id));
|
||||
} catch (ConversionException ignored) {}
|
||||
}
|
||||
|
||||
@@ -445,9 +445,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
if (null != propertyObj) {
|
||||
|
||||
if (!conversions.isSimpleType(propertyObj.getClass())) {
|
||||
writePropertyInternal(propertyObj, dbo, prop);
|
||||
writePropertyInternal(propertyObj, bson, prop);
|
||||
} else {
|
||||
writeSimpleInternal(propertyObj, dbo, prop);
|
||||
writeSimpleInternal(propertyObj, bson, prop);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -461,20 +461,20 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
Object propertyObj = accessor.getProperty(inverseProp);
|
||||
|
||||
if (null != propertyObj) {
|
||||
writePropertyInternal(propertyObj, dbo, inverseProp);
|
||||
writePropertyInternal(propertyObj, bson, inverseProp);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked" })
|
||||
protected void writePropertyInternal(Object obj, Bson dbo, MongoPersistentProperty prop) {
|
||||
protected void writePropertyInternal(Object obj, Bson bson, MongoPersistentProperty prop) {
|
||||
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
DocumentAccessor accessor = new DocumentAccessor(dbo);
|
||||
DocumentAccessor accessor = new DocumentAccessor(bson);
|
||||
|
||||
TypeInformation<?> valueType = ClassTypeInformation.from(obj.getClass());
|
||||
TypeInformation<?> type = prop.getTypeInformation();
|
||||
@@ -527,14 +527,14 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
Object existingValue = accessor.get(prop);
|
||||
Document propDbObj = existingValue instanceof Document ? (Document) existingValue : new Document();
|
||||
addCustomTypeKeyIfNecessary(ClassTypeInformation.from(prop.getRawType()), obj, propDbObj);
|
||||
Document document = existingValue instanceof Document ? (Document) existingValue : new Document();
|
||||
addCustomTypeKeyIfNecessary(ClassTypeInformation.from(prop.getRawType()), obj, document);
|
||||
|
||||
MongoPersistentEntity<?> entity = isSubtype(prop.getType(), obj.getClass())
|
||||
? mappingContext.getPersistentEntity(obj.getClass()) : mappingContext.getPersistentEntity(type);
|
||||
|
||||
writeInternal(obj, propDbObj, entity);
|
||||
accessor.put(prop, propDbObj);
|
||||
writeInternal(obj, document, entity);
|
||||
accessor.put(prop, document);
|
||||
}
|
||||
|
||||
private boolean isSubtype(Class<?> left, Class<?> right) {
|
||||
@@ -602,7 +602,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return writeMapInternal(map, new Document(), property.getTypeInformation());
|
||||
}
|
||||
|
||||
Document dbObject = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
for (Map.Entry<Object, Object> entry : map.entrySet()) {
|
||||
|
||||
@@ -612,14 +612,14 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
if (conversions.isSimpleType(key.getClass())) {
|
||||
|
||||
String simpleKey = prepareMapKey(key.toString());
|
||||
dbObject.put(simpleKey, value != null ? createDBRef(value, property) : null);
|
||||
document.put(simpleKey, value != null ? createDBRef(value, property) : null);
|
||||
|
||||
} else {
|
||||
throw new MappingException("Cannot use a complex object as a key value.");
|
||||
}
|
||||
}
|
||||
|
||||
return dbObject;
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -643,9 +643,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
} else if (element instanceof Collection || elementType.isArray()) {
|
||||
sink.add(writeCollectionInternal(asCollection(element), componentType, new BasicDBList()));
|
||||
} else {
|
||||
Document propDbObj = new Document();
|
||||
writeInternal(element, propDbObj, componentType);
|
||||
sink.add(propDbObj);
|
||||
Document document = new Document();
|
||||
writeInternal(element, document, componentType);
|
||||
sink.add(document);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,11 +656,11 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* Writes the given {@link Map} to the given {@link Document} considering the given {@link TypeInformation}.
|
||||
*
|
||||
* @param obj must not be {@literal null}.
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param bson must not be {@literal null}.
|
||||
* @param propertyType must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
protected Bson writeMapInternal(Map<Object, Object> obj, Bson dbo, TypeInformation<?> propertyType) {
|
||||
protected Bson writeMapInternal(Map<Object, Object> obj, Bson bson, TypeInformation<?> propertyType) {
|
||||
|
||||
for (Map.Entry<Object, Object> entry : obj.entrySet()) {
|
||||
|
||||
@@ -671,23 +671,23 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
String simpleKey = prepareMapKey(key);
|
||||
if (val == null || conversions.isSimpleType(val.getClass())) {
|
||||
writeSimpleInternal(val, dbo, simpleKey);
|
||||
writeSimpleInternal(val, bson, simpleKey);
|
||||
} else if (val instanceof Collection || val.getClass().isArray()) {
|
||||
addToMap(dbo, simpleKey,
|
||||
addToMap(bson, simpleKey,
|
||||
writeCollectionInternal(asCollection(val), propertyType.getMapValueType(), new BasicDBList()));
|
||||
} else {
|
||||
Document newDbo = new Document();
|
||||
Document document = new Document();
|
||||
TypeInformation<?> valueTypeInfo = propertyType.isMap() ? propertyType.getMapValueType()
|
||||
: ClassTypeInformation.OBJECT;
|
||||
writeInternal(val, newDbo, valueTypeInfo);
|
||||
addToMap(dbo, simpleKey, newDbo);
|
||||
writeInternal(val, document, valueTypeInfo);
|
||||
addToMap(bson, simpleKey, document);
|
||||
}
|
||||
} else {
|
||||
throw new MappingException("Cannot use a complex object as a key value.");
|
||||
}
|
||||
}
|
||||
|
||||
return dbo;
|
||||
return bson;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -762,9 +762,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
*
|
||||
* @param type
|
||||
* @param value must not be {@literal null}.
|
||||
* @param dbObject must not be {@literal null}.
|
||||
* @param bson must not be {@literal null}.
|
||||
*/
|
||||
protected void addCustomTypeKeyIfNecessary(TypeInformation<?> type, Object value, Bson dbObject) {
|
||||
protected void addCustomTypeKeyIfNecessary(TypeInformation<?> type, Object value, Bson bson) {
|
||||
|
||||
TypeInformation<?> actualType = type != null ? type.getActualType() : null;
|
||||
Class<?> reference = actualType == null ? Object.class : actualType.getType();
|
||||
@@ -772,7 +772,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
|
||||
boolean notTheSameClass = !valueType.equals(reference);
|
||||
if (notTheSameClass) {
|
||||
typeMapper.writeType(valueType, dbObject);
|
||||
typeMapper.writeType(valueType, bson);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -787,8 +787,8 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
addToMap(dbObject, key, getPotentiallyConvertedSimpleWrite(value));
|
||||
}
|
||||
|
||||
private void writeSimpleInternal(Object value, Bson dbObject, MongoPersistentProperty property) {
|
||||
DocumentAccessor accessor = new DocumentAccessor(dbObject);
|
||||
private void writeSimpleInternal(Object value, Bson bson, MongoPersistentProperty property) {
|
||||
DocumentAccessor accessor = new DocumentAccessor(bson);
|
||||
accessor.put(property, getPotentiallyConvertedSimpleWrite(value));
|
||||
}
|
||||
|
||||
@@ -891,9 +891,9 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* @see org.springframework.data.mongodb.core.convert.ValueResolver#getValueInternal(org.springframework.data.mongodb.core.mapping.MongoPersistentProperty, com.mongodb.Document, org.springframework.data.mapping.model.SpELExpressionEvaluator, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Object getValueInternal(MongoPersistentProperty prop, Bson dbo, SpELExpressionEvaluator evaluator,
|
||||
public Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator,
|
||||
ObjectPath path) {
|
||||
return new MongoDbPropertyValueProvider(dbo, evaluator, path).getPropertyValue(prop);
|
||||
return new MongoDbPropertyValueProvider(bson, evaluator, path).getPropertyValue(prop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -960,17 +960,17 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
* Reads the given {@link Document} into a {@link Map}. will recursively resolve nested {@link Map}s as well.
|
||||
*
|
||||
* @param type the {@link Map} {@link TypeInformation} to be used to unmarshall this {@link Document}.
|
||||
* @param dbObject must not be {@literal null}
|
||||
* @param bson must not be {@literal null}
|
||||
* @param path must not be {@literal null}
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
protected Map<Object, Object> readMap(TypeInformation<?> type, Bson dbObject, ObjectPath path) {
|
||||
protected Map<Object, Object> readMap(TypeInformation<?> type, Bson bson, ObjectPath path) {
|
||||
|
||||
Assert.notNull(dbObject, "Document must not be null!");
|
||||
Assert.notNull(bson, "Document must not be null!");
|
||||
Assert.notNull(path, "Object path must not be null!");
|
||||
|
||||
Class<?> mapType = typeMapper.readType(dbObject, type).getType();
|
||||
Class<?> mapType = typeMapper.readType(bson, type).getType();
|
||||
|
||||
TypeInformation<?> keyType = type.getComponentType();
|
||||
Class<?> rawKeyType = keyType == null ? null : keyType.getType();
|
||||
@@ -978,7 +978,7 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
TypeInformation<?> valueType = type.getMapValueType();
|
||||
Class<?> rawValueType = valueType == null ? null : valueType.getType();
|
||||
|
||||
Map<String, Object> sourceMap = asMap(dbObject);
|
||||
Map<String, Object> sourceMap = asMap(bson);
|
||||
Map<Object, Object> map = CollectionFactory.createMap(mapType, rawKeyType, sourceMap.keySet().size());
|
||||
|
||||
if (!DBRef.class.equals(rawValueType) && isCollectionOfDbRefWhereBulkFetchIsPossible(sourceMap.values())) {
|
||||
@@ -1094,12 +1094,12 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
if (obj instanceof Document) {
|
||||
Document newValueDbo = new Document();
|
||||
Document newValueDocument = new Document();
|
||||
for (String vk : ((Document) obj).keySet()) {
|
||||
Object o = ((Document) obj).get(vk);
|
||||
newValueDbo.put(vk, convertToMongoType(o, typeHint));
|
||||
newValueDocument.put(vk, convertToMongoType(o, typeHint));
|
||||
}
|
||||
return newValueDbo;
|
||||
return newValueDocument;
|
||||
}
|
||||
|
||||
if (obj instanceof DBObject) {
|
||||
@@ -1131,18 +1131,18 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return maybeConvertList((Collection<?>) obj, typeHint);
|
||||
}
|
||||
|
||||
Document newDbo = new Document();
|
||||
this.write(obj, newDbo);
|
||||
Document newDocument = new Document();
|
||||
this.write(obj, newDocument);
|
||||
|
||||
if (typeInformation == null) {
|
||||
return removeTypeInfo(newDbo, true);
|
||||
return removeTypeInfo(newDocument, true);
|
||||
}
|
||||
|
||||
if (typeInformation.getType().equals(NestedDocument.class)) {
|
||||
return removeTypeInfo(newDbo, false);
|
||||
return removeTypeInfo(newDocument, false);
|
||||
}
|
||||
|
||||
return !obj.getClass().equals(typeInformation.getType()) ? newDbo : removeTypeInfo(newDbo, true);
|
||||
return !obj.getClass().equals(typeInformation.getType()) ? newDocument : removeTypeInfo(newDocument, true);
|
||||
}
|
||||
|
||||
public List maybeConvertList(Iterable<?> source, TypeInformation<?> typeInformation) {
|
||||
@@ -1168,14 +1168,14 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
return object;
|
||||
}
|
||||
|
||||
Document dbObject = (Document) object;
|
||||
Document document = (Document) object;
|
||||
String keyToRemove = null;
|
||||
|
||||
for (String key : dbObject.keySet()) {
|
||||
for (String key : document.keySet()) {
|
||||
|
||||
if (recursively) {
|
||||
|
||||
Object value = dbObject.get(key);
|
||||
Object value = document.get(key);
|
||||
|
||||
if (value instanceof BasicDBList) {
|
||||
for (Object element : (BasicDBList) value) {
|
||||
@@ -1201,10 +1201,10 @@ public class MappingMongoConverter extends AbstractMongoConverter implements App
|
||||
}
|
||||
|
||||
if (keyToRemove != null) {
|
||||
dbObject.remove(keyToRemove);
|
||||
document.remove(keyToRemove);
|
||||
}
|
||||
|
||||
return dbObject;
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,6 +28,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface MongoConverter
|
||||
extends EntityConverter<MongoPersistentEntity<?>, MongoPersistentProperty, Object, Bson>, MongoWriter<Object>,
|
||||
|
||||
@@ -251,24 +251,24 @@ public class MongoExampleMapper {
|
||||
|
||||
private void applyStringMatcher(Map.Entry<String, Object> entry, StringMatcher stringMatcher, boolean ignoreCase) {
|
||||
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
if (ObjectUtils.nullSafeEquals(StringMatcher.DEFAULT, stringMatcher)) {
|
||||
|
||||
if (ignoreCase) {
|
||||
dbo.put("$regex", Pattern.quote((String) entry.getValue()));
|
||||
entry.setValue(dbo);
|
||||
document.put("$regex", Pattern.quote((String) entry.getValue()));
|
||||
entry.setValue(document);
|
||||
}
|
||||
} else {
|
||||
|
||||
Type type = stringMatcherPartMapping.get(stringMatcher);
|
||||
String expression = MongoRegexCreator.INSTANCE.toRegularExpression((String) entry.getValue(), type);
|
||||
dbo.put("$regex", expression);
|
||||
entry.setValue(dbo);
|
||||
document.put("$regex", expression);
|
||||
entry.setValue(document);
|
||||
}
|
||||
|
||||
if (ignoreCase) {
|
||||
dbo.put("$options", "i");
|
||||
document.put("$options", "i");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,8 @@ import org.springframework.data.convert.TypeMapper;
|
||||
* Mongo-specific {@link TypeMapper} exposing that {@link Document}s might contain a type key.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
* @since 1.0
|
||||
*/
|
||||
public interface MongoTypeMapper extends TypeMapper<Bson> {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import com.mongodb.DBRef;
|
||||
* @author Mark Pollack
|
||||
* @author Thomas Risberg
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface MongoWriter<T> extends EntityWriter<T, Bson> {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
* Copyright 2015-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,6 +24,7 @@ import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
|
||||
* Internal API to trigger the resolution of properties.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
interface ValueResolver {
|
||||
|
||||
@@ -32,10 +33,10 @@ interface ValueResolver {
|
||||
* {@link SpELExpressionEvaluator} and {@link ObjectPath}.
|
||||
*
|
||||
* @param prop
|
||||
* @param dbo
|
||||
* @param bson
|
||||
* @param evaluator
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
Object getValueInternal(MongoPersistentProperty prop, Bson dbo, SpELExpressionEvaluator evaluator, ObjectPath parent);
|
||||
Object getValueInternal(MongoPersistentProperty prop, Bson bson, SpELExpressionEvaluator evaluator, ObjectPath parent);
|
||||
}
|
||||
|
||||
@@ -125,17 +125,6 @@ public @interface CompoundIndex {
|
||||
*/
|
||||
boolean useGeneratedName() default false;
|
||||
|
||||
/**
|
||||
* The collection the index will be created in. Will default to the collection the annotated domain class will be
|
||||
* stored in.
|
||||
*
|
||||
* @return
|
||||
* @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might
|
||||
* result in broken definitions. Will be removed in 1.7.
|
||||
*/
|
||||
@Deprecated
|
||||
String collection() default "";
|
||||
|
||||
/**
|
||||
* If {@literal true} the index will be created in the background.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -46,9 +46,9 @@ public class CompoundIndexDefinition extends Index {
|
||||
@Override
|
||||
public Document getIndexKeys() {
|
||||
|
||||
Document dbo = new Document();
|
||||
dbo.putAll(this.keys);
|
||||
dbo.putAll(super.getIndexKeys());
|
||||
return dbo;
|
||||
Document document = new Document();
|
||||
document.putAll(this.keys);
|
||||
document.putAll(super.getIndexKeys());
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,16 +83,6 @@ public @interface GeoSpatialIndexed {
|
||||
*/
|
||||
boolean useGeneratedName() default false;
|
||||
|
||||
/**
|
||||
* Name of the collection in which to create the index.
|
||||
*
|
||||
* @return
|
||||
* @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might
|
||||
* result in broken definitions. Will be removed in 1.7.
|
||||
*/
|
||||
@Deprecated
|
||||
String collection() default "";
|
||||
|
||||
/**
|
||||
* Minimum value for indexed values.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2014 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -119,31 +119,31 @@ public class GeospatialIndex implements IndexDefinition {
|
||||
|
||||
public Document getIndexKeys() {
|
||||
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
switch (type) {
|
||||
|
||||
case GEO_2D:
|
||||
dbo.put(field, "2d");
|
||||
document.put(field, "2d");
|
||||
break;
|
||||
|
||||
case GEO_2DSPHERE:
|
||||
dbo.put(field, "2dsphere");
|
||||
document.put(field, "2dsphere");
|
||||
break;
|
||||
|
||||
case GEO_HAYSTACK:
|
||||
dbo.put(field, "geoHaystack");
|
||||
document.put(field, "geoHaystack");
|
||||
if (!StringUtils.hasText(additionalField)) {
|
||||
throw new IllegalArgumentException("When defining geoHaystack index, an additionnal field must be defined");
|
||||
}
|
||||
dbo.put(additionalField, 1);
|
||||
document.put(additionalField, 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported geospatial index " + type);
|
||||
}
|
||||
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
public Document getIndexOptions() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.mongodb.core.query.Order;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -34,17 +33,7 @@ import org.springframework.util.StringUtils;
|
||||
public class Index implements IndexDefinition {
|
||||
|
||||
public enum Duplicates {
|
||||
RETAIN, //
|
||||
|
||||
/**
|
||||
* Dropping Duplicates was removed in MongoDB Server 2.8.0-rc0.
|
||||
* <p>
|
||||
* See https://jira.mongodb.org/browse/SERVER-14710
|
||||
*
|
||||
* @deprecated since 1.7.
|
||||
*/
|
||||
@Deprecated //
|
||||
DROP
|
||||
RETAIN
|
||||
}
|
||||
|
||||
private final Map<String, Direction> fieldSpec = new LinkedHashMap<String, Direction>();
|
||||
@@ -67,31 +56,6 @@ public class Index implements IndexDefinition {
|
||||
fieldSpec.put(key, direction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link Indexed} on the given key and {@link Order}.
|
||||
*
|
||||
* @deprecated use {@link #Index(String, Direction)} instead.
|
||||
* @param key must not be {@literal null} or empty.
|
||||
* @param order must not be {@literal null}.
|
||||
*/
|
||||
@Deprecated
|
||||
public Index(String key, Order order) {
|
||||
this(key, order.toDirection());
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given field to the index.
|
||||
*
|
||||
* @deprecated use {@link #on(String, Direction)} instead.
|
||||
* @param key must not be {@literal null} or empty.
|
||||
* @param order must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public Index on(String key, Order order) {
|
||||
return on(key, order.toDirection());
|
||||
}
|
||||
|
||||
public Index on(String key, Direction direction) {
|
||||
fieldSpec.put(key, direction);
|
||||
return this;
|
||||
@@ -162,56 +126,44 @@ public class Index implements IndexDefinition {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see http://docs.mongodb.org/manual/core/index-creation/#index-creation-duplicate-dropping
|
||||
* @param duplicates
|
||||
* @return
|
||||
*/
|
||||
public Index unique(Duplicates duplicates) {
|
||||
if (duplicates == Duplicates.DROP) {
|
||||
this.dropDuplicates = true;
|
||||
}
|
||||
return unique();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.data.mongodb.core.index.IndexDefinition#getIndexKeys()
|
||||
*/
|
||||
public Document getIndexKeys() {
|
||||
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
for (Entry<String, Direction> entry : fieldSpec.entrySet()) {
|
||||
dbo.put(entry.getKey(), Direction.ASC.equals(entry.getValue()) ? 1 : -1);
|
||||
document.put(entry.getKey(), Direction.ASC.equals(entry.getValue()) ? 1 : -1);
|
||||
}
|
||||
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
public Document getIndexOptions() {
|
||||
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
if (StringUtils.hasText(name)) {
|
||||
dbo.put("name", name);
|
||||
document.put("name", name);
|
||||
}
|
||||
if (unique) {
|
||||
dbo.put("unique", true);
|
||||
document.put("unique", true);
|
||||
}
|
||||
if (dropDuplicates) {
|
||||
dbo.put("dropDups", true);
|
||||
document.put("dropDups", true);
|
||||
}
|
||||
if (sparse) {
|
||||
dbo.put("sparse", true);
|
||||
document.put("sparse", true);
|
||||
}
|
||||
if (background) {
|
||||
dbo.put("background", true);
|
||||
document.put("background", true);
|
||||
}
|
||||
if (expire >= 0) {
|
||||
dbo.put("expireAfterSeconds", expire);
|
||||
document.put("expireAfterSeconds", expire);
|
||||
}
|
||||
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2014 by the original author(s).
|
||||
* Copyright (c) 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.mongodb.core.index;
|
||||
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
import org.springframework.data.mongodb.core.query.Order;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -53,20 +52,6 @@ public final class IndexField {
|
||||
this.weight = weight == null ? Float.NaN : weight;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a default {@link IndexField} with the given key and {@link Order}.
|
||||
*
|
||||
* @deprecated use {@link #create(String, Direction)}.
|
||||
* @param key must not be {@literal null} or emtpy.
|
||||
* @param direction must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public static IndexField create(String key, Order order) {
|
||||
Assert.notNull(order);
|
||||
return new IndexField(key, order.toDirection(), Type.DEFAULT);
|
||||
}
|
||||
|
||||
public static IndexField create(String key, Direction order) {
|
||||
Assert.notNull(order);
|
||||
return new IndexField(key, order, Type.DEFAULT);
|
||||
@@ -98,17 +83,6 @@ public final class IndexField {
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the direction of the {@link IndexField} or {@literal null} in case we have a geo index field.
|
||||
*
|
||||
* @deprecated use {@link #getDirection()} instead.
|
||||
* @return the direction
|
||||
*/
|
||||
@Deprecated
|
||||
public Order getOrder() {
|
||||
return Direction.ASC.equals(direction) ? Order.ASCENDING : Order.DESCENDING;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the direction of the {@link IndexField} or {@literal null} in case we have a geo index field.
|
||||
*
|
||||
|
||||
@@ -38,19 +38,6 @@ public class IndexInfo {
|
||||
private final boolean sparse;
|
||||
private final String language;
|
||||
|
||||
/**
|
||||
* @deprecated Will be removed in 1.7. Please use {@link #IndexInfo(List, String, boolean, boolean, boolean, String)}
|
||||
* @param indexFields
|
||||
* @param name
|
||||
* @param unique
|
||||
* @param dropDuplicates
|
||||
* @param sparse
|
||||
*/
|
||||
@Deprecated
|
||||
public IndexInfo(List<IndexField> indexFields, String name, boolean unique, boolean dropDuplicates, boolean sparse) {
|
||||
this(indexFields, name, unique, dropDuplicates, sparse, "");
|
||||
}
|
||||
|
||||
public IndexInfo(List<IndexField> indexFields, String name, boolean unique, boolean dropDuplicates, boolean sparse,
|
||||
String language) {
|
||||
|
||||
|
||||
@@ -109,16 +109,6 @@ public @interface Indexed {
|
||||
*/
|
||||
boolean useGeneratedName() default false;
|
||||
|
||||
/**
|
||||
* Collection name for index to be created on.
|
||||
*
|
||||
* @return
|
||||
* @deprecated The collection name is derived from the domain type. Fixing the collection via this attribute might
|
||||
* result in broken definitions. Will be removed in 1.7.
|
||||
*/
|
||||
@Deprecated
|
||||
String collection() default "";
|
||||
|
||||
/**
|
||||
* If {@literal true} the index will be created in the background.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -153,9 +153,6 @@ public class MongoPersistentEntityIndexCreator implements ApplicationListener<Ma
|
||||
if (indexOptions.containsKey("unique")) {
|
||||
ops = ops.unique((Boolean) indexOptions.get("unique"));
|
||||
}
|
||||
// if(indexOptions.containsField("dropDuplicates")) {
|
||||
// ops = ops.((boolean)indexOptions.get("dropDuplicates"));
|
||||
// }
|
||||
if (indexOptions.containsKey("sparse")) {
|
||||
ops = ops.sparse((Boolean) indexOptions.get("sparse"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,7 +33,6 @@ import org.springframework.data.mapping.Association;
|
||||
import org.springframework.data.mapping.AssociationHandler;
|
||||
import org.springframework.data.mapping.PropertyHandler;
|
||||
import org.springframework.data.mapping.model.MappingException;
|
||||
import org.springframework.data.mongodb.core.index.Index.Duplicates;
|
||||
import org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexResolver.TextIndexIncludeOptions.IncludeStrategy;
|
||||
import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexDefinitionBuilder;
|
||||
import org.springframework.data.mongodb.core.index.TextIndexDefinition.TextIndexedFieldSpec;
|
||||
@@ -321,7 +320,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected IndexDefinitionHolder createCompoundIndexDefinition(String dotPath, String fallbackCollection,
|
||||
protected IndexDefinitionHolder createCompoundIndexDefinition(String dotPath, String collection,
|
||||
CompoundIndex index, MongoPersistentEntity<?> entity) {
|
||||
|
||||
CompoundIndexDefinition indexDefinition = new CompoundIndexDefinition(
|
||||
@@ -332,7 +331,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
}
|
||||
|
||||
if (index.unique()) {
|
||||
indexDefinition.unique(index.dropDups() ? Duplicates.DROP : Duplicates.RETAIN);
|
||||
indexDefinition.unique();
|
||||
}
|
||||
|
||||
if (index.sparse()) {
|
||||
@@ -343,7 +342,6 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
indexDefinition.background();
|
||||
}
|
||||
|
||||
String collection = StringUtils.hasText(index.collection()) ? index.collection() : fallbackCollection;
|
||||
return new IndexDefinitionHolder(dotPath, indexDefinition, collection);
|
||||
}
|
||||
|
||||
@@ -379,11 +377,10 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
* @param persitentProperty
|
||||
* @return
|
||||
*/
|
||||
protected IndexDefinitionHolder createIndexDefinition(String dotPath, String fallbackCollection,
|
||||
protected IndexDefinitionHolder createIndexDefinition(String dotPath, String collection,
|
||||
MongoPersistentProperty persitentProperty) {
|
||||
|
||||
Indexed index = persitentProperty.findAnnotation(Indexed.class);
|
||||
String collection = StringUtils.hasText(index.collection()) ? index.collection() : fallbackCollection;
|
||||
|
||||
Index indexDefinition = new Index().on(dotPath,
|
||||
IndexDirection.ASCENDING.equals(index.direction()) ? Sort.Direction.ASC : Sort.Direction.DESC);
|
||||
@@ -393,7 +390,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
}
|
||||
|
||||
if (index.unique()) {
|
||||
indexDefinition.unique(index.dropDups() ? Duplicates.DROP : Duplicates.RETAIN);
|
||||
indexDefinition.unique();
|
||||
}
|
||||
|
||||
if (index.sparse()) {
|
||||
@@ -420,11 +417,10 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
|
||||
* @param persistentProperty
|
||||
* @return
|
||||
*/
|
||||
protected IndexDefinitionHolder createGeoSpatialIndexDefinition(String dotPath, String fallbackCollection,
|
||||
protected IndexDefinitionHolder createGeoSpatialIndexDefinition(String dotPath, String collection,
|
||||
MongoPersistentProperty persistentProperty) {
|
||||
|
||||
GeoSpatialIndexed index = persistentProperty.findAnnotation(GeoSpatialIndexed.class);
|
||||
String collection = StringUtils.hasText(index.collection()) ? index.collection() : fallbackCollection;
|
||||
|
||||
GeospatialIndex indexDefinition = new GeospatialIndex(dotPath);
|
||||
indexDefinition.withBits(index.bits());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -113,15 +113,15 @@ public class TextIndexDefinition implements IndexDefinition {
|
||||
options.put("default_language", defaultLanguage);
|
||||
}
|
||||
|
||||
Document weightsDbo = new Document();
|
||||
Document weightsDocument = new Document();
|
||||
for (TextIndexedFieldSpec fieldSpec : fieldSpecs) {
|
||||
if (fieldSpec.isWeighted()) {
|
||||
weightsDbo.put(fieldSpec.getFieldname(), fieldSpec.getWeight());
|
||||
weightsDocument.put(fieldSpec.getFieldname(), fieldSpec.getWeight());
|
||||
}
|
||||
}
|
||||
|
||||
if (!weightsDbo.isEmpty()) {
|
||||
options.put("weights", weightsDbo);
|
||||
if (!weightsDocument.isEmpty()) {
|
||||
options.put("weights", weightsDocument);
|
||||
}
|
||||
if (StringUtils.hasText(languageOverride)) {
|
||||
options.put("language_override", languageOverride);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011 by the original author(s).
|
||||
* Copyright (c) 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,6 +34,7 @@ import com.mongodb.DBRef;
|
||||
* Simple constant holder for a {@link SimpleTypeHolder} enriched with Mongo specific simple types.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public abstract class MongoSimpleTypes {
|
||||
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* Copyright 2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.mapping;
|
||||
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.*;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Demarcates a property to be used as version field to implement optimistic locking on entities.
|
||||
*
|
||||
* @since 1.4
|
||||
* @author Patryk Wasik
|
||||
* @deprecated use {@link org.springframework.data.annotation.Version} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
@Documented
|
||||
@Target({ FIELD })
|
||||
@Retention(RUNTIME)
|
||||
@org.springframework.data.annotation.Version
|
||||
public @interface Version {
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 by the original author(s).
|
||||
* Copyright 2013-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,26 +31,14 @@ public abstract class AbstractDeleteEvent<T> extends MongoMappingEvent<Document>
|
||||
/**
|
||||
* Creates a new {@link AbstractDeleteEvent} for the given {@link Document} and type.
|
||||
*
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param type can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #AbstractDeleteEvent(Document, Class, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public AbstractDeleteEvent(Document dbo, Class<T> type) {
|
||||
this(dbo, type, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link AbstractDeleteEvent} for the given {@link Document} and type.
|
||||
*
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param document must not be {@literal null}.
|
||||
* @param type can be {@literal null}.
|
||||
* @param collectionName can be {@literal null}.
|
||||
* @since 1.8
|
||||
*/
|
||||
public AbstractDeleteEvent(Document dbo, Class<T> type, String collectionName) {
|
||||
public AbstractDeleteEvent(Document document, Class<T> type, String collectionName) {
|
||||
|
||||
super(dbo, dbo, collectionName);
|
||||
super(document, document, collectionName);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.mapping.event;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2015 by the original author(s).
|
||||
* Copyright (c) 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,25 +30,13 @@ public class AfterConvertEvent<E> extends MongoMappingEvent<E> {
|
||||
/**
|
||||
* Creates new {@link AfterConvertEvent}.
|
||||
*
|
||||
* @param dbo can be {@literal null}.
|
||||
* @param source must not be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #AfterConvertEvent(Document, Object, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public AfterConvertEvent(Document dbo, E source) {
|
||||
this(dbo, source, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link AfterConvertEvent}.
|
||||
*
|
||||
* @param dbo can be {@literal null}.
|
||||
* @param document can be {@literal null}.
|
||||
* @param source must not be {@literal null}.
|
||||
* @param collectionName can be {@literal null}.
|
||||
* @since 1.8
|
||||
*/
|
||||
public AfterConvertEvent(Document dbo, E source, String collectionName) {
|
||||
super(source, dbo, collectionName);
|
||||
public AfterConvertEvent(Document document, E source, String collectionName) {
|
||||
super(source, document, collectionName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 by the original author(s).
|
||||
* Copyright 2013-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,18 +28,6 @@ public class AfterDeleteEvent<T> extends AbstractDeleteEvent<T> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates a new {@link AfterDeleteEvent} for the given {@link Document} and type.
|
||||
*
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param type can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #AfterDeleteEvent(Document, Class, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public AfterDeleteEvent(Document dbo, Class<T> type) {
|
||||
this(dbo, type, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link AfterDeleteEvent} for the given {@link Document}, type and collectionName.
|
||||
*
|
||||
@@ -48,7 +36,7 @@ public class AfterDeleteEvent<T> extends AbstractDeleteEvent<T> {
|
||||
* @param collectionName can be {@literal null}.
|
||||
* @since 1.8
|
||||
*/
|
||||
public AfterDeleteEvent(Document dbo, Class<T> type, String collectionName) {
|
||||
super(dbo, type, collectionName);
|
||||
public AfterDeleteEvent(Document document, Class<T> type, String collectionName) {
|
||||
super(document, type, collectionName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2015 by the original author(s).
|
||||
* Copyright (c) 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,29 +32,17 @@ public class AfterLoadEvent<T> extends MongoMappingEvent<Document> {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final Class<T> type;
|
||||
|
||||
/**
|
||||
* Creates a new {@link AfterLoadEvent} for the given {@link Document} and type.
|
||||
*
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param type can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #AfterLoadEvent(Document, Class, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public AfterLoadEvent(Document dbo, Class<T> type) {
|
||||
this(dbo, type, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link AfterLoadEvent} for the given {@link Document}, type and collectionName.
|
||||
*
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param document must not be {@literal null}.
|
||||
* @param type must not be {@literal null}.
|
||||
* @param collectionName can be {@literal null}.
|
||||
* @since 1.8
|
||||
*/
|
||||
public AfterLoadEvent(Document dbo, Class<T> type, String collectionName) {
|
||||
public AfterLoadEvent(Document document, Class<T> type, String collectionName) {
|
||||
|
||||
super(dbo, dbo, collectionName);
|
||||
super(document, document, collectionName);
|
||||
|
||||
Assert.notNull(type, "Type must not be null!");
|
||||
this.type = type;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2015 by the original author(s).
|
||||
* Copyright (c) 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,28 +28,16 @@ public class AfterSaveEvent<E> extends MongoMappingEvent<E> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Creates new {@link AfterSaveEvent}
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #AfterSaveEvent(Object, Document, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public AfterSaveEvent(E source, Document dbo) {
|
||||
super(source, dbo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link AfterSaveEvent}.
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @param document can be {@literal null}.
|
||||
* @param collectionName can be {@literal null}.
|
||||
* @since 1.8
|
||||
*/
|
||||
public AfterSaveEvent(E source, Document dbo, String collectionName) {
|
||||
super(source, dbo, collectionName);
|
||||
public AfterSaveEvent(E source, Document document, String collectionName) {
|
||||
super(source, document, collectionName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,17 +26,6 @@ public class BeforeConvertEvent<T> extends MongoMappingEvent<T> {
|
||||
|
||||
private static final long serialVersionUID = 252614269008845243L;
|
||||
|
||||
/**
|
||||
* Creates new {@link BeforeConvertEvent}.
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #BeforeConvertEvent(Object, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public BeforeConvertEvent(T source) {
|
||||
this(source, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link BeforeConvertEvent}.
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 by the original author(s).
|
||||
* Copyright 2013-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,27 +28,15 @@ public class BeforeDeleteEvent<T> extends AbstractDeleteEvent<T> {
|
||||
|
||||
private static final long serialVersionUID = -2627547705679734497L;
|
||||
|
||||
/**
|
||||
* Creates a new {@link BeforeDeleteEvent} for the given {@link Document} and type.
|
||||
*
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param type can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #BeforeDeleteEvent(Document, Class, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public BeforeDeleteEvent(Document dbo, Class<T> type) {
|
||||
this(dbo, type, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new {@link BeforeDeleteEvent} for the given {@link Document}, type and collectionName.
|
||||
*
|
||||
* @param dbo must not be {@literal null}.
|
||||
* @param document must not be {@literal null}.
|
||||
* @param type can be {@literal null}.
|
||||
* @param collectionName can be {@literal null}.
|
||||
* @since 1.8
|
||||
*/
|
||||
public BeforeDeleteEvent(Document dbo, Class<T> type, String collectionName) {
|
||||
super(dbo, type, collectionName);
|
||||
public BeforeDeleteEvent(Document document, Class<T> type, String collectionName) {
|
||||
super(document, type, collectionName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2015 by the original author(s).
|
||||
* Copyright (c) 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,24 +32,12 @@ public class BeforeSaveEvent<E> extends MongoMappingEvent<E> {
|
||||
* Creates new {@link BeforeSaveEvent}.
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #BeforeSaveEvent(Object, Document, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public BeforeSaveEvent(E source, Document dbo) {
|
||||
super(source, dbo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link BeforeSaveEvent}.
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @param document can be {@literal null}.
|
||||
* @param collectionName can be {@literal null}.
|
||||
* @since 1.8
|
||||
*/
|
||||
public BeforeSaveEvent(E source, Document dbo, String collectionName) {
|
||||
super(source, dbo, collectionName);
|
||||
public BeforeSaveEvent(E source, Document document, String collectionName) {
|
||||
super(source, document, collectionName);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.mapping.event;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
@@ -26,6 +25,7 @@ import org.springframework.context.ApplicationListener;
|
||||
* @author Jon Brisbin
|
||||
* @author Martin Baumgartner
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class LoggingEventListener extends AbstractMongoEventListener<Object> {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2011-2015 by the original author(s).
|
||||
* Copyright (c) 2011-2016 by the original author(s).
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,32 +28,20 @@ import org.springframework.context.ApplicationEvent;
|
||||
public class MongoMappingEvent<T> extends ApplicationEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private final Document dbo;
|
||||
private final Document document;
|
||||
private final String collectionName;
|
||||
|
||||
/**
|
||||
* Creates new {@link MongoMappingEvent}.
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @deprecated since 1.8. Please use {@link #MongoMappingEvent(Object, Document, String)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public MongoMappingEvent(T source, Document dbo) {
|
||||
this(source, dbo, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates new {@link MongoMappingEvent}.
|
||||
*
|
||||
* @param source must not be {@literal null}.
|
||||
* @param dbo can be {@literal null}.
|
||||
* @param document can be {@literal null}.
|
||||
* @param collectionName can be {@literal null}.
|
||||
*/
|
||||
public MongoMappingEvent(T source, Document dbo, String collectionName) {
|
||||
public MongoMappingEvent(T source, Document document, String collectionName) {
|
||||
|
||||
super(source);
|
||||
this.dbo = dbo;
|
||||
this.document = document;
|
||||
this.collectionName = collectionName;
|
||||
}
|
||||
|
||||
@@ -61,7 +49,7 @@ public class MongoMappingEvent<T> extends ApplicationEvent {
|
||||
* @return {@literal null} if not set.
|
||||
*/
|
||||
public Document getDocument() {
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ import java.util.Set;
|
||||
import javax.validation.ConstraintViolationException;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.bson.Document;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.Assert;
|
||||
@@ -31,6 +30,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Maciej Walkowiak
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class ValidatingMongoEventListener extends AbstractMongoEventListener<Object> {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,33 +23,34 @@ import org.bson.Document;
|
||||
* map-reduce.
|
||||
*
|
||||
* @author Mark Pollack
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class GroupBy {
|
||||
|
||||
private Document dboKeys;
|
||||
private String keyFunction;
|
||||
private String initial;
|
||||
private Document initialDbObject;
|
||||
private Document initialDocument;
|
||||
private String reduce;
|
||||
private String finalize;
|
||||
|
||||
public GroupBy(String... keys) {
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
for (String key : keys) {
|
||||
dbo.put(key, 1);
|
||||
document.put(key, 1);
|
||||
}
|
||||
dboKeys = dbo;
|
||||
dboKeys = document;
|
||||
}
|
||||
|
||||
// NOTE GroupByCommand does not handle keyfunction.
|
||||
|
||||
public GroupBy(String key, boolean isKeyFunction) {
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
if (isKeyFunction) {
|
||||
keyFunction = key;
|
||||
} else {
|
||||
dbo.put(key, 1);
|
||||
dboKeys = dbo;
|
||||
document.put(key, 1);
|
||||
dboKeys = document;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ public class GroupBy {
|
||||
}
|
||||
|
||||
public GroupBy initialDocument(Document initialDocument) {
|
||||
initialDbObject = initialDocument;
|
||||
this.initialDocument = initialDocument;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -83,24 +84,24 @@ public class GroupBy {
|
||||
|
||||
public Document getGroupByObject() {
|
||||
// return new GroupCommand(dbCollection, dboKeys, condition, initial, reduce, finalize);
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
if (dboKeys != null) {
|
||||
dbo.put("key", dboKeys);
|
||||
document.put("key", dboKeys);
|
||||
}
|
||||
if (keyFunction != null) {
|
||||
dbo.put("$keyf", keyFunction);
|
||||
document.put("$keyf", keyFunction);
|
||||
}
|
||||
|
||||
dbo.put("$reduce", reduce);
|
||||
document.put("$reduce", reduce);
|
||||
|
||||
dbo.put("initial", initialDbObject);
|
||||
document.put("initial", initialDocument);
|
||||
if (initial != null) {
|
||||
dbo.put("initial", initial);
|
||||
document.put("initial", initial);
|
||||
}
|
||||
if (finalize != null) {
|
||||
dbo.put("finalize", finalize);
|
||||
document.put("finalize", finalize);
|
||||
}
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011 - 2014 the original author or authors.
|
||||
* Copyright 2011 - 2016O the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2011 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,6 +20,12 @@ import java.util.Collections;
|
||||
|
||||
import org.bson.Document;
|
||||
|
||||
/**
|
||||
* @author Thomas Risberg
|
||||
* @author John Brisbin
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class BasicUpdate extends Update {
|
||||
|
||||
private Document updateObject = null;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -617,9 +617,9 @@ public class Criteria implements CriteriaDefinition {
|
||||
} else {
|
||||
Document criteriaObject = new Document();
|
||||
for (Criteria c : this.criteriaChain) {
|
||||
Document dbo = c.getSingleCriteriaObject();
|
||||
for (String k : dbo.keySet()) {
|
||||
setValue(criteriaObject, k, dbo.get(k));
|
||||
Document document = c.getSingleCriteriaObject();
|
||||
for (String k : document.keySet()) {
|
||||
setValue(criteriaObject, k, document.get(k));
|
||||
}
|
||||
}
|
||||
return criteriaObject;
|
||||
@@ -628,7 +628,7 @@ public class Criteria implements CriteriaDefinition {
|
||||
|
||||
protected Document getSingleCriteriaObject() {
|
||||
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
boolean not = false;
|
||||
|
||||
for (Entry<String, Object> entry : criteria.entrySet()) {
|
||||
@@ -641,33 +641,33 @@ public class Criteria implements CriteriaDefinition {
|
||||
}
|
||||
|
||||
if (not) {
|
||||
Document notDbo = new Document();
|
||||
notDbo.put(key, value);
|
||||
dbo.put("$not", notDbo);
|
||||
Document notDocument = new Document();
|
||||
notDocument.put(key, value);
|
||||
document.put("$not", notDocument);
|
||||
not = false;
|
||||
} else {
|
||||
if ("$not".equals(key) && value == null) {
|
||||
not = true;
|
||||
} else {
|
||||
dbo.put(key, value);
|
||||
document.put(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.hasText(this.key)) {
|
||||
if (not) {
|
||||
return new Document("$not", dbo);
|
||||
return new Document("$not", document);
|
||||
}
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
Document queryCriteria = new Document();
|
||||
|
||||
if (!NOT_SET.equals(isValue)) {
|
||||
queryCriteria.put(this.key, this.isValue);
|
||||
queryCriteria.putAll(dbo);
|
||||
queryCriteria.putAll(document);
|
||||
} else {
|
||||
queryCriteria.put(this.key, dbo);
|
||||
queryCriteria.put(this.key, document);
|
||||
}
|
||||
|
||||
return queryCriteria;
|
||||
@@ -681,10 +681,10 @@ public class Criteria implements CriteriaDefinition {
|
||||
return bsonList;
|
||||
}
|
||||
|
||||
private void setValue(Document dbo, String key, Object value) {
|
||||
Object existing = dbo.get(key);
|
||||
private void setValue(Document document, String key, Object value) {
|
||||
Object existing = document.get(key);
|
||||
if (existing == null) {
|
||||
dbo.put(key, value);
|
||||
document.put(key, value);
|
||||
} else {
|
||||
throw new InvalidMongoDbApiUsageException("Due to limitations of the com.mongodb.BasicDocument, "
|
||||
+ "you can't add a second '" + key + "' expression specified as '" + key + " : " + value + "'. "
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2014 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 the original author or authors.
|
||||
* Copyright 2010-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.util.ObjectUtils;
|
||||
* @author Thomas Risberg
|
||||
* @author Oliver Gierke
|
||||
* @author Patryk Wasik
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class Field {
|
||||
|
||||
@@ -81,22 +82,22 @@ public class Field {
|
||||
|
||||
public Document getFieldsObject() {
|
||||
|
||||
Document dbo = new Document((Map) criteria);
|
||||
Document document = new Document((Map) criteria);
|
||||
|
||||
for (Entry<String, Object> entry : slices.entrySet()) {
|
||||
dbo.put(entry.getKey(), new Document("$slice", entry.getValue()));
|
||||
document.put(entry.getKey(), new Document("$slice", entry.getValue()));
|
||||
}
|
||||
|
||||
for (Entry<String, Criteria> entry : elemMatchs.entrySet()) {
|
||||
Document dbObject = new Document("$elemMatch", entry.getValue().getCriteriaObject());
|
||||
dbo.put(entry.getKey(), dbObject);
|
||||
document.put(entry.getKey(), dbObject);
|
||||
}
|
||||
|
||||
if (postionKey != null) {
|
||||
dbo.put(postionKey + ".$", positionValue);
|
||||
document.put(postionKey + ".$", positionValue);
|
||||
}
|
||||
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2015 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -298,19 +298,6 @@ public final class NearQuery {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the distance multiplier to the multiplier of the given {@link Metric}.
|
||||
*
|
||||
* @deprecated use {@link #in(Metric)} instead.
|
||||
* @param metric must not be {@literal null}.
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
public NearQuery distanceMultiplier(Metric metric) {
|
||||
Assert.notNull(metric);
|
||||
return in(metric);
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures whether to return spherical values for the actual distance.
|
||||
*
|
||||
@@ -411,32 +398,32 @@ public final class NearQuery {
|
||||
*/
|
||||
public Document toDocument() {
|
||||
|
||||
Document dbObject = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
if (query != null) {
|
||||
dbObject.put("query", query.getQueryObject());
|
||||
document.put("query", query.getQueryObject());
|
||||
}
|
||||
|
||||
if (maxDistance != null) {
|
||||
dbObject.put("maxDistance", maxDistance.getNormalizedValue());
|
||||
document.put("maxDistance", maxDistance.getNormalizedValue());
|
||||
}
|
||||
|
||||
if (minDistance != null) {
|
||||
dbObject.put("minDistance", minDistance.getNormalizedValue());
|
||||
document.put("minDistance", minDistance.getNormalizedValue());
|
||||
}
|
||||
|
||||
if (metric != null) {
|
||||
dbObject.put("distanceMultiplier", metric.getMultiplier());
|
||||
document.put("distanceMultiplier", metric.getMultiplier());
|
||||
}
|
||||
|
||||
if (num != null) {
|
||||
dbObject.put("num", num);
|
||||
document.put("num", num);
|
||||
}
|
||||
|
||||
dbObject.put("near", Arrays.asList(point.getX(), point.getY()));
|
||||
document.put("near", Arrays.asList(point.getX(), point.getY()));
|
||||
|
||||
dbObject.put("spherical", spherical);
|
||||
document.put("spherical", spherical);
|
||||
|
||||
return dbObject;
|
||||
return document;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.mongodb.core.query;
|
||||
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
|
||||
/**
|
||||
* An enum that specifies the ordering for sort or index specifications
|
||||
*
|
||||
* @deprecated prefer {@link Direction}
|
||||
* @author Thomas Risberg
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@Deprecated
|
||||
public enum Order {
|
||||
|
||||
ASCENDING {
|
||||
@Override
|
||||
public Direction toDirection() {
|
||||
return Direction.ASC;
|
||||
}
|
||||
},
|
||||
|
||||
DESCENDING {
|
||||
@Override
|
||||
public Direction toDirection() {
|
||||
return Direction.DESC;
|
||||
}
|
||||
};
|
||||
|
||||
public abstract Direction toDirection();
|
||||
}
|
||||
@@ -218,17 +218,17 @@ public class Query {
|
||||
|
||||
public Document getQueryObject() {
|
||||
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
for (CriteriaDefinition definition : criteria.values()) {
|
||||
dbo.putAll(definition.getCriteriaObject());
|
||||
document.putAll(definition.getCriteriaObject());
|
||||
}
|
||||
|
||||
if (!restrictedTypes.isEmpty()) {
|
||||
dbo.put(RESTRICTED_TYPES_KEY, getRestrictedTypes());
|
||||
document.put(RESTRICTED_TYPES_KEY, getRestrictedTypes());
|
||||
}
|
||||
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
public Document getFieldsObject() {
|
||||
@@ -241,13 +241,13 @@ public class Query {
|
||||
return null;
|
||||
}
|
||||
|
||||
Document dbo = new Document();
|
||||
Document document = new Document();
|
||||
|
||||
for (org.springframework.data.domain.Sort.Order order : this.sort) {
|
||||
dbo.put(order.getProperty(), order.isAscending() ? 1 : -1);
|
||||
document.put(order.getProperty(), order.isAscending() ? 1 : -1);
|
||||
}
|
||||
|
||||
return dbo;
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -77,8 +77,8 @@ public abstract class SerializationUtils {
|
||||
|
||||
if (source instanceof Document) {
|
||||
|
||||
Document dbo = (Document) source;
|
||||
Iterator<Map.Entry<String, Object>> iter = dbo.entrySet().iterator();
|
||||
Document document = (Document) source;
|
||||
Iterator<Map.Entry<String, Object>> iter = document.entrySet().iterator();
|
||||
String pathPrefix = currentPath.isEmpty() ? "" : currentPath + ".";
|
||||
|
||||
while (iter.hasNext()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,7 @@ import org.springframework.util.Assert;
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class ExpressionTransformationContextSupport<T extends ExpressionNode> {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import org.springframework.data.mongodb.core.query.Criteria;
|
||||
* GridFs-specific helper class to define {@link Criteria}s.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class GridFsCriteria extends Criteria {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011-2014 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,6 +33,7 @@ import com.mongodb.gridfs.GridFSFile;
|
||||
* @author Philipp Schneider
|
||||
* @author Thomas Darimont
|
||||
* @author Martin Baumgartner
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public interface GridFsOperations extends ResourcePatternResolver {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2011 the original author or authors.
|
||||
* Copyright 2011-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,6 +29,7 @@ import com.mongodb.gridfs.GridFSDBFile;
|
||||
* {@link GridFSDBFile} based {@link Resource} implementation.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Christoph Strobl
|
||||
*/
|
||||
public class GridFsResource extends InputStreamResource {
|
||||
|
||||
|
||||
@@ -134,14 +134,14 @@ public class GridFsTemplate implements GridFsOperations, ResourcePatternResolver
|
||||
*/
|
||||
public ObjectId store(InputStream content, String filename, String contentType, Object metadata) {
|
||||
|
||||
Document dbObject = null;
|
||||
Document document = null;
|
||||
|
||||
if (metadata != null) {
|
||||
dbObject = new Document();
|
||||
converter.write(metadata, dbObject);
|
||||
document = new Document();
|
||||
converter.write(metadata, document);
|
||||
}
|
||||
|
||||
return store(content, filename, contentType, dbObject);
|
||||
return store(content, filename, contentType, document);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -35,23 +35,12 @@ import org.springframework.data.annotation.QueryAnnotation;
|
||||
@QueryAnnotation
|
||||
public @interface Meta {
|
||||
|
||||
/**
|
||||
* Set the maximum time limit in milliseconds for processing operations.
|
||||
*
|
||||
* @deprecated since 1.10 because of spelling issues. Please use {@link #maxExecutionTimeMs()} instead.
|
||||
* @return
|
||||
*/
|
||||
@AliasFor("maxExecutionTimeMs")
|
||||
@Deprecated
|
||||
long maxExcecutionTime() default -1;
|
||||
|
||||
/**
|
||||
* Set the maximum time limit in milliseconds for processing operations.
|
||||
*
|
||||
* @return
|
||||
* @since 1.10
|
||||
*/
|
||||
@AliasFor("maxExcecutionTime")
|
||||
long maxExecutionTimeMs() default -1;
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,17 +126,6 @@ public class MongoParameters extends Parameters<MongoParameters, MongoParameter>
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of a {@link Distance} parameter to be used for geo queries.
|
||||
*
|
||||
* @return
|
||||
* @deprecated since 1.7. Please use {@link #getMaxDistanceIndex()} instead.
|
||||
*/
|
||||
@Deprecated
|
||||
public int getDistanceIndex() {
|
||||
return getMaxDistanceIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the {@link Distance} parameter to be used for max distance in geo queries.
|
||||
*
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user