Spring Data Couchbase

org.springframework.data.couchbase.core.convert
Class MappingCouchbaseConverter

java.lang.Object
  extended by org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
      extended by org.springframework.data.couchbase.core.convert.MappingCouchbaseConverter
All Implemented Interfaces:
Aware, InitializingBean, ApplicationContextAware, EntityConverter<CouchbasePersistentEntity<?>,CouchbasePersistentProperty,Object,CouchbaseDocument>, EntityReader<Object,CouchbaseDocument>, EntityWriter<Object,CouchbaseDocument>, CouchbaseConverter, CouchbaseWriter<Object,CouchbaseDocument>

public class MappingCouchbaseConverter
extends AbstractCouchbaseConverter
implements ApplicationContextAware

A mapping converter for Couchbase. The converter is responsible for reading from and writing to entities and converting it into a consumable database represenation.

Author:
Michael Nitschinger, Oliver Gierke

Field Summary
protected  ApplicationContext applicationContext
          The overall application context.
protected  MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext
          The generic mapping context.
protected  CouchbaseTypeMapper typeMapper
          The Couchbase specific type mapper in use.
 
Fields inherited from class org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
conversions, conversionService, instantiators
 
Constructor Summary
MappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext)
          Create a new MappingCouchbaseConverter.
 
Method Summary
protected  void addCustomTypeKeyIfNecessary(TypeInformation<?> type, Object source, CouchbaseDocument target)
          Add a custom type key if needed.
protected  void copyCouchbaseDocument(CouchbaseDocument source, CouchbaseDocument target)
          Helper method to copy the internals from a source document into a target document.
 MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> getMappingContext()
           
protected  Object getValueInternal(CouchbasePersistentProperty property, CouchbaseDocument source, Object parent)
          Loads the property value through the value provider.
<R> R
read(Class<R> clazz, CouchbaseDocument source)
           
protected
<R> R
read(CouchbasePersistentEntity<R> entity, CouchbaseDocument source, Object parent)
          Read an incoming CouchbaseDocument into the target entity.
protected
<R> R
read(TypeInformation<R> type, CouchbaseDocument source)
          Read an incoming CouchbaseDocument into the target entity.
protected
<R> R
read(TypeInformation<R> type, CouchbaseDocument source, Object parent)
          Read an incoming CouchbaseDocument into the target entity.
protected  Map<Object,Object> readMap(TypeInformation<?> type, CouchbaseDocument source, Object parent)
          Recursively parses the a map from the source document.
 void setApplicationContext(ApplicationContext applicationContext)
           
 void write(Object source, CouchbaseDocument target)
           
protected  void writeInternal(Object source, CouchbaseDocument target, CouchbasePersistentEntity<?> entity)
          Internal helper method to write the source object into the target document.
protected  void writeInternal(Object source, CouchbaseDocument target, TypeInformation<?> typeHint)
          Convert a source object into a CouchbaseDocument target.
 
Methods inherited from class org.springframework.data.couchbase.core.convert.AbstractCouchbaseConverter
afterPropertiesSet, getConversionService, setCustomConversions, setInstantiators
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

applicationContext

protected ApplicationContext applicationContext
The overall application context.


mappingContext

protected final MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext
The generic mapping context.


typeMapper

protected CouchbaseTypeMapper typeMapper
The Couchbase specific type mapper in use.

Constructor Detail

MappingCouchbaseConverter

public MappingCouchbaseConverter(MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> mappingContext)
Create a new MappingCouchbaseConverter.

Parameters:
mappingContext - the mapping context to use.
Method Detail

getMappingContext

public MappingContext<? extends CouchbasePersistentEntity<?>,CouchbasePersistentProperty> getMappingContext()
Specified by:
getMappingContext in interface EntityConverter<CouchbasePersistentEntity<?>,CouchbasePersistentProperty,Object,CouchbaseDocument>

read

public <R> R read(Class<R> clazz,
                  CouchbaseDocument source)
Specified by:
read in interface EntityReader<Object,CouchbaseDocument>

read

protected <R> R read(TypeInformation<R> type,
                     CouchbaseDocument source)
Read an incoming CouchbaseDocument into the target entity.

Type Parameters:
R - the entity type.
Parameters:
type - the type information of the target entity.
source - the document to convert.
Returns:
the converted entity.

read

protected <R> R read(TypeInformation<R> type,
                     CouchbaseDocument source,
                     Object parent)
Read an incoming CouchbaseDocument into the target entity.

Type Parameters:
R - the entity type.
Parameters:
type - the type information of the target entity.
source - the document to convert.
parent - an optional parent object.
Returns:
the converted entity.

read

protected <R> R read(CouchbasePersistentEntity<R> entity,
                     CouchbaseDocument source,
                     Object parent)
Read an incoming CouchbaseDocument into the target entity.

Type Parameters:
R - the entity type.
Parameters:
entity - the target entity.
source - the document to convert.
parent - an optional parent object.
Returns:
the converted entity.

getValueInternal

protected Object getValueInternal(CouchbasePersistentProperty property,
                                  CouchbaseDocument source,
                                  Object parent)
Loads the property value through the value provider.

Parameters:
property - the source property.
source - the source document.
parent - the optional parent.
Returns:
the actual property value.

readMap

protected Map<Object,Object> readMap(TypeInformation<?> type,
                                     CouchbaseDocument source,
                                     Object parent)
Recursively parses the a map from the source document.

Parameters:
type - the type information for the document.
source - the source document.
parent - the optional parent.
Returns:
the recursively parsed map.

write

public void write(Object source,
                  CouchbaseDocument target)
Specified by:
write in interface EntityWriter<Object,CouchbaseDocument>

writeInternal

protected void writeInternal(Object source,
                             CouchbaseDocument target,
                             TypeInformation<?> typeHint)
Convert a source object into a CouchbaseDocument target.

Parameters:
source - the source object.
target - the target document.
typeHint - the type information for the source.

copyCouchbaseDocument

protected void copyCouchbaseDocument(CouchbaseDocument source,
                                     CouchbaseDocument target)
Helper method to copy the internals from a source document into a target document.

Parameters:
source - the source document.
target - the target document.

writeInternal

protected void writeInternal(Object source,
                             CouchbaseDocument target,
                             CouchbasePersistentEntity<?> entity)
Internal helper method to write the source object into the target document.

Parameters:
source - the source object.
target - the target document.
entity - the persistent entity to convert from.

addCustomTypeKeyIfNecessary

protected void addCustomTypeKeyIfNecessary(TypeInformation<?> type,
                                           Object source,
                                           CouchbaseDocument target)
Add a custom type key if needed.

Parameters:
type - the type information.
source - th the source object.
target - the target document.

setApplicationContext

public void setApplicationContext(ApplicationContext applicationContext)
Specified by:
setApplicationContext in interface ApplicationContextAware

Spring Data Couchbase

Copyright © 2011-2014–2014 Pivotal Software, Inc.. All rights reserved.