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

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


      target.put(name, collectionDoc);
      return;
    }

    if (valueType.isMap()) {
      CouchbaseDocument mapDoc = createMap((Map<Object, Object>) source, prop);
      target.put(name, mapDoc);
      return;
    }

    Class<?> basicTargetType = conversions.getCustomWriteTarget(source.getClass(), null);
    if (basicTargetType != null) {
      target.put(name, conversionService.convert(source, basicTargetType));
      return;
    }

    CouchbaseDocument propertyDoc = new CouchbaseDocument();
    addCustomTypeKeyIfNecessary(type, source, propertyDoc);

    CouchbasePersistentEntity<?> entity = isSubtype(prop.getType(), source.getClass()) ? mappingContext
      .getPersistentEntity(source.getClass()) : mappingContext.getPersistentEntity(type);
    writeInternal(source, propertyDoc, entity);
View Full Code Here


   */
  private CouchbaseDocument createMap(final Map<Object, Object> map, final CouchbasePersistentProperty prop) {
    Assert.notNull(map, "Given map must not be null!");
    Assert.notNull(prop, "PersistentProperty must not be null!");

    return writeMapInternal(map, new CouchbaseDocument(), prop.getTypeInformation());
  }
View Full Code Here

        if (val == null || conversions.isSimpleType(val.getClass())) {
          writeSimpleInternal(val, target, simpleKey);
        } else if (val instanceof Collection || val.getClass().isArray()) {
          target.put(simpleKey, writeCollectionInternal(asCollection(val), new CouchbaseList(), type.getMapValueType()));
        } else {
          CouchbaseDocument embeddedDoc = new CouchbaseDocument();
          TypeInformation<?> valueTypeInfo = type.isMap() ? type.getMapValueType() : ClassTypeInformation.OBJECT;
          writeInternal(val, embeddedDoc, valueTypeInfo);
          target.put(simpleKey, embeddedDoc);
        }
      } else {
View Full Code Here

      if (elementType == null || conversions.isSimpleType(elementType)) {
        target.put(element);
      } else if (element instanceof Collection || elementType.isArray()) {
        target.put(writeCollectionInternal(asCollection(element), new CouchbaseList(), componentType));
      } else {
        CouchbaseDocument embeddedDoc = new CouchbaseDocument();
        writeInternal(element, embeddedDoc, componentType);
        target.put(embeddedDoc);
      }

    }
View Full Code Here

        service = new JacksonTranslationService();
    }

    @Test
    public void shouldEncodeNonASCII() {
        CouchbaseDocument doc = new CouchbaseDocument("key");
        doc.put("language", "русский");
        String expected = "{\"language\":\"русский\"}";
        assertEquals(expected,  service.encode(doc));
    }
View Full Code Here

    }

    @Test
    public void shouldDecodeNonASCII() {
        String source = "{\"language\":\"русский\"}";
        CouchbaseDocument target = new CouchbaseDocument();
        service.decode(source, target);
        assertEquals("русский", target.get("language"));
    }
View Full Code Here

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

    final CouchbaseDocument converted = new CouchbaseDocument(id);
    Object readEntity = couchbaseConverter.read(entityClass, (CouchbaseDocument) translateDecode(
      (String) result.getValue(), converted));

    final BeanWrapper<Object> beanWrapper = BeanWrapper.create(readEntity, couchbaseConverter.getConversionService());
    CouchbasePersistentEntity<?> persistentEntity = mappingContext.getPersistentEntity(readEntity.getClass());
View Full Code Here

    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);

    maybeEmitEvent(new BeforeSaveEvent<Object>(objectToSave, converted));
    execute(new BucketCallback<Boolean>() {
      @Override
      public Boolean doInBucket() throws InterruptedException, ExecutionException {
        if (version == null) {
          OperationFuture<Boolean> setFuture = client.set(converted.getId(), converted.getExpiration(),
            translateEncode(converted), persistTo, replicateTo);
          boolean future = setFuture.get();
          if (!future) {
            handleWriteResultError("Saving document failed: " + setFuture.getStatus().getMessage());
          }
          return future;
        } else {
          OperationFuture<CASResponse> casFuture = client.asyncCas(converted.getId(), version,
            converted.getExpiration(), translateEncode(converted), persistTo, replicateTo);
          CASResponse cas = casFuture.get();
          if (cas == CASResponse.EXISTS) {
            throw new OptimisticLockingFailureException("Saving document with version value failed: " + cas);
          } else {
            long newCas = casFuture.getCas();
View Full Code Here

        beanWrapper.setProperty(persistentEntity.getVersionProperty(), 0);
      }
    }

    maybeEmitEvent(new BeforeConvertEvent<Object>(objectToInsert));
    final CouchbaseDocument converted = new CouchbaseDocument();
    couchbaseConverter.write(objectToInsert, converted);

    maybeEmitEvent(new BeforeSaveEvent<Object>(objectToInsert, converted));
    execute(new BucketCallback<Boolean>() {
      @Override
      public Boolean doInBucket() throws InterruptedException, ExecutionException {
        OperationFuture<Boolean> addFuture = client.add(converted.getId(), converted.getExpiration(),
          translateEncode(converted), persistTo, replicateTo);
        boolean result = addFuture.get();
        if(result == false) {
          handleWriteResultError("Inserting document failed: "
            + addFuture.getStatus().getMessage());
View Full Code Here

    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);

    maybeEmitEvent(new BeforeSaveEvent<Object>(objectToUpdate, converted));
    execute(new BucketCallback<Boolean>() {
      @Override
      public Boolean doInBucket() throws InterruptedException, ExecutionException {
        if (version == null) {
          return client.replace(converted.getId(), converted.getExpiration(), translateEncode(converted), persistTo,
            replicateTo).get();
        } else {
          OperationFuture<CASResponse> casFuture = client.asyncCas(converted.getId(), version,
            converted.getExpiration(), translateEncode(converted), persistTo, replicateTo);
          CASResponse cas = casFuture.get();

          if (cas == CASResponse.EXISTS) {
            throw new OptimisticLockingFailureException("Updating document with version value failed: " + cas);
          } else {
View Full Code Here

TOP

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

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.