@Override public Class<?> getFieldType() { if (!isIdProperty()) { return getType(); } MongoId idAnnotation = findAnnotation(MongoId.class); if (idAnnotation == null) { return FieldType.OBJECT_ID.getJavaClass(); } FieldType fieldType = idAnnotation.targetType(); if (fieldType == FieldType.IMPLICIT) { return getType(); } return fieldType.getJavaClass(); }
/** * @return true if {@link org.springframework.data.mongodb.core.mapping.Field} having non blank * {@link org.springframework.data.mongodb.core.mapping.Field#value()} present. * @since 1.7 */ protected boolean hasExplicitFieldName() { return StringUtils.hasText(getAnnotatedFieldName()); }
@Override public DBRef getDBRef() { if (!dbRefResolved) { this.dbref = super.getDBRef(); this.dbRefResolved = true; } return this.dbref; } }
@Override public boolean isLanguageProperty() { return getFieldName().equals(LANGUAGE_FIELD_NAME) || isExplicitLanguageProperty(); }
/** * Creates a new {@link BasicMongoPersistentProperty}. * * @param property * @param owner * @param simpleTypeHolder * @param fieldNamingStrategy */ public BasicMongoPersistentProperty(Property property, MongoPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder, @Nullable FieldNamingStrategy fieldNamingStrategy) { super(property, owner, simpleTypeHolder); this.fieldNamingStrategy = fieldNamingStrategy == null ? PropertyNameFieldNamingStrategy.INSTANCE : fieldNamingStrategy; if (isIdProperty() && getFieldName() != ID_FIELD_NAME) { LOG.warn("Customizing field name for id property not allowed! Custom name will not be considered!"); } }
/** * Also considers fields as id that are of supported id type and name. * * @see #SUPPORTED_ID_PROPERTY_NAMES * @see #SUPPORTED_ID_TYPES */ @Override public boolean isIdProperty() { if (super.isIdProperty()) { return true; } // We need to support a wider range of ID types than just the ones that can be converted to an ObjectId // but still we need to check if there happens to be an explicit name set return SUPPORTED_ID_PROPERTY_NAMES.contains(getName()) && !hasExplicitFieldName(); }
/** * Returns the key to be used to store the value of the property inside a Mongo {@link org.bson.Document}. * * @return */ public String getFieldName() { if (isIdProperty()) { if (getOwner().getIdProperty() == null) { return ID_FIELD_NAME; } if (getOwner().isIdProperty(this)) { return ID_FIELD_NAME; } } if (hasExplicitFieldName()) { return getAnnotatedFieldName(); } String fieldName = fieldNamingStrategy.getFieldName(this); if (!StringUtils.hasText(fieldName)) { throw new MappingException(String.format("Invalid (null or empty) field name returned for property %s by %s!", this, fieldNamingStrategy.getClass())); } return fieldName; }
@Override public boolean isExplicitLanguageProperty() { return isAnnotationPresent(Language.class); };
@Nullable public DBRef getDBRef() { return findAnnotation(DBRef.class); }
@Override public String getFieldName() { if (this.fieldName == null) { this.fieldName = super.getFieldName(); } return this.fieldName; }
@Override public Class<?> getFieldType() { if (this.fieldType == null) { this.fieldType = super.getFieldType(); } return this.fieldType; }
/** * Returns the key to be used to store the value of the property inside a Mongo {@link org.bson.Document}. * * @return */ public String getFieldName() { if (isIdProperty()) { if (getOwner().getIdProperty() == null) { return ID_FIELD_NAME; } if (getOwner().isIdProperty(this)) { return ID_FIELD_NAME; } } if (hasExplicitFieldName()) { return getAnnotatedFieldName(); } String fieldName = fieldNamingStrategy.getFieldName(this); if (!StringUtils.hasText(fieldName)) { throw new MappingException(String.format("Invalid (null or empty) field name returned for property %s by %s!", this, fieldNamingStrategy.getClass())); } return fieldName; }
@Override public boolean isTextScoreProperty() { return isAnnotationPresent(TextScore.class); } }
@Override public boolean isLanguageProperty() { return getFieldName().equals(LANGUAGE_FIELD_NAME) || isExplicitLanguageProperty(); }
/** * Also considers fields as id that are of supported id type and name. * * @see #SUPPORTED_ID_PROPERTY_NAMES * @see #SUPPORTED_ID_TYPES */ @Override public boolean isIdProperty() { if (super.isIdProperty()) { return true; } // We need to support a wider range of ID types than just the ones that can be converted to an ObjectId // but still we need to check if there happens to be an explicit name set return SUPPORTED_ID_PROPERTY_NAMES.contains(getName()) && !hasExplicitFieldName(); }
/** * Creates a new {@link BasicMongoPersistentProperty}. * * @param field * @param propertyDescriptor * @param owner * @param simpleTypeHolder * @param fieldNamingStrategy */ public BasicMongoPersistentProperty(Property property, MongoPersistentEntity<?> owner, SimpleTypeHolder simpleTypeHolder, @Nullable FieldNamingStrategy fieldNamingStrategy) { super(property, owner, simpleTypeHolder); this.fieldNamingStrategy = fieldNamingStrategy == null ? PropertyNameFieldNamingStrategy.INSTANCE : fieldNamingStrategy; if (isIdProperty() && getFieldName() != ID_FIELD_NAME) { LOG.warn("Customizing field name for id property not allowed! Custom name will not be considered!"); } }
public int getFieldOrder() { org.springframework.data.mongodb.core.mapping.Field annotation = findAnnotation( org.springframework.data.mongodb.core.mapping.Field.class); return annotation != null ? annotation.order() : Integer.MAX_VALUE; }
@Override public String getFieldName() { if (this.fieldName == null) { this.fieldName = super.getFieldName(); } return this.fieldName; }
@Override public boolean isExplicitIdProperty() { return isAnnotationPresent(Id.class); }
@Nullable private String getAnnotatedFieldName() { org.springframework.data.mongodb.core.mapping.Field annotation = findAnnotation( org.springframework.data.mongodb.core.mapping.Field.class); return annotation != null ? annotation.value() : null; }