|
40 | 40 | import org.springframework.data.mongodb.core.mapreduce.MapReduceOptions;
|
41 | 41 | import org.springframework.data.mongodb.core.mapreduce.MapReduceResults;
|
42 | 42 | import org.springframework.data.mongodb.core.query.BasicQuery;
|
| 43 | +import org.springframework.data.mongodb.core.query.Collation; |
43 | 44 | import org.springframework.data.mongodb.core.query.Criteria;
|
44 | 45 | import org.springframework.data.mongodb.core.query.NearQuery;
|
45 | 46 | import org.springframework.data.mongodb.core.query.Query;
|
@@ -1754,119 +1755,115 @@ default long exactCount(Query query, String collectionName) {
|
1754 | 1755 | <T> List<T> findAllAndRemove(Query query, Class<T> entityClass, String collectionName);
|
1755 | 1756 |
|
1756 | 1757 | /**
|
1757 |
| - * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to |
1758 |
| - * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document. |
1759 |
| - * <br /> |
| 1758 | + * Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} |
| 1759 | + * document. <br /> |
1760 | 1760 | * The collection name is derived from the {@literal replacement} type. <br />
|
1761 |
| - * Options are defaulted to {@link ReplaceOptions#empty()}. <br /> |
1762 |
| - * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}. |
| 1761 | + * Options are defaulted to {@link ReplaceOptions#none()}. |
1763 | 1762 | *
|
1764 |
| - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional |
1765 |
| - * fields specification. Must not be {@literal null}. |
| 1763 | + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record. The query may |
| 1764 | + * contain an index {@link Query#withHint(String) hint} or the {@link Query#collation(Collation) collation} |
| 1765 | + * to use. Must not be {@literal null}. |
1766 | 1766 | * @param replacement the replacement document. Must not be {@literal null}.
|
1767 | 1767 | * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
|
1768 | 1768 | * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
|
1769 | 1769 | * {@link #getCollectionName(Class) derived} from the given replacement value.
|
| 1770 | + * @since 4.2 |
1770 | 1771 | */
|
1771 | 1772 | default <T> UpdateResult replace(Query query, T replacement) {
|
1772 |
| - return replace(query, replacement, ReplaceOptions.empty()); |
| 1773 | + return replace(query, replacement, ReplaceOptions.none()); |
1773 | 1774 | }
|
1774 | 1775 |
|
1775 | 1776 | /**
|
1776 |
| - * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to |
1777 |
| - * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} |
1778 |
| - * document.<br /> |
1779 |
| - * Options are defaulted to {@link ReplaceOptions#empty()}. <br /> |
1780 |
| - * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}. |
| 1777 | + * Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} |
| 1778 | + * document. Options are defaulted to {@link ReplaceOptions#none()}. |
1781 | 1779 | *
|
1782 |
| - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional |
1783 |
| - * fields specification. Must not be {@literal null}. |
| 1780 | + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record. The query may |
| 1781 | + * contain an index {@link Query#withHint(String) hint} or the {@link Query#collation(Collation) collation} |
| 1782 | + * to use. Must not be {@literal null}. |
1784 | 1783 | * @param replacement the replacement document. Must not be {@literal null}.
|
1785 | 1784 | * @param collectionName the collection to query. Must not be {@literal null}.
|
1786 | 1785 | * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
|
1787 | 1786 | * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
|
1788 | 1787 | * {@link #getCollectionName(Class) derived} from the given replacement value.
|
| 1788 | + * @since 4.2 |
1789 | 1789 | */
|
1790 | 1790 | default <T> UpdateResult replace(Query query, T replacement, String collectionName) {
|
1791 |
| - return replace(query, replacement, ReplaceOptions.empty(), collectionName); |
| 1791 | + return replace(query, replacement, ReplaceOptions.none(), collectionName); |
1792 | 1792 | }
|
1793 | 1793 |
|
1794 | 1794 | /**
|
1795 |
| - * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to |
1796 |
| - * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document |
1797 |
| - * taking {@link ReplaceOptions} into account.<br /> |
1798 |
| - * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}. |
| 1795 | + * Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} |
| 1796 | + * document taking {@link ReplaceOptions} into account. |
1799 | 1797 | *
|
1800 |
| - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional |
1801 |
| - * fields specification. Must not be {@literal null}. |
| 1798 | + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record.The query may |
| 1799 | + * contain an index {@link Query#withHint(String) hint} or the {@link Query#collation(Collation) collation} |
| 1800 | + * to use. Must not be {@literal null}. |
1802 | 1801 | * @param replacement the replacement document. Must not be {@literal null}.
|
1803 |
| - * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. |
| 1802 | + * @param options the {@link ReplaceOptions} holding additional information. Must not be {@literal null}. |
1804 | 1803 | * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
|
1805 | 1804 | * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
|
1806 | 1805 | * {@link #getCollectionName(Class) derived} from the given replacement value.
|
| 1806 | + * @since 4.2 |
1807 | 1807 | */
|
1808 | 1808 | default <T> UpdateResult replace(Query query, T replacement, ReplaceOptions options) {
|
1809 | 1809 | return replace(query, replacement, options, getCollectionName(ClassUtils.getUserClass(replacement)));
|
1810 | 1810 | }
|
1811 | 1811 |
|
1812 | 1812 | /**
|
1813 |
| - * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to |
1814 |
| - * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document |
1815 |
| - * taking {@link ReplaceOptions} into account.<br /> |
1816 |
| - * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}. |
| 1813 | + * Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} |
| 1814 | + * document taking {@link ReplaceOptions} into account. |
1817 | 1815 | *
|
1818 |
| - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional |
1819 |
| - * fields specification. Must not be {@literal null}. |
| 1816 | + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record. The query may * |
| 1817 | + * contain an index {@link Query#withHint(String) hint} or the {@link Query#collation(Collation) collation} |
| 1818 | + * to use. Must not be {@literal null}. |
1820 | 1819 | * @param replacement the replacement document. Must not be {@literal null}.
|
1821 |
| - * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. |
| 1820 | + * @param options the {@link ReplaceOptions} holding additional information. Must not be {@literal null}. |
1822 | 1821 | * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
|
1823 | 1822 | * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
|
1824 | 1823 | * {@link #getCollectionName(Class) derived} from the given replacement value.
|
| 1824 | + * @since 4.2 |
1825 | 1825 | */
|
1826 | 1826 | default <T> UpdateResult replace(Query query, T replacement, ReplaceOptions options, String collectionName) {
|
1827 | 1827 |
|
1828 | 1828 | Assert.notNull(replacement, "Replacement must not be null");
|
1829 |
| - return replace(query, replacement, options, (Class<T>) ClassUtils.getUserClass(replacement), collectionName); |
| 1829 | + return replace(query, (Class<T>) ClassUtils.getUserClass(replacement), replacement, options, collectionName); |
1830 | 1830 | }
|
1831 | 1831 |
|
1832 | 1832 | /**
|
1833 |
| - * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to |
1834 |
| - * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document |
1835 |
| - * taking {@link ReplaceOptions} into account.<br /> |
1836 |
| - * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}. |
| 1833 | + * Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} |
| 1834 | + * document taking {@link ReplaceOptions} into account. |
1837 | 1835 | *
|
1838 |
| - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional |
1839 |
| - * fields specification. Must not be {@literal null}. |
1840 |
| - * @param replacement the replacement document. Must not be {@literal null}. |
1841 |
| - * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. |
| 1836 | + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record. The query may |
| 1837 | + * contain an index {@link Query#withHint(String) hint} or the {@link Query#collation(Collation) collation} |
| 1838 | + * to use. Must not be {@literal null}. |
1842 | 1839 | * @param entityType the type used for mapping the {@link Query} to domain type fields and deriving the collection
|
| 1840 | + * @param replacement the replacement document. Must not be {@literal null}. |
| 1841 | + * @param options the {@link ReplaceOptions} holding additional information. Must not be {@literal null}. |
1843 | 1842 | * from. Must not be {@literal null}.
|
1844 | 1843 | * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
|
1845 | 1844 | * @throws org.springframework.data.mapping.MappingException if the collection name cannot be
|
1846 | 1845 | * {@link #getCollectionName(Class) derived} from the given replacement value.
|
| 1846 | + * @since 4.2 |
1847 | 1847 | */
|
1848 |
| - default <S> UpdateResult replace(Query query, S replacement, ReplaceOptions options, Class<S> entityType) { |
1849 |
| - |
1850 |
| - return replace(query, replacement, options, entityType, getCollectionName(ClassUtils.getUserClass(entityType))); |
| 1848 | + default <S,T> UpdateResult replace(Query query, Class<S> entityType, T replacement, ReplaceOptions options) { |
| 1849 | + return replace(query, entityType, replacement, options, getCollectionName(ClassUtils.getUserClass(entityType))); |
1851 | 1850 | }
|
1852 | 1851 |
|
1853 | 1852 | /**
|
1854 |
| - * Triggers <a href="https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/">replaceOne</a> to |
1855 |
| - * replace a single document matching {@link Criteria} of given {@link Query} with the {@code replacement} document |
1856 |
| - * taking {@link ReplaceOptions} into account.<br /> |
1857 |
| - * <strong>NOTE:</strong> The replacement entity must not hold an {@literal id}. |
| 1853 | + * Replace a single document matching the {@link Criteria} of given {@link Query} with the {@code replacement} |
| 1854 | + * document taking {@link ReplaceOptions} into account. |
1858 | 1855 | *
|
1859 |
| - * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record and also an optional |
1860 |
| - * fields specification. Must not be {@literal null}. |
1861 |
| - * @param replacement the replacement document. Must not be {@literal null}. |
1862 |
| - * @param options the {@link FindAndModifyOptions} holding additional information. Must not be {@literal null}. |
| 1856 | + * @param query the {@link Query} class that specifies the {@link Criteria} used to find a record. The query may |
| 1857 | + * contain an index {@link Query#withHint(String) hint} or the {@link Query#collation(Collation) collation} |
| 1858 | + * to use. Must not be {@literal null}. |
1863 | 1859 | * @param entityType the type used for mapping the {@link Query} to domain type fields. Must not be {@literal null}.
|
| 1860 | + * @param replacement the replacement document. Must not be {@literal null}. |
| 1861 | + * @param options the {@link ReplaceOptions} holding additional information. Must not be {@literal null}. |
1864 | 1862 | * @param collectionName the collection to query. Must not be {@literal null}.
|
1865 | 1863 | * @return the {@link UpdateResult} which lets you access the results of the previous replacement.
|
1866 |
| - * @throws org.springframework.data.mapping.MappingException if the collection name cannot be |
1867 |
| - * {@link #getCollectionName(Class) derived} from the given replacement value. |
| 1864 | + * @since 4.2 |
1868 | 1865 | */
|
1869 |
| - <S> UpdateResult replace(Query query, S replacement, ReplaceOptions options, Class<S> entityType, |
| 1866 | + <S,T> UpdateResult replace(Query query, Class<S> entityType, T replacement, ReplaceOptions options, |
1870 | 1867 | String collectionName);
|
1871 | 1868 |
|
1872 | 1869 | /**
|
|
0 commit comments