com.sleepycat.persist.impl
Class EnhancedAccessor

java.lang.Object
  extended by com.sleepycat.persist.impl.EnhancedAccessor
All Implemented Interfaces:
Accessor

public class EnhancedAccessor
extends java.lang.Object
implements Accessor

Implements Accessor for a complex persistent class.

Author:
Mark Hayes

Constructor Summary
EnhancedAccessor(Catalog catalog, java.lang.Class type, ComplexFormat format)
          Creates an accessor for a complex type.
EnhancedAccessor(java.lang.Class type)
          Creates an accessor.
 
Method Summary
 java.lang.Object getField(java.lang.Object o, int field, int superLevel, boolean isSecField)
          Returns the value of a given field, representing primitives as primitive wrapper objects.
(package private) static boolean isEnhanced(java.lang.Class type)
          Returns whether a given class is a (registered) enhanced class.
 boolean isPriKeyFieldNullOrZero(java.lang.Object o)
          Returns whether the primary key field is null (for a reference type) or zero (for a primitive integer type).
 java.lang.Object newArray(int len)
          Creates a new one dimensional array of the given length, having the target class as its component type.
 java.lang.Object newInstance()
          Creates a new instance of the target class using its default constructor.
 void readNonKeyFields(java.lang.Object o, EntityInput input, int startField, int endField, int superLevel)
          Reads a range of non-key field values from the given EntityInput, reading fields in super classes first and in name order within class.
 void readPriKeyField(java.lang.Object o, EntityInput input)
          Reads the primary key field value from the given EntityInput.
 void readSecKeyFields(java.lang.Object o, EntityInput input, int startField, int endField, int superLevel)
          Reads a range of secondary key field values from the given EntityInput, reading fields in super classes first and in name order within class.
static void registerClass(java.lang.String className, Enhanced prototype)
          Registers a prototype instance, and should be called during initialization of the prototype class.
 void setField(java.lang.Object o, int field, int superLevel, boolean isSecField, java.lang.Object value)
          Changes the value of a given field, representing primitives as primitive wrapper objects.
 void writeNonKeyFields(java.lang.Object o, EntityOutput output)
          Writes all non-key field values to the given EntityOutput, writing fields in super classes first and in name order within class.
 void writePriKeyField(java.lang.Object o, EntityOutput output)
          Writes the primary key field value to the given EntityOutput.
 void writeSecKeyFields(java.lang.Object o, EntityOutput output)
          Writes all secondary key field values to the given EntityOutput, writing fields in super classes first and in name order within class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EnhancedAccessor

EnhancedAccessor(java.lang.Class type)
Creates an accessor.


EnhancedAccessor

EnhancedAccessor(Catalog catalog,
                 java.lang.Class type,
                 ComplexFormat format)
Creates an accessor for a complex type.

Method Detail

registerClass

public static void registerClass(java.lang.String className,
                                 Enhanced prototype)
Registers a prototype instance, and should be called during initialization of the prototype class. The prototype may be null for an abstract class.


isEnhanced

static boolean isEnhanced(java.lang.Class type)
Returns whether a given class is a (registered) enhanced class.


newInstance

public java.lang.Object newInstance()
Description copied from interface: Accessor
Creates a new instance of the target class using its default constructor.

Specified by:
newInstance in interface Accessor

newArray

public java.lang.Object newArray(int len)
Description copied from interface: Accessor
Creates a new one dimensional array of the given length, having the target class as its component type.

Using a special method for a one dimensional array, which can be implemented by bytecode generation, is a compromise. We use reflection to create multidimensional arrays. We could in the future generate code to create arrays as they are encountered, if there is a need to avoid reflection for multidimensional arrays.

Specified by:
newArray in interface Accessor

isPriKeyFieldNullOrZero

public boolean isPriKeyFieldNullOrZero(java.lang.Object o)
Description copied from interface: Accessor
Returns whether the primary key field is null (for a reference type) or zero (for a primitive integer type). Null and zero are used as an indication that the key should be assigned from a sequence.

Specified by:
isPriKeyFieldNullOrZero in interface Accessor

writePriKeyField

public void writePriKeyField(java.lang.Object o,
                             EntityOutput output)
Description copied from interface: Accessor
Writes the primary key field value to the given EntityOutput.

To write a primary key with a reference type, this method must call EntityOutput.writeKeyObject.

Specified by:
writePriKeyField in interface Accessor
Parameters:
o - is the object whose primary key field is to be written.
output - the output data to write to.

readPriKeyField

public void readPriKeyField(java.lang.Object o,
                            EntityInput input)
Description copied from interface: Accessor
Reads the primary key field value from the given EntityInput.

To read a primary key with a reference type, this method must call EntityInput.readKeyObject.

Specified by:
readPriKeyField in interface Accessor
Parameters:
o - is the object whose primary key field is to be read.
input - the input data to read from.

writeSecKeyFields

public void writeSecKeyFields(java.lang.Object o,
                              EntityOutput output)
Description copied from interface: Accessor
Writes all secondary key field values to the given EntityOutput, writing fields in super classes first and in name order within class.

Specified by:
writeSecKeyFields in interface Accessor
Parameters:
o - is the object whose secondary key fields are to be written.

If the primary key has a reference type, this method must call EntityOutput.registerPriKeyObject before writing any other fields.

output - the output data to write to.

readSecKeyFields

public void readSecKeyFields(java.lang.Object o,
                             EntityInput input,
                             int startField,
                             int endField,
                             int superLevel)
Description copied from interface: Accessor
Reads a range of secondary key field values from the given EntityInput, reading fields in super classes first and in name order within class.

If the primary key has a reference type, this method must call EntityInput.registerPriKeyObject before reading any other fields.

To read all fields, pass -1 for superLevel, zero for startField and Integer.MAX_VALUE for endField. Fields from super classes are read first.

To read a specific range of fields, pass a non-negative number for superLevel and the specific indices of the field range to be read in the class at that level.

Specified by:
readSecKeyFields in interface Accessor
Parameters:
o - is the object whose secondary key fields are to be read.
input - the input data to read from.
startField - the starting field index in the range of fields to read. To read all fields, the startField should be zero.
endField - the ending field index in the range of fields to read. To read all fields, the endField should be Integer.MAX_VALUE.
superLevel - is a non-negative number to read the fields of the class that is the Nth super instance; or a negative number to read fields in all classes.

writeNonKeyFields

public void writeNonKeyFields(java.lang.Object o,
                              EntityOutput output)
Description copied from interface: Accessor
Writes all non-key field values to the given EntityOutput, writing fields in super classes first and in name order within class.

Specified by:
writeNonKeyFields in interface Accessor
Parameters:
o - is the object whose non-key fields are to be written.
output - the output data to write to.

readNonKeyFields

public void readNonKeyFields(java.lang.Object o,
                             EntityInput input,
                             int startField,
                             int endField,
                             int superLevel)
Description copied from interface: Accessor
Reads a range of non-key field values from the given EntityInput, reading fields in super classes first and in name order within class.

To read all fields, pass -1 for superLevel, zero for startField and Integer.MAX_VALUE for endField. Fields from super classes are read first.

To read a specific range of fields, pass a non-negative number for superLevel and the specific indices of the field range to be read in the class at that level.

Specified by:
readNonKeyFields in interface Accessor
Parameters:
o - is the object whose non-key fields are to be read.
input - the input data to read from.
startField - the starting field index in the range of fields to read. To read all fields, the startField should be zero.
endField - the ending field index in the range of fields to read. To read all fields, the endField should be Integer.MAX_VALUE.
superLevel - is a non-negative number to read the fields of the class that is the Nth super instance; or a negative number to read fields in all classes.

getField

public java.lang.Object getField(java.lang.Object o,
                                 int field,
                                 int superLevel,
                                 boolean isSecField)
Description copied from interface: Accessor
Returns the value of a given field, representing primitives as primitive wrapper objects.

Specified by:
getField in interface Accessor
Parameters:
o - is the object containing the key field.
field - is the field index.
superLevel - is a positive number to identify the field of the class that is the Nth super instance; or zero to identify the field in this class.
isSecField - is true for a secondary key field or false for a non-key field.
Returns:
the current field value, or null for a reference type field that is null.

setField

public void setField(java.lang.Object o,
                     int field,
                     int superLevel,
                     boolean isSecField,
                     java.lang.Object value)
Description copied from interface: Accessor
Changes the value of a given field, representing primitives as primitive wrapper objects.

Specified by:
setField in interface Accessor
Parameters:
o - is the object containing the key field.
field - is the field index.
superLevel - is a positive number to identify the field of the class that is the Nth super instance; or zero to identify the field in this class.
isSecField - is true for a secondary key field or false for a non-key field.
value - is the new value of the field, or null to set a reference type field to null.


Copyright 2004-2006 Sleepycat, Inc. All Rights Reserved.