Skip to content

DATAMONGO-1176 - Add support for reactive data access. #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
189d4dd
DATAMONGO-1514 - SpringDataMongodbQuery needs to be public.
LinkedList Oct 27, 2016
cb90bfc
DATAMONGO-1514 - Polishing.
odrotbohm Oct 27, 2016
f782338
DATAMONGO-1513 - Fixed identifier population for event listener gener…
odrotbohm Oct 30, 2016
9c20da3
DATAMONGO-1504 - Assert compatibility with MongoDB 3.4.
christophstrobl Oct 5, 2016
2ae75a4
DATAMONGO-1500 - Fix JSON serialization error in derived queries with…
christophstrobl Nov 2, 2016
6a9823f
DATAMONGO-1521 - Added Aggregation.skip(…) overload to support longs.
odrotbohm Nov 3, 2016
255d325
DATAMONGO-1502 - Updated changelog.
odrotbohm Nov 3, 2016
ea9b402
DATAMONGO-1525 - Improved creation of empty collections, esp. EnumSet.
odrotbohm Nov 7, 2016
da5289f
DATAMONGO-1448 - Prepare 2.0 development.
mp911de Jun 9, 2016
4371760
DATAMONGO-1461 - Upgrade Hibernate/Validator/JPA dependencies to matc…
mp911de Jul 12, 2016
30b7b40
DATAMONGO-1176 - Switch to new mongo-java-driver API.
christophstrobl Apr 5, 2016
96eb2b3
DATAMONGO-1176 - Switch to Document API.
christophstrobl Apr 4, 2016
ac9e9ea
DATAMONGO-1176 - Polishing.
mp911de Jun 13, 2016
b9e02b2
DATAMONGO-1176 - Cleanup.
christophstrobl Oct 28, 2016
5610077
DATAMONGO-1176 - Cleanup.
mp911de Nov 3, 2016
4732e2a
DATAMONGO-1176 - Test code cleanup.
mp911de Nov 4, 2016
c5ac30d
DATAMONGO-1444 - Investigate reactive support in Spring Data MongoDB.
mp911de Jun 1, 2016
e021678
DATAMONGO-1444 - Add support for RxJava wrapper types and slice queries.
mp911de Mar 3, 2016
0f96a88
DATAMONGO-1444 - Polishing.
christophstrobl Oct 28, 2016
9ab9621
DATAMONGO-1444 - Adopt changes in Spring Data Commons.
christophstrobl Nov 7, 2016
8f75faf
DATAMONGO-1444 - Update bulk insert operations.
christophstrobl Nov 7, 2016
0711607
DATAMONGO-1444 - Make Project Reactor dependency no longer required f…
mp911de Nov 8, 2016
d69cbda
DATAMONGO-1444 - Polishing.
odrotbohm Nov 13, 2016
1c77a64
DATAMONGO-1444 - Adapt to new changes in reactive repository configur…
odrotbohm Nov 14, 2016
d952a65
DATAMONGO-1444 - Moved to new base class for reactive repository fact…
odrotbohm Nov 14, 2016
655dea4
DATAMONGO-1444 - Accept Collection and subtypes in ReactiveMongoOpera…
mp911de Nov 14, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ before_script:
env:
matrix:
- PROFILE=ci
- PROFILE=mongo-next
- PROFILE=mongo3
- PROFILE=mongo3-next
- PROFILE=mongo31
- PROFILE=mongo32
- PROFILE=mongo33
- PROFILE=mongo34-next

# Current MongoDB version is 2.4.2 as of 2016-04, see https://github.com/travis-ci/travis-ci/issues/3694
# apt-get starts a MongoDB instance so it's not started using before_script
Expand Down
53 changes: 32 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1444-SNAPSHOT</version>
<packaging>pom</packaging>

<name>Spring Data MongoDB</name>
Expand All @@ -15,7 +15,7 @@
<parent>
<groupId>org.springframework.data.build</groupId>
<artifactId>spring-data-parent</artifactId>
<version>1.9.0.BUILD-SNAPSHOT</version>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>

<modules>
Expand All @@ -28,9 +28,9 @@
<properties>
<project.type>multi</project.type>
<dist.id>spring-data-mongodb</dist.id>
<springdata.commons>1.13.0.BUILD-SNAPSHOT</springdata.commons>
<mongo>2.14.3</mongo>
<mongo.osgi>2.13.0</mongo.osgi>
<springdata.commons>2.0.0.DATACMNS-836-SNAPSHOT</springdata.commons>
<mongo>3.2.2</mongo>
<mongo.reactivestreams>1.2.0</mongo.reactivestreams>
</properties>

<developers>
Expand Down Expand Up @@ -100,25 +100,20 @@
</roles>
<timezone>+1</timezone>
</developer>
<developer>
<id>mpaluch</id>
<name>Mark Paluch</name>
<email>mpaluch at pivotal.io</email>
<organization>Pivotal</organization>
<organizationUrl>http://www.pivotal.io</organizationUrl>
<roles>
<role>Developer</role>
</roles>
<timezone>+1</timezone>
</developer>
</developers>

<profiles>
<profile>

<id>mongo-next</id>
<properties>
<mongo>2.15.0-SNAPSHOT</mongo>
</properties>

<repositories>
<repository>
<id>mongo-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>

</profile>

<profile>

<id>mongo3</id>
Expand Down Expand Up @@ -178,6 +173,22 @@

</profile>

<profile>

<id>mongo34-next</id>
<properties>
<mongo>3.4.0-SNAPSHOT</mongo>
</properties>

<repositories>
<repository>
<id>mongo-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>

</profile>

<profile>
<id>release</id>
<build>
Expand Down
18 changes: 13 additions & 5 deletions spring-data-mongodb-cross-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1444-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>spring-data-mongodb-cross-store</artifactId>
<name>Spring Data MongoDB - Cross-Store Support</name>

<properties>
<jpa>2.0.0</jpa>
<hibernate>3.6.10.Final</hibernate>
<jpa>2.1.1</jpa>
<hibernate>5.2.1.Final</hibernate>
</properties>

<dependencies>
Expand Down Expand Up @@ -48,7 +48,15 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1444-SNAPSHOT</version>
</dependency>

<!-- reactive -->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-core</artifactId>
<version>${reactor}</version>
<optional>true</optional>
</dependency>

<dependency>
Expand Down Expand Up @@ -87,7 +95,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.0.2.GA</version>
<version>5.2.4.Final</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import javax.persistence.EntityManagerFactory;

import org.bson.Document;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
Expand All @@ -29,10 +30,10 @@
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.util.ClassUtils;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mongodb.MongoException;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.model.Filters;
import com.mongodb.client.result.DeleteResult;

/**
* @author Thomas Risberg
Expand Down Expand Up @@ -74,15 +75,15 @@ public void getPersistentState(Class<? extends ChangeSetBacked> entityClass, Obj

String collName = getCollectionNameForEntity(entityClass);

final DBObject dbk = new BasicDBObject();
final Document dbk = new Document();
dbk.put(ENTITY_ID, id);
dbk.put(ENTITY_CLASS, entityClass.getName());
if (log.isDebugEnabled()) {
log.debug("Loading MongoDB data for {}", dbk);
}
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
for (DBObject dbo : collection.find(dbk)) {
public Object doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
for (Document dbo : collection.find(dbk)) {
String key = (String) dbo.get(ENTITY_FIELD_NAME);
if (log.isDebugEnabled()) {
log.debug("Processing key: {}", key);
Expand Down Expand Up @@ -143,27 +144,31 @@ public Object persistState(ChangeSetBacked entity, ChangeSet cs) throws DataAcce
for (String key : cs.getValues().keySet()) {
if (key != null && !key.startsWith("_") && !key.equals(ChangeSetPersister.ID_KEY)) {
Object value = cs.getValues().get(key);
final DBObject dbQuery = new BasicDBObject();
final Document dbQuery = new Document();
dbQuery.put(ENTITY_ID, getPersistentId(entity, cs));
dbQuery.put(ENTITY_CLASS, entity.getClass().getName());
dbQuery.put(ENTITY_FIELD_NAME, key);
DBObject dbId = mongoTemplate.execute(collName, new CollectionCallback<DBObject>() {
public DBObject doInCollection(DBCollection collection) throws MongoException, DataAccessException {
return collection.findOne(dbQuery);
final Document dbId = mongoTemplate.execute(collName, new CollectionCallback<Document>() {
public Document doInCollection(MongoCollection<Document> collection)
throws MongoException, DataAccessException {
Document id = collection.find(dbQuery).first();
return id;
}
});

if (value == null) {
if (log.isDebugEnabled()) {
log.debug("Flush: removing: {}", dbQuery);
}
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
collection.remove(dbQuery);
public Object doInCollection(MongoCollection<Document> collection)
throws MongoException, DataAccessException {
DeleteResult dr = collection.deleteMany(dbQuery);
return null;
}
});
} else {
final DBObject dbDoc = new BasicDBObject();
final Document dbDoc = new Document();
dbDoc.putAll(dbQuery);
if (log.isDebugEnabled()) {
log.debug("Flush: saving: {}", dbQuery);
Expand All @@ -174,8 +179,18 @@ public Object doInCollection(DBCollection collection) throws MongoException, Dat
dbDoc.put("_id", dbId.get("_id"));
}
mongoTemplate.execute(collName, new CollectionCallback<Object>() {
public Object doInCollection(DBCollection collection) throws MongoException, DataAccessException {
collection.save(dbDoc);
public Object doInCollection(MongoCollection<Document> collection)
throws MongoException, DataAccessException {

if (dbId != null) {
collection.replaceOne(Filters.eq("_id", dbId.get("_id")), dbDoc);
} else {

if (dbDoc.containsKey("_id") && dbDoc.get("_id") == null) {
dbDoc.remove("_id");
}
collection.insertOne(dbDoc);
}
return null;
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.bson.Document;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand All @@ -36,8 +37,6 @@
import org.springframework.transaction.support.TransactionCallback;
import org.springframework.transaction.support.TransactionTemplate;

import com.mongodb.DBObject;

/**
* Integration tests for MongoDB cross-store persistence (mainly {@link MongoChangeSetPersister}).
*
Expand All @@ -48,14 +47,11 @@
@ContextConfiguration("classpath:/META-INF/spring/applicationContext.xml")
public class CrossStoreMongoTests {

@Autowired
MongoTemplate mongoTemplate;
@Autowired MongoTemplate mongoTemplate;

@PersistenceContext
EntityManager entityManager;
@PersistenceContext EntityManager entityManager;

@Autowired
PlatformTransactionManager transactionManager;
@Autowired PlatformTransactionManager transactionManager;
TransactionTemplate txTemplate;

@Before
Expand Down Expand Up @@ -187,7 +183,7 @@ public Person doInTransaction(TransactionStatus status) {

boolean weFound3 = false;

for (DBObject dbo : this.mongoTemplate.getCollection(mongoTemplate.getCollectionName(Person.class)).find()) {
for (Document dbo : this.mongoTemplate.getCollection(mongoTemplate.getCollectionName(Person.class)).find()) {
Assert.assertTrue(!dbo.get("_entity_id").equals(2L));
if (dbo.get("_entity_id").equals(3L)) {
weFound3 = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<mongo:mapping-converter/>

<!-- Mongo config -->
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoFactoryBean">
<bean id="mongo" class="org.springframework.data.mongodb.core.MongoClientFactoryBean">
<property name="host" value="localhost"/>
<property name="port" value="27017"/>
</bean>
Expand Down
18 changes: 0 additions & 18 deletions spring-data-mongodb-cross-store/template.mf

This file was deleted.

2 changes: 1 addition & 1 deletion spring-data-mongodb-distribution/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1444-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion spring-data-mongodb-log4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-mongodb-parent</artifactId>
<version>1.10.0.BUILD-SNAPSHOT</version>
<version>2.0.0.DATAMONGO-1444-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 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.
Expand Down Expand Up @@ -30,13 +30,15 @@
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.Mongo;
import com.mongodb.MongoClient;
import com.mongodb.WriteConcern;

/**
* Log4j appender writing log entries into a MongoDB instance.
*
* @author Jon Brisbin
* @author Oliver Gierke
* @auhtor Christoph Strobl
*/
public class MongoLog4jAppender extends AppenderSkeleton {

Expand All @@ -58,8 +60,8 @@ public class MongoLog4jAppender extends AppenderSkeleton {
protected String collectionPattern = "%c";
protected PatternLayout collectionLayout = new PatternLayout(collectionPattern);
protected String applicationId = System.getProperty("APPLICATION_ID", null);
protected WriteConcern warnOrHigherWriteConcern = WriteConcern.SAFE;
protected WriteConcern infoOrLowerWriteConcern = WriteConcern.NORMAL;
protected WriteConcern warnOrHigherWriteConcern = WriteConcern.ACKNOWLEDGED;
protected WriteConcern infoOrLowerWriteConcern = WriteConcern.UNACKNOWLEDGED;
protected Mongo mongo;
protected DB db;

Expand Down Expand Up @@ -128,7 +130,7 @@ public void setInfoOrLowerWriteConcern(String wc) {
}

protected void connectToMongo() throws UnknownHostException {
this.mongo = new Mongo(host, port);
this.mongo = new MongoClient(host, port);
this.db = mongo.getDB(database);
}

Expand Down
Loading