com.sleepycat.je.sync
Class RecordMapping

java.lang.Object
  extended by com.sleepycat.je.sync.RecordMapping
All Implemented Interfaces:
RecordConverter, Serializable

public class RecordMapping
extends Object
implements RecordConverter

Defines record conversion based on the fields/properties of a Java object, and uses a JE binding to convert between local raw records and Java objects.

The set of field/properties in a Java object that are converted are those that are considered to be persistent. When bean properties are not used, the definition of persistent fields is the same as used in the DPL (TODO: add doc reference). When bean properties are used, all Java bean properties are considered to be persistent. The set of persistent fields/properties can be customized using the fieldMapping.

See Also:
Serialized Form

Constructor Summary
RecordMapping(EntityBinding entityBinding, boolean beanProperties)
          Creates a complete record mapping using an entity binding, with a null fieldMapping, fieldConverter, and newRecordClass.
RecordMapping(EntityBinding entityBinding, boolean beanProperties, Map<String,String> fieldMapping, boolean partialMapping, Class newRecordClass)
          Creates a record mapping using an entity binding, with an optional fieldMapping, fieldConverter, and newRecordClass.
RecordMapping(EntryBinding keyBinding, EntryBinding valueBinding, boolean beanProperties)
          Creates a complete record mapping using separate key and value bindings, with a null fieldMapping, fieldConverter, and newRecordClass.
RecordMapping(EntryBinding keyBinding, EntryBinding valueBinding, boolean beanProperties, Map<String,String> fieldMapping, boolean partialMapping, Class newRecordClass)
          Creates a record mapping using separate key and value bindings, with an optional fieldMapping, fieldConverter, and newRecordClass.
 
Method Summary
 void convertExternalToLocal(Object[] externalFieldValues, DatabaseEntry localKey, DatabaseEntry localData)
          Called internally to convert an array of external record values to a local raw data record.
 void convertLocalToExternal(DatabaseEntry localKey, DatabaseEntry localData, Object[] externalFieldValues)
          Called internally to convert the local raw data record to an array of external record values.
 boolean getBeanProperties()
          Returns true if local bean property names are used or false if local field names are used.
 EntityBinding getEntityBinding()
          Returns the entity binding, or null if key and value bindings are used.
 String[] getExternalFieldNames()
          Returns an array of the names of fields in the external RDBMS.
 Class[] getExternalFieldTypes()
          Returns an array of the types of fields in the external RDBMS.
 Map<String,String> getFieldMapping()
          Returns a Map from local field/property name to external field/column name, or null if no custom mapping is used.
 EntryBinding getKeyBinding()
          Returns the key binding, or null if an entity binding is used.
 Class getNewRecordClass()
          Returns the class used to bind a newly inserted record in a JE Database.
 boolean getPartialMapping()
          Returns true if the field map is a partial mapping and other field names that match should be transferred, or false if it is a complete mapping and omitted names should not be transferred.
 EntryBinding getValueBinding()
          Returns the value binding, or null if an entity binding is used.
 void initializeConverter(Class[] externalFieldTypes, String[] externalFieldNames)
          Called internally to initialize the converter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecordMapping

public RecordMapping(EntityBinding entityBinding,
                     boolean beanProperties)
Creates a complete record mapping using an entity binding, with a null fieldMapping, fieldConverter, and newRecordClass.


RecordMapping

public RecordMapping(EntityBinding entityBinding,
                     boolean beanProperties,
                     Map<String,String> fieldMapping,
                     boolean partialMapping,
                     Class newRecordClass)
Creates a record mapping using an entity binding, with an optional fieldMapping, fieldConverter, and newRecordClass.


RecordMapping

public RecordMapping(EntryBinding keyBinding,
                     EntryBinding valueBinding,
                     boolean beanProperties)
Creates a complete record mapping using separate key and value bindings, with a null fieldMapping, fieldConverter, and newRecordClass.


RecordMapping

public RecordMapping(EntryBinding keyBinding,
                     EntryBinding valueBinding,
                     boolean beanProperties,
                     Map<String,String> fieldMapping,
                     boolean partialMapping,
                     Class newRecordClass)
Creates a record mapping using separate key and value bindings, with an optional fieldMapping, fieldConverter, and newRecordClass.

Method Detail

getEntityBinding

public EntityBinding getEntityBinding()
Returns the entity binding, or null if key and value bindings are used.


getKeyBinding

public EntryBinding getKeyBinding()
Returns the key binding, or null if an entity binding is used.


getValueBinding

public EntryBinding getValueBinding()
Returns the value binding, or null if an entity binding is used.


getBeanProperties

public boolean getBeanProperties()
Returns true if local bean property names are used or false if local field names are used.


getFieldMapping

public Map<String,String> getFieldMapping()
Returns a Map from local field/property name to external field/column name, or null if no custom mapping is used.


getPartialMapping

public boolean getPartialMapping()
Returns true if the field map is a partial mapping and other field names that match should be transferred, or false if it is a complete mapping and omitted names should not be transferred.


getNewRecordClass

public Class getNewRecordClass()
Returns the class used to bind a newly inserted record in a JE Database.

When performing an import and no JE record currently exists, the Class.forName method is called to create a Java object for binding.

The newRecordClass may be null when import operations are not used for this data set.


initializeConverter

public void initializeConverter(Class[] externalFieldTypes,
                                String[] externalFieldNames)
Called internally to initialize the converter.

Specified by:
initializeConverter in interface RecordConverter

convertLocalToExternal

public void convertLocalToExternal(DatabaseEntry localKey,
                                   DatabaseEntry localData,
                                   Object[] externalFieldValues)
Called internally to convert the local raw data record to an array of external record values.

Converts the local raw key/value to a Java object using the entity or key/value bindings, and returns the external field/column values obtained from the Java object using reflection.

Specified by:
convertLocalToExternal in interface RecordConverter

convertExternalToLocal

public void convertExternalToLocal(Object[] externalFieldValues,
                                   DatabaseEntry localKey,
                                   DatabaseEntry localData)
Called internally to convert an array of external record values to a local raw data record.

Converts the external field/column values to a Java object using reflection, and returns the local raw key/value obtained using the entity or key/value bindings.

Specified by:
convertExternalToLocal in interface RecordConverter

getExternalFieldTypes

public Class[] getExternalFieldTypes()
Description copied from interface: RecordConverter
Returns an array of the types of fields in the external RDBMS.

Specified by:
getExternalFieldTypes in interface RecordConverter
Returns:
an array of the fields' types in the external RDBMS.
See Also:
RecordConverter.getExternalFieldTypes()

getExternalFieldNames

public String[] getExternalFieldNames()
Description copied from interface: RecordConverter
Returns an array of the names of fields in the external RDBMS.

Specified by:
getExternalFieldNames in interface RecordConverter
Returns:
an array of fields' names in the external RDBMS.
See Also:
RecordConverter.getExternalFieldNames()


Copyright (c) 2004-2012 Oracle. All rights reserved.