1<?xml version="1.0" encoding="UTF-8" standalone="no"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 6 <title>Deleting Entity Objects</title> 7 <link rel="stylesheet" href="gettingStarted.css" type="text/css" /> 8 <meta name="generator" content="DocBook XSL Stylesheets V1.62.4" /> 9 <link rel="home" href="index.html" title="Getting Started with Berkeley DB" /> 10 <link rel="up" href="persist_access.html" title="Chapter��5.��Saving and Retrieving Objects" /> 11 <link rel="previous" href="dpl_entityjoin.html" title="Join Cursors" /> 12 <link rel="next" href="dpl_replace.html" title="Replacing Entity Objects" /> 13 </head> 14 <body> 15 <div class="navheader"> 16 <table width="100%" summary="Navigation header"> 17 <tr> 18 <th colspan="3" align="center">Deleting Entity Objects</th> 19 </tr> 20 <tr> 21 <td width="20%" align="left"><a accesskey="p" href="dpl_entityjoin.html">Prev</a>��</td> 22 <th width="60%" align="center">Chapter��5.��Saving and Retrieving Objects</th> 23 <td width="20%" align="right">��<a accesskey="n" href="dpl_replace.html">Next</a></td> 24 </tr> 25 </table> 26 <hr /> 27 </div> 28 <div class="sect1" lang="en" xml:lang="en"> 29 <div class="titlepage"> 30 <div> 31 <div> 32 <h2 class="title" style="clear: both"><a id="dpl_delete"></a>Deleting Entity Objects</h2> 33 </div> 34 </div> 35 <div></div> 36 </div> 37 <p> 38 The simplest way to remove an object from your entity store 39 is to delete it by its primary index. For example, 40 using the <tt class="classname">SimpleDA</tt> class that we 41 created earlier in this document 42 (see <a href="simpleda.html">SimpleDA.class</a>), 43 you can delete the <tt class="classname">SimpleEntityClass</tt> 44 object with a primary key of <tt class="literal">keyone</tt> as 45 follows: 46 </p> 47 <pre class="programlisting">sda.pIdx.delete("keyone");</pre> 48 <p> 49 You can also delete objects by their secondary keys. When 50 you do this, all objects related to the secondary key are 51 deleted, unless the key is a foreign object. 52 </p> 53 <p> 54 For example, the following deletes all 55 <tt class="classname">SimpleEntityClass</tt> with a secondary 56 key of <tt class="literal">skeyone</tt>: 57 </p> 58 <pre class="programlisting">sda.sIdx.delete("skeyone");</pre> 59 <p> 60 Finally, if you are indexing by foreign key, then the 61 results of deleting the key is determined by the foreign 62 key constraint that you have set for the index. See 63 <a href="dplindexcreate.html#foreignkey">Foreign Key Constraints</a> 64 for more information. 65 </p> 66 </div> 67 <div class="navfooter"> 68 <hr /> 69 <table width="100%" summary="Navigation footer"> 70 <tr> 71 <td width="40%" align="left"><a accesskey="p" href="dpl_entityjoin.html">Prev</a>��</td> 72 <td width="20%" align="center"> 73 <a accesskey="u" href="persist_access.html">Up</a> 74 </td> 75 <td width="40%" align="right">��<a accesskey="n" href="dpl_replace.html">Next</a></td> 76 </tr> 77 <tr> 78 <td width="40%" align="left" valign="top">Join Cursors��</td> 79 <td width="20%" align="center"> 80 <a accesskey="h" href="index.html">Home</a> 81 </td> 82 <td width="40%" align="right" valign="top">��Replacing Entity Objects</td> 83 </tr> 84 </table> 85 </div> 86 </body> 87</html> 88