diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/CachingMongoPersistentProperty.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/CachingMongoPersistentProperty.java new file mode 100644 index 000000000..a732a635b --- /dev/null +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/CachingMongoPersistentProperty.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2011 by the original author(s). + * + * 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 org.springframework.data.mapping.model.SimpleTypeHolder; + +/** + * {@link MongoPersistentProperty} caching access to {@link #isIdProperty()} and {@link #getFieldName()}. + * + * @author Oliver Gierke + */ +public class CachingMongoPersistentProperty extends BasicMongoPersistentProperty { + + private Boolean isIdProperty; + private String fieldName; + + /** + * Creates a new {@link CachingMongoPersistentProperty}. + * + * @param field + * @param propertyDescriptor + * @param owner + * @param simpleTypeHolder + */ + public CachingMongoPersistentProperty(Field field, PropertyDescriptor propertyDescriptor, + MongoPersistentEntity owner, SimpleTypeHolder simpleTypeHolder) { + super(field, propertyDescriptor, owner, simpleTypeHolder); + } + + /* + * (non-Javadoc) + * @see org.springframework.data.mongodb.core.mapping.BasicMongoPersistentProperty#isIdProperty() + */ + @Override + public boolean isIdProperty() { + + if (this.isIdProperty == null) { + this.isIdProperty = super.isIdProperty(); + } + + return this.isIdProperty; + } + + /* + * (non-Javadoc) + * @see org.springframework.data.mongodb.core.mapping.BasicMongoPersistentProperty#getFieldName() + */ + @Override + public String getFieldName() { + + if (this.fieldName == null) { + this.fieldName = super.getFieldName(); + } + + return super.getFieldName(); + } +} diff --git a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java index d5906625a..f09e7ea07 100644 --- a/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java +++ b/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java @@ -43,7 +43,7 @@ public class MongoMappingContext extends AbstractMappingContext owner, SimpleTypeHolder simpleTypeHolder) { - return new BasicMongoPersistentProperty(field, descriptor, owner, simpleTypeHolder); + return new CachingMongoPersistentProperty(field, descriptor, owner, simpleTypeHolder); } /* (non-Javadoc)