com.sleepycat.persist.impl
Class CompositeKeyFormat

java.lang.Object
  extended by com.sleepycat.persist.impl.Format
      extended by com.sleepycat.persist.impl.CompositeKeyFormat
All Implemented Interfaces:
Reader, RawType, Serializable

public class CompositeKeyFormat
extends Format

Format for a composite key class. This class is similar to ComplexFormat in that a composite key class and other complex classes have fields, and the Accessor interface is used to access those fields. Composite key classes are different in the following ways: - The superclass must be Object. No inheritance is allowed. - All instance fields must be annotated with @KeyField, which determines their order in the data bytes. - Although fields may be reference types (primitive wrappers or other simple reference types), they are stored as if they were primitives. No object format ID is stored, and the class of the object must be the declared classs of the field; i.e., no polymorphism is allowed for key fields. In other words, a composite key is stored as an ordinary tuple as defined in the com.sleepycat.bind.tuple package. This keeps the key small and gives it a well defined sort order. - If the key class implements Comparable, it is called by the Database btree comparator. It must therefore be available during JE recovery, before the store and catalog have been opened. To support this, this format can be constructed during recovery. A SimpleCatalog singleton instance is used to provide a catalog of simple types that is used by the composite key format. - When interacting with the Accessor, the composite key format treats the Accessor's non-key fields as its key fields. The Accessor's key fields are secondary keys, while the composite format's key fields are the component parts of a single key.

Author:
Mark Hayes
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.sleepycat.persist.impl.Format
ID_BIGDEC, ID_BIGINT, ID_BOOL, ID_BOOL_W, ID_BYTE, ID_BYTE_W, ID_CHAR, ID_CHAR_W, ID_DATE, ID_DOUBLE, ID_DOUBLE_W, ID_FLOAT, ID_FLOAT_W, ID_INT, ID_INT_W, ID_LONG, ID_LONG_W, ID_NULL, ID_NUMBER, ID_OBJECT, ID_PREDEFINED, ID_SHORT, ID_SHORT_W, ID_SIMPLE_MAX, ID_SIMPLE_MIN, ID_STRING
 
Constructor Summary
CompositeKeyFormat(Class cls, ClassMetadata metadata, List<FieldMetadata> fieldNames)
           
CompositeKeyFormat(Class cls, ClassMetadata metadata, String[] fieldNames)
           
 
Method Summary
(package private)  void collectRelatedFormats(Catalog catalog, Map<String,Format> newFormats)
          Calls catalog.createFormat for formats that this format depends on, or that should also be persistent.
(package private)  Object convertRawObject(Catalog catalog, boolean rawAccess, RawObject rawObject, IdentityHashMap converted)
          Converts a RawObject to a current class object and adds the converted pair to the converted map.
(package private)  void copySecKey(RecordInput input, RecordOutput output)
          Called after skipToSecKey() to copy the data bytes of a singular (XXX_TO_ONE) key field.
(package private)  boolean evolve(Format newFormatParam, Evolver evolver)
          Called for an existing format that may not equal the current format for the same class.
(package private)  ClassMetadata getClassMetadata()
          Returns the original model class metadata used to create this class, or null if this is not a model class.
(package private) static String[] getFieldNameArray(List<FieldMetadata> list)
           
 Map<String,RawField> getFields()
          Returns a map of field name to raw field for each non-static non-transient field declared in this class, or null if this is not a complex type (in other words, this is a simple type or an array type).
(package private)  Format getSequenceKeyFormat()
          Validates and returns the simple integer key format for a sequence key associated with this format.
(package private)  void initialize(Catalog catalog, int initVersion)
          Initializes an uninitialized format, initializing its related formats (superclass formats and array component formats) first.
(package private)  boolean isModelClass()
          Returns whether this class is present in the EntityModel.
(package private)  void migrateFromBeta(Map<String,Format> formatMap)
          Special handling for JE 3.0.12 beta formats.
(package private)  Object newArray(int len)
          Creates an array of the format's class of the given length, as if Array.newInstance(getType(), len) were called.
 Object newInstance(EntityInput input, boolean rawAccess)
          Creates a new instance of the target class using its default constructor.
 Object readObject(Object o, EntityInput input, boolean rawAccess)
          Called after newInstance() to read the rest of the data bytes and fill in the object contents.
(package private)  void skipContents(RecordInput input)
          Skips over the object's contents, as if readObject() were called, but without returning an object.
(package private)  void writeObject(Object o, EntityOutput output, boolean rawAccess)
          Writes a given instance of the target class to the output data bytes.
 
Methods inherited from class com.sleepycat.persist.impl.Format
areNestedRefsProhibited, copySecMultiKey, evolveMetadata, getCatalog, getClassName, getComponentType, getDimensions, getEntityFormat, getEntityMetadata, getEnumConstants, getEvolveNeeded, getExistingType, getId, getLatestVersion, getPreviousVersion, getProxiedFormat, getReader, getSuperFormat, getSuperType, getType, getVersion, getWrapperFormat, initializeIfNeeded, initializeReader, isArray, isAssignableTo, isCurrentVersion, isDeleted, isEntity, isEnum, isInitialized, isNew, isPredefined, isPriKeyNullOrZero, isPrimitive, isSameClass, isSimple, nullifySecKey, readPriKey, setDeleted, setEvolveNeeded, setId, setLatestVersion, setProxiedFormat, setReader, setSuperFormat, setUnused, skipToSecKey, toString, writePriKey
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

CompositeKeyFormat

CompositeKeyFormat(Class cls,
                   ClassMetadata metadata,
                   List<FieldMetadata> fieldNames)

CompositeKeyFormat

CompositeKeyFormat(Class cls,
                   ClassMetadata metadata,
                   String[] fieldNames)
Method Detail

getFieldNameArray

static String[] getFieldNameArray(List<FieldMetadata> list)

migrateFromBeta

void migrateFromBeta(Map<String,Format> formatMap)
Description copied from class: Format
Special handling for JE 3.0.12 beta formats.

Overrides:
migrateFromBeta in class Format

isModelClass

boolean isModelClass()
Description copied from class: Format
Returns whether this class is present in the EntityModel. Returns false for a simple type, array type, or enum type.

Overrides:
isModelClass in class Format

getClassMetadata

ClassMetadata getClassMetadata()
Description copied from class: Format
Returns the original model class metadata used to create this class, or null if this is not a model class.

Overrides:
getClassMetadata in class Format

getFields

public Map<String,RawField> getFields()
Description copied from interface: RawType
Returns a map of field name to raw field for each non-static non-transient field declared in this class, or null if this is not a complex type (in other words, this is a simple type or an array type).

Specified by:
getFields in interface RawType
Overrides:
getFields in class Format

collectRelatedFormats

void collectRelatedFormats(Catalog catalog,
                           Map<String,Format> newFormats)
Description copied from class: Format
Calls catalog.createFormat for formats that this format depends on, or that should also be persistent.

Specified by:
collectRelatedFormats in class Format

initialize

void initialize(Catalog catalog,
                int initVersion)
Description copied from class: Format
Initializes an uninitialized format, initializing its related formats (superclass formats and array component formats) first.

Specified by:
initialize in class Format

newArray

Object newArray(int len)
Description copied from class: Format
Creates an array of the format's class of the given length, as if Array.newInstance(getType(), len) were called. Formats implement this method for specific classes, or call the accessor, to avoid the reflection overhead of Array.newInstance.

Specified by:
newArray in class Format

newInstance

public Object newInstance(EntityInput input,
                          boolean rawAccess)
Description copied from class: Format
Creates a new instance of the target class using its default constructor. Normally this creates an empty object, and readObject() is called next to fill in the contents. This is done in two steps to allow the instance to be registered by EntityInput before reading the contents. This allows the fields in an object or a nested object to refer to the parent object in a graph. Alternatively, this method may read all or the first portion of the data, rather than that being done by readObject(). This is required for simple types and enums, where the object cannot be created without reading the data. In these cases, there is no possibility that the parent object will be referenced by the child object in the graph. It should not be done in other cases, or the graph references may not be maintained faithfully. Is public only in order to implement the Reader interface. Note that this method should only be called directly in raw conversion mode or during conversion of an old format. Normally it should be called via the getReader method and the Reader interface.

Specified by:
newInstance in interface Reader
Specified by:
newInstance in class Format

readObject

public Object readObject(Object o,
                         EntityInput input,
                         boolean rawAccess)
Description copied from class: Format
Called after newInstance() to read the rest of the data bytes and fill in the object contents. If the object was read completely by newInstance(), this method does nothing. Is public only in order to implement the Reader interface. Note that this method should only be called directly in raw conversion mode or during conversion of an old format. Normally it should be called via the getReader method and the Reader interface.

Specified by:
readObject in interface Reader
Specified by:
readObject in class Format

writeObject

void writeObject(Object o,
                 EntityOutput output,
                 boolean rawAccess)
Description copied from class: Format
Writes a given instance of the target class to the output data bytes. This is the complement of the newInstance()/readObject() pair.

Specified by:
writeObject in class Format

convertRawObject

Object convertRawObject(Catalog catalog,
                        boolean rawAccess,
                        RawObject rawObject,
                        IdentityHashMap converted)
Description copied from class: Format
Converts a RawObject to a current class object and adds the converted pair to the converted map.

Overrides:
convertRawObject in class Format

skipContents

void skipContents(RecordInput input)
Description copied from class: Format
Skips over the object's contents, as if readObject() were called, but without returning an object. Used for extracting secondary key bytes without having to instantiate the object. For reference types, the format ID is read just before calling this method, so this method is responsible for skipping everything following the format ID.

Specified by:
skipContents in class Format

copySecKey

void copySecKey(RecordInput input,
                RecordOutput output)
Description copied from class: Format
Called after skipToSecKey() to copy the data bytes of a singular (XXX_TO_ONE) key field.

Overrides:
copySecKey in class Format

getSequenceKeyFormat

Format getSequenceKeyFormat()
Description copied from class: Format
Validates and returns the simple integer key format for a sequence key associated with this format. For a composite key type, the format of the one and only field is returned. For a simple integer type, this format is returned. Otherwise (the default implementation), an IllegalArgumentException is thrown.

Overrides:
getSequenceKeyFormat in class Format

evolve

boolean evolve(Format newFormatParam,
               Evolver evolver)
Description copied from class: Format
Called for an existing format that may not equal the current format for the same class.

If this method returns true, then it must have determined that the old and new formats are equal, and it must have called either Evolver.useOldFormat or useEvolvedFormat. If this method returns false, then it must have determined that the old format could not be evolved to the new format, and it must have called Evolver.addInvalidMutation, addMissingMutation or addEvolveError.

Specified by:
evolve in class Format


Copyright 2004,2008 Oracle. All rights reserved.