Sindbad~EG File Manager
<!--$Id: binding.so,v 1.2 2003/09/03 18:34:52 gburd Exp $-->
<!--Copyright 1997-2003 by Sleepycat Software, Inc.-->
<!--All rights reserved.-->
<!--See the file LICENSE for redistribution information.-->
<html>
<head>
<title>Berkeley DB Reference Guide: Serializable Entity - Using transient fields in an entity binding</title>
<meta name="description" content="Berkeley DB: An embedded database programmatic toolkit.">
<meta name="keywords" content="embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++">
</head>
<body bgcolor=white>
<a name="2"><!--meow--></a>
<table width="100%"><tr valign=top>
<td><h3><dl><dt>Berkeley DB Reference Guide:<dd>Java API Tutorial - Serializable Entity</dl></h3></td>
<td align=right><a href="../bdb_sentity/class.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../bdb_sentity/remove.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Serializable Entity - Using transient fields in an entity binding</h3>
<p>The entity bindings from the prior example have been changed in this
example to use the entity object both as a value object and an entity object.</p>
<p>Before, the <b>dataToObject</b> method combined the deserialized value
object with the key fields to create a new entity object. Now, this method
uses the deserialized object directly as an entity, and initializes its key
using the fields read from the key tuple.</p>
<p>Before, the <b>objectToValue</b> method constructed a new value
object using information in the entity. Now it simply returns the entity.
Nothing needs to be changed in the entity, since the transient key fields won't
be serialized.</p>
<hr size=1 noshade>
<blockquote><pre>
public class SampleViews
{
...
private static class PartBinding extends TupleSerialBinding
{
private PartBinding(TupleFormat keyFormat,
SerialFormat valueFormat)
{
super(keyFormat, valueFormat);
}
<p>
public Object dataToObject(TupleInput keyInput, Object valueInput)
throws IOException
{
String number = keyInput.readString();
<b> Part part = (Part) valueInput;
part.setKey(number);
return part;
</b> }
<p>
public void objectToKey(Object object, TupleOutput output)
throws IOException
{
Part part = (Part) object;
output.writeString(part.getNumber());
}
<p>
public Object objectToValue(Object object)
throws IOException
{
<b> return object;
</b> }
}
<p>
private static class SupplierBinding extends TupleSerialBinding
{
private SupplierBinding(TupleFormat keyFormat,
SerialFormat valueFormat)
{
super(keyFormat, valueFormat);
}
<p>
public Object dataToObject(TupleInput keyInput, Object valueInput)
throws IOException
{
String number = keyInput.readString();
<b> Supplier supplier = (Supplier) valueInput;
supplier.setKey(number);
return supplier;
</b> }
<p>
public void objectToKey(Object object, TupleOutput output)
throws IOException
{
Supplier supplier = (Supplier) object;
output.writeString(supplier.getNumber());
}
<p>
public Object objectToValue(Object object)
throws IOException
{
<b> return object;
</b> }
}
<p>
private static class ShipmentBinding extends TupleSerialBinding
{
private ShipmentBinding(TupleFormat keyFormat,
SerialFormat valueFormat)
{
super(keyFormat, valueFormat);
}
<p>
public Object dataToObject(TupleInput keyInput, Object valueInput)
throws IOException
{
String partNumber = keyInput.readString();
String supplierNumber = keyInput.readString();
<b> Shipment shipment = (Shipment) valueInput;
shipment.setKey(partNumber, supplierNumber);
return shipment;
</b> }
<p>
public void objectToKey(Object object, TupleOutput output)
throws IOException
{
Shipment shipment = (Shipment) object;
output.writeString(shipment.getPartNumber());
output.writeString(shipment.getSupplierNumber());
}
<p>
public Object objectToValue(Object object)
throws IOException
{
<b> return object;
</b> }
}
}
</pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../bdb_sentity/class.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../bdb_sentity/remove.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p><font size=1><a href="../../sleepycat/legal.html">Copyright (c) 1996-2003</a> <a href="http://www.sleepycat.com">Sleepycat Software, Inc.</a> - All rights reserved.</font>
</body>
</html>
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists