com.sleepycat.bind.serial
public class SerialBinding extends SerialBase implements EntryBinding
EntryBinding
that treats a key or data entry as
a serialized object.
This binding stores objects in serialized object format. The
deserialized objects are returned by the binding, and their
Class
must implement the Serializable
interface.
For key bindings, a tuple binding is usually a better choice than a serial binding. A tuple binding gives a reasonable sort order, and works with comparators in all cases -- see below.
WARNING: SerialBinding should not be used with Berkeley DB Java Edition for key bindings, when a custom comparator is used. In JE, comparators are instantiated and called internally at times when databases are not accessible. Because serial bindings depend on the class catalog database, a serial binding cannot be used during these times. An attempt to use a serial binding with a custom comparator will result in a NullPointerException during environment open or close.
Constructor Summary | |
---|---|
SerialBinding(ClassCatalog classCatalog, Class baseClass)
Creates a serial binding.
|
Method Summary | |
---|---|
Object | entryToObject(DatabaseEntry entry)
Deserialize an object from an entry buffer. |
Class | getBaseClass()
Returns the base class for this binding.
|
ClassLoader | getClassLoader()
Returns the class loader to be used during deserialization, or null if
a default class loader should be used. |
void | objectToEntry(Object object, DatabaseEntry entry)
Serialize an object into an entry buffer. |
Parameters: classCatalog is the catalog to hold shared class information and for a database should be a StoredClassCatalog. baseClass is the base class for serialized objects stored using this binding -- all objects using this binding must be an instance of this class.
Parameters: entry is the input serialized entry.
Returns: the output deserialized object.
Returns: the base class for this binding.
This method may be overriden to return a dynamically determined class
loader. For example,
Thread.currentThread().getContextClassLoader()
could be
called to use the context class loader for the curren thread. Or
getBaseClass().getClassLoader()
could be called to use the
class loader for the base class, assuming that a base class has been
specified.
If this method returns null, a default class loader will be used as
determined by the java.io.ObjectInputStream.resolveClass
method.
Note that this method sets the DatabaseEntry offset property to a non-zero value and the size property to a value less than the length of the byte array.
Parameters: object is the input deserialized object. entry is the output serialized entry.
Throws: IllegalArgumentException if the object is not an instance of the base class for this binding.