INT-4173 Add Query support for Mongo i-c-adapter

JIRA: https://jira.spring.io/browse/INT-4173

INT-4173 convert query-expression to BasicQuery - fix checkstyle violation

INT-4173 convert query-expression to BasicQuery - refactor. address CR comments

INT-4173 convert query-expression to BasicQuery - UT coverage, xsd attribute documentation

INT-4173 cr comments, refactoring, register mongo api package for int-mongo:inbound-channel-adapter query-expression

INT-4173: Documentation, address PR comments & checkstyle violations

Polishing code style and imports order

**Cherry-pick to 4.3.x**

Conflicts:
	spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/inbound/MongoDbMessageSourceTests.java
This commit is contained in:
Yaron Yamin
2016-12-06 00:25:27 +02:00
committed by Artem Bilan
parent fa0ba9b84e
commit e7f93b9e0b
8 changed files with 201 additions and 55 deletions

View File

@@ -25,8 +25,10 @@ import org.springframework.data.mongodb.core.convert.MongoConverter;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.expression.Expression;
import org.springframework.expression.TypeLocator;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.expression.spel.support.StandardTypeLocator;
import org.springframework.integration.context.IntegrationObjectSupport;
import org.springframework.integration.core.MessageSource;
import org.springframework.integration.expression.ExpressionUtils;
@@ -55,11 +57,12 @@ import com.mongodb.DBObject;
*
* @author Amol Nayak
* @author Oleg Zhurakousky
* @author Yaron Yamin
*
* @since 2.2
*/
public class MongoDbMessageSource extends IntegrationObjectSupport
implements MessageSource<Object> {
implements MessageSource<Object> {
private final Expression queryExpression;
@@ -84,7 +87,6 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
* which should resolve to a MongoDb 'query' string
* (see http://www.mongodb.org/display/DOCS/Querying).
* The 'queryExpression' will be evaluated on every call to the {@link #receive()} method.
*
* @param mongoDbFactory The mongodb factory.
* @param queryExpression The query expression.
*/
@@ -102,7 +104,6 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
* (see http://www.mongodb.org/display/DOCS/Querying).
* It assumes that the {@link MongoOperations} is fully initialized and ready to be used.
* The 'queryExpression' will be evaluated on every call to the {@link #receive()} method.
*
* @param mongoTemplate The mongo template.
* @param queryExpression The query expression.
*/
@@ -119,7 +120,6 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
* {@link MongoTemplate#find(Query, Class)} or {@link MongoTemplate#findOne(Query, Class)}
* method.
* Default is {@link DBObject}.
*
* @param entityClass The entity class.
*/
public void setEntityClass(Class<?> entityClass) {
@@ -134,7 +134,6 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
* {@link #receive()} will use {@link MongoTemplate#findOne(Query, Class)},
* and the payload of the returned {@link Message} will be the returned target Object of type
* identified by {{@link #entityClass} instead of a List.
*
* @param expectSingleResult true if a single result is expected.
*/
public void setExpectSingleResult(boolean expectSingleResult) {
@@ -145,7 +144,6 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
* Sets the SpEL {@link Expression} that should resolve to a collection name
* used by the {@link Query}. The resulting collection name will be included
* in the {@link MongoHeaders#COLLECTION_NAME} header.
*
* @param collectionNameExpression The collection name expression.
*/
public void setCollectionNameExpression(Expression collectionNameExpression) {
@@ -157,7 +155,6 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
* Allows you to provide a custom {@link MongoConverter} used to assist in deserialization
* data read from MongoDb. Only allowed if this instance was constructed with a
* {@link MongoDbFactory}.
*
* @param mongoConverter The mongo converter.
*/
public void setMongoConverter(MongoConverter mongoConverter) {
@@ -174,8 +171,12 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
@Override
protected void onInit() throws Exception {
this.evaluationContext =
ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
TypeLocator typeLocator = this.evaluationContext.getTypeLocator();
if (typeLocator instanceof StandardTypeLocator) {
//Register MongoDB query API package so FQCN can be avoided in query-expression.
((StandardTypeLocator) typeLocator).registerImport("org.springframework.data.mongodb.core.query");
}
if (this.mongoTemplate == null) {
this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter);
}
@@ -194,7 +195,20 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
public Message<Object> receive() {
Assert.isTrue(this.initialized, "This class is not yet initialized. Invoke its afterPropertiesSet() method");
Message<Object> message = null;
Query query = new BasicQuery(this.queryExpression.getValue(this.evaluationContext, String.class));
Object value = this.queryExpression.getValue(this.evaluationContext);
Assert.notNull(value, "'queryExpression' must not evaluate to null");
Query query;
if (value instanceof String) {
query = new BasicQuery((String) value);
}
else if (value instanceof Query) {
query = ((Query) value);
}
else {
throw new IllegalStateException("'queryExpression' must evaluate to String " +
"or org.springframework.data.mongodb.core.query.Query");
}
Assert.notNull(query, "'queryExpression' must not evaluate to null");
String collectionName = this.collectionNameExpression.getValue(this.evaluationContext, String.class);
Assert.notNull(collectionName, "'collectionNameExpression' must not evaluate to null");
@@ -225,4 +239,5 @@ public class MongoDbMessageSource extends IntegrationObjectSupport
return message;
}
}

View File

@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.springframework.org/schema/integration/mongodb"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:integration="http://www.springframework.org/schema/integration"
targetNamespace="http://www.springframework.org/schema/integration/mongodb"
elementFormDefault="qualified" attributeFormDefault="unqualified">
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:integration="http://www.springframework.org/schema/integration"
targetNamespace="http://www.springframework.org/schema/integration/mongodb"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:import namespace="http://www.springframework.org/schema/beans" />
<xsd:import namespace="http://www.springframework.org/schema/integration"
@@ -45,9 +45,8 @@
<xsd:attribute name="query-expression" type="xsd:string">
<xsd:annotation>
<xsd:documentation>
SpEL expression which should resolve to a
String value identifying the
MongoDb Query. Also see 'query' attribute
SpEL expression which should resolve to a String query (please refer to the 'query' attribute),
or to an instance of MongoDb Query (e.q., query-expression="new BasicQuery('{''name'' : ''Bob''}').limit(2)").
This attribute is mutually exclusive with 'query' attribute.
</xsd:documentation>
</xsd:annotation>

View File

@@ -48,6 +48,25 @@
auto-startup="false">
<int:poller fixed-rate="5000" />
</int-mongodb:inbound-channel-adapter>
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithStringQueryExpression"
channel="replyChannel"
collection-name="foo"
mongo-template="mongoDbTemplate"
query-expression="new String('{''name'' : ''Bob''}')"
entity-class="java.lang.Object"
auto-startup="false">
<int:poller fixed-rate="5000" />
</int-mongodb:inbound-channel-adapter>
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithQueryExpression"
channel="replyChannel"
collection-name="foo"
mongo-template="mongoDbTemplate"
query-expression="new BasicQuery('{''name'' : ''Bob''}').limit(1)"
entity-class="java.lang.Object"
auto-startup="false">
<int:poller fixed-rate="5000" />
</int-mongodb:inbound-channel-adapter>
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapterWithNamedCollectionExpression"
channel="replyChannel"

View File

@@ -51,6 +51,7 @@ import com.mongodb.util.JSON;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Yaron Yamin
* @since 2.2
*/
@ContextConfiguration
@@ -80,6 +81,14 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
@Qualifier("mongoInboundAdapterWithNamedCollection")
private SourcePollingChannelAdapter mongoInboundAdapterWithNamedCollection;
@Autowired
@Qualifier("mongoInboundAdapterWithQueryExpression")
private SourcePollingChannelAdapter mongoInboundAdapterWithQueryExpression;
@Autowired
@Qualifier("mongoInboundAdapterWithStringQueryExpression")
private SourcePollingChannelAdapter mongoInboundAdapterWithStringQueryExpression;
@Autowired
@Qualifier("mongoInboundAdapterWithNamedCollectionExpression")
private SourcePollingChannelAdapter mongoInboundAdapterWithNamedCollectionExpression;
@@ -152,6 +161,30 @@ public class MongoDbInboundChannelAdapterIntegrationTests extends MongoDbAvailab
this.mongoInboundAdapterWithNamedCollection.stop();
}
@Test
@MongoDbAvailable
public void testWithQueryExpression() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoInboundAdapterWithQueryExpression.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals(1, message.getPayload().size());
assertEquals("Bob", message.getPayload().get(0).getName());
this.mongoInboundAdapterWithQueryExpression.stop();
}
@Test
@MongoDbAvailable
public void testWithStringQueryExpression() throws Exception {
this.mongoTemplate.save(this.createPerson("Bob"), "foo");
this.mongoInboundAdapterWithStringQueryExpression.start();
@SuppressWarnings("unchecked")
Message<List<Person>> message = (Message<List<Person>>) replyChannel.receive(10000);
assertNotNull(message);
assertEquals("Bob", message.getPayload().get(0).getName());
this.mongoInboundAdapterWithStringQueryExpression.stop();
}
@Test
@MongoDbAvailable

View File

@@ -1,11 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
xmlns:mongo="http://www.springframework.org/schema/data/mongo"
xsi:schemaLocation="http://www.springframework.org/schema/data/mongo http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-mongodb="http://www.springframework.org/schema/integration/mongodb"
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration/mongodb http://www.springframework.org/schema/integration/mongodb/spring-integration-mongodb.xsd">
@@ -28,6 +26,33 @@
<int:poller fixed-rate="100"/>
</int-mongodb:inbound-channel-adapter>
<int-mongodb:inbound-channel-adapter id="fullConfigWithQueryExpression"
collection-name-expression="'foo'"
query-expression="new BasicQuery('{''address.state'' : ''PA''}').limit(2)"
mongo-converter="mongoConverter"
mongodb-factory="mongoDbFactory"
auto-startup="false">
<int:poller fixed-rate="100"/>
</int-mongodb:inbound-channel-adapter>
<int-mongodb:inbound-channel-adapter id="fullConfigWithSpelQuery"
collection-name-expression="'foo'"
query="{''address.state'' : ''PA''}"
mongo-converter="mongoConverter"
mongodb-factory="mongoDbFactory"
auto-startup="false">
<int:poller fixed-rate="100"/>
</int-mongodb:inbound-channel-adapter>
<int-mongodb:inbound-channel-adapter id="fullConfigWithQuery"
collection-name-expression="'foo'"
query="{'address.state' : 'PA'}"
mongo-converter="mongoConverter"
mongodb-factory="mongoDbFactory"
auto-startup="false">
<int:poller fixed-rate="100"/>
</int-mongodb:inbound-channel-adapter>
<int-mongodb:inbound-channel-adapter id="fullConfigWithCollectionName"
collection-name="foo"
query="bar"

View File

@@ -23,7 +23,6 @@ import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
@@ -44,6 +43,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Artem Bilan
* @author Yaron Yamin
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -67,6 +67,18 @@ public class MongoDbInboundChannelAdapterParserTests {
@Qualifier("fullConfigWithCollectionExpression.adapter")
private SourcePollingChannelAdapter fullConfigWithCollectionExpressionAdapter;
@Autowired
@Qualifier("fullConfigWithQueryExpression.adapter")
private SourcePollingChannelAdapter fullConfigWithQueryExpressionAdapter;
@Autowired
@Qualifier("fullConfigWithQuery.adapter")
private SourcePollingChannelAdapter fullConfigWithQueryAdapter;
@Autowired
@Qualifier("fullConfigWithSpelQuery.adapter")
private SourcePollingChannelAdapter fullConfigWithSpelQueryAdapter;
@Autowired
@Qualifier("fullConfigWithCollectionName.adapter")
private SourcePollingChannelAdapter fullConfigWithCollectionNameAdapter;
@@ -90,28 +102,36 @@ public class MongoDbInboundChannelAdapterParserTests {
@Test
public void fullConfigWithCollectionExpression() {
MongoDbMessageSource source = TestUtils.getPropertyValue(this.fullConfigWithCollectionExpressionAdapter,
"source", MongoDbMessageSource.class);
assertEquals(false, TestUtils.getPropertyValue(this.fullConfigWithCollectionExpressionAdapter, "shouldTrack"));
assertNotNull(TestUtils.getPropertyValue(source, "mongoTemplate"));
assertEquals(this.mongoDbFactory, TestUtils.getPropertyValue(source, "mongoDbFactory"));
assertEquals(this.mongoConverter, TestUtils.getPropertyValue(source, "mongoConverter"));
assertNotNull(TestUtils.getPropertyValue(source, "evaluationContext"));
MongoDbMessageSource source = assertMongoDbMessageSource(this.fullConfigWithCollectionExpressionAdapter);
assertTrue(TestUtils.getPropertyValue(source, "collectionNameExpression") instanceof SpelExpression);
assertEquals("'foo'", TestUtils.getPropertyValue(source, "collectionNameExpression.expression"));
}
@Test
public void fullConfigWithCollectionName() {
MongoDbMessageSource source = TestUtils.getPropertyValue(this.fullConfigWithCollectionNameAdapter, "source",
MongoDbMessageSource.class);
public void fullConfigWithQueryExpression() {
MongoDbMessageSource source = assertMongoDbMessageSource(this.fullConfigWithQueryExpressionAdapter);
assertTrue(TestUtils.getPropertyValue(source, "queryExpression") instanceof SpelExpression);
assertEquals("new BasicQuery('{''address.state'' : ''PA''}').limit(2)",
TestUtils.getPropertyValue(source, "queryExpression.expression"));
}
assertEquals(false, TestUtils.getPropertyValue(this.fullConfigWithCollectionNameAdapter, "shouldTrack"));
assertNotNull(TestUtils.getPropertyValue(source, "mongoTemplate"));
assertEquals(this.mongoDbFactory, TestUtils.getPropertyValue(source, "mongoDbFactory"));
assertEquals(this.mongoConverter, TestUtils.getPropertyValue(source, "mongoConverter"));
assertNotNull(TestUtils.getPropertyValue(source, "evaluationContext"));
@Test
public void fullConfigWithSpelQuery() {
MongoDbMessageSource source = assertMongoDbMessageSource(this.fullConfigWithSpelQueryAdapter);
assertTrue(TestUtils.getPropertyValue(source, "queryExpression") instanceof LiteralExpression);
assertEquals("{''address.state'' : ''PA''}", TestUtils.getPropertyValue(source, "queryExpression.literalValue"));
}
@Test
public void fullConfigWithQuery() {
MongoDbMessageSource source = assertMongoDbMessageSource(this.fullConfigWithQueryAdapter);
assertTrue(TestUtils.getPropertyValue(source, "queryExpression") instanceof LiteralExpression);
assertEquals("{'address.state' : 'PA'}", TestUtils.getPropertyValue(source, "queryExpression.literalValue"));
}
@Test
public void fullConfigWithCollectionName() {
MongoDbMessageSource source = assertMongoDbMessageSource(this.fullConfigWithCollectionNameAdapter);
assertTrue(TestUtils.getPropertyValue(source, "collectionNameExpression") instanceof LiteralExpression);
assertEquals("foo", TestUtils.getPropertyValue(source, "collectionNameExpression.literalValue"));
}
@@ -141,4 +161,15 @@ public class MongoDbInboundChannelAdapterParserTests {
.close();
}
private MongoDbMessageSource assertMongoDbMessageSource(Object testedBean) {
MongoDbMessageSource source = TestUtils.getPropertyValue(testedBean, "source", MongoDbMessageSource.class);
assertEquals(false, TestUtils.getPropertyValue(testedBean, "shouldTrack"));
assertNotNull(TestUtils.getPropertyValue(source, "mongoTemplate"));
assertEquals(this.mongoDbFactory, TestUtils.getPropertyValue(source, "mongoDbFactory"));
assertEquals(this.mongoConverter, TestUtils.getPropertyValue(source, "mongoConverter"));
assertNotNull(TestUtils.getPropertyValue(source, "evaluationContext"));
return source;
}
}

View File

@@ -36,6 +36,7 @@ import org.springframework.data.mongodb.core.convert.MappingMongoConverter;
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.expression.Expression;
import org.springframework.expression.common.LiteralExpression;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.integration.mongodb.rules.MongoDbAvailable;
import org.springframework.integration.mongodb.rules.MongoDbAvailableTests;
@@ -46,11 +47,13 @@ import com.mongodb.util.JSON;
* @author Amol Nayak
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Yaron Yamin
*
* @since 2.2
*
*/
public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
/**
* Tests by providing a null MongoDB Factory
*
@@ -75,7 +78,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
@Test
@MongoDbAvailable
public void validateSuccessfullQueryWithSinigleElementIfOneInListAsDbObject() throws Exception {
public void validateSuccessfulQueryWithSingleElementIfOneInListAsDbObject() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
@@ -96,7 +99,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
@Test
@MongoDbAvailable
public void validateSuccessfullQueryWithSinigleElementIfOneInList() throws Exception {
public void validateSuccessfulQueryWithSingleElementIfOneInList() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
@@ -118,7 +121,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
@Test
@MongoDbAvailable
public void validateSuccessfullQueryWithSinigleElementIfOneInListAndSingleResult() throws Exception {
public void validateSuccessfulQueryWithSingleElementIfOneInListAndSingleResult() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
@@ -140,7 +143,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
@Test
@MongoDbAvailable
public void validateSuccessfullSubObjectQueryWithSinigleElementIfOneInList() throws Exception {
public void validateSuccessfulSubObjectQueryWithSingleElementIfOneInList() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
@@ -161,8 +164,29 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
@Test
@MongoDbAvailable
public void validateSuccessfullQueryWithMultipleElements() throws Exception {
public void validateSuccessfulQueryWithMultipleElements() throws Exception {
List<Person> persons = queryMultipleElements(new LiteralExpression("{'address.state' : 'PA'}"));
assertEquals(3, persons.size());
}
@Test
@MongoDbAvailable
public void validateSuccessfulStringQueryExpressionWithMultipleElements() throws Exception {
List<Person> persons = queryMultipleElements(new SpelExpressionParser()
.parseExpression("\"{'address.state' : 'PA'}\""));
assertEquals(3, persons.size());
}
@Test
@MongoDbAvailable
public void validateSuccessfulBasicQueryExpressionWithMultipleElements() throws Exception {
List<Person> persons = queryMultipleElements(new SpelExpressionParser()
.parseExpression("new BasicQuery(\"{'address.state' : 'PA'}\").limit(2)"));
assertEquals(2, persons.size());
}
@SuppressWarnings("unchecked")
private List<Person> queryMultipleElements(Expression queryExpression) throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
@@ -170,18 +194,16 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
template.save(this.createPerson("Moe"), "data");
template.save(this.createPerson("Jack"), "data");
Expression queryExpression = new LiteralExpression("{'address.state' : 'PA'}");
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
@SuppressWarnings("unchecked")
List<Person> persons = (List<Person>) messageSource.receive().getPayload();
assertEquals(3, persons.size());
return (List<Person>) messageSource.receive().getPayload();
}
@Test
@MongoDbAvailable
public void validateSuccessfullQueryWithNullReturn() throws Exception {
public void validateSuccessfulQueryWithNullReturn() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
@@ -200,7 +222,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
@SuppressWarnings("unchecked")
@Test
@MongoDbAvailable
public void validateSuccessfullQueryWithCustomConverter() throws Exception {
public void validateSuccessfulQueryWithCustomConverter() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
@@ -226,7 +248,7 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
@SuppressWarnings("unchecked")
@Test
@MongoDbAvailable
public void validateSuccessfullQueryWithMongoTemplate() throws Exception {
public void validateSuccessfulQueryWithMongoTemplate() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
@@ -272,4 +294,5 @@ public class MongoDbMessageSourceTests extends MongoDbAvailableTests {
result = (DBObject) messageSource.receive().getPayload();
assertEquals(id, result.get("_id"));
}
}

View File

@@ -190,7 +190,8 @@ The _MongoDb Inbound Channel Adapter_ is a polling consumer that reads data from
As you can see from the configuration above, you configure a _MongoDb Inbound Channel Adapter_ using the `inbound-channel-adapter` element, providing values for various attributes such as:
* `query` or `query-expression` - a JSON query (see http://www.mongodb.org/display/DOCS/Querying[MongoDb Querying])
* `query` - a JSON query (see http://www.mongodb.org/display/DOCS/Querying[MongoDb Querying])
* `query-expression` - A SpEL expression that is evaluated to a JSON query String (as the `query` attribute above), or to an instance of `o.s.data.mongodb.core.query.Query`. Mutually exclusive with `query` attribute.
* `entity-class` - the type of the payload object; if not supplied, a `com.mongodb.DBObject` will be returned.
* `collection-name` or `collection-name-expression` - Identifies the name of the MongoDb collection to use.
* `mongodb-factory` - reference to an instance of `o.s.data.mongodb.MongoDbFactory`
@@ -214,7 +215,7 @@ You can do this using Transaction Synchronization feature that was added with Sp
----
<int-mongodb:inbound-channel-adapter id="mongoInboundAdapter"
channel="replyChannel"
query="{'name' : 'Bob'}"
query-expression="new BasicQuery('{''name'' : ''Bob''}').limit(100)"
entity-class="java.lang.Object"
auto-startup="false">
<int:poller fixed-rate="200" max-messages-per-poll="1">