Package org.springframework.data.couchbase.core.mapping

Examples of org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty


    });

    entity.doWithAssociations(new AssociationHandler<CouchbasePersistentProperty>() {
      @Override
      public void doWithAssociation(final Association<CouchbasePersistentProperty> association) {
        CouchbasePersistentProperty inverseProp = association.getInverse();
        Object obj = getValueInternal(inverseProp, source, result);
        wrapper.setProperty(inverseProp, obj);
      }
    });
View Full Code Here


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

    final BeanWrapper<Object> wrapper = BeanWrapper.create(source, conversionService);
    final CouchbasePersistentProperty idProperty = entity.getIdProperty();
    final CouchbasePersistentProperty versionProperty = entity.getVersionProperty();

    if (idProperty != null && target.getId() == null) {
      String id = wrapper.getProperty(idProperty, String.class);
      target.setId(id);
    }
    target.setExpiration(entity.getExpiry());

    entity.doWithProperties(new PropertyHandler<CouchbasePersistentProperty>() {
      @Override
      public void doWithPersistentProperty(final CouchbasePersistentProperty prop) {
        if (prop.equals(idProperty) || (versionProperty != null && prop.equals(versionProperty))) {
          return;
        }

        Object propertyObj = wrapper.getProperty(prop, prop.getType());
        if (null != propertyObj) {
          if (!conversions.isSimpleType(propertyObj.getClass())) {
            writePropertyInternal(propertyObj, target, prop);
          } else {
            writeSimpleInternal(propertyObj, target, prop.getFieldName());
          }
        }
      }
    });

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

  public void save(Object objectToSave, final PersistTo persistTo, final ReplicateTo replicateTo) {
    ensureNotIterable(objectToSave);

    final BeanWrapper<Object> beanWrapper = BeanWrapper.create(objectToSave, couchbaseConverter.getConversionService());
    CouchbasePersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(objectToSave.getClass());
    final CouchbasePersistentProperty versionProperty = persistentEntity.getVersionProperty();
    final Long version = versionProperty != null ? beanWrapper.getProperty(versionProperty, Long.class) : null;

    maybeEmitEvent(new BeforeConvertEvent<Object>(objectToSave));
    final CouchbaseDocument converted = new CouchbaseDocument();
    couchbaseConverter.write(objectToSave, converted);
View Full Code Here

  public void update(Object objectToUpdate, final PersistTo persistTo, final ReplicateTo replicateTo) {
    ensureNotIterable(objectToUpdate);

    final BeanWrapper<Object> beanWrapper = BeanWrapper.create(objectToUpdate, couchbaseConverter.getConversionService());
    CouchbasePersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(objectToUpdate.getClass());
    final CouchbasePersistentProperty versionProperty = persistentEntity.getVersionProperty();
    final Long version = versionProperty != null ? beanWrapper.getProperty(versionProperty, Long.class) : null;

    maybeEmitEvent(new BeforeConvertEvent<Object>(objectToUpdate));
    final CouchbaseDocument converted = new CouchbaseDocument();
    couchbaseConverter.write(objectToUpdate, converted);
View Full Code Here

   * @param entity the entity from where to extract the ID from.
   * @return the id of the entity.
   */
  @Override
  public ID getId(T entity) {
    CouchbasePersistentProperty idProperty = entityMetadata.getIdProperty();

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

View Full Code Here

TOP

Related Classes of org.springframework.data.couchbase.core.mapping.CouchbasePersistentProperty

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.