Berkeley DB Reference Guide: Serializable Entity - Removing the redundant value classes
Description: Berkeley DB: An embedded database programmatic toolkit.
Keywords: embedded,database,programmatic,toolkit,b+tree,btree,hash,hashing,transaction,transactions,locking,logging,access method,access methods,Java,C,C++

### Berkeley DB Reference Guide: Java API Tutorial - Serializable Entity |

### Serializable Entity - Removing the redundant value classes

The PartValue, SupplierValue and ShipmentValue classes have been removed in this example, and the Part, Supplier and Shipment entity classes are used in their place.

The serial formats are created with the entity classes.

>     public class SampleDatabase
>     {
>         ...
>         public SampleDatabase(String homeDirectory, boolean runRecovery)
>             throws DbException, FileNotFoundException
>         {
>             ...
>             partKeyFormat = new TupleFormat();
>             partValueFormat = new SerialFormat(javaCatalog, Part.class);
>             supplierKeyFormat = new TupleFormat();
>             supplierValueFormat = new SerialFormat(javaCatalog, Supplier.class);
>             shipmentKeyFormat = new TupleFormat();
>             shipmentValueFormat = new SerialFormat(javaCatalog, Shipment.class);
>             cityKeyFormat = new TupleFormat();
>             ...
>         }
>     }

The index key extractor uses the entity class as well.

>     public class SampleDatabase
>     {
>         ...
>         private static class SupplierByCityExtractor
>             extends TupleSerialKeyExtractor
>         {
>             private SupplierByCityExtractor(TupleFormat primaryKeyFormat,
>                                             SerialFormat valueFormat,
>                                             TupleFormat indexKeyFormat)
>             {
>                 super(primaryKeyFormat, valueFormat, indexKeyFormat);
>             }

>             public void extractIndexKey(TupleInput primaryKeyInput,
>                                         Object valueInput,
>                                         TupleOutput indexKeyOutput)
>                 throws IOException
>             {
>                 Supplier supplierValue = (Supplier) valueInput;
>                 indexKeyOutput.writeString(supplierValue.getCity());
>             }

>             public void clearIndexKey(Object valueInputOutput)
>                 throws IOException
>             {
>                 throw new UnsupportedOperationException();
>             }
>         }

>     }

Copyright (c) 1996-2003 Sleepycat Software, Inc. - All rights reserved.