Browse Source
Removed Sort in favor of Sort in Spring Data Commons. Deprecated Order in favor of Direction in Spring Data Commons. Changed implementation to use the types from Spring Data Commons.pull/30/merge
26 changed files with 245 additions and 526 deletions
@ -1,167 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-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.core.mapping; |
|
||||||
|
|
||||||
import java.beans.PropertyDescriptor; |
|
||||||
import java.lang.reflect.Field; |
|
||||||
import java.util.Arrays; |
|
||||||
import java.util.List; |
|
||||||
|
|
||||||
import org.springframework.data.mapping.Association; |
|
||||||
import org.springframework.data.mapping.context.AbstractMappingContext; |
|
||||||
import org.springframework.data.mapping.model.AbstractPersistentProperty; |
|
||||||
import org.springframework.data.mapping.model.BasicPersistentEntity; |
|
||||||
import org.springframework.data.mapping.model.SimpleTypeHolder; |
|
||||||
import org.springframework.data.mongodb.MongoCollectionUtils; |
|
||||||
import org.springframework.data.util.TypeInformation; |
|
||||||
|
|
||||||
/** |
|
||||||
* @deprecated use {@link MongoMappingContext} instead. |
|
||||||
* @author Oliver Gierke |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class SimpleMongoMappingContext extends |
|
||||||
AbstractMappingContext<SimpleMongoMappingContext.SimpleMongoPersistentEntity<?>, MongoPersistentProperty> { |
|
||||||
|
|
||||||
/* |
|
||||||
* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentEntity(org.springframework.data.util.TypeInformation) |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected <T> SimpleMongoPersistentEntity<T> createPersistentEntity(TypeInformation<T> typeInformation) { |
|
||||||
return new SimpleMongoPersistentEntity<T>(typeInformation); |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mapping.context.AbstractMappingContext#createPersistentProperty(java.lang.reflect.Field, java.beans.PropertyDescriptor, org.springframework.data.mapping.model.MutablePersistentEntity, org.springframework.data.mapping.model.SimpleTypeHolder) |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected SimplePersistentProperty createPersistentProperty(Field field, PropertyDescriptor descriptor, |
|
||||||
SimpleMongoPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder) { |
|
||||||
return new SimplePersistentProperty(field, descriptor, owner, simpleTypeHolder); |
|
||||||
} |
|
||||||
|
|
||||||
static class SimplePersistentProperty extends AbstractPersistentProperty<MongoPersistentProperty> implements |
|
||||||
MongoPersistentProperty { |
|
||||||
|
|
||||||
private static final List<String> ID_FIELD_NAMES = Arrays.asList("id", "_id"); |
|
||||||
|
|
||||||
/** |
|
||||||
* Creates a new {@link SimplePersistentProperty}. |
|
||||||
* |
|
||||||
* @param field |
|
||||||
* @param propertyDescriptor |
|
||||||
* @param information |
|
||||||
*/ |
|
||||||
public SimplePersistentProperty(Field field, PropertyDescriptor propertyDescriptor, MongoPersistentEntity<?> owner, |
|
||||||
SimpleTypeHolder simpleTypeHolder) { |
|
||||||
super(field, propertyDescriptor, owner, simpleTypeHolder); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mapping.BasicPersistentProperty#isIdProperty() |
|
||||||
*/ |
|
||||||
public boolean isIdProperty() { |
|
||||||
return ID_FIELD_NAMES.contains(field.getName()); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#getKey() |
|
||||||
*/ |
|
||||||
public String getFieldName() { |
|
||||||
return isIdProperty() ? "_id" : getName(); |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#getFieldOrder() |
|
||||||
*/ |
|
||||||
public int getFieldOrder() { |
|
||||||
return Integer.MAX_VALUE; |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mapping.AbstractPersistentProperty#createAssociation() |
|
||||||
*/ |
|
||||||
@Override |
|
||||||
protected Association<MongoPersistentProperty> createAssociation() { |
|
||||||
return new Association<MongoPersistentProperty>(this, null); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#isDbReference() |
|
||||||
*/ |
|
||||||
public boolean isDbReference() { |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#getDBRef() |
|
||||||
*/ |
|
||||||
public DBRef getDBRef() { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentProperty#isVersion() |
|
||||||
*/ |
|
||||||
public boolean isVersionProperty() { |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.mapping.MongoPersistentProperty#usePropertyAccess() |
|
||||||
*/ |
|
||||||
public boolean usePropertyAccess() { |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
static class SimpleMongoPersistentEntity<T> extends BasicPersistentEntity<T, MongoPersistentProperty> implements |
|
||||||
MongoPersistentEntity<T> { |
|
||||||
|
|
||||||
/** |
|
||||||
* @param information |
|
||||||
*/ |
|
||||||
public SimpleMongoPersistentEntity(TypeInformation<T> information) { |
|
||||||
super(information); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentEntity#getCollection() |
|
||||||
*/ |
|
||||||
public String getCollection() { |
|
||||||
return MongoCollectionUtils.getPreferredCollectionName(getType()); |
|
||||||
} |
|
||||||
|
|
||||||
/* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.core.mapping.MongoPersistentEntity#getVersionProperty() |
|
||||||
*/ |
|
||||||
public MongoPersistentProperty getVersionProperty() { |
|
||||||
return null; |
|
||||||
} |
|
||||||
|
|
||||||
/* |
|
||||||
* (non-Javadoc) |
|
||||||
* @see org.springframework.data.mongodb.core.mapping.MongoPersistentEntity#hasVersionProperty() |
|
||||||
*/ |
|
||||||
public boolean hasVersionProperty() { |
|
||||||
return false; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,56 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2010-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.core.query; |
|
||||||
|
|
||||||
import java.util.LinkedHashMap; |
|
||||||
import java.util.Map; |
|
||||||
|
|
||||||
import com.mongodb.BasicDBObject; |
|
||||||
import com.mongodb.DBObject; |
|
||||||
|
|
||||||
/** |
|
||||||
* Helper class to define sorting criterias for a Query instance. |
|
||||||
* |
|
||||||
* @author Thomas Risberg |
|
||||||
* @author Oliver Gierke |
|
||||||
* @deprecated use {@link org.springframework.data.domain.Sort} instead. See |
|
||||||
* {@link Query#with(org.springframework.data.domain.Sort)}. |
|
||||||
*/ |
|
||||||
@Deprecated |
|
||||||
public class Sort { |
|
||||||
|
|
||||||
private Map<String, Order> fieldSpec = new LinkedHashMap<String, Order>(); |
|
||||||
|
|
||||||
public Sort() { |
|
||||||
} |
|
||||||
|
|
||||||
public Sort(String key, Order order) { |
|
||||||
fieldSpec.put(key, order); |
|
||||||
} |
|
||||||
|
|
||||||
public Sort on(String key, Order order) { |
|
||||||
fieldSpec.put(key, order); |
|
||||||
return this; |
|
||||||
} |
|
||||||
|
|
||||||
public DBObject getSortObject() { |
|
||||||
DBObject dbo = new BasicDBObject(); |
|
||||||
for (String k : fieldSpec.keySet()) { |
|
||||||
dbo.put(k, fieldSpec.get(k).equals(Order.ASCENDING) ? 1 : -1); |
|
||||||
} |
|
||||||
return dbo; |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,32 +0,0 @@ |
|||||||
package org.springframework.data.mongodb.core.mapping; |
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.*; |
|
||||||
import static org.junit.Assert.*; |
|
||||||
|
|
||||||
import org.junit.Test; |
|
||||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty; |
|
||||||
import org.springframework.data.mongodb.core.mapping.SimpleMongoMappingContext; |
|
||||||
import org.springframework.data.mongodb.core.mapping.SimpleMongoMappingContext.SimpleMongoPersistentEntity; |
|
||||||
|
|
||||||
/** |
|
||||||
* Unit tests for {@link SimpleMongoMappingContext}. |
|
||||||
* |
|
||||||
* @author Oliver Gierke |
|
||||||
*/ |
|
||||||
public class SimpleMappingContextUnitTests { |
|
||||||
|
|
||||||
@Test |
|
||||||
public void returnsIdPropertyCorrectly() { |
|
||||||
|
|
||||||
SimpleMongoMappingContext context = new SimpleMongoMappingContext(); |
|
||||||
SimpleMongoPersistentEntity<?> entity = context.getPersistentEntity(Person.class); |
|
||||||
|
|
||||||
MongoPersistentProperty idProperty = entity.getIdProperty(); |
|
||||||
assertThat(idProperty, is(notNullValue())); |
|
||||||
assertThat(idProperty.getName(), is("id")); |
|
||||||
} |
|
||||||
|
|
||||||
static class Person { |
|
||||||
String id; |
|
||||||
} |
|
||||||
} |
|
||||||
Loading…
Reference in new issue