Sophie

Sophie

distrib > Mandriva > 2007.0 > x86_64 > media > main-release > by-pkgid > a4c98df40e78f6c892308fd6841f950a > files > 842

lib64db4.2-devel-4.2.52-11mdv2007.0.x86_64.rpm

<!--$Id: classes.so,v 1.2 2003/09/03 18:34:46 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: Defining entity classes</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 - Entity</dl></h3></td>
<td align=right><a href="../bdb_entity/intro.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../bdb_entity/bindings.html"><img src="../../images/next.gif" alt="Next"></a>
</td></tr></table>
<p>
<h3 align=center>Defining entity classes</h3>
<p>As described in the prior section, <i>entity classes</i> are combined
key/value classes that are managed by entity bindings.  In this example the
<b>Part</b>, <b>Supplier</b> and <b>Shipment</b> classes are entity
classes.  These classes contain fields that are a union of the fields of the
key and value classes that were defined earlier for each store.</p>
<p>In general, entity classes may be defined in any way desired by the
application.  The entity binding, which is also defined by the application, is
responsible for mapping between key/value objects and entity objects.</p>
<hr size=1 noshade>
<p>The <b>Part</b>, <b>Supplier</b> and <b>Shipment</b> classes are
defined below.</p>
<p>An important difference between the entity classes defined here and the
key and value classes defined earlier is that the entity classes are not
serializable (do not implement the 
<a href="http://java.sun.com/j2se/1.3/docs/api/java/io/Serializable.html">Serializable</a>
interface).  This is because the entity classes are not directly stored.  The
entity binding decomposes an entity object into key and value objects, and
only the key and value objects are serialized for storage.</p>
<p>One advantage of using entities can already be seen in the
<b>toString</b> method of the classes below.  These return debugging output
for the combined key and value, and will be used later to create a listing of
the database that is more readable than in the prior examples.</p>
<blockquote><pre><b>public class Part
{
    private String number;
    private String name;
    private String color;
    private Weight weight;
    private String city;
<p>
    public Part(String number, String name, String color, Weight weight,
                String city)
    {
        this.number = number;
        this.name = name;
        this.color = color;
        this.weight = weight;
        this.city = city;
    }
<p>
    public final String getNumber()
    {
        return number;
    }
<p>
    public final String getName()
    {
        return name;
    }
<p>
    public final String getColor()
    {
        return color;
    }
<p>
    public final Weight getWeight()
    {
        return weight;
    }
<p>
    public final String getCity()
    {
        return city;
    }
<p>
    public String toString()
    {
        return "Part: number=" + number +
               " name=" + name +
               " color=" + color +
               " weight=" + weight +
               " city=" + city + '';
    }
}
</b></pre></blockquote>
<blockquote><pre><b>public class Supplier
{
    private String number;
    private String name;
    private int status;
    private String city;
<p>
    public Supplier(String number, String name, int status, String city)
    {
        this.number = number;
        this.name = name;
        this.status = status;
        this.city = city;
    }
<p>
    public final String getNumber()
    {
        return number;
    }
<p>
    public final String getName()
    {
        return name;
    }
<p>
    public final int getStatus()
    {
        return status;
    }
<p>
    public final String getCity()
    {
        return city;
    }
<p>
    public String toString()
    {
        return "Supplier: number=" + number +
               " name=" + name +
               " status=" + status +
               " city=" + city + '';
    }
}
</b></pre></blockquote>
<blockquote><pre><b>public class Shipment
{
    private String partNumber;
    private String supplierNumber;
    private int quantity;
<p>
    public Shipment(String partNumber, String supplierNumber, int quantity)
    {
        this.partNumber = partNumber;
        this.supplierNumber = supplierNumber;
        this.quantity = quantity;
    }
<p>
    public final String getPartNumber()
    {
        return partNumber;
    }
<p>
    public final String getSupplierNumber()
    {
        return supplierNumber;
    }
<p>
    public final int getQuantity()
    {
        return quantity;
    }
<p>
    public String toString()
    {
        return "Shipment: part=" + partNumber +
                " supplier=" + supplierNumber +
                " quantity=" + quantity + '';
    }
}
</b></pre></blockquote>
<table width="100%"><tr><td><br></td><td align=right><a href="../bdb_entity/intro.html"><img src="../../images/prev.gif" alt="Prev"></a><a href="../toc.html"><img src="../../images/ref.gif" alt="Ref"></a><a href="../bdb_entity/bindings.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>