Skip to content

Commit

Permalink
DATAMONGO-1679 - Adapt to API changes in repository interfaces.
Browse files Browse the repository at this point in the history
  • Loading branch information
odrotbohm committed May 3, 2017
1 parent 5d8370f commit e323859
Show file tree
Hide file tree
Showing 30 changed files with 459 additions and 581 deletions.
Expand Up @@ -422,7 +422,7 @@ protected Object convertSimpleOrDocument(Object source, MongoPersistentEntity<?>
return getMappedObject((BasicDBObject) source, entity);
}

if(source instanceof BsonValue) {
if (source instanceof BsonValue) {
return source;
}

Expand Down
Expand Up @@ -15,13 +15,14 @@
*/
package org.springframework.data.mongodb.core.query;

import lombok.EqualsAndHashCode;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.bson.Document;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

/**
* @author Thomas Risberg
Expand All @@ -30,6 +31,7 @@
* @author Christoph Strobl
* @author Mark Paluch
*/
@EqualsAndHashCode
public class Field {

private final Map<String, Integer> criteria = new HashMap<String, Integer>();
Expand Down Expand Up @@ -83,6 +85,7 @@ public Field position(String field, int value) {

public Document getFieldsObject() {

@SuppressWarnings({ "unchecked", "rawtypes" })
Document document = new Document((Map) criteria);

for (Entry<String, Object> entry : slices.entrySet()) {
Expand All @@ -99,58 +102,4 @@ public Document getFieldsObject() {

return document;
}

/*
* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object object) {

if (this == object) {
return true;
}

if (!(object instanceof Field)) {
return false;
}

Field that = (Field) object;

if (!this.criteria.equals(that.criteria)) {
return false;
}

if (!this.slices.equals(that.slices)) {
return false;
}

if (!this.elemMatchs.equals(that.elemMatchs)) {
return false;
}

boolean samePositionKey = this.postionKey == null ? that.postionKey == null
: this.postionKey.equals(that.postionKey);
boolean samePositionValue = this.positionValue == that.positionValue;

return samePositionKey && samePositionValue;
}

/*
* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {

int result = 17;

result += 31 * ObjectUtils.nullSafeHashCode(this.criteria);
result += 31 * ObjectUtils.nullSafeHashCode(this.elemMatchs);
result += 31 * ObjectUtils.nullSafeHashCode(this.slices);
result += 31 * ObjectUtils.nullSafeHashCode(this.postionKey);
result += 31 * ObjectUtils.nullSafeHashCode(this.positionValue);

return result;
}
}
Expand Up @@ -33,7 +33,6 @@
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.InvalidMongoDbApiUsageException;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;

/**
* @author Thomas Risberg
Expand All @@ -48,8 +47,8 @@ public class Query {

private final Set<Class<?>> restrictedTypes = new HashSet<Class<?>>();
private final Map<String, CriteriaDefinition> criteria = new LinkedHashMap<String, CriteriaDefinition>();
private Field fieldSpec;
private Sort sort;
private Field fieldSpec = null;
private Sort sort = Sort.unsorted();
private long skip;
private int limit;
private String hint;
Expand Down Expand Up @@ -103,9 +102,11 @@ public Query addCriteria(CriteriaDefinition criteriaDefinition) {
}

public Field fields() {
if (fieldSpec == null) {

if (this.fieldSpec == null) {
this.fieldSpec = new Field();
}

return this.fieldSpec;
}

Expand Down Expand Up @@ -170,22 +171,19 @@ public Query with(Pageable pageable) {
*/
public Query with(Sort sort) {

if (sort == null || ObjectUtils.nullSafeEquals(Sort.unsorted(), sort)) {
Assert.notNull(sort, "Sort must not be null!");

if (sort.isUnsorted()) {
return this;
}

for (Order order : sort) {
if (order.isIgnoreCase()) {
throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
+ "MongoDB does not support sorting ignoreing case currently!", order.getProperty()));
}
}
sort.stream().filter(Order::isIgnoreCase).findFirst().ifPresent(it -> {

if (this.sort == null) {
this.sort = sort;
} else {
this.sort = this.sort.and(sort);
}
throw new IllegalArgumentException(String.format("Given sort contained an Order for %s with ignore case! "
+ "MongoDB does not support sorting ignoring case currently!", it.getProperty()));
});

this.sort = this.sort.and(sort);

return this;
}
Expand Down Expand Up @@ -238,15 +236,14 @@ public Document getFieldsObject() {

public Document getSortObject() {

if (this.sort == null) {
if (this.sort.isUnsorted()) {
return null;
}

Document document = new Document();

for (org.springframework.data.domain.Sort.Order order : this.sort) {
document.put(order.getProperty(), order.isAscending() ? 1 : -1);
}
this.sort.stream()//
.forEach(order -> document.put(order.getProperty(), order.isAscending() ? 1 : -1));

return document;
}
Expand Down Expand Up @@ -440,7 +437,7 @@ protected boolean querySettingsEquals(Query that) {

boolean criteriaEqual = this.criteria.equals(that.criteria);
boolean fieldsEqual = nullSafeEquals(this.fieldSpec, that.fieldSpec);
boolean sortEqual = nullSafeEquals(this.sort, that.sort);
boolean sortEqual = this.sort.equals(that.sort);
boolean hintEqual = nullSafeEquals(this.hint, that.hint);
boolean skipEqual = this.skip == that.skip;
boolean limitEqual = this.limit == that.limit;
Expand Down
Expand Up @@ -38,10 +38,10 @@ public interface MongoRepository<T, ID extends Serializable>

/*
* (non-Javadoc)
* @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable)
* @see org.springframework.data.repository.CrudRepository#saveAll(java.lang.Iterable)
*/
@Override
<S extends T> List<S> save(Iterable<S> entites);
<S extends T> List<S> saveAll(Iterable<S> entites);

/*
* (non-Javadoc)
Expand All @@ -58,9 +58,9 @@ public interface MongoRepository<T, ID extends Serializable>
List<T> findAll(Sort sort);

/**
* Inserts the given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use
* the returned instance for further operations as the save operation might have changed the entity instance
* completely. Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
* Inserts the given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use the
* returned instance for further operations as the save operation might have changed the entity instance completely.
* Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
*
* @param entity must not be {@literal null}.
* @return the saved entity
Expand Down
Expand Up @@ -15,16 +15,14 @@
*/
package org.springframework.data.mongodb.repository;

import java.io.Serializable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import org.reactivestreams.Publisher;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.NoRepositoryBean;

import org.springframework.data.repository.reactive.ReactiveSortingRepository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/**
* Mongo specific {@link org.springframework.data.repository.Repository} interface with reactive support.
Expand All @@ -33,44 +31,46 @@
* @since 2.0
*/
@NoRepositoryBean
public interface ReactiveMongoRepository<T, ID extends Serializable> extends ReactiveSortingRepository<T, ID> {
public interface ReactiveMongoRepository<T, ID> extends ReactiveSortingRepository<T, ID> {

/**
* Inserts the given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use
* the returned instance for further operations as the save operation might have changed the entity instance
* completely. Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
* Inserts the given entity. Assumes the instance to be new to be able to apply insertion optimizations. Use the
* returned instance for further operations as the save operation might have changed the entity instance completely.
* Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
*
* @param entity must not be {@literal null}.
* @return the saved entity
*/
<S extends T> Mono<S> insert(S entity);

/**
* Inserts the given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use
* the returned instance for further operations as the save operation might have changed the entity instance
* completely. Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
* Inserts the given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use the
* returned instance for further operations as the save operation might have changed the entity instance completely.
* Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
*
* @param entities must not be {@literal null}.
* @return the saved entity
*/
<S extends T> Flux<S> insert(Iterable<S> entities);

/**
* Inserts the given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use
* the returned instance for further operations as the save operation might have changed the entity instance
* completely. Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
* Inserts the given entities. Assumes the instance to be new to be able to apply insertion optimizations. Use the
* returned instance for further operations as the save operation might have changed the entity instance completely.
* Prefer using {@link #save(Object)} instead to avoid the usage of store-specific API.
*
* @param entities must not be {@literal null}.
* @return the saved entity
*/
<S extends T> Flux<S> insert(Publisher<S> entities);

/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example)
*/
<S extends T> Flux<S> findAll(Example<S> example);

/* (non-Javadoc)
/*
* (non-Javadoc)
* @see org.springframework.data.repository.query.QueryByExampleExecutor#findAll(org.springframework.data.domain.Example, org.springframework.data.domain.Sort)
*/
<S extends T> Flux<S> findAll(Example<S> example, Sort sort);
Expand Down
Expand Up @@ -15,16 +15,14 @@
*/
package org.springframework.data.mongodb.repository.query;

import java.io.Serializable;

import org.springframework.data.repository.core.EntityInformation;

/**
* Mongo specific {@link EntityInformation}.
*
* @author Oliver Gierke
*/
public interface MongoEntityInformation<T, ID extends Serializable> extends EntityInformation<T, ID> {
public interface MongoEntityInformation<T, ID> extends EntityInformation<T, ID> {

/**
* Returns the name of the collection the entity shall be persisted to.
Expand All @@ -39,4 +37,4 @@ public interface MongoEntityInformation<T, ID extends Serializable> extends Enti
* @return
*/
String getIdAttribute();
}
}
Expand Up @@ -15,8 +15,6 @@
*/
package org.springframework.data.mongodb.repository.support;

import java.io.Serializable;

import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
Expand All @@ -30,7 +28,7 @@
* @author Oliver Gierke
* @author Christoph Strobl
*/
public class MappingMongoEntityInformation<T, ID extends Serializable> extends PersistentEntityInformation<T, ID>
public class MappingMongoEntityInformation<T, ID> extends PersistentEntityInformation<T, ID>
implements MongoEntityInformation<T, ID> {

private final MongoPersistentEntity<T> entityMetadata;
Expand Down
Expand Up @@ -15,8 +15,6 @@
*/
package org.springframework.data.mongodb.repository.support;

import java.io.Serializable;

import org.springframework.data.domain.Persistable;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.repository.query.MongoEntityInformation;
Expand All @@ -42,8 +40,7 @@ private MongoEntityInformationSupport() {}
* @return never {@literal null}.
*/
@SuppressWarnings("unchecked")
static <T, ID extends Serializable> MongoEntityInformation<T, ID> entityInformationFor(
MongoPersistentEntity<?> entity, Class<?> idType) {
static <T, ID> MongoEntityInformation<T, ID> entityInformationFor(MongoPersistentEntity<?> entity, Class<?> idType) {

Assert.notNull(entity, "Entity must not be null!");

Expand Down

0 comments on commit e323859

Please sign in to comment.