Package org.springframework.data.mongodb.core.mapping

Examples of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty


   */
  @Test
  public void shouldNotEagerlyResolveIdPropertyWithPropertyAccess() {

    MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(ClassWithLazyDbRefs.class);
    MongoPersistentProperty property = entity.getPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");

    String idValue = new ObjectId().toString();
    DBRef dbRef = converter.toDBRef(new LazyDbRefTargetPropertyAccess(idValue), property);

    DBObject object = new BasicDBObject("dbRefToConcreteTypeWithPropertyAccess", dbRef);
View Full Code Here


   */
  @Test
  public void shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked() throws Exception {

    MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(WithObjectMethodOverrideLazyDbRefs.class);
    MongoPersistentProperty property = entity.getPersistentProperty("dbRefToConcreteTypeWithPropertyAccess");

    String idValue = new ObjectId().toString();
    DBRef dbRef = converter.toDBRef(new LazyDbRefTargetPropertyAccess(idValue), property);

    WithObjectMethodOverrideLazyDbRefs result = converter.read(WithObjectMethodOverrideLazyDbRefs.class,
View Full Code Here

    if (entity == null || source == null) {
      return;
    }

    if (entity.hasTextScoreProperty() && !MetaMapping.IGNORE.equals(metaMapping)) {
      MongoPersistentProperty textScoreProperty = entity.getTextScoreProperty();
      if (MetaMapping.FORCE.equals(metaMapping)
          || (MetaMapping.WHEN_PRESENT.equals(metaMapping) && source.containsField(textScoreProperty.getFieldName()))) {
        source.putAll(getMappedTextScoreField(textScoreProperty));
      }
    }
  }
View Full Code Here

    if (!documentField.isAssociation()) {
      return false;
    }

    Class<? extends Object> type = value.getClass();
    MongoPersistentProperty property = documentField.getProperty();

    if (property.getActualType().isAssignableFrom(type)) {
      return true;
    }

    MongoPersistentEntity<?> entity = documentField.getPropertyEntity();
    return entity.hasIdProperty()
View Full Code Here

    ParameterValueProvider<MongoPersistentProperty> provider = getParameterProvider(entity, dbo, evaluator, path);
    EntityInstantiator instantiator = instantiators.getInstantiatorFor(entity);
    S instance = instantiator.createInstance(entity, provider);

    final BeanWrapper<S> wrapper = BeanWrapper.create(instance, conversionService);
    final MongoPersistentProperty idProperty = entity.getIdProperty();
    final S result = wrapper.getBean();

    // make sure id property is set before all other properties
    Object idValue = null;

    if (idProperty != null) {
      idValue = getValueInternal(idProperty, dbo, evaluator, path);
      wrapper.setProperty(idProperty, idValue);
    }

    final ObjectPath currentPath = path.push(result, entity, idValue);

    // Set properties not already set in the constructor
    entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
      public void doWithPersistentProperty(MongoPersistentProperty prop) {

        // we skip the id property since it was already set
        if (idProperty != null && idProperty.equals(prop)) {
          return;
        }

        if (!dbo.containsField(prop.getFieldName()) || entity.isConstructorArgument(prop)) {
          return;
        }

        wrapper.setProperty(prop, getValueInternal(prop, dbo, evaluator, currentPath));
      }
    });

    // Handle associations
    entity.doWithAssociations(new AssociationHandler<MongoPersistentProperty>() {
      public void doWithAssociation(Association<MongoPersistentProperty> association) {

        final MongoPersistentProperty property = association.getInverse();
        Object value = dbo.get(property.getFieldName());

        if (value == null) {
          return;
        }
View Full Code Here

    if (null == entity) {
      throw new MappingException("No mapping metadata found for entity of type " + obj.getClass().getName());
    }

    final BeanWrapper<Object> wrapper = BeanWrapper.create(obj, conversionService);
    final MongoPersistentProperty idProperty = entity.getIdProperty();

    if (!dbo.containsField("_id") && null != idProperty) {

      try {
        Object id = wrapper.getProperty(idProperty, Object.class);
        dbo.put("_id", idMapper.convertId(id));
      } catch (ConversionException ignored) {}
    }

    // Write the properties
    entity.doWithProperties(new PropertyHandler<MongoPersistentProperty>() {
      public void doWithPersistentProperty(MongoPersistentProperty prop) {

        if (prop.equals(idProperty) || !prop.isWritable()) {
          return;
        }

        Object propertyObj = wrapper.getProperty(prop);

        if (null != propertyObj) {

          if (!conversions.isSimpleType(propertyObj.getClass())) {
            writePropertyInternal(propertyObj, dbo, prop);
          } else {
            writeSimpleInternal(propertyObj, dbo, prop);
          }
        }
      }
    });

    entity.doWithAssociations(new AssociationHandler<MongoPersistentProperty>() {
      public void doWithAssociation(Association<MongoPersistentProperty> association) {
        MongoPersistentProperty inverseProp = association.getInverse();
        Class<?> type = inverseProp.getType();
        Object propertyObj = wrapper.getProperty(inverseProp, type);
        if (null != propertyObj) {
          writePropertyInternal(propertyObj, dbo, inverseProp);
        }
      }
View Full Code Here

    if (null == targetEntity) {
      throw new MappingException("No mapping metadata found for " + target.getClass());
    }

    MongoPersistentProperty idProperty = targetEntity.getIdProperty();

    if (idProperty == null) {
      throw new MappingException("No id property found on class " + targetEntity.getType());
    }

    Object id = null;

    if (target.getClass().equals(idProperty.getType())) {
      id = target;
    } else {
      BeanWrapper<Object> wrapper = BeanWrapper.create(target, conversionService);
      id = wrapper.getProperty(idProperty, Object.class);
    }
View Full Code Here

     * @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#isIdKey()
     */
    @Override
    public boolean isIdField() {

      MongoPersistentProperty idProperty = entity.getIdProperty();

      if (idProperty != null) {
        return idProperty.getName().equals(name) || idProperty.getFieldName().equals(name);
      }

      return DEFAULT_ID_NAMES.contains(name);
    }
View Full Code Here

     * (non-Javadoc)
     * @see org.springframework.data.mongodb.core.convert.QueryMapper.Field#getEntity()
     */
    @Override
    public MongoPersistentEntity<?> getPropertyEntity() {
      MongoPersistentProperty property = getProperty();
      return property == null ? null : mappingContext.getPersistentEntity(property);
    }
View Full Code Here

        Iterator<MongoPersistentProperty> iterator = propertyPath.iterator();
        boolean associationDetected = false;

        while (iterator.hasNext()) {

          MongoPersistentProperty property = iterator.next();

          if (property.isAssociation()) {
            associationDetected = true;
            continue;
          }

          if (associationDetected && !property.isIdProperty()) {
            throw new MappingException(String.format(INVALID_ASSOCIATION_REFERENCE, pathExpression));
          }
        }

        return propertyPath;
View Full Code Here

TOP

Related Classes of org.springframework.data.mongodb.core.mapping.MongoPersistentProperty

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.