Examples of MongoPersistentProperty


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

    if (source == null) {
      return proxy;
    }

    MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(property);
    MongoPersistentProperty idProperty = persistentEntity.getIdProperty();
   
    if(idProperty.usePropertyAccess()) {
      return proxy;
    }
   
    SpELExpressionEvaluator evaluator = new DefaultSpELExpressionEvaluator(proxy, spELContext);
    BeanWrapper<Object> proxyWrapper = BeanWrapper.create(proxy, null);
   
    DBObject object = new BasicDBObject(idProperty.getFieldName(), source.getId());
    ObjectPath objectPath = ObjectPath.ROOT.push(proxy, persistentEntity, null);
    proxyWrapper.setProperty(idProperty, resolver.getValueInternal(idProperty, object, evaluator, objectPath));

    return proxy;
  }
View Full Code Here

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

    return findById(id, entityClass, determineCollectionName(entityClass));
  }

  public <T> T findById(Object id, Class<T> entityClass, String collectionName) {
    MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entityClass);
    MongoPersistentProperty idProperty = persistentEntity == null ? null : persistentEntity.getIdProperty();
    String idKey = idProperty == null ? ID_FIELD : idProperty.getName();
    return doFindOne(collectionName, new BasicDBObject(idKey, id), null, entityClass);
  }
View Full Code Here

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

  }

  private <T> void doSaveVersioned(T objectToSave, MongoPersistentEntity<?> entity, String collectionName) {

    BeanWrapper<T> beanWrapper = BeanWrapper.create(objectToSave, this.mongoConverter.getConversionService());
    MongoPersistentProperty idProperty = entity.getIdProperty();
    MongoPersistentProperty versionProperty = entity.getVersionProperty();

    Number version = beanWrapper.getProperty(versionProperty, Number.class);

    // Fresh instance -> initialize version property
    if (version == null) {
      doInsert(collectionName, objectToSave, this.mongoConverter);
    } else {

      assertUpdateableIdIfNotSet(objectToSave);

      // Create query for entity with the id and old version
      Object id = beanWrapper.getProperty(idProperty);
      Query query = new Query(Criteria.where(idProperty.getName()).is(id).and(versionProperty.getName()).is(version));

      // Bump version number
      Number number = beanWrapper.getProperty(versionProperty, Number.class);
      beanWrapper.setProperty(versionProperty, number.longValue() + 1);
View Full Code Here

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

    if (object instanceof DBObject) {
      return Collections.singletonMap(ID_FIELD, ((DBObject) object).get(ID_FIELD)).entrySet().iterator().next();
    }

    MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(objectType);
    MongoPersistentProperty idProp = entity == null ? null : entity.getIdProperty();

    if (idProp == null) {
      throw new MappingException("No id property found for object of type " + objectType);
    }

    Object idValue = BeanWrapper.create(object, mongoConverter.getConversionService())
        .getProperty(idProp, Object.class);
    return Collections.singletonMap(idProp.getFieldName(), idValue).entrySet().iterator().next();
  }
View Full Code Here

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

  }

  private void assertUpdateableIdIfNotSet(Object entity) {

    MongoPersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(entity.getClass());
    MongoPersistentProperty idProperty = persistentEntity == null ? null : persistentEntity.getIdProperty();

    if (idProperty == null) {
      return;
    }

    ConversionService service = mongoConverter.getConversionService();
    Object idValue = BeanWrapper.create(entity, service).getProperty(idProperty, Object.class);

    if (idValue == null && !MongoSimpleTypes.AUTOGENERATED_ID_TYPES.contains(idProperty.getType())) {
      throw new InvalidDataAccessApiUsageException(String.format(
          "Cannot autogenerate id of type %s for entity of type %s!", idProperty.getType().getName(), entity.getClass()
              .getName()));
    }
  }
View Full Code Here

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

      DBObject dbObject = (DBObject) savedObject;
      dbObject.put(ID_FIELD, id);
      return;
    }

    MongoPersistentProperty idProp = getIdPropertyFor(savedObject.getClass());

    if (idProp == null) {
      return;
    }

    ConversionService conversionService = mongoConverter.getConversionService();
    BeanWrapper<Object> wrapper = BeanWrapper.create(savedObject, conversionService);

    Object idValue = wrapper.getProperty(idProp, idProp.getType());

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

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

    MongoParameterAccessor delegate = new StubParameterAccessor(parameters);
    PotentiallyConvertingIterator iterator = new ConvertingParameterAccessor(converter, delegate).iterator();

    MongoPersistentEntity<?> entity = context.getPersistentEntity(Entity.class);
    MongoPersistentProperty property = entity.getPersistentProperty("property");

    return iterator.nextConverted(property);
  }
View Full Code Here

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

   * @see org.springframework.data.repository.support.EntityInformation#getId(java.lang.Object)
   */
  @SuppressWarnings("unchecked")
  public ID getId(T entity) {

    MongoPersistentProperty idProperty = entityMetadata.getIdProperty();

    if (idProperty == null) {
      return null;
    }

View Full Code Here

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

      return super.getKeyForPath(expr, metadata);
    }

    Path<?> parent = metadata.getParent();
    MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(parent.getType());
    MongoPersistentProperty property = entity.getPersistentProperty(metadata.getName());

    return property == null ? super.getKeyForPath(expr, metadata) : property.getFieldName();
  }
View Full Code Here

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

   * @see com.mysema.query.mongodb.MongodbSerializer#isReference(com.mysema.query.types.Path)
   */
  @Override
  protected boolean isReference(Path<?> path) {

    MongoPersistentProperty property = getPropertyFor(path);
    return property == null ? false : property.isAssociation();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.