public class SerialBinding<E> extends SerialBase implements EntryBinding<E>
EntryBindingthat 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
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.
SerialBinding and other classes in this package use standard Java
serialization and all rules of Java serialization apply. This includes the
rules for class evolution. Once an instance of a class is stored, the class
must maintain its
serialVersionUID and follow the rules defined in
the Java specification. To use a new incompatible version of a class, a
ClassCatalog must be used or the class catalog database
must be truncated.
If more advanced class evolution features are required, consider using
Direct Persistence Layer.
|Constructor and Description|
Creates a serial binding.
|Modifier and Type||Method and Description|
Deserialize an object from an entry buffer.
Returns the base class for this binding.
Returns the class loader to be used during deserialization, or null if a default class loader should be used.
Serialize an object into an entry buffer.
getSerialBufferSize, getSerialOutput, setSerialBufferSize
public SerialBinding(ClassCatalog classCatalog, java.lang.Class<E> baseClass)
classCatalog- is the catalog to hold shared class information and for a database should be a
baseClass- is the base class for serialized objects stored using this binding -- all objects using this binding must be an instance of this class. Note that if this parameter is non-null, then this binding will not support serialization of null values.
public final java.lang.Class<E> getBaseClass()
public java.lang.ClassLoader getClassLoader()
ClassCatalog.getClassLoader(), if it returns a non-null value. If
ClassCatalog.getClassLoader()returns null, then
This method may be overridden to return a dynamically determined
class loader. For example,
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
public E entryToObject(DatabaseEntry entry)
objectToEntry(E, com.sleepycat.je.DatabaseEntry), since the fixed serialization header is assumed to not be included in the input data.
SerialInputis used to deserialize the object.
public void objectToEntry(E object, DatabaseEntry entry)
entryToObject(com.sleepycat.je.DatabaseEntry)method must be used.
SerialOutputis used to serialize the object.
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.
object- is the input deserialized object.
entry- is the output serialized entry.
java.lang.IllegalArgumentException- if the object is not an instance of the base class for this binding, including if the object is null and a non-null base class was specified.
Copyright (c) 2002, 2017 Oracle and/or its affiliates. All rights reserved.