Browse Source
The presence of ObjectToObjectConverter in a DefaultConversionService causes the guard trying to register converters for ObjectIds in AbstractMongoConverter to not trigger the registration. This in turn caused ObjectId conversions to be executed via reflection instead of the straight forward method calls and thus a drop in performance for such operations. We no unconditionally register the converters to make sure they really get applied. Related tickets: SPR-13703.pull/663/head
2 changed files with 94 additions and 6 deletions
@ -0,0 +1,90 @@
@@ -0,0 +1,90 @@
|
||||
/* |
||||
* Copyright 2015 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.convert; |
||||
|
||||
import static org.mockito.Mockito.*; |
||||
|
||||
import org.junit.Test; |
||||
import org.springframework.core.convert.support.DefaultConversionService; |
||||
import org.springframework.core.convert.support.GenericConversionService; |
||||
import org.springframework.data.mapping.context.MappingContext; |
||||
import org.springframework.data.mongodb.core.convert.MongoConverters.ObjectIdToStringConverter; |
||||
import org.springframework.data.mongodb.core.convert.MongoConverters.StringToObjectIdConverter; |
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity; |
||||
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty; |
||||
import org.springframework.data.util.TypeInformation; |
||||
|
||||
import com.mongodb.DBObject; |
||||
import com.mongodb.DBRef; |
||||
|
||||
/** |
||||
* Unit tests for {@link AbstractMongoConverter}. |
||||
* |
||||
* @author Oliver Gierke |
||||
*/ |
||||
public class AbstractMongoConverterUnitTests { |
||||
|
||||
/** |
||||
* @see DATAMONGO-1324 |
||||
*/ |
||||
@Test |
||||
public void registersObjectIdConvertersExplicitly() { |
||||
|
||||
DefaultConversionService conversionService = spy(new DefaultConversionService()); |
||||
|
||||
new SampleMongoConverter(conversionService).afterPropertiesSet(); |
||||
|
||||
verify(conversionService).addConverter(StringToObjectIdConverter.INSTANCE); |
||||
verify(conversionService).addConverter(ObjectIdToStringConverter.INSTANCE); |
||||
} |
||||
|
||||
static class SampleMongoConverter extends AbstractMongoConverter { |
||||
|
||||
public SampleMongoConverter(GenericConversionService conversionService) { |
||||
super(conversionService); |
||||
} |
||||
|
||||
@Override |
||||
public MongoTypeMapper getTypeMapper() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
@Override |
||||
public MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> getMappingContext() { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
@Override |
||||
public <R> R read(Class<R> type, DBObject source) { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
@Override |
||||
public void write(Object source, DBObject sink) { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
@Override |
||||
public Object convertToMongoType(Object obj, TypeInformation<?> typeInformation) { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
|
||||
@Override |
||||
public DBRef toDBRef(Object object, MongoPersistentProperty referingProperty) { |
||||
throw new UnsupportedOperationException(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue