DATAMONGO-443 - Upgraded to Querydsl 2.5.0.

Updated repository implementation and support classes to use Google Guava API instead of Commons Collections introduced in Querydsl 2.5.0.
This commit is contained in:
Oliver Gierke
2012-05-07 14:26:22 +02:00
parent cf131aaa7e
commit 7162677992
5 changed files with 81 additions and 20 deletions

View File

@@ -13,7 +13,7 @@
<properties>
<mongo.version>2.7.1</mongo.version>
<querydsl.version>2.3.2</querydsl.version>
<querydsl.version>2.5.0</querydsl.version>
<cdi.version>1.0</cdi.version>
<validation.version>1.0.0.GA</validation.version>
<webbeans.version>1.1.3</webbeans.version>

View File

@@ -19,7 +19,6 @@ import java.io.Serializable;
import java.util.List;
import java.util.regex.Pattern;
import org.apache.commons.collections15.Transformer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
@@ -38,7 +37,6 @@ import org.springframework.data.querydsl.SimpleEntityPathResolver;
import org.springframework.data.repository.core.EntityMetadata;
import org.springframework.util.Assert;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mysema.query.mongodb.MongodbQuery;
import com.mysema.query.mongodb.MongodbSerializer;
@@ -164,13 +162,9 @@ public class QueryDslMongoRepository<T, ID extends Serializable> extends SimpleM
*/
private MongodbQuery<T> createQueryFor(Predicate predicate) {
DBCollection collection = getMongoOperations().getCollection(getEntityInformation().getCollectionName());
MongodbQuery<T> query = new MongodbQuery<T>(collection, new Transformer<DBObject, T>() {
public T transform(DBObject input) {
Class<T> type = getEntityInformation().getJavaType();
return getMongoOperations().getConverter().read(type, input);
}
}, serializer);
Class<T> domainType = getEntityInformation().getJavaType();
MongodbQuery<T> query = new SpringDataMongodbQuery<T>(getMongoOperations(), serializer, domainType);
return query.where(predicate);
}

View File

@@ -15,14 +15,11 @@
*/
package org.springframework.data.mongodb.repository.support;
import org.apache.commons.collections15.Transformer;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.util.Assert;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mysema.query.mongodb.MongodbQuery;
import com.mysema.query.mongodb.MongodbSerializer;
import com.mysema.query.types.EntityPath;
@@ -75,11 +72,6 @@ public abstract class QuerydslRepositorySupport {
Assert.notNull(path);
Assert.hasText(collection);
DBCollection dbCollection = template.getCollection(collection);
return new MongodbQuery<T>(dbCollection, new Transformer<DBObject, T>() {
public T transform(DBObject input) {
return template.getConverter().read(path.getType(), input);
}
}, serializer);
return new SpringDataMongodbQuery<T>(template, serializer, path.getType(), collection);
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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.repository.support;
import org.springframework.data.mongodb.core.MongoOperations;
import com.google.common.base.Function;
import com.mongodb.DBCollection;
import com.mongodb.DBObject;
import com.mysema.query.mongodb.MongodbQuery;
import com.mysema.query.mongodb.MongodbSerializer;
/**
* Spring Data specfic {@link MongodbQuery} implementation.
*
* @author Oliver Gierke
*/
class SpringDataMongodbQuery<T> extends MongodbQuery<T> {
private final MongoOperations operations;
/**
* Creates a new {@link SpringDataMongodbQuery}.
*
* @param operations must not be {@literal null}.
* @param serializer must not be {@literal null}.
* @param type must not be {@literal null}.
*/
public SpringDataMongodbQuery(final MongoOperations operations, final MongodbSerializer serializer,
final Class<? extends T> type) {
this(operations, serializer, type, operations.getCollectionName(type));
}
/**
* Creates a new {@link SpringDataMongodbQuery} to query the given collection.
*
* @param operations must not be {@literal null}.
* @param serializer must not be {@literal null}.
* @param type must not be {@literal null}.
* @param collectionName must not be {@literal null} or empty.
*/
public SpringDataMongodbQuery(final MongoOperations operations, final MongodbSerializer serializer,
final Class<? extends T> type, String collectionName) {
super(operations.getCollection(collectionName), new Function<DBObject, T>() {
public T apply(DBObject input) {
return operations.getConverter().read(type, input);
}
}, serializer);
this.operations = operations;
}
/*
* (non-Javadoc)
* @see com.mysema.query.mongodb.MongodbQuery#getCollection(java.lang.Class)
*/
@Override
protected DBCollection getCollection(Class<?> type) {
return operations.getCollection(operations.getCollectionName(type));
}
}

View File

@@ -7,6 +7,7 @@ Import-Package:
Export-Template:
org.springframework.data.mongodb.*;version="${project.version}"
Import-Template:
com.google.common.base.*;version="[11.0.0,12.0.0)";resolution:=optional,
com.mongodb.*;version="0",
com.mysema.query.*;version="[2.1.1, 3.0.0)";resolution:=optional,
javax.annotation.processing.*;version="0",
@@ -14,7 +15,6 @@ Import-Template:
javax.tools.*;version="0",
javax.validation.*;version="${validation.version:[=.=.=.=,+1.0.0)}";resolution:=optional,
org.aopalliance.*;version="[1.0.0, 2.0.0)";resolution:=optional,
org.apache.commons.collections15.*;version="[4.0.0,5.0.0)";resolution:=optional,
org.bson.*;version="0",
org.slf4j.*;version="${org.slf4j.version:[=.=.=,+1.0.0)}",
org.springframework.*;version="${org.springframework.version.30:[=.=.=.=,+1.0.0)}",